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

Source for file inc.php

Documentation is available at inc.php

  1. <?php
  2. /**
  3.  * Program Initilization and base functions
  4.  * 
  5.  * This is the initilization script.
  6.  *
  7.  * @author Eric Lamb <eric@ericlamb.net>
  8.  * @version .01
  9.  * @link http://blog.ericlamb.net/
  10.  * @copyright 2008 Eric Lamb
  11.  * @package    StupidGrep
  12.  * @filesource
  13.  */
  14.  
  15. /**
  16.  * All passed paramaters
  17.  * @global array    $input 
  18.  */
  19. $input arguments($argv);
  20.  
  21. /**
  22.  * Include DB class
  23.  */
  24. include 'includes/classes/mySQL.class.php';
  25.  
  26. /**
  27.  * Include DB connection values
  28.  */
  29. include 'includes/connect.php';
  30.  
  31. /**
  32.  * Check if we're dealing with 0 paramaters or help
  33.  */
  34. if(isset($argv[1]&& in_array($argv[1]array('--help''-h''-?'))) {
  35.     display_help();
  36.     exit;
  37. }
  38.  
  39. /**
  40.  * Displays the CLI help mode.
  41.  *
  42.  * @param   string    $parse    The source directory to parse
  43.  * @return  bool 
  44.  */
  45. function display_help(){
  46.     global $argv;
  47. ?>
  48. Takes a given string (--search) and searches the 
  49. Stupid Deal of the Day for a match. If a match is 
  50. found an email is sent to (--email)
  51.  
  52.  Usage: 
  53.  <?php echo $argv[0]?> <option>
  54.  
  55.  <option> With the --help, -help, -h,
  56.  or -? options, you can get this help.
  57.  
  58.  Example:
  59.  <?php echo $argv[0]?> --search="term1" --email="foo@bar.com"
  60. <?
  61. }
  62.  
  63. /**
  64.  * Returns the passed array and createds the paramater array
  65.  *
  66.  * @param   array    $argv    Passed values
  67.  * @return  array 
  68.  */
  69. function arguments($argv{
  70.    $_ARG array();
  71.    foreach ($argv as $arg{
  72.        if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#'$arg$matches)) {
  73.            $key $matches[1];
  74.            switch ($matches[2]{
  75.                case '':
  76.                case 'true':
  77.                $arg true;
  78.                break;
  79.                case 'false':
  80.                $arg false;
  81.                break;
  82.                default:
  83.                $arg $matches[2];
  84.            }
  85.            
  86.            /* make unix like -afd == -a -f -d */            
  87.            if(preg_match("/^-([a-zA-Z0-9]+)/"$matches[0]$match)) {
  88.                $string $match[1];
  89.                for($i=0strlen($string$i$i++{
  90.                 $_ARG[$string[$i]] true;
  91.                }
  92.            else {
  93.                $_ARG[$key$arg
  94.            }            
  95.        else {
  96.            $_ARG['input'][$arg;
  97.        }        
  98.    }
  99.    return $_ARG
  100. }
  101.  
  102. /**
  103.  * Validates an string to ensure it matches a valid email address syntax
  104.  *
  105.  * @param   string    $email 
  106.  * @return  array 
  107.  */
  108. function  checkEmail_basic($email{
  109.     if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" $email)) {    
  110.         return false;
  111.     }
  112.     return true;
  113. }
  114. ?>

Documentation generated on Thu, 01 Jan 2009 14:04:18 -0800 by phpDocumentor 1.4.2