示例#1
0
    echo Lang::txt('COM_RESOURCES_ERROR_MUST_BE_PART_OF_GROUP') . ' ' . implode(', ', $ghtml);
    ?>
						</p>
						<?php 
} else {
    $ccount = count($this->model->children('standalone'));
    if ($ccount > 0) {
        echo \Components\Resources\Helpers\Html::primary_child($this->option, $this->model->resource, '', '');
    }
    $video = 0;
    $audio = 0;
    $notes = 0;
    $children = $this->model->children('standalone');
    if (!empty($children)) {
        foreach ($children as $child) {
            $rhelper = new \Components\Resources\Helpers\Helper($child->id, $this->database);
            $rhelper->getChildren();
            if ($rhelper->children && count($rhelper->children) > 0) {
                foreach ($rhelper->children as $grandchild) {
                    switch (\Components\Resources\Helpers\Html::getFileExtension($grandchild->path)) {
                        case 'm4v':
                        case 'mp4':
                        case 'wmv':
                        case 'mov':
                        case 'qt':
                        case 'mpg':
                        case 'mpeg':
                        case 'mpe':
                        case 'mp2':
                        case 'mpv2':
                            $videos++;
示例#2
0
 /**
  * Special formatting for results
  *
  * @param      object $row    Database row
  * @param      string $period Time period
  * @return     string
  */
 public static function out($row, $period)
 {
     $database = App::get('db');
     $helper = new \Components\Resources\Helpers\Helper($row->id, $database);
     // Instantiate a helper object
     if (!isset($row->authors)) {
         $helper->getContributors();
         $row->authors = $helper->contributors;
     }
     // Get the component params and merge with resource params
     $config = Component::params('com_resources');
     $rparams = new \Hubzero\Config\Registry($row->params);
     // Set the display date
     switch ($rparams->get('show_date', $config->get('show_date'))) {
         case 0:
             $thedate = '';
             break;
         case 1:
             $thedate = Date::of($row->created)->toLocal(Lang::txt('DATE_FORMAT_HZ1'));
             break;
         case 2:
             $thedate = Date::of($row->modified)->toLocal(Lang::txt('DATE_FORMAT_HZ1'));
             break;
         case 3:
             $thedate = Date::of($row->publish_up)->toLocal(Lang::txt('DATE_FORMAT_HZ1'));
             break;
     }
     // Start building HTML
     $html = "\t" . '<li class="resource">' . "\n";
     $html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a></p>' . "\n";
     if ($rparams->get('show_ranking', $config->get('show_ranking'))) {
         $helper->getCitationsCount();
         $helper->getLastCitationDate();
         if ($row->area == 'Tools') {
             $stats = new \Components\Resources\Helpers\Usage\Stats($database, $row->id, $row->category, $row->rating, $helper->citationsCount, $helper->lastCitationDate);
         } else {
             $stats = new \Components\Resources\Helpers\Usage\Andmore($database, $row->id, $row->category, $row->rating, $helper->citationsCount, $helper->lastCitationDate);
         }
         $statshtml = $stats->display();
         $row->ranking = round($row->ranking, 1);
         $html .= "\t\t" . '<div class="metadata">' . "\n";
         $r = 10 * $row->ranking;
         if (intval($r) < 10) {
             $r = '0' . $r;
         }
         $html .= "\t\t\t" . '<dl class="rankinfo">' . "\n";
         $html .= "\t\t\t\t" . '<dt class="ranking"><span class="rank-' . $r . '">' . Lang::txt('PLG_WHATSNEW_RESOURCES_THIS_HAS') . '</span> ' . number_format($row->ranking, 1) . ' ' . Lang::txt('PLG_WHATSNEW_RESOURCES_RANKING') . '</dt>' . "\n";
         $html .= "\t\t\t\t" . '<dd>' . "\n";
         $html .= "\t\t\t\t\t" . '<p>' . Lang::txt('PLG_WHATSNEW_RESOURCES_RANKING_EXPLANATION') . '</p>' . "\n";
         $html .= "\t\t\t\t\t" . '<div>' . "\n";
         $html .= $statshtml;
         $html .= "\t\t\t\t\t" . '</div>' . "\n";
         $html .= "\t\t\t\t" . '</dd>' . "\n";
         $html .= "\t\t\t" . '</dl>' . "\n";
         $html .= "\t\t" . '</div>' . "\n";
     } elseif ($rparams->get('show_rating', $config->get('show_rating'))) {
         switch ($row->rating) {
             case 0.5:
                 $class = ' half-stars';
                 break;
             case 1:
                 $class = ' one-stars';
                 break;
             case 1.5:
                 $class = ' onehalf-stars';
                 break;
             case 2:
                 $class = ' two-stars';
                 break;
             case 2.5:
                 $class = ' twohalf-stars';
                 break;
             case 3:
                 $class = ' three-stars';
                 break;
             case 3.5:
                 $class = ' threehalf-stars';
                 break;
             case 4:
                 $class = ' four-stars';
                 break;
             case 4.5:
                 $class = ' fourhalf-stars';
                 break;
             case 5:
                 $class = ' five-stars';
                 break;
             case 0:
             default:
                 $class = ' no-stars';
                 break;
         }
         $html .= "\t\t" . '<div class="metadata">' . "\n";
         $html .= "\t\t\t" . '<p class="rating"><span class="avgrating' . $class . '"><span>' . Lang::txt('PLG_WHATSNEW_RESOURCES_OUT_OF_5_STARS', $row->rating) . '</span>&nbsp;</span></p>' . "\n";
         $html .= "\t\t" . '</div>' . "\n";
     }
     $html .= "\t\t" . '<p class="details">' . $thedate . ' <span>|</span> ' . $row->area;
     if ($row->authors) {
         $html .= ' <span>|</span> ' . Lang::txt('PLG_WHATSNEW_RESOURCES_CONTRIBUTORS') . ' ' . $row->authors;
     }
     $html .= '</p>' . "\n";
     if ($row->itext) {
         $html .= "\t\t" . '<p>' . \Hubzero\Utility\String::truncate(strip_tags(stripslashes($row->itext)), 200) . '</p>' . "\n";
     } else {
         if ($row->ftext) {
             $html .= "\t\t" . '<p>' . \Hubzero\Utility\String::truncate(strip_tags(stripslashes($row->ftext)), 200) . '</p>' . "\n";
         }
     }
     $html .= "\t\t" . '<p class="href">' . Request::base() . trim($row->href, '/') . '</p>' . "\n";
     $html .= "\t" . '</li>' . "\n";
     // Return output
     return $html;
 }
示例#3
0
 /**
  * Generate an RSS feed
  *
  * @return  string  RSS
  */
 public function feedTask()
 {
     // Incoming
     $tagstring = trim(Request::getVar('tag', '', 'request', 'none', 2));
     // Ensure we were passed a tag
     if (!$tagstring) {
         throw new Exception(Lang::txt('COM_TAGS_NO_TAG'), 404);
     }
     // Break the string into individual tags
     $tgs = explode(',', $tagstring);
     // Sanitize the tag
     $tags = array();
     $added = array();
     foreach ($tgs as $tag) {
         // Load the tag
         $tagobj = Tag::getInstance($tag);
         if (in_array($tagobj->get('tag'), $added)) {
             continue;
         }
         $added[] = $tagobj->get('tag');
         // Ensure we loaded the tag's info from the database
         if ($tagobj->exists()) {
             $tags[] = $tagobj;
         }
     }
     // Paging variables
     $limitstart = Request::getInt('limitstart', 0);
     $limit = Request::getInt('limit', Config::get('list_limit'));
     $areas = array();
     $searchareas = Event::trigger('tags.onTagAreas');
     foreach ($searchareas as $area) {
         $areas = array_merge($areas, $area);
     }
     // Get the active category
     $area = Request::getVar('area', '');
     $sort = Request::getVar('sort', '');
     if ($area) {
         $activeareas = array($area);
     } else {
         $activeareas = $areas;
     }
     // Get the search results
     if (count($activeareas) > 1) {
         $sqls = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, $activeareas));
         if ($sqls) {
             $s = array();
             foreach ($sqls as $sql) {
                 if (!is_string($sql)) {
                     continue;
                 }
                 if (trim($sql) != '') {
                     $s[] = $sql;
                 }
             }
             $query = "(";
             $query .= implode(") UNION (", $s);
             $query .= ") ORDER BY ";
             switch ($sort) {
                 case 'title':
                     $query .= 'title ASC, publish_up';
                     break;
                 case 'id':
                     $query .= "id DESC";
                     break;
                 case 'date':
                 default:
                     $query .= 'publish_up DESC, title';
                     break;
             }
             $query .= $limit != 'all' && $limit > 0 ? " LIMIT {$limitstart}, {$limit}" : "";
         }
         $this->database->setQuery($query);
         $results = array($this->database->loadObjectList());
     } else {
         $results = Event::trigger('tags.onTagView', array($tags, $limit, $limitstart, $sort, $activeareas));
     }
     // Run through the array of arrays returned from plugins and find the one that returned results
     $rows = array();
     if ($results) {
         foreach ($results as $result) {
             if (is_array($result) && !empty($result)) {
                 $rows = $result;
                 break;
             }
         }
     }
     // Build some basic RSS document information
     $title = Lang::txt(strtoupper($this->_option)) . ': ';
     for ($i = 0, $n = count($tags); $i < $n; $i++) {
         if ($i > 0) {
             $title .= '+ ';
         }
         $title .= $tags[$i]->get('raw_tag') . ' ';
     }
     $title = trim($title);
     $title .= ': ' . $area;
     // Set the mime encoding for the document
     Document::setType('feed');
     // Start a new feed object
     $doc = Document::instance();
     $doc->link = Route::url('index.php?option=' . $this->_option);
     $doc->title = Config::get('sitename') . ' - ' . $title;
     $doc->description = Lang::txt('COM_TAGS_RSS_DESCRIPTION', Config::get('sitename'), $title);
     $doc->copyright = Lang::txt('COM_TAGS_RSS_COPYRIGHT', gmdate("Y"), Config::get('sitename'));
     $doc->category = Lang::txt('COM_TAGS_RSS_CATEGORY');
     // Start outputing results if any found
     if (count($rows) > 0) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php';
         foreach ($rows as $row) {
             // Prepare the title
             $title = strip_tags($row->title);
             $title = html_entity_decode($title);
             // Strip html from feed item description text
             $description = html_entity_decode(String::truncate(Sanitize::stripAll(stripslashes($row->ftext)), 300));
             $author = '';
             @($date = $row->publish_up ? date('r', strtotime($row->publish_up)) : '');
             if (isset($row->data3) || isset($row->rcount)) {
                 $resourceEx = new \Components\Resources\Helpers\Helper($row->id, $this->database);
                 $resourceEx->getCitationsCount();
                 $resourceEx->getLastCitationDate();
                 $resourceEx->getContributors();
                 $author = strip_tags($resourceEx->contributors);
             }
             // Load individual item creator class
             $item = new \Hubzero\Document\Type\Feed\Item();
             $item->title = $title;
             $item->link = $row->href;
             $item->description = $description;
             $item->date = $date;
             $item->category = isset($row->data1) ? $row->data1 : '';
             $item->author = $author;
             // Loads item info into rss array
             $doc->addItem($item);
         }
     }
 }
示例#4
0
         break;
     case 4:
         $class = ' four-stars';
         break;
     case 4.5:
         $class = ' fourhalf-stars';
         break;
     case 5:
         $class = ' five-stars';
         break;
     case 0:
     default:
         $class = ' no-stars';
         break;
 }
 $helper = new \Components\Resources\Helpers\Helper($line->id, $database);
 $helper->getContributors();
 // If the user is logged in, get their rating for this resource
 if (!User::isGuest()) {
     $mr = new \Components\Resources\Tables\Review($database);
     $myrating = $mr->loadUserRating($line->id, User::get('id'));
 } else {
     $myrating = 0;
 }
 switch ($myrating) {
     case 0.5:
         $myclass = ' half-stars';
         break;
     case 1:
         $myclass = ' one-stars';
         break;
示例#5
0
 /**
  * Static method for formatting results
  *
  * @param      object $row Database row
  * @return     string HTML
  */
 public static function out($row)
 {
     $authorized = false;
     if (User::authorise('core.manage', 'com_resources')) {
         $authorized = true;
     }
     $database = App::get('db');
     // Instantiate a helper object
     $helper = new \Components\Resources\Helpers\Helper($row->id, $database);
     $helper->getContributors();
     // Get the component params and merge with resource params
     $config = Component::params('com_resources');
     $rparams = new \Hubzero\Config\Registry($row->params);
     //$params = $config;
     //$params->merge($rparams);
     // Set the display date
     switch ($rparams->get('show_date', $config->get('show_date'))) {
         case 0:
             $thedate = '';
             break;
         case 1:
             $thedate = Date::of($row->created)->toLocal('d M Y');
             break;
         case 2:
             $thedate = Date::of($row->modified)->toLocal('d M Y');
             break;
         case 3:
             $thedate = Date::of($row->publish_up)->toLocal('d M Y');
             break;
     }
     $html = "\t" . '<li class="';
     switch ($row->access) {
         case 1:
             $html .= 'registered';
             break;
         case 2:
             $html .= 'special';
             break;
         case 3:
             $html .= 'protected';
             break;
         case 4:
             $html .= 'private';
             break;
         case 0:
         default:
             $html .= 'public';
             break;
     }
     $html .= ' resource">' . "\n";
     $html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a>';
     if ($authorized || $row->created_by == User::get('id')) {
         switch ($row->state) {
             case 5:
                 $html .= ' <span class="resource-status internal">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_PENDING_INTERNAL') . '</span>';
                 break;
             case 4:
                 $html .= ' <span class="resource-status deleted">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_DELETED') . '</span>';
                 break;
             case 3:
                 $html .= ' <span class="resource-status pending">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_PENDING') . '</span>';
                 break;
             case 2:
                 $html .= ' <span class="resource-status draft">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_DRAFT') . '</span>';
                 break;
             case 1:
                 $html .= ' <span class="resource-status published">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_PUBLISHED') . '</span>';
                 break;
             case 0:
             default:
                 $html .= ' <span class="resource-status unpublished">' . Lang::txt('PLG_MEMBERS_RESOURCES_STATUS_UNPUBLISHED') . '</span>';
                 break;
         }
     }
     $html .= '</p>' . "\n";
     if ($rparams->get('show_ranking')) {
         $helper->getCitationsCount();
         $helper->getLastCitationDate();
         if ($row->category == 7) {
             $stats = new \Components\Resources\Helpers\Usage\Tools($database, $row->id, $row->category, $row->rating, $helper->citationsCount, $helper->lastCitationDate);
         } else {
             $stats = new \Components\Resources\Helpers\Usage\Andmore($database, $row->id, $row->category, $row->rating, $helper->citationsCount, $helper->lastCitationDate);
         }
         $statshtml = $stats->display();
         $row->ranking = round($row->ranking, 1);
         $html .= "\t\t" . '<div class="metadata">' . "\n";
         $r = 10 * $row->ranking;
         if (intval($r) < 10) {
             $r = '0' . $r;
         }
         $html .= "\t\t\t" . '<dl class="rankinfo">' . "\n";
         $html .= "\t\t\t\t" . '<dt class="ranking"><span class="rank-' . $r . '">' . Lang::txt('PLG_MEMBERS_RESOURCES_THIS_HAS') . '</span> ' . number_format($row->ranking, 1) . ' ' . Lang::txt('PLG_MEMBERS_RESOURCES_RANKING') . '</dt>' . "\n";
         $html .= "\t\t\t\t" . '<dd>' . "\n";
         $html .= "\t\t\t\t\t" . '<p>' . Lang::txt('PLG_MEMBERS_RESOURCES_RANKING_EXPLANATION') . '</p>' . "\n";
         $html .= "\t\t\t\t\t" . '<div>' . "\n";
         $html .= $statshtml;
         $html .= "\t\t\t\t\t" . '</div>' . "\n";
         $html .= "\t\t\t\t" . '</dd>' . "\n";
         $html .= "\t\t\t" . '</dl>' . "\n";
         $html .= "\t\t" . '</div>' . "\n";
     } elseif ($rparams->get('show_rating')) {
         switch ($row->rating) {
             case 0.5:
                 $class = ' half-stars';
                 break;
             case 1:
                 $class = ' one-stars';
                 break;
             case 1.5:
                 $class = ' onehalf-stars';
                 break;
             case 2:
                 $class = ' two-stars';
                 break;
             case 2.5:
                 $class = ' twohalf-stars';
                 break;
             case 3:
                 $class = ' three-stars';
                 break;
             case 3.5:
                 $class = ' threehalf-stars';
                 break;
             case 4:
                 $class = ' four-stars';
                 break;
             case 4.5:
                 $class = ' fourhalf-stars';
                 break;
             case 5:
                 $class = ' five-stars';
                 break;
             case 0:
             default:
                 $class = ' no-stars';
                 break;
         }
         $html .= "\t\t" . '<div class="metadata">' . "\n";
         $html .= "\t\t\t" . '<p class="rating"><span class="avgrating' . $class . '"><span>' . Lang::txt('PLG_MEMBERS_RESOURCES_OUT_OF_5_STARS', $row->rating) . '</span>&nbsp;</span></p>' . "\n";
         $html .= "\t\t" . '</div>' . "\n";
     }
     $html .= "\t\t" . '<p class="details">' . $thedate . ' <span>|</span> ' . stripslashes($row->area);
     if ($helper->contributors) {
         $html .= ' <span>|</span> ' . Lang::txt('PLG_MEMBERS_RESOURCES_CONTRIBUTORS') . ': ' . $helper->contributors;
     }
     $html .= '</p>' . "\n";
     if ($row->itext) {
         $html .= \Hubzero\Utility\String::truncate(stripslashes($row->itext), array('html' => true)) . "\n";
     } else {
         if ($row->ftext) {
             $html .= \Hubzero\Utility\String::truncate(stripslashes($row->ftext), array('html' => true)) . "\n";
         }
     }
     $html .= "\t" . '</li>' . "\n";
     return $html;
 }
示例#6
0
 /**
  * Display a list of attachments
  *
  * @param      integer $id Resource ID
  * @return     void
  */
 public function displayTask($id = null)
 {
     $this->view->setLayout('display');
     // 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'));
         return;
     }
     $this->view->id = $id;
     $this->view->allowupload = Request::getInt('allowupload', 1);
     $this->view->resource = new \Components\Resources\Tables\Resource($this->database);
     $this->view->resource->load($id);
     // Initiate a resource helper class
     $helper = new \Components\Resources\Helpers\Helper($id, $this->database);
     $helper->getChildren();
     // get config
     $this->view->cparams = Component::params('com_resources');
     $this->view->path = '';
     $this->view->children = $helper->children;
     // Set errors to view
     foreach ($this->getErrors() as $error) {
         $this->setError($error);
     }
     // Output HTML
     $this->view->display();
 }
示例#7
0
?>
<h3><?php 
echo Lang::txt('PLG_RESOURCES_RELATED_HEADER');
?>
</h3>

<?php 
if ($this->related) {
    ?>
	<table class="related-resources">
		<tbody>
		<?php 
    foreach ($this->related as $line) {
        if ($line->section != 'Topic') {
            $class = \Components\Resources\Helpers\Html::getRatingClass($line->rating);
            $resourceEx = new \Components\Resources\Helpers\Helper($line->id, $database);
            $resourceEx->getContributors();
            // If the user is logged in, get their rating for this resource
            if (!User::isGuest()) {
                $mr = new \Components\Resources\Tables\Review($database);
                $myrating = $mr->loadUserRating($line->id, User::get('id'));
            } else {
                $myrating = 0;
            }
            $myclass = \Components\Resources\Helpers\Html::getRatingClass($myrating);
            // Get the SEF for the resource
            if ($line->alias) {
                $sef = Route::url('index.php?option=' . $this->option . '&alias=' . $line->alias);
            } else {
                $sef = Route::url('index.php?option=' . $this->option . '&id=' . $line->id);
            }
示例#8
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();
 }
示例#9
0
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
$database = App::get('db');
// Instantiate a helper object
$helper = new \Components\Resources\Helpers\Helper($this->line->id, $database);
$helper->getContributors();
$helper->getContributorIDs();
/*
// Determine if they have access to edit
if (!Config::isGuest())
{
	if ((!$this->show_edit && $this->line->created_by == Config::get('id'))
	 || in_array(Config::get('id'), $helper->contributorIDs))
	{
		$this->show_edit = 2;
	}
}
*/
// Get parameters
$params = clone $this->config;
示例#10
0
$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();
        $sub_child = $rh->children;
        $hasHUBpresenter = false;
        foreach ($sub_child as $sc) {
            $rt = new \Components\Resources\Tables\Type($this->database);
            $rt->load($sc->type);
            if (strtolower($rt->type) == "hubpresenter") {
                $hasHUBpresenter = true;
            }
        }
        if (!$hasHUBpresenter) {
            unset($children[$k]);
        }
    }
} else {
示例#11
0
 /**
  * Save a review
  *
  * @return  void
  */
 public function savereview()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $data = Request::getVar('review', array(), 'post', 'none', 2);
     // Bind the form data to our object
     $row = \Components\Resources\Reviews\Models\Review::oneOrNew($data['id'])->set($data);
     // Perform some text cleaning, etc.
     if ($row->isNew()) {
         $row->set('state', \Components\Resources\Reviews\Models\Review::STATE_PUBLISHED);
     }
     $row->set('comment', \Hubzero\Utility\Sanitize::stripImages(\Hubzero\Utility\Sanitize::clean($row->get('comment'))));
     $row->set('anonymous', $row->get('anonymous') ? 1 : 0);
     // Save the data
     if (!$row->save()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent resource
     $resource =& $this->resource;
     $resource->calculateRating();
     $resource->updateRating();
     // Instantiate a helper object and get all the contributor IDs
     $database = App::get('db');
     $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::getInstance();
     $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'));
     }
 }
示例#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'));
     }
 }
示例#13
0
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'helper.php';
include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'usage.php';
$database = App::get('db');
// Instantiate a helper object
$RE = new \Components\Resources\Helpers\Helper($this->row->id, $database);
$RE->getContributors();
// Get the component params and merge with resource params
$config = Component::params('com_resources');
$rparams = new \Hubzero\Config\Registry($this->row->params);
$params = $config;
$params->merge($rparams);
// Set the display date
switch ($params->get('show_date')) {
    case 0:
        $thedate = '';
        break;
    case 1:
        $thedate = Date::of($this->row->created)->toLocal('d M Y');
        break;
    case 2: