[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Content.vote 6 * 7 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 10 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 11 */ 12 13 use Joomla\CMS\Plugin\CMSPlugin; 14 use Joomla\CMS\Plugin\PluginHelper; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('_JEXEC') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Vote plugin. 22 * 23 * @since 1.5 24 */ 25 class PlgContentVote extends CMSPlugin 26 { 27 /** 28 * @var \Joomla\CMS\Application\CMSApplication 29 * 30 * @since 3.7.0 31 */ 32 protected $app; 33 34 /** 35 * The position the voting data is displayed in relative to the article. 36 * 37 * @var string 38 * 39 * @since 3.7.0 40 */ 41 protected $votingPosition; 42 43 /** 44 * @param object &$subject The object to observe 45 * @param array $config An optional associative array of configuration settings. 46 * 47 * @since 3.7.0 48 */ 49 public function __construct(&$subject, $config) 50 { 51 parent::__construct($subject, $config); 52 53 $this->votingPosition = $this->params->get('position', 'top'); 54 } 55 56 /** 57 * Displays the voting area when viewing an article and the voting section is displayed before the article 58 * 59 * @param string $context The context of the content being passed to the plugin 60 * @param object &$row The article object 61 * @param object &$params The article params 62 * @param integer $page The 'page' number 63 * 64 * @return string|boolean HTML string containing code for the votes if in com_content else boolean false 65 * 66 * @since 1.6 67 */ 68 public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) 69 { 70 if ($this->votingPosition !== 'top') { 71 return ''; 72 } 73 74 return $this->displayVotingData($context, $row, $params, $page); 75 } 76 77 /** 78 * Displays the voting area when viewing an article and the voting section is displayed after the article 79 * 80 * @param string $context The context of the content being passed to the plugin 81 * @param object &$row The article object 82 * @param object &$params The article params 83 * @param integer $page The 'page' number 84 * 85 * @return string|boolean HTML string containing code for the votes if in com_content else boolean false 86 * 87 * @since 3.7.0 88 */ 89 public function onContentAfterDisplay($context, &$row, &$params, $page = 0) 90 { 91 if ($this->votingPosition !== 'bottom') { 92 return ''; 93 } 94 95 return $this->displayVotingData($context, $row, $params, $page); 96 } 97 98 /** 99 * Displays the voting area 100 * 101 * @param string $context The context of the content being passed to the plugin 102 * @param object &$row The article object 103 * @param object &$params The article params 104 * @param integer $page The 'page' number 105 * 106 * @return string|boolean HTML string containing code for the votes if in com_content else boolean false 107 * 108 * @since 3.7.0 109 */ 110 private function displayVotingData($context, &$row, &$params, $page) 111 { 112 $parts = explode('.', $context); 113 114 if ($parts[0] !== 'com_content') { 115 return false; 116 } 117 118 if (empty($params) || !$params->get('show_vote', null)) { 119 return ''; 120 } 121 122 // Load plugin language files only when needed (ex: they are not needed if show_vote is not active). 123 $this->loadLanguage(); 124 125 // Get the path for the rating summary layout file 126 $path = PluginHelper::getLayoutPath('content', 'vote', 'rating'); 127 128 // Render the layout 129 ob_start(); 130 include $path; 131 $html = ob_get_clean(); 132 133 if ($this->app->input->getString('view', '') === 'article' && $row->state == 1) { 134 // Get the path for the voting form layout file 135 $path = PluginHelper::getLayoutPath('content', 'vote', 'vote'); 136 137 // Render the layout 138 ob_start(); 139 include $path; 140 $html .= ob_get_clean(); 141 } 142 143 return $html; 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |