예제 #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
 /**
  * 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]);
 }