* @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 Gets a callable URL for a thumbnail of PDF etc * @author Leo Brown * @param * @return string The URL */ static function get_thumbnail_url($size, $local_url){ return WP_PLUGIN_URL.'/attachment-gallery/thumbnail.php?'. 'size='.$size. '&file='.$local_url; } /** * @desc Get shortcode options since we're retrofitting this and need to detect them later * @author Leo Brown * */ function thumbnailable_extensions(&$baseTypes){ $baseTypes[]='pdf'; return $baseTypes; } /** * @desc Get shortcode options since we're retrofitting this and need to detect them later * @author Leo Brown * */ function image_downsize($false, $id, $size=null){ // we're not doing this - hand back to Wordpress if(true){ // return image_downsize($id, $size); } // The original returns array( $img_url, $width, $height, $is_intermediate ); return array( AttachmentGalleryManager::get_thumbnail_url($size, wp_get_attachment_url($id)) ); } /** * @desc Get shortcode options since we're retrofitting this and need to detect them later * @author Leo Brown * */ function detect_gallery_options($content){ // get shortcode $shortcode=array(); $options=array(); if(preg_match("/{$this->marker}/", $content, $shortcode)){ // extract and use shortcode_parse_atts() to get the array $shortcode=reset($shortcode); preg_match('/\[[^ ]* (.*)\]/', $shortcode, $options); $options=shortcode_parse_atts(end($options)); return $options; } 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=array('size'=>'100x150')){ // get our attachments $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){ // downlaod links $linkize=($options['download'] && ('no'!==$options['download'])); // classes $class = ' '; if(@$options['grid']) $class.="attachment_gallery_grid"; // output gallery $html .= "
'; if(@$options['grid']) $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 preg_replace("/{$this->marker}/",$gallery,$page); } /** * @desc * @author Leo Brown * */ function find_attachment_links(&$input, $types){ // not yet used // 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