[go: up one dir, main page]

Menu

[r15]: / trunk / voteext.php  Maximize  Restore  History

Download this file

186 lines (167 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* @version $Revision$
* @package Joomla
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
jimport('joomla.version');
if (!defined('PLGX_POS_BEFORECONTENT')) {
define('PLGX_POS_BEFORECONTENT', 1);
define('PLGX_POS_AFTERCONTENT', 2);
define('PLGX_POS_AFTERTITLE', 3);
define('PLGX_POS_BEFOREARTICLE', 4);
define('PLGX_POS_AFTERHEAD', 5);
}
if (!defined('JPATH_THEMES')) define('JPATH_THEMES', JPATH_SITE.DS.'templates');
class plgContentVoteExt extends JPlugin
{
var $pluginPath;
var $is15;
var $is2;
var $resourceURI;
var $encoding;
var $task;
var $xsclass;
function plgContentVoteExt(&$subject, $params)
{
parent::__construct($subject, $params);
$this->encoding = 'UTF-8';
$this->pluginPath = dirname(__FILE__).DS.$this->_name;
$this->loadLanguage();
$version = new JVersion();
$this->is15 = version_compare($version->RELEASE, "1.5");
$this->is2 = version_compare($version->RELEASE, "2.0");
$this->resourceURI = '/plugins/'.$this->_type.'/'.$this->_name.'/';
if ($this->is2) {
$this->resourceURI .= $this->_name.'/';
}
$this->task = 'vote';
if ($this->is2) {
$this->task = 'article.vote';
}
$this->xsclass = 'accessibility';
if ($this->is2) {
$this->xsclass = 'unseen';
}
}
// ------------ 2.5 API ------------
function onContentPrepare($context, &$row, &$params, $page=0)
{
}
function onContentAfterTitle($context, &$row, &$params, $page=0)
{
return $this->onAfterDisplayTitle($row, $params, $page);
}
function onContentBeforeDisplay($context, &$row, &$params, $page=0)
{
return $this->onBeforeDisplayContent($row, $params, $page);
}
function onContentAfterDisplay($context, &$row, &$params, $page=0)
{
return $this->onAfterDisplayContent($row, $params, $page);
}
// ------------ 1.5 API ------------
function onAfterDisplayTitle(&$article, &$params, $limitstart)
{
if (PLGX_POS_AFTERTITLE == $this->params->get('display_at', PLGX_POS_BEFORECONTENT)) {
return $this->render($article, $params, $limitstart);
}
return '';
}
function onBeforeDisplayContent(&$article, &$params, $limitstart)
{
if (PLGX_POS_BEFORECONTENT == $this->params->get('display_at', PLGX_POS_BEFORECONTENT)) {
return $this->render($article, $params, $limitstart);
}
return '';
}
function onAfterDisplayContent(&$article, &$params, $limitstart)
{
if (PLGX_POS_AFTERCONTENT == $this->params->get('display_at', PLGX_POS_BEFORECONTENT)) {
return $this->render($article, $params, $limitstart);
}
return '';
}
/**
* $html = current($mainframe->triggerEvent('onContentVote', array(&$this->article, &$this->params, 1)));
* echo $html;
*/
function onContentVote(&$article, &$params, $limitstart)
{
return $this->render($article, $params, $limitstart);
}
function render(&$row, &$params, $page=0)
{
$html = '';
if ($params->get('show_vote') && !$params->get('popup')) {
if ($this->is2 && ('article' != JRequest::getString('view', '') || $row->state != 1)) {
$params->set('intro_only', 1);
}
$this->uri = JFactory::getURI();
$this->assignRef('article', $row);
$html = $this->loadTemplate($params);
}
return $html;
}
function getImage($file, &$imgAttrs, $alt, $asTag = true, $useSystem = false)
{
if ($this->is2) {
$attrs = '';
if ($asTag && is_array($imgAttrs)) {
foreach ($imgAttrs as $key => $value) {
if (0 < strlen($attrs)) $attrs .= ' ';
$attrs .= $key.'="'.htmlspecialchars($value, ENT_COMPAT, $this->encoding, false).'"';
}
}
//image($file, $alt, $attribs = null, $relative = false, $path_only = false);
return JHtml::_('image', ($useSystem ? 'system/' : $this->resourceURI) . $file, $alt, $attrs, $useSystem, !$asTag);
}
else if ($this->is15) {
return JHtml::_('image.site', $file, $useSystem ? '/images/M_images/' : $this->resourceURI, NULL, '', $alt, $imgAttrs, $asTag);
}
return '';
}
function assignRef($key, &$val)
{
if (is_string($key) && substr($key, 0, 1) != '_')
{
unset($this->$key);
$this->$key =& $val;
return true;
}
return false;
}
function loadTemplate(&$params, $name = 'default')
{
global $mainframe;
if (!isset($mainframe)) {
$mainframe = JFactory::getApplication();
}
$override = JPATH_THEMES.DS.$mainframe->getTemplate().DS.'html'.DS
.'plg_'.$this->_type.'_'.$this->_name.DS.$name.'.php';
ob_start();
if (is_readable($override)) {
include($override);
}
else {
$override = $this->pluginPath.DS.'tmpl'.DS.$name.'.php';
if (is_readable($override)) {
include($override);
}
else {
ob_end_clean();
JError::raiseError(500, '['.$this->_name.'] '.JText::_('Failed to load template').' '.$name.'.php');
return '';
}
}
return ob_get_clean();
}
}