Пример #1
0
 /**
  * Remove one or more types
  *
  * @return  void  Redirects back to main listing
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.delete', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming (expecting an array)
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Ensure we have an ID to work with
     if (empty($ids)) {
         // Redirect with error message
         Notify::warning(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     $i = 0;
     foreach ($ids as $id) {
         // Check if the type is being used
         $rt = Type::oneOrFail($id);
         $usage = Resource::all()->whereEquals('type', $id)->total();
         if ($usage) {
             Notify::error(Lang::txt('COM_RESOURCES_TYPE_BEING_USED', $id));
             continue;
         }
         // Delete the type
         if (!$rt->destroy()) {
             Notify::error($rt->getError());
             continue;
         }
         $i++;
     }
     if ($i) {
         Notify::success(Lang::txt('COM_RESOURCES_ITEMS_REMOVED', $i));
     }
     // Redirect
     $this->cancelTask();
 }
Пример #2
0
 /**
  * Edit a role
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     Request::setVar('hidemainmenu', 1);
     if (!is_object($row)) {
         // Incoming (expecting an array)
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = !empty($id) ? $id[0] : 0;
         }
         $row = Role::oneOrNew($id);
     }
     if ($row->isNew()) {
         $row->set('created_by', User::get('id'));
         $row->set('created', Date::toSql());
     }
     $types = Type::getMajorTypes();
     // Set any errors
     foreach ($this->getErrors() as $error) {
         Notify::error($error);
     }
     // Output the HTML
     $this->view->set('row', $row)->set('types', $types)->setLayout('edit')->display();
 }
Пример #3
0
 /**
  * Parse the segments of a URL.
  *
  * @param   array  &$segments  The segments of the URL to parse.
  * @return  array  The URL attributes to be used by the application.
  */
 public function parse(&$segments)
 {
     $vars = array();
     if (empty($segments[0])) {
         return $vars;
     }
     if (is_numeric($segments[0])) {
         $vars['id'] = $segments[0];
     } elseif (in_array($segments[0], array('browse', 'license', 'sourcecode', 'plugin'))) {
         $vars['task'] = $segments[0];
     } elseif (in_array($segments[0], array('new', 'draft', 'start', 'retract', 'delete', 'discard', 'remove', 'reorder', 'access'))) {
         $vars['task'] = $segments[0];
         $vars['controller'] = 'create';
         if (isset($segments[1])) {
             $vars['id'] = $segments[1];
         }
     } else {
         include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'type.php';
         $types = Type::getMajorTypes();
         // Normalize the title
         // This is so we can determine the type of resource to display from the URL
         // For example, /resources/teachingmaterials => Teaching Materials
         foreach ($types as $type) {
             if (trim($segments[0]) == $type->alias) {
                 $vars['type'] = $segments[0];
                 $vars['task'] = 'browsetags';
                 break;
             }
         }
         if ($segments[0] == 'license') {
             $vars['task'] = $segments[0];
         } else {
             if (!isset($vars['type'])) {
                 $vars['alias'] = $segments[0];
             }
         }
     }
     if (!empty($segments[1])) {
         switch ($segments[1]) {
             case 'download':
                 $vars['task'] = 'download';
                 if (isset($segments[2])) {
                     $vars['file'] = $segments[2];
                 }
                 break;
             case 'play':
                 $vars['task'] = 'play';
                 break;
             case 'watch':
                 $vars['task'] = 'watch';
                 break;
             case 'video':
                 $vars['task'] = 'video';
                 break;
                 //case 'license':  $vars['task'] = 'license';  break;
             //case 'license':  $vars['task'] = 'license';  break;
             case 'citation':
                 $vars['task'] = 'citation';
                 break;
             case 'feed.rss':
                 $vars['task'] = 'feed';
                 break;
             case 'feed':
                 $vars['task'] = 'feed';
                 break;
             case 'license':
             case 'sourcecode':
                 $vars['tool'] = $segments[1];
                 break;
             default:
                 if ($segments[0] == 'browse') {
                     $vars['type'] = $segments[1];
                 } else {
                     $vars['active'] = $segments[1];
                 }
                 break;
         }
     }
     return $vars;
 }
Пример #4
0
 /**
  * Process the compose step
  *
  * @return  void
  */
 public function step_compose_process()
 {
     // Initiate extended database class
     $fields = Request::getVar('fields', array(), 'post');
     $row = Resource::oneOrNew($fields['id'])->set($fields);
     $isNew = $row->get('id') < 1 || substr($row->get('id'), 0, 4) == '9999';
     //$row->created    = ($row->created)    ? $row->created    : Date::toSql();
     //$row->created_by = ($row->created_by) ? $row->created_by : User::get('id');
     // Set status to "composing"
     if ($isNew) {
         $row->set('published', 2);
     }
     $row->set('published', (int) $row->get('published', 2));
     $row->set('publish_up', $row->get('publish_up') && $row->get('publish_up') != '0000-00-00 00:00:00' ? $row->get('publish_up') : Date::toSql());
     $row->set('publish_down', $row->get('publish_down') && $row->get('publish_down') != '0000-00-00 00:00:00' ? $row->get('publish_down') : '0000-00-00 00:00:00');
     $row->set('modified', Date::toSql());
     $row->set('modified_by', User::get('id'));
     $row->set('access', (int) $row->get('access', 0));
     $row->set('fulltxt', trim(preg_replace('/\\\\/', "%5C", $row->get('fulltxt'))));
     $row->set('introtext', String::truncate(strip_tags($row->get('fulltxt')), 500));
     // Get custom areas, add wrapper tags, and compile into fulltxt
     $type = Type::oneOrFail($row->get('type'));
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'elements.php';
     $elements = new Elements(array(), $type->customFields);
     $schema = $elements->getSchema();
     $fields = array();
     if (is_object($schema)) {
         foreach ($schema->fields as $field) {
             $fields[$field->name] = $field;
         }
     }
     $fulltxt = $row->get('fulltxt');
     $nbtag = Request::getVar('nbtag', array(), 'post');
     $found = array();
     foreach ($nbtag as $tagname => $tagcontent) {
         $f = '';
         $fulltxt .= "\n" . '<nb:' . $tagname . '>';
         if (is_array($tagcontent)) {
             $c = count($tagcontent);
             $num = 0;
             foreach ($tagcontent as $key => $val) {
                 if (trim($val)) {
                     $num++;
                 }
                 $fulltxt .= '<' . $key . '>' . trim($val) . '</' . $key . '>';
             }
             if ($c == $num) {
                 $f = 'found';
             }
         } else {
             $f = trim($tagcontent);
             if ($f) {
                 $fulltxt .= trim($tagcontent);
             }
         }
         $fulltxt .= '</nb:' . $tagname . '>' . "\n";
         if (!$f && isset($fields[$tagname]) && $fields[$tagname]->required) {
             $this->setError(Lang::txt('COM_CONTRIBUTE_REQUIRED_FIELD_CHECK', $fields[$tagname]->label));
         }
         $found[] = $tagname;
     }
     $row->set('fulltxt', $fulltxt);
     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));
         }
     }
     $row->set('title', preg_replace('/\\s+/', ' ', $row->get('title')));
     $row->set('title', $this->_txtClean($row->get('title')));
     // Strip any scripting there may be
     if (trim($row->get('fulltxt'))) {
         $row->set('fulltxt', \Components\Resources\Helpers\Html::stripStyles($row->get('fulltxt')));
         $row->set('fulltxt', $this->_txtClean($row->get('fulltxt')));
         $row->set('footertext', $this->_txtClean($row->get('footertext')));
     }
     // Fall back to step if any errors found
     if ($this->getError()) {
         $this->step--;
         $this->view->step = $this->step;
         $this->view->setLayout('compose');
         return $this->step_compose($row);
     }
     // reset id
     if ($isNew) {
         $row->set('id', 0);
     }
     // Store new content
     if (!$row->save()) {
         $this->setError(Lang::txt('Error: Failed to store changes.'));
         $this->step--;
         $this->view->step = $this->step;
         $this->view->setLayout('compose');
         return $this->step_compose($row);
     }
     // build path to temp upload folder and future permanent folder
     $session = App::get('session');
     $created = Date::format('Y-m-d 00:00:00');
     $oldPath = $row->basepath() . Html::build_path($created, $session->get('resources_temp_id'), '');
     $newPath = $row->filespace();
     // if we have a temp dir, move it to permanent location
     if (is_dir($oldPath)) {
         \Filesystem::move($oldPath, $newPath);
         $old = DS . $session->get('resources_temp_id') . DS;
         $new = DS . $row->id . DS;
         // update all images in abstract
         $row->set('introtext', str_replace($old, $new, $row->get('introtext')));
         $row->set('fulltxt', str_replace($old, $new, $row->get('fulltxt')));
         $row->save();
         // clear temp id
         $session->clear('resources_temp_id');
     }
     // Is it a new resource?
     if ($isNew) {
         // Automatically attach this user as the first author
         Request::setVar('pid', $row->get('id'));
         Request::setVar('id', $row->get('id'));
         Request::setVar('authid', User::get('id'));
         include_once __DIR__ . DS . 'authors.php';
         $authors = new Authors();
         $authors->saveTask(0);
     }
     // Log activity
     $recipients = array(['resource', $row->get('id')], ['user', $row->get('created_by')]);
     foreach ($row->authors()->where('authorid', '>', 0)->rows() as $author) {
         $recipients[] = ['user', $author->get('authorid')];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => $isNew ? 'updated' : 'created', 'scope' => 'resource', 'scope_id' => $row->get('id'), 'description' => Lang::txt('COM_RESOURCES_ACTIVITY_ENTRY_' . (!$isNew ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url('index.php?option=com_resources&id=' . $row->get('id')) . '">' . $row->get('title') . '</a>'), 'details' => array('title' => $row->get('title'), 'url' => Route::url('index.php?option=com_resources&id=' . $row->get('id')))], 'recipients' => $recipients]);
 }