public function execute()
 {
     $photo_id = $this->post('id', true);
     if (!is_array($photo_id)) {
         if (strpos($photo_id, ',') !== false) {
             $photo_id = array_map('intval', explode(',', $photo_id));
         } else {
             $photo_id = array($photo_id);
         }
     }
     $tag = waRequest::post('tag', '');
     if (!$tag) {
         $tag = array();
     }
     if (!is_array($tag)) {
         if (strpos($tag, ',') !== false) {
             $tag = explode(',', $tag);
         } else {
             $tag = array($tag);
         }
     }
     $tag = array_map('trim', $tag);
     $tag_model = new photosTagModel();
     $photo_tag_model = new photosPhotoTagsModel();
     $photo_rights_model = new photosPhotoRightsModel();
     $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true);
     if ($allowed_photo_id) {
         $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tag, true));
         $this->response = true;
     } else {
         throw new waAPIException('access_denied', 403);
     }
 }
 public function execute()
 {
     $tag_name = waRequest::get('tag');
     $tag_name = urldecode($tag_name);
     $tag_model = new photosTagModel();
     $tag = $tag_model->getByName($tag_name);
     $title = _w('Tag not found');
     $photos = array();
     $config = $this->getConfig();
     if ($tag) {
         $hash = '/tag/' . $tag_name;
         $collection = new photosCollection($hash);
         $count = $config->getOption('photos_per_page');
         $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count);
         $photos = photosCollection::extendPhotos($photos);
         $title = $collection->getTitle();
         $this->view->assign('frontend_link', photosCollection::getFrontendLink($hash));
         $this->view->assign('total_count', $collection->count());
     }
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
     $this->view->assign('title', $title);
     $this->view->assign('photos', $photos);
     $this->view->assign('big_size', $config->getSize('big'));
     $this->view->assign('sort_method', 'upload_datetime');
     $this->template = 'templates/actions/photo/PhotoList.html';
 }
 /**
  *
  * 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;
 }
 public function execute()
 {
     if (!$this->getRights('upload')) {
         throw new waRightsException(_w("You don't have sufficient access rights"));
     }
     $groups_model = new waGroupModel();
     $this->view->assign('groups', $groups_model->getNames());
     $photo_tag_model = new photosTagModel();
     $cloud = $photo_tag_model->getCloud('name');
     $this->view->assign('cloud', $cloud);
 }
 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 execute()
 {
     if ($this->getRights('upload')) {
         $this->executeAction('upload_dialog', new photosUploadAction());
     }
     $album_model = new photosAlbumModel();
     $albums = $album_model->getAlbums();
     $top_level_albums_count = 0;
     foreach ($albums as $a) {
         if (!$a['parent_id']) {
             $top_level_albums_count++;
         }
     }
     /**
      * Extend photo toolbar in photo-page
      * Add extra item to toolbar
      * @event backend_photo_toolbar
      * @return array[string][string]string $return[%plugin_id%]['edit_menu'] Extra item for edit_menu in photo_toolbar
      * @return array[string][string]string $return[%plugin_id%]['share_menu'] Extra item for edit_menu in photo_toolbar
      */
     $this->view->assign('backend_photo_toolbar', wa()->event('backend_photo_toolbar'));
     $tree = new photosViewTree($albums);
     $this->view->assign('albums', $tree->display());
     $this->view->assign('albums_count', count($albums));
     $this->view->assign('top_level_albums_count', $top_level_albums_count);
     $this->view->assign('app_albums', self::getAppAlbums());
     $collection = new photosCollection();
     $collection_rated = new photosCollection('search/rate>0');
     $this->view->assign('count', $collection->count());
     $this->view->assign('rated_count', $collection_rated->count());
     $this->view->assign('last_login_datetime', $this->getConfig()->getLastLoginTime());
     /**
      * Extend sidebar
      * Add extra item to sidebar
      * @event backend_sidebar
      * @return array[string][string]string $return[%plugin_id%]['menu'] Extra item for menu in sidebar
      * @return array[string][string]string $return[%plugin_id%]['section'] Extra section in sidebar
      */
     $this->view->assign('backend_sidebar', wa()->event('backend_sidebar'));
     /**
      * Include plugins js and css
      * @event backend_assets
      * @return array[string]string $return[%plugin_id%] Extra head tag content
      */
     $this->view->assign('backend_assets', wa()->event('backend_assets'));
     $photo_tag_model = new photosTagModel();
     $this->view->assign('cloud', $photo_tag_model->getCloud());
     $this->view->assign('popular_tags', $photo_tag_model->popularTags());
     $this->view->assign('rights', array('upload' => $this->getRights('upload'), 'edit' => $this->getRights('edit')));
     $config = $this->getConfig();
     $this->view->assign('big_size', $config->getSize('big'));
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
 }
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $album_model = new photosAlbumModel();
     $album = $album_model->getById($id);
     if (!$album) {
         throw new waException(_w("Unknown album"), 404);
     }
     $album_right_model = new photosAlbumRightsModel();
     if (!$album_right_model->checkRights($album, true)) {
         throw new waException(_w("You don't have sufficient access rights"), 403);
     }
     if ($album['type'] == photosAlbumModel::TYPE_DYNAMIC && $album['conditions']) {
         $album['conditions'] = photosCollection::parseConditions($album['conditions']);
     }
     if (!$album['conditions']) {
         $album['conditions'] = array();
     }
     $absolute_full_url = photosFrontendAlbum::getLink($album);
     if ($absolute_full_url) {
         $pos = strrpos($absolute_full_url, $album['url']);
         $full_base_url = $pos !== false ? rtrim(substr($absolute_full_url, 0, $pos), '/') . '/' : '';
         $album['full_base_url'] = $full_base_url;
     }
     $this->view->assign('album', $album);
     if ($album['parent_id']) {
         $this->view->assign('parent', $album_model->getById($album['parent_id']));
     }
     $collection = new photosCollection('album/' . $id);
     $photos_count = $collection->count();
     $this->view->assign('photos_count', $photos_count);
     $album_params_model = new photosAlbumParamsModel();
     $this->view->assign('params', $album_params_model->get($id));
     $groups_model = new waGroupModel();
     $groups = $groups_model->getAll('id', true);
     $rights = $album_right_model->getByField('album_id', $id, 'group_id');
     $photo_tag_model = new photosTagModel();
     $cloud = $photo_tag_model->getCloud('name');
     if (!empty($album['conditions']['tag'][1])) {
         foreach ($album['conditions']['tag'][1] as $tag_name) {
             $cloud[$tag_name]['checked'] = true;
         }
     }
     $this->view->assign('rights', $rights);
     $this->view->assign('groups', $groups);
     $this->view->assign('cloud', $cloud);
 }
 public function execute()
 {
     if (!$this->getRights('upload')) {
         throw new waRightsException(_w("You don't have sufficient access rights"));
     }
     $parent_id = waRequest::get('parent_id', 0, waRequest::TYPE_INT);
     $parent = null;
     if ($parent_id) {
         $album_model = new photosAlbumModel();
         $parent = $album_model->getById($parent_id);
     }
     $this->view->assign('parent', $parent);
     $groups_model = new waGroupModel();
     $this->view->assign('groups', $groups_model->getNames());
     $photo_tag_model = new photosTagModel();
     $cloud = $photo_tag_model->getCloud('name');
     $this->view->assign('cloud', $cloud);
 }
Beispiel #9
0
 /**
  * Delete by id with taking into account case of stack.
  *
  * If deleting photo is single photo then just delete photo.
  * If deleting photo is parent of stack then first of all make unstack
  * If deleting photo is children photo in stack then after deleting photo decrease stack
  *
  * @param int $id
  */
 public function delete($id)
 {
     $id = (int) $id;
     if (!$id) {
         return;
     }
     $parent = $this->getStackParent($id);
     if ($parent && $parent['id'] == $id) {
         $this->unstack($id);
     }
     // first of all try delete from disk
     $photo = $this->getById($id);
     $path = photosPhoto::getPhotoPath($photo);
     $thumb_dir = photosPhoto::getPhotoThumbDir($photo);
     waFiles::delete(dirname($path));
     waFiles::delete($thumb_dir);
     // delete some related models
     $related_models = array('AlbumPhotos', 'PhotoExif', 'PhotoRights');
     foreach ($related_models as $name) {
         $model_name = 'photos' . $name . 'Model';
         $model = new $model_name();
         $model->deleteByField('photo_id', $id);
     }
     // especial deleting rest models:
     //  tags
     $photo_tags_model = new photosPhotoTagsModel();
     $tags_model = new photosTagModel();
     $tag_ids = array_keys($photo_tags_model->getByField('photo_id', $id, 'tag_id'));
     $photo_tags_model->deleteByField('photo_id', $id);
     $tags_model->decreaseCounters($tag_ids);
     // delete photo(s) itself
     $this->deleteById($id);
     // if deleted just one photo in stack (not stack itself)
     if ($parent && $parent['id'] != $id) {
         $stack_count = $parent['stack_count'] - 1;
         $stack_count = $stack_count > 1 ? $stack_count : 0;
         $sql = "UPDATE {$this->table} SET stack_count = i:stack_count WHERE id = i:id";
         $this->exec($sql, array('id' => $parent['id'], 'stack_count' => $stack_count));
     }
 }
 public function execute()
 {
     $photo_id = waRequest::post('photo_id', array(), waRequest::TYPE_ARRAY_INT);
     $one_photo = waRequest::post('one_photo', 0, waRequest::TYPE_INT);
     $tags = waRequest::post('tags', '', waRequest::TYPE_STRING_TRIM);
     $tags = $tags ? explode(',', $tags) : array();
     $delete_tags = waRequest::post('delete_tags', array(), waRequest::TYPE_ARRAY_INT);
     $tag_model = new photosTagModel();
     $photo_tag_model = new photosPhotoTagsModel();
     $photo_rights_model = new photosPhotoRightsModel();
     $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true);
     $denied_photo_id = array_values(array_diff($photo_id, $allowed_photo_id));
     if ($allowed_photo_id) {
         if ($one_photo) {
             $allowed_photo_id = $allowed_photo_id[0];
             $photo_tag_model->set($allowed_photo_id, $tags);
             $photo_model = new photosPhotoModel();
             if ($parent_id = $photo_model->getStackParentId($allowed_photo_id)) {
                 $this->response['parent_id'] = $parent_id;
             }
         } else {
             if ($delete_tags) {
                 $photo_tag_model->delete($allowed_photo_id, $delete_tags);
             }
             $photo_tag_model->assign($allowed_photo_id, $tag_model->getIds($tags, true));
         }
         $allowed_photo_id = (array) $allowed_photo_id;
         $tags = $photo_tag_model->getTags($allowed_photo_id);
         if (!$tags && $allowed_photo_id) {
             $tags = array_fill_keys($allowed_photo_id, array());
         }
         $this->response['tags'] = $tags;
     }
     if ($denied_photo_id) {
         $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") . '.';
     }
     $this->response['cloud'] = $tag_model->getCloud();
 }
 private function _set($photo_id, $tag_ids = array())
 {
     $tag_model = new photosTagModel();
     $delete_photo_tags = $this->getByField('photo_id', $photo_id, 'tag_id');
     foreach ($tag_ids as $tag_id) {
         if (!isset($delete_photo_tags[$tag_id])) {
             $this->insert(array('photo_id' => $photo_id, 'tag_id' => $tag_id));
             $tag_model->query('UPDATE ' . $tag_model->getTableName() . ' SET count = count + 1 WHERE id = i:id', array('id' => $tag_id));
         } else {
             unset($delete_photo_tags[$tag_id]);
         }
     }
     $delete_tag_ids = array_keys($delete_photo_tags);
     $this->deleteByField(array('tag_id' => $delete_tag_ids, 'photo_id' => $photo_id));
     $tag_model->decreaseCounters($delete_tag_ids);
     return true;
 }
 protected function tagPrepareIntersection($tag_names)
 {
     $tag_model = new photosTagModel();
     $in = array();
     $title = array();
     foreach (explode(',', $tag_names) as $tag_name) {
         $tag = $tag_model->getByName($tag_name);
         if ($tag) {
             $in[] = (int) $tag['id'];
             $title[] = $tag['name'];
         }
     }
     if (!$in) {
         $this->where[] = "0";
     } else {
         $sql = "SELECT photo_id, COUNT(tag_id) cnt FROM `photos_photo_tags` \n                WHERE tag_id IN (" . implode(',', $in) . ")\n                GROUP BY photo_id\n                HAVING cnt = " . count($in);
         $photo_id = array_keys($tag_model->query($sql)->fetchAll('photo_id'));
         if ($photo_id) {
             $this->where[] = "p.id IN (" . implode(',', $photo_id) . ")";
             $this->addTitle(sprintf(_w('Tagged “%s”'), implode(',', $title)));
         } else {
             $this->where[] = "0";
         }
     }
 }
 protected function tagPrepare($id, $auto_title = true)
 {
     $tag_model = new photosTagModel();
     $tag = false;
     if (is_numeric($id)) {
         $tag = $tag_model->getById($id);
     }
     if (!$tag) {
         $tag = $tag_model->getByName($id);
         $id = $tag['id'];
     }
     $this->joins['tags'] = array('table' => 'photos_photo_tags', 'alias' => 'pt');
     $this->where[] = "pt.tag_id = " . (int) $id;
     $this->addTitle(sprintf(_w('Tagged “%s”'), $tag['name']));
 }