<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.plugin.plugin' );
ximport('Hubzero_Plugin');

/**
 * Display sponsors on a resource page
 */
class plgResourcesSponsors extends Hubzero_Plugin
{

	/**
	 * Short description for 'plgResourcesRecommendations'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      unknown &$subject Parameter description (if any) ...
	 * @param      unknown $config Parameter description (if any) ...
	 * @return     void
	 */
	public function plgResourcesSponsors(&$subject, $config)
	{
		parent::__construct($subject, $config);

		// Load plugin parameters
		$this->_plugin = JPluginHelper::getPlugin( 'resources', 'sponsors' );
		$this->loadLanguage();
		if (version_compare(JVERSION, '1.6', 'lt'))
		{
			$this->params = new JParameter($this->_plugin->params);
		}
	}

	/**
	 * Short description for 'onResourcesSubAreas'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      unknown $resource Parameter description (if any) ...
	 * @return     array Return description (if any) ...
	 */
	public function &onResourcesSubAreas( $resource )
	{
		$areas = array(
			'sponsors' => JText::_('PLG_RESOURCES_SPONSORS')
		);
		return $areas;
	}

	/**
	 * Short description for 'onResourcesSub'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      object $resource Parameter description (if any) ...
	 * @param      unknown $option Parameter description (if any) ...
	 * @param      integer $miniview Parameter description (if any) ...
	 * @return     array Return description (if any) ...
	 */
	public function onResourcesSub($resource, $option, $miniview=0)
	{
		$arr = array(
			'html'=>'',
			'metadata'=>''
		);

		// Get recommendations
		$this->database = JFactory::getDBO();

		// Instantiate a view
		ximport('Hubzero_Plugin_View');
		$this->view = new Hubzero_Plugin_View(
			array(
				'folder'  => 'resources',
				'element' => 'sponsors',
				'name'    => 'display',
				'layout'  => 'mini'
			)
		);
		
		if ($miniview) 
		{
			$this->view->setLayout('mini');
		}

		// Pass the view some info
		$this->view->option   = $option;
		$this->view->resource = $resource;
		$this->view->params   = $this->params;
		$this->view->data     = '';
		
		/*require_once(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . $option . DS . 'tables' . DS . 'type.php');
		require_once(JPATH_ROOT . DS . 'components' . DS . $option . DS . 'helpers' . DS . 'html.php');
		
		// Parse for <nb: > tags
		$type = new ResourcesType($this->database);
		$type->load($resource->type);

		$fields = array();
		if (trim($type->customFields) != '') 
		{
			$fs = explode("\n", trim($type->customFields));
			foreach ($fs as $f)
			{
				$fields[] = explode('=', $f);
			}
		}
		
		$names = array('sponsor', 'sponsors', 'sponsordata', 'sponsorsdata', 'sponsoredby');

		$maintext  = ($resource->fulltext)
				   ? stripslashes($resource->fulltext)
				   : stripslashes($resource->introtext);

		if (!empty($fields)) 
		{
			for ($i=0, $n=count($fields); $i < $n; $i++)
			{
				// Clean the original text of any matches
				if (in_array($fields[$i][0], $names))
				{
					$this->view->data = ResourcesHtml::parseTag($maintext, $fields[$i][0]);
					$maintext = str_replace('<nb:' . $fields[$i][0] . '>' . end($fields[$i]) . '</nb:' . $fields[$i][0] . '>', '', $maintext);
				}
			}
			$resource->fulltext = trim($maintext);
		}*/
		require_once(JPATH_ROOT . DS . 'plugins' . DS . 'resources' . DS . 'sponsors' . DS . 'tables' . DS . 'sponsor.php');
		//$format = $this->params->get('format', '{journal}@{sponsor}');
		
		$this->sponsors = array();
		
		$model = new ResourcesSponsor($this->database);
		$records = $model->getRecords(array('state' => 1));
		if (!$records)
		{
			return $arr;
		}
		
		foreach ($records As $record)
		{
			$this->sponsors[$record->alias] = $record;
		}
		
		//$helper = new ResourcesHelper($resource->id, $this->database);
		//$tags = $helper->getTags();
		include_once(JPATH_ROOT . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'tags.php');
		$rt = new ResourcesTags($this->database);
		$tags = $rt->getTags($resource->id);
		
		if ($tags)
		{
			foreach ($tags as $tag)
			{
				if (isset($this->sponsors[$tag->tag]))
				{
					$this->view->data = $this->sponsors[$tag->tag]->description;
					break;
				}
			}
		}
		
		if ($this->getError()) 
		{
			$this->view->setError( $this->getError() );
		}

		// Return the output
		$arr['html'] = $this->view->loadTemplate();

		return $arr;
	}
	
	public function onManage($option, $controller='plugins', $task='default')
	{<commit_msg>add onCanManage() method to sponsors plugin<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.plugin.plugin' );
ximport('Hubzero_Plugin');

/**
 * Display sponsors on a resource page
 */
class plgResourcesSponsors extends Hubzero_Plugin
{

	/**
	 * Short description for 'plgResourcesRecommendations'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      unknown &$subject Parameter description (if any) ...
	 * @param      unknown $config Parameter description (if any) ...
	 * @return     void
	 */
	public function plgResourcesSponsors(&$subject, $config)
	{
		parent::__construct($subject, $config);

		// Load plugin parameters
		$this->_plugin = JPluginHelper::getPlugin( 'resources', 'sponsors' );
		$this->loadLanguage();
		if (version_compare(JVERSION, '1.6', 'lt'))
		{
			$this->params = new JParameter($this->_plugin->params);
		}
	}

	/**
	 * Short description for 'onResourcesSubAreas'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      unknown $resource Parameter description (if any) ...
	 * @return     array Return description (if any) ...
	 */
	public function &onResourcesSubAreas( $resource )
	{
		$areas = array(
			'sponsors' => JText::_('PLG_RESOURCES_SPONSORS')
		);
		return $areas;
	}

	/**
	 * Short description for 'onResourcesSub'
	 * 
	 * Long description (if any) ...
	 * 
	 * @param      object $resource Parameter description (if any) ...
	 * @param      unknown $option Parameter description (if any) ...
	 * @param      integer $miniview Parameter description (if any) ...
	 * @return     array Return description (if any) ...
	 */
	public function onResourcesSub($resource, $option, $miniview=0)
	{
		$arr = array(
			'html'=>'',
			'metadata'=>''
		);

		// Get recommendations
		$this->database = JFactory::getDBO();

		// Instantiate a view
		ximport('Hubzero_Plugin_View');
		$this->view = new Hubzero_Plugin_View(
			array(
				'folder'  => 'resources',
				'element' => 'sponsors',
				'name'    => 'display',
				'layout'  => 'mini'
			)
		);
		
		if ($miniview) 
		{
			$this->view->setLayout('mini');
		}

		// Pass the view some info
		$this->view->option   = $option;
		$this->view->resource = $resource;
		$this->view->params   = $this->params;
		$this->view->data     = '';
		
		/*require_once(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . $option . DS . 'tables' . DS . 'type.php');
		require_once(JPATH_ROOT . DS . 'components' . DS . $option . DS . 'helpers' . DS . 'html.php');
		
		// Parse for <nb: > tags
		$type = new ResourcesType($this->database);
		$type->load($resource->type);

		$fields = array();
		if (trim($type->customFields) != '') 
		{
			$fs = explode("\n", trim($type->customFields));
			foreach ($fs as $f)
			{
				$fields[] = explode('=', $f);
			}
		}
		
		$names = array('sponsor', 'sponsors', 'sponsordata', 'sponsorsdata', 'sponsoredby');

		$maintext  = ($resource->fulltext)
				   ? stripslashes($resource->fulltext)
				   : stripslashes($resource->introtext);

		if (!empty($fields)) 
		{
			for ($i=0, $n=count($fields); $i < $n; $i++)
			{
				// Clean the original text of any matches
				if (in_array($fields[$i][0], $names))
				{
					$this->view->data = ResourcesHtml::parseTag($maintext, $fields[$i][0]);
					$maintext = str_replace('<nb:' . $fields[$i][0] . '>' . end($fields[$i]) . '</nb:' . $fields[$i][0] . '>', '', $maintext);
				}
			}
			$resource->fulltext = trim($maintext);
		}*/
		require_once(JPATH_ROOT . DS . 'plugins' . DS . 'resources' . DS . 'sponsors' . DS . 'tables' . DS . 'sponsor.php');
		//$format = $this->params->get('format', '{journal}@{sponsor}');
		
		$this->sponsors = array();
		
		$model = new ResourcesSponsor($this->database);
		$records = $model->getRecords(array('state' => 1));
		if (!$records)
		{
			return $arr;
		}
		
		foreach ($records As $record)
		{
			$this->sponsors[$record->alias] = $record;
		}
		
		//$helper = new ResourcesHelper($resource->id, $this->database);
		//$tags = $helper->getTags();
		include_once(JPATH_ROOT . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'tags.php');
		$rt = new ResourcesTags($this->database);
		$tags = $rt->getTags($resource->id);
		
		if ($tags)
		{
			foreach ($tags as $tag)
			{
				if (isset($this->sponsors[$tag->tag]))
				{
					$this->view->data = $this->sponsors[$tag->tag]->description;
					break;
				}
			}
		}
		
		if ($this->getError()) 
		{
			$this->view->setError( $this->getError() );
		}

		// Return the output
		$arr['html'] = $this->view->loadTemplate();

		return $arr;
	}
	
	public function onCanManage()
	{
		return $this->_plugin->name;
	}
	
	public function onManage($option, $controller='plugins', $task='default')
	{
{'fraction_non_alphanumeric': 0.17076083248038212, 'fraction_numerical': 0.004947117024906175, 'mean_word_length': 3.1815263908701854, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1185082', 'n_tokens_mistral': 4323, 'n_tokens_neox': 3734, 'n_words': 998}