* @date May 24th 2010 * */ Class AttachmentGalleryManager{ var $path; var $options=array(); var $marker='[attachmentgallery]'; var $downloadText='Download Now'; /** * @desc * @author Leo Brown * */ function AttachmentGalleryManager(){ $this->path = dirname(__FILE__).'/'; } /** * @desc * @author Leo Brown * */ function detect_gallery_options($content){ if(false!==strpos($content,$this->marker)){ return array( 'filetypes'=>array('.pdf') ); } else return false; } /** * @desc Returns gallery HTML on the basis of options * @author Leo Brown * @param $options Array Options array * @return string HTML of Gallery */ function get_attachment_gallery(&$contents,$options){ $attachments = $this->find_attachment_links($contents, $options['filetypes']); // generate HTML for gallery $html=''; if($attachments){ $html .= '
'; } return $html; } /** * @desc Splices gallery content back into page content * @author Leo Brown * @todo Move this function to the shortcode library, probably * */ function insert_gallery($page, $gallery){ return str_replace($this->marker,$gallery,$page); } /** * @desc * @author Leo Brown * */ function find_attachment_links(&$input, $types){ if(!$types) $types=array('.pdf'); $types=implode($types,'|'); $results=array(); $regexp = "]*href=(['\"]??)([^\" >]*?{$types})\\1[^>]*>(.*)<\/a>"; if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) { foreach($matches as $match){ $results[]=array( 'title'=>$match[3], 'url'=>$match[2] ); // remove the link $input=str_replace($match[0],'',$input); } } return $results; } } /** * @desc Hooks the_content and absorbs attachment links, replaces them with a gallery * @author Leo Brown * */ function attachmentGalleryHook($content){ $manager=new AttachmentGalleryManager($options); $options = $manager->detect_gallery_options($content); if($options){ $gallery = $manager->get_attachment_gallery($content,$options); if($gallery){ return $manager->insert_gallery($content, $gallery); } } else return $content; } ?>