Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.formhelp.php

Documentation is available at function.formhelp.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty {formhelp} function plugin
  10.  *
  11.  * Type:    function
  12.  * Name:    formhelp
  13.  * Input:
  14.  *            - note        (optional)    words that are displayed, can also be an array, where: 'key: value'<br /> is printed
  15.  *                                    only displayed if site_form_help is enabled
  16.  *            - link        (optional)    provide a link to an internal page (avoids the problem with links being inerpreted
  17.  *                                    prematurely by the tra() function
  18.  *                                    <package>/<path to file>/<title>
  19.  *            - package    (optional)    creates a page to 'Package'.ucfirst( $package ) and takes precedence over $page, should both be set.
  20.  *                                    only dispalyed if help is enabled
  21.  *            - install    (optional)    used for packages that require a separate installation
  22.  *                                    passed in as an array:
  23.  *                                        package => name of package to be installed
  24.  *                                        file => path to installation file e.g.: admin/install.php
  25.  *            - page        (optional)    page name on bitweaver
  26.  *                                    only dispalyed if help is enabled
  27.  *            - force        (optional)    if set, it will always dipslay this entry regardless of the feature settings
  28.  */
  29. function smarty_function_formhelp( $pParams, &$gBitSmarty ) {
  30.     $atts = $ret_note = $ret_page = $ret_link = $ret_install = '';
  31.  
  32.     if( !empty( $pParams['hash'] ) ) {
  33.         $hash = &$pParams['hash'];
  34.     } else {
  35.         // maybe params were passed in separately
  36.         $hash = &$pParams;
  37.     }
  38.  
  39.     // we need to do some hash modification if we're in the installer
  40.     if( !empty( $hash['is_installer'] )) {
  41.         if( !empty( $hash['note']['upgrade'] )) {
  42.             $hash['note']['version'] = $hash['note']['upgrade'];
  43.             unset( $hash['note']['upgrade'] );
  44.         }
  45.     }
  46.  
  47.     foreach( $hash as $key => $val ) {
  48.         switch( $key ) {
  49.             case 'note':
  50.             case 'warning':
  51.             case 'link':
  52.             case 'page':
  53.                 $rawHash[$key] = $val;
  54.                 break;
  55.             case 'label':
  56.             case 'package':
  57.             case 'install':
  58.             case 'force':
  59.                 $$key = $val;
  60.                 break;
  61.             default:
  62.                 if( $val ) {
  63.                     $atts .= $key.'="'.$val.'" ';
  64.                 }
  65.                 break;
  66.         }
  67.     }
  68.  
  69.     if( !empty( $package ) ) {
  70.         $rawHash['page'] = ucfirst( $package ).'Package';
  71.     }
  72.  
  73.     // if link was passed in as a string, convert it into an array
  74.     if( !empty( $rawHash['link'] ) && is_string( $rawHash['link'] ) ) {
  75.         $l = explode( '/', $rawHash['link'] );
  76.         unset( $rawHash['link'] );
  77.         // package is first, title last, and all remaining elements file (can be 'foo/bar.php' as well)
  78.         $rawHash['link']['package'] = array_shift( $l );
  79.         $rawHash['link']['title']   = array_pop( $l );
  80.         $rawHash['link']['file']    = implode( '/', $l );
  81.     }
  82.  
  83.     global $gBitSystem;
  84.     if( $gBitSystem->isFeatureActive( 'site_online_help' ) || $gBitSystem->isFeatureActive( 'site_form_help' ) || $force == 'y' ) {
  85.         if( !empty( $rawHash ) ) {
  86.             if( !empty( $rawHash['page'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) {
  87.                 $ret_page = '<strong>'.tra( 'Online help' ).'</strong>: <a class=\'external\' href=\'http://doc.bitweaver.org/wiki/index.php?page='.$rawHash['page'].'\'>'.$rawHash['page'].'</a><br />';
  88.             }
  89.  
  90.             if( !empty( $rawHash['link'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) {
  91.                 if( is_array( $rawHash['link'] ) ) {
  92.                     $ret_link  = '<strong>'.tra( 'IntraLink' ).'</strong>: ';
  93.                     $ret_link .= '<a href=\'';
  94.                     $ret_link .= constant( strtoupper( $rawHash['link']['package'] ).'_PKG_URL' ).$rawHash['link']['file'];
  95.                     $ret_link .= '\'>'.tra( $rawHash['link']['title'] ).'</a>';
  96.                 }
  97.             }
  98.  
  99.             if( ( !empty( $rawHash['note'] ) && $gBitSystem->isFeatureActive('site_form_help') ) || ( !empty( $force ) && !empty( $rawHash['note'] ) ) ) {
  100.                 if( is_array( $rawHash['note'] ) ) {
  101.                     foreach( $rawHash['note'] as $name => $value ) {
  102.                         if( $name == 'install' ) {
  103.                             $ret_install  = '<strong>'.tra( 'Install' ).'</strong>: '.tra( 'To use this package, you will first have to run the package specific installer' ).': ';
  104.                             $ret_install .= '<a href=\'';
  105.                             $ret_install .= constant( strtoupper( $value['package'] ).'_PKG_URL' ).$value['file'];
  106.                             $ret_install .= '\'>'.ucfirst( $value['package'] ).'</a>';
  107.                         } else {
  108.                             $ret_note .= '<strong>'.ucfirst( tra( $name ) ).'</strong>: '.tra( $value ).'<br />';
  109.                         }
  110.                     }
  111.                 } else {
  112.                     $ret_note .= tra( $rawHash['note'] ).'<br />';
  113.                 }
  114.             }
  115.  
  116.             if( !empty( $rawHash['warning'] ) ) {
  117.                 $ret_note .= '<span class="warning">'.tra( $rawHash['warning'] ).'</span><br />';
  118.             }
  119.  
  120.             // join all the output content into one string
  121.             $content = $ret_note.$ret_page.$ret_link.$ret_install;
  122.  
  123.             $html = '';
  124.             // using the overlib popup system
  125.             if( !empty( $content ) ) {
  126.                 if( $gBitSystem->isFeatureActive('site_help_popup') ) {
  127.                     $gBitSmarty->loadPlugin( 'smarty_modifier_popup' );
  128.                     $gBitSmarty->loadPlugin( 'smarty_function_biticon' );
  129.  
  130.                     $gBitSmarty->assign( 'title',tra('Extended Help') );
  131.  
  132.                     $gBitSmarty->assign( 'content', $content );
  133.                     $gBitSmarty->assign( 'closebutton', TRUE );
  134.                     $text = $gBitSmarty->fetch('bitpackage:kernel/popup_box.tpl');
  135.                     $text = preg_replace( '/"/',"'",$text );
  136.  
  137.                     $popup = array(
  138.                         'trigger' => 'onclick',
  139.                         'text' => $text,
  140.                         'fullhtml' => '1',
  141.                         'sticky' => '1',
  142.                         'timeout' => '8000',
  143.                     );
  144.  
  145.                     $biticon = array(
  146.                         'ipackage' => 'icons',
  147.                         'iname' => 'dialog-information',
  148.                         'iforce' => 'icon',
  149.                         'iexplain' => 'Extended Help',
  150.                     );
  151.  
  152.                     $html .= ' <span class="formhelppopup" '.$atts.'>&nbsp;';
  153.                     $html .= '<a '.smarty_function_popup( $popup, $gBitSmarty ).'>';
  154.                     $html .= smarty_function_biticon( $biticon, $gBitSmarty );
  155.                     $html .= '</a>';
  156.                     $html .= '</span>';
  157.                 } else {
  158.                     $html .= '<span class="help-block" '.$atts.'>'.$content.'</span>';
  159.                 }
  160.             }
  161.  
  162.             return $html;
  163.         }
  164.     }
  165. }
  166. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:37 +0000 by phpDocumentor 1.5.0-lsces