Ejemplo n.º 1
0
 /**
  * Get a link
  *
  * @param   object  $params  Registry
  * @return  string
  */
 static function getLink(&$params)
 {
     $data = Document::getHeadData();
     foreach ($data['links'] as $link => $value) {
         $value = Arr::toString($value);
         if (strpos($value, 'application/' . $params->get('format') . '+xml')) {
             return $link;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Generates the head HTML and return the results as a string
  *
  * @param   object  &$document  The document for which the head will be created
  * @return  string  The head hTML
  */
 public function fetchHead(&$document)
 {
     // Trigger the onBeforeCompileHead event (skip for installation, since it causes an error)
     \Event::trigger('onBeforeCompileHead');
     // Get line endings
     $lnEnd = $document->_getLineEnd();
     $tab = $document->_getTab();
     $tagEnd = ' />';
     $buffer = array();
     // Generate base tag (need to happen first)
     $base = $document->getBase();
     if (!empty($base)) {
         $buffer[] = $tab . '<base href="' . $document->getBase() . '" />';
     }
     // Generate META tags (needs to happen as early as possible in the head)
     foreach ($document->_metaTags as $type => $tag) {
         foreach ($tag as $name => $content) {
             if ($type == 'http-equiv') {
                 $content .= '; charset=' . $document->getCharset();
                 $buffer[] = $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />';
             } elseif ($type == 'standard' && !empty($content) && isset($content['content'])) {
                 $buffer[] = $tab . '<meta name="' . $content['name'] . '" content="' . htmlspecialchars($content['content']) . '" />';
             }
         }
     }
     // Don't add empty descriptions
     if ($description = $document->getDescription()) {
         $buffer[] = $tab . '<meta name="description" content="' . htmlspecialchars($description) . '" />';
     }
     // Don't add empty generators
     if ($generator = $document->getGenerator()) {
         $buffer[] = $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />';
     }
     $buffer[] = $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>';
     // Generate link declarations
     foreach ($document->_links as $link => $linkAtrr) {
         $line = $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"';
         if ($temp = Arr::toString($linkAtrr['attribs'])) {
             $line .= ' ' . $temp;
         }
         $line .= ' />';
         $buffer[] = $line;
     }
     // Generate stylesheet links
     foreach ($document->_styleSheets as $strSrc => $strAttr) {
         $line = $tab . '<link rel="stylesheet" href="' . $strSrc . '" type="' . $strAttr['mime'] . '"';
         if (!is_null($strAttr['media'])) {
             $line .= ' media="' . $strAttr['media'] . '" ';
         }
         if ($temp = Arr::toString($strAttr['attribs'])) {
             $line .= ' ' . $temp;
         }
         $buffer[] = $line . $tagEnd;
     }
     // Generate stylesheet declarations
     foreach ($document->_style as $type => $content) {
         $buffer[] = $tab . '<style type="' . $type . '">';
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer[] = $tab . $tab . '<![CDATA[';
         }
         $buffer[] = $content;
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer[] = $tab . $tab . ']]>';
         }
         $buffer[] = $tab . '</style>';
     }
     // Generate script file links
     foreach ($document->_scripts as $strSrc => $strAttr) {
         $line = $tab . '<script src="' . $strSrc . '"';
         if (!is_null($strAttr['mime'])) {
             $line .= ' type="' . $strAttr['mime'] . '"';
         }
         if ($strAttr['defer']) {
             $line .= ' defer="defer"';
         }
         if ($strAttr['async']) {
             $line .= ' async="async"';
         }
         $line .= '></script>';
         $buffer[] = $line;
     }
     // Generate script declarations
     foreach ($document->_script as $type => $content) {
         $buffer[] = $tab . '<script type="' . $type . '">';
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer[] = $tab . $tab . '<![CDATA[';
         }
         if (is_array($content)) {
             foreach ($content as $c) {
                 $buffer[] = $c;
             }
         } else {
             $buffer[] = $content;
         }
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer[] = $tab . $tab . ']]>';
         }
         $buffer[] = $tab . '</script>';
     }
     // Generate script language declarations.
     if (count(\JText::script())) {
         $buffer[] = $tab . '<script type="text/javascript">';
         $buffer[] = $tab . $tab . '(function() {';
         $buffer[] = $tab . $tab . $tab . 'var strings = ' . json_encode(\JText::script()) . ';';
         $buffer[] = $tab . $tab . $tab . 'if (typeof Joomla == \'undefined\') {';
         $buffer[] = $tab . $tab . $tab . $tab . 'Joomla = {};';
         $buffer[] = $tab . $tab . $tab . $tab . 'Joomla.JText = strings;';
         $buffer[] = $tab . $tab . $tab . '} else {';
         $buffer[] = $tab . $tab . $tab . $tab . 'Joomla.JText.load(strings);';
         $buffer[] = $tab . $tab . $tab . '}';
         $buffer[] = $tab . $tab . '})();';
         $buffer[] = $tab . '</script>';
     }
     foreach ($document->_custom as $custom) {
         $buffer[] = $tab . $custom;
     }
     return implode($lnEnd, $buffer);
 }
Ejemplo n.º 3
0
 /**
  * Get the master query for retrieving a list of articles subject to the model state.
  *
  * @return	JDatabaseQuery
  * @since	1.6
  */
 function getListQuery()
 {
     // Create a new query object.
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     // Select the required fields from the table.
     $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.language, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, uam.name as modified_by_name,' . 'CASE WHEN a.publish_up = 0 THEN a.created ELSE a.publish_up END as publish_up,' . 'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' . 'a.hits, a.xreference, a.featured,' . ' ' . $query->length('a.fulltext') . ' AS readmore'));
     // Process an Archived Article layout
     if ($this->getState('filter.published') == 2) {
         // If badcats is not null, this means that the article is inside an archived category
         // In this case, the state is set to 2 to indicate Archived (even if the article state is Published)
         $query->select($this->getState('list.select', 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END AS state'));
     } else {
         // Process non-archived layout
         // If badcats is not null, this means that the article is inside an unpublished category
         // In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published)
         $query->select($this->getState('list.select', 'CASE WHEN badcats.id is not null THEN 0 ELSE a.state END AS state'));
     }
     $query->from('#__content AS a');
     // Join over the frontpage articles.
     if ($this->context != 'com_content.featured') {
         $query->join('LEFT', '#__content_frontpage AS fp ON fp.content_id = a.id');
     }
     // Join over the categories.
     $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias');
     $query->join('LEFT', '#__categories AS c ON c.id = a.catid');
     // Join over the users for the author and modified_by names.
     $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author");
     $query->select("ua.email AS author_email");
     $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
     $query->join('LEFT', '#__users AS uam ON uam.id = a.modified_by');
     // Get contact id
     $subQuery = $db->getQuery(true);
     $subQuery->select('MAX(contact.id) AS id');
     $subQuery->from('#__contact_details AS contact');
     $subQuery->where('contact.published = 1');
     $subQuery->where('contact.user_id = a.created_by');
     // Filter by language
     if ($this->getState('filter.language')) {
         $subQuery->where('(contact.language in (' . $db->quote(Lang::getTag()) . ',' . $db->quote('*') . ') OR contact.language IS NULL)');
     }
     // [!] Hubzero - Removed contact_details table
     //$query->select('(' . $subQuery . ') as contactid');
     $query->select('(0) as contactid');
     // Join over the categories to get parent category titles
     $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias');
     $query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');
     // Join on voting table
     $query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count');
     $query->join('LEFT', '#__content_rating AS v ON a.id = v.content_id');
     // Join to check for category published state in parent categories up the tree
     $query->select('c.published, CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published');
     $subquery = 'SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ';
     $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt ';
     $subquery .= 'WHERE parent.extension = ' . $db->quote('com_content');
     if ($this->getState('filter.published') == 2) {
         // Find any up-path categories that are archived
         // If any up-path categories are archived, include all children in archived layout
         $subquery .= ' AND parent.published = 2 GROUP BY cat.id ';
         // Set effective state to archived if up-path category is archived
         $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END';
     } else {
         // Find any up-path categories that are not published
         // If all categories are published, badcats.id will be null, and we just use the article state
         $subquery .= ' AND parent.published != 1 GROUP BY cat.id ';
         // Select state to unpublished if up-path category is unpublished
         $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 0 END';
     }
     $query->join('LEFT OUTER', '(' . $subquery . ') AS badcats ON badcats.id = c.id');
     // Filter by access level.
     if ($access = $this->getState('filter.access')) {
         $groups = implode(',', User::getAuthorisedViewLevels());
         $query->where('a.access IN (' . $groups . ')');
         $query->where('c.access IN (' . $groups . ')');
     }
     // Filter by published state
     $published = $this->getState('filter.published');
     if (is_numeric($published)) {
         // Use article state if badcats.id is null, otherwise, force 0 for unpublished
         $query->where($publishedWhere . ' = ' . (int) $published);
     } elseif (is_array($published)) {
         \Hubzero\Utility\Arr::toInteger($published);
         $published = implode(',', $published);
         // Use article state if badcats.id is null, otherwise, force 0 for unpublished
         $query->where($publishedWhere . ' IN (' . $published . ')');
     }
     // Filter by featured state
     $featured = $this->getState('filter.featured');
     switch ($featured) {
         case 'hide':
             $query->where('a.featured = 0');
             break;
         case 'only':
             $query->where('a.featured = 1');
             break;
         case 'show':
         default:
             // Normally we do not discriminate
             // between featured/unfeatured items.
             break;
     }
     // Filter by a single or group of articles.
     $articleId = $this->getState('filter.article_id');
     if (is_numeric($articleId)) {
         $type = $this->getState('filter.article_id.include', true) ? '= ' : '<> ';
         $query->where('a.id ' . $type . (int) $articleId);
     } elseif (is_array($articleId)) {
         \Hubzero\Utility\Arr::toInteger($articleId);
         $articleId = implode(',', $articleId);
         $type = $this->getState('filter.article_id.include', true) ? 'IN' : 'NOT IN';
         $query->where('a.id ' . $type . ' (' . $articleId . ')');
     }
     // Filter by a single or group of categories
     $categoryId = $this->getState('filter.category_id');
     if (is_numeric($categoryId)) {
         $type = $this->getState('filter.category_id.include', true) ? '= ' : '<> ';
         // Add subcategory check
         $includeSubcategories = $this->getState('filter.subcategories', false);
         $categoryEquals = 'a.catid ' . $type . (int) $categoryId;
         if ($includeSubcategories) {
             $levels = (int) $this->getState('filter.max_category_levels', '1');
             // Create a subquery for the subcategory list
             $subQuery = $db->getQuery(true);
             $subQuery->select('sub.id');
             $subQuery->from('#__categories as sub');
             $subQuery->join('INNER', '#__categories as this ON sub.lft > this.lft AND sub.rgt < this.rgt');
             $subQuery->where('this.id = ' . (int) $categoryId);
             if ($levels >= 0) {
                 $subQuery->where('sub.level <= this.level + ' . $levels);
             }
             // Add the subquery to the main query
             $query->where('(' . $categoryEquals . ' OR a.catid IN (' . $subQuery->__toString() . '))');
         } else {
             $query->where($categoryEquals);
         }
     } elseif (is_array($categoryId) && count($categoryId) > 0) {
         \Hubzero\Utility\Arr::toInteger($categoryId);
         $categoryId = implode(',', $categoryId);
         if (!empty($categoryId)) {
             $type = $this->getState('filter.category_id.include', true) ? 'IN' : 'NOT IN';
             $query->where('a.catid ' . $type . ' (' . $categoryId . ')');
         }
     }
     // Filter by author
     $authorId = $this->getState('filter.author_id');
     $authorWhere = '';
     if (is_numeric($authorId)) {
         $type = $this->getState('filter.author_id.include', true) ? '= ' : '<> ';
         $authorWhere = 'a.created_by ' . $type . (int) $authorId;
     } elseif (is_array($authorId)) {
         \Hubzero\Utility\Arr::toInteger($authorId);
         $authorId = implode(',', $authorId);
         if ($authorId) {
             $type = $this->getState('filter.author_id.include', true) ? 'IN' : 'NOT IN';
             $authorWhere = 'a.created_by ' . $type . ' (' . $authorId . ')';
         }
     }
     // Filter by author alias
     $authorAlias = $this->getState('filter.author_alias');
     $authorAliasWhere = '';
     if (is_string($authorAlias)) {
         $type = $this->getState('filter.author_alias.include', true) ? '= ' : '<> ';
         $authorAliasWhere = 'a.created_by_alias ' . $type . $db->Quote($authorAlias);
     } elseif (is_array($authorAlias)) {
         $first = current($authorAlias);
         if (!empty($first)) {
             \Hubzero\Utility\Arr::toString($authorAlias);
             foreach ($authorAlias as $key => $alias) {
                 $authorAlias[$key] = $db->Quote($alias);
             }
             $authorAlias = implode(',', $authorAlias);
             if ($authorAlias) {
                 $type = $this->getState('filter.author_alias.include', true) ? 'IN' : 'NOT IN';
                 $authorAliasWhere = 'a.created_by_alias ' . $type . ' (' . $authorAlias . ')';
             }
         }
     }
     if (!empty($authorWhere) && !empty($authorAliasWhere)) {
         $query->where('(' . $authorWhere . ' OR ' . $authorAliasWhere . ')');
     } elseif (empty($authorWhere) && empty($authorAliasWhere)) {
         // If both are empty we don't want to add to the query
     } else {
         // One of these is empty, the other is not so we just add both
         $query->where($authorWhere . $authorAliasWhere);
     }
     // Define null and now dates
     $nullDate = $db->Quote($db->getNullDate());
     $nowDate = $db->Quote(Date::toSql());
     if (!User::authorise('core.edit.state', 'com_content') && !User::authorise('core.edit', 'com_content')) {
         // Filter by start and end dates.
         $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')');
         $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')');
     }
     // Filter by Date Range or Relative Date
     $dateFiltering = $this->getState('filter.date_filtering', 'off');
     $dateField = $this->getState('filter.date_field', 'a.created');
     switch ($dateFiltering) {
         case 'range':
             $startDateRange = $db->Quote($this->getState('filter.start_date_range', $nullDate));
             $endDateRange = $db->Quote($this->getState('filter.end_date_range', $nullDate));
             $query->where('(' . $dateField . ' >= ' . $startDateRange . ' AND ' . $dateField . ' <= ' . $endDateRange . ')');
             break;
         case 'relative':
             $relativeDate = (int) $this->getState('filter.relative_date', 0);
             $query->where($dateField . ' >= DATE_SUB(' . $nowDate . ', INTERVAL ' . $relativeDate . ' DAY)');
             break;
         case 'off':
         default:
             break;
     }
     // process the filter for list views with user-entered filters
     $params = $this->getState('params');
     if (is_object($params) && $params->get('filter_field') != 'hide' && ($filter = $this->getState('list.filter'))) {
         // clean filter variable
         $filter = JString::strtolower($filter);
         $hitsFilter = intval($filter);
         $filter = $db->Quote('%' . $db->escape($filter, true) . '%', false);
         switch ($params->get('filter_field')) {
             case 'author':
                 $query->where('LOWER( CASE WHEN a.created_by_alias > ' . $db->quote(' ') . ' THEN a.created_by_alias ELSE ua.name END ) LIKE ' . $filter . ' ');
                 break;
             case 'hits':
                 $query->where('a.hits >= ' . $hitsFilter . ' ');
                 break;
             case 'title':
             default:
                 // default to 'title' if parameter is not valid
                 $query->where('LOWER( a.title ) LIKE ' . $filter);
                 break;
         }
     }
     // Filter by language
     if ($this->getState('filter.language')) {
         $query->where('a.language in (' . $db->quote(Lang::getTag()) . ',' . $db->quote('*') . ')');
     }
     // Add the list ordering clause.
     $query->order($this->getState('list.ordering', 'a.ordering') . ' ' . $this->getState('list.direction', 'ASC'));
     return $query;
 }
Ejemplo n.º 4
0
 /**
  * Generates an HTML radio list.
  *
  * @param   array    $data       An array of objects
  * @param   string   $name       The value of the HTML name attribute
  * @param   string   $attribs    Additional HTML attributes for the <select> tag
  * @param   mixed    $optKey     The key that is selected
  * @param   string   $optText    The name of the object variable for the option value
  * @param   string   $selected   The name of the object variable for the option text
  * @param   boolean  $idtag      Value of the field id or null by default
  * @param   boolean  $translate  True if options will be translated
  * @return  string HTML for the select list
  */
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = Arr::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? Lang::txt($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= '<label for="' . $id_text . $k . '"' . ' id="' . $id_text . $k . '-lbl" class="radiobtn option">' . "\n";
         $html .= '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . $t . "\n";
         $html .= '</label>' . "\n";
     }
     $html .= "\n";
     return $html;
 }
Ejemplo n.º 5
0
 /**
  * Write a <img /> element
  *
  * @param   string   $file       The relative or absolute URL to use for the src attribute
  * @param   string   $alt        The alt text.
  * @param   string   $attribs    The target attribute to use
  * @param   array    $relative   An associative array of attributes to add
  * @param   boolean  $path_only  If set to true, it tries to find an override for the file in the template
  * @return  string
  */
 public static function image($file, $alt, $attribs = null, $relative = false, $path_only = false)
 {
     if (is_array($attribs)) {
         $attribs = Arr::toString($attribs);
     }
     $includes = self::includeRelativeFiles('images', $file, $relative, false, false);
     // If only path is required
     if ($path_only) {
         if (count($includes)) {
             return $includes[0];
         } else {
             return null;
         }
     } else {
         return '<img src="' . (count($includes) ? $includes[0] : '') . '" alt="' . $alt . '" ' . $attribs . ' />';
     }
 }
Ejemplo n.º 6
0
 static function print_popup($article, $params, $attribs = array())
 {
     $url = ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language);
     $url .= '&tmpl=component&print=1&layout=default&page=' . @$request->limitstart;
     $status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
     // checks template image directory for image, if non found default are loaded
     /*if ($params->get('show_icons'))
     		{
     			$text = Html::asset('image', 'printButton.png', Lang::txt('JGLOBAL_PRINT'), NULL, true);
     		}
     		else
     		{*/
     $text = Lang::txt('JGLOBAL_ICON_SEP') . '&#160;' . Lang::txt('JGLOBAL_PRINT') . '&#160;' . Lang::txt('JGLOBAL_ICON_SEP');
     //}
     $attribs['title'] = Lang::txt('JGLOBAL_PRINT');
     $attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
     $attribs['rel'] = 'nofollow';
     return '<a href="' . Route::url($url) . '" ' . \Hubzero\Utility\Arr::toString($attribs) . '>' . $text . '</a>';
 }