public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $datas = $datas['menus']; foreach ($datas as $product_id => $data) { $product = new Catalog_Model_Product(); if ($id = $this->getRequest()->getParam('id')) { $product->find($id); if ($product->getValueId() != $option_value->getId()) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!$product->getId()) { $product->setValueId($option_value->getId()); } $pos_datas = array(); if (!empty($data['pos'])) { foreach ($data['pos'] as $key => $pos_data) { $pos_datas[$key] = $pos_data; } } if (!empty($data['picture'])) { if (substr($data['picture'], 0, 1) == '/') { unset($data['picture']); } else { $illus_relative_path = '/feature/' . $option_value->getValueId() . '/'; $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $data['picture']; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!copy($file, $folder . $data['picture'])) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $data['picture'] = $illus_relative_path . $data['picture']; } } } $product->addData($data)->setType('menu'); $product->setPosDatas($pos_datas); $product->save(); } $html = array(); if (!$product->getData('is_deleted')) { $html['menu_id'] = $product->getId(); } $html['success'] = 1; $html['success_message'] = $this->_('Set meal successfully saved.'); $html['message_timeout'] = 2; $html['message_button'] = 0; $html['message_loader'] = 0; } catch (Exception $e) { $html = array('message' => $this->_('An error occurred while saving the set meal. Please try again later.')); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_('An error occurred while saving')); } if (empty($datas['title'])) { throw new Exception($this->_('Folder title is required')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $folder = new Folder_Model_Folder(); $category = new Folder_Model_Category(); if (!empty($datas['category_id'])) { $category->find($datas['category_id'], 'category_id'); } if ($datas['parent_id'] == 'null') { unset($datas['parent_id']); //Assigne le nom de catégorie root à la feature $option_value->setTabbarName($datas['title'])->save(); } else { $datas['pos'] = $category->getNextCategoryPosition($datas['parent_id']); } if (!empty($datas['file'])) { $relative_path = '/folder/'; $path = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file']; if (!is_dir($path)) { mkdir($path, 0777, true); } if (!copy($file, $path . $datas['file'])) { throw new exception($this->_('An error occurred while saving. Please try again later.')); } else { $datas['picture'] = $relative_path . $datas['file']; } } else { if (!empty($datas['remove_picture'])) { $datas['picture'] = null; } } $category->addData($datas)->save(); //Change root category if (!isset($datas['parent_id'])) { $folder->find($option_value->getId(), 'value_id'); $folder->setValueId($datas['value_id'])->setRootCategoryId($category->getId())->save(); $parent_id = 'null'; } else { $parent_id = $datas['parent_id']; } $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'category_id' => $category->getId(), 'parent_id' => $parent_id, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function uploadAction() { try { if (empty($_FILES) || empty($_FILES['module']['name'])) { throw new Exception("No file has been sent"); } $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true)); // $adapter->addValidator('MimeType', false, 'application/zip'); if ($adapter->receive()) { $file = $adapter->getFileInfo(); $parser = new Installer_Model_Installer_Module_Parser(); if ($parser->setFile($file['module']['tmp_name'])->check()) { $infos = pathinfo($file['module']['tmp_name']); $filename = $infos['filename']; $this->_redirect('installer/module/install', array('module_name' => $filename)); } else { $messages = $parser->getErrors(); $message = implode("\n", $messages); throw new Exception($this->_($message)); } } else { $messages = $adapter->getMessages(); if (!empty($messages)) { $message = implode("\n", $messages); } else { $message = $this->_("An error occurred during the process. Please try again later."); } throw new Exception($message); } } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); $this->_redirect('installer/module'); } }
public function uploadAction() { if ($app_id = $this->getRequest()->getParam("app_id")) { try { if (empty($_FILES) || empty($_FILES['file']['name'])) { throw new Exception("No file has been sent"); } $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true)); if ($adapter->receive()) { $file = $adapter->getFileInfo(); $data = array("success" => 1, "name" => $file["file"]["name"], "message" => $this->_("The file has been successfully uploaded")); } else { $messages = $adapter->getMessages(); if (!empty($messages)) { $message = implode("\n", $messages); } else { $message = $this->_("An error occurred during the process. Please try again later."); } throw new Exception($message); } } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
public function savecrop($params = array()) { $temp = Core_Model_Directory::getTmpDirectory(true) . '/'; $file = $temp . $params['file']; $source_width = $params['source_width']; $source_height = $params['source_height']; $crop_width = $params['crop_width']; $crop_height = $params['crop_height']; $targ_w = $params['output_width']; $targ_h = $params['output_height']; $quality = !empty($params['quality']) ? $params['quality'] : 90; $folder = $temp; if (isset($params['dest_folder'])) { $folder = $params['dest_folder']; } if (!is_dir($folder)) { mkdir($folder, 0777, true); } $source = imagecreatefromstring(file_get_contents($file)); $dest = imagecreatetruecolor($targ_w, $targ_h); $trans_colour = imagecolorallocatealpha($source, 0, 0, 0, 127); $format = pathinfo($file, PATHINFO_EXTENSION); $dst_x = 0; $dst_y = 0; $src_x = $params['x1'] * $source_width / $crop_width; $src_y = $params['y1'] * $source_height / $crop_height; $dst_w = $targ_w; $dst_h = $targ_h; $src_w = $params['w'] * $source_width / $crop_width; $src_h = $params['h'] * $source_height / $crop_height; imagealphablending($dest, false); imagefill($dest, 0, 0, $trans_colour); imagecopyresampled($dest, $source, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagesavealpha($dest, true); if (!in_array($format, array("png", "jpg", "jpeg", "gif"))) { $format = "jpg"; } if (empty($params['ext'])) { $params['ext'] = $format; } $new_name = uniqid() . '.' . $params['ext']; if (isset($params['new_name'])) { $new_name = $params['new_name']; } if (in_array($params['ext'], array('jpg', 'jpeg'))) { imagejpeg($dest, $folder . $new_name, $quality); } else { if ($params['ext'] == 'png') { imagepng($dest, $folder . $new_name); } else { if ($params['ext'] == 'gif') { imagegif($dest, $folder . $new_name); } } } return $new_name; }
public function colorize1Action() { if ($this->getRequest()->getParam('id') || $this->getRequest()->getParam('url') || $this->getRequest()->getParam('path') and $color = $this->getRequest()->getParam('color')) { $cache = Zend_Registry::get('cache'); $id = $this->getRequest()->getParam('id'); // $cache_id = 'colorized_image_'.sha1($id.':'.$color); // $cache->remove($cache_id); // $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('colorized_image'));die; // if (($img = $cache->load($cache_id)) === false) { if ($this->getRequest()->getParam('id')) { $image = new Media_Model_Library_Image(); $image->find($id); $path = $image->getLink(); $image_path = Media_Model_Library_Image::getBaseImagePathTo($path); } else { if ($this->getRequest()->getParam('url')) { $url = $this->getRequest()->getParam('url'); $path = Core_Model_Directory::getTmpDirectory(true) . '/' . $url; $image_path = $path; } else { if ($this->getRequest()->getParam('path')) { $path = $this->getRequest()->getParam('path'); $path = Core_Model_Directory::getBasePathTo(base64_decode($path)); if (!is_file($path)) { die; } $image_path = $path; } } } $color = $color; $rgb = $this->toRgb($color); list($width, $height) = getimagesize($image_path); $new_img = imagecreatefromstring(file_get_contents($image_path)); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $colors = imagecolorat($new_img, $x, $y); $current_rgb = imagecolorsforindex($new_img, $colors); $color = imagecolorallocatealpha($new_img, $rgb['red'], $rgb['green'], $rgb['blue'], $current_rgb['alpha']); imagesetpixel($new_img, $x, $y, $color); } } imagesavealpha($new_img, true); ob_start(); @imagepng($new_img); $contents = ob_get_contents(); ob_end_clean(); imagedestroy($new_img); // $cache->save($contents, $cache_id, array('colorized_image')); $img = $contents; // } // Zend_Debug::dump($img); die; $this->getResponse()->setHeader('Content-Type', 'image/png'); $this->getLayout()->setHtml($img); die; } }
public function extract() { $tmp_dir = Core_Model_Directory::getTmpDirectory(true) . '/'; if (!is_writable($tmp_dir)) { throw new Exception($this->_("The folder %s is not writable. Please fix this issue and try again.", $tmp_dir)); } else { if (is_dir($this->_tmp_directory)) { Core_Model_Directory::delete($this->_tmp_directory); } mkdir($this->_tmp_directory, 0777); exec('unzip "' . $this->_tmp_file . '" -d "' . $this->_tmp_directory . '" 2>&1', $output); if (!count(glob($this->_tmp_directory))) { throw new Exception($this->_("Unable to extract the archive. Please make sure that the 'zip' extension is installed.")); } exec('unzip "' . $this->_tmp_file . '" -d "' . $this->_tmp_directory . '" 2>&1', $output); $base_path = $this->_tmp_directory . "/app/modules/Template/db"; if (file_exists("{$base_path}/database.template.php")) { $template = new Installer_Model_Installer_Module(); $template->find("Template", "name"); $tmp_new_version = explode(".", $template->getVersion()); if (count($tmp_new_version) > 3) { $version = "{$tmp_new_version[0]}.{$tmp_new_version[1]}.{$tmp_new_version[2]}." . ($tmp_new_version[3] + 1); } else { $version = "{$template->getVersion()}.1"; } $file = "database.{$version}.php"; rename("{$base_path}/database.template.php", "{$base_path}/{$file}"); } return $this->_tmp_directory; } /* $zip = new ZipArchive(); if($zip->open($this->_tmp_file)) { $tmp_dir = Core_Model_Directory::getTmpDirectory(true).'/'; if(!is_writable($tmp_dir)) { throw new Exception($this->_("The folder %s is not writable. Please fix this issue and try again.", $tmp_dir)); } else { if(is_dir($this->_tmp_directory)) { Core_Model_Directory::delete($this->_tmp_directory); } mkdir($this->_tmp_directory, 0777); if($zip->extractTo($this->_tmp_directory)) { $zip->close(); return $this->_tmp_directory; } else { throw new Exception($this->_("Unable to open the file. Please, make sure that you sent a valid archive.")); } } } else { throw new Exception($this->_("Unable to open the archive.")); } */ }
/** * @usage Zend_Debug::dump($this->getUrl('front/image/crop', array( 'image' => base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/11/fitness.jpg'), 'width' => 640, 'height' => 400 ))); */ public function cropAction() { $datas = $this->getRequest()->getParams(); $default_url = ''; try { if (!empty($datas['image'])) { $default_url = $datas['image']; } else { die; } if (empty($datas['width']) or empty($datas['height'])) { throw new Exception(''); } $image = base64_decode($datas['image']); $expected_width = $datas['width']; $expected_height = $datas['height']; $this->_setFileType($image); $image_id = 'wordpress_image_' . sha1($image) . '-' . $expected_width . 'x' . $expected_height; $tmp_file = Core_Model_Directory::getTmpDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; if (!is_dir(Core_Model_Directory::getImageCacheDirectory(true))) { mkdir(Core_Model_Directory::getImageCacheDirectory(true), 0777); } $dest_file = Core_Model_Directory::getImageCacheDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; // if(file_exists($dest_file)) unlink($dest_file); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { $image_url = $datas['image']; $new_img = imagecreatefromstring(file_get_contents($image)); $this->_saveImage($new_img, $tmp_file); imagedestroy($new_img); list($width, $height) = getimagesize($tmp_file); $new_width = $width; $new_height = $height; $ratio_width = $expected_width / $width; $ratio_height = $expected_height / $height; if ($ratio_height > $ratio_width) { $new_width *= $ratio_height; $new_height *= $ratio_height; } else { $new_width *= $ratio_width; $new_height *= $ratio_width; } Thumbnailer_CreateThumb::createThumbnail($tmp_file, $dest_file, $new_width, $new_height, $this->_image_ext, false, array('resizeUp' => true)); Thumbnailer_CreateThumb::crop($dest_file, $dest_file, 0, 0, $expected_width, $expected_height, true); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { throw new Exception(''); } } $image_url = $dest_file; } catch (Exception $e) { $image_url = ''; } if (!empty($image_url)) { $this->_showImage($image_url); } die; }
public function editpostAction() { if ($data = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($data['value_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($data['value_id']); $html = ''; $contact = new Contact_Model_Contact(); $contact->find($option_value->getId(), 'value_id'); if (!empty($data['file'])) { $file = pathinfo($data['file']); $filename = $file['basename']; $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try again later.')); } else { $data['cover'] = $relative_path . '/' . $filename; } } else { if (!empty($data['remove_cover'])) { $data['cover'] = null; } } $contact->setData($data); if ($contact->getStreet() and $contact->getPostcode() and $contact->getCity()) { $latlon = Siberian_Google_Geocoding::getLatLng(array("street" => $contact->getStreet(), "postcode" => $contact->getPostcode(), "city" => $contact->getCity())); if (!empty($latlon[0]) && !empty($latlon[1])) { $contact->setLatitude($latlon[0])->setLongitude($latlon[1]); } } else { $contact->setLatitude(null)->setLongitude(null); } $contact->save(); $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['agenda_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $event = new Event_Model_Event_Custom(); $option_value = $this->getCurrentOptionValue(); $data = array(); if (!empty($datas['id'])) { $event->find($datas['id']); if ($event->getAgendaId() != $datas['agenda_id']) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!empty($datas['picture'])) { if (substr($datas['picture'], 0, 1) == '/') { unset($datas['picture']); } else { $application = $this->getApplication(); $illus_relative_path = '/feature/' . $option_value->getId() . '/'; $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['picture']; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!copy($file, $folder . $datas['picture'])) { throw new exception($this->_("An error occurred while saving your picture. Please try againg later.")); } else { $datas['picture'] = $illus_relative_path . $datas['picture']; } } } else { $datas['picture'] = null; } if (!empty($datas['rsvp']) and stripos($datas['rsvp'], 'http') === false) { $datas['rsvp'] = 'http://' . $datas['rsvp']; } $event->addData($datas)->save(); $cache = Zend_Registry::get('cache'); $cache->remove($option_value->getObject()->getCacheId()); $html = array('success' => '1', 'success_message' => $this->_("Event successfully saved"), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostcategoryAction() { if ($data = $this->getRequest()->getPost()) { try { $isNew = false; if (!$data["category_id"]) { $isNew = true; $topic = new Topic_Model_Topic(); $topic->find(array("value_id" => $this->getCurrentOptionValue()->getValueId())); if (!$topic->getId()) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $category = new Topic_Model_Category(); $position = $category->getMaxPosition($topic->getId()); $data["position"] = $position ? $position + 1 : 1; $data["topic_id"] = $topic->getId(); } else { $category = new Topic_Model_Category($data["category_id"]); } if (!empty($data["file"])) { $picture = $data["file"]; $relative_path = '/features/topic/'; $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $path = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $picture; if (file_exists($file)) { if (!is_dir($path)) { mkdir($path, 0777, true); } if (!copy($file, $folder . $picture)) { throw new exception($this->_('An error occurred while saving. Please try again later.')); } else { $data['picture'] = $relative_path . $picture; } } } if ($data["remove_picture"]) { $data['picture'] = null; } $category->addData($data)->save(); $html = array('is_new' => (int) $isNew, 'category_id' => $category->getId(), 'category_label' => $category->getName(), 'success' => '1', 'success_message' => $this->_('Category successfully saved.'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); if ($isNew) { $html['row_html'] = $this->getLayout()->addPartial('child_' . $category->getId(), 'admin_view_default', 'topic/application/edit/list.phtml')->setCategory($category)->toHtml(); } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->_sendHtml($html); } }
public function cropAction() { $picture = $this->getRequest()->getParam('picture'); $image_sizes = getimagesize(Core_Model_Directory::getTmpDirectory(true) . '/' . $picture); $option_value_id = ''; $is_colorizable = false; if ($this->getRequest()->getParam('option_value_id')) { $option_value_id = $this->getRequest()->getParam('option_value_id'); } if ($this->getRequest()->getParam('is_colorizable')) { $is_colorizable = $this->getRequest()->getParam('is_colorizable'); } $html = $this->getLayout()->addPartial('crop', 'core_view_default', 'page/layout/crop.phtml')->setPicture($picture)->setWidth($image_sizes[0])->setHeight($image_sizes[1])->setOutputWidth($this->getRequest()->getParam('outputWidth'))->setOutputHeight($this->getRequest()->getParam('outputHeight'))->setOutputUrl($this->getRequest()->getParam('outputUrl'))->setQuality($this->getRequest()->getParam('quality'))->setUploader($this->getRequest()->getParam('uploader'))->setOptionId($option_value_id)->setIsColorizable($is_colorizable)->setImageColor($this->getRequest()->getParam('image_color'))->toHtml(); $this->getLayout()->setHtml($html); }
public function saveFile($file) { $path = Core_Model_Directory::getTmpDirectory(true) . "/" . $file; $new_name = null; if (file_exists($path)) { $path_parts = pathinfo($path); $extension = $path_parts["extension"]; $new_name = uniqid() . "." . $extension; $base_path = Core_Model_Directory::getBasePathTo("images/application/" . $this->getAppId() . "/messages/"); if (!dir($base_path)) { mkdir($base_path, 0777, true); } rename($path, $base_path . $new_name); $message_file = new Message_Model_Application_File(); $message_file->setMessageId($this->getId())->setFile($new_name)->save(); } return $new_name; }
public function colorizeAction() { if ($this->getRequest()->getParam('id') || $this->getRequest()->getParam('url') || $this->getRequest()->getParam('path') and $color = $this->getRequest()->getParam('color')) { $params = array('id', 'url', 'path', 'color'); $path = ''; foreach ($params as $param) { $id[] = $this->getRequest()->getParam($param); } $id = md5(implode('+', $id)); if ($image_id = $this->getRequest()->getParam('id')) { $image = new Media_Model_Library_Image(); $image->find($image_id); if (!$image->getCanBeColorized()) { $color = null; } $path = $image->getLink(); $path = Media_Model_Library_Image::getBaseImagePathTo($path, $image->getAppId()); } else { if ($url = $this->getRequest()->getParam('url')) { $path = Core_Model_Directory::getTmpDirectory(true) . '/' . $url; } else { if ($path = $this->getRequest()->getParam('path')) { $path = base64_decode($path); if (!Zend_Uri::check($path)) { $path = Core_Model_Directory::getBasePathTo($path); if (!is_file($path)) { die; } } } } } $image = new Core_Model_Lib_Image(); $image->setId($id)->setPath($path)->setColor($color)->colorize(); ob_start(); @imagepng($image->getResources()); $contents = ob_get_contents(); ob_end_clean(); imagedestroy($image->getResources()); $this->getResponse()->setHeader('Content-Type', 'image/png'); $this->getLayout()->setHtml($contents); } }
public function editpostAction() { $html = ''; if ($datas = $this->getRequest()->getPost()) { try { if (!empty($datas['text'])) { $comment = new Comment_Model_Comment(); $img_src = Core_Model_Directory::getTmpDirectory(true) . '/'; $image = ''; if (empty($datas['image'])) { $datas['image'] = null; } else { if (file_exists($img_src . $datas['image'])) { $img_src = $img_src . $datas['image']; $relativePath = '/feature/' . $this->getCurrentOptionValue()->getId(); $img_dst = Application_Model_Application::getBaseImagePath() . $relativePath; if (!is_dir($img_dst)) { mkdir($img_dst, 0777, true); } $img_dst .= '/' . $datas['image']; @rename($img_src, $img_dst); if (!file_exists($img_dst)) { throw new Exception($this->_('An error occurred while saving your picture. Please try againg later.')); } $datas['image'] = $relativePath . '/' . $datas['image']; $image = Application_Model_Application::getImagePath() . '/'; $image .= $datas['image']; } } $comment->setData($datas)->save(); $url = array('comment/admin/edit'); if ($pos_id) { $url[] = 'pos_id/' . $pos_id; } $html = array('success' => '1', 'success_message' => $this->_('Information successfully saved'), 'image' => $image, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_('An error occurred while saving your contact informations.')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $html = ''; $contact = new Contact_Model_Contact(); $contact->find($option_value->getId(), 'value_id'); if (!empty($datas['file'])) { $relative_path = '/contact/cover/'; $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file']; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!copy($file, $folder . $datas['file'])) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $datas['cover'] = $relative_path . $datas['file']; } } else { if (!empty($datas['remove_cover'])) { $datas['cover'] = null; } } $contact->setData($datas)->save(); $html = array('success' => '1', 'success_message' => $this->_('Informations successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function savecrop($params = array()) { $temp = Core_Model_Directory::getTmpDirectory(true) . '/'; $file = $temp . $params['file']; $source_width = $params['source_width']; $source_height = $params['source_height']; $crop_width = $params['crop_width']; $crop_height = $params['crop_height']; $targ_w = $params['output_width']; $targ_h = $params['output_height']; $folder = $temp; if (isset($params['dest_folder'])) { $folder = $params['dest_folder']; } if (!is_dir($folder)) { mkdir($folder, 0777, true); } $source = imagecreatefromstring(file_get_contents($file)); $dest = imagecreatetruecolor($targ_w, $targ_h); $trans_colour = imagecolorallocatealpha($source, 0, 0, 0, 127); $dst_x = 0; $dst_y = 0; $src_x = $params['x1'] * $source_width / $crop_width; $src_y = $params['y1'] * $source_height / $crop_height; $dst_w = $targ_w; $dst_h = $targ_h; $src_w = $params['w'] * $source_width / $crop_width; $src_h = $params['h'] * $source_height / $crop_height; imagealphablending($dest, false); imagefill($dest, 0, 0, $trans_colour); imagecopyresampled($dest, $source, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagesavealpha($dest, true); $new_name = uniqid() . '.png'; if (isset($params['new_name'])) { $new_name = $params['new_name']; } imagepng($dest, $folder . $new_name); return $new_name; }
protected function _extract() { $zip = new ZipArchive(); if ($zip->open($this->_tmp_file)) { $tmp_dir = Core_Model_Directory::getTmpDirectory(true) . '/'; if (!is_writable($tmp_dir)) { $this->_addError($this->_("The folder %s is not writable. Please fix this issue and try again.", $tmp_dir)); } else { if (is_dir($this->_tmp_directory)) { $this->_removeTmpDirectory($this->_tmp_directory); } mkdir($this->_tmp_directory, 0777); if ($zip->extractTo($tmp_dir . $this->_module_name)) { return true; } else { $this->_addError($this->_("Unable to extract the archive.")); } $zip->close(); } } else { $this->_addError($this->_("Unable to open the archive.")); } return false; }
public function editAction() { if ($datas = $this->getRequest()->getPost()) { try { $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['agenda_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $event = new Event_Model_Event_Custom(); $option_value = $this->getCurrentOptionValue(); $data = array(); if (!empty($datas['id'])) { $event->find($datas['id']); if ($event->getAgendaId() != $datas['agenda_id']) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!empty($datas['picture'])) { $filename = $datas['picture']; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (file_exists($img_src)) { $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_("An error occurred while saving your picture. Please try againg later.")); } else { $datas['picture'] = $relative_path . '/' . $filename; } } else { unset($data['picture']); } } else { $datas['picture'] = null; } foreach (array("rsvp", "ticket_shop_url", "location_url") as $url_type) { if (!empty($datas[$url_type]) and stripos($datas[$url_type], 'http') === false) { $datas[$url_type] = 'http://' . $datas[$url_type]; } } if (!empty($datas["websites"]) and is_array($datas["websites"])) { $websites = array(); $cpt = 0; foreach ($datas["websites"] as $website) { if (empty($website["label"]) or empty($website["url"])) { continue; } if (stripos($website["url"], 'http') === false) { $website["url"] = 'http://' . $website["url"]; } $websites[++$cpt] = $website; } $datas["websites"] = Zend_Json::encode($websites); } else { $datas["websites"] = null; } $event->addData($datas)->save(); $cache = Zend_Registry::get('cache'); $cache->remove($option_value->getObject()->getCacheId()); $html = array('success' => '1', 'success_message' => $this->_("Event successfully saved"), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostAction() { if ($data = $this->getRequest()->getPost()) { $html = ''; try { // Test s'il y a un value_id if (empty($data['value_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($data['value_id']); // Instancie une nouvelle promotion $promotion = new Promotion_Model_Promotion(); // Test si l'option des réductions spéciales est activée et payée if ($id = $this->getRequest()->getParam('id')) { $promotion->find($id); if ($promotion->getValueId() and $promotion->getValueId() != $option_value->getId()) { throw new Exception('An error occurred while saving. Please try again later.'); } } //Vérifs champs if (empty($data['title']) || empty($data['description']) || empty($data['title'])) { throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields')); } if (!isset($data['is_illimited']) && empty($data['end_at'])) { throw new Exception($this->_('An error occurred while saving your discount. Please fill in all fields')); } if (!empty($data['end_at'])) { $date_actuelle = new Zend_Date(); $date_modif = new Zend_Date($data['end_at'], 'y-MM-dd'); if ($date_modif < $date_actuelle) { throw new Exception($this->_('Please select an end date greater than the current date.')); die; } } if (!empty($data['is_illimited'])) { $data['end_at'] = null; } $data['force_validation'] = !empty($data['force_validation']); $data['is_unique'] = !empty($data['is_unique']); $data['owner'] = 1; if (isset($data['available_for']) and $data['available_for'] == 'all') { $promotion->resetConditions(); } if (!empty($data['picture'])) { $filename = pathinfo($data['picture'], PATHINFO_BASENAME); $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try again later.')); } else { $data['picture'] = $relative_path . '/' . $filename; } } else { if (!empty($data['remove_cover'])) { $data['picture'] = null; } } $promotion->setData($data); $promotion->save(); if (!empty($data['unlock_code'])) { $dir_image = Core_Model_Directory::getBasePathTo("/images/application/" . $this->getApplication()->getId()); if (!is_dir($dir_image)) { mkdir($dir_image, 0775, true); } if (!is_dir($dir_image . "/application")) { mkdir($dir_image . "/application", 0775, true); } if (!is_dir($dir_image . "/application/qrpromotion")) { mkdir($dir_image . "/application/qrpromotion", 0775, true); } $dir_image .= "/application/qrpromotion/"; $image_name = $promotion->getId() . "-qrpromotion_qrcode.png"; copy('http://api.qrserver.com/v1/create-qr-code/?color=000000&bgcolor=FFFFFF&data=sendback%3A' . $data["unlock_code"] . '&qzone=1&margin=0&size=200x200&ecc=L', $dir_image . $image_name); } $html = array('promotion_id' => $promotion->getId(), 'success_message' => $this->_('Discount successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'url' => '/promotion/admin/list'); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $isNew = false; $application = $this->getApplication(); // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $html = array('success' => '1', 'success_message' => $this->_('Link has been successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); // Prépare la weblink $weblink = $option_value->getObject(); if (!$weblink->getId()) { $weblink->setValueId($datas['value_id']); } // S'il y a une cover image if (!empty($datas['file'])) { if (!empty($datas['file'])) { $relative_path = '/weblink/cover/'; $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $path = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file']; if (!is_dir($path)) { mkdir($path, 0777, true); } if (!copy($file, $folder . $datas['file'])) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $weblink->setCover($relative_path . $datas['file']); } if (empty($datas['link'])) { $html['success_message'] = $this->_("The image has been successfully saved"); } } } else { if (!empty($datas['remove_cover'])) { $weblink->setCover(null); if (empty($datas['link'])) { $html['success_message'] = $this->_("The image has been successfully deleted"); } } } // Sauvegarde le weblink $weblink->save(); if (!empty($datas['link'])) { $link_datas = $datas['link']; if (empty($link_datas['url']) or !Zend_Uri::check($link_datas['url'])) { throw new Exception($this->_('Please enter a valid url')); } // Prépare le link $link = new Weblink_Model_Weblink_Link(); if (!empty($link_datas['link_id'])) { $link->find($link_datas['link_id']); } $isNew = !$link->getId(); $link_datas['weblink_id'] = $weblink->getId(); // Test s'il y a un picto if (!empty($link_datas['picto']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'])) { $relative_path = '/pictos/'; $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $path = Application_Model_Application::getBaseImagePath() . $relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto']; if (!is_dir($path)) { mkdir($path, 0777, true); } if (!copy($file, $folder . $link_datas['picto'])) { throw new exception($this->_("An error occurred while saving your picto. Please try againg later.")); } else { $link_datas['picto'] = $relative_path . $link_datas['picto']; } } // Sauvegarde le link $link->addData($link_datas)->save(); if ($link->getIsDeleted()) { $html['success_message'] = $this->_('Link has been successfully deleted'); $html['is_deleted'] = 1; } } if ($isNew) { $html['row_html'] = $this->getLayout()->addPartial('row_', 'admin_view_default', 'weblink/application/multi/edit/row.phtml')->setCurrentLink($link)->setCurrentOptionValue($option_value)->toHtml(); } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function uploadiconAction() { if ($datas = $this->getRequest()->getPost()) { try { $uploader = new Core_Model_Lib_Uploader(); $file = $uploader->savecrop($datas); if (!empty($file)) { $option_value = new Application_Model_Option_Value(); $option_value->find($datas['option_id']); $lib = new Media_Model_Library(); $lib->find($option_value->getLibraryId()); $library_name = $lib->getName(); $formated_library_name = Core_Model_Lib_String::format($library_name, true); $base_lib_path = Media_Model_Library_Image::getBaseImagePathTo($formated_library_name); $files = Core_Model_Directory::getTmpDirectory(true) . '/' . $file; $CanBeColorized = $datas['is_colorized'] == 'true' ? 1 : 0; if (!is_dir($base_lib_path)) { mkdir($base_lib_path, 0777, true); } if (!copy($files, $base_lib_path . '/' . $file)) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $icon_lib = new Media_Model_Library_Image(); $icon_lib->setLibraryId($option_value->getLibraryId())->setLink('/' . $formated_library_name . '/' . $file)->setOptionId($option_value->getOptionId())->setAdminId($this->getSession()->getAdmin()->getId())->setCanBeColorized($CanBeColorized)->setPosition(0)->save(); $option_value->setIcon('/' . $formated_library_name . '/' . $file)->setIconId($icon_lib->getImageId())->save(); $icon_saved = $this->setIcon($icon_lib->getImageId(), $datas['option_id']); // Charge l'option_value $option_value = new Application_Model_Option_Value(); $option_value->find($datas['option_id']); $icon_color = $this->getApplication()->getDesignBlock('tabbar')->getImageColor(); $html = array('success' => 1, 'file' => '/' . $formated_library_name . '/' . $file, 'icon_id' => $icon_lib->getImageId(), 'colorizable' => $CanBeColorized, 'icon_url' => Media_Model_Library_Image::getImagePathTo($formated_library_name . '/' . $file), 'colored_icon_url' => $this->getUrl('template/block/colorize', array('id' => $option_value->getIconId(), 'color' => str_replace('#', '', $icon_color))), 'colored_header_icon_url' => $icon_saved['colored_header_icon_url'], 'message' => '', 'message_button' => 1, 'message_loader' => 1); } } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
/** * @usage Zend_Debug::dump($this->getUrl('front/image/crop', array( 'image' => base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/11/fitness.jpg'), 'width' => 640, 'height' => 400 ))); */ public function cropAction() { // Zend_Debug::dump(base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/09/fitness1.jpg')); // die; // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvZml0bmVzczEuanBn // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvZml0bmVzcy1oZi5qcGc // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvQnJhZC1QaXR0LUZpZ2h0LUNsdWItMy5qcGc $datas = $this->getRequest()->getParams(); $default_url = ''; try { if (!empty($datas['image'])) { $default_url = $datas['image']; } else { die; } if (empty($datas['width']) or empty($datas['height'])) { throw new Exception(''); } $image = base64_decode($datas['image']); $expected_width = $datas['width']; $expected_height = $datas['height']; $this->_setFileType($image); $image_id = 'wordpress_image_' . sha1($image) . '-' . $expected_width . 'x' . $expected_height; $tmp_file = Core_Model_Directory::getTmpDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; if (!is_dir(Core_Model_Directory::getImageCacheDirectory(true))) { mkdir(Core_Model_Directory::getImageCacheDirectory(true), 0777); } $image_path = Core_Model_Directory::getImageCacheDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; $dest_file = Core_Model_Directory::getBasePathTo($image_path); // if(file_exists($dest_file)) unlink($dest_file); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { $image_url = $datas['image']; $new_img = imagecreatefromstring(file_get_contents($image)); $this->_saveImage($new_img, $tmp_file); imagedestroy($new_img); list($width, $height) = getimagesize($tmp_file); $new_width = $width; $new_height = $height; $ratio_width = $expected_width / $width; $ratio_height = $expected_height / $height; if ($ratio_height > $ratio_width) { $new_width *= $ratio_height; $new_height *= $ratio_height; } else { $new_width *= $ratio_width; $new_height *= $ratio_width; } Thumbnailer_CreateThumb::createThumbnail($tmp_file, $dest_file, $new_width, $new_height, $this->_image_ext, false, array('resizeUp' => true)); Thumbnailer_CreateThumb::crop($dest_file, $dest_file, 0, 0, $expected_width, $expected_height, true); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { throw new Exception(''); } } $image_url = $dest_file; } catch (Exception $e) { $image_url = ''; } if (!empty($image_url)) { $this->_showImage($image_url); } die; }
public function editpostAction() { if ($data = $this->getRequest()->getPost()) { try { if (empty($data['value_id'])) { throw new Exception($this->_('An error occurred while saving the product. Please try again later.')); } $option_value = new Application_Model_Option_Value(); $option_value->find($data['value_id']); $html = array(); $product = new Catalog_Model_Product(); if (!empty($data['product_id'])) { $product->find($data['product_id']); } $isNew = (bool) (!$product->getId()); $isDeleted = !empty($data['is_deleted']); if ($product->getId() and $product->getValueId() != $option_value->getId()) { throw new Exception($this->_('An error occurred while saving the product. Please try again later.')); } if (!$isDeleted) { if (!isset($data['is_active'])) { $data['is_active'] = 1; } $data['value_id'] = $option_value->getValueId(); $parent_id = $data['category_id']; if (!empty($data['subcategory_id'])) { $data['category_id'] = $data['subcategory_id']; } if (!empty($data['picture'])) { if (!file_exists(Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture'])) { unset($data['picture']); } else { $illus_relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = pathinfo(Core_Model_Directory::getBasePathTo($data['picture'])); $filename = $file['basename']; $img_src = Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture']; $img_dst = $folder . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $data['picture'] = $illus_relative_path . '/' . $filename; } } } } if (!$product->getId() and empty($data['is_multiple']) or $product->getId() and $product->getData('type') != 'format' and isset($data['option'])) { unset($data['option']); } $product->addData($data); $product->save(); $html = array('success' => 1); if (!$isDeleted) { $product_id = $product->getId(); $product = new Catalog_Model_Product(); $product->find($product_id); $html = array('success' => 1, 'product_id' => $product->getId(), 'parent_id' => $parent_id, 'category_id' => $data['category_id']); $html['product_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category/product.phtml')->setProduct($product)->setOptionValue($option_value)->toHtml(); } } catch (Exception $e) { $html['message'] = $e->getMessage(); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { $html = ''; try { // Test s'il y a un value_id if (empty($datas['value_id'])) { throw new Exception($this->_("An error occurred while saving your images gallery. Please try again later.")); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $isNew = true; $save = true; $image = new Media_Model_Gallery_Image(); if (!empty($datas['id'])) { $image->find($datas['id']); $isNew = false; $id = $datas['id']; } else { $id = 'new'; $datas['value_id'] = $option_value->getId(); } if ($image->getId() and $image->getValueId() != $option_value->getId()) { throw new Exception("An error occurred while saving your images gallery. Please try again later."); } if (!empty($datas['param_instagram'])) { $instagram = new Media_Model_Gallery_Image_Instagram(); $userId = $instagram->getUserId($datas['param_instagram']); if (!$userId) { throw new Exception($this->_("The entered name is not a valid Instagram user.")); } $datas['type_id'] = 'instagram'; } elseif (!empty($datas['param'])) { $datas['type_id'] = 'picasa'; } else { $datas['type_id'] = 'custom'; } $html = array('success' => 1, 'is_new' => (int) $isNew); if (empty($datas['type_id']) or $datas['type_id'] == 'picasa') { $image->setTypeId('picasa'); $image->getTypeInstance()->setParam($datas['param']); if (empty($datas['album_id'])) { $albums = $image->getTypeInstance()->findAlbums(); } if (!empty($albums)) { $html['albums'] = $albums; $save = false; } $datas['type'] = !empty($datas['album_id']) || !empty($albums) ? 'album' : 'search'; } if ($save) { $image->setData($datas)->save(); $html['id'] = (int) $image->getId(); $html['is_new'] = (int) $isNew; $html['success_message'] = $this->_("Images gallery has been saved successfully"); $html['message_timeout'] = 2; $html['message_button'] = 0; $html['message_loader'] = 0; if (isset($datas['images']['list_' . $id])) { foreach ($datas['images']['list_' . $id] as $key => $info) { $gallery = new Media_Model_Gallery_Image_Custom(); if (!empty($info['image_id'])) { $gallery->find($info['image_id']); } if (!empty($info['delete'])) { $gallery->delete(); continue; } if (!$gallery->getId()) { $gallery->setGalleryId($image->getId()); } if (!empty($info['path'])) { $filename = $info['path']; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (file_exists($img_src)) { $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@rename($img_src, $img_dst)) { throw new Exception("An error occurred while saving your images gallery. Please try again later."); } $gallery->setUrl($relative_path . '/' . $filename); } } $gallery->setTitle(!empty($info['title']) ? $info['title'] : null)->setDescription(!empty($info['description']) ? $info['description'] : null)->save(); } } } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function resizeAction() { try { $folder = Core_Model_Directory::getTmpDirectory(true) . '/'; $current_file = $this->getRequest()->getParam('file'); $image_sizes = getimagesize($folder . $current_file); $src_width = $image_sizes[0]; $src_height = $image_sizes[1]; $params = array('file' => $current_file, 'source_width' => $src_width, 'source_height' => $src_height, 'crop_width' => $src_width, 'crop_height' => $src_height, 'output_width' => 400, 'output_height' => 200, 'w' => 400, 'h' => 200); if ($src_width < $params['output_width'] || $src_height < $params['output_height']) { $source = imagecreatefromstring(file_get_contents($folder . $current_file)); $dest_ratio = $params['output_width'] / $src_width; $dest_width = $params['output_width']; $dest_height = $src_height * $dest_ratio; $dest = ImageCreateTrueColor($dest_width, $dest_height); $trans_colour = imagecolorallocatealpha($dest, 0, 0, 0, 127); imagefill($dest, 0, 0, $trans_colour); imagecopyresized($dest, $source, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height); imagesavealpha($dest, true); imagepng($dest, $folder . $current_file, 0); $params["source_width"] = $dest_width; $params["source_height"] = $dest_height; $params["crop_width"] = $dest_width; $params["crop_height"] = $dest_height; } $x1 = $params["source_width"] / 2 - $params["output_width"] / 2; $y1 = $params["source_height"] / 2 - $params["output_height"] / 2; $params['x1'] = $x1; $params['y1'] = $y1; $uploader = new Core_Model_Lib_Uploader(); $new_file = $uploader->savecrop($params); $datas = array('success' => 1, 'fullsize_file' => $current_file, 'file' => $new_file, 'message_success' => 'Enregistrement réussi', 'message_button' => 0, 'message_timeout' => 2); } catch (Exception $e) { $datas = array('error' => 1, 'message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($datas)); }
public function copyAction() { if ($file = $this->getRequest()->getParam("file")) { $data = array(); try { $filename = base64_decode($file); $file = Core_Model_Directory::getTmpDirectory(true) . "/{$filename}"; if (!file_exists($file)) { throw new Exception($this->_("The file %s does not exist", $filename)); } $parser = new Installer_Model_Installer_Module_Parser(); if ($parser->setFile($file)->copy()) { $data = array("success" => 1); } else { $messages = $parser->getErrors(); $message = implode("\n", $messages); throw new Exception($this->_($message)); } } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
protected function _createIcon($datas) { // Créé l'icône $image = imagecreatetruecolor(256, 256); // Rempli la couleur de fond $rgb = $this->_hex2RGB(00); $background_color = imagecolorallocate($image, $rgb['red'], $rgb['green'], $rgb['blue']); imagefill($image, 0, 0, $background_color); $targ_w = $targ_h = 256; if (!empty($datas['icon']['file'])) { //Applique l'image $logo_relative_path = '/logo/'; $folder = Application_Model_Application::getBaseImagePath() . $logo_relative_path; if (!is_dir($folder)) { mkdir($folder, 0777, true); } $src = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['icon']['file']; $source = imagecreatefromstring(file_get_contents($src)); } $dest = ImageCreateTrueColor($targ_w, $targ_h); imagecopyresampled($dest, $image, 0, 0, 0, 0, $targ_w, $targ_h, $targ_w, $targ_h); if ($datas['icon']['file'] != '') { imagecopyresampled($dest, $source, 0, 0, $datas['icon']['x1'], $datas['icon']['y1'], $targ_w, $targ_h, $datas['icon']['w'], $datas['icon']['h']); } return $dest; }
public function uploadcertificateAction() { if ($app_id = $this->getRequest()->getParam("app_id")) { try { if (empty($_FILES) || empty($_FILES['file']['name'])) { throw new Exception("No file has been sent"); } $application = new Application_Model_Application(); $application->find($app_id); $base_path = Core_Model_Directory::getBasePathTo("var/apps/iphone/"); $path = Core_Model_Directory::getPathTo("var/apps/iphone/"); $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true)); if ($adapter->receive()) { $file = $adapter->getFileInfo(); $certificat = new Push_Model_Certificate(); $certificat->find(array('type' => 'ios', 'app_id' => $app_id)); if (!$certificat->getId()) { $certificat->setType("ios")->setAppId($app_id); } $new_name = uniqid("cert_") . ".pem"; if (!rename($file["file"]["tmp_name"], $base_path . $new_name)) { throw new Exception($this->_("An error occurred while saving. Please try again later.")); } $certificat->setPath($path . $new_name)->save(); $data = array("success" => 1, "message" => $this->_("The file has been successfully uploaded")); } else { $messages = $adapter->getMessages(); if (!empty($messages)) { $message = implode("\n", $messages); } else { $message = $this->_("An error occurred during the process. Please try again later."); } throw new Exception($message); } } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { $html = ''; try { $message = new Push_Model_Message(); $message->setMessageTypeByOptionValue($this->getCurrentOptionValue()->getOptionId()); $sendNow = false; $inputs = array('send_at', 'send_until'); foreach ($inputs as $input) { if (empty($datas[$input . '_a_specific_datetime'])) { $datas[$input] = null; } else { if (empty($datas[$input])) { throw new Exception($this->_('Please, enter a valid date')); } else { $date = new Zend_Date($datas[$input]); $datas[$input] = $date->toString('y-MM-dd HH:mm:ss'); } } } if (empty($datas['send_at'])) { $sendNow = true; $datas['send_at'] = Zend_Date::now()->toString('y-MM-dd HH:mm:ss'); } if (!empty($datas['send_until']) and $datas['send_at'] > $datas['send_until']) { throw new Exception($this->_("The duration limit must be higher than the sent date")); } // Récupère l'option_value en cours $option_value = new Application_Model_Option_Value(); if (!empty($datas['file'])) { $file = pathinfo($datas['file']); $filename = $file['basename']; $relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $relative_path; $img_dst = $folder . $filename; $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try again later.')); } else { $datas['cover'] = $relative_path . $filename; } } else { if (!empty($data['remove_cover'])) { $data['cover'] = null; } } if (empty($datas['action_value'])) { $datas['action_value'] = null; } else { if (!preg_match('/^[0-9]*$/', $datas['action_value'])) { $url = "http://" . $datas['action_value']; if (stripos($datas['action_value'], "http://") !== false || stripos($datas['action_value'], "https://") !== false) { $url = $datas['action_value']; } $datas['action_value'] = file_get_contents("http://tinyurl.com/api-create.php?url=" . urlencode($url)); } } $datas['type_id'] = $message->getMessageType(); $datas['app_id'] = $this->getApplication()->getId(); $datas["send_to_all"] = $datas["topic_receiver"] ? 0 : 1; $message->setData($datas)->save(); //PnTopics if ($datas["topic_receiver"]) { $topic_data = explode(";", $datas["topic_receiver"]); foreach ($topic_data as $id_topic) { if ($id_topic != "") { $category_message = new Topic_Model_Category_Message(); $category_message_data = array("category_id" => $id_topic, "message_id" => $message->getId()); $category_message->setData($category_message_data); $category_message->save(); } } } if ($message->getMessageType() == 1) { if ($sendNow) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, $this->getUrl('push/message/send', array('message_id' => $message->getId()))); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); // Follow the redirects (needed for mod_rewrite) curl_setopt($c, CURLOPT_HEADER, false); // Don't retrieve headers curl_setopt($c, CURLOPT_NOBODY, true); // Don't retrieve the body curl_setopt($c, CURLOPT_RETURNTRANSFER, true); // Return from curl_exec rather than echoing curl_setopt($c, CURLOPT_FRESH_CONNECT, true); // Always ensure the connection is fresh // Timeout super fast once connected, so it goes into async. curl_setopt($c, CURLOPT_TIMEOUT, 10); curl_exec($c); curl_close($c); } } else { $message->updateStatus('delivered'); } $html = array('success' => 1, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); if ($sendNow) { $html['success_message'] = $this->_('Your message has been saved successfully and will be sent in a few minutes'); } else { $html['success_message'] = $this->_('Your message has been saved successfully and will be sent at the entered date'); } } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }