public static function update($values, $user) { $id = $values['id']; if ($id) { $q = new Doctrine_Query(); $q = $q->select('t.*')->from('Theme t'); $q = $q->addWhere('id = ?', array($id)); if (!$user->getRole() == User::ADMIN) { $q = $q->addWhere('user_id = ?', array($user->getId())); } $theme = $q->fetchOne(); } else { $theme = new Theme(); } if ($theme) { $theme->setName($values['name']); $theme->setDescription($values['description']); if (!$theme->getUserId()) { $theme->setUserId($user->getId()); } $file = $values['file']; if ($file) { $filename = $file->getOriginalName(); $theme->setFileName($filename); } $theme->setApproved(false); $theme->save(); $folderpath = $theme->getFolderPath(); if (!is_dir($folderpath)) { mkdir($folderpath); } if ($file) { $filepath = $folderpath . $theme->getFileName(); $file->save($filepath); } $screenshot = $values['screenshot']; if ($screenshot) { $screenshotpath = $folderpath . $theme->getId() . $screenshot->getOriginalName(); $screenshot->save($screenshotpath); $smallThumb = new Thumbnail($screenshotpath); if ($smallThumb->getCurrentWidth() > 150 || $smallThumb->getCurrentHeight() > 150) { $smallThumb->resize(150, 150); } $smallThumb->show(100, $folderpath . 'smallthumb.png'); $bigThumb = new Thumbnail($screenshotpath); if ($bigThumb->getCurrentWidth() > 500 || $bigThumb->getCurrentHeight() > 500) { $bigThumb->resize(500, 500); } $bigThumb->show(100, $folderpath . 'bigthumb.png'); $screenshot = new Thumbnail($screenshotpath); $screenshot->show(100, $folderpath . 'screenshot.png'); unlink($screenshotpath); } $outputs = array(); if ($file) { exec(Tools::get('edje_list_path') . ' ' . $filepath, $outputs); $groups = array_splice($outputs, 4); $groups = array_keys(array_flip($groups)); $name = substr($outputs[0], 6); if ($name) { $theme->setName($name); } $author = substr($outputs[1], 8); if ($author) { $theme->setAuthor($author); } $license = substr($outputs[2], 9); $theme->setLicense($license); $version = substr($outputs[3], 9); $theme->setVersion($version); $theme->save(); $theme->clearThemeGroups(); foreach ($groups as $group) { $theme->addThemeGroup($group); } } return $theme; } return null; }
function getImages($text, $thumb_size=70) { $matches = array(); preg_match("/\<img.+?src=\"(.+?)\".+?\/>/", $text, $matches); $images = new stdClass(); $images->image = false; $images->thumb = false; $paths = array(); if (isset($matches[1])) { $image_path = $matches[1]; //joomla 1.5 only $full_url = JURI::base(); //remove any protocol/site info from the image path $parsed_url = parse_url($full_url); $paths[] = $full_url; if (isset($parsed_url['path']) && $parsed_url['path'] != "/") $paths[] = $parsed_url['path']; foreach ($paths as $path) { if (strpos($image_path,$path) !== false) { $image_path = substr($image_path,strpos($image_path, $path)+strlen($path)); } } // remove any / that begins the path if (substr($image_path, 0 , 1) == '/') $image_path = substr($image_path, 1); //if after removing the uri, still has protocol then the image //is remote and we don't support thumbs for external images if (strpos($image_path,'http://') !== false || strpos($image_path,'https://') !== false) { return false; } $images->image = JURI::Root(True)."/".$image_path; // create a thumb filename $file_div = strrpos($image_path,'.'); $thumb_ext = substr($image_path, $file_div); $thumb_prev = substr($image_path, 0, $file_div); $thumb_path = $thumb_prev . "_thumb" . $thumb_ext; // check to see if this file exists, if so we don't need to create it if (function_exists("gd_info")) { // file doens't exist, so create it and save it if (!class_exists("Thumbnail")) include_once('thumbnail.inc.php'); if (file_exists($thumb_path)) { $existing_thumb = new Thumbnail($thumb_path); $images->size = $existing_thumb->currentDimensions; $current_size = $existing_thumb->getCurrentWidth(); } if (!file_exists($thumb_path) || $current_size!=$thumb_size) { $thumb = new Thumbnail($image_path); if ($thumb->error) { echo "ROKNEWSPAGER ERROR: " . $thumb->errmsg . ": " . $image_path; return false; } $thumb->resize($thumb_size); if (!is_writable(dirname($thumb_path))) { $thumb->destruct(); return false; } $images->size = $thumb->currentDimensions; $thumb->save($thumb_path); $thumb->destruct(); } } $images->thumb = $thumb_path; } return $images; }
function crop($imagePath, $thumbnailPath, $dimensions) { $crop = false; $newSize = trim(intval($dimensions[0])) > 0 ? trim(intval($dimensions[0])) : 100; $thumb = new Thumbnail($imagePath); if ($thumb->error) { echo $imagePath . ":" . $thumb->errmsg . "<br />"; return false; } $minLength = min($thumb->getCurrentWidth(), $thumb->getCurrentHeight()); $maxLength = max($thumb->getCurrentWidth(), $thumb->getCurrentHeight()); // Image is smaller than the specified size so we just rename it and save if ($maxLength <= $newSize) { $thumb->save($thumbnailPath, $this->quality); //Just rename and save without processing } else { // At least one side is larger than specified thumbnail size // Both sides are larger than resize length so first we scale and if image is not square we crop if ($minLength > $newSize) { // Scale smaller size to desired new size if ($thumb->getCurrentWidth() < $thumb->getCurrentHeight()) { $thumb->resize($newSize, 0); $crop = true; } elseif ($thumb->getCurrentWidth() > $thumb->getCurrentHeight()) { $thumb->resize(0, $newSize); $crop = true; } else { $thumb->resize($newSize, $newSize); } if ($crop) { $thumb->cropFromCenter($newSize); } // One size is smaller than the new size, so we only crop the larger size to the new size } else { $cropX = intval(($thumb->getCurrentWidth() - $newSize) / 2); $cropY = intval(($thumb->getCurrentHeight() - $newSize) / 2); $thumb->crop($cropX, $cropY, $newSize, $newSize); } $thumb->save($thumbnailPath, $this->quality); } $thumb->destruct(); if (file_exists($thumbnailPath)) { return true; } return false; }
public static function update($values, $user) { $id = $values['id']; if ($id) { $q = new Doctrine_Query(); $q = $q->select('m.*')->from('Madule m'); $q = $q->addWhere('id = ?', array($id)); if (!$user->getRole() == User::ADMIN) { $q = $q->addWhere('user_id = ?', array($user->getId())); } $module = $q->fetchOne(); } else { $module = new Madule(); } if ($module) { $module->setName($values['name']); $module->setDescription($values['description']); $module->setSourceUrl($values['source_url']); if (!$module->getUserId()) { $module->setUserId($user->getId()); } $module->setApplicationId($values['application_id']); $module->setApproved(false); $module->save(); $folderpath = $module->getFolderPath(); if (!is_dir($folderpath)) { mkdir($folderpath); } $screenshot = $values['screenshot']; if ($screenshot) { $screenshotpath = $folderpath . $module->getId() . $screenshot->getOriginalName(); $screenshot->save($screenshotpath); $smallThumb = new Thumbnail($screenshotpath); if ($smallThumb->getCurrentWidth() > 150 || $smallThumb->getCurrentHeight() > 150) { $smallThumb->resize(150, 150); } $smallThumb->show(100, $folderpath . 'smallthumb.png'); $bigThumb = new Thumbnail($screenshotpath); if ($bigThumb->getCurrentWidth() > 500 || $bigThumb->getCurrentHeight() > 500) { $bigThumb->resize(500, 500); } $bigThumb->show(100, $folderpath . 'bigthumb.png'); $screenshot = new Thumbnail($screenshotpath); $screenshot->show(100, $folderpath . 'screenshot.png'); unlink($screenshotpath); } return $module; } return null; }
function uploadImages($listing_id, $path) { $imgMaxWidth = $this->Config->content_max_imgwidth; $fileKeys = $this->fileKeys; $images = array(); // Load thumbnail library App::import('Vendor', 'thumbnail' . DS . 'thumbnail.inc'); foreach ($fileKeys as $key) { $tmp_name = $_FILES['image']['tmp_name'][$key]; $name = basename($_FILES['image']['name'][$key]); // Append datetime stamp to file name $nameArray = explode(".", $name); // Leave only valid characters $nameArray[count($nameArray) - 2] = preg_replace('/[^0-9a-z]+/i', '', $nameArray[count($nameArray) - 2]); $nameArray[count($nameArray) - 2] = preg_replace('/[^\\w\\d\\s]+/i', '', $nameArray[count($nameArray) - 2]); $nameArray[count($nameArray) - 2] = $nameArray[count($nameArray) - 2] . "_" . time(); // Prepend contentid $name = $listing_id . "_" . implode(".", $nameArray); $uploadfile = $path . $name; if (move_uploaded_file($tmp_name, $uploadfile)) { $images[] = "jreviews/" . $name . "|||0||bottom||"; chmod($uploadfile, 0644); // Begin image resizing if ($imgMaxWidth > 0) { $thumb = new Thumbnail($uploadfile); if ($thumb->getCurrentWidth() > $imgMaxWidth) { $thumb->resize($imgMaxWidth, $thumb->getCurrentHeight()); } $thumb->save($uploadfile); $thumb->destruct(); } } } $this->images = $images; }