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);
         } 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);
     }
 }
Beispiel #2
0
 protected function _copyImages()
 {
     $application = $this->getApplication();
     $icons = array($this->_sources_dst . '/res/drawable-mdpi/app_icon.png' => $application->getIcon(48, null, true), $this->_sources_dst . '/res/drawable-mdpi/push_icon.png' => $application->getIcon(24, null, true), $this->_sources_dst . '/res/drawable-hdpi/app_icon.png' => $application->getIcon(72, null, true), $this->_sources_dst . '/res/drawable-hdpi/push_icon.png' => $application->getIcon(36, null, true), $this->_sources_dst . '/res/drawable-xhdpi/app_icon.png' => $application->getIcon(96, null, true), $this->_sources_dst . '/res/drawable-xhdpi/push_icon.png' => $application->getIcon(48, null, true), $this->_sources_dst . '/res/drawable-xxhdpi/app_icon.png' => $application->getIcon(144, null, true), $this->_sources_dst . '/res/drawable-xxhdpi/push_icon.png' => $application->getIcon(72, null, true), $this->_dst . '/app_icon.png' => $application->getIcon(512, null, true));
     $startup_images = array("mdpi" => array("old" => "startup_image.png", "new" => $application->getStartupImageUrl("standard", "base")), "hdpi" => array("old" => "startup_image.png", "new" => $application->getStartupImageUrl("standard", "base")), "xhdpi" => array("old" => "startup_image.jpg", "new" => $application->getStartupImageUrl("iphone_6", "base")), "xxhdpi" => array("old" => "startup_image.jpg", "new" => $application->getStartupImageUrl("iphone_6_plus", "base")));
     foreach ($startup_images as $density => $startup_image) {
         $oldfile = $startup_image['old'];
         unlink($this->_sources_dst . "/res/drawable-{$density}/{$oldfile}");
         $newfile = $startup_image['new'];
         $extension = pathinfo($newfile, PATHINFO_EXTENSION);
         $icons[$this->_sources_dst . "/res/drawable-{$density}/startup_image.{$extension}"] = $newfile;
     }
     foreach ($icons as $icon_dst => $icon_src) {
         if (Core_Model_Lib_Image::getMimeType($icon_src) != 'image/png') {
             list($width, $height) = getimagesize($icon_src);
             $newStartupImage = imagecreatetruecolor($width, $height);
             $startupSrc = imagecreatefromstring(file_get_contents($icon_src));
             imagecopyresized($newStartupImage, $startupSrc, 0, 0, 0, 0, $width, $height, $width, $height);
             imagepng($newStartupImage, $icon_dst);
         } else {
             if (!@copy($icon_src, $icon_dst)) {
                 throw new Exception($this->_('An error occured while copying your app icon. Please check the icon, try to send it again and try again.'));
             }
         }
     }
     return $this;
 }
Beispiel #3
0
 protected 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, $image->getAppId());
     } 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;
 }
Beispiel #4
0
 public function getThumbnailUrl()
 {
     if ($picture = $this->getPictureUrl()) {
         $newIcon = new Core_Model_Lib_Image();
         $newIcon->setId(sha1($picture . "_thumbnail"))->setPath(Core_Model_Directory::getBasePathTo($picture))->setWidth(100)->setHeight(100)->crop();
         return $newIcon->getUrl();
     }
     return null;
 }
Beispiel #5
0
 public function getIcon($size = null, $name = null, $base = false)
 {
     if (!$size) {
         $size = 114;
     }
     $icon = self::getBaseImagePath() . $this->getData('icon');
     if (!is_file($icon) or !file_exists($icon)) {
         $icon = self::getBaseImagePath() . '/placeholder/no-image.png';
     }
     if (empty($name)) {
         $name = sha1($icon . $size);
     }
     $name .= '_' . filesize($icon);
     $newIcon = new Core_Model_Lib_Image();
     $newIcon->setId($name)->setPath($icon)->setWidth($size)->crop();
     return $newIcon->getUrl($base);
 }
 public function getAllPictos()
 {
     $picto_urls = array();
     foreach ($this->getBlocks() as $block) {
         $dir = Core_Model_Directory::getDesignPath(true, "/images/pictos/", "mobile");
         $pictos = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, 4096), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($pictos as $picto) {
             $colorized_color = Core_Model_Lib_Image::getColorizedUrl($picto->getPathName(), $block->getColor());
             $colorized_background_color = Core_Model_Lib_Image::getColorizedUrl($picto->getPathName(), $block->getBackgroundColor());
             $picto_urls[$colorized_color] = $colorized_color;
             $picto_urls[$colorized_background_color] = $colorized_background_color;
         }
     }
     return $picto_urls;
 }
Beispiel #7
0
 protected function _copyImages()
 {
     $application = $this->getApplication();
     // Touch Icon
     $icons = array($this->_dst . '/Images.xcassets/AppIcon.appiconset/29x29.png' => $application->getIcon(29, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/29x29-1.png' => $application->getIcon(29, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/29x29@2x.png' => $application->getIcon(58, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/29x29@2x-1.png' => $application->getIcon(58, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/29x29@3x.png' => $application->getIcon(87, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/40x40.png' => $application->getIcon(40, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/40x40@2x.png' => $application->getIcon(80, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/40x40@2x-1.png' => $application->getIcon(80, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/40x40@3x.png' => $application->getIcon(120, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/50x50.png' => $application->getIcon(50, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/50x50@2x.png' => $application->getIcon(100, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/72x72.png' => $application->getIcon(72, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/72x72@2x.png' => $application->getIcon(144, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/76x76.png' => $application->getIcon(76, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/76x76@2x.png' => $application->getIcon(152, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/57x57.png' => $application->getIcon(57, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/57x57@2x.png' => $application->getIcon(114, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/60x60@2x.png' => $application->getIcon(120, null, true), $this->_dst . '/Images.xcassets/AppIcon.appiconset/60x60@3x.png' => $application->getIcon(180, null, true), $this->_dst . '/../TouchIcon.png' => $application->getAppStoreIcon(true));
     foreach ($icons as $icon_dst => $icon_src) {
         if (!@copy($icon_src, $icon_dst)) {
             throw new Exception($this->_('An error occured while copying your app icon. Please check the icon, try to send it again and try again.'));
         }
     }
     // Startup Images
     $startup_src = $application->getStartupImageUrl("standard", true);
     $startup_src_retina = $application->getStartupImageUrl("retina", true);
     $startup_src_iphone_6 = $application->getStartupImageUrl("iphone_6", true);
     $startup_src_iphone_6_plus = $application->getStartupImageUrl("iphone_6_plus", true);
     $startup_src_ipad_retina = $application->getStartupImageUrl("ipad_retina", true);
     $startups = array($startup_src => array(array("width" => 320, "height" => 480, "dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/320x480.png'), array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/640x960.png'), array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/640x960-1.png')), $startup_src_retina => array(array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/640x1136.png'), array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/640x1136-1.png')), $startup_src_iphone_6 => array(array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/750x1334.png')), $startup_src_iphone_6_plus => array(array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/1242x2208.png')), $startup_src_ipad_retina => array(array("width" => 768, "height" => 1024, "dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/768x1024.png'), array("width" => 768, "height" => 1024, "dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/768x1024-1.png'), array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/1536x2048.png'), array("dst" => $this->_dst . '/Images.xcassets/LaunchImage.launchimage/1536x2048-1.png')));
     try {
         foreach ($startups as $startup_src => $images) {
             foreach ($images as $image) {
                 if (!empty($image["width"]) or Core_Model_Lib_Image::getMimeType($startup_src) != 'image/png') {
                     list($width, $height) = getimagesize($startup_src);
                     if (empty($image["width"])) {
                         $image["width"] = $width;
                     }
                     if (empty($image["height"])) {
                         $image["height"] = $height;
                     }
                     $newStartupImage = imagecreatetruecolor($image["width"], $image["height"]);
                     $startupSrc = imagecreatefromstring(file_get_contents($startup_src));
                     imagecopyresized($newStartupImage, $startupSrc, 0, 0, 0, 0, $image["width"], $image["height"], $width, $height);
                     imagepng($newStartupImage, $image["dst"]);
                 } else {
                     if (!@copy($startup_src, $image["dst"])) {
                         throw new Exception('An error occurred while generating the startup image. Please check the image, try to send it again and try again.', "{$image["width"]}x{$image["height"]}");
                     }
                 }
             }
         }
     } catch (Exception $e) {
         throw new Exception('An error occurred while generating the startup image. Please check the image, try to send it again and try again.');
     }
 }
 /**
  * Sauvegarde
  */
 public function postAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $data = $data["form"];
             $data_image = array();
             $errors = '';
             // Recherche des sections
             $section = new Form_Model_Section();
             $sections = $section->findByValueId($this->getCurrentOptionValue()->getId());
             $field = new Form_Model_Field();
             // Date Validator
             //                $validator = new Zend_Validate_Date(array('format' => 'yyyy-mm-ddTHH:mm'));
             $dataChanged = array();
             foreach ($sections as $k => $section) {
                 // Load the fields
                 $section->findFields($section->getId());
                 // Browse the fields
                 foreach ($section->getFields() as $field) {
                     // If the field has options
                     if ($field->hasOptions()) {
                         // If the data is not empty
                         if (isset($data[$field->getId()])) {
                             // if all checkbox = false
                             $empty_checkbox = false;
                             if (is_array($data[$field->getId()])) {
                                 if (count($data[$field->getId()]) <= count(array_keys($data[$field->getId()], false))) {
                                     $empty_checkbox = true;
                                 }
                             }
                             if (!$empty_checkbox) {
                                 // Browse the field's options
                                 foreach ($field->getOptions() as $option) {
                                     // If it's a multiselect option and there's at least one selected option, store its value
                                     if (is_array($data[$field->getId()])) {
                                         // If the key exists,
                                         if (array_key_exists($option["id"], $data[$field->getId()])) {
                                             //                                            $data[$field->getId()][$option["id"]] = $option["name"];
                                             if ($data[$field->getId()][$option["id"]]) {
                                                 $dataChanged[$field->getName()][$option["id"]] = $option["name"];
                                             }
                                         }
                                         // If the current option has been posted, store its value
                                     } else {
                                         if ($option["id"] == $data[$field->getId()]) {
                                             //                                        $data[$field->getId()] = $option["name"];
                                             $dataChanged[$field->getName()] = $option["name"];
                                         }
                                     }
                                 }
                             } else {
                                 if ($field->isRequired()) {
                                     $errors .= $this->_('<strong>%s</strong> must be filled<br />', $field->getName());
                                 }
                             }
                             // If the field is empty and required, add an error
                         } else {
                             if ($field->isRequired()) {
                                 $errors .= $this->_('<strong>%s</strong> must be filled<br />', $field->getName());
                             }
                         }
                     } else {
                         // If the field is required
                         if ($field->isRequired()) {
                             // Add an error based on its type (and if it's empty)
                             switch ($field->getType()) {
                                 case "email":
                                     if (empty($data[$field->getId()]) or !Zend_Validate::is($data[$field->getId()], 'EmailAddress')) {
                                         $errors .= $this->_('<strong>%s</strong> must be a valid email address<br />', $field->getName());
                                     }
                                     break;
                                 case "nombre":
                                     if (!isset($data[$field->getId()]) or !Zend_Validate::is($data[$field->getId()], 'Digits')) {
                                         $errors .= $this->_('<strong>%s</strong> must be a numerical value<br />', $field->getName());
                                     }
                                     break;
                                 case "date":
                                     if (!isset($data[$field->getId()])) {
                                         $errors .= $this->_('<strong>%s</strong> must be a valid date (e.g. dd/mm/yyyy)<br />', $field->getName());
                                     }
                                     break;
                                 default:
                                     if (empty($data[$field->getId()])) {
                                         $errors .= $this->_('<strong>%s</strong> must be filled<br />', $field->getName());
                                     }
                                     break;
                             }
                         }
                         // If not empty, store its value
                         if (!empty($data[$field->getId()])) {
                             // If the field is an image
                             if ($field->getType() == "image") {
                                 $image = $data[$field->getId()];
                                 if (!preg_match("@^data:image/([^;]+);@", $image, $matches)) {
                                     throw new Exception($this->_("Unrecognized image format"));
                                 }
                                 $extension = $matches[1];
                                 $fileName = uniqid() . '.' . $extension;
                                 $relativePath = $this->getCurrentOptionValue()->getImagePathTo();
                                 $fullPath = Application_Model_Application::getBaseImagePath() . $relativePath;
                                 if (!is_dir($fullPath)) {
                                     mkdir($fullPath, 0777, true);
                                 }
                                 $filePath = $fullPath . '/' . $fileName;
                                 $contents = file_get_contents($image);
                                 if ($contents === FALSE) {
                                     throw new Exception($this->_("No uploaded image"));
                                 }
                                 $res = @file_put_contents($filePath, $contents);
                                 if ($res === FALSE) {
                                     throw new Exception('Unable to save image');
                                 }
                                 list($width, $height) = getimagesize($fullPath . DS . $fileName);
                                 $max_height = $max_width = 600;
                                 $image_name = uniqid($max_height);
                                 if ($height > $width) {
                                     $image_width = $max_height * $width / $height;
                                     $image_height = $max_height;
                                 } else {
                                     $image_width = $max_width;
                                     $image_height = $max_width * $height / $width;
                                 }
                                 $newIcon = new Core_Model_Lib_Image();
                                 $newIcon->setId($image_name)->setPath($fullPath . DS . $fileName)->setWidth($image_width)->setHeight($image_height)->crop();
                                 $image_url = $this->getRequest()->getBaseUrl() . $newIcon->getUrl();
                                 $dataChanged[$field->getName()] = '<br/><img width="' . $image_width . '" height="' . $image_height . '" src="' . $image_url . '" alt="' . $field->getName() . '" />';
                             } else {
                                 $dataChanged[$field->getName()] = $data[$field->getId()];
                             }
                         }
                     }
                 }
             }
             if (empty($errors)) {
                 $form = $this->getCurrentOptionValue()->getObject();
                 $layout = $this->getLayout()->loadEmail('form', 'send_email');
                 $layout->getPartial('content_email')->setFields($dataChanged);
                 $content = $layout->render();
                 $mail = new Zend_Mail('UTF-8');
                 $mail->setBodyHtml($content);
                 $mail->setFrom($form->getEmail(), $this->getApplication()->getName());
                 $mail->addTo($form->getEmail(), $this->_('Your app\'s form'));
                 $mail->setSubject($this->_('Your app\'s form'));
                 $mail->send();
                 $html = array("success" => 1, "message" => $this->_("The form has been sent successfully"));
             } else {
                 $html = array('error' => 1, 'message' => $errors);
             }
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }