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 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; }