Exemplo n.º 1
0
 /**
  * Asks user to authorize with Instagram.
  *
  * @return Rsc_Http_Response
  */
 public function authorizationAction(Rsc_Http_Request $request)
 {
     $galleryId = $request->query->get('id');
     $galleries = new GridGallery_Galleries_Model_Galleries();
     $client = $this->getClient($galleryId);
     try {
         return $this->response('@insta/authorization.twig', array('url' => $client->getAuthorizationUrl(), 'id' => $galleryId, 'galleryName' => $galleries->getById($galleryId)->title));
     } catch (Exception $e) {
         return $this->response('error.twig', array('message' => $e->getMessage()));
     }
 }
Exemplo n.º 2
0
 /**
  * Attach Action
  * Attaches resources to the specified gallery
  *
  * @param Rsc_Http_Request $request
  * @return Rsc_Http_Response
  */
 public function attachAction(Rsc_Http_Request $request)
 {
     $logger = $this->getEnvironment()->getLogger();
     $lang = $this->getEnvironment()->getLang();
     try {
         $gid = $this->getModel('resources')->attachFromRequest($request, $lang);
     } catch (GridGallery_Galleries_Exception_AttachException $e) {
         if ($logger) {
             $logger->error('Failed to attach resources to gallery: {exception}', array('exception' => $e));
         }
         return $this->response('ajax', $this->getErrorResponseData($e->getMessage()));
     }
     $galleries = new GridGallery_Galleries_Model_Galleries();
     $gallery = $galleries->getById($gid);
     /*return $this->response(
           'ajax',
           $this->getSuccessResponseData(
               sprintf(
                   $lang->translate(
                       'The resources are successfully attached to the <a href="%s">%s</a>'
                   ),
                   $this->generateUrl(
                       'galleries',
                       'view',
                       array('gallery_id' => $gid)
                   ),
                   $gallery->title
               )
           )
       );*/
     return $this->response('ajax', array('message' => $this->translate('The resources are successfully attached to the ' . $gallery->title), 'galleryId' => (int) $gallery->id, 'redirectUrl' => $this->getEnvironment()->generateUrl('galleries', 'view', array('gallery_id' => $gallery->id))));
 }
Exemplo n.º 3
0
 public function getOldGallery($attributes)
 {
     $galleries = new GridGallery_Galleries_Model_Galleries();
     $twig = $this->getEnvironment()->getTwig();
     $cache = $this->getEnvironment()->getCache();
     $gallery = $galleries->getById($attributes['id']);
     if (!$gallery) {
         return;
     }
     $key = sprintf('gallery_settings_%s', $attributes['id']);
     /** @var GridGallery_Settings_Registry $registry */
     $registry = $this->getEnvironment()->getModule('settings')->getRegistry();
     if (true === (bool) $registry->get('cache_enabled')) {
         $ttl = $registry->get('cache_ttl');
         $cache->setTtl($ttl);
         if (null === ($settings = $cache->get($key))) {
             $settings = $this->getGallerySettings($attributes['id']);
             $cache->set($key, $settings, (int) $ttl);
         }
     } else {
         $settings = $this->getGallerySettings($attributes['id']);
     }
     if (array_key_exists('position', $attributes)) {
         $position = strtolower($attributes['position']);
         if (!in_array($position, array('left', 'center', 'right'), false)) {
             $position = 'center';
         }
         $settings->data['area']['position'] = $position;
     }
     if (property_exists($gallery, 'photos') && is_array($gallery->photos)) {
         $position = new GridGallery_Photos_Model_Position();
         /*foreach ($gallery->photos as $index => $row) {
               $gallery->photos[$index] = $position->setPosition(
                   $row,
                   'gallery',
                   $gallery->id
               );
           }*/
         $positions = $position->setPosition($gallery->photos, 'gallery', $gallery->id);
         foreach ($gallery->photos as $index => $row) {
             foreach ($positions as $pos) {
                 if ($row->id == $pos->photo_id) {
                     $gallery->photos[$index]->position = $pos->position;
                 }
             }
         }
         $gallery->photos = $position->sort($gallery->photos);
         $cats = array();
         foreach ($gallery->photos as $photo) {
             if (property_exists($photo, 'tags') && is_array($photo->tags) && count($photo->tags) > 0) {
                 foreach ($photo->tags as $tag) {
                     if (!isset($cats[$tag])) {
                         $cats[$tag] = true;
                     }
                 }
             }
         }
     }
     $settingsModel = new GridGallery_Galleries_Model_Settings();
     $postsLenght = sizeof($settingsModel->getPostsToRender($attributes['id'])) + sizeof($settingsModel->getPagesToRender($attributes['id']));
     if (isset($settings->data['posts']) && $settings->data['posts']['enable']) {
         foreach ($settingsModel->getPostsToRender($attributes['id']) as $post) {
             foreach ($post['categories'] as $category) {
                 if (!isset($cats[$category['name']])) {
                     $cats[$category['name']] = true;
                 }
             }
         }
         foreach ($settingsModel->getPagesToRender($attributes['id']) as $page) {
             foreach ($page['categories'] as $category) {
                 if (!isset($cats[$category['name']])) {
                     $cats[$category['name']] = true;
                 }
             }
         }
     }
     if (is_array($gallery->photos) && $gallery->photos) {
         foreach ($gallery->photos as $photo) {
             $photo->attachment['caption'] = html_entity_decode($photo->attachment['caption']);
         }
     }
     $template = $twig->render('@galleries/r314/shortcode/gallery.twig', array('gallery' => $gallery, 'settings' => is_object($settings) ? $settings->data : $settings, 'colorbox' => $this->getEnvironment()->getModule('colorbox')->getLocationUrl(), 'categories' => isset($cats) ? $cats : array(), 'postsLength' => $postsLenght, 'posts' => $settingsModel->getPostsToRender($attributes['id']), 'pages' => $settingsModel->getPagesToRender($attributes['id']), 'mobile' => isset($settings->data['box']['mobile']) ? $settingsModel->isMobile($settings->data['box']['mobile']) : null));
     return preg_replace('/\\s+/', ' ', trim($template));
 }