| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        module
 
     | 
  
  
    | 
      5
     | 
    
       * @package         droplets
 
     | 
  
  
    | 
      6
     | 
    
       * @author          Ruud Eisinga (Ruud) John (PCWacht)
 
     | 
  
  
    | 
      7
     | 
    
       * @author          WebsiteBaker Project
 
     | 
  
  
    | 
      8
     | 
    
       * @copyright       2004-2009, Ryan Djurovich
 
     | 
  
  
    | 
      9
     | 
    
       * @copyright       2009-2011, Website Baker Org. e.V.
 
     | 
  
  
    | 
      10
     | 
    
       * @link            http://www.websitebaker2.org/
 
     | 
  
  
    | 
      11
     | 
    
       * @license         http://www.gnu.org/licenses/gpl.html
 
     | 
  
  
    | 
      12
     | 
    
       * @platform        WebsiteBaker 2.8.x
 
     | 
  
  
    | 
      13
     | 
    
       * @requirements    PHP 5.2.2 and higher
 
     | 
  
  
    | 
      14
     | 
    
       * @version         $Id: droplets.php 2 2017-07-02 15:14:29Z Manuela $
 
     | 
  
  
    | 
      15
     | 
    
       * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/modules/droplets/droplets.php $
 
     | 
  
  
    | 
      16
     | 
    
       * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 
     | 
  
  
    | 
      17
     | 
    
       *
 
     | 
  
  
    | 
      18
     | 
    
       *    droplets are small codeblocks that are called from anywhere in the template.
 
     | 
  
  
    | 
      19
     | 
    
       *     To call a droplet just use [[dropletname]]. optional parameters for a droplet can be used like [[dropletname?parameter=value¶meter2=value]]\
 
     | 
  
  
    | 
      20
     | 
    
       *
 
     | 
  
  
    | 
      21
     | 
    
       *  1.0.2, bugfix, Reused the evalDroplet function so the extracted parameters will be only available within the scope of the eval and cleared when ready.
 
     | 
  
  
    | 
      22
     | 
    
       *  1.0.3, optimize, reduce memory consumption, increase speed, remove CSS, enable nested droplets
 
     | 
  
  
    | 
      23
     | 
    
       *
 
     | 
  
  
    | 
      24
     | 
    
       */
 
     | 
  
  
    | 
      25
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      26
     | 
    
      // Must include code to stop this file being accessed directly
 
     | 
  
  
    | 
      27
     | 
    
      if(!defined('WB_PATH')) {
     | 
  
  
    | 
      28
     | 
    
      
 
     | 
  
  
    | 
      29
     | 
    
          require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 
     | 
  
  
    | 
      30
     | 
    
          throw new IllegalFileException();
 
     | 
  
  
    | 
      31
     | 
    
      }
 
     | 
  
  
    | 
      32
     | 
    
      /* -------------------------------------------------------- */
 
     | 
  
  
    | 
      33
     | 
    
      
 
     | 
  
  
    | 
      34
     | 
    
          function do_eval($_x_codedata, $_x_varlist, &$wb_page_data)
 
     | 
  
  
    | 
      35
     | 
    
          {
     | 
  
  
    | 
      36
     | 
    
              extract($_x_varlist, EXTR_SKIP);
 
     | 
  
  
    | 
      37
     | 
    
              return(eval($_x_codedata));
 
     | 
  
  
    | 
      38
     | 
    
          }
 
     | 
  
  
    | 
      39
     | 
    
      
 
     | 
  
  
    | 
      40
     | 
    
          function processDroplets( &$wb_page_data ) {
     | 
  
  
    | 
      41
     | 
    
      // collect all droplets from document
 
     | 
  
  
    | 
      42
     | 
    
              $droplet_tags = array();
 
     | 
  
  
    | 
      43
     | 
    
              $droplet_replacements = array();
 
     | 
  
  
    | 
      44
     | 
    
              $droplet_search = '\[\[(.*?)\]\]'; // \[\[(\S*?)\]\]
 
     | 
  
  
    | 
      45
     | 
    
              if( preg_match_all( '/'.$droplet_search.'/', $wb_page_data, $found_droplets ) )
 
     | 
  
  
    | 
      46
     | 
    
              {
     | 
  
  
    | 
      47
     | 
    
                  foreach( $found_droplets[1] as $droplet )
 
     | 
  
  
    | 
      48
     | 
    
                  {
     | 
  
  
    | 
      49
     | 
    
                      if(array_key_exists( '[['.$droplet.']]', $droplet_tags) == false)
 
     | 
  
  
    | 
      50
     | 
    
                      {
     | 
  
  
    | 
      51
     | 
    
      // go in if same droplet with same arguments is not processed already
 
     | 
  
  
    | 
      52
     | 
    
                          $varlist = array();
 
     | 
  
  
    | 
      53
     | 
    
      // split each droplet command into droplet_name and request_string
 
     | 
  
  
    | 
      54
     | 
    
                          $tmp = preg_split('/\?/', $droplet, 2);
     | 
  
  
    | 
      55
     | 
    
                          $droplet_name = $tmp[0];
 
     | 
  
  
    | 
      56
     | 
    
                          $request_string = (isset($tmp[1]) ? $tmp[1] : '');
 
     | 
  
  
    | 
      57
     | 
    
                          if( $request_string != '' )
 
     | 
  
  
    | 
      58
     | 
    
                          {
     | 
  
  
    | 
      59
     | 
    
      // make sure we can parse the arguments correctly
 
     | 
  
  
    | 
      60
     | 
    
                              $request_string = html_entity_decode($request_string, ENT_COMPAT,DEFAULT_CHARSET);
 
     | 
  
  
    | 
      61
     | 
    
      // create array of arguments from query_string
 
     | 
  
  
    | 
      62
     | 
    
                              $argv = preg_split( '/&(?!amp;)/', $request_string );
 
     | 
  
  
    | 
      63
     | 
    
                              foreach ($argv as $argument)
 
     | 
  
  
    | 
      64
     | 
    
                              {
     | 
  
  
    | 
      65
     | 
    
      // split argument in pair of varname, value
 
     | 
  
  
    | 
      66
     | 
    
                                  list( $variable, $value ) = explode('=', $argument,2);
     | 
  
  
    | 
      67
     | 
    
                                  if( !empty($value) )
 
     | 
  
  
    | 
      68
     | 
    
                                  {
     | 
  
  
    | 
      69
     | 
    
      // re-encode the value and push the var into varlist
 
     | 
  
  
    | 
      70
     | 
    
                                      $varlist[$variable] = htmlentities($value, ENT_COMPAT,DEFAULT_CHARSET);
 
     | 
  
  
    | 
      71
     | 
    
                                  }
 
     | 
  
  
    | 
      72
     | 
    
                              }
 
     | 
  
  
    | 
      73
     | 
    
                          }
 
     | 
  
  
    | 
      74
     | 
    
                          else
 
     | 
  
  
    | 
      75
     | 
    
                          {
     | 
  
  
    | 
      76
     | 
    
      // no arguments given, so
 
     | 
  
  
    | 
      77
     | 
    
                              $droplet_name = $droplet;
 
     | 
  
  
    | 
      78
     | 
    
                          }
 
     | 
  
  
    | 
      79
     | 
    
      // request the droplet code from database
 
     | 
  
  
    | 
      80
     | 
    
                          $sql  = 'SELECT `code` FROM `'.TABLE_PREFIX.'mod_droplets` '
 
     | 
  
  
    | 
      81
     | 
    
                                . 'WHERE `name` LIKE \''.$droplet_name.'\''
 
     | 
  
  
    | 
      82
     | 
    
                                .   'AND `active` = 1';
 
     | 
  
  
    | 
      83
     | 
    
                          $codedata = $GLOBALS['database']->get_one($sql);
 
     | 
  
  
    | 
      84
     | 
    
                          if (!is_null($codedata))
 
     | 
  
  
    | 
      85
     | 
    
                          {
     | 
  
  
    | 
      86
     | 
    
                              $newvalue = do_eval($codedata, $varlist, $wb_page_data);
 
     | 
  
  
    | 
      87
     | 
    
      // check returnvalue (must be a string of 1 char at least or (bool)true
 
     | 
  
  
    | 
      88
     | 
    
                              if ($newvalue == '' && $newvalue !== true)
 
     | 
  
  
    | 
      89
     | 
    
                              {
     | 
  
  
    | 
      90
     | 
    
                                  if(DEBUG === true)
 
     | 
  
  
    | 
      91
     | 
    
                                  {
     | 
  
  
    | 
      92
     | 
    
                                      $newvalue = '<span class="mod_droplets_err">Error in: '.$droplet.', no valid returnvalue.</span>';
 
     | 
  
  
    | 
      93
     | 
    
                                  } else {
     | 
  
  
    | 
      94
     | 
    
                                      $newvalue = true;
 
     | 
  
  
    | 
      95
     | 
    
                                  }
 
     | 
  
  
    | 
      96
     | 
    
                              }
 
     | 
  
  
    | 
      97
     | 
    
                              if ($newvalue === true) { $newvalue = ""; }
     | 
  
  
    | 
      98
     | 
    
      // remove any defined CSS section from code. For valid XHTML a CSS-section is allowed inside <head>...</head> only!
 
     | 
  
  
    | 
      99
     | 
    
                              $newvalue = preg_replace('/<style.*>.*<\/style>/siU', '', $newvalue);
     | 
  
  
    | 
      100
     | 
    
      // push droplet-tag and it's replacement into Search/Replace array after executing only
 
     | 
  
  
    | 
      101
     | 
    
                              $droplet_tags[]         = '[['.$droplet.']]';
 
     | 
  
  
    | 
      102
     | 
    
                              $droplet_replacements[] = $newvalue;
 
     | 
  
  
    | 
      103
     | 
    
                          }
 
     | 
  
  
    | 
      104
     | 
    
                      }
 
     | 
  
  
    | 
      105
     | 
    
                  }    // End foreach( $found_droplets[1] as $droplet )
 
     | 
  
  
    | 
      106
     | 
    
      // replace each Droplet-Tag with coresponding $newvalue
 
     | 
  
  
    | 
      107
     | 
    
                  $wb_page_data = str_replace($droplet_tags, $droplet_replacements, $wb_page_data);
 
     | 
  
  
    | 
      108
     | 
    
              }
 
     | 
  
  
    | 
      109
     | 
    
      // returns TRUE if droplets found in content, FALSE if not
 
     | 
  
  
    | 
      110
     | 
    
              return( count($droplet_tags)!=0 );
 
     | 
  
  
    | 
      111
     | 
    
          }
 
     | 
  
  
    | 
      112
     | 
    
      
 
     | 
  
  
    | 
      113
     | 
    
          function evalDroplets( &$wb_page_data, $max_loops = 3 ) {
     | 
  
  
    | 
      114
     | 
    
              $max_loops = ((int)$max_loops = 0 ? 3 : (int)$max_loops);
 
     | 
  
  
    | 
      115
     | 
    
              while( (processDroplets($wb_page_data) == true) && ($max_loops > 0))
 
     | 
  
  
    | 
      116
     | 
    
              {
     | 
  
  
    | 
      117
     | 
    
                  $max_loops--;
 
     | 
  
  
    | 
      118
     | 
    
              }
 
     | 
  
  
    | 
      119
     | 
    
              return $wb_page_data;
 
     | 
  
  
    | 
      120
     | 
    
          }
 
     |