<commit_before><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.document.document');

/**
 * Class for adding stylesheets from components, modules, and plugins to the document
 *
 * @package       hubzero-cms
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright 2005-2011 Purdue University. All rights reserved.
 * @license       http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */
class Hubzero_Document
{
	/**
	 * Adds a linked stylesheet from a component to the page
	 *
	 * @param	string  $component  Component name
	 * @param	string  $stylesheet Stylesheet name (optional, uses component name if left blank)
	 * @param	string  $type       Mime encoding type
	 * @param	string  $media      Media type that this stylesheet applies to
	 * @param	string  $attribs    Attributes to add to the link
	 * @return  void
	 */
	public static function addComponentStylesheet($component, $stylesheet = '', $type = 'text/css', $media = null, $attribs = array())
	{
		$mainframe =& JFactory::getApplication();

		$jdocument = &JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		if (empty($stylesheet)) 
		{
			$stylesheet = substr($component, 4) . '.css';
		}

		$templatecss = DS . 'templates' . DS . $template . DS . 'html' . DS . $component . DS . $stylesheet;

		$assetcss = DS . 'components' . DS . $component . DS . 'assets' . DS . 'css' . DS . $stylesheet;

		$componentcss = DS . 'components' . DS . $component . DS . $stylesheet;

		if (file_exists(JPATH_SITE . $templatecss)) 
		{
			// Chech for CSS in /templates/$template/html/$component/
			$jdocument->addStyleSheet($templatecss . '?v=' . filemtime(JPATH_SITE . $templatecss), $type, $media, $attribs);
		}
		else if (file_exists(JPATH_SITE . $assetcss)) 
		{
			// Chech for CSS in /components/$component/assets/css/
			$jdocument->addStyleSheet($assetcss . '?v=' . filemtime(JPATH_SITE . $assetcss), $type, $media, $attribs);
		} 
		else if (file_exists(JPATH_SITE . $componentcss)) 
		{
			// Chech for CSS in /components/$component/
			$jdocument->addStyleSheet($componentcss . '?v=' . filemtime(JPATH_SITE . $componentcss), $type, $media, $attribs);
		}
	}

	/**
	 * Adds a linked script to the page
	 *
	 * @param   string  $component  URL to the linked script
	 * @param	string  $script     Script name (optional, uses module name if left blank)
	 * @param   string  $type       Type of script. Defaults to 'text/javascript'
	 * @param   bool    $defer      Adds the defer attribute.
	 * @param   bool    $async      Adds the async attribute.
	 * @return  void
	 */
	public static function addComponentScript($component, $script = '', $type = "text/javascript", $defer = false, $async = false)
	{
		$mainframe = JFactory::getApplication();

		$jdocument = JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		if (empty($script)) 
		{
			$script = substr($component, 4);
		}

		$base = DS . 'components' . DS . $component;

		$url = $base . DS . $script . '.js';
		$urlAlt = '';
		if (JPluginHelper::isEnabled('system', 'jquery'))
		{
			if (file_exists(JPATH_SITE . $base . DS . $script . '.jquery.js')) 
			{
				$urlAlt .= $base . DS . $script . '.jquery.js';
			}
		}

		if ($urlAlt && file_exists(JPATH_SITE . $urlAlt)) 
		{
			$jdocument->addScript($urlAlt . '?v=' . filemtime(JPATH_SITE . $urlAlt), $type, $defer, $async);
		} 
		else if (file_exists(JPATH_SITE . $url)) 
		{
			$jdocument->addScript($url . '?v=' . filemtime(JPATH_SITE . $url), $type, $defer, $async);
		}
	}

	/**
	 * Gets the path to a component image
	 * checks template overrides first, then component
	 *
	 * @param	string  $component	Component name
	 * @param	string  $image		Image to look for<commit_msg>Added methods for pushing system scripts and styles to document<commit_after><?php
/**
 * HUBzero CMS
 *
 * Copyright 2005-2011 Purdue University. All rights reserved.
 *
 * This file is part of: The HUBzero(R) Platform for Scientific Collaboration
 *
 * The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
 * software: you can redistribute it and/or modify it under the terms of
 * the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * HUBzero is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright 2005-2011 Purdue University. All rights reserved.
 * @license   http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.document.document');

/**
 * Class for adding stylesheets from components, modules, and plugins to the document
 *
 * @package       hubzero-cms
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright 2005-2011 Purdue University. All rights reserved.
 * @license       http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
 */
class Hubzero_Document
{
	/**
	 * Adds a linked stylesheet from a component to the page
	 *
	 * @param	string  $component  Component name
	 * @param	string  $stylesheet Stylesheet name (optional, uses component name if left blank)
	 * @param	string  $type       Mime encoding type
	 * @param	string  $media      Media type that this stylesheet applies to
	 * @param	string  $attribs    Attributes to add to the link
	 * @return  void
	 */
	public static function addComponentStylesheet($component, $stylesheet = '', $type = 'text/css', $media = null, $attribs = array())
	{
		$mainframe =& JFactory::getApplication();

		$jdocument = &JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		if (empty($stylesheet)) 
		{
			$stylesheet = substr($component, 4) . '.css';
		}

		$templatecss = DS . 'templates' . DS . $template . DS . 'html' . DS . $component . DS . $stylesheet;

		$assetcss = DS . 'components' . DS . $component . DS . 'assets' . DS . 'css' . DS . $stylesheet;

		$componentcss = DS . 'components' . DS . $component . DS . $stylesheet;

		if (file_exists(JPATH_SITE . $templatecss)) 
		{
			// Chech for CSS in /templates/$template/html/$component/
			$jdocument->addStyleSheet($templatecss . '?v=' . filemtime(JPATH_SITE . $templatecss), $type, $media, $attribs);
		}
		else if (file_exists(JPATH_SITE . $assetcss)) 
		{
			// Chech for CSS in /components/$component/assets/css/
			$jdocument->addStyleSheet($assetcss . '?v=' . filemtime(JPATH_SITE . $assetcss), $type, $media, $attribs);
		} 
		else if (file_exists(JPATH_SITE . $componentcss)) 
		{
			// Chech for CSS in /components/$component/
			$jdocument->addStyleSheet($componentcss . '?v=' . filemtime(JPATH_SITE . $componentcss), $type, $media, $attribs);
		}
	}

	/**
	 * Adds a linked script from a component to the page
	 *
	 * @param   string  $component  URL to the linked script
	 * @param	string  $script     Script name (optional, uses module name if left blank)
	 * @param   string  $type       Type of script. Defaults to 'text/javascript'
	 * @param   bool    $defer      Adds the defer attribute.
	 * @param   bool    $async      Adds the async attribute.
	 * @return  void
	 */
	public static function addComponentScript($component, $script = '', $type = "text/javascript", $defer = false, $async = false)
	{
		$mainframe = JFactory::getApplication();

		$jdocument = JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		if (empty($script)) 
		{
			$script = substr($component, 4);
		}

		$base = DS . 'components' . DS . $component;

		$url = $base . DS . $script . '.js';
		$urlAlt = '';
		if (JPluginHelper::isEnabled('system', 'jquery'))
		{
			if (file_exists(JPATH_SITE . $base . DS . $script . '.jquery.js')) 
			{
				$urlAlt .= $base . DS . $script . '.jquery.js';
			}
		}

		if ($urlAlt && file_exists(JPATH_SITE . $urlAlt)) 
		{
			$jdocument->addScript($urlAlt . '?v=' . filemtime(JPATH_SITE . $urlAlt), $type, $defer, $async);
		} 
		else if (file_exists(JPATH_SITE . $url)) 
		{
			$jdocument->addScript($url . '?v=' . filemtime(JPATH_SITE . $url), $type, $defer, $async);
		}
	}

	/**
	 * Adds a linked stylesheet from the system to the page
	 *
	 * @param	string  $stylesheet Stylesheet name
	 * @param	string  $type       Mime encoding type
	 * @param	string  $media      Media type that this stylesheet applies to
	 * @param	string  $attribs    Attributes to add to the link
	 * @return  void
	 */
	public static function addSystemStylesheet($stylesheet, $type = 'text/css', $media = null, $attribs = array())
	{
		if (!$stylesheet)
		{
			return;
		}

		$mainframe =& JFactory::getApplication();

		$jdocument = &JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		$templatecss = DS . 'templates' . DS . $template . DS . 'html' . DS . 'system' . DS . 'css' . DS . $stylesheet;

		$systemcss = DS . 'media' . DS . 'system' . DS . 'css' . DS . $stylesheet;

		if (file_exists(JPATH_SITE . $templatecss)) 
		{
			$jdocument->addStyleSheet($templatecss . '?v=' . filemtime(JPATH_SITE . $templatecss), $type, $media, $attribs);
		} 
		else 
		{
			$jdocument->addStyleSheet($systemcss . '?v=' . filemtime(JPATH_SITE . $systemcss), $type, $media, $attribs);
		}
	}

	/**
	 * Adds a linked script from the system to the page
	 *
	 * @param	string  $script     Script name (optional, uses module name if left blank)
	 * @param   string  $type       Type of script. Defaults to 'text/javascript'
	 * @param   bool    $defer      Adds the defer attribute.
	 * @param   bool    $async      Adds the async attribute.
	 * @return  void
	 */
	public static function addSystemScript($script, $type = 'text/javascript', $defer = false, $async = false)
	{
		if (!$script)
		{
			return;
		}

		$mainframe = JFactory::getApplication();

		$jdocument = JFactory::getDocument();

		$template  = $mainframe->getTemplate();

		$base = DS . 'media' . DS . 'system' . DS . 'js';

		$url = $base . DS . $script . '.js';
		$urlAlt = '';
		if (JPluginHelper::isEnabled('system', 'jquery'))
		{
			if (file_exists(JPATH_SITE . $base . DS . $script . '.jquery.js')) 
			{
				$urlAlt .= $base . DS . $script . '.jquery.js';
			}
		}

		if ($urlAlt && file_exists(JPATH_SITE . $urlAlt)) 
		{
			$jdocument->addScript($urlAlt . '?v=' . filemtime(JPATH_SITE . $urlAlt), $type, $defer, $async);
		} 
		else if (file_exists(JPATH_SITE . $url)) 
		{
			$jdocument->addScript($url . '?v=' . filemtime(JPATH_SITE . $url), $type, $defer, $async);
		}
	}

	/**
	 * Gets the path to a component image
	 * checks template overrides first, then component
	 *
	 * @param	string  $component	Component name
	 * @param	string  $image		Image to look for
{'fraction_non_alphanumeric': 0.1366120218579235, 'fraction_numerical': 0.005382921458282359, 'mean_word_length': 3.2151942248195255, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3492631', 'n_tokens_mistral': 4260, 'n_tokens_neox': 3870, 'n_words': 1215}