/** * 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 some needed libraries include_once __DIR__ . DS . 'resources.recommendation.php'; // Set some filters for returning results $filters = array('id' => $resource->id, 'threshold' => $this->params->get('threshold', '0.21'), 'limit' => $this->params->get('display_limit', 10)); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->resource = $resource; // Get recommendations $database = App::get('db'); $r = new ResourcesRecommendation($database); $view->results = $r->getResults($filters); if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); return $arr; }
/** * Return data on a publication sub view (this will be some form of HTML) * * @param object $publication Current publication * @param string $option Name of the component * @param integer $miniview View style * @return array */ public function onPublicationSub($publication, $option, $miniview = 0) { $arr = array('html' => '', 'metadata' => '', 'name' => 'recommendations'); // Check if our area is in the array of areas we want to return results for $areas = array('recommendations'); if (!array_intersect($areas, $this->onPublicationSubAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationSubAreas($publication)))) { return false; } // Get some needed libraries include_once PATH_CORE . DS . 'plugins' . DS . 'publications' . DS . 'recommendations' . DS . 'publication.recommendation.php'; // Set some filters for returning results $filters = array('id' => $publication->get('id'), 'threshold' => $this->params->get('threshold', '0.21'), 'limit' => $this->params->get('display_limit', 10)); // Get recommendations $database = App::get('db'); $r = new PublicationRecommendation($database); $results = $r->getResults($filters); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->publication = $publication; $view->results = $results; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); return $arr; }
/** * Send emails to authors with the monthly stats * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function sendAuthorStats(\Components\Cron\Models\Job $job) { $database = App::get('db'); $pconfig = Component::params('com_publications'); // Get some params $limit = $pconfig->get('limitStats', 5); $image = $pconfig->get('email_image', ''); Lang::load('com_publications', PATH_CORE) || Lang::load('com_publications', PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'site'); // Is logging enabled? if (is_file(PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'logs.php')) { require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'logs.php'; } else { $this->setError('Publication logs not present on this hub, cannot email stats to authors'); return false; } // Helpers require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'helpers' . DS . 'imghandler.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'helpers' . DS . 'html.php'; // Get all registered authors who subscribed to email $query = "SELECT A.user_id, P.picture "; $query .= " FROM #__publication_authors as A "; $query .= " JOIN #__xprofiles as P ON A.user_id = P.uidNumber "; $query .= " WHERE P.mailPreferenceOption != 0 "; // either 1 (set to YES) or -1 (never set) $query .= " AND A.user_id > 0 AND A.status=1 "; // If we need to restrict to selected authors $params = $job->get('params'); if (is_object($params) && $params->get('userids')) { $apu = explode(',', $params->get('userids')); $apu = array_map('trim', $apu); $query .= " AND A.user_id IN ("; $tquery = ''; foreach ($apu as $a) { $tquery .= "'" . $a . "',"; } $tquery = substr($tquery, 0, strlen($tquery) - 1); $query .= $tquery . ") "; } $query .= " GROUP BY A.user_id "; $database->setQuery($query); if (!($authors = $database->loadObjectList())) { return true; } // Set email config $from = array('name' => Config::get('fromname') . ' ' . Lang::txt('Publications'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); $subject = Lang::txt('Monthly Publication Usage Report'); $i = 0; foreach ($authors as $author) { // Get the user's account $user = User::getInstance($author->user_id); if (!$user->get('id')) { // Skip if not registered continue; } // Get pub stats for each author $pubLog = new \Components\Publications\Tables\Log($database); $pubstats = $pubLog->getAuthorStats($author->user_id); if (!$pubstats || !count($pubstats)) { // Nothing to send continue; } // Plain text $eview = new \Hubzero\Plugin\View(array('folder' => 'cron', 'element' => 'publications', 'name' => 'emails', 'layout' => 'stats_plain')); $eview->option = 'com_publications'; $eview->controller = 'publications'; $eview->user = $user; $eview->pubstats = $pubstats; $eview->limit = $limit; $eview->image = $image; $eview->config = $pconfig; $eview->totals = $pubLog->getTotals($author->user_id, 'author'); $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('stats_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Build message $message = new \Hubzero\Mail\Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications'); $message->addPart($plain, 'text/plain'); $message->addPart($html, 'text/html'); // Send mail if (!$message->send()) { $this->setError(Lang::txt('PLG_CRON_PUBLICATIONS_ERROR_FAILED_TO_MAIL', $user->get('email'))); } $mailed[] = $user->get('email'); } return true; }
/** * 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' => ''); $database = App::get('db'); // Build the query that checks topic pages $sql1 = "SELECT v.id, v.pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS introtext,\n\t\t\t\t\tNULL AS type, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'Topic' AS section, w.`group_cn`\n\t\t\t\tFROM `#__wiki_page` AS w\n\t\t\t\tJOIN `#__wiki_version` AS v ON w.id=v.pageid\n\t\t\t\tJOIN `#__wiki_page_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='resource' AND wl.scope_id=" . $database->Quote($resource->id); if (!User::isGuest()) { if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) { $sql1 .= ''; } else { $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members'); $groups = array(); if ($ugs && count($ugs) > 0) { foreach ($ugs as $ug) { $groups[] = $ug->cn; } } $g = "'" . implode("','", $groups) . "'"; $sql1 .= "AND (w.access!=1 OR (w.access=1 AND (w.group_cn IN ({$g}) OR w.created_by='" . User::get('id') . "'))) "; } } else { $sql1 .= "AND w.access!=1 "; } $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10"; // Build the query that checks resource parents $sql2 = "SELECT DISTINCT r.id, NULL AS pageid, NULL AS version, r.title, r.alias, r.introtext, r.type, r.published, r.publish_up, " . " NULL AS scope, r.rating, r.times_rated, r.ranking, rt.type AS section, NULL AS `group` " . " FROM #__resource_types AS rt, #__resources AS r" . " JOIN #__resource_assoc AS a ON r.id=a.parent_id" . " LEFT JOIN #__resource_types AS t ON r.logical_type=t.id" . " WHERE r.published=1 AND a.child_id=" . $resource->id . " AND r.type=rt.id AND r.type!=8 "; if (!User::isGuest()) { if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) { $sql2 .= ''; } else { $sql2 .= "AND (r.access!=1 OR (r.access=1 AND (r.group_owner IN ({$g}) OR r.created_by='" . User::get('id') . "'))) "; } } else { $sql2 .= "AND r.access=0 "; } $sql2 .= "ORDER BY r.ranking LIMIT 10"; // Build the final query $query = "SELECT k.* FROM (({$sql1}) UNION ({$sql2})) AS k ORDER BY ranking DESC LIMIT 10"; // Execute the query $database->setQuery($query); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->resource = $resource; $view->related = $database->loadObjectList(); foreach ($this->getErrors() as $error) { $view->setError($error); } // Return the output $arr['html'] = $view->loadTemplate(); // Return the an array of content return $arr; }