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

Source for file _functions.php

Documentation is available at _functions.php

  1. <?php
  2.  
  3.   /** 
  4.    * dbscript for PHP 4 & 5 - restful crud framework
  5.    * @version 0.1.2 -- 19-Feb-2007
  6.    * @author Brian Hendrickson <brian@dbscript.net>
  7.    * @link http://dbscript.net/
  8.    * @copyright Copyright 2007 Brian Hendrickson
  9.    * @package dbscript
  10.    * @license http://www.opensource.org/licenses/mit-license.php MIT License
  11.    */
  12.  
  13.  
  14.   /**
  15.    * classify
  16.    * 
  17.    * takes a table/resource name ('entries')
  18.    * makes it singular & capitalized ('Entry')
  19.    *
  20.    * @access public
  21.    * @param string $resource 
  22.    * @return string 
  23.    */
  24.  
  25. function classify$resource {
  26.   
  27.   $n strtolower(str_replace'_'' '$resource ));
  28.   
  29.   switch$n {
  30.     
  31.     // renaming handlers
  32.     
  33.     case 'people' :
  34.       $n 'Person';
  35.       break;
  36.       
  37.     case substr$n-== 'ies' :
  38.       $n substr$n0-"y";
  39.       break;
  40.       
  41.     case substr$n-== 's' :
  42.       $n substr$n0-);
  43.       break;
  44.       
  45.   }
  46.   
  47.   $n ucwords($n);
  48.   
  49.   $n str_replace' '''$n );
  50.   
  51.   return $n;
  52.   
  53. }
  54.  
  55.  
  56.   /**
  57.    * tableize
  58.    * 
  59.    * takes a (CamelCase or not) name ('DbSession')
  60.    * makes it lower_case and plural ('db_sessions')
  61.    * 
  62.    * @access public
  63.    * @param string $table 
  64.    * @return string 
  65.    */
  66.    
  67. function tableize$object {
  68.  
  69.   $n preg_split'//'$object );
  70.   
  71.     // replace uppercase Chars with _ and lowercase char
  72.   foreach $n as $idx=>$char {
  73.     if ctype_upper$char && $idx && $char )
  74.       $n[$idx"_" strtolower($char);
  75.     elseif ctype_upper$char ) )
  76.       $n[$idxstrtolower($char);
  77.   }
  78.  
  79.   $n implode($n);
  80.  
  81.   switchstrtolower($n) ) {
  82.     
  83.     // renaming handlers
  84.  
  85.     case $n == 'person' :
  86.       $n 'people';
  87.       break;
  88.  
  89.     case substr$n-== 'y' :
  90.       $n substr$n0-"ies";
  91.       break;
  92.       
  93.     case substr$n-!= 's' :
  94.       $n $n "s";
  95.       break;
  96.       
  97.   }
  98.   
  99.   return $n;
  100.   
  101. }
  102.  
  103.  
  104.   /**
  105.    * Error
  106.    * 
  107.    * custom Error handling per-client-type
  108.    * 
  109.    * @author Brian Hendrickson <brian@dbscript.net>
  110.    * @access public
  111.    * @param integer $errno 
  112.    * @param string $errstr 
  113.    * @param string $errfile 
  114.    * @param integer $errline 
  115.    * @todo return based on content-negotiation status
  116.    */
  117.  
  118. function dbscript_error($errno$errstr$errfile$errline{
  119.   if (!error_reporting(|| $errno == 2048{
  120.     return;
  121.   }
  122.   switch ($errno{
  123.     case E_USER_ERROR:
  124.       $req request_object();
  125.       if (isset($_GET['dbscript_xml_error_continue'])) {
  126.         $xml "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
  127.         $xml .= "<root>\n";
  128.         $xml .= "  <dbscript_error>Fatal error in line $errline of file $errfile<br>: $errstr</dbscript_error>\n";
  129.         $xml .= "</root>\n";
  130.         print $xml;
  131.       elseif (isset($req->error)) {
  132.         $req->handle_error$errstr );
  133.         print "<b>ERROR</b[$errno] $errstr<br />\n";
  134.         print "  Fatal error in line $errline of file $errfile<br />\n";
  135.         print "Aborting...<br />\n";
  136.         exit(1);
  137.       else {
  138.         print "<b>ERROR</b[$errno] $errstr<br />\n";
  139.         print "  Fatal error in line $errline of file $errfile<br />\n";
  140.         print "Aborting...<br />\n";
  141.         exit(1);
  142.       }
  143.       break;
  144.     case E_USER_WARNING:
  145.       print "<b>WARNING</b[$errno] $errstr<br />\n";
  146.       break;
  147.     case E_USER_NOTICE:
  148.       print "<b>NOTICE</b[$errno] $errstr<br />\n";
  149.       break;
  150.     default:
  151.       print "<b>ERROR</b[$errno] $errstr<br />\n";
  152.       print "  Error in line $errline of file $errfile<br />\n";
  153.       break;
  154.   }
  155. }
  156.  
  157.  
  158.   /**
  159.    * Trigger Before
  160.    * 
  161.    * trip before filters for a function
  162.    * 
  163.    * @access public
  164.    * @param string $func 
  165.    * @param object $obj_a 
  166.    * @param object $obj_b 
  167.    */
  168.  
  169. function trigger_before$func&$obj_a&$obj_b {
  170.   if isset$GLOBALS['ASPECTS']['before'][$func) ) {
  171.     foreach$GLOBALS['ASPECTS']['before'][$funcas $callback {
  172.       call_user_func_array$callbackarray$obj_a$obj_b ) );
  173.     }
  174.   }
  175. }
  176.  
  177.  
  178.   /**
  179.    * Trigger After
  180.    * 
  181.    * trip after filters for a function
  182.    * 
  183.    * @access public
  184.    * @param string $func 
  185.    * @param object $obj_a 
  186.    * @param object $obj_b 
  187.    */
  188.  
  189. function trigger_after$func&$obj_a&$obj_b {
  190.   if isset$GLOBALS['ASPECTS']['after'][$func) ) {
  191.     foreach$GLOBALS['ASPECTS']['after'][$funcas $callback {
  192.       call_user_func_array$callbackarray$obj_a$obj_b ) );
  193.     }
  194.   }
  195. }
  196.  
  197.  
  198.   /**
  199.    * aspect_join_functions
  200.    * 
  201.    * add trigger function name pairs to GLOBALS
  202.    * 
  203.    * @access public
  204.    * @param string $func 
  205.    * @param string $callback 
  206.    * @param string $type 
  207.    */
  208.    
  209. function aspect_join_functions$func$callback$type 'after' {
  210.   $GLOBALS['ASPECTS'][$type][$func][$callback;
  211. }
  212.  
  213.  
  214.   /**
  215.    * Before Filter
  216.    * 
  217.    * set an aspect function to trigger before another function
  218.    * 
  219.    * @access public
  220.    * @param string $name 
  221.    * @param string $func 
  222.    * @param string $when 
  223.    */
  224.  
  225. function before_filter$name$func$when 'before' {
  226.   aspect_join_functions$func$name$when );
  227. }
  228.  
  229.  
  230.   /**
  231.    * After Filter
  232.    * 
  233.    * set an aspect function to trigger after another function
  234.    * 
  235.    * @access public
  236.    * @param string $name 
  237.    * @param string $func 
  238.    * @param string $when 
  239.    */
  240.  
  241. function after_filter$name$func$when 'after' {
  242.   aspect_join_functions$func$name$when );
  243. }
  244.  
  245.  
  246.   /**
  247.    * Never
  248.    * 
  249.    * returns false
  250.    * 
  251.    * @access public
  252.    * @return boolean false
  253.    */
  254.  
  255. function never({
  256.   return false;
  257. }
  258.  
  259.  
  260.   /**
  261.    * Always
  262.    * 
  263.    * returns true
  264.    * 
  265.    * @access public
  266.    * @return boolean true
  267.    */
  268.  
  269. function always({
  270.   return true;
  271. }
  272.  
  273.  
  274.   /**
  275.    * model_path
  276.    * 
  277.    * path to data models
  278.    * 
  279.    * @access public
  280.    * @return string 
  281.    */
  282.   
  283. function model_path({
  284.   return $GLOBALS['PATH']['models'];
  285. }
  286.  
  287.  
  288.   /**
  289.    * library_path
  290.    * 
  291.    * path to libraries
  292.    * 
  293.    * @access public
  294.    * @return string 
  295.    */
  296.   
  297. function library_path({
  298.   return $GLOBALS['PATH']['library'];
  299. }
  300.  
  301.  
  302.   /**
  303.    * dbscript_path
  304.    * 
  305.    * path to library/dbscript
  306.    * 
  307.    * @access public
  308.    * @return string 
  309.    */
  310.   
  311. function dbscript_path({
  312.   return $GLOBALS['PATH']['dbscript'];
  313. }
  314.  
  315.  
  316.   /**
  317.    * ignore_errors
  318.    * 
  319.    * returns value of environment variable, if set
  320.    * 
  321.    * @access public
  322.    * @return boolean 
  323.    */
  324.   
  325. function ignore_errors({
  326.   global $env;
  327.   if isset$env['ignore_errors'&& $env['ignore_errors')
  328.     return true;
  329.   return false;
  330. }
  331.  
  332.  
  333.   /**
  334.    * plugin_path
  335.    * 
  336.    * path to data models
  337.    * 
  338.    * @access public
  339.    * @return string 
  340.    */
  341.   
  342. function plugin_path({
  343.   return $GLOBALS['PATH']['plugins'];
  344. }
  345.  
  346.  
  347.   /**
  348.    * controller_path
  349.    * 
  350.    * path to controllers
  351.    * 
  352.    * @access public
  353.    * @return string 
  354.    */
  355.   
  356. function controller_path({
  357.   return $GLOBALS['PATH']['controllers'];
  358. }
  359.  
  360.  
  361.   /**
  362.    * db_object
  363.    * 
  364.    * get global Database object
  365.    * 
  366.    * @access public
  367.    * @return string 
  368.    */
  369.   
  370. function &db_object({
  371.   global $db;
  372.   return $db;
  373. }
  374.  
  375.  
  376. function &environment({
  377.   global $env;
  378.   return $env;
  379. }
  380.  
  381.  
  382. function render_blob$value {
  383.   
  384.   $db =db_object();
  385.   
  386.   if (is_array$value )) {
  387.  
  388.     $db->large_object_fetch
  389.  
  390.       $value['t'],
  391.       $value['f'],
  392.       $value['k'],
  393.       $value['i']
  394.  
  395.     );
  396.  
  397.   else {
  398.  
  399.     $db->large_object_fetch$value );
  400.  
  401.   }
  402.  
  403. }
  404.  
  405.  
  406. function fetch_blob$value {
  407.   
  408.   $db =db_object();
  409.   
  410.   if (is_array$value )) {
  411.  
  412.     $db->large_object_fetch
  413.  
  414.       $value['t'],
  415.       $value['f'],
  416.       $value['k'],
  417.       $value['i'],
  418.       true
  419.  
  420.     );
  421.  
  422.   else {
  423.  
  424.     $db->large_object_fetch$valuetrue );
  425.  
  426.   }
  427.  
  428. }
  429.  
  430.   /**
  431.    * template_exists
  432.    * 
  433.    * find a template during content-negotiation
  434.    * 
  435.    * @access public
  436.    * @param Mapper $request 
  437.    * @param string $extension 
  438.    * @return boolean 
  439.    */
  440.   
  441. function template_exists&$request$extension$template {
  442.   #if ($template == 'introspection') print 'ye';
  443.   #print "template_exists $template ".$extension."<br>";
  444.   
  445.   $view $request->get_template_path$extension$template );
  446.   
  447.   if file_exists$view ) )
  448.     return true;
  449.   
  450.   return false;
  451.   
  452. }
  453.  
  454.  
  455.   /**
  456.    * Form For
  457.    * 
  458.    * generate a form action string
  459.    * 
  460.    * @access public
  461.    * @param string $template 
  462.    * @todo implement
  463.    */
  464.  
  465. function form_for&$resource&$member$url {
  466.  
  467.   $request =request_object();
  468.  
  469.   if (is_object($resource)) {
  470.     
  471.     if isset$resource->table )) {
  472.       
  473.        // remote_form_for :entry, @new_entry, :url => entries_url(:project_id => @project.id )
  474.        
  475.        return "<form method=\"post\" >";
  476.       
  477.     }
  478.     
  479.   }
  480.   
  481. }
  482.  
  483.  
  484.   /**
  485.    * URL For
  486.    * 
  487.    * generate a url from a Route
  488.    * 
  489.    * @access public
  490.    * @param array $params 
  491.    * @param array $altparams 
  492.    */
  493.  
  494. function url_for$params$altparams NULL {
  495.  
  496.   $request =request_object();
  497.   
  498.   print $request->url_for$params$altparams );
  499.   
  500. }
  501.  
  502.  
  503.   /**
  504.    * Redirect To
  505.    * 
  506.    * redirect the browser via Routes
  507.    * 
  508.    * @access public
  509.    * @param string $template 
  510.    */
  511.  
  512. function redirect_to$param$altparam NULL {
  513.   
  514.   $request =request_object();
  515.   
  516.   $request->redirect_to$param$altparam );
  517.   
  518. }
  519.  
  520.  
  521.   /**
  522.    * Render
  523.    * 
  524.    * render template or blob using content-negotiation
  525.    * 
  526.    * @access public
  527.    * @param string $template 
  528.    */
  529.  
  530. function render$param$value {
  531.   
  532.   $db =db_object();
  533.   $response =response_object();
  534.   $request =request_object();
  535.   
  536.   if ($param == 'action' && !(strpos($value,"."=== false)) {
  537.     $spleet split("\.",$value);
  538.     $value $spleet[0];
  539.     $request->set_param'client_wants'$spleet[1);
  540.   }
  541.   
  542.   $request->set_param$param$value );
  543.   
  544.   $response->render$request );
  545.   
  546.   exit;
  547.   
  548. }
  549.  
  550.  
  551.   /**
  552.    * Render Partial
  553.    * 
  554.    * render a _template using content-negotiation
  555.    * 
  556.    * @access public
  557.    * @param string $template 
  558.    */
  559.  
  560. function render_partial$template {
  561.   
  562.   $request =request_object();
  563.   
  564.   $response =response_object();
  565.   
  566.   if (!(strpos($template,"."=== false)) {
  567.     $spleet split("\.",$template);
  568.     $template $spleet[0];
  569.     $request->set_param'client_wants'$spleet[1);
  570.   }
  571.   
  572.   $response->render_partial$request$template );
  573.   
  574. }
  575.  
  576.  
  577.   /**
  578.    * content_for_layout
  579.    * 
  580.    * render a _template using content-negotiation
  581.    * 
  582.    * @access public
  583.    * @param string $template 
  584.    */
  585.  
  586. function content_for_layout({
  587.   
  588.   $request =request_object();
  589.   
  590.   render_partial$request->action );
  591.   
  592. }
  593.  
  594.  
  595. function breadcrumbs({
  596.   $request =request_object();
  597.   echo $request->breadcrumbs();
  598. }
  599.  
  600.  
  601.   /**
  602.    * request_object
  603.    * 
  604.    * get global Mapper object
  605.    * 
  606.    * @access public
  607.    * @return Mapper 
  608.    */
  609.   
  610. function &request_object({
  611.   global $request;
  612.   return $request;
  613. }
  614.  
  615.  
  616. function content_types({
  617.   global $env;
  618.   $variants array(
  619.     array(
  620.       'id' => 'html',
  621.       'qs' => 1.000,
  622.       'type' => 'text/html',
  623.       'encoding' => null,
  624.       'charset' => 'iso-8859-1',
  625.       'language' => 'en',
  626.       'size' => 3000
  627.     )
  628.   );
  629.   if (isset($env['content_types']))
  630.     return $env['content_types'];
  631.   else
  632.     return $variants;
  633. }
  634.  
  635.  
  636.   /**
  637.    * response_object
  638.    * 
  639.    * get global View object
  640.    * 
  641.    * @access public
  642.    * @return View 
  643.    */
  644.   
  645. function &response_object({
  646.   global $response;
  647.   return $response;
  648. }
  649.  
  650.  
  651.   /**
  652.    * db_include
  653.    * 
  654.    * get global Mapper object
  655.    * 
  656.    * @access public
  657.    * @return string 
  658.    */
  659.  
  660. function db_include$file {
  661.   if (is_array($file)) {
  662.     foreach($file as $f)
  663.       require_once dbscript_path($f ".php";
  664.   else {
  665.     require_once dbscript_path($file ".php";
  666.   }  
  667. }
  668.  
  669.  
  670.   /**
  671.    * version
  672.    * 
  673.    * get dbscript version
  674.    * 
  675.    * @access public
  676.    * @return string 
  677.    */
  678.   
  679. function version({
  680.   global $version;
  681.   return $version;
  682. }
  683.  
  684.  
  685. function timestamp({
  686.   return date"Y-m-d H:i:s"strtotime"now" ));
  687. }
  688.  
  689.   /**
  690.    * dbsession_model
  691.    * 
  692.    * get global DbSession data model
  693.    * 
  694.    * @access public
  695.    * @return string 
  696.    */
  697.   
  698. function dbsession_model({
  699.   global $DbSession;
  700.   return $DbSession;
  701. }
  702.  
  703.  
  704.   /**
  705.    * magic_quotes_stripslashes_b
  706.    * 
  707.    * @access public
  708.    * @param array $a 
  709.    * @return array $r
  710.    */
  711.  
  712. function magic_quotes_stripslashes_b($a// Back
  713.    $r=array();
  714.    foreach ($a as $k=>$v{
  715.        if (!is_array($v)) $r[stripslashes($k)stripslashes($v);
  716.        else $r[stripslashes($k)magic_quotes_stripslashes_b($v);
  717.    }
  718.    return $r;
  719. }
  720.  
  721.  
  722.   /**
  723.    * magic_quotes_stripslashes
  724.    * 
  725.    * @access public
  726.    * @param array $a 
  727.    * @return array $r
  728.    */
  729.  
  730. function magic_quotes_stripslashes($a// Top
  731.    $r=array();
  732.    foreach ($a as $k=>$v{
  733.        if (!is_array($v)) $r[$kstripslashes($v);
  734.        else $r[$kmagic_quotes_stripslashes_b($v);
  735.    }
  736.    return $r;
  737. }
  738.  
  739.  
  740.   /**
  741.    * magic_quotes_stripquotes_b
  742.    * 
  743.    * @access public
  744.    * @param array $a 
  745.    * @return array $r
  746.    */
  747.  
  748. function magic_quotes_stripquotes_b($a// Back
  749.    $r=array();
  750.    foreach ($a as $k=>$v{
  751.        if (!is_array($v)) $r[str_replace('\'\'','\'',$k)str_replace('\'\'','\'',$v);
  752.        else $r[str_replace('\'\'','\'',$k)magic_quotes_stripquotes_b($v);
  753.    }
  754.    return $r;
  755. }
  756.  
  757.  
  758.   /**
  759.    * magic_quotes_stripquotes
  760.    * 
  761.    * @access public
  762.    * @param array $a 
  763.    * @return array $r
  764.    */
  765.  
  766. function magic_quotes_stripquotes($a// Top
  767.    $r=array();
  768.    foreach ($a as $k=>$v{
  769.      if (!is_array($v)) $r[$kstr_replace('\'\'','\'',$v);
  770.      else $r[$kmagic_quotes_stripquotes_b($v);
  771.    }
  772.    return $r;
  773. }
  774.  
  775.  
  776.   /**
  777.    * header_status
  778.    * 
  779.    * @access public
  780.    * @param string $status 
  781.    */
  782.    
  783. function header_status$status {
  784.   if substrphp_sapi_name()0== 'cgi' )
  785.     header'Status: ' $statusTRUE );
  786.   else
  787.     header$_SERVER['SERVER_PROTOCOL'.' '$status );
  788. }
  789.  
  790.   /**
  791.    * set_cookie
  792.    * 
  793.    * bake a fresh Cookie
  794.    * 
  795.    * @access public
  796.    * @param integer $userid 
  797.    */
  798.  
  799. function set_cookie($userid{
  800.   $cookie new Cookie();
  801.   $cookie->userid $userid;
  802.   $cookie->set();
  803. }
  804.  
  805.  
  806.   /**
  807.    * unset_cookie
  808.    * 
  809.    * throw the Cookie away? noo..
  810.    * 
  811.    * @access public
  812.    */
  813.  
  814. function unset_cookie({
  815.   $cookie new Cookie();
  816.   $cookie->logout();
  817. }
  818.  
  819.  
  820.   /**
  821.    * check_cookie
  822.    * 
  823.    * is the Cookie fit for consumption?
  824.    * 
  825.    * @access public
  826.    */
  827.  
  828. function check_cookie({
  829.   $cookie new Cookie();
  830.   if ($cookie->validate()) {
  831.     return true;
  832.   else {
  833.     return false;
  834.   }
  835. }
  836.   
  837.   
  838.   /**
  839.    * Vars
  840.    * 
  841.    * mutator function makes an array of local variables extractable
  842.    * 
  843.    * @access public
  844.    * @param string $var 
  845.    * @return string 
  846.    */
  847.   
  848.   function vars($varios$scope=false$prefix='unique'$suffix='value'{
  849.     if $scope )
  850.       $vals $scope;
  851.     else
  852.       $vals $GLOBALS;
  853.     $i 0;
  854.     foreach ($varios as $orig{
  855.       $var =$varios[$i];
  856.       $old $var;
  857.       $var $new $prefix rand($suffix;
  858.       $vname FALSE;
  859.       foreach$vals as $key => $val {
  860.         if $val === $new $vname $key;
  861.       }
  862.       $var $old;
  863.       if ($vname{
  864.         $varios[$vname$var;
  865.       }
  866.       $i++;
  867.     }
  868.     return $varios;
  869.   }
  870.  
  871.  
  872.   /**
  873.    * Randomstring
  874.    * 
  875.    * give it a string length and you will receive a random string!
  876.    * 
  877.    * @access public
  878.    * @param integer $len 
  879.    * @return string 
  880.    */
  881.  
  882. function randomstring($len{
  883.    srand(date("s"));
  884.    $i 0;
  885.    $str "";
  886.    while($i<$len)
  887.      {
  888.        $str.=chr((rand()%26)+97);
  889.        $i++;
  890.    }
  891.    return $str;
  892. }
  893.  
  894.  
  895. function getEtag($id{
  896.   return "ci-".dechex(crc32($id.microtime()));
  897. }
  898.  
  899.  
  900.   /**
  901.    * drop_array_element
  902.    * 
  903.    * returns the array minus the named element
  904.    * 
  905.    * @access public
  906.    * @param string $str 
  907.    */
  908.  
  909. function drop_array_element($array_with_elements$key_name{
  910.   $key_index array_keys(array_keys($array_with_elements)$key_name);
  911.   if (count($key_index!= ''{
  912.     array_splice($array_with_elements$key_index[0]1);
  913.   }
  914.   return $array_with_elements;
  915. }
  916.  
  917.  
  918.   /**
  919.    * dictionary_parse
  920.    * 
  921.    * Parses an xml dictionary.
  922.    * First argument is file name OR xml data.
  923.    * Second argument must be 'true' if the first arg is file name.
  924.    *
  925.    * <code>
  926.    * $array = dictionary_parse( $file_name, true );
  927.    * </code>
  928.    *
  929.    * @author Brian Hendrickson <brian@dbscript.net>
  930.    * @access public
  931.    * @param string $data 
  932.    * @return array 
  933.    */
  934.  
  935. function dictionary_parse$data /* parse XML dictionaries (lookup tables) */
  936.   $dict array();
  937.   $xml_parser xml_parser_create();
  938.   xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDING1);
  939.   xml_parser_set_option($xml_parserXML_OPTION_SKIP_WHITE0);
  940.   if (!$xml_parser{
  941.     trigger_error("error creating xml parser (xml_parser_create) in dictionary_parse"E_USER_ERROR );
  942.   }
  943.   $func_args func_get_args();
  944.   if (count($func_args1{
  945.     if ($func_args[1== true{
  946.       $data file_get_contents($data);
  947.       if (!$data{
  948.         trigger_error("error reading file contents in dictionary_parse, file name was: ".$func_args[0]E_USER_ERROR );
  949.       }
  950.     }
  951.   }
  952.   $int xml_parse_into_struct($xml_parser$data$values$tags);
  953.   if (!($int 0)) {
  954.     trigger_error("error parsing XML in dictionary_parse: ".xml_error_string(xml_get_error_code($xml_parser))E_USER_ERROR )." "$data;
  955.   }
  956.   foreach ($tags as $tagname=>$valuelocations{
  957.     if ($tagname == "KEY"{
  958.       $i 0;
  959.       foreach ($valuelocations as $valkey=>$valloc{
  960.         $map[$i$values[$valloc]['value'];
  961.         $dict[$values[$valloc]['value']] "";
  962.         $i++;
  963.       }
  964.     }
  965.     if ($tagname == "STRING"{
  966.       $i 0;
  967.       foreach ($valuelocations as $valkey=>$valloc{
  968.         if (isset($values[$valloc]['value'])) {
  969.           $dict[$map[$i]] $values[$valloc]['value'];
  970.         else {
  971.           $dict[$map[$i]] "";
  972.         }
  973.         $i++;
  974.       }
  975.     }
  976.   }
  977.   xml_parser_free($xml_parser);
  978.   return $dict;
  979. }
  980.  
  981.  
  982.   /**
  983.    * in_string
  984.    * 
  985.    * search for a substring
  986.    * 
  987.    * @access public
  988.    * @param string $needle 
  989.    * @param array $haystack 
  990.    * @param integer $insensitive 
  991.    * @return boolean 
  992.    */
  993.  
  994. function in_string($needle$haystack$insensitive 0{
  995.   if ($insensitive{
  996.     return (false !== stristr($haystack$needle)) true false;
  997.   else {
  998.     return (false !== strpos($haystack$needle))  true false;
  999.   }
  1000.   
  1001.  
  1002.   /**
  1003.    * get_script_name
  1004.    * 
  1005.    * the name of the current script
  1006.    * 
  1007.    * @access public
  1008.    * @return string 
  1009.    */
  1010.  
  1011. function get_script_name({
  1012.   if (!empty($_SERVER['PHP_SELF'])) {
  1013.     $strScript $_SERVER['PHP_SELF'];
  1014.   else if (!empty($_SERVER['SCRIPT_NAME'])) {
  1015.     $strScript @$_SERVER['SCRIPT_NAME'];
  1016.   else {
  1017.     trigger_error("error reading script name in get_script_name"E_USER_ERROR );
  1018.   }
  1019.   $intLastSlash strrpos($strScript"/");
  1020.   if (strrpos($strScript"\\")>$intLastSlash{
  1021.     $intLastSlash strrpos($strScript"\\");
  1022.   }
  1023.   return substr($strScript$intLastSlash+1strlen($strScript));
  1024. }
  1025.  
  1026.  
  1027. function dircopy($srcdir$dstdir$verbose false{
  1028.   $num 0;
  1029.   if(!is_dir($dstdir)) mkdir($dstdir);
  1030.   if($curdir opendir($srcdir)) {
  1031.    while($file readdir($curdir)) {
  1032.      if($file != '.' && $file != '..'{
  1033.        $srcfile $srcdir DIRECTORY_SEPARATOR $file;
  1034.        $dstfile $dstdir DIRECTORY_SEPARATOR $file;
  1035.        if(is_file($srcfile)) {
  1036.          if(is_file($dstfile)) $ow filemtime($srcfilefilemtime($dstfile)else $ow 1;
  1037.          if($ow 0{
  1038.            if($verboseecho "Copying '$srcfileto '$dstfile'...";
  1039.            if(copy($srcfile$dstfile)) {
  1040.              touch($dstfilefilemtime($srcfile))$num++;
  1041.              if($verboseecho "OK\n";
  1042.            }
  1043.            else echo "ErrorFile '$srcfilecould not be copied!\n";
  1044.          }                  
  1045.        }
  1046.        else if(is_dir($srcfile)) {
  1047.          $num += dircopy($srcfile$dstfile$verbose);
  1048.        }
  1049.      }
  1050.    }
  1051.    closedir($curdir);
  1052.   }
  1053.   return $num;
  1054. }
  1055.  
  1056.  
  1057.   /**
  1058.    * is_obj
  1059.    * 
  1060.    * more flexible is_object
  1061.    * 
  1062.    * @access public
  1063.    * @param object $object 
  1064.    * @param boolean $check 
  1065.    * @param boolean $strict 
  1066.    * @return boolean 
  1067.    */
  1068.  
  1069. function is_obj&$object$check=null$strict=true {
  1070.   if (is_object($object)) {
  1071.     if ($check == null{
  1072.       return true;
  1073.     else {
  1074.       $object_name get_class($object);
  1075.       return ($strict === true)
  1076.       $object_name == $check ):
  1077.       strtolower($object_name== strtolower($check) );
  1078.     }    
  1079.   else {
  1080.     return false;
  1081.   }
  1082. }
  1083.  
  1084.  
  1085. ?>

Documentation generated on Mon, 19 Feb 2007 10:25:06 -0800 by phpDocumentor 1.3.1