Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Created June 7, 2010 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcheiligers/428817 to your computer and use it in GitHub Desktop.
Save marcheiligers/428817 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Mad Mimi Archives Plugin
Plugin URI: http://mimi.fascinationstreet.co.za/mimi_archives.php
Version: 0.01
Author: <a href="http://fascinationstreet.co.za/">Marc Heiligers</a>
Description: A plugin which displays archived newsletters from Mad Mimi in your blog
Distributed under the MIT license. Please don't sue me :-)
You will need to add your Mad Mimi username and API key before uploading.
*/
if(!class_exists("MadMimiArchives")) {
class MadMimiArchives {
function MadMimiArchives() {
$this->mad_mimi_username = ""; //Your Mad Mimi account email address
$this->mad_mimi_api_key = ""; //Your Mad Mimi API Key (click Account, it's at the bottom)
$this->mad_mimi_archive_marker = "[[MadMimiArchives]]"; //The text that will be replaced in your posts or pages
$this->mad_mimi_archive_prefix = "Archived "; //The prefix in the promotion name which will mark a promotion as archived
}
function addArchives($content = '') {
if(strpos($content, $this->mad_mimi_archive_marker) !== false) {
$promos = $this->getArchives();
$list = "<ul>";
foreach($promos as $promo) {
$name = $promo->getAttributeNode("name")->value;
if(substr($name, 0, strlen($this->mad_mimi_archive_prefix)) == $this->mad_mimi_archive_prefix) {
$name = substr($name, strlen($this->mad_mimi_archive_prefix));
$mimio = $promo->getAttributeNode("mimio")->value;
$list .= "<li><a href='http://mim.io/$mimio' target='_blank'>$name</a></li>";
}
}
$list .= "</ul>";
$content = str_replace($this->mad_mimi_archive_marker, $list, $content);
}
return $content;
}
function getArchives() {
$url = "http://api.madmimi.com/promotions.xml";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, "$url?username=$this->mad_mimi_username&api_key=$this->mad_mimi_api_key");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$dom = new DOMDocument;
$dom->loadXML($response);
$promos = $dom->getElementsByTagName("promotion");
return $promos;
}
}
}
if(class_exists("MadMimiArchives")) {
$mad_mimi_archives = new MadMimiArchives();
}
if(isset($mad_mimi_archives)) {
add_filter('the_content', array(&$mad_mimi_archives, 'addArchives'));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment