Source for file FilterFunctions.php

Documentation is available at FilterFunctions.php

  1. <?php
  2. /**
  3. * List of functions used to evaluate the FILTER statements in
  4. * SPARQL queries.
  5. *
  6. @package sparql
  7. @author   Tobias Gauss <tobias.gauss@web.de>
  8. @version     $Id: fsource_sparql__sparqlFilterFunctions.php.html 443 2007-06-01 16:25:38Z cax $
  9. *
  10. */
  11.  
  12.  
  13.  
  14.  
  15. /**
  16. * Evaluates the regex() function. Returns true if the regex is matched false if not.
  17. *
  18. @param String  $string   the string which has to be evaluated
  19. @param String  $pattern  the regex pattern
  20. @param String  $flags    additional flags like "i"
  21. @return boolean 
  22. */
  23. function regex($string,$pattern,$flags ''){
  24.     $string trim($string);
  25.     $pattern trim($pattern);
  26.     if(strpos($string,"str_")===0){
  27.         $string substr($string,4);
  28.         $pattern substr($pattern,4);
  29.         $flags substr($flags,4);
  30.     }else{
  31.         return false;
  32.     }
  33.     if(preg_match('/'.$pattern.'/'.$flags,$string))
  34.     return true;
  35.     else
  36.     return false;
  37. }
  38.  
  39. /**
  40. * Evaluates the dateTime() function.Tries to convert a date string into
  41. * a unix timestamp.
  42. *
  43. @param  String $string the date string
  44. @return integer        the corresponding unix timestamp
  45. */
  46. function dateTime($string){
  47.     $string trim($string);
  48.     if(strpos($string,"str_")===0)
  49.     $string substr($string,4);
  50.  
  51.     $time strtotime($string);
  52.     if($time == -1)
  53.     return $string;
  54.     else
  55.     return $time;
  56. }
  57.  
  58.  
  59. /**
  60. * Evaluates the langMatches() function. Return true if the lang tag matches false if not.
  61. *
  62. @param String $lang_range the string.
  63. @param String $lang_tag the regex pattern
  64. @return boolean 
  65. */
  66. function langMatches($lang_range,$lang_tag){
  67.  
  68.     if($lang_range == null)
  69.     return false;
  70.  
  71.     if(strpos($lang_range,"str_")===0)
  72.     $lang_range substr($lang_range,4);
  73.     if(strpos($lang_tag,"str_")===0)
  74.     $lang_tag substr($lang_tag,4);
  75.  
  76.     if(strtolower($lang_range== strtolower($lang_tag))
  77.     return true;
  78.     $tags =  preg_match_all("/[^\-\s].[^\-\s]*/",$lang_range,$hits);
  79.     if($tags){
  80.         if($lang_tag == '*')
  81.         return true;
  82.         foreach($hits[0as $tag){
  83.             if(strtolower($tag== strtolower($lang_tag))
  84.             return true;
  85.         }
  86.         return false;
  87.     }else{
  88.         return false;
  89.     }
  90. }
  91.  
  92. /**
  93. * Evaluates the str() function. Returns the string representation of a
  94. * variable or RDF term.
  95. *
  96. @param  String $string the string
  97. @return boolean 
  98. */
  99. function str($string){
  100.     $str preg_match("/\".[^\"]*\"|\'.[^\']*\'/",$string,$hits);
  101.     if($str != 0){
  102.         return "str_".$hits[0];
  103.     }else{
  104.         if(strpos($string,"str_")===0){
  105.             return $string;
  106.         }else{
  107.             if(strpos($string,"uri_")===0)
  108.                 return "str_".substr($string,4);
  109.             if(strpos($string,'<')==0)
  110.                 return "str_".substr($string,1,-1);
  111.         }
  112.     }
  113.     return false;
  114. }
  115.  
  116. /**
  117. * Evaluates the lang() function. Returns lang tag of a Literal.
  118. *
  119. @param  String $string the string.
  120. @return String the lang tag or false if there is no language tag.
  121. */
  122. function lang($string){
  123.     $str preg_match("/\".[^\"]*\"@(.[^\s]*)|\'.[^\']*\'@(.[^\s]*)/",$string,$hits);
  124.     if($str){
  125.         if($hits[1!= null)
  126.         return $hits[1];
  127.         else
  128.         return $hits[2];
  129.     }else{
  130.         return false;
  131.     }
  132. }
  133.  
  134.  
  135.  
  136. ?>

Documentation generated on Fri, 1 Jun 2007 16:49:03 +0200 by phpDocumentor 1.3.2