public function execute()
 {
     $this->init();
     $url = trim(waRequest::param('url', '', waRequest::TYPE_STRING_TRIM), '/');
     if (!$url) {
         throw new waException(_w('Page not found', 404));
     }
     $this->route($url);
     if (!$this->album) {
         throw new waException(_w('Page not found', 404));
     }
     $this->album = photosFrontendAlbum::escapeFields($this->album);
     // retrieve user params
     $album_params_model = new photosAlbumParamsModel();
     $params = $album_params_model->get($this->album['id']);
     $params = photosPhoto::escape($params);
     $this->album += $params;
     // "childcrumbs" - list of childs (sub-albums). Use in 'plain' template
     $childcrumbs = $this->album_model->getChildcrumbs($this->album['id'], true);
     waRequest::setParam('breadcrumbs', $this->album_model->getBreadcrumbs($this->album['id'], true));
     waRequest::setParam('nofollow', $this->album['status'] <= 0 ? true : false);
     waRequest::setParam('disable_sidebar', true);
     $this->setThemeTemplate('album.html');
     $this->view->assign('album', $this->album);
     $this->view->assign('childcrumbs', $childcrumbs);
     $this->getResponse()->addJs('js/common.js?v=' . wa()->getVersion(), true);
     $this->finite();
 }
 public function execute()
 {
     $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
     if (in_array($name, $this->availableFields) === false) {
         throw new waException(_w("Can't update album: unknown field"));
     }
     $album_rights_model = new photosAlbumRightsModel();
     $id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT);
     if (is_array($id)) {
         $id = current($id);
     }
     if ($id) {
         $album_model = new photosAlbumModel();
         $album = $album_model->getById($id);
         if (!$album) {
             throw new waException(_w('Unknown album'));
         }
         if (!$album_rights_model->checkRights($album, true)) {
             throw new waException(_w("You don't have sufficient access rights"));
         }
         $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM);
         $album_model->updateById($id, array($name => $value));
         $album['not_escaped_name'] = $value;
         $album['name'] = photosPhoto::escape($value);
         $this->response['album'] = $album;
     }
 }
 public function execute()
 {
     $action = waRequest::param('action', 'default');
     $disable_sidebar = waRequest::param('disable_sidebar', false);
     $this->view->assign('action', $action);
     $this->view->assign('breadcrumbs', waRequest::param('breadcrumbs', array()));
     if (!$this->getResponse()->getTitle()) {
         $title = waRequest::param('title') ? photosPhoto::escape(waRequest::param('title')) : wa()->accountName();
         $this->getResponse()->setTitle($title);
     }
     $this->view->assign('nofollow', waRequest::param('nofollow', false));
     $this->view->assign('disable_sidebar', $disable_sidebar);
     /**
      * Include plugins js and css
      * @event frontend_assets
      * @return array[string][string]string $return[%plugin_id%] Extra header data (css/js/meta)
      */
     $this->view->assign('frontend_assets', wa()->event('frontend_assets'));
     /**
      * @event frontend_layout
      * @return array[string][string]string $return[%plugin_id%]['header'] Header menu section
      * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section
      */
     $this->view->assign('frontend_layout', wa()->event('frontend_layout'));
     /**
      * @event frontend_sidebar
      * @return array[string][string]string $return[%plugin_id%]['menu'] Sidebar menu item
      * @return array[string][string]string $return[%plugin_id%]['section'] Sidebar section item
      */
     $this->view->assign('frontend_sidebar', wa()->event('frontend_sidebar'));
     $this->setThemeTemplate('index.html');
 }
 protected function workupPhotos(&$photos)
 {
     foreach ($photos as &$photo) {
         $photo['name'] = photosPhoto::escape($photo['name']);
     }
     unset($photo);
     return $photos;
 }
 /**
  *
  * Get photos tags list
  * @return array
  */
 public function tags()
 {
     $photo_tag_model = new photosTagModel();
     $cloud = $photo_tag_model->getCloud();
     foreach ($cloud as &$tag) {
         $tag['name'] = photosPhoto::escape($tag['name']);
     }
     unset($tag);
     return $cloud;
 }
Ejemplo n.º 6
0
 public function execute()
 {
     $query = waRequest::request('q', '', waRequest::TYPE_STRING_TRIM);
     $tag_model = new photosTagModel();
     $tags = $tag_model->select('name')->where("name LIKE '" . $tag_model->escape($query, 'like') . "%'")->fetchAll('name', true);
     $tags = array_keys($tags);
     foreach ($tags as &$tag) {
         $tag = photosPhoto::escape($tag);
     }
     unset($tag);
     echo implode("\n", $tags);
 }
 public function finite()
 {
     $collection = new photosCollection($this->hash);
     $photos = $collection->getPhotos("*,thumb,frontend_link,tags", $this->offset, $this->photos_per_page);
     $photos = photosCollection::extendPhotos($photos);
     if ($this->hash) {
         $title = $collection->getTitle();
         if (!$title) {
             $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName());
         } else {
             $this->getResponse()->setTitle($title);
         }
         $this->view->assign('title', photosPhoto::escape($title));
     } else {
         $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName());
         $this->getResponse()->setMeta('keywords', waRequest::param('meta_keywords'));
         $this->getResponse()->setMeta('description', waRequest::param('meta_description'));
         $this->view->assign('title', '');
     }
     $this->workupPhotos($photos);
     $total_count = $collection->count();
     $this->view->assign('photos_per_page', $this->photos_per_page);
     $this->view->assign('pages_count', floor($total_count / $this->photos_per_page) + 1);
     $this->view->assign('total_photos_count', $total_count);
     $this->view->assign('offset', $this->offset);
     $this->view->assign('photos', $photos);
     $is_xhr = waRequest::isXMLHttpRequest();
     $this->view->assign('is_xhr', $is_xhr);
     if ($is_xhr) {
         $this->view->assign('frontend_collection', array());
     } else {
         /**
          * @event frontend_collection
          * @return array[string][string]string $return[%plugin_id%]['name'] Extra name info
          * @return array[string][string]string $return[%plugin_id%]['content'] Extra album description and etc
          * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section
          * @return array[string][string]string $return[%plugin_id%]['sidebar'] Footer section
          * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section
          */
         $this->view->assign('frontend_collection', wa()->event('frontend_collection'));
     }
     $this->view->assign('lazy_load', !is_null(waRequest::get('lazy')));
     $v = wa()->getVersion();
     $this->getResponse()->addJs('js/lazy.load.js?v=' . $v, true);
     $this->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true);
 }
 public function display($view_type = 'backend')
 {
     $result = $view_type == 'backend' ? '<li class="dr ' . $this->getClass() . '" rel="' . $this->data['id'] . '"><span class="count">' . (!is_null($this->data['count']) ? $this->data['count'] : '') . '</span>' : '<li>';
     if ($this->childs) {
         $result .= $view_type == 'backend' ? '<i class="icon16 darr overhanging collapse-handler" id="album-' . $this->data['id'] . '-handler"></i>' : '';
     }
     $result .= $view_type == 'backend' ? '<a href="' . $this->getHash() . '"><i class="icon16 ' . $this->getIcon() . '"></i>' . photosPhoto::escape($this->data['name']) . ' ' . $this->getStatusIcon() . ' <strong class="small highlighted count-new">' . (!empty($this->data['count_new']) ? '+' . $this->data['count_new'] : '') . '</strong></a>' : '<a href="' . photosFrontendAlbum::getLink($this->data) . '">' . photosPhoto::escape($this->data['name']) . '</a>';
     if ($this->childs) {
         $result .= $view_type == 'backend' ? '<ul class="menu-v with-icons"><li class="drag-newposition"></li>' : '<ul class="menu-v">';
         foreach ($this->childs as $e) {
             $result .= $e->display($view_type);
         }
         $result .= '</ul>';
     }
     $result .= $view_type == 'backend' ? '</li><li class="drag-newposition"></li>' : '</li>';
     return $result;
 }
 public function execute()
 {
     $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
     if (in_array($name, $this->availableFields) === false) {
         throw new waException("Can't update photo: unknown field");
     }
     $photo_id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT);
     $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM);
     if ($photo_id) {
         $photo_rights_model = new photosPhotoRightsModel();
         if (count($photo_id) == 1) {
             // editing only one photo
             if (!$photo_rights_model->checkRights(current($photo_id), true)) {
                 throw new waException(_w("You don't have sufficient access rights"));
             }
             // validations for one photo
             if ($name == 'url') {
                 if (!$this->validateUrl($value, current($photo_id))) {
                     // $photo_id is array of ids, so make current()
                     $this->errors['url'] = _w('URL is in use');
                     return;
                 }
             }
             $allowed_photo_id = $photo_id;
             $denied_photo_id = array();
         } else {
             $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true);
             $denied_photo_id = array_diff($photo_id, $allowed_photo_id);
         }
         if ($allowed_photo_id) {
             if ($name == 'rate') {
                 $value = (int) $value;
                 if ($value < 0 || $value > 5) {
                     $value = 0;
                 }
             }
             $data[$name] = $value;
             $this->photo_model = new photosPhotoModel();
             if ($name == 'description' || $name == 'rate') {
                 $this->photo_model->update($allowed_photo_id, $data);
                 if (count($photo_id) == 1 && $allowed_photo_id) {
                     // means that we edit field in one-photo page
                     $photo_id = current($photo_id);
                     if ($parent_id = $this->photo_model->getStackParentId($photo_id)) {
                         $this->response['parent_id'] = $parent_id;
                     }
                 }
                 // change count of rated
                 if ($name == 'rate') {
                     $this->response['count'] = $this->photo_model->countRated();
                     $this->log('photos_rate', 1);
                 }
             } else {
                 // update only parent photo(s)
                 $this->photo_model->updateById($allowed_photo_id, $data);
             }
             if ($name == 'name') {
                 $this->response['value'] = photosPhoto::escape($value);
             }
         }
         if (count($denied_photo_id) > 0 && count($photo_id) > 0) {
             $this->response['alert_msg'] = photosPhoto::sprintf_wplural("The operation was not performed to %d photo (%%s)", "The operation was not performed to %d photos (%%s)", count($denied_photo_id), _w("out of %d selected", "out of %d selected", count($photo_id))) . ', ' . _w("because you don't have sufficient access rights") . '.';
         }
         $allowed_photo_id_map = array();
         foreach ($allowed_photo_id as $id) {
             $allowed_photo_id_map[$id] = true;
         }
         $this->response['allowed_photo_id'] = $allowed_photo_id_map;
     }
 }
 public function execute()
 {
     $this->id = waRequest::post('id', null, waRequest::TYPE_INT);
     $group_ids = null;
     $status = waRequest::post('status', 0, waRequest::TYPE_INT);
     if (!$status) {
         $group_ids = waRequest::post('groups', array(), waRequest::TYPE_ARRAY_INT);
         if (!$group_ids) {
             // visible only for creator
             $status = -1;
             $group_ids = array(-$this->getUser()->getId());
         }
     }
     $this->album_model = new photosAlbumModel();
     if (!$this->id) {
         if (!$this->getRights('upload')) {
             throw new waException(_w("You don't have sufficient access rights"));
         }
         $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
         $type = waRequest::post('type', 0, waRequest::TYPE_INT);
         $data = array('name' => $name, 'status' => $status, 'type' => $type, 'group_ids' => $group_ids);
         if ($status <= 0) {
             $data['hash'] = md5(uniqid(time(), true));
         } else {
             $data['url'] = $this->album_model->suggestUniqueUrl(photosPhoto::suggestUrl($name));
         }
         if ($type == photosAlbumModel::TYPE_DYNAMIC) {
             $data['conditions'] = $this->getPrepareConditions();
         }
         $this->save($data);
         $this->response = array('id' => $this->id, 'name' => photosPhoto::escape($name), 'type' => $type, 'status' => $status);
     } else {
         $album_rights_model = new photosAlbumRightsModel();
         if (!$album_rights_model->checkRights($this->id, true)) {
             throw new waException(_w("You don't have sufficient access rights"));
         }
         $conditions = $this->getPrepareConditions();
         $params = array();
         $album_params = waRequest::post('params', '', waRequest::TYPE_STRING_TRIM);
         $album_params = explode(PHP_EOL, $album_params);
         foreach ($album_params as $param) {
             $param = explode('=', $param);
             if (count($param) < 2) {
                 continue;
             }
             $params[$param[0]] = $param[1];
         }
         $params = $params ? $params : null;
         $description = waRequest::post('description', null, waRequest::TYPE_STRING_TRIM);
         $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM);
         $url = waRequest::post('url', null, waRequest::TYPE_STRING_TRIM);
         $data = array('status' => $status, 'group_ids' => $group_ids, 'conditions' => $conditions, 'url' => $url, 'description' => $description, 'params' => $params, 'name' => $name);
         if ($status <= 0) {
             $data['hash'] = md5(uniqid(time(), true));
         }
         if (waRequest::post('order') == 'rate') {
             $data['params']['order'] = 'rate';
         }
         if (!$this->validate($data)) {
             return;
         }
         $this->save($data);
         $apply_all_photos = waRequest::post('apply_all_photos', 0, waRequest::TYPE_INT);
         if ($apply_all_photos) {
             // apply to first of $count photos
             $count = waRequest::post('count', 50, waRequest::TYPE_INT);
             $collection = new photosCollection('album/' . $this->id);
             $total_count = $collection->count();
             $photos = $collection->getPhotos('*', 0, $count, false);
             $photo_model = new photosPhotoModel();
             $photo_ids = array();
             foreach ($photos as $photo) {
                 if ($photo['status'] == 1 && $status == 1) {
                     continue;
                 }
                 if ($photo['stack_count'] > 0) {
                     $photo_ids = array_merge($photo_ids, $photo_model->getIdsByParent($photo['id']));
                 } else {
                     $photo_ids[] = $photo['id'];
                 }
             }
             $photo_rights_model = new photosPhotoRightsModel();
             $allowed_photo_ids = $photo_rights_model->filterAllowedPhotoIds($photo_ids, true);
             $photo_model->updateAccess($allowed_photo_ids, $status, $group_ids);
             $this->response['total_count'] = $total_count;
             $this->response['count'] = $count;
             $this->response['status'] = $status;
             $this->response['groups'] = $group_ids;
         }
     }
 }
 public function getAuthorInfo($author)
 {
     $wa_app_url = wa()->getAppUrl(null, false);
     $datetime = waDateTime::format('humandatetime', $author['photo_upload_datetime']);
     $html = '<a href="' . $wa_app_url . 'author/' . $author['id'] . '/">' . photosPhoto::escape($author['name']) . '</a> ' . _w('on') . ' ' . $datetime;
     return $html;
 }
Ejemplo n.º 12
0
 public static function escapeFields($photo)
 {
     // escape
     $photo['name'] = photosPhoto::escape($photo['name']);
     //         $photo['description'] = photosPhoto::escape($photo['description']);
     $photo['url'] = photosPhoto::escape($photo['url']);
     return $photo;
 }
 /**
  * Get "childcrumbs" (sub-albums) for album (list of childrens)
  * @param int $id
  * @param bool $escape
  * @return array of items array('name' => '..', 'full_url' => '..')
  */
 public function getChildcrumbs($id, $escape = false)
 {
     $sql = "SELECT id, full_url, name, note FROM {$this->table} WHERE parent_id = i:id AND status = 1";
     $result = $this->query($sql, array('id' => $id));
     $childcrumbs = array();
     foreach ($result as $album) {
         $childcrumbs[] = array('id' => $album['id'], 'name' => $escape ? photosPhoto::escape($album['name']) : $album['name'], 'full_url' => photosFrontendAlbum::getLink($album), 'note' => $escape ? photosPhoto::escape($album['note']) : $album['note']);
     }
     return $childcrumbs;
 }
 public static function escapeFields($album)
 {
     // escape
     $album['name'] = photosPhoto::escape($album['name']);
     return $album;
 }
 public function execute()
 {
     $id = waRequest::post('id', 0, waRequest::TYPE_INT);
     $in_stack = waRequest::post('in_stack', 0, waRequest::TYPE_INT);
     $hash = waRequest::post('hash', null, waRequest::TYPE_STRING_TRIM);
     $hash = urldecode($hash);
     // get photo
     $this->photo_model = new photosPhotoModel();
     $this->photo = $this->photo_model->getById($id);
     if (!$this->photo) {
         throw new waException(_w("Photo doesn't exists"), 404);
     }
     $photo_rights_model = new photosPhotoRightsModel();
     if (!$photo_rights_model->checkRights($this->photo)) {
         throw new waRightsException(_w("You don't have sufficient access rights"));
     }
     $this->photo['name_not_escaped'] = $this->photo['name'];
     $this->photo = photosPhoto::escapeFields($this->photo);
     $this->photo['upload_datetime_formatted'] = waDateTime::format('humandate', $this->photo['upload_datetime']);
     $this->photo['upload_timestamp'] = strtotime($this->photo['upload_datetime']);
     $this->photo['edit_rights'] = $photo_rights_model->checkRights($this->photo, true);
     $this->photo['private_url'] = photosPhotoModel::getPrivateUrl($this->photo);
     $this->photo['thumb'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getThumbPhotoSize());
     $this->photo['thumb_big'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getBigPhotoSize());
     $this->photo['thumb_middle'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getMiddlePhotoSize());
     $original_photo_path = photosPhoto::getOriginalPhotoPath($this->photo);
     if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) {
         $this->photo['original_exists'] = true;
     } else {
         $this->photo['original_exists'] = false;
     }
     $photo_tags_model = new photosPhotoTagsModel();
     $tags = $photo_tags_model->getTags($id);
     $this->photo['tags'] = $tags;
     $this->response['photo'] = $this->photo;
     // get stack if it's possible
     if (!$in_stack && ($stack = $this->photo_model->getStack($id, array('thumb' => true, 'thumb_crop' => true, 'thumb_big' => true, 'thumb_middle' => true)))) {
         $this->response['stack'] = $stack;
     }
     // get albums
     $album_photos_model = new photosAlbumPhotosModel();
     $albums = $album_photos_model->getAlbums($id, array('id', 'name'));
     $this->response['albums'] = isset($albums[$id]) ? array_values($albums[$id]) : array();
     // exif info
     $exif_model = new photosPhotoExifModel();
     $exif = $exif_model->getByPhoto($this->photo['id']);
     if (isset($exif['DateTimeOriginal'])) {
         $exif['DateTimeOriginal'] = waDateTime::format('humandatetime', $exif['DateTimeOriginal'], date_default_timezone_get());
     }
     $this->response['exif'] = $exif;
     // get author
     $contact = new waContact($this->photo['contact_id']);
     $this->response['author'] = array('id' => $contact['id'], 'name' => photosPhoto::escape($contact['name']), 'photo_url' => $contact->getPhoto(photosPhoto::AUTHOR_PHOTO_SIZE), 'backend_url' => $this->getConfig()->getBackendUrl(true) . 'contacts/#/contact/' . $contact['id']);
     // for making inline-editable widget
     $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%'));
     $hooks = array();
     $parent_id = $this->photo_model->getStackParentId($this->photo);
     $photo_id = $parent_id ? $parent_id : $id;
     /**
      * Extend photo page
      * Add extra widget(s)
      * @event backend_photo
      * @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo any widget
      */
     $hooks['backend_photo'] = wa()->event('backend_photo', $photo_id);
     $this->response['hooks'] = $hooks;
     if ($hash !== null) {
         $collection = new photosCollection($hash);
         if (strstr($hash, 'rate>0') !== false) {
             $collection->orderBy('p.rate DESC, p.id');
         }
         $this->response['photo_stream'] = $this->getPhotoStream($collection);
         if ($collection->getAlbum()) {
             $this->response['album'] = $collection->getAlbum();
         }
     }
 }
 /**
  * Get breadcrumbs for album (list of parents)
  * @param int $id
  * @param boolean $escape
  * @param boolean $use_itself
  * @return array of items array('name' => '..', 'full_url' => '..')
  */
 public function getBreadcrumbs($album_id, $escape = false, $use_itself = false)
 {
     $breadcrumbs = array();
     while ($album_id) {
         $sql = "SELECT id, full_url, parent_id, name, status FROM {$this->table} WHERE id = i:id AND status = 1";
         $album = $this->query($sql, array('id' => $album_id))->fetch();
         if ($album) {
             $url = photosFrontendAlbum::getLink($album);
             $breadcrumbs[] = array('album_id' => $album['id'], 'name' => $escape ? photosPhoto::escape($album['name']) : $album['name'], 'full_url' => $url, 'url' => $url, 'status' => $album['status']);
             $album_id = $album['parent_id'];
         } else {
             $album_id = null;
         }
     }
     $breadcrumbs = array_reverse($breadcrumbs);
     if (!$use_itself) {
         array_pop($breadcrumbs);
     }
     return $breadcrumbs;
 }