/** * 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; }
/** * 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(); }
/** * 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); }
/** * Return either a count or an array of the member's contributions * * @param object $member Current member * @param string $option Component name * @param string $authorized Authorization level * @param integer $limit Number of record to return * @param integer $limitstart Record return start * @param string $sort Field to sort records on * @param array $areas Areas to return data for * @return array */ public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null) { $database = App::get('db'); if (is_array($areas) && $limit) { $ars = $this->onMembersContributionsAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a member ID? if ($member instanceof \Hubzero\User\Profile) { if (!$member->get('uidNumber')) { return array(); } else { $uidNumber = $member->get('uidNumber'); } } else { if (!$member->uidNumber) { return array(); } else { $uidNumber = $member->uidNumber; } } // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['author'] = $uidNumber; $filters['sortby'] = $sort; //$filters['authorized'] = $authorized; //$filters['usergroups'] = \Hubzero\User\Helper::getGroups($uidNumber, 'all'); $filters['usergroups'] = $member->getGroups('all'); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); $normalized_valid_chars = 'a-zA-Z0-9'; for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^{$normalized_valid_chars}]/", "", $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } } if ($total == 0) { return array(); } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit //if (count($areas) == 1 && key($areas[0]) != 'resources') { if (count($areas) == 1 && !isset($areas['resources'])) { $filters['type'] = isset($cats[$areas[0]]) ? $cats[$areas[0]]['id'] : 0; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } } } // Return the results return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->onMembersContributionsAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { $i = 0; foreach ($val as $a => $t) { if ($limitstart == -1) { if ($i == 0) { $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } else { $counts[] = 0; } } else { $filters['type'] = $cats[$a]['id']; // Execute a count query for each area/category $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } $i++; } } } // Return the counts $this->_total = $counts; return $counts; } }
/** * 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(); }
/** * 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(); }
/** * Display module content * * @return void */ public function display() { if (User::isGuest()) { return false; } include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; include_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php'; $this->steps = array('Type', 'Compose', 'Attach', 'Authors', 'Tags', 'Review'); $database = App::get('db'); $rr = new \Components\Resources\Tables\Resource($database); $rt = new \Components\Resources\Tables\Type($database); $query = "SELECT r.*, t.type AS typetitle\n\t\t\tFROM " . $rr->getTableName() . " AS r\n\t\t\tLEFT JOIN " . $rt->getTableName() . " AS t ON r.type=t.id\n\t\t\tWHERE r.published=2 AND r.standalone=1 AND r.type!=7 AND r.created_by=" . User::get('id'); $database->setQuery($query); $this->rows = $database->loadObjectList(); if ($this->rows) { include_once Component::path('com_resources') . DS . 'tables' . DS . 'assoc.php'; include_once Component::path('com_resources') . DS . 'tables' . DS . 'contributor.php'; include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php'; } require $this->getLayoutPath(); }
/** * Retrieve records for items associated with this group * * @param object $group Group that owns the records * @param unknown $authorized Authorization level * @param mixed $limit SQL record limit * @param integer $limitstart SQL record limit start * @param string $sort The field to sort records by * @param string $access Access level * @param mixed $areas An array or string of areas that should retrieve records * @return mixed Returns integer when counting records, array when retrieving records */ public function getResources($group, $authorized, $limit = 0, $limitstart = 0, $sort = 'date', $access = 'all', $areas = null) { // Check if our area is in the array of areas we want to return results for if (is_array($areas) && $limit) { $ars = $this->getResourcesAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a member ID? if (!$group->get('cn')) { return array(); } $database = App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['now'] = \Date::toSql(); $filters['sortby'] = $sort; $filters['group'] = $group->get('cn'); $filters['access'] = $access; $filters['authorized'] = $authorized; $filters['state'] = array(1); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^a-zA-Z0-9]/", '', $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } } if ($total == 0) { return array(); } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (count($areas) == 1 && !isset($areas['resources']) && $areas[0] != 'resources') { $filters['type'] = $cats[$areas[0]]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } } } // Return the results return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->getResourcesAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { $i = 0; foreach ($val as $a => $t) { if ($limitstart == -1) { if ($i == 0) { $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } else { $counts[] = 0; } } else { $filters['type'] = $cats[$a]['id']; // Execute a count query for each area/category $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } $i++; } } } // Return the counts $this->_total = $counts; return $counts; } }
/** * Update a tool version * * @return void */ public function updateTask() { // get vars if (!$this->_toolid) { $this->_toolid = Request::getInt('toolid', 0); } // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); // do we have an alias? if ($this->_toolid == 0) { if ($alias = Request::getVar('app', '')) { $this->_toolid = $obj->getToolId($alias); } } if (!$this->_error) { $this->_error = Request::getVar('error', ''); } $error = ''; //$id = $this->_toolid; // make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } $newstate = Request::getVar('newstate', ''); $priority = Request::getVar('priority', 3); $comment = Request::getVar('comment', ''); $access = Request::getInt('access', 0); $newversion = Request::getVar('newversion', ''); $editversion = Request::getVar('editversion', 'dev'); $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hztv = $hzt->getRevision($editversion); $oldstatus = $hztv ? $hztv->toArray() : array(); $oldstatus['toolstate'] = $hzt->state; if ($newstate && !intval($newstate)) { $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate); } if (intval($newstate) && $newstate != $oldstatus['toolstate']) { Log::debug(__FUNCTION__ . "() state changing"); if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved') && \Components\Tools\Models\Tool::validateVersion($oldstatus['version'], $error, $hzt->id)) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action confirm"); $this->_action = 'confirm'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved')) { $this->_error = $error; Log::debug(__FUNCTION__ . "() state changing to approved, action new"); $this->_action = 'new'; $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL'); $this->versionsTask(); return; } else { if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { Log::debug(__FUNCTION__ . "() state changing to published"); $hzt->published = '1'; } } } $this->_error = $error; // update dev screenshots of a published tool changes status if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Published')) { // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); Log::debug(__FUNCTION__ . "() state changing away from published"); // Get version ids $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id); $to = $objV->getVersionIdFromResource($rid, 'dev'); $from = $objV->getVersionIdFromResource($rid, 'current'); $dev_hztv = $hzt->getRevision('dev'); $current_hztv = $hzt->getRevision('current'); Log::debug("update: to={$to} from={$from} dev=" . $dev_hztv->id . " current=" . $current_hztv->id); if ($to && $from) { require_once __DIR__ . DS . 'screenshots.php'; $ss = new Screenshots(); $ss->transfer($from, $to, $rid); } } // If the tool was cancelled ... if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) { include_once __DIR__ . DS . 'resource.php'; $r = new \Components\Resources\Tables\Resource($this->database); $r->loadAlias($hzt->toolname); if ($r && $r->id) { $rstatus = 2; if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) { $rstatus = 1; } $resource = new Resource(); $resource->updatePage($r->id, $oldstatus, $rstatus); } } Log::debug(__FUNCTION__ . "() state changing to {$newstate}"); $hzt->state = $newstate; $hzt->state_changed = Date::toSql(); } // if priority changes if (intval($priority) && $priority != $oldstatus['priority']) { $hzt->priority = $priority; } // save tool info $hzt->update(); $hztv->update(); //@FIXME: look // get tool status after updates $status = $hztv->toArray(); $status['toolstate'] = $hzt->state; // update history ticket Log::debug(__FUNCTION__ . "() before newUpdateTicket test"); if ($oldstatus != $status || !empty($comment)) { Log::debug(__FUNCTION__ . "() before newUpdateTicket"); $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, $access, 1); Log::debug(__FUNCTION__ . "() after newUpdateTicket"); } $this->_msg = Lang::txt('COM_TOOLS_NOTICE_STATUS_CHANGED'); $this->statusTask(); }
//get the manifest for the presentation $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);
/** * 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(); }
/** * Get a count of all resources * * @param integer $gid Group ID * @param string $authorized Authorization level * @return integer */ public static function getResourcesCount($gid = NULL, $authorized) { if (!$gid) { return 0; } $database = App::get('db'); include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php'; $rr = new \Components\Resources\Tables\Resource($database); $database->setQuery("SELECT COUNT(*) FROM " . $rr->getTableName() . " AS r WHERE r.group_owner=" . $database->quote($gid)); return $database->loadResult(); }
/** * 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; }
/** * 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; }
/** * [_getResources description] * @param string $type [description] * @param integer $limit [description] * @return [type] [description] */ private function _getResources($type = 'all', $limit = 5) { // database object $database = \App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array(); $filters['now'] = date('Y-m-d H:i:s', time() + 0 * 60 * 60); $filters['sortby'] = 'date'; $filters['group'] = $this->group->get('cn'); $filters['access'] = 'all'; $filters['authorized'] = ''; $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = 0; // Get categories $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $normalized = preg_replace("/[^a-zA-Z0-9]/", '', $categories[$i]->type); $normalized = strtolower($normalized); $cats[$normalized] = array(); $cats[$normalized]['id'] = $categories[$i]->id; } // do we have a type? if (in_array($type, array_keys($cats))) { $filters['type'] = $cats[$type]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); return $rows; }
/** * 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(); }
/** * 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; }
/** * Get module contents * * @return void */ public function run() { include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php'; include_once Component::path('com_members') . DS . 'tables' . DS . 'profile.php'; include_once Component::path('com_members') . DS . 'tables' . DS . 'association.php'; include_once Component::path('com_answers') . DS . 'tables' . DS . 'question.php'; include_once Component::path('com_answers') . DS . 'tables' . DS . 'response.php'; include_once Component::path('com_blog') . DS . 'tables' . DS . 'entry.php'; include_once Component::path('com_blog') . DS . 'tables' . DS . 'comment.php'; $this->database = \App::get('db'); // Get the admin configured settings $filters = array(); $filters['limit'] = 5; $filters['start'] = 0; // featured items $tbls = array('resources', 'profiles'); $spots = array(); $spots[0] = trim($this->params->get('spotone')); $spots[1] = trim($this->params->get('spottwo')); $spots[2] = trim($this->params->get('spotthree')); $spots[3] = trim($this->params->get('spotfour')); $spots[4] = trim($this->params->get('spotfive')); $spots[5] = trim($this->params->get('spotsix')); $spots[6] = trim($this->params->get('spotseven')); $numspots = $this->params->get('numspots', 3); // some collectors $activespots = array(); $rows = array(); // styling $cls = trim($this->params->get('moduleclass_sfx')); $txtLength = trim($this->params->get('txt_length')); $start = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 00:00:00'; $end = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 23:59:59'; $this->html = ''; $k = 1; $out = ''; for ($i = 0, $n = $numspots; $i < $numspots; $i++) { $spot = $spots[$i]; if ($spot == '') { continue; } $row = null; $out = ''; $tbl = ''; $tbl = $spot == 'tools' || $spot == 'nontools' ? 'resources' : ''; $tbl = $spot == 'members' ? 'profiles' : $tbl; $tbl = $spot == 'topics' ? 'topics' : $tbl; $tbl = $spot == 'itunes' ? 'itunes' : $tbl; $tbl = $spot == 'answers' ? 'answers' : $tbl; $tbl = $spot == 'blog' ? 'blog' : $tbl; $tbl = !$tbl ? array_rand($tbls, 1) : $tbl; // we need to randomly choose one switch ($tbl) { case 'resources': // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($this->database); $filters['start'] = 0; $filters['type'] = $spot; $filters['sortby'] = 'random'; $filters['minranking'] = trim($this->params->get('minranking')); $filters['tag'] = $spot == 'tools' ? trim($this->params->get('tag')) : ''; // tag is set for tools only // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false); break; case 'profiles': // No - so we need to randomly choose one $filters['start'] = 0; $filters['sortby'] = "RAND()"; $filters['search'] = ''; $filters['state'] = 'public'; $filters['authorized'] = false; $filters['tag'] = ''; $filters['contributions'] = trim($this->params->get('min_contributions')); $filters['show'] = trim($this->params->get('show')); $mp = new \Components\Members\Tables\Profile($this->database); // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $mp->getRecords($filters, false); break; case 'topics': // No - so we need to randomly choose one $topics_tag = trim($this->params->get('topics_tag')); $query = "SELECT DISTINCT w.id, w.pagename, w.title "; $query .= " FROM #__wiki_page AS w "; if ($topics_tag) { $query .= " JOIN #__tags_object AS RTA ON RTA.objectid=w.id AND RTA.tbl='wiki' "; $query .= " INNER JOIN #__tags AS TA ON TA.id=RTA.tagid "; } else { $query .= ", #__wiki_version AS v "; } $query .= " WHERE w.access!=1 AND w.scope = '' "; if ($topics_tag) { $query .= " AND (TA.tag='" . $topics_tag . "' OR TA.raw_tag='" . $topics_tag . "') "; } else { $query .= " AND v.pageid=w.id AND v.approved = 1 AND v.pagetext != '' "; } $query .= " ORDER BY RAND() "; $this->database->setQuery($query); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList(); break; case 'itunes': // Initiate a resource object $rr = new \Components\Resources\Tables\Resource($this->database); $filters['start'] = 0; $filters['sortby'] = 'random'; $filters['tag'] = trim($this->params->get('itunes_tag')); // Get records $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false); break; case 'answers': $query = "SELECT C.id, C.subject, C.question, C.created, C.created_by, C.anonymous "; $query .= ", (SELECT COUNT(*) FROM #__answers_responses AS a WHERE a.state!=2 AND a.question_id=C.id) AS rcount "; $query .= " FROM #__answers_questions AS C "; $query .= " WHERE C.state=0 "; $query .= " AND (C.reward > 0 OR C.helpful > 0) "; $query .= " ORDER BY RAND() "; $this->database->setQuery($query); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList(); break; case 'blog': $filters = array(); $filters['limit'] = 1; $filters['start'] = 0; $filters['state'] = 'public'; $filters['order'] = "RAND()"; $filters['search'] = ''; $filters['scope'] = 'member'; $filters['group_id'] = 0; $filters['authorized'] = false; $filters['sql'] = ''; $mp = new \Components\Blog\Tables\Entry($this->database); $entry = $mp->getRecords($filters); $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $entry; break; } if ($rows && count($rows[$spot]) > 0) { $row = $rows[$spot][0]; } // make sure we aren't pulling the same item if ($k != 1 && in_array($spot, $activespots) && $rows && count($rows[$spot]) > 1) { $row = count($rows[$spot]) < $k ? $rows[$spot][$k - 1] : $rows[$spot][1]; // get the next one } // pull info if ($row) { $out = $this->_composeEntry($row, $tbl, $txtLength); $itemid = $this->_composeEntry($row, $tbl, 0, 1); $activespots[] = $spot; } // Did we get any results? if ($out) { $this->html .= '<li class="spot_' . $k . '">' . $out . '</li>' . "\n"; $k++; } } // Output HTML require $this->getLayoutPath(); }
/** * Pull a list of records that were created within the time frame ($period) * * @param object $period Time period to pull results for * @param mixed $limit Number of records to pull * @param integer $limitstart Start of records to pull * @param array $areas Active area(s) * @param array $tagids Array of tag IDs * @return array */ public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array()) { if (is_array($areas) && $limit) { $ars = $this->onWhatsnewAreas(); if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($ars['resources']))) { return array(); } } // Do we have a time period? if (!is_object($period)) { return array(); } $database = App::get('db'); // Instantiate some needed objects $rr = new \Components\Resources\Tables\Resource($database); // Build query $filters = array('startdate' => $period->cStartDate, 'enddate' => $period->cEndDate, 'sortby' => 'date'); if (count($tagids) > 0) { $filters['tags'] = $tagids; } $filters['usergroups'] = \Hubzero\User\Helper::getGroups((int) User::get('id', 0), 'all'); // Get categories $categories = $this->_cats; if (!is_array($categories)) { $rt = new \Components\Resources\Tables\Type($database); $categories = $rt->getMajorTypes(); } // Normalize the category names // e.g., "Oneline Presentations" -> "onlinepresentations" $cats = array(); for ($i = 0; $i < count($categories); $i++) { $cats[$categories[$i]->alias] = array(); $cats[$categories[$i]->alias]['id'] = $categories[$i]->id; } $filters['authorized'] = false; if ($limit) { if ($this->_total != null) { $total = 0; $t = $this->_total; foreach ($t as $l) { $total += $l; } if ($total == 0) { return array(); } } $filters['select'] = 'records'; $filters['limit'] = $limit; $filters['limitstart'] = $limitstart; // Check the area of return. If we are returning results for a specific area/category // we'll need to modify the query a bit if (count($areas) == 1 && isset($areas[0]) && $areas[0] != 'resources') { $filters['type'] = $cats[$areas[0]]['id']; } // Get results $database->setQuery($rr->buildPluginQuery($filters)); $rows = $database->loadObjectList(); // Did we get any results? if ($rows) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php'; // Loop through the results and set each item's HREF foreach ($rows as $key => $row) { $resourceEx = new \Components\Resources\Helpers\Helper($row->id, $database); $resourceEx->getContributors(); $rows[$key]->authors = $resourceEx->contributors; if ($row->alias) { $rows[$key]->href = Route::url('index.php?option=com_resources&alias=' . $row->alias); } else { $rows[$key]->href = Route::url('index.php?option=com_resources&id=' . $row->id); } if ($row->itext) { $rows[$key]->text = $rows[$key]->itext; } else { if ($row->ftext) { $rows[$key]->text = $rows[$key]->ftext; } } } } return $rows; } else { $filters['select'] = 'count'; // Get a count $counts = array(); $ares = $this->onWhatsnewAreas(); foreach ($ares as $area => $val) { if (is_array($val)) { foreach ($val as $a => $t) { $filters['type'] = $cats[$a]['id']; $database->setQuery($rr->buildPluginQuery($filters)); $counts[] = $database->loadResult(); } } } // Return the counts $this->_total = $counts; return $counts; } }
/** * 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; }