| Current Path : /home/g/i/t/giteleslfp/www/plugins/system/tooltipgc/ |
| Current File : /home/g/i/t/giteleslfp/www/plugins/system/tooltipgc/tooltipgc.php |
<?php
/**
* @copyright Copyright (C) 2010 Cédric KEIFLIN alias ced1870 & Ghazal
* http://www.joomlack.fr
* @license GNU/GPL
* */
defined('_JEXEC') or die('Restricted access');
jimport('joomla.event.plugin');
// exemple de syntaxe :{tooltip}Déclencheur{end-texte}un petit garçon bien sympathique{end-tooltip}
class plgSystemTooltipgc extends JPlugin {
protected $autoloadLanguage = true;
function __construct(&$subject, $params) {
parent::__construct($subject, $params);
}
public function onBeforeRender() {
JHTML::_('jquery.framework', true);
}
public function onAfterRender() {
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
$doctype = $doc->getType();
$input = new JInput();
// si pas en frontend, on sort
if ($app->isClient('administrator')) {
return false;
}
// si pas HTML, on sort
if ($doctype !== 'html') {
return;
}
// if edit mode we stop
if ($input->get('layout') == 'edit' || $input->get('controller') == 'config.display.modules') {
return;
}
// récupère les données de la page
if (version_compare(JVERSION, '4') >= 0) {
$body = JFactory::getApplication()->getBody();
} else {
$body = JResponse::getBody();
}
// testes si le plugin est appelé, sinon on sort
if (!stristr($body, "{tooltip}"))
return;
// JHTML::_('jquery.framework', true);
// charge les paramètres par défaut
$plugin = JPluginHelper::getPlugin('system', 'tooltipgc');
$pluginParams = new JRegistry($plugin->params);
$largeur = $pluginParams->get('stylewidth', '150');
$fxduration = $pluginParams->get('fxduration', '300');
$dureebulle = $pluginParams->get('dureebulle', '500');
$opacity = $pluginParams->get('opacity', '80') / 100;
$fxtransition = $pluginParams->get('fxtransition', 'linear');
// mobile detection
if (!class_exists('Tooltipck\Mobile_Detect')) {
require_once dirname(__FILE__) . '/Mobile_Detect.php';
}
$detect = new Tooltipck\Mobile_Detect;
$regex = "#{tooltip}(.*?){end-tooltip}#s"; // masque de recherche
$body = preg_replace_callback($regex, 'plgSystemTooltipgc::createTooltipgc', $body);
$declaration = "\t<link rel=\"stylesheet\" href=\"" . JURI::base(true) . "/plugins/system/tooltipgc/assets/tooltipgc.css\" type=\"text/css\" media=\"screen\" />"
. "\n\t<script src=\"" . JURI::base(true) . "/plugins/system/tooltipgc/assets/tooltipgc.js\" type=\"text/javascript\"></script>"
. "\n\t<script type=\"text/javascript\">"
. "\n\tjQuery(document).ready(function($){"
. "new Tooltipgc($('.infotip'), { "
. "fxtransition: '" . $fxtransition . "', "
. "fxduration: " . $fxduration . ", "
. "dureebulle: " . $dureebulle . ", "
. "ismobile: " . ($detect->isMobile() ? '1' : '0') . ", "
. "opacite: " . $opacity . " });"
. " }); "
. "\n\t</script>"
. "\n\t<style type=\"text/css\">"
. ".tooltipgc_tooltip {" . $this->getCssStyles() . "}"
// . $this->createTooltipCss()
. "\n\t</style>";
$body = str_replace("</head>", $declaration . "\n</head>", $body);
if (version_compare(JVERSION, '4') >= 0) {
JFactory::getApplication()->setBody($body);
} else {
JResponse::setBody($body);
}
return;
}
function getCssStyles($prefix = '') {
$plugin = JPluginHelper::getPlugin('system', 'tooltipgc');
$pluginParams = new JRegistry($plugin->params);
if ($prefix == 'mobileoverlay') {
$bgcolor1 = $pluginParams->get($prefix . 'bgcolor1', '#000000');
$bgopacity = $pluginParams->get($prefix . 'bgopacity', '1');
$padding = '';
$tipoffsetx = '';
$bgcolor2 = '';
$roundedcornerstl = '';
$shadowblur = '';
$borderwidth = '';
} else {
$padding = $pluginParams->get($prefix . 'padding', '5') . 'px';
$tipoffsetx = $pluginParams->get($prefix . 'tipoffsetx', '0') . 'px';
$tipoffsety = $pluginParams->get($prefix . 'tipoffsety', '0') . 'px';
$bgcolor1 = $pluginParams->get($prefix . 'bgcolor1', '#f0f0f0');
$bgcolor2 = $pluginParams->get($prefix . 'bgcolor2', '#e3e3e3');
$bgopacity = $pluginParams->get($prefix . 'bgopacity', '1');
$roundedcornerstl = $pluginParams->get($prefix . 'roundedcornerstl', '') . 'px';
$roundedcornerstr = $pluginParams->get($prefix . 'roundedcornerstr', '') . 'px';
$roundedcornersbr = $pluginParams->get($prefix . 'roundedcornersbr', '') . 'px';
$roundedcornersbl = $pluginParams->get($prefix . 'roundedcornersbl', '') . 'px';
$shadowcolor = $pluginParams->get($prefix . 'shadowcolor', '#444444');
$shadowblur = $pluginParams->get($prefix . 'shadowblur', '3') . 'px';
$shadowspread = $pluginParams->get($prefix . 'shadowspread', '0') . 'px';
$shadowoffsetx = $pluginParams->get($prefix . 'shadowoffsetx', '0') . 'px';
$shadowoffsety = $pluginParams->get($prefix . 'shadowoffsety', '0') . 'px';
$bordercolor = $pluginParams->get($prefix . 'bordercolor', '#efefef');
$borderwidth = $pluginParams->get($prefix . 'borderwidth', '1') . 'px';
$shadowinset = $pluginParams->get($prefix . 'shadowinset', 0);
}
$css = array();
// faire test existence valeur, si vide ne pas charger la ligne
$css[] = $padding ? 'padding: ' . $padding . ';' : '';
$css[] = $borderwidth ? 'border: ' . $bordercolor . ' ' . $borderwidth . ' solid;' : '';
$css[] = $roundedcornerstl ? '-moz-border-radius: ' . $roundedcornerstl . ' ' . $roundedcornerstr . ' ' . $roundedcornersbr . ' ' . $roundedcornersbl . ';' : '';
$css[] = $roundedcornerstl ? '-webkit-border-radius: ' . $roundedcornerstl . ' ' . $roundedcornerstr . ' ' . $roundedcornersbr . ' ' . $roundedcornersbl . ';' : '';
$css[] = $roundedcornerstl ? 'border-radius: ' . $roundedcornerstl . ' ' . $roundedcornerstr . ' ' . $roundedcornersbr . ' ' . $roundedcornersbl . ';' : '';
$css[] = $bgcolor1 ? 'background: ' . $this->hex2RGB($bgcolor1, $bgopacity) . ';' : '';
$css[] = $bgcolor2 ? 'background: -moz-linear-gradient(top, ' . $bgcolor1 . ', ' . $bgcolor2 . ');' : '';
$css[] = $bgcolor2 ? 'background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(' . $bgcolor1 . '), to(' . $bgcolor2 . '));' : '';
$css[] = $tipoffsetx && $tipoffsety ? 'margin: ' . $tipoffsety . ' 0 0 ' . $tipoffsetx . ';' : '';
$css[] = $shadowblur ? '-moz-box-shadow: ' . $shadowinset . $shadowoffsetx . ' ' . $shadowoffsety . ' ' . $shadowblur . ' ' . $shadowspread . ' ' . $shadowcolor . ';' : '';
$css[] = $shadowblur ? '-webkit-box-shadow: ' . $shadowinset . $shadowoffsetx . ' ' . $shadowoffsety . ' ' . $shadowblur . ' ' . $shadowspread . ' ' . $shadowcolor . ';' : '';
$css[] = $shadowblur ? 'box-shadow: ' . $shadowinset . $shadowoffsetx . ' ' . $shadowoffsety . ' ' . $shadowblur . ' ' . $shadowspread . ' ' . $shadowcolor . ';' : '';
// .'opacity: '.$opacity.';'
return implode('', $css);
}
function createTooltipgc(&$matches) {
$ID = (int) (microtime(true) * 100000); // pour ID
// charge les paramètres par défaut
$plugin = JPluginHelper::getPlugin('system', 'tooltipgc');
$pluginParams = new JRegistry($plugin->params);
$largeur = $pluginParams->def('stylewidth', '150');
$fxduration = $pluginParams->def('fxduration', '300');
$dureebulle = $pluginParams->def('dureebulle', '500');
$tipoffsetx = $pluginParams->get('tipoffsetx', '0');
$tipoffsety = $pluginParams->get('tipoffsety', '0');
// découpe l'expression pour récupérer les textes
$patterns = "#{tooltip}(.*){(.*)}(.*){end-tooltip}#Uis";
$result = preg_match($patterns, $matches[0], $results);
// vérifie si des paramètres personnalisés existent
$relparams = Array();
$params = explode('|', $results[2]);
$parmsnumb = count($params);
for ($i = 1; $i < $parmsnumb; $i++) {
// old params
$fxduration = stristr($params[$i], "mood=") ? str_replace('mood=', '', $params[$i]) : $fxduration;
$dureebulle = stristr($params[$i], "tipd=") ? str_replace('tipd=', '', $params[$i]) : $dureebulle;
$tipoffsetx = stristr($params[$i], "offsetx=") ? str_replace('offsetx=', '', $params[$i]) : $tipoffsetx;
$tipoffsety = stristr($params[$i], "offsety=") ? str_replace('offsety=', '', $params[$i]) : $tipoffsety;
$largeur = stristr($params[$i], "w=") ? str_replace('px', '', str_replace('w=', '', $params[$i])) : $largeur;
// new params
$fxduration = stristr($params[$i], "time=") ? str_replace('time=', '', $params[$i]) : $fxduration;
$dureebulle = stristr($params[$i], "delayOut=") ? str_replace('delayOut=', '', $params[$i]) : $dureebulle;
$largeur = stristr($params[$i], "width=") ? str_replace('px', '', str_replace('width=', '', $params[$i])) : $largeur;
}
// compile the rel attribute to inject the specific params
$relparams['time'] = 'time=' . $fxduration;
$relparams['delayOut'] = 'delayOut=' . $dureebulle;
$relparams['offsetx'] = 'offsetx=' . $tipoffsetx;
$relparams['offsety'] = 'offsety=' . $tipoffsety;
$tooltiprel = '';
if (count($relparams)) {
$tooltiprel = ' data-params="' . implode("|", $relparams) . '"';
}
// compile le code HTML de sortie
$result = '<span class="infotip" id="tooltipgc' . $ID . '"' . $tooltiprel . '>'
. $results[1]
. '<span class="tooltipgc_tooltip" data-width="' . $largeur . '" style="width:' . $largeur . 'px;"><span class="tooltipgc_inner">'
. $results[3]
. '</span></span></span>';
return $result;
}
/**
* Ajax entry point for other functions
*
* @return mixed - the return from the called function
*
*/
function onAjaxTooltipgc() {
$app = JFactory::getApplication();
$input = $app->input;
$method = $input->get('method');
$paramsClass = $input->get('paramsclass', '', 'string');
// loads the language files from the frontend
$lang = JFactory::getLanguage();
$lang->load('plg_editors-xtd_tooltipgcbutton', JPATH_SITE . '/plugins/editors-xtd/tooltipgcbutton', $lang->getTag(), false);
if ($paramsClass) {
require_once(JPATH_SITE. '/plugins/editors-xtd/tooltipgcbutton/includes/' . strtolower($paramsClass) . '.php');
$results = call_user_func('TooltipgcParams' . ucfirst($paramsClass) . '::' . $method);
} else if (method_exists($this, $method)) {
$results = call_user_func('self::' . $method);
}
return $results;
}
/**
* Test if there is already a unit, else add the px
*
* @param string $value
* @return string
*/
function testUnit($value) {
if ((stristr($value, 'px')) OR (stristr($value, 'em')) OR (stristr($value, '%'))) {
return $value;
}
if ($value == '') {
$value = 0;
}
return $value . 'px';
}
/**
* Convert a hexa decimal color code to its RGB equivalent
*
* @param string $hexStr (hexadecimal color value)
* @param boolean $returnAsString (if set true, returns the value separated by the separator character. Otherwise returns associative array)
* @param string $seperator (to separate RGB values. Applicable only if second parameter is true.)
* @return array or string (depending on second parameter. Returns False if invalid hex color value)
*/
function hex2RGB($hexStr, $opacity) {
if (!stristr($opacity, '.'))
$opacity = $opacity / 100;
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
$rgbArray = array();
if (strlen($hexStr) == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster
$colorVal = hexdec($hexStr);
$rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
$rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
$rgbArray['blue'] = 0xFF & $colorVal;
} elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations
$rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
$rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
$rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
} else {
return false; //Invalid hex color code
}
$rgbacolor = "rgba(" . $rgbArray['red'] . "," . $rgbArray['green'] . "," . $rgbArray['blue'] . "," . $opacity . ")";
return $rgbacolor;
}
}