Example #1
0
 /**
  * Return data on a resource sub view (this will be some form of HTML)
  *
  * @param   object   $resource  Current resource
  * @param   string   $option    Name of the component
  * @param   integer  $miniview  View style
  * @return  array
  */
 public function onResourcesSub($resource, $option, $miniview = 0)
 {
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     require_once __DIR__ . DS . 'models' . DS . 'sponsor.php';
     $records = \Plugins\Resources\Sponsors\Models\Sponsor::all()->whereEquals('state', 1)->rows();
     if (!$records) {
         return $arr;
     }
     $data = '';
     $sponsors = array();
     foreach ($records as $record) {
         $sponsors[$record->alias] = $record;
     }
     $rt = new \Components\Resources\Helpers\Tags($resource->id);
     $tags = $rt->tags();
     if ($tags) {
         foreach ($tags as $tag) {
             if (isset($sponsors[$tag->get('tag')])) {
                 $data = $sponsors[$tag->get('tag')]->description;
                 break;
             }
         }
     }
     // Instantiate a view
     $view = $this->view('mini', 'display')->set('option', $option)->set('resource', $resource)->set('params', $this->params)->set('data', $data)->setErrors($this->getErrors());
     if ($miniview) {
         $view->setLayout('mini');
     }
     // Return the output
     $arr['html'] = $view->loadTemplate();
     return $arr;
 }
Example #2
0
 /**
  * Method to get list of tools
  *
  * @apiMethod GET
  * @apiUri    /tools/list
  * @apiParameter {
  * 		"name":          "user_id",
  * 		"description":   "Member identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       0
  * }
  * @return    void
  */
 public function listTask()
 {
     //get the userid and attempt to load user profile
     $userid = Request::getInt('user_id', 0);
     $result = User::getInstance($userid);
     //make sure we have a user
     //if ($result === false) return $this->not_found();
     //instantiate database object
     $database = \App::get('db');
     //get list of tools
     $tools = \Components\Tools\Models\Tool::getMyTools();
     //get the supported tag
     $rconfig = Component::params('com_resources');
     $supportedtag = $rconfig->get('supportedtag', '');
     //get supportedtag usage
     include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php';
     $resource_tags = new \Components\Resources\Helpers\Tags(0);
     $supportedtagusage = $resource_tags->getTagUsage($supportedtag, 'alias');
     //create list of tools
     $t = array();
     foreach ($tools as $k => $tool) {
         if (isset($t[$tool->alias])) {
             $t[$tool->alias]['versions'][] = $tool->revision;
             continue;
         }
         $t[$tool->alias]['alias'] = $tool->alias;
         $t[$tool->alias]['title'] = $tool->title;
         $t[$tool->alias]['description'] = $tool->description;
         $t[$tool->alias]['versions'] = array($tool->revision);
         $t[$tool->alias]['supported'] = in_array($tool->alias, $supportedtagusage) ? 1 : 0;
     }
     //encode and return result
     $object = new stdClass();
     $object->tools = array_values($t);
     $this->send($object);
 }
Example #3
0
         $task_access = 'accessprotected';
         $row->groupname = 'COM_RESOURCES_ACCESS_SPECIAL';
         break;
     case 3:
         $color_access = 'protected';
         $task_access = 'accessprivate';
         $row->groupname = 'COM_RESOURCES_ACCESS_PROTECTED';
         break;
     case 4:
         $color_access = 'private';
         $task_access = 'accesspublic';
         $row->groupname = 'COM_RESOURCES_ACCESS_PRIVATE';
         break;
 }
 // Get the tags on this item
 $rt = new \Components\Resources\Helpers\Tags($row->id);
 $tags = $rt->tags()->count();
 // See if it's checked out or not
 if ($row->checked_out || $row->checked_out_time != '0000-00-00 00:00:00') {
     $date = Date::of($row->checked_out_time)->toLocal(Lang::txt('DATE_FORMAT_LC1'));
     $time = Date::of($row->checked_out_time)->toLocal('H:i');
     $checked = '<span class="editlinktip hasTip" title="' . Lang::txt('JLIB_HTML_CHECKED_OUT') . '::' . $this->escape($row->editor) . '<br />' . $date . '<br />' . $time . '">';
     $checked .= '<span class="checkedout"></span>' . '</span>';
     $info .= $row->checked_out_time != '0000-00-00 00:00:00' ? Lang::txt('COM_RESOURCES_CHECKED_OUT') . ': ' . Date::of($row->checked_out_time)->toLocal(Lang::txt('DATE_FORMAT_HZ1')) . '<br />' : '';
     if ($row->editor) {
         $info .= Lang::txt('COM_RESOURCES_CHECKED_OUT_BY') . ': ' . $this->escape($row->editor);
     }
 } else {
     $checked = Html::grid('id', $i, $row->id, false, 'id');
 }
 ?>
Example #4
0
 /**
  * Preview the resource
  *
  * @return     void
  */
 public function previewTask()
 {
     // Incoming
     $alias = Request::getVar('app', '');
     $version = Request::getVar('editversion', 'dev');
     $rid = Request::getInt('rid', 0);
     // Load the tool
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolId($alias);
     if (!$this->_toolid) {
         // not a tool resource page
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline'));
         return;
     }
     // Make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Get tool version (dev or current) information
     $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
     // Instantiate our tag object
     $tagcloud = new \Components\Resources\Helpers\Tags($rid);
     $tags = Request::getVar('tags', '', 'post');
     $tagfa = Request::getVar('tagfa', '', 'post');
     // Process new tags
     $newtags = '';
     if ($tagfa) {
         $newtags = $tagfa . ', ';
     }
     if ($tags) {
         $newtags .= $tags;
     }
     $tagcloud->setTags($newtags, User::get('id'));
     // Get some needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     // Load the resource object
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->loadAlias($alias);
     if (!User::isGuest()) {
         $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
         // Get the groups the user has access to
         $usersgroups = $this->_getUsersGroups($xgroups);
     } else {
         $usersgroups = array();
     }
     // Get updated version
     $objV = new \Components\Tools\Tables\Version($this->database);
     $thistool = $objV->getVersionInfo('', $version, $resource->alias, '');
     $thistool = $thistool ? $thistool[0] : '';
     // Replace resource info with requested version
     $objV->compileResource($thistool, '', $resource, 'dev', $this->rconfig);
     // get language library
     $lang = Lang::getRoot();
     if (!$lang->load(strtolower('com_resources'), JPATH_BASE)) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_LOADING_LANGUAGE'));
     }
     // Set the document title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_PREVIEW_TOOL_PAGE') . ' (' . $resource->alias . ')';
     Document::setTitle($this->view->title);
     // Set the document pathway (breadcrumbs)
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
     }
     if (Pathway::count() <= 1) {
         Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $thistool->toolname), 'index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias);
         Pathway::append(Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&app=' . $alias . '&task=start&step=1');
     }
     $this->view->toolid = $this->_toolid;
     $this->view->step = 5;
     $this->view->version = $version;
     $this->view->resource = $resource;
     $this->view->config = $this->rconfig;
     $this->view->usersgroups = $usersgroups;
     $this->view->status = $status;
     // Pass error messages to the view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
Example #5
0
                    break;
                    // published
                // published
                case 2:
                    $state = 'draft';
                    break;
                    // draft
                // draft
                case 3:
                    $state = 'pending';
                    break;
                    // pending
            }
            $attachments = $ra->getCount($submission->id);
            $authors = $rc->getCount($submission->id, 'resources');
            $rt = new \Components\Resources\Helpers\Tags($submission->id);
            $tags = $rt->tags('count');
            ?>
					<tr class="<?php 
            echo $cls;
            ?>
">
						<td><?php 
            if ($submission->published == 2) {
                ?>
<a href="<?php 
                echo Route::url('index.php?option=' . $this->option . '&task=draft&step=1&id=' . $submission->id);
                ?>
"><?php 
            }
            echo stripslashes($submission->title);
Example #6
0
        echo $stats->display();
        ?>
					</div>
				</dd>
			</dl>
			<?php 
    }
    if ($this->model->params->get('show_audience')) {
        include_once PATH_CORE . DS . 'components' . DS . $this->option . DS . 'tables' . DS . 'audience.php';
        include_once PATH_CORE . DS . 'components' . DS . $this->option . DS . 'tables' . DS . 'audiencelevel.php';
        $ra = new \Components\Resources\Tables\Audience($database);
        $audience = $ra->getAudience($this->model->resource->id, $versionid = 0, $getlabels = 1, $numlevels = 4);
        $this->view('_audience', 'view')->set('audience', $audience)->set('showtips', 1)->set('numlevels', 4)->set('audiencelink', $this->model->params->get('audiencelink'))->display();
    }
    if ($this->model->params->get('supportedtag')) {
        $rt = new \Components\Resources\Helpers\Tags($this->model->resource->id);
        if ($rt->checkTagUsage($this->model->params->get('supportedtag'), $this->model->resource->id)) {
            include_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'helpers' . DS . 'handler.php';
            $tag = new \Components\Tags\Tables\Tag($database);
            $tag->loadTag($this->model->params->get('supportedtag'));
            ?>
			<p class="supported">
				<a href="<?php 
            echo $this->model->params->get('supportedlink', Route::url('index.php?option=com_tags&tag=' . $tag->tag));
            ?>
"><?php 
            echo $this->escape(stripslashes($tag->raw_tag));
            ?>
</a>
			</p>
			<?php 
Example #7
0
 /**
  * Build a query from filters
  *
  * @param   array   $filters  Filters to build query from
  * @return  string  SQL
  */
 public function buildQuery($filters = array())
 {
     $now = \Date::toSql();
     $query = "";
     if (isset($filters['tag']) && $filters['tag'] != '') {
         $query .= "FROM #__tags_object AS RTA ";
         $query .= "INNER JOIN #__tags AS TA ON RTA.tagid = TA.id AND RTA.tbl='resources', {$this->_tbl} AS C ";
     } else {
         $query .= "FROM {$this->_tbl} AS C ";
     }
     $query .= "LEFT JOIN #__resource_types AS t ON C.type=t.id ";
     $query .= "LEFT JOIN #__resource_types AS lt ON C.logical_type=lt.id ";
     if (isset($filters['type']) && $filters['type'] == 'tools' && isset($filters['toolState'])) {
         $query .= "LEFT JOIN #__tool AS T ON C.alias=T.toolname ";
     }
     $query .= "WHERE C.published=1 AND C.standalone=1 ";
     if (isset($filters['type']) && $filters['type'] != '') {
         if ($filters['type'] == 'nontools') {
             $query .= "AND C.type!=7 ";
         } else {
             if ($filters['type'] == 'tools') {
                 $filters['type'] = 7;
             }
             $query .= "AND C.type=" . $this->_db->quote($filters['type']) . " ";
             if (isset($filters['toolState'])) {
                 $query .= "AND T.state=" . $this->_db->quote($filters['toolState']) . " ";
             }
         }
     } else {
         $query .= "AND C.type!=8 ";
     }
     if (isset($filters['minranking']) && $filters['minranking'] != '' && $filters['minranking'] > 0) {
         $query .= "AND C.ranking > " . $this->_db->quote($filters['minranking']) . " ";
     }
     $query .= "AND (C.publish_up = '0000-00-00 00:00:00' OR C.publish_up <= " . $this->_db->quote($now) . ") ";
     $query .= "AND (C.publish_down = '0000-00-00 00:00:00' OR C.publish_down >= " . $this->_db->quote($now) . ") AND ";
     if (isset($filters['access']) && $filters['access'] == 'public') {
         $query .= "(C.access=0 OR C.access=3) ";
     } else {
         if (!\User::isGuest()) {
             $profile = \Hubzero\User\Profile::getInstance(\User::get('id'));
             $xgroups = is_object($profile) ? $profile->getGroups('all') : array();
             if ($xgroups != '') {
                 $usersgroups = self::getUsersGroups($xgroups);
                 if (count($usersgroups) > 1) {
                     $groups = implode("','", $usersgroups);
                 } else {
                     $groups = count($usersgroups) ? $usersgroups[0] : '';
                 }
                 $query .= "(C.access=0 OR C.access=1 OR C.access=3 OR (C.access=4 AND (C.group_owner IN ('" . $groups . "') ";
                 foreach ($usersgroups as $group) {
                     $query .= " OR C.group_access LIKE " . $this->_db->quote('%;' . $group . ';%');
                 }
                 $query .= "))) ";
             } else {
                 $query .= "(C.access=0 OR C.access=1 OR C.access=3) ";
             }
         } else {
             $query .= "(C.access=0 OR C.access=3) ";
         }
     }
     if (isset($filters['search']) && $filters['search'] != '') {
         $words = array();
         $ws = explode(' ', $filters['search']);
         foreach ($ws as $w) {
             $w = trim($w);
             if (strlen($w) > 2) {
                 $words[] = $w;
             }
         }
         $text = implode(' +', $words);
         $text = addslashes($text);
         $text2 = str_replace('+', '', $text);
         $query .= "AND ((MATCH(C.title) AGAINST ('+{$text} -\"{$text2}\"') > 0) OR" . " (MATCH(C.introtext,C.fulltxt) AGAINST ('+{$text} -\"{$text2}\"') > 0)) ";
     }
     if (isset($filters['tag']) && $filters['tag'] != '') {
         include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'tags.php';
         $tagging = new \Components\Resources\Helpers\Tags();
         $tags = $tagging->parseTags($filters['tag']);
         $query .= "AND RTA.objectid=C.id AND TA.tag IN ('" . implode("','", $tags) . "')";
         //" OR TA.alias IN ('" . implode("','", $tags) . "'))";
         $query .= " GROUP BY C.id HAVING uniques=" . count($tags);
     }
     $query .= " ORDER BY ";
     if (isset($filters['sortby'])) {
         switch ($filters['sortby']) {
             case 'date_created':
                 $query .= 'created DESC';
                 break;
             case 'date_modified':
                 $query .= 'modified DESC';
                 break;
             case 'title':
                 $query .= 'title ASC, publish_up';
                 break;
             case 'rating':
                 $query .= "rating DESC, times_rated DESC";
                 break;
             case 'ranking':
                 $query .= "ranking DESC";
                 break;
             case 'random':
                 $query .= "RAND()";
                 break;
             case 'date':
             case 'date_published':
             default:
                 $query .= 'publish_up DESC';
                 break;
         }
     }
     return $query;
 }
Example #8
0
?>
	</section>
	<section class="below section">
	<?php 
if ($this->results) {
    ?>
		<div class="subject">
			<h3><?php 
    echo Lang::txt('COM_RESOURCES_TOP_RATED');
    ?>
</h3>
			<?php 
    $supported = array();
    if ($this->supportedtag) {
        include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php';
        $rt = new \Components\Resources\Helpers\Tags(0);
        $supported = $rt->getTagUsage($this->supportedtag, 'id');
    }
    $this->view('_list', 'browse')->set('lines', $this->results)->set('show_edit', $this->authorized)->set('supported', $supported)->display();
    ?>
		</div><!-- / .subject -->
	<?php 
}
?>
		<aside class="aside">
			<p><?php 
echo Lang::txt('COM_RESOURCES_TOP_RATED_EXPLANATION');
?>
</p>
		</aside><!-- / .aside -->
	</div><!-- / .main section -->
Example #9
0
    $view->contributors = $this->model->contributors('submitter');
    $view->badges = $this->plugin->get('badges', 0);
    $view->showorgs = 1;
    $view->display();
    ?>
				</div>
			</div>
		<?php 
}
?>

		<?php 
if ($this->model->params->get('show_assocs')) {
    ?>
			<?php 
    $tagger = new \Components\Resources\Helpers\Tags($this->model->resource->id);
    if ($tags = $tagger->render('cloud', $this->model->access('edit') ? array() : array('admin' => 0))) {
        ?>
				<h4><?php 
        echo Lang::txt('PLG_RESOURCES_ABOUT_TAGS');
        ?>
</h4>
				<div class="resource-content">
					<?php 
        echo $tags;
        ?>
				</div>
			<?php 
    }
    ?>
		<?php 
Example #10
0
				<div class="clearfix"></div>
			</div><!-- / .container -->
		</div><!-- / .subject -->
		<aside class="aside">
			<div class="container">
				<h3><?php 
echo Lang::txt('COM_RESOURCES_FIND_RESOURCE');
?>
</h3>
				<p><?php 
echo Lang::txt('COM_RESOURCES_FIND_RESOURCE_DETAILS');
?>
</p>
			</div><!-- / .container -->
			<div class="container">
				<h3><?php 
echo Lang::txt('COM_RESOURCES_POPULAR_TAGS');
?>
</h3>
				<?php 
$rt = new \Components\Resources\Helpers\Tags(0);
echo $rt->getTopTagCloud(20, $this->filters['tag']);
?>
				<p><?php 
echo Lang::txt('COM_RESOURCES_POPULAR_TAGS_HINT');
?>
</p>
			</div>
		</aside><!-- / .aside -->
	</section><!-- / .main section -->
</form>
Example #11
0
 /**
  * Check if the tags step is completed
  *
  * @param   integer  $id  Resource ID
  * @return  boolean  True if step completed
  */
 public function step_tags_check($id)
 {
     $database = App::get('db');
     $rt = new \Components\Resources\Helpers\Tags($id);
     $tags = $rt->tags('count');
     if ($tags > 0) {
         return true;
     }
     return false;
 }
Example #12
0
 /**
  * Save a review
  *
  * @return     void
  */
 public function savereview()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $resource_id = Request::getInt('resource_id', 0);
     // Do we have a resource ID?
     if (!$resource_id) {
         // No ID - fail! Can't do anything else without an ID
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $database = App::get('db');
     // Bind the form data to our object
     $row = new \Components\Resources\Tables\Review($database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         return;
     }
     // Perform some text cleaning, etc.
     $row->id = Request::getInt('reviewid', 0);
     if (!$row->id) {
         $row->state = 1;
     }
     $row->comment = \Hubzero\Utility\Sanitize::stripImages(\Hubzero\Utility\Sanitize::clean($row->comment));
     $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0;
     $row->created = $row->created && $row->created != '0000-00-00 00:00:00' ? $row->created : Date::toSql();
     // Check for missing (required) fields
     if (!$row->check()) {
         $this->setError($row->getError());
         return;
     }
     // Save the data
     if (!$row->store()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent resource
     $resource =& $this->resource;
     $resource->calculateRating();
     $resource->updateRating();
     // Process tags
     $tags = trim(Request::getVar('review_tags', ''));
     if ($tags) {
         $rt = new \Components\Resources\Helpers\Tags($resource_id);
         $rt->setTags($tags, $row->user_id);
     }
     // Instantiate a helper object and get all the contributor IDs
     $helper = new \Components\Resources\Helpers\Helper($resource->id, $database);
     $helper->getContributorIDs();
     $users = $helper->contributorIDs;
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'resources', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->user = User::getRoot();
     $eview->resource = $resource;
     $eview->review = $row;
     $message = $eview->loadTemplate();
     // Build the "from" data for the e-mail
     $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('PLG_RESOURCES_REVIEWS_CONTRIBUTIONS'), 'email' => Config::get('mailfrom'));
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('resources_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_FAILED_TO_MESSAGE'));
     }
 }
Example #13
0
 /**
  * Return data on a resource sub view (this will be some form of HTML)
  *
  * @param      object  $resource Current resource
  * @param      string  $option    Name of the component
  * @param      integer $miniview  View style
  * @return     array
  */
 public function onResourcesSub($resource, $option, $miniview = 0)
 {
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     // Get recommendations
     $this->database = App::get('db');
     // Instantiate a view
     $this->view = $this->view('mini', 'display');
     if ($miniview) {
         $this->view->setLayout('mini');
     }
     // Pass the view some info
     $this->view->option = $option;
     $this->view->resource = $resource;
     $this->view->params = $this->params;
     $this->view->data = '';
     require_once __DIR__ . DS . 'tables' . DS . 'sponsor.php';
     $this->sponsors = array();
     $model = new \Plugins\Resources\Sponsors\Tables\Sponsor($this->database);
     $records = $model->getRecords(array('state' => 1));
     if (!$records) {
         return $arr;
     }
     foreach ($records as $record) {
         $this->sponsors[$record->alias] = $record;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'tags.php';
     $rt = new \Components\Resources\Helpers\Tags($resource->id);
     $tags = $rt->tags();
     if ($tags) {
         foreach ($tags as $tag) {
             if (isset($this->sponsors[$tag->get('tag')])) {
                 $this->view->data = $this->sponsors[$tag->get('tag')]->description;
                 break;
             }
         }
     }
     if ($this->getError()) {
         $this->view->setError($this->getError());
     }
     // Return the output
     $arr['html'] = $this->view->loadTemplate();
     return $arr;
 }