Beispiel #1
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 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;
     }
 }
Beispiel #3
0
 public function createDummyContents($option_value, $design, $category)
 {
     $dummy_content_xml = $this->_getDummyXml($design, $category);
     foreach ($dummy_content_xml->folders->folder as $folder) {
         $root_category = new Folder_Model_Category();
         $root_category->addData((array) $folder->category->main->content)->save();
         if ($folder->category->main->features) {
             $i = 1;
             foreach ($folder->category->main->features->feature as $feature) {
                 $option = new Application_Model_Option();
                 $option->find((string) $feature->code, "code")->getObject();
                 $option_value_obj = new Application_Model_Option_Value();
                 $icon_id = NULL;
                 if ((string) $feature->icon) {
                     $icon = new Media_Model_Library_Image();
                     $icon->find((string) $feature->icon, "link");
                     if (!$icon->getData()) {
                         $icon->setLibraryId($option->getLibraryId())->setLink((string) $feature->icon)->setOptionId($option->getId())->setCanBeColorized($feature->colorizable ? (string) $feature->colorizable : 1)->setPosition(0)->save();
                     }
                     $icon_id = $icon->getId();
                 }
                 $datas = array("tabbar_name" => (string) $feature->name ? (string) $feature->name : NULL, "icon_id" => $icon_id, "app_id" => $this->getApplication()->getId(), "option_id" => $option->getId(), "layout_id" => $this->getApplication()->getLayout()->getId(), "folder_id" => $option_value->getId(), "folder_category_id" => $root_category->getId(), "folder_category_position" => $i++);
                 $option_value_obj->addData($datas)->save();
             }
         }
         $this->unsData();
         $this->setValueId($option_value->getId())->setRootCategoryId($root_category->getId())->save();
         foreach ($folder->category->subcategory as $subcategory) {
             $sub_root_category = new Folder_Model_Category();
             $sub_root_category->addData((array) $subcategory->content)->setParentId($root_category->getId())->save();
             if ($folder->category->subcategory->features) {
                 $i = 1;
                 foreach ($folder->category->subcategory->features->children() as $feature) {
                     $option = new Application_Model_Option();
                     $option->find((string) $feature->code, "code")->getObject();
                     $option_value_obj = new Application_Model_Option_Value();
                     $icon_id = NULL;
                     if ((string) $feature->icon) {
                         $icon = new Media_Model_Library_Image();
                         $icon->find((string) $feature->icon, "link");
                         if (!$icon->getData()) {
                             $icon->setLibraryId($option->getLibraryId())->setLink((string) $feature->icon)->setOptionId($option->getId())->setCanBeColorized(1)->setPosition(0)->save();
                         }
                         $icon_id = $icon->getId();
                     }
                     $datas = array("tabbar_name" => (string) $feature->name ? (string) $feature->name : NULL, "icon_id" => $icon_id, "app_id" => $this->getApplication()->getId(), "option_id" => $option->getId(), "layout_id" => $this->getApplication()->getLayout()->getId(), "folder_id" => $option_value->getId(), "folder_category_id" => $sub_root_category->getId(), "folder_category_position" => $i++);
                     $option_value_obj->addData($datas)->save();
                 }
             }
         }
     }
 }
 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);
     }
 }
Beispiel #5
0
 public function getIconUrl($base = false)
 {
     if (empty($this->_icon_url) and $this->getIconId()) {
         if ($this->getIcon() and !$base) {
             $this->_icon_url = Media_Model_Library_Image::getImagePathTo($this->getIcon(), $this->getAppId());
         } else {
             $icon = new Media_Model_Library_Image();
             $icon->find($this->getIconId());
             $this->_icon_url = $icon->getUrl();
         }
     }
     return $this->_icon_url;
 }
 public function deleteiconAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $icon = new Media_Model_Library_Image();
             $icon->find($datas['icon_id']);
             if ($icon->getAdminId()) {
                 $icon->delete();
             } else {
                 throw new Exception($this->_("You may not delete a library icon"));
             }
             $html = array('success' => 1);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
foreach ($categories_designs as $category_code => $design_codes) {
    $categories_designs_data = array("category_id" => $category_ids[$category_code]);
    foreach ($design_codes as $design_code) {
        $categories_designs_data["design_id"] = $design_ids[$design_code];
        $this->_db->insert("template_design_category", $categories_designs_data);
    }
}
// Assigning features to designs
$design_codes = array("dj" => array("newswall" => array("icon" => "/newswall/newswall2.png"), "music_gallery" => array("name" => "Playlists"), "push_notification" => array("name" => "Messages", "icon" => "/push_notifications/push2.png"), "image_gallery" => array("icon" => "/images/image5.png"), "facebook" => array(), "calendar" => array("icon" => "/calendar/calendar2.png"), "video_gallery" => array("icon" => "/videos/video2.png"), "custom_page" => array("name" => "About me"), "booking" => array("icon" => "/booking/booking4.png")), "fairground" => array("fanwall" => array("icon" => "/../../images/templates/fairground/icons/fanwall.png"), "loyalty" => array("name" => "Loyalty", "icon" => "/loyalty/loyalty4.png"), "social_gaming" => array("icon" => "/contest/contest4.png"), "discount" => array("name" => "Coupons", "icon" => "/discount/discount5.png"), "calendar" => array("icon" => "/calendar/calendar2.png"), "image_gallery" => array("icon" => "/images/image7.png"), "push_notification" => array("name" => "Push", "icon" => "/push_notifications/push3.png"), "video_gallery" => array(), "newswall" => array("name" => "News"), "facebook" => array()), "pizza" => array("m_commerce" => array("name" => "Orders"), "loyalty" => array("name" => "Loyalty"), "social_gaming" => array(), "discount" => array(), "facebook" => array(), "contact" => array()));
foreach ($design_codes as $design_code => $option_codes) {
    foreach ($option_codes as $option_code => $option_infos) {
        $design = new Template_Model_Design();
        $design->find($design_code, "code");
        $option = new Application_Model_Option();
        $options = $option->findAll(array("code IN (?)" => $option_code));
        foreach ($options as $option) {
            $icon_id = NULL;
            if (isset($option_infos["icon"])) {
                $icon = new Media_Model_Library_Image();
                $icon->find($option_infos["icon"], "link");
                if (!$icon->getData()) {
                    $icon->setLibraryId($option->getLibraryId())->setLink($option_infos["icon"])->setOptionId($option->getId())->setCanBeColorized(1)->setPosition(0)->save();
                }
                $icon_id = $icon->getId();
            }
            $data = array("design_id" => $design->getId(), "option_id" => $option->getId(), "option_tabbar_name" => isset($option_infos["name"]) ? $option_infos["name"] : NULL, "option_icon" => $icon_id, "option_background_image" => isset($option_infos["background_image"]) ? $option_infos["background_image"] : NULL);
            $design_content = new Template_Model_Design_Content();
            $design_content->setData($data)->save();
        }
    }
}
Beispiel #8
0
 public function deletePictures()
 {
     if ($picture_list = $this->getRemovePicture()) {
         foreach ($picture_list as $picture) {
             if ($picture != "") {
                 $image = new Media_Model_Library_Image();
                 $image->find($picture);
                 if ($image->getId()) {
                     unlink(Application_Model_Application::getBaseImagePath() . $image->getLink());
                     $image->delete();
                 }
             }
         }
     }
 }
 public function deletesliderimageAction()
 {
     try {
         $image_id = $this->_request->getparam('image_id');
         $library_image = new Media_Model_Library_Image();
         $library_image->find($image_id);
         $file = Core_Model_Directory::getBasePathTo($library_image->getLink());
         $library_image->delete();
         if (file_exists($file)) {
             if (unlink($file)) {
                 $html = array('success' => 1, 'reload' => 1);
             } else {
                 throw new Exception($this->_("An error occurred while deleting your picture"));
             }
         }
     } catch (Exception $e) {
         $html = array('message' => $e->getMessage());
     }
     $this->getLayout()->setHtml(Zend_Json::encode($html));
 }
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             $previews = $data["previews"];
             $option_id = !empty($data["option_id"]) ? $data["option_id"] : null;
             $preview_id = !empty($data["preview_id"]) ? $data["preview_id"] : null;
             if (empty($previews)) {
                 throw new Exception($this->_("An error occurred while saving your previews. Please try again later."));
             }
             $preview = new Preview_Model_Preview();
             if (!empty($option_id) and empty($preview_id)) {
                 //No preview for this option yet, we create one if it doesn't exists.
                 $preview->find($option_id, "option_id");
                 if ($preview->getId()) {
                     throw new Exception($this->_("Sorry, but an existing preview for this feature has been found. Please edit existing one."));
                 }
                 $preview->setData("option_id", $option_id);
             } else {
                 //Existing preview
                 if (!empty($preview_id)) {
                     $preview->find($data["preview_id"]);
                 } else {
                     throw new Exception($this->_("An error occurred while saving your previews. Please try again later."));
                 }
             }
             $previews_language_data = array();
             foreach ($previews as $language_code => $data) {
                 $option = new Application_Model_Option();
                 $option->find($preview->getOptionId());
                 if ($preview->getId()) {
                     $library_id = $preview->findLibraryIdByLanguageCode($language_code);
                 } else {
                     $library_id = null;
                 }
                 if (!$library_id) {
                     $library = new Media_Model_Library();
                     $library->setName('preview_' . $language_code . '_' . $option->getCode())->save();
                     $data["library_id"] = $library->getId();
                 } else {
                     $data["library_id"] = $library_id;
                 }
                 //IMAGES------------------------------------------------
                 foreach ($data["images"] as $key => $image) {
                     $library_image = new Media_Model_Library_Image();
                     //We only copy new files
                     if ($image["new"] == 1) {
                         $old_path = Core_Model_Directory::getTmpDirectory(true);
                         $new_path = Core_Model_Directory::getBasePathTo("images/previews/" . $language_code . "/" . $option->getCode());
                         $new_path_base = Core_Model_Directory::getPathTo("images/previews/" . $language_code . "/" . $option->getCode());
                         if (!is_dir($new_path)) {
                             if (!@mkdir($new_path, 0777, true)) {
                                 throw new Exception($this->_("Unable to create the directory."));
                             }
                         }
                         if (!@rename($old_path . "/" . $image["filename"], $new_path . "/" . $image["filename"])) {
                             throw new Exception($this->_("Unable to copy the file."));
                         }
                         $data_image = array("library_id" => $data["library_id"], "link" => $new_path_base . "/" . $image["filename"], "can_be_colorized" => 0, "position" => $key);
                         $library_image->setData($data_image)->save();
                     } else {
                         //For existing images, we save position
                         $library_image->find($image["id"]);
                         if ($library_image->getImageId()) {
                             $library_image->setPosition($key)->save();
                         }
                     }
                     //We delete images to delete
                     if ($image["to_delete"] == 1 and $image["new"] == 0) {
                         if (!@unlink(Core_Model_Directory::getBasePathTo($image["link"]))) {
                             throw new Exception($this->_("Unable to delete the file."));
                         }
                         $library_image = new Media_Model_Library_Image();
                         $library_image->find($image["id"]);
                         $library_image->delete();
                     }
                 }
                 unset($data["images"]);
                 //<--IMAGES------------------------------------------------
                 unset($data["from_database"]);
                 $data['language_code'] = $language_code;
                 $data['preview_id'] = $preview->getId();
                 $previews_language_data[] = $data;
             }
             $preview->setLanguageData($previews_language_data);
             $preview->save();
             $data = array("success" => 1, "message" => $this->_("Preview successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }