Ejemplo n.º 1
0
 public static function getBaseImagePathTo($path = '')
 {
     if (!empty($path) and substr($path, 0, 1) != '/') {
         $path = '/' . $path;
     }
     return Core_Model_Directory::getBasePathTo(self::PATH . $path);
 }
Ejemplo n.º 2
0
 public function cleanHtmlFile()
 {
     if (file_exists(Core_Model_Directory::getCacheDirectory(true) . '/' . $this->_getFilename())) {
         @unlink(Core_Model_Directory::getCacheDirectory(true) . '/' . $this->_getFilename());
     }
     return $this;
 }
Ejemplo n.º 3
0
 public function copyTo($option)
 {
     if ($this->getEventType() == 'cstm') {
         $custom_event = new Event_Model_Event_Custom();
         $custom_events = $custom_event->findAll(array('agenda_id' => $this->getId()));
         $this->setId(null)->setValueId($option->getId())->save();
         foreach ($custom_events as $custom_event) {
             $custom_event->setId(null)->setAgendaId($this->getId());
             if ($image_url = $custom_event->getPictureUrl()) {
                 $file = pathinfo($image_url);
                 $filename = $file['basename'];
                 $relativePath = $option->getImagePathTo();
                 $folder = Core_Model_Directory::getBasePathTo(Application_Model_Application::PATH_IMAGE . '/' . $relativePath);
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 $img_src = Core_Model_Directory::getBasePathTo($image_url);
                 $img_dst = $folder . '/' . $filename;
                 if (@copy($img_src, $img_dst)) {
                     $custom_event->setPicture($relativePath . '/' . $filename);
                 }
             }
             $custom_event->save();
         }
     } else {
         $this->setId(null)->setValueId($option->getId())->save();
     }
     return $this;
 }
Ejemplo n.º 4
0
 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));
     }
 }
Ejemplo n.º 5
0
 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));
     }
 }
Ejemplo n.º 6
0
 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');
     }
 }
Ejemplo n.º 7
0
 public function getColorizedImage($image_id, $color)
 {
     $color = str_replace('#', '', $color);
     $id = md5(implode('+', array($image_id, $color)));
     $url = '';
     $image = new Media_Model_Library_Image();
     if (is_numeric($image_id)) {
         $image->find($image_id);
         if (!$image->getId()) {
             return $url;
         }
         if (!$image->getCanBeColorized()) {
             $color = null;
         }
         $path = $image->getLink();
         $path = Media_Model_Library_Image::getBaseImagePathTo($path);
     } else {
         if (!Zend_Uri::check($image_id) and stripos($image_id, Core_Model_Directory::getBasePathTo()) === false) {
             $path = Core_Model_Directory::getBasePathTo($image_id);
         } else {
             $path = $image_id;
         }
     }
     try {
         $image = new Core_Model_Lib_Image();
         $image->setId($id)->setPath($path)->setColor($color)->colorize();
         $url = $image->getUrl();
     } catch (Exception $e) {
         $url = '';
     }
     return $url;
 }
 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);
     }
 }
Ejemplo n.º 9
0
 public function copyTo($option)
 {
     $old_weblink_id = $this->getId();
     $this->setId(null)->setValueId($option->getId());
     if ($image_url = $this->getCoverUrl()) {
         $file = pathinfo($image_url);
         $filename = $file['basename'];
         $relativePath = $option->getRelativePath();
         $folder = Core_Model_Directory::getBasePathTo(Application_Model_Application::PATH_IMAGE . '/' . $relativePath);
         if (!is_dir($folder)) {
             mkdir($folder, 0777, true);
         }
         $img_src = Core_Model_Directory::getBasePathTo($image_url);
         $img_dst = $folder . '/' . $filename;
         if (@copy($img_src, $img_dst)) {
             $this->setImage($relativePath . '/' . $filename);
         }
     }
     $this->save();
     $link = new Weblink_Model_Weblink_Link();
     $links = $link->findAll(array('weblink_id' => $old_weblink_id));
     foreach ($links as $link) {
         $link->setId(null)->setWeblinkId($this->getId())->save();
     }
     return $this;
 }
Ejemplo n.º 10
0
 public function uploadAction()
 {
     if ($code = $this->getRequest()->getPost("code")) {
         try {
             if (empty($_FILES) || empty($_FILES['file']['name'])) {
                 throw new Exception("No file has been sent");
             }
             $path = Core_Model_Directory::getPathTo(System_Model_Config::IMAGE_PATH);
             $base_path = Core_Model_Directory::getBasePathTo(System_Model_Config::IMAGE_PATH);
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0777, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             if ($adapter->receive()) {
                 $file = $adapter->getFileInfo();
                 $config = new System_Model_Config();
                 $config->find($code, "code");
                 $config->setValue($path . DS . $file['file']['name'])->save();
                 $message = sprintf("Your %s has been successfully saved", $code);
                 $this->_sendHtml(array("success" => 1, "message" => $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) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
     }
 }
Ejemplo n.º 11
0
 public function save()
 {
     $value_changed = $this->getValue() != $this->getOrigValue();
     if (stripos($this->getValue(), "image/png;base64") !== false) {
         $data = substr($this->getValue(), strpos($this->getValue(), ",") + 1);
         $data = str_replace(' ', '+', $data);
         $data = base64_decode($data);
         $ext = $this->getCode() == "favicon" ? ".ico" : ".png";
         $filename = $this->getCode() . $ext;
         $filepath = Core_Model_Directory::getBasePathTo("images/default");
         if (!is_dir($filepath)) {
             mkdir($filepath, 0777, true);
         }
         if (!is_writable($filepath)) {
             throw new Exception($this->_("The folder /images/default is not writable."));
         }
         file_put_contents("{$filepath}/{$filename}", $data);
         $this->setValue("/images/default/{$this->getCode()}.{$ext}");
     }
     parent::save();
     if ($this->getCode() == "system_timezone" && $value_changed) {
         $config = new self();
         $config->find("system_territory", "code");
         $value = $this->getValue();
         $territories = Zend_Registry::get("Zend_Locale")->getTranslationList('TerritoryToTimezone');
         $territory = $value && !empty($territories[$value]) ? $territories[$value] : null;
         $data = array("code" => "system_territory", "value" => $territory);
         $config->addData($data)->save();
     }
 }
Ejemplo n.º 12
0
 public function apkisgeneratedAction()
 {
     $appName = $this->getRequest()->getParam('app_name');
     $apk_base_path = Core_Model_Directory::getBasePathTo("var/tmp/applications/android/{$appName}/Siberian/app/build/outputs/apk/app-release.apk");
     $apk_path = Core_Model_Directory::getPathTo("var/tmp/applications/android/{$appName}/Siberian/app/build/outputs/apk/app-release.apk");
     $apk_is_generated = false;
     $link = $this->getUrl() . $apk_path;
     $link = str_replace("//", "/", $link);
     if (file_exists($apk_base_path)) {
         if (time() - filemtime($apk_base_path) <= 600) {
             $apk_is_generated = true;
         }
     }
     $user = new Backoffice_Model_User();
     try {
         $user = $user->findAll(null, "user_id ASC", array("limit" => "1"))->current();
         $sender = System_Model_Config::getValueFor("support_email");
         $support_name = System_Model_Config::getValueFor("support_name");
         $layout = $this->getLayout()->loadEmail('application', 'download_source');
         $subject = $this->_('Android APK Generation');
         $layout->getPartial('content_email')->setLink($link);
         $layout->getPartial('content_email')->setApkStatus($apk_is_generated);
         $content = $layout->render();
         $mail = new Zend_Mail('UTF-8');
         $mail->setBodyHtml($content);
         $mail->setFrom($sender, $support_name);
         $mail->addTo($user->getEmail());
         $mail->setSubject($subject);
         $mail->send();
     } catch (Exception $e) {
         $logger = Zend_Registry::get("logger");
         $logger->sendException("Fatal Error Sending the APK Generation Email: \n" . print_r($e, true), "apk_generation_");
     }
     die('ok');
 }
Ejemplo n.º 13
0
 public function setMessage($message)
 {
     $this->_message = $message;
     if ($certificate = Push_Model_Certificate::getiOSCertificat($message->getAppId())) {
         $this->__certificate = Core_Model_Directory::getBasePathTo($certificate);
     }
     return $this;
 }
Ejemplo n.º 14
0
 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;
 }
Ejemplo n.º 15
0
 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;
     }
 }
Ejemplo n.º 16
0
 /**
  * @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;
 }
Ejemplo n.º 17
0
 public function getPictureUrl()
 {
     $url = null;
     if ($this->getPicture()) {
         if (file_exists(Core_Model_Directory::getBasePathTo(Application_Model_Application::getImagePath() . $this->getPicture()))) {
             $url = Application_Model_Application::getImagePath() . $this->getPicture();
         }
     }
     return $url;
 }
Ejemplo n.º 18
0
 public static function addModule($module_name)
 {
     $current_language = Core_Model_Language::getCurrentLanguage();
     if (file_exists(Core_Model_Directory::getBasePathTo("/languages/{$current_language}/{$module_name}.csv"))) {
         self::$_translator->addTranslation(array('content' => Core_Model_Directory::getBasePathTo("/languages/{$current_language}/{$module_name}.csv"), 'locale' => $current_language));
     }
     if (file_exists(Core_Model_Directory::getBasePathTo("/languages/{$current_language}/emails/{$module_name}.csv"))) {
         self::$_translator->addTranslation(array('content' => Core_Model_Directory::getBasePathTo("/languages/{$current_language}/emails/{$module_name}.csv"), 'locale' => $current_language));
     }
 }
Ejemplo n.º 19
0
 public function deleteTranslation($language_code)
 {
     $library_id = $this->findLibraryIdByLanguageCode($language_code);
     $this->setLibraryId($library_id);
     $images = $this->findImages();
     foreach ($images as $image) {
         if (!@unlink(Core_Model_Directory::getBasePathTo($image->getLink()))) {
             throw new Exception($this->_("Unable to delete the file %s", $image->getLink()));
         }
     }
     $this->deleteLanguageData($language_code);
 }
Ejemplo n.º 20
0
 public static function getBaseImagePathTo($path = '', $app_id = null)
 {
     if (!empty($path) and substr($path, 0, 1) != '/') {
         $path = '/' . $path;
     }
     if (!is_null($app_id)) {
         $path = sprintf(self::APPLICATION_PATH . $path, $app_id);
     } else {
         $path = self::PATH . $path;
     }
     return Core_Model_Directory::getBasePathTo($path);
 }
 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));
     }
 }
Ejemplo n.º 22
0
 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 uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/certificates/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             $app_id = $this->getRequest()->getParam('app_id');
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0775, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             $adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
             $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
             $files = $adapter->getFileInfo();
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 } else {
                     if (!$adapter->isValid($file)) {
                         if (count($adapter->getMessages()) == 1) {
                             $erreur_message = $this->_('Error : <br/>');
                         } else {
                             $erreur_message = $this->_('Errors : <br/>');
                         }
                         foreach ($adapter->getMessages() as $message) {
                             $erreur_message .= '- ' . $message . '<br/>';
                         }
                         throw new Exception($erreur_message);
                     } else {
                         $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
                         $adapter->receive($file);
                     }
                 }
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
             if (!$certificat->getId()) {
                 $certificat->setType('ios')->setAppId($app_id);
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Info successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
Ejemplo n.º 25
0
 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);
 }
Ejemplo n.º 26
0
 public static function checkPermissions()
 {
     $errors = array();
     $base_path = Core_Model_Directory::getBasePathTo('/');
     if (is_file($base_path . 'htaccess.txt')) {
         if (!is_writable($base_path)) {
             $errors[] = 'The root directory /';
         }
         if (!is_writable($base_path . 'htaccess.txt')) {
             $errors[] = '/htaccess.txt';
         }
     }
     $paths = array('var/cache', 'var/session', 'var/tmp');
     foreach ($paths as $path) {
         if (!is_file($base_path . $path)) {
             // the folder does not exist, create it
             mkdir($base_path . $path, 0777, true);
         }
         if (!is_writable($base_path . $path)) {
             $errors[] = '/var and all of its subfolders';
             break;
         }
     }
     if (!is_writable($base_path . 'app/modules')) {
         $errors[] = '/app/modules and all of its subfolders';
     }
     $paths = array('app/design/desktop/siberian/layout', 'app/design/desktop/siberian/template');
     foreach ($paths as $path) {
         if (!is_writable($base_path . $path)) {
             $errors[] = '/app/design/desktop/siberian and all of its subfolders';
             break;
         }
     }
     $paths = array('app/design/mobile/siberian/layout', 'app/design/mobile/siberian/template');
     foreach ($paths as $path) {
         if (!is_writable($base_path . $path)) {
             $errors[] = '/app/design/mobile/siberian and all of its subfolders';
             break;
         }
     }
     $paths = array("app/design/email", "images", "app/configs", "app/configs/app.sample.ini");
     foreach ($paths as $path) {
         if (!is_writable($base_path . $path)) {
             $errors[] = $path;
         }
     }
     return $errors;
 }
Ejemplo n.º 27
0
 public static function checkPermissions()
 {
     $errors = array();
     $base_path = Core_Model_Directory::getBasePathTo('/');
     if (is_file($base_path . 'htaccess.txt') and !file_exists($base_path . ".htaccess")) {
         if (!is_writable($base_path)) {
             $errors[] = 'The root directory /';
         }
         if (!is_writable($base_path . 'htaccess.txt')) {
             $errors[] = '/htaccess.txt';
         }
     }
     $paths = array('var', 'var/cache', 'var/session', 'var/tmp');
     foreach ($paths as $path) {
         if (!is_dir($base_path . $path)) {
             @mkdir($base_path . $path, 0777);
         }
         if (!is_writable($base_path . $path)) {
             $errors[] = $path;
         }
     }
     //        if(!is_writable($base_path.'app/modules')) {
     //            $errors[] = '/app/modules and all of its subfolders';
     //        }
     //
     //        $paths = array('app/design/desktop/siberian/layout', 'app/design/desktop/siberian/template');
     //        foreach($paths as $path) {
     //            if(!is_writable($base_path.$path)) {
     //                $errors[] = '/app/design/desktop/siberian and all of its subfolders';
     //                break;
     //            }
     //        }
     //
     //        $paths = array('app/design/mobile/siberian/layout', 'app/design/mobile/siberian/template');
     //        foreach($paths as $path) {
     //            if(!is_writable($base_path.$path)) {
     //                $errors[] = '/app/design/mobile/siberian and all of its subfolders';
     //                break;
     //            }
     //        }
     $paths = array("app/configs");
     foreach ($paths as $path) {
         if (!is_writable($base_path . $path)) {
             $errors[] = $path;
         }
     }
     return $errors;
 }
Ejemplo n.º 28
0
 public static function prepare()
 {
     $territories = Zend_Locale::getTranslationList('language');
     $directories = new DirectoryIterator(Core_Model_Directory::getBasePathTo('languages'));
     foreach ($directories as $directory) {
         $dir_name = $directory->getFileName();
         if (!$directory->isDot() and isset($territories[$dir_name])) {
             $locale = Zend_Locale::getLocaleToTerritory($dir_name);
             self::$_languages[$directory->getFileName()] = new Core_Model_Default(array('code' => $directory->getFileName(), 'name' => ucfirst($territories[$dir_name]), 'locale' => $locale));
             self::$_language_codes[] = $directory->getFileName();
         }
     }
     self::$_languages[self::DEFAULT_LANGUAGE] = new Core_Model_Default(array('code' => self::DEFAULT_LANGUAGE, 'name' => ucfirst($territories[self::DEFAULT_LANGUAGE]), 'locale' => self::DEFAULT_LOCALE));
     self::$_language_codes[] = self::DEFAULT_LANGUAGE;
     asort(self::$_languages);
 }
Ejemplo n.º 29
0
 protected function _cpFolder()
 {
     $src = Core_Model_Directory::getBasePathTo(self::SOURCE_FOLDER);
     $dst = Core_Model_Directory::getBasePathTo(self::DEST_FOLDER);
     // Supprime le dossier s'il existe puis le créé
     if (is_dir($dst)) {
         Core_Model_Directory::delete($dst);
     }
     mkdir($dst, 0775, true);
     // Copie les sources
     Core_Model_Directory::duplicate($src, $dst);
     $this->_zipname = 'ios_source';
     $this->_dst = $dst . '/Siberian';
     $this->_base_dst = $dst;
     return $this;
 }
Ejemplo n.º 30
0
 public function prepare($name)
 {
     $this->_name = $name;
     $this->findByName($name);
     if (!$this->getId()) {
         $this->setName($name)->setVersion(self::DEFAULT_VERSION);
         $this->_isInstalled = false;
     } else {
         $this->_isInstalled = true;
     }
     $this->_basePath = Core_Model_Directory::getBasePathTo("app/modules/{$name}");
     $versions = array();
     $installer = array("version" => "0.0.0");
     if (is_dir("{$this->_basePath}/db")) {
         $max_version = "0.0.0";
         $files = new DirectoryIterator("{$this->_basePath}/db");
         if (!$this->isInstalled()) {
             foreach ($files as $file) {
                 if ($file->isDot() or !preg_match("/^(database)([0-9.]*)(install.php)\$/", $file->getFilename())) {
                     continue;
                 }
                 $version = str_replace(array('database.', '.install.php'), '', $file);
                 if (version_compare($version, $installer["version"]) > 0) {
                     $installer = array("version" => $version, "path" => $file->getPathName());
                 }
             }
         }
         foreach ($files as $file) {
             if ($file->isDot() or !preg_match("/^(database)(([0-9.]*)|(.template\\.))(php)\$/", $file->getFilename())) {
                 continue;
             }
             $version = str_replace(array('database.', '.php'), '', $file->getFilename());
             if (version_compare($version, $installer["version"]) > 0) {
                 $this->_dbFiles[$version] = $file->getPathName();
                 $versions[] = $version;
             }
         }
         if (!empty($installer["path"])) {
             $this->_dbFiles[$installer["version"]] = $installer["path"];
             $versions[] = $installer["version"];
         }
         uksort($this->_dbFiles, "version_compare");
         usort($versions, "version_compare");
     }
     $this->_lastVersion = !empty($versions) ? end($versions) : self::DEFAULT_VERSION;
     return $this;
 }