Esempio n. 1
0
 public function getImages($offset)
 {
     if (!$this->_images) {
         $this->_images = array();
         try {
             $image = new Media_Model_Gallery_Image_Custom();
             $params = array('limit' => self::DISPLAYED_PER_PAGE);
             if (!empty($offset)) {
                 $params['offset'] = $offset;
             }
             $images = $image->findAll(array('gallery_id' => $this->getImageId()), 'image_id DESC', $params);
         } catch (Exception $e) {
             $images = array();
         }
         foreach ($images as $key => $image) {
             $this->_images[] = new Core_Model_Default(array('offset' => $offset++, 'title' => $image->getTitle(), 'description' => $image->getDescription(), 'author' => null, 'image' => Application_Model_Application::getImagePath() . $image->getData('url')));
         }
     }
     return $this->_images;
 }
Esempio n. 2
0
 public function createDummyContents($option_value, $design, $category)
 {
     $dummy_content_xml = $this->_getDummyXml($design, $category);
     if ($dummy_content_xml->images) {
         foreach ($dummy_content_xml->images->children() as $content) {
             $this->unsData();
             $this->addData((array) $content->content)->setValueId($option_value->getId())->save();
             if ($content->attributes()->type == "custom") {
                 foreach ($content->custom as $custom_images) {
                     $custom = new Media_Model_Gallery_Image_Custom();
                     $custom->setGalleryId($this->getId())->addData((array) $custom_images)->save();
                 }
             }
         }
     }
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_("An error occurred while saving your images gallery. Please try again later."));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $isNew = true;
             $save = true;
             $image = new Media_Model_Gallery_Image();
             if (!empty($datas['id'])) {
                 $image->find($datas['id']);
                 $isNew = false;
                 $id = $datas['id'];
             } else {
                 $id = 'new';
                 $datas['value_id'] = $option_value->getId();
             }
             if ($image->getId() and $image->getValueId() != $option_value->getId()) {
                 throw new Exception("An error occurred while saving your images gallery. Please try again later.");
             }
             if (!empty($datas['param_instagram'])) {
                 $instagram = new Media_Model_Gallery_Image_Instagram();
                 $userId = $instagram->getUserId($datas['param_instagram']);
                 if (!$userId) {
                     throw new Exception($this->_("The entered name is not a valid Instagram user."));
                 }
                 $datas['type_id'] = 'instagram';
             } elseif (!empty($datas['param'])) {
                 $datas['type_id'] = 'picasa';
             } else {
                 $datas['type_id'] = 'custom';
             }
             $html = array('success' => 1, 'is_new' => (int) $isNew);
             if (empty($datas['type_id']) or $datas['type_id'] == 'picasa') {
                 $image->setTypeId('picasa');
                 $image->getTypeInstance()->setParam($datas['param']);
                 if (empty($datas['album_id'])) {
                     $albums = $image->getTypeInstance()->findAlbums();
                 }
                 if (!empty($albums)) {
                     $html['albums'] = $albums;
                     $save = false;
                 }
                 $datas['type'] = !empty($datas['album_id']) || !empty($albums) ? 'album' : 'search';
             }
             if ($save) {
                 $image->setData($datas)->save();
                 $html['id'] = (int) $image->getId();
                 $html['is_new'] = (int) $isNew;
                 $html['success_message'] = $this->_("Images gallery has been saved successfully");
                 $html['message_timeout'] = 2;
                 $html['message_button'] = 0;
                 $html['message_loader'] = 0;
                 if (isset($datas['images']['list_' . $id])) {
                     foreach ($datas['images']['list_' . $id] as $key => $info) {
                         $gallery = new Media_Model_Gallery_Image_Custom();
                         if (!empty($info['image_id'])) {
                             $gallery->find($info['image_id']);
                         }
                         if (!empty($info['delete'])) {
                             $gallery->delete();
                             continue;
                         }
                         if (!$gallery->getId()) {
                             $gallery->setGalleryId($image->getId());
                         }
                         if (!empty($info['path'])) {
                             $filename = $info['path'];
                             $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                             if (file_exists($img_src)) {
                                 $relative_path = $option_value->getImagePathTo();
                                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                                 $img_dst = $folder . '/' . $filename;
                                 if (!is_dir($folder)) {
                                     mkdir($folder, 0777, true);
                                 }
                                 if (!@rename($img_src, $img_dst)) {
                                     throw new Exception("An error occurred while saving your images gallery. Please try again later.");
                                 }
                                 $gallery->setUrl($relative_path . '/' . $filename);
                             }
                         }
                         $gallery->setTitle(!empty($info['title']) ? $info['title'] : null)->setDescription(!empty($info['description']) ? $info['description'] : null)->save();
                     }
                 }
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }