* @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']); // get metadata reader @include_once 'PDFMetaData.class.php'; if(class_exists('PDFMetaData')) $metaReader=new PDFMetaData(); // generate HTML for gallery $html=''; if($attachments){ $html .= '
'; } return $html; } /** * @desc Places items the cache * @author Leo Brown * */ function cache_set($key, $data){ return @file_put_contents( sys_get_temp_dir().'/attachment_cache_'. md5($key),serialize($data) ); } /** * @desc Accesses the cache * @author Leo Brown * */ function cache_get($key){ return @unserialize(@file_get_contents( sys_get_temp_dir(). '/attachment_cache_'.md5($key) )); } /** * @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,'|'); // our list of files $results=array(); // pattern for any link - hand written / may need to be modified $regexp = "]*href=(['\"]??)([^\" >]*)\\1[^>]*>(.*)<\/a>"; // process our matches if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) { foreach($matches as $match){ // storage for this result $result=array(); // known values $result['title']=$match[3]; $result['url'] =$match[2]; // test if is rel=attachment (regex from _fix_attachment_links in post.php) $search = "#[\s]+rel=(\"|')(.*?)wp-att-(?P