示例#1
0
 /**
  * Generate module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     $database = \App::get('db');
     //Get the admin configured settings
     $filters = array('limit' => 1, 'start' => 0, 'type' => trim($this->params->get('type')), 'sortby' => 'random', 'minranking' => trim($this->params->get('minranking')), 'tag' => trim($this->params->get('tag')), 'access' => 'public', 'toolState' => 7);
     $row = null;
     // No - so we need to randomly choose one
     // Initiate a resource object
     $rr = new \Components\Resources\Tables\Resource($database);
     // Get records
     $rows = $rr->getRecords($filters, false);
     if (count($rows) > 0) {
         $row = $rows[0];
     }
     $this->cls = trim($this->params->get('moduleclass_sfx'));
     $this->txt_length = trim($this->params->get('txt_length'));
     // Did we get any results?
     if ($row) {
         $config = Component::params('com_resources');
         // Resource
         $id = $row->id;
         include_once Component::path('com_resources') . DS . 'helpers' . DS . 'html.php';
         $path = DS . trim($config->get('uploadpath', '/site/resources'), DS);
         $path = \Components\Resources\Helpers\Html::build_path($row->created, $row->id, $path);
         if ($row->type == 7) {
             include_once Component::path('com_tools') . DS . 'tables' . DS . 'version.php';
             $tv = new \Components\Tools\Tables\Version($database);
             $versionid = $tv->getVersionIdFromResource($id, 'current');
             $picture = $this->getToolImage($path, $versionid);
         } else {
             $picture = $this->getImage($path);
         }
         $thumb = $path . DS . $picture;
         if (!is_file(PATH_APP . $thumb)) {
             $thumb = DS . trim($config->get('defaultpic'));
         }
         $row->typetitle = trim(stripslashes($row->typetitle));
         if (substr($row->typetitle, -1, 1) == 's' && substr($row->typetitle, -3, 3) != 'ies') {
             $row->typetitle = substr($row->typetitle, 0, strlen($row->typetitle) - 1);
         }
         $this->id = $id;
         $this->thumb = $thumb;
     }
     $this->row = $row;
     require $this->getLayoutPath();
 }
示例#2
0
 /**
  * Delete a file
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Incoming parent ID
     $pid = Request::getInt('pid', 0);
     if (!$pid) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // get tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolIdFromResource($pid);
     // make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Incoming child ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid);
         return;
     }
     // Load resource info
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->load($id);
     // Check for stored file
     if ($row->path == '') {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_MISSING_FILE_PATH'));
         $this->displayTask($pid);
         return;
     }
     // Get resource path
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $listdir = \Components\Resources\Helpers\Html::build_path($row->created, $id, '');
     // Build the path
     $path = $this->_buildUploadPath($listdir, '');
     // Check if the folder even exists
     if (!is_dir($path) or !$path) {
         $this->setError(Lang::txt('COM_TOOLS_DIRECTORY_NOT_FOUND'));
     } else {
         // Attempt to delete the file
         if (!Filesystem::deleteDirectory($path)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_DELETE_DIRECTORY'));
         }
         // Delete associations to the resource
         $row->deleteExistence();
         // Delete resource
         $row->delete();
     }
     // Push through to the attachments view
     $this->displayTask($pid);
 }
示例#3
0
 /**
  * Removes a resource
  * Redirects to main listing
  *
  * @return     void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array(0));
     // Ensure we have some IDs to work with
     if (count($ids) < 1) {
         $this->setMessage(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     foreach ($ids as $id) {
         // Load resource info
         $row = new Resource($this->database);
         $row->load($id);
         // Get path and delete directories
         if ($row->path != '') {
             $listdir = $row->path;
         } else {
             // No stored path, derive from created date
             $listdir = Html::build_path($row->created, $id, '');
         }
         // Build the path
         $path = Utilities::buildUploadPath($listdir, '');
         $base = PATH_APP . '/' . trim($this->config->get('webpath', '/site/resources'), '/');
         $baseY = $base . '/' . Date::of($row->created)->format("Y");
         $baseM = $baseY . '/' . Date::of($row->created)->format("m");
         // Check if the folder even exists
         if (!is_dir($path) or !$path) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
         } else {
             if ($path == $base || $path == $baseY || $path == $baseM) {
                 $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
             } else {
                 // Attempt to delete the folder
                 if (!\Filesystem::deleteDirectory($path)) {
                     $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_DELETE_DIRECTORY'));
                 }
             }
         }
         // Delete associations to the resource
         $row->deleteExistence();
         // Delete the resource
         $row->delete();
     }
     $pid = Request::getInt('pid', 0);
     // Redirect
     App::redirect($this->buildRedirectURL($pid));
 }
示例#4
0
 /**
  * Display an upload form and file listing
  *
  * @return     void
  */
 public function displayTask()
 {
     $this->view->setLayout('display');
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $this->view->resource = Request::getInt('resource', 0);
     if (!$this->view->resource) {
         echo '<p class="error">' . Lang::txt('No resource ID provided.') . '</p>';
         return;
     }
     // Incoming sub-directory
     $this->view->subdir = Request::getVar('subdir', '');
     // Build the path
     //$this->view->path = Utilities::buildUploadPath($this->view->listdir, $this->view->subdir);
     $row = new Resource($this->database);
     $row->load($this->view->resource);
     // allow for temp resource uploads
     if (!$row->created || $row->created == '0000-00-00 00:00:00') {
         $row->created = Date::format('Y-m-d 00:00:00');
     }
     $this->view->path = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($row->created, $this->view->resource, '') . DS . 'media';
     $folders = array();
     $docs = array();
     if (is_dir($this->view->path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($this->view->path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$this->view->path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->row = $row;
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     // Set any errors
     if ($this->getError()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
     }
     // Output the HTML
     $this->view->display();
 }
示例#5
0
 /**
  * Return a path to resource
  *
  * @param	$createdDate	Resource creation date
  * @param	$resourceId		Resource ID
  * @param	$versionId		Resource Version ID
  *
  * @return     path
  */
 public static function getResourcePath($createdDate, $resourceId, $versionId)
 {
     //include the resources html helper file
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     //get resource upload path
     $resourceParams = Component::params('com_resources');
     $path = DS . trim($resourceParams->get("uploadpath"), DS);
     //build path based on resource creation date and id
     $path .= \Components\Resources\Helpers\Html::build_path($createdDate, $resourceId, '');
     //append version id if we have one
     if ($versionId) {
         $path .= DS . $versionId;
     }
     return $path;
 }
示例#6
0
 /**
  * Display a list of screenshots for this entry
  *
  * @param      integer $rid     Resource ID
  * @param      string  $version Tool version
  * @return     void
  */
 public function displayTask($rid = NULL, $version = NULL)
 {
     $this->view->setLayout('display');
     // Incoming
     if (!$rid) {
         $rid = Request::getInt('rid', 0);
     }
     if (!$version) {
         $version = Request::getVar('version', 'dev');
     }
     // Ensure we have an ID to work with
     if (!$rid) {
         App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         return;
     }
     // Get resource information
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($rid);
     // Get version id
     $objV = new \Components\Tools\Tables\Version($this->database);
     $vid = $objV->getVersionIdFromResource($rid, $version);
     // Do we have a published tool?
     $this->view->published = $objV->getCurrentVersionProperty($resource->alias, 'id');
     // Get screenshot information for this resource
     $ss = new \Components\Resources\Tables\Screenshot($this->database);
     $this->view->shots = $ss->getScreenshots($rid, $vid);
     // Build paths
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $path = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, '');
     $this->view->upath = PATH_APP . DS . trim($this->rconfig->get('uploadpath'), DS) . $path;
     $this->view->wpath = DS . trim($this->rconfig->get('uploadpath'), DS) . $path;
     if ($vid) {
         $this->view->upath .= DS . $vid;
         $this->view->wpath .= DS . $vid;
     }
     // Make sure wpath is preceded by app
     if (substr($this->view->wpath, 0, 4) != DS . 'app') {
         $this->view->wpath = DS . 'app' . $this->view->wpath;
     }
     // get config
     $this->view->cparams = Component::params('com_resources');
     $this->view->version = $version;
     $this->view->rid = $rid;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
示例#7
0
 /**
  * Download a file
  * Runs through various permissions checks to ensure user has access
  *
  * @return     void
  */
 public function downloadTask()
 {
     // Incoming
     $id = Request::getInt('id', 0);
     $alias = Request::getVar('alias', '');
     $d = Request::getVar('d', 'inline');
     //make sure we have a proper disposition
     if ($d != "inline" && $d != "attachment") {
         $d = "inline";
     }
     // Load the resource
     $resource = new Resource($this->database);
     if ($alias && !$resource->loadAlias($alias)) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
         return;
     } elseif (substr($id, 0, 4) == '9999') {
         $resource->id = $id;
         $resource->standalone = 1;
         $resource->path = null;
         $resource->created = Date::of('now')->format('Y-m-d 00:00:00');
     } elseif (!$resource->load($id)) {
         App::abort(404, Lang::txt('COM_RESOURCES_RESOURCE_NOT_FOUND'));
         return;
     }
     // Check if the resource is for logged-in users only and the user is logged-in
     if ($token = Request::getVar('token', '', 'get')) {
         $token = base64_decode($token);
         $key = App::hash(@$_SERVER['HTTP_USER_AGENT']);
         $crypter = new \Hubzero\Encryption\Encrypter(new \Hubzero\Encryption\Cipher\Simple(), new \Hubzero\Encryption\Key('simple', $key, $key));
         $session_id = $crypter->decrypt($token);
         $session = \Hubzero\Session\Helper::getSession($session_id);
         $user = User::getInstance($session->userid);
         $user->guest = 0;
         $user->id = $session->userid;
         $user->usertype = $session->usertype;
     } else {
         $user = User::getRoot();
     }
     if ($resource->access == 1 && $user->get('guest')) {
         App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH'));
         return;
     }
     // Check if the resource is "private" and the user is allowed to view it
     if ($resource->access == 4 || $resource->access == 3 || !$resource->standalone) {
         if ($this->checkGroupAccess($resource, $user)) {
             App::abort(403, Lang::txt('COM_RESOURCES_ALERTNOTAUTH'));
             return;
         }
     }
     if ($resource->standalone && !$resource->path) {
         $resource->path = DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($resource->created, $resource->id, '') . DS . 'media' . DS . Request::getVar('file');
     }
     $resource->path = trim($resource->path);
     // Ensure we have a path
     // Ensure resource is published - stemedhub #472
     if (empty($resource->path) && $resource->published != 1) {
         App::abort(404, Lang::txt('COM_RESOURCES_FILE_NOT_FOUND'));
         return;
     }
     // Get the configured upload path
     $base_path = $this->config->get('uploadpath', '/site/resources');
     if ($base_path) {
         $base_path = DS . trim($base_path, DS);
     }
     // Does the path start with a slash?
     if (substr($resource->path, 0, 1) != DS) {
         $resource->path = DS . $resource->path;
         // Does the beginning of the $resource->path match the config path?
         if (substr($resource->path, 0, strlen($base_path)) == $base_path) {
             // Yes - this means the full path got saved at some point
         } else {
             // No - append it
             $resource->path = $base_path . $resource->path;
         }
     }
     // Add root path
     $filename = PATH_APP . $resource->path;
     // Ensure the file exist
     if (!file_exists($filename)) {
         App::abort(404, Lang::txt('COM_RESOURCES_FILE_NOT_FOUND') . ' ' . $filename);
         return;
     }
     $ext = strtolower(\Filesystem::extension($filename));
     if (!in_array($ext, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'pdf', 'htm', 'html', 'txt', 'json', 'xml'))) {
         $d = 'attachment';
     }
     // Initiate a new content server and serve up the file
     $xserver = new \Hubzero\Content\Server();
     $xserver->filename($filename);
     $xserver->disposition($d);
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     if (!$xserver->serve()) {
         // Should only get here on error
         throw new Exception(Lang::txt('COM_RESOURCES_SERVER_ERROR'), 500);
     } else {
         exit;
     }
     return;
 }
示例#8
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]);
 }
示例#9
0
 /**
  * Process the compose step
  *
  * @return     void
  */
 public function step_compose_process()
 {
     // Initiate extended database class
     $row = new Resource($this->database);
     $row->load(Request::getInt('id', 0));
     if (!$row->bind($_POST)) {
         throw new Exception($row->getError(), 500);
     }
     $isNew = $row->id < 1 || substr($row->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->published = 2;
     } else {
         $row->published = $row->published ?: 2;
     }
     $row->publish_up = $row->publish_up && $row->publish_up != '0000-00-00 00:00:00' ? $row->publish_up : Date::toSql();
     $row->publish_down = $row->publish_down && $row->publish_down != '0000-00-00 00:00:00' ? $row->publish_down : '0000-00-00 00:00:00';
     $row->modified = Date::toSql();
     $row->modified_by = User::get('id');
     $row->access = $row->access ?: 0;
     $row->fulltxt = trim(preg_replace('/\\\\/', "%5C", $row->fulltxt));
     $row->introtext = String::truncate(strip_tags($row->fulltxt), 500);
     //$row->fulltxt   = $this->_txtAutoP($row->fulltxt, 1);
     // Get custom areas, add wrapper tags, and compile into fulltxt
     $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 Elements(array(), $type->customFields);
     $schema = $elements->getSchema();
     $fields = array();
     if (is_object($schema)) {
         foreach ($schema->fields as $field) {
             $fields[$field->name] = $field;
         }
     }
     $nbtag = isset($_POST['nbtag']) ? $_POST['nbtag'] : array();
     $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);
                 //(isset($fields[$tagname]) && $fields[$tagname]->type == 'textarea') ? $this->_txtAutoP(trim($tagcontent), 1) : trim($tagcontent);
             }
         }
         $row->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;
     }
     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->title = preg_replace('/\\s+/', ' ', $row->title);
     $row->title = $this->_txtClean($row->title);
     // Strip any scripting there may be
     if (trim($row->fulltxt)) {
         $row->fulltxt = \Components\Resources\Helpers\Html::stripStyles($row->fulltxt);
         $row->fulltxt = $this->_txtClean($row->fulltxt);
         //$row->fulltxt   = $this->_txtAutoP($row->fulltxt, 1);
         $row->footertext = $this->_txtClean($row->footertext);
     }
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
     }
     // Fall back to step if any errors found
     if ($this->getError()) {
         $this->step--;
         $this->view->step = $this->step;
         $this->view->setLayout('compose');
         $this->step_compose($row);
         return;
     }
     // reset id
     if ($isNew) {
         $row->id = null;
     }
     // Store new content
     if (!$row->store()) {
         $this->setError(Lang::txt('Error: Failed to store changes.'));
         $this->step--;
         $this->view->step = $this->step;
         $this->view->setLayout('compose');
         $this->step_compose($row);
         return;
     }
     // build path to temp upload folder and future permanent folder
     $session = App::get('session');
     $created = Date::format('Y-m-d 00:00:00');
     $oldPath = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($created, $session->get('resources_temp_id'), '');
     $newPath = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($row->created, $row->id, '');
     // 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->introtext = str_replace($old, $new, $row->introtext);
         $row->fulltxt = str_replace($old, $new, $row->fulltxt);
         $row->store();
         // clear temp id
         $session->clear('resources_temp_id');
     }
     // Checkin the resource
     $row->checkin();
     // Is it a new resource?
     if ($isNew) {
         // Get the resource ID
         if (!$row->id) {
             $row->id = $row->insertid();
         }
         // Automatically attach this user as the first author
         Request::setVar('pid', $row->id);
         Request::setVar('id', $row->id);
         Request::setVar('authid', User::get('id'));
         include_once __DIR__ . DS . 'authors.php';
         $authors = new Authors();
         $authors->saveTask(0);
     }
 }
示例#10
0
    /**
     * Generate macro output
     *
     * @return     string
     */
    public function render()
    {
        //get the args passed in
        $content = $this->args;
        // args will be null if the macro is called without parenthesis.
        if (!$content) {
            return;
        }
        //generate a unique id for the slider
        $id = uniqid();
        // null base url for now
        $base_url = '';
        // needed objects
        $db = \App::get('db');
        $option = \Request::getCmd('option');
        $config = \Component::params($option);
        // define a base url
        switch ($option) {
            case 'com_groups':
                $cn = \Request::getVar('cn');
                $group = Group::getInstance($cn);
                $base_url = DS . trim($config->get('uploadpath', 'site/groups'), DS) . DS;
                $base_url .= $group->get('gidNumber') . DS . 'uploads';
                break;
            case 'com_resources':
                $row = new \Components\Resources\Tables\Resource($db);
                $row->load($this->pageid);
                $base_url = DS . trim($config->get('uploadpath', 'site/resources'), DS) . DS;
                $base_url .= \Components\Resources\Helpers\Html::build_path($row->created, $this->pageid, '') . DS . 'media';
                break;
        }
        //seperate image list into array of images
        $slides = array_map('trim', explode(',', $content));
        //array for checked slides
        $final_slides = array();
        //check each passed in slide
        foreach ($slides as $slide) {
            //check to see if image is external
            if (strpos($slide, 'http') === false) {
                $slide = trim($slide);
                //check if internal file actually exists
                if (is_file(PATH_APP . $base_url . DS . $slide)) {
                    $final_slides[] = $base_url . DS . $slide;
                }
            } else {
                $headers = get_headers($slide);
                if (strpos($headers[0], "OK") !== false) {
                    $final_slides[] = $slide;
                }
            }
        }
        $html = '';
        $html .= '<div class="wiki_slider">';
        $html .= '<div id="slider_' . $id . '">';
        foreach ($final_slides as $fs) {
            $html .= '<img src="' . $fs . '" alt="" />';
        }
        $html .= '</div>';
        $html .= '<div class="wiki_slider_pager" id="slider_' . $id . '_pager"></div>';
        $html .= '</div>';
        \Document::addStyleSheet('plugins/content/formathtml/macros/macro-assets/slider/slider.css');
        \Document::addScript('plugins/content/formathtml/macros/macro-assets/slider/slider.js');
        \Document::addScriptDeclaration('
			var $jQ = jQuery.noConflict();

			$jQ(function() {
				$jQ("#slider_' . $id . '").cycle({
					fx: \'scrollHorz\',
					speed: 450,
					pager: \'#slider_' . $id . '_pager\'
				});
			});
		');
        return $html;
    }