/** * Save Resource Tags * * @return void */ private function _saveTagsData() { // save tags $resourcesTags = new Tags($this->record->resource->id); $resourcesTags->setTags($this->record->tags, $this->_user->get('id'), 1, 1); }
/** * Saves changes to the tag list on a resource * Redirects back to main resource listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $entered = Request::getVar('tags', ''); $selected = Request::getVar('tgs', array(0)); // Process tags $tagging = new TagCloud($id); $tagArray = $tagging->parseTags($entered); $tagArray2 = $tagging->parseTags($entered, 1); $diffTags = array_diff($tagArray, $selected); foreach ($diffTags as $diffed) { array_push($selected, $tagArray2[$diffed]); } $tags = implode(',', $selected); $tagging->setTags($tags, User::get('id'), 1); // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=items', false), Lang::txt('COM_RESOURCES_TAGS_UPDATED', $id)); }
/** * Saves a resource * Redirects to main listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Initiate extended database class $row = new Resource($this->database); if (!$row->bind($_POST)) { throw new Exception($row->getError(), 400); } $isNew = 0; if ($row->id < 1) { $isNew = 1; } if ($isNew) { // New entry $row->created = $row->created ? $row->created : Date::toSql(); $row->created_by = $row->created_by ? $row->created_by : User::get('id'); $row->access = 0; } else { $old = new Resource($this->database); $old->load($row->id); $created_by_id = Request::getInt('created_by_id', 0); // Updating entry $row->modified = Date::toSql(); $row->modified_by = User::get('id'); if ($created_by_id) { $row->created_by = $row->created_by ? $row->created_by : $created_by_id; } else { $row->created_by = $row->created_by ? $row->created_by : User::get('id'); } } // publish up $row->publish_up = Date::of($row->publish_up, Config::get('offset'))->toSql(); // publish down if (!$row->publish_down || trim($row->publish_down) == '0000-00-00 00:00:00' || trim($row->publish_down) == 'Never') { $row->publish_down = '0000-00-00 00:00:00'; } else { $row->publish_down = Date::of($row->publish_down, Config::get('offset'))->toSql(); } // Get parameters $params = Request::getVar('params', array(), 'post'); if (is_array($params)) { $txt = new \Hubzero\Config\Registry(''); foreach ($params as $k => $v) { $txt->set($k, $v); } $row->params = $txt->toString(); } // Get attributes $attribs = Request::getVar('attrib', array(), 'post'); if (is_array($attribs)) { $txta = new \Hubzero\Config\Registry(''); foreach ($attribs as $k => $v) { if ($k == 'timeof') { if (strtotime(trim($v)) === false) { $v = NULL; } $v = trim($v) ? Date::of($v, Config::get('offset'))->toSql() : NULL; } $txta->set($k, $v); } $row->attribs = $txta->toString(); } // Get custom areas, add wrappers, and compile into fulltxt if (isset($_POST['nbtag'])) { $type = new Type($this->database); $type->load($row->type); include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'elements.php'; $elements = new \Components\Resources\Models\Elements(array(), $type->customFields); $schema = $elements->getSchema(); $fields = array(); foreach ($schema->fields as $field) { $fields[$field->name] = $field; } $nbtag = $_POST['nbtag']; $found = array(); foreach ($nbtag as $tagname => $tagcontent) { $f = ''; $row->fulltxt .= "\n" . '<nb:' . $tagname . '>'; if (is_array($tagcontent)) { $c = count($tagcontent); $num = 0; foreach ($tagcontent as $key => $val) { if (trim($val)) { $num++; } $row->fulltxt .= '<' . $key . '>' . trim($val) . '</' . $key . '>'; } if ($c == $num) { $f = 'found'; } } else { $f = trim($tagcontent); if ($f) { $row->fulltxt .= trim($tagcontent); } } $row->fulltxt .= '</nb:' . $tagname . '>' . "\n"; if (!$tagcontent && isset($fields[$tagname]) && $fields[$tagname]->required) { throw new Exception(Lang::txt('RESOURCES_REQUIRED_FIELD_CHECK', $fields[$tagname]->label), 500); } $found[] = $tagname; } foreach ($fields as $field) { if (!in_array($field->name, $found) && $field->required) { $found[] = $field->name; $this->setError(Lang::txt('COM_CONTRIBUTE_REQUIRED_FIELD_CHECK', $field->label)); } } } // Code cleaner for xhtml transitional compliance if ($row->type != 7) { $row->introtext = str_replace('<br>', '<br />', $row->introtext); $row->fulltxt = str_replace('<br>', '<br />', $row->fulltxt); } // Check content if (!$row->check()) { throw new Exception($row->getError(), 500); } // Store content if (!$row->store()) { throw new Exception($row->getError(), 500); } // Checkin resource $row->checkin(); // Rename the temporary upload directory if it exist $tmpid = Request::getInt('tmpid', 0, 'post'); if ($tmpid != Html::niceidformat($row->id)) { // Build the full paths $path = Html::dateToPath($row->created); $dir_id = Html::niceidformat($row->id); $tmppath = Utilities::buildUploadPath($path . DS . $tmpid); $newpath = Utilities::buildUploadPath($path . DS . $dir_id); // Attempt to rename the temp directory if (\Filesystem::exists($tmppath)) { $result = \Filesystem::move($tmppath, $newpath); if ($result !== true) { $this->setError($result); } } $row->path = str_replace($tmpid, Html::niceidformat($row->id), $row->path); $row->store(); } // Incoming tags $tags = Request::getVar('tags', '', 'post'); // Save the tags $rt = new Tags($row->id); $rt->setTags($tags, User::get('id'), 1, 1); // Incoming authors if ($row->type != 7) { $authorsOldstr = Request::getVar('old_authors', '', 'post'); $authorsNewstr = Request::getVar('new_authors', '', 'post'); if (!$authorsNewstr) { $authorsNewstr = $authorsOldstr; } include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor.php'; $authorsNew = explode(',', $authorsNewstr); $authorsOld = explode(',', $authorsOldstr); // We have either a new ordering or new authors or both if ($authorsNewstr) { for ($i = 0, $n = count($authorsNew); $i < $n; $i++) { $rc = new Contributor($this->database); $rc->subtable = 'resources'; $rc->subid = $row->id; if (is_numeric($authorsNew[$i])) { $rc->authorid = $authorsNew[$i]; } else { $rc->authorid = $rc->getUserId($authorsNew[$i]); } $rc->ordering = $i; $rc->role = trim(Request::getVar($authorsNew[$i] . '_role', '')); $rc->name = trim(Request::getVar($authorsNew[$i] . '_name', '')); $rc->organization = trim(Request::getVar($authorsNew[$i] . '_organization', '')); $authorsNew[$i] = $rc->authorid; if (in_array($authorsNew[$i], $authorsOld)) { //echo 'update: ' . $rc->authorid . ', ' . $rc->role . ', ' . $rc->name . ', ' . $rc->organization . '<br />'; // Updating record $rc->updateAssociation(); } else { //echo 'create: ' . $rc->authorid . ', ' . $rc->role . ', ' . $rc->name . ', ' . $rc->organization . '<br />'; // New record $rc->createAssociation(); } } } // Run through previous author list and check to see if any IDs had been dropped if ($authorsOldstr) { $rc = new Contributor($this->database); for ($i = 0, $n = count($authorsOld); $i < $n; $i++) { if (!in_array($authorsOld[$i], $authorsNew)) { $rc->deleteAssociation($authorsOld[$i], $row->id, 'resources'); } } } } // If this is a child, add parent/child association $pid = Request::getInt('pid', 0, 'post'); if ($isNew && $pid) { $this->_attachChild($row->id, $pid); } // Is this a standalone resource and we need to email approved submissions? if ($row->standalone == 1 && $this->config->get('email_when_approved')) { // If the state went from pending to published if ($row->published == 1 && $old->published == 3) { $this->_emailContributors($row, $this->database); } } // Redirect App::redirect($this->buildRedirectURL($pid), Lang::txt('COM_RESOURCES_ITEM_SAVED')); }
/** * Saves changes to the tag list on a resource * Redirects back to main resource listing * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $id = Request::getInt('id', 0); $entered = Request::getVar('tags', ''); $selected = Request::getVar('tgs', array(0)); // Process tags $tagging = new TagCloud($id); $tagArray = $tagging->parseTags($entered); $tagArray2 = $tagging->parseTags($entered, 1); $diffTags = array_diff($tagArray, $selected); foreach ($diffTags as $diffed) { array_push($selected, $tagArray2[$diffed]); } $tags = implode(',', $selected); $tagging->setTags($tags, User::get('id'), 1); Notify::success(Lang::txt('COM_RESOURCES_TAGS_UPDATED', $id)); // Redirect $this->cancelTask(); }