Exemple #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;
     }
 }
Exemple #3
0
 public function getImages()
 {
     if (empty($this->_images)) {
         $this->_images = array();
         $image = new Media_Model_Library_Image();
         if ($this->getId()) {
             $this->_images = $image->findAll(array('library_id = ?' => $this->getId()), array('position ASC', 'image_id ASC', 'can_be_colorized DESC'));
         }
     }
     return $this->_images;
 }
Exemple #4
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);
     }
 }
<?php

$this->query("\n    CREATE TABLE `push_apns_devices` (\n        `device_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `app_version` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,\n        `device_uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL,\n        `last_known_latitude` decimal(11,8) DEFAULT NULL,\n        `last_known_longitude` decimal(11,8) DEFAULT NULL,\n        `device_token` char(64) COLLATE utf8_unicode_ci NOT NULL,\n        `device_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `device_model` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n        `device_version` varchar(25) COLLATE utf8_unicode_ci NOT NULL,\n        `push_badge` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `push_alert` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `push_sound` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n        `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n        `created_at` datetime NOT NULL,\n        `updated_at` timestamp NOT NULL,\n        PRIMARY KEY (`device_id`),\n        UNIQUE KEY `UNIQUE_KEY_APP_NAME_APP_VERSION_DEVICE_UID` (`app_name`,`app_version`,`device_uid`),\n        KEY `KEY_DEVICE_TOKEN` (`device_token`),\n        KEY `KEY_STATUS` (`status`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n    CREATE TABLE `push_delivered_message` (\n        `deliver_id` int(11) NOT NULL AUTO_INCREMENT,\n        `device_id` int(11) NOT NULL,\n        `device_uid` text COLLATE utf8_unicode_ci NOT NULL,\n        `device_type` tinyint(1) NOT NULL,\n        `message_id` int(11) NOT NULL,\n        `status` tinyint(1) NOT NULL DEFAULT '0',\n        `is_read` tinyint(1) NOT NULL DEFAULT '0',\n        `is_displayed` int(11) NOT NULL DEFAULT '0',\n        `delivered_at` datetime NOT NULL,\n        PRIMARY KEY (`deliver_id`),\n        KEY `KEY_DEVICE_ID` (`device_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$this->query("\n    CREATE TABLE `push_gcm_devices` (\n        `device_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `registration_id` text COLLATE utf8_unicode_ci,\n        `development` enum('production','sandbox') CHARACTER SET latin1 NOT NULL DEFAULT 'production',\n        `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n        `created_at` datetime NOT NULL,\n        `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n        PRIMARY KEY (`device_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n    CREATE TABLE `push_messages` (\n        `message_id` int(11) NOT NULL AUTO_INCREMENT,\n        `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL,\n        `text` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n        `latitude` decimal(11,8) DEFAULT NULL,\n        `longitude` decimal(11,8) DEFAULT NULL,\n        `radius` decimal(7,2) DEFAULT NULL,\n        `send_at` datetime DEFAULT NULL,\n        `send_until` datetime DEFAULT NULL,\n        `delivered_at` datetime DEFAULT NULL,\n        `status` enum('queued','delivered','sending','failed') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued',\n        `created_at` datetime NOT NULL,\n        `updated_at` datetime NOT NULL,\n        PRIMARY KEY (`message_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$this->query("\n    CREATE TABLE `push_certificate` (\n        `certificate_id` int(11) NOT NULL AUTO_INCREMENT,\n        `app_id` INT(11) NULL DEFAULT NULL,\n        `type` varchar(30) NOT NULL,\n        `path` varchar(255) NULL DEFAULT NULL,\n        `created_at` datetime NOT NULL,\n        `updated_at` datetime NOT NULL,\n        PRIMARY KEY (`certificate_id`)\n    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n");
$library = new Media_Model_Library();
$library->setName('Push')->save();
$icon_paths = array('/push_notifications/push1.png', '/push_notifications/push2.png', '/push_notifications/push3.png', '/push_notifications/push4.png', '/push_notifications/push5.png', '/loyalty/loyalty6.png');
$icon_id = 0;
foreach ($icon_paths as $key => $icon_path) {
    $datas = array('library_id' => $library->getId(), 'link' => $icon_path, 'can_be_colorized' => 1);
    $image = new Media_Model_Library_Image();
    $image->setData($datas)->save();
    if ($key == 0) {
        $icon_id = $image->getId();
    }
}
$datas = array('library_id' => $library->getId(), 'icon_id' => $icon_id, 'code' => 'push_notification', 'name' => 'Push Notifications', 'model' => '', 'desktop_uri' => 'push/application/', 'mobile_uri' => 'push/mobile/', 'only_once' => 1, 'is_ajax' => 1, 'position' => 130);
$option = new Application_Model_Option();
$option->setData($datas)->save();
<?php

$media_library = new Media_Model_Library();
$media_library->setName("Code Scan")->save();
$icon_id = null;
$files_icon = new DirectoryIterator(Core_Model_Directory::getBasePathTo("images/library/code_scan"));
foreach ($files_icon as $file) {
    if ($file->isDot()) {
        continue;
    }
    $icon = new Media_Model_Library_Image();
    $icon_data = array("library_id" => $media_library->getId(), "link" => "/code_scan/" . $file->getFilename(), "can_be_colorized" => 1);
    $icon->setData($icon_data)->save();
    if ($icon_id == null) {
        $icon_id = $icon->getId();
    }
}
$option_data = array("code" => "code_scan", "name" => "Code Scan", "model" => "Codescan_Model_Codescan", "library_id" => $media_library->getId(), "icon_id" => $icon_id, "desktop_uri" => "codescan/application/", "mobile_uri" => "codescan/mobile_view/", "position" => 150);
$option = new Application_Model_Option();
$option->setData($option_data)->save();
Exemple #8
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 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));
     }
 }
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();
        }
    }
}
Exemple #11
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));
 }
$library = new Media_Model_Library();
$library->setName('Weblink')->save();
$icon_paths = array('/weblink/link1.png', '/weblink/link2.png', '/weblink/link3.png');
$icon_id = 0;
foreach ($icon_paths as $key => $icon_path) {
    $data = array('library_id' => $library->getId(), 'link' => $icon_path, 'can_be_colorized' => 1);
    $image = new Media_Model_Library_Image();
    $image->setData($data)->save();
    if ($key == 0) {
        $icon_id = $image->getId();
    }
}
$category = new Application_Model_Option_Category();
$category->find("integration", "code");
$data = array('category_id' => $category->getId(), 'library_id' => $library->getId(), 'icon_id' => $icon_id, 'code' => "weblink_mono", 'name' => "Link", 'model' => "Weblink_Model_Type_Mono", 'desktop_uri' => "weblink/application_mono/", 'mobile_uri' => "weblink/mobile_mono/", 'only_once' => 0, 'is_ajax' => 0, 'position' => 150);
$option = new Application_Model_Option();
$option->setData($data)->save();
$data = array('category_id' => $category->getId(), 'library_id' => $library->getId(), 'icon_id' => $icon_id, 'code' => "weblink_multi", 'name' => "Links", 'model' => "Weblink_Model_Type_Multi", 'desktop_uri' => "weblink/application_multi/", 'mobile_uri' => "weblink/mobile_multi/", 'only_once' => 0, 'is_ajax' => 1, 'position' => 160);
$option = new Application_Model_Option();
$option->setData($data)->save();
$features = array('Magento' => array('icon_path' => '/magento/magento1.png', 'datas' => array('code' => 'magento', 'name' => 'Magento', 'model' => 'Weblink_Model_Type_Mono', 'desktop_uri' => 'weblink/application_magento/', 'mobile_uri' => 'weblink/mobile_mono/')), 'WooCommerce' => array('icon_path' => '/woocommerce/woocommerce1.png', 'datas' => array('code' => 'woocommerce', 'name' => 'WooCommerce', 'model' => 'Weblink_Model_Type_Mono', 'desktop_uri' => 'weblink/application_woocommerce/', 'mobile_uri' => 'weblink/mobile_mono/')), 'Prestashop' => array('icon_path' => '/prestashop/prestashop1.png', 'datas' => array('code' => 'prestashop', 'name' => 'Prestashop', 'model' => 'Weblink_Model_Type_Mono', 'desktop_uri' => 'weblink/application_prestashop/', 'mobile_uri' => 'weblink/mobile_mono/')), 'Volusion' => array('icon_path' => '/volusion/volusion1.png', 'datas' => array('code' => 'volusion', 'name' => 'Volusion', 'model' => 'Weblink_Model_Type_Mono', 'desktop_uri' => 'weblink/application_volusion/', 'mobile_uri' => 'weblink/mobile_mono/')), 'Shopify' => array('icon_path' => '/shopify/shopify1.png', 'datas' => array('code' => 'shopify', 'name' => 'Shopify', 'model' => 'Weblink_Model_Type_Mono', 'desktop_uri' => 'weblink/application_shopify/', 'mobile_uri' => 'weblink/mobile_mono/')));
foreach ($features as $feature_name => $feature) {
    $library = new Media_Model_Library();
    $library->setName($feature_name)->save();
    $data = array('library_id' => $library->getId(), 'link' => $feature['icon_path'], 'can_be_colorized' => 1);
    $image = new Media_Model_Library_Image();
    $image->setData($data)->save();
    $data = array_merge($feature['datas'], array('category_id' => $category->getId(), 'library_id' => $library->getId(), 'icon_id' => $image->getId(), 'only_once' => 0, 'is_ajax' => 0, 'position' => 155));
    $option = new Application_Model_Option();
    $option->setData($data)->save();
}
 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);
     }
 }