Exemple #1
0
 /**
  * Append a tag to the existing tag list
  *
  * @param   mixed  $tag
  * @return  void
  */
 public function append($tag)
 {
     if (!isset($this->_cache['tags'])) {
         $this->_cache['tags'] = new ItemList(array());
     }
     if (!$tag) {
         return;
     }
     if (!$tag instanceof Tag) {
         $tg = new Tag($tag);
         $tg->set('raw_tag', $tag);
         $tag = $tg;
     }
     $this->_cache['tags']->add($tag);
 }
Exemple #2
0
 /**
  * Copy all tag associations from one tag to another
  *
  * @return     void
  */
 public function pierceTask()
 {
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     $step = Request::getInt('step', 1);
     $step = $step ? $step : 1;
     // Make sure we have some IDs to work with
     if ($step == 1 && (!$ids || count($ids) < 1)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     $idstr = implode(',', $ids);
     switch ($step) {
         case 1:
             Request::setVar('hidemainmenu', 1);
             $this->view->step = 2;
             $this->view->idstr = $idstr;
             $this->view->tags = array();
             // Loop through the IDs of the tags we want to merge
             foreach ($ids as $id) {
                 // Load the tag's info
                 $this->view->tags[] = new Tag(intval($id));
             }
             // Get all tags
             $cloud = new Cloud();
             // Set any errors
             if ($this->getError()) {
                 $this->view->setError($this->getError());
             }
             // Output the HTML
             $this->view->display();
             break;
         case 2:
             // Check for request forgeries
             Request::checkToken();
             // Get the string of tag IDs we plan to merge
             $ind = Request::getVar('ids', '', 'post');
             if ($ind) {
                 $ids = explode(',', $ind);
             } else {
                 $ids = array();
             }
             // Incoming
             $tag_exist = Request::getInt('existingtag', 0, 'post');
             $tag_new = Request::getVar('newtag', '', 'post');
             // Are we merging tags into a totally new tag?
             if ($tag_new) {
                 // Yes, we are
                 $newtag = new Tag($tag_new);
                 if (!$newtag->exists()) {
                     $newtag->set('raw_tag', $tag_new);
                 }
                 if (!$newtag->store(true)) {
                     $this->setError($newtag->getError());
                 }
                 $mtag = $newtag->get('id');
             } else {
                 // No, we're merging into an existing tag
                 $mtag = $tag_exist;
             }
             foreach ($ids as $id) {
                 if ($mtag == $id) {
                     continue;
                 }
                 $oldtag = new Tag(intval($id));
                 if (!$oldtag->copyTo($mtag)) {
                     $this->setError($oldtag->getError());
                 }
             }
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TAGS_TAGS_COPIED'));
             break;
     }
 }
 /**
  * Update an entry
  *
  * @return  void
  */
 public function updateTask()
 {
     $this->requiresAuthentication();
     $id = Request::getInt('id', 0);
     $tag = Request::getVar('tag', null);
     $raw = Request::getVar('raw_tag', null);
     $label = Request::getVar('label', null);
     $admin = Request::getInt('admin', 0);
     $subs = Request::getVar('substitutes', null);
     if (!$id) {
         throw new Exception(Lang::txt('COM_TAGS_ERROR_MISSING_DATA'), 500);
     }
     $record = new Tag($id);
     if (!$record->exists()) {
         $record->set('admin', $admin ? 1 : 0);
         if ($raw_tag) {
             $record->set('raw_tag', $raw_tag);
         }
         if ($tag) {
             $record->set('tag', $tag);
         }
         $record->set('label', $label);
         $record->set('substitutions', $subs);
         if (!$record->store(true)) {
             throw new Exception($record->getError(), 500);
         }
     }
     $this->send($record->toObject());
 }