Beispiel #1
0
 /**
  * Rate a resource
  *
  * @param      string $option Name of the component
  * @return     array
  */
 public function onResourcesRateItem($option)
 {
     $id = Request::getInt('rid', 0);
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     $database = App::get('db');
     $resource = new \Components\Resources\Tables\Resource($database);
     $resource->load($id);
     $h = new PlgResourcesReviewsHelper();
     $h->resource = $resource;
     $h->option = $option;
     $h->_option = $option;
     $h->execute();
     return $arr;
 }
Beispiel #2
0
 /**
  * Remove any associated resources when group is deleted
  *
  * @param      object $group Group being deleted
  * @return     string Log of items removed
  */
 public function onGroupDelete($group)
 {
     // Get all the IDs for resources associated with this group
     $ids = $this->getResourceIDs($group->get('cn'));
     // Start the log text
     $log = Lang::txt('PLG_GROUPS_RESOURCES_LOG') . ': ';
     if (count($ids) > 0) {
         $database = App::get('db');
         // Loop through all the IDs for resources associated with this group
         foreach ($ids as $id) {
             // Disassociate the resource from the group and unpublish it
             $rr = new \Components\Resources\Tables\Resource($database);
             $rr->load($id->id);
             $rr->group_owner = '';
             $rr->published = 0;
             $rr->store();
             // Add the page ID to the log
             $log .= $id->id . ' ' . "\n";
         }
     } else {
         $log .= Lang::txt('PLG_GROUPS_RESOURCES_NONE') . "\n";
     }
     // Return the log
     return $log;
 }
Beispiel #3
0
 /**
  * Issue master DOI for tool resources if does not exist
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function issueResourceMasterDoi(\Components\Cron\Models\Job $job)
 {
     $database = App::get('db');
     $config = Component::params('com_publications');
     // Is config to issue master DOI turned ON?
     if (!$config->get('master_doi')) {
         return true;
     }
     // Get all tool resources without master DOI
     $sql = "SELECT r.id, r.created_by, v.id as tool_version_id,\n\t\t\t\tv.toolid, v.toolname, v.title, v.description,\n\t\t\t\tv.instance, v.revision, v.released\n\t\t\t\tFROM #__resources AS r, #__tool_version AS v\n\t\t\t\tWHERE r.published=1\n\t\t\t\tAND r.type=7\n\t\t\t\tAND r.standalone=1\n\t\t\t\tAND r.alias=v.toolname\n\t\t\t\tAND v.state=1\n\t\t\t\tAND (r.master_doi IS NULL OR r.master_doi=0)\n\t\t\t\tGROUP BY r.id\n\t\t\t\tORDER BY v.title, v.toolname, v.revision DESC";
     $database->setQuery($sql);
     if (!($rows = $database->loadObjectList())) {
         // No applicable results
         return true;
     }
     // Includes
     require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'models' . DS . 'doi.php';
     // Get DOI service
     $doiService = new \Components\Publications\Models\Doi();
     // Is service enabled?
     if (!$doiService->on() || !$doiService->_configs->livesite) {
         return true;
     }
     // Go through records
     foreach ($rows as $row) {
         // Reset metadata
         $doiService->reset();
         // Map data
         $pubYear = $row->released && $row->released != '0000-00-00 00:00:00' ? gmdate('Y', strtotime($row->released)) : gmdate('Y');
         $doiService->set('pubYear', $pubYear);
         $doiService->mapUser($row->created_by, array(), 'creator');
         $doiService->set('resourceType', 'Software');
         $doiService->set('title', htmlspecialchars(stripslashes($row->title)));
         $doiService->set('url', $doiService->_configs->livesite . DS . 'resources' . DS . $row->toolname . DS . 'main');
         // Register DOI
         $masterDoi = $doiService->register();
         // Save with publication record
         $resource = new \Components\Resources\Tables\Resource($database);
         if ($masterDoi && $resource->load($row->id)) {
             $resource->master_doi = strtoupper($masterDoi);
             $resource->store();
         }
     }
     return true;
 }
Beispiel #4
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);
 }
Beispiel #5
0
 /**
  * Display a list of authors
  *
  * @param   integer  $id  Resource ID
  * @return  void
  */
 public function displayTask($id = null)
 {
     // Incoming
     if (!$id) {
         $id = Request::getInt('rid', 0);
     }
     // Ensure we have an ID to work with
     if (!$id) {
         App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
     }
     $this->view->version = Request::getVar('version', 'dev');
     // Get all contributors of this resource
     $helper = new \Components\Resources\Helpers\Helper($id, $this->database);
     if ($this->view->version == 'dev') {
         $helper->getCons();
     } else {
         $obj = new \Components\Tools\Tables\Tool($this->database);
         $toolname = $obj->getToolnameFromResource($id);
         $objV = new \Components\Tools\Tables\Version($this->database);
         $revision = $objV->getCurrentVersionProperty($toolname, 'revision');
         $helper->getToolAuthors($toolname, $revision);
     }
     // Get a list of all existing contributors
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'contributor' . DS . 'roletype.php';
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($id);
     $rt = new \Components\Resources\Tables\Contributor\RoleType($this->database);
     // Output HTML
     $this->view->config = $this->config;
     $this->view->contributors = $helper->_contributors;
     $this->view->id = $id;
     $this->view->roles = $rt->getRolesForType($resource->type);
     $this->view->setErrors($this->getErrors())->setLayout('display')->display();
 }
Beispiel #6
0
 /**
  * Update the associated resource page for this tool
  *
  * @param      integer $rid       Resource ID
  * @param      array   $status    Fields to update
  * @param      integer $published Published state
  * @param      integer $newtool   Updating for a new tool?
  * @return     boolean True if no errors
  */
 public function updatePage($rid, $status = array(), $published = 0, $newtool = 0)
 {
     if ($rid === NULL) {
         return false;
     }
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($rid);
     if (count($status) > 0) {
         $resource->fulltxt = addslashes($status['fulltxt']);
         $resource->introtext = $status['description'];
         $resource->title = preg_replace('/\\s+/', ' ', $status['title']);
         $resource->modified = Date::toSql();
         $resource->modified_by = User::get('id');
     }
     if ($published) {
         $resource->published = $published;
     }
     if ($newtool && $published == 1) {
         $resource->publish_up = Date::toSql();
     }
     if (!$resource->store()) {
         $this->setError($row->getError());
         return false;
     } else {
         if ($newtool) {
             \Notify::success(Lang::txt('COM_TOOLS_NOTICE_RES_PUBLISHED'), 'tools');
         } else {
             \Notify::success(Lang::txt('COM_TOOLS_NOTICE_RES_UPDATED'), 'tools');
         }
     }
     return true;
 }
Beispiel #7
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();
 }
Beispiel #8
0
$contents = file_get_contents(PATH_ROOT . $this->manifest);
//content folder
$content_folder = $this->content_folder;
//decode the json formatted manifest so we can use the information
$presentation = json_decode($contents);
$presentation = $presentation->presentation;
if (!is_object($presentation)) {
    $presentation = new stdClass();
    $presentation->slides = array();
    $presentation->media = array();
    $presentation->placeholder = null;
    $presentation->duration = null;
}
//get this resource
$rr = new \Components\Resources\Tables\Resource($this->database);
$rr->load($this->resid);
//get the parent resource
$rh = new \Components\Resources\Helpers\Helper($this->resid, $this->database);
$rh->getParents();
$parent = $rh->parents[0];
//check to see if parent type is series
$rt = new \Components\Resources\Tables\Type($this->database);
$rt->load($parent->type);
//if we have a series get children
if ($rt->type == "Series" || $rt->type == "Courses") {
    $rh->getChildren($parent->id, 0, 'yes');
    $children = $rh->children;
    //remove any children without a HUBpresenter
    foreach ($children as $k => $c) {
        $rh = new \Components\Resources\Helpers\Helper($c->id, $this->database);
        $rh->getChildren();
Beispiel #9
0
 /**
  * Lists all files and folders for a given directory
  *
  * @return     void
  */
 public function listTask()
 {
     // 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('COM_TOOLS_CONTRIBUTE_NO_ID') . '</p>';
         return;
     }
     /*$this->view->version = Request::getInt('version', 0);
     		if (!$this->view->version)
     		{
     			echo '<p class="error">' . Lang::txt('No tool version ID provided.') . '</p>';
     			return;
     		}*/
     // Incoming sub-directory
     $this->view->subdir = Request::getVar('subdir', '');
     // Build the path
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->load($this->view->resource);
     $path = \Components\Resources\Helpers\Html::dateToPath($row->created) . DS . \Components\Resources\Helpers\Html::niceidformat($this->view->resource);
     $path = \Components\Resources\Helpers\Utilities::buildUploadPath($path, $this->view->subdir) . DS . 'media';
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($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[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     $this->view->config = $this->config;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Beispiel #10
0
 /**
  * Temp function to issue new service DOIs for tool versions published previously
  *
  * @return  void
  */
 public function batchdoiTask()
 {
     $yearFormat = 'Y';
     //  Limit one-time batch size
     $limit = Request::getInt('limit', 2);
     // Store output
     $created = array();
     $failed = array();
     // Initiate extended database classes
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $objDOI = new \Components\Resources\Tables\Doi($this->database);
     $objV = new \Components\Tools\Tables\Version($this->database);
     $objA = new \Components\Tools\Tables\Author($this->database);
     $live_site = rtrim(Request::base(), '/');
     $sitename = Config::get('sitename');
     // Get config
     $config = \Component::params($this->_option);
     // Get all tool publications without new DOI
     $this->database->setQuery("SELECT * FROM `#__doi_mapping` WHERE doi='' OR doi IS NULL ");
     $rows = $this->database->loadObjectList();
     if ($rows) {
         $i = 0;
         foreach ($rows as $row) {
             if ($limit && $i == $limit) {
                 // Output status message
                 if ($created) {
                     foreach ($created as $cr) {
                         echo '<p>' . $cr . '</p>';
                     }
                 }
                 echo '<p>' . Lang::txt('COM_TOOLS_REGISTERED_DOIS', count($created), count($failed)) . '</p>';
                 return;
             }
             // Skip entries with no resource information loaded / non-tool resources
             if (!$resource->load($row->rid) || !$row->alias) {
                 continue;
             }
             // Get version info
             $this->database->setQuery("SELECT * FROM `#__tool_version` WHERE toolname='" . $row->alias . "' AND revision='" . $row->local_revision . "' AND state!=3 LIMIT 1");
             $results = $this->database->loadObjectList();
             if ($results) {
                 $title = $results[0]->title ? $results[0]->title : $resource->title;
                 $pubyear = $results[0]->released ? trim(Date::of($results[0]->released)->toLocal($yearFormat)) : date('Y');
             } else {
                 // Skip if version not found
                 continue;
             }
             // Collect metadata
             $metadata = array();
             $metadata['targetURL'] = $live_site . '/resources/' . $row->rid . '/?rev=' . $row->local_revision;
             $metadata['title'] = htmlspecialchars($title);
             $metadata['pubYear'] = $pubyear;
             // Get authors
             $objA = new \Components\Tools\Tables\Author($this->database);
             $authors = $objA->getAuthorsDOI($row->rid);
             // Register DOI
             $doiSuccess = $objDOI->registerDOI($authors, $config, $metadata, $doierr);
             if ($doiSuccess) {
                 $this->database->setQuery("UPDATE `#__doi_mapping` SET doi='{$doiSuccess}' WHERE rid={$row->rid} AND local_revision={$row->local_revision}");
                 if (!$this->database->query()) {
                     $failed[] = $doiSuccess;
                 } else {
                     $created[] = $doiSuccess;
                 }
             } else {
                 print_r($doierr);
                 echo '<br />';
                 print_r($metadata);
                 echo '<br />';
             }
             $i++;
         }
     }
     // Output status message
     if ($created) {
         foreach ($created as $cr) {
             echo '<p>' . $cr . '</p>';
         }
     }
     echo '<p>' . Lang::txt('COM_TOOLS_REGISTERED_DOIS', count($created), count($failed)) . '</p>';
     return;
 }
Beispiel #11
0
 /**
  * Removes an item reported as abusive
  *
  * @param      integer $referenceid ID of the database table row
  * @param      integer $parentid    If the element has a parent element
  * @param      string  $category    Element type (determines table to look in)
  * @param      string  $message     Message to user to append to
  * @return     string
  */
 public function deleteReportedItem($referenceid, $parentid, $category, $message)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $this->loadLanguage();
     $database = App::get('db');
     switch ($category) {
         case 'review':
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'review.php';
             // Delete the review
             $review = new \Components\Resources\Tables\Review($database);
             $review->load($referenceid);
             $review->state = 2;
             $review->store();
             // Recalculate the average rating for the parent resource
             $resource = new \Components\Resources\Tables\Resource($database);
             $resource->load($parentid);
             $resource->calculateRating();
             if (!$resource->store()) {
                 $this->setError($resource->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
         case 'reviewcomment':
             $comment = \Hubzero\Item\Comment::oneOrFail($referenceid);
             $comment->set('state', $comment::STATE_DELETED);
             if (!$comment->save()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
     }
     return $message;
 }
Beispiel #12
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;
    }