public function findAction() { if ($gallery_id = $this->getRequest()->getParam("gallery_id")) { try { $offset = $this->getRequest()->getParam('offset', 0); $data = array("collection" => array()); $image = new Media_Model_Gallery_Image(); $image->find($gallery_id); if (!$image->getId() or $image->getValueId() != $this->getCurrentOptionValue()->getId()) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $images = $image->setOffset($offset)->getImages(); foreach ($images as $key => $link) { $key += $offset; $data["collection"][] = array("offset" => $link->getOffset(), "gallery_id" => $key, "is_visible" => false, "url" => $link->getImage(), "title" => $link->getTitle(), "description" => $link->getDescription(), "author" => $link->getAuthor()); } if ($image->getTypeId() != "custom") { $data["show_load_more"] = count($data["images"]) > 0; } else { $data["show_load_more"] = $key - $offset + 1 > Media_Model_Gallery_Image_Abstract::DISPLAYED_PER_PAGE - 1 ? true : false; } } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }
public function loadmoreAction() { if ($datas = $this->getRequest()->getPost()) { try { if (empty($datas['gallery_id'])) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $offset = !empty($datas['offset']) ? $datas['offset'] : 0; $image = new Media_Model_Gallery_Image(); $image->find($datas['gallery_id']); if (!$image->getId() or $image->getValueId() != $this->getCurrentOptionValue()->getId()) { throw new Exception($this->_('An error occurred while loading pictures. Please try later.')); } $images = $image->setOffset($offset)->getImages(); $html = array(); $image_datas = array(); // $offset--; foreach ($images as $key => $link) { $key += $offset; $html[] = $this->getLayout()->addPartial('row', 'core_view_default', 'media/gallery/image/l1/view/list/li.phtml')->setCurrentImage($image)->setKey($key)->setLink($link)->toHtml(); $image_datas[] = $link->getData(); } $html = array('html' => implode('', $html), 'images' => $image_datas, 'id' => $image->getId()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function findallAction() { if ($value_id = $this->getRequest()->getParam("value_id")) { try { $image = new Media_Model_Gallery_Image(); $images = $image->findAll(array('value_id' => $value_id)); $data = array("galleries" => array()); foreach ($images as $image) { $data["galleries"][] = array("id" => $image->getId(), "name" => $image->getName(), "type" => $image->getTypeId()); } $data["page_title"] = $this->getCurrentOptionValue()->getTabbarName(); $data["header_right_button"]["picto_url"] = $this->_getColorizedImage($this->_getImage('pictos/more.png', true), $this->getApplication()->getBlock('subheader')->getColor()); } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }
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)); } }