/** * * @param $post * @return unknown_type * @todo anything in the html that has dodgy characters in it will make DOM unhappy. * Probably best to hold back errors. */ public static function AutoGenThumbs($post) { $tracker = OnePanelDebug::Track('Trying to autogenerate thumbnails.'); // Wordpress is crazy $post_id = wp_is_post_revision($post); OnePanelDebug::Info('Post id: ' . $post_id); // Create thumbnail module object? OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/module.php'); OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/feature.php'); OnePanelLib::RequireFileOnce(ONE_PANEL_DIR . '/panel/thumbnails.php'); $thumbnail_feature_object = new Thumbnails(); // Scan the post for images $dom_doc = new DOMDocument(); @$dom_doc->loadHTML($_POST['content']); // Grab the first image $first_image = $dom_doc->getElementsByTagName('img')->item(0); if (is_null($first_image)) { OnePanelDebug::Info('No images found in post'); return true; } // Get the location of the image $src = str_replace('"', '', $first_image->getAttribute('src')); $src = str_replace('\\', '', $src); // Get the real path $src = str_replace(get_option('siteurl'), '', $src); $location = ABSPATH . $src; $location = str_replace('//', '/', $location); // Generate OnePanelDebug::Info('Calling CreateThumbs with ' . $location . ' ' . $post_id); $thumbnail_feature_object->CreateThumbs($location, $post_id, 'All', false); // All done $tracker->Affirm(); return true; }
/** * Return thumbnail URL * * @param void * @return string */ function getThumbnailUrl() { $mime_type = $this->getMimeType(); $start = substr($mime_type, 0, strpos($mime_type, '/')); switch ($start) { case 'application': switch ($mime_type) { case 'application/x-diskcopy': return get_image_url('types/disk-image.gif'); case 'application/pdf': return get_image_url('types/document-pdf.gif'); default: $extension = strtolower(get_file_extension($this->getName())); if ($extension) { switch ($extension) { case 'psd': return get_image_url('types/document-psd.gif'); case 'ai': return get_image_url('types/document-ai.gif'); case 'fla': case 'flv': case 'swf': return get_image_url('types/document-fla.gif'); case 'doc': return get_image_url('types/document-doc.gif'); case 'xls': return get_image_url('types/document-xls.gif'); case 'ppt': return get_image_url('types/document-ppt.gif'); case 'zip': case 'gz': case 'tar': case 'rar': case 'ace': case '7z': case 'sit': return get_image_url('types/archive.gif'); } // switch } // if return get_image_url('types/blank.gif'); } // switch // switch case 'audio': return get_image_url('types/audio.gif'); case 'image': if (CREATE_THUMBNAILS && in_array($mime_type, array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png')) && filesize($this->getFilePath()) < RESIZE_SMALLER_THAN) { $thumbnail_path = Thumbnails::create($this->getFilePath(), $this->getId() . '-80x80', 80, 80); if ($thumbnail_path) { return Thumbnails::getUrl(basename($thumbnail_path)); } // if } // if return get_image_url('types/image.gif'); case 'text': return get_image_url('types/text.gif'); case 'video': return get_image_url('types/video.gif'); default: return get_image_url('types/blank.gif'); } // if }
/** * Return large preview URL * * @param void * @return string */ function getPreviewUrl() { if (CREATE_THUMBNAILS && $this->isImage() && filesize($this->getFilePath()) < RESIZE_SMALLER_THAN) { $preview_path = Thumbnails::create($this->getFilePath(), $this->getId() . '-735x500', 735, 500); if ($preview_path) { return Thumbnails::getUrl(basename($preview_path)); } // if } // if return ''; }