Advertisement
Guest User

Xavi

a guest
Nov 10th, 2010
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.25 KB | None | 0 0
  1. <?php
  2. // (c) Copyright 2002-2010 by authors of the Tiki Wiki/CMS/Groupware Project
  3. //
  4. // All Rights Reserved. See copyright.txt for details and a complete list of authors.
  5. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
  6. // $Id: function.button.php 28190 2010-07-29 12:55:12Z sylvieg $
  7.  
  8. //this script may only be included - so its better to die if called directly.
  9. if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  10.   header("location: index.php");
  11.   exit;
  12. }
  13.  
  14. /*
  15.  * smarty_function_button: Display a Tikiwiki button
  16.  *
  17.  * params will be used as params for as smarty self_link params, except those special params specific to smarty button :
  18.  *  - _text: Text that will be shown in the button
  19.  *  - _auto_args: comma separated list of URL arguments that will be kept from _REQUEST (like $auto_query_args) (in addition of course of those you can specify in the href param)
  20.  *                    You can also use _auto_args='*' to specify that every arguments listed in the global var $auto_query_args has to be kept from URL
  21.  *  - _flip_id: id HTML atribute of the element to show/hide (for type 'flip'). This will automatically generate an 'onclick' attribute that will use tiki javascript function flip() to show/hide some content.
  22.  *  - _flip_hide_text: if set to 'n', do not display a '(Hide)' suffix after _text when status is not 'hidden'
  23.  *  - _flip_default_open: if set to 'y', the flip is open by default (if no cookie jar)
  24.  *  - _escape: if set to 'y', will escape the apostrophes in onclick
  25.  */
  26. function smarty_function_button($params, &$smarty) {
  27.     if ( ! is_array($params) || ! isset($params['_text']) ) return;
  28.     global $tikilib, $prefs, $auto_query_args;
  29.  
  30.     require_once $smarty->_get_plugin_filepath('block', 'self_link');
  31.  
  32.     $selected = false ;
  33.     if ( ! empty($params['_selected']) ) {
  34.         // Filter the condition
  35.         if (preg_match('/[a-zA-Z0-9 =<>!]+/',$params['_selected'])) {
  36.             $error_report = error_reporting(~E_ALL);
  37.             $return = eval ( '$selected =' . $params['_selected'].";" );
  38.             error_reporting($error_report);
  39.             if ($return !== FALSE) {
  40.                 if ($selected) {
  41.                     if (! empty($params['_selected_class']) ) {
  42.                         $params['_class'] = $params['_selected_class'];
  43.                     } else {
  44.                         $params['_class'] = 'selected';
  45.                     }
  46.                     if (! empty($params['_selected_text']) ) {
  47.                         $params['_text'] = $params['_selected_text'];
  48.                     }
  49.                     if (! empty($params['_selected_title']) ) {
  50.                         $params['_title'] = $params['_selected_title'];
  51.                     }
  52.                     if (! empty($params['_selected_icon']) ) {
  53.                         $params['_icon'] = $params['_selected_icon'];
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.     }
  59.  
  60.     $disabled = false ;
  61.     if ( ! empty($params['_disabled']) ) {
  62.         // Filter the condition
  63.         if (preg_match('/[a-zA-Z0-9 =<>!]+/',$params['_disabled'])) {
  64.             $error_report = error_reporting(~E_ALL);
  65.             $return = eval ( '$disabled =' . $params['_disabled'].";" );
  66.             error_reporting($error_report);
  67.             if ($return !== FALSE) {
  68.                 if ($disabled) {
  69.                     if (! empty($params['_disabled_class']) ) {
  70.                         $params['_class'] = $params['_disabled_class'];
  71.                     } else {
  72.                         $params['_class'] = 'disabled';
  73.                     }
  74.                     if (! empty($params['_disabled_text']) ) {
  75.                         $params['_text'] = $params['_disabled_text'];
  76.                     }
  77.                     if (! empty($params['_disabled_title']) ) {
  78.                         $params['_title'] = $params['_disabled_title'];
  79.                     }
  80.                     if (! empty($params['_disabled_icon']) ) {
  81.                         $params['_icon'] = $params['_disabled_icon'];
  82.                     }
  83.                 }
  84.             }
  85.         }
  86.         unset($params['_disabled']);
  87.     }
  88.  
  89.     //apply class only to the button
  90.     if (!empty($params['_class'])) {
  91.         $class = $params['_class'];
  92.     }
  93.     if (!empty($params['_id'])) {
  94.         $id = ' id="'.$params['_id'].'"';
  95.     } else {
  96.         $id = '';
  97.     }
  98.    
  99.     unset($params['_class']);
  100.  
  101.     if (!$disabled) {
  102.         $flip_id = '';
  103.         if ( ! empty($params['_flip_id']) ) {
  104.             $params['_onclick'] = "javascript:flip('"
  105.                 . $params['_flip_id']
  106.                 . "');flip('"
  107.                 . $params['_flip_id']
  108.                 . "_close','inline');return false;";
  109.             if ( ! empty($params['_escape']) ) {
  110.                 $params['_onclick'] = addslashes($params['_onclick']);
  111.             }
  112.             if ( ! isset($params['_flip_hide_text']) || $params['_flip_hide_text'] != 'n' ) {
  113.                 $cookie_key = 'show_' . $params['_flip_id'];
  114.                 $params['_text'] .= '<span id="'.$params['_flip_id'].'_close" style="display:'
  115.                     . ( ((isset($_SESSION['tiki_cookie_jar'][$cookie_key]) && $_SESSION['tiki_cookie_jar'][$cookie_key] == 'y') || (isset($params['_flip_default_open']) && $params['_flip_default_open'] == 'y')) ? 'inline' : 'none' )
  116.                     . ';"> (' . tra('Hide') . ')</span>';
  117.             }
  118.         }
  119.  
  120.         $auto_query_args_orig = $auto_query_args;
  121.         if ( !empty($params['_auto_args']) ) {
  122.             if ( $params['_auto_args'] != '*' ) {
  123.                 if ( !isset($auto_query_args) ) $auto_query_args = null;
  124.                 $auto_query_args = explode(',', $params['_auto_args']);
  125.             }
  126.         } else {
  127.             $params['_noauto'] = 'y';
  128.         }
  129.  
  130.         // Remove params that does not start with a '_', since we don't want them to modify the URL except when in auto_query_args
  131.         if ( ! isset($params['_keepall']) || $params['_keepall'] != 'y') {
  132.             foreach ( $params as $k => $v ) {
  133.                 if ( $k[0] != '_' && $k != 'href' && (empty($auto_query_args) || !in_array($k,$auto_query_args)) ) unset($params[$k]);
  134.             }
  135.         }
  136.  
  137.         $url_args = array();
  138.         if ( ! empty($params['href']) ) {
  139.  
  140.             // Handle anchors
  141.             if ( strpos($params['href'], '#') )
  142.                 list($params['href'], $params['_anchor']) = explode('#', $params['href'], 2);
  143.  
  144.             // Handle script and URL arguments
  145.             if ( ( $pos = strpos($params['href'], '?') ) !== false ) {
  146.                 $params['_script'] = substr($params['href'], 0, $pos);
  147.                 TikiLib::parse_str($tikilib->htmldecode(substr($params['href'], $pos+1)), $url_args);
  148.                 $params = array_merge($params, $url_args);
  149.             } else {
  150.                 $params['_script'] = $params['href'];
  151.             }
  152.  
  153.             unset($params['href']);
  154.         }
  155.  
  156.         $html = smarty_block_self_link(
  157.                 $params,
  158.                 $params['_text'],
  159.                 $smarty,
  160.                 false
  161.                 );
  162.     } else {
  163.         $params['_disabled'] = 'y';
  164.         $html = smarty_block_self_link(
  165.                 $params,
  166.                 $params['_text'],
  167.                 $smarty,
  168.                 false
  169.                 );
  170.     }
  171.  
  172.     $auto_query_args = $auto_query_args_orig;
  173.     return '<span class="'.(!empty($params['_noborder']) ? '' : 'button').(!empty($class)?" $class":'').'"'.$id.'>'.$html.'</span>';
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement