function _fixItem($item, $order = 'created desc, title') { // Return false if no item if (!$item) { return $item; } // Get the item indexes for the indicated weblog (cached to minimize the number of SQL queries) $cacheName = 'YD_CACHE_WEBLOG_ITEMIDS_' . md5(strtolower($order)); if (!isset($GLOBALS[$cacheName])) { $sql = $this->_prepareQuery('SELECT id FROM ' . YDConfig::get('db_prefix', '') . 'items', $order); $item_ids = $this->db->getValuesByName($sql, 'id'); $GLOBALS[$cacheName] = $item_ids; } // Get the ID of the previous and the next item $pos = array_search($item['id'], $GLOBALS[$cacheName]); $item['newer_id'] = $pos == 0 ? false : $GLOBALS[$cacheName][$pos - 1]; $item['older_id'] = $pos == sizeof($GLOBALS[$cacheName]) - 1 ? false : $GLOBALS[$cacheName][$pos + 1]; // Add the year, month and yearmonth fields $item['yearmonth'] = ucwords(strftime('%B %Y', $item['created'])); $item['month'] = ucwords(strftime('%B', $item['created'])); $item['year'] = ucwords(strftime('%Y', $item['created'])); // Get the list of images related to this item $imgPath = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/'; // Get the list of pictures if any if (is_dir($imgPath)) { // Get a handle to the directory $dir = new YDFSDirectory(dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/'); // Get the list of files $images = $dir->getContents(array('!index.html', '!index.php', '!m_*.*', '!s_*.*'), null, array('YDFSImage')); // Make the relative path for each file foreach ($images as $key => $image) { // Generate the thumbnails if not there yet if (!is_file($dir->getAbsolutePath() . '/s_' . $image->getBasename())) { $image->saveThumbnail(48, 48, $dir->getAbsolutePath() . '/s_' . $image->getBasename()); } if (!is_file($dir->getAbsolutePath() . '/m_' . $image->getBasename())) { $image->saveThumbnail(100, 100, $dir->getAbsolutePath() . '/m_' . $image->getBasename()); } // Set the relative path $dir_uploads = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads'); $dir_uploads = new YDFSDirectory($dir_uploads); $image->relative_path = str_replace($dir_uploads->getAbsolutePath(), '', $image->getAbsolutePath()); // Update the backslashes $image->relative_path = str_replace('\\', '/', $image->relative_path); // Remove the leading slash if (substr($image->relative_path, 0, 1) == '/') { $image->relative_path = substr($image->relative_path, 1); } // Make links to the thumbnails $image->relative_path_s = dirname($image->relative_path) . '/s_' . basename($image->relative_path); $image->relative_path_m = dirname($image->relative_path) . '/m_' . basename($image->relative_path); // Update the original image $images[$key] = $image; } // Add it to the item $item['images'] = $images; } else { // No images for this item $item['images'] = array(); } // Get the count of images $item['num_images'] = sizeof($item['images']); // Return the fixed item return $item; }
function _fixItem($item, $order = 'created desc, title') { // Return false if no item if (!$item) { return $item; } // Get the item indexes for the indicated weblog (cached to minimize the number of SQL queries) $cacheName = 'YD_CACHE_WEBLOG_ITEMIDS_' . md5(strtolower($order)); if (!isset($GLOBALS[$cacheName])) { $sql = $this->_prepareQuery('SELECT id FROM #_items', $order); $item_ids = $this->db->getValuesByName($sql, 'id'); $GLOBALS[$cacheName] = $item_ids; } // Get the ID of the previous and the next item $pos = array_search($item['id'], $GLOBALS[$cacheName]); $item['newer_id'] = $pos == 0 ? false : $GLOBALS[$cacheName][$pos - 1]; $item['older_id'] = $pos == sizeof($GLOBALS[$cacheName]) - 1 ? false : $GLOBALS[$cacheName][$pos + 1]; // Add the year, month and yearmonth fields $item['yearmonth'] = ucwords(strftime('%B %Y', $item['created'])); $item['month'] = ucwords(strftime('%B', $item['created'])); $item['year'] = ucwords(strftime('%Y', $item['created'])); // Get the list of images related to this item $imgPath = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/'; // Get the list of pictures if any if (is_dir($imgPath)) { // Get a handle to the directory $dir = new YDFSDirectory(dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads') . '/item_' . $item['id'] . '/'); // Get the list of files $images = $dir->getContents(array('!index.html', '!index.php', '!m_*.*', '!s_*.*'), null, array('YDFSImage')); // Make the relative path for each file foreach ($images as $key => $image) { // Generate the thumbnails if not there yet if (!is_file($dir->getAbsolutePath() . '/s_' . $image->getBasename())) { $image->saveThumbnail(48, 48, $dir->getAbsolutePath() . '/s_' . $image->getBasename()); } if (!is_file($dir->getAbsolutePath() . '/m_' . $image->getBasename())) { $image->saveThumbnail(100, 100, $dir->getAbsolutePath() . '/m_' . $image->getBasename()); } // Set the relative path $dir_uploads = dirname(__FILE__) . '/../' . YDConfig::get('dir_uploads', 'uploads'); $dir_uploads = new YDFSDirectory($dir_uploads); $image->relative_path = str_replace($dir_uploads->getAbsolutePath(), '', $image->getAbsolutePath()); // Update the backslashes $image->relative_path = ltrim(str_replace('\\', '/', $image->relative_path), '/'); // Merge the title and description if any $image = $this->getItemImageMetaData($image); // Create the full title, including item title, image title and description if any $image->full_description = $item['title'] . ' » ' . $image->title; if ($image->description) { $image->full_description .= '<p class="img_description">' . YDTemplate_modifier_bbcode($image->description) . '</p>'; } $image->full_description_html = htmlspecialchars($image->full_description, ENT_QUOTES); // Make links to the thumbnails $image->relative_path_s = dirname($image->relative_path) . '/s_' . basename($image->relative_path); $image->relative_path_m = dirname($image->relative_path) . '/m_' . basename($image->relative_path); // Add the thumbnails as objects $image->relative_path_s_obj = new YDFSImage($dir_uploads->getAbsolutePath() . '/' . $image->relative_path_s); $image->relative_path_m_obj = new YDFSImage($dir_uploads->getAbsolutePath() . '/' . $image->relative_path_m); // Update the original image $images[$key] = $image; } // Add it to the item $item['images'] = $images; } else { // No images for this item $item['images'] = array(); } // Fix the image paths if (strtolower(basename(dirname(YD_SELF_FILE))) != 'manage') { $uploads = YDConfig::get('dir_uploads', 'uploads'); $item['body'] = str_replace('../' . $uploads, $uploads, $item['body']); $item['body_more'] = str_replace('../' . $uploads, $uploads, $item['body_more']); } // Get the count of images $item['num_images'] = sizeof($item['images']); // Return the fixed item return $item; }
function getImages($as_class = true) { // Get the list of files $dir = new YDFSDirectory($this->dir_rel); $images = @$dir->getContents(array('!index.html', '!index.php'), null, array('YDFSImage'), true, 'desc'); // Make the relative path for each file foreach ($images as $key => $image) { // Set the relative path $image->relative_path = str_replace($dir->getAbsolutePath(), '', $image->getAbsolutePath()); // Update the backslashes $image->relative_path = str_replace('\\', '/', $image->relative_path); // Remove the leading slash if (substr($image->relative_path, 0, 1) == '/') { $image->relative_path = substr($image->relative_path, 1); } // Update the original image $images[$key] = $image; } // Convert to a plain array if needed if ($as_class === false) { foreach ($images as $key => $image) { $images[$key] = $image->relative_path; } } // Return the list return $images; }
/** * This function copies a directory or an array of directories from the * source directory to the target directory. * * @param $directories The directory name or an array of directories * relative to the source directory. * @param $overwrite (optional) If true, overwrite the files. Default: true. * @param $recursive (optional) Copies all subdirectories as well. Default: true. * * @returns An array with the results. */ function copyDirectory($directories, $overwrite = true, $recursive = true) { $res = array(); if (!is_array($directories)) { $directories = array($directories); } foreach ($directories as $directory) { // Source directory path $source = YDPath::join($this->_source_dir, $directory); // Target directory path $target = YDPath::join($this->_target_dir, $directory); // Source directory $d = new YDFSDirectory($source); // Source directory files $files = $d->getContents('', '', array('YDFSFile', 'YDFSImage')); foreach ($files as $k => $file) { $files[$k] = YDPath::join($directory, $file); } // Copy source directory files to target $res = array_merge($res, $this->copyFile($files, $overwrite)); if ($recursive) { // Get source subdirectories $dirs = $d->getContents('', '', 'YDFSDirectory'); // Cycle through all source subdirectories foreach ($dirs as $dir) { $res = array_merge($res, $this->copyDirectory(str_replace($this->_source_dir, '', YDPath::join($d->getAbsolutePath(), $dir)), $overwrite, $recursive)); } } } return $res; }