3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* , , / \ ((__-^^-,-^^-__)) `-_---' `---_-' `--|o` 'o|--' \ ` / ): :( :o_o: "-" This file is part of CookieLayer. CookieLayer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. CookieLayer 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 General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar. If not, see <http://www.gnu.org/licenses/>. */ /** * CakePHP CookieLayerHelper to use without cakephp framework. * @author Juan Fran */ if(!defined('ROOT')) die('ROOT constant not defined!'); if(!defined('DS')) die('DS constant not defined!'); class CookieLayerHelper { /* Default settings This script have some options more that cakephp CookieLayerHelper script. */ private $settings = array( // Text messages to show. If you want to change the messages values, you´ll need to change the Locales files from cakephp. // IMPORTANT TO CHANGE THE MESSAGE VALUES: // You can change the msg string (msgstr) param in the .po files inside the locale folder. // or You can change the following text array values and then change the msgid and msgstr in each .po file, and compile the .po file. 'texts' => array( 'normalText' => 'we use our own cookies and cookies from others to improve our services by analyzing their browsing habits. If you continue to browse, we consider that you accept the terms. You can change the settings or get more information ', 'strictText' => 'we use our own cookies and cookies from others to improve our services by analyzing their browsing habits. By accepting, you approve our cookies policy. You can change the settings or get more information ', 'underStdText' => 'Understood', 'agreeText' => 'Agree', 'disagreeTest' => 'Disagree', 'title' => 'Cookie Policy', 'here' => 'here' ), 'locale' => 'en_GB.UTF-8', // this may differ depending on the server. Default en_GB.UTF-8 'langDomain' => 'cakeCookieLayerHelper', // Domain for cakephp translations. Default cakeCookieLayerHelper. 'localeDir' => 'Locale', // Dir name only. Default /php_js/Locale 'mode' => 'strict', // normal: show understood button and include all cookies without ask. // strict: show agree and disagree buttons, and only include cookies when user press agre button. It takes normalText or strictText 'position' => 'bottom', // Layer position. Default is bottom. Options: [poisition => 'top' or 'bottom'] 'themePath' => '', // Css file. Relative path. Default /php_js/css/CookieLayer.css 'theme' => 'Dark', // Theme. Default theme Dark. 'separator' => ' - ', // Separator for links. Default '-'. 'showLayerOnce' => false, // Show the layer once and then it hides. Default false. 'autoHide' => true, // Auto hide. Indicates that the bar is going to hide in x (how is indicated in param timeOut) seconds. Default true. 'timeOut' => 10, // Time out for auto hide and showLayerOnce. 'scriptPath' => '', // Js file. Relative path. Default /php_js/js/CookieLayer.js 'scriptLoader' => '', // Js Loader file. Relative path. Default is /php_js/js/CookieLayerLoader.js // Function to execute when the user click the accept button or understood. // When the user enter twice to the site, this function is going to execute again, because the user accepted the terms the first time. 'onAceptClick' => ' /* Instead of load the source code via CookieLayerLoader.js, here you can include more source code. */ ', 'onDisagreeClick' => ' /* Here you can include code that is going to execute when disagree button was pressed */ ', ); public function __construct($settings = array()) { $this->settings = (array_merge($this->settings, (array) $settings)); // Default paths if(empty($this->settings['themePath'])) $this->settings['themePath'] = 'css' . DS . 'CookieLayer.css'; if(empty($this->settings['scriptPath'])) $this->settings['scriptPath'] = 'js' . DS . 'CookieLayer.js'; if(empty($this->settings['scriptLoader'])) $this->settings['scriptLoader'] = 'js' . DS . 'CookieLayerLoader.js'; // Check files if(!file_exists(ROOT . $this->settings['themePath'])){ throw new Exception('Error. Css theme file ' . ROOT . $this->settings['themePath'] . ' not found!'); } if(!file_exists(ROOT . $this->settings['scriptPath'])){ throw new Exception('Error. Js script file ' . ROOT . $this->settings['scriptPath'] . ' not found!'); } if(!file_exists(ROOT . $this->settings['scriptLoader'])){ throw new Exception('Error. Js Loader script file ' . ROOT . $this->settings['scriptLoader'] . ' not found!'); } if(!file_exists(ROOT . $this->settings['localeDir'])){ throw new Exception('Error. Locale dir ' . ROOT . $this->settings['localeDir'] . ' not found!'); } // If you made a call to a setLocale function before call constructor, this line can be commented setlocale(LC_ALL, $this->settings['locale']); bindtextdomain($this->settings['langDomain'], $this->settings['localeDir']); bind_textdomain_codeset($this->settings['langDomain'], 'UTF-8'); textdomain($this->settings['langDomain']); } private function getOptions() { if ($this->settings['mode'] == 'normal') // Get links return '<a href=\'#\' class=\'lAgree\'>' . _($this->settings['texts']['underStdText']) . '</a>'; else return '<a href=\'#\' class=\'lAgree\'>' . _($this->settings['texts']['agreeText']) . '</a>' . ' ' . '<a href=\'#\' class=\'lDisagree\'>' . _($this->settings['texts']['disagreeTest']) . '</a>'; } function url(){ if(isset($_SERVER['HTTPS'])){ $protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http"; } else{ $protocol = 'http'; } //return $protocol . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; return $protocol . "://localhost/dev.cookielayer.com/php_js/"; } public function render() { echo '<link rel=\'stylesheet\' href=\'' . $this->url() . $this->settings['themePath'] . '\' type=\'text/css\'>'; /* * * <div id="CookieLayer" style="bottom: -66px;" class="hideToBottom"> * <div id="cL_Dark"> * * <div id="CookieLayerHeader" class="border-top"> * * <span class="title"> * <a href="#">Política de Cookies</a></span></div> * * <div id="CookieLayerBody" class="border-top"><p>Utilizamos cookies propias y de terceros para mejorar nuestros servicios mediante el análisis de sus hábitos de navegación. Si continua navegando, consideramos que aceptas los terminos. Puede cambiar la configuración u obtener más información <a href="/pages/aviso">aquí</a>. - <a href="#" class="lAgree">Entendido</a></p></div> * * <div id="CookieLayerFooter" style="display: none;"><span class="title"><a href="#">Política de Cookies</a></span></div></div></div> * * * */ $text = ($this->settings['mode']=='normal') ? _($this->settings['texts']['normalText']): _($this->settings['texts']['strictText']); echo '<div id=\'CookieLayer\'> <div id=\'' . 'cL_' . $this->settings['theme'] . '\'> <div id=\'CookieLayerHeader\' class=\'border-top\'> <span class=\'title\'><a href=\'#\'>' . _($this->settings['texts']['title']) . '</a></span> </div> <div id=\'CookieLayerBody\' class=\'border-top\'> <p>' . $text . $this->getOptions() . '</p> </div> <div id=\'CookieLayerFooter\'> <span class=\'title\'><a href=\'#\'>' . _($this->settings['texts']['title']) . '</a></span> </div> </div> </div> '; echo '<script src=\'' . $this->url() . $this->settings['scriptPath'] . '\' type=\'text/javascript\'></script>'; ?> <script type="text/javascript"> var config = { theme : '<?php echo $this->settings['theme']; ?>', mode : '<?php echo $this->settings['mode']; ?>', position : '<?php echo $this->settings['position']; ?>', autoHide : <?php if($this->settings['position']) echo 'true'; else echo 'false'; ?>, showLayerOnce : <?php if($this->settings['showLayerOnce']) echo 'true'; else echo 'false'; ?>, timeOut : <?php echo $this->settings['timeOut']; ?>, scriptLoader : '<?php echo $this->url() . $this->settings['scriptLoader']; ?>', onAceptClick : function(){<?php echo $this->settings['onAceptClick']; ?>}, onDisagreeClick: function(){<?php echo $this->settings['onDisagreeClick']; ?>} }; // Initialize. window.CookieLayer.initialize(config); </script> <?php } }
based on LqYRn
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
ROOT constant not defined!
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VvMU8 on line 45
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VvMU8 on line 45
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/VvMU8 on line 45
Process exited with code 255.