Exemplo n.º 1
0
    function toString()
    {
        $ret = '<' . $this->name;
        $attribute_string = array();
        foreach ($this->attributes as $key => $att) {
            $attribute_string[] = $key . '="' . $att . '"';
        }
        $attribute_string = implode($attribute_string, ' ');
        $ret .= ' ' . $attribute_string;
        if (count($this->sections) && is_array($this->sections)) {
            $ret .= '>
';
            foreach ($this->sections as $sect) {
                $type = ArrayUtility::getArrayValue($sect, 'type');
                $data = ArrayUtility::getArrayValue($sect, 'data');
                if ($type == 'cdata') {
                    $ret .= $data;
                } else {
                    $ret .= $data->toString();
                }
            }
            $ret .= '</' . $this->name . '>
';
        } else {
            $ret .= ' />
';
        }
        return $ret;
    }
Exemplo n.º 2
0
 /**
  *This method returns the controller from this url
  *
  *@param null
  *@return string The controller name
  */
 public function getController()
 {
     //break url string into array of substrings
     $array = explode("/", $this->url);
     //procede if parameters were found
     if (sizeof($array) > 0) {
         //remove empty elements
         $array = ArrayUtility::clean($array);
         //remove whitespace from array elements
         $array = ArrayUtility::trim($array);
         //check if array still contains elements
         if (sizeof($array) > 0) {
             //set the parameters array value
             $this->parameters = $array;
             //return the controller
             return $array[0];
         } else {
             //return null
             return null;
         }
     } else {
         //return null for controller
         return null;
     }
 }
 public function displaySiteTemplate($view = 'site_template')
 {
     ob_start();
     Display::displaySiteTemplate($view);
     $data = ob_get_clean();
     if ($this->ajaxResponse()) {
         echo $this->getAjaxResponse($view);
     } else {
         echo $data;
     }
     $view_cache = array();
     foreach ($this->views as $name => $view) {
         $view_cache[$name] = $view->toString();
     }
     $cache = ArrayUtility::merge($view_cache, $this->variables);
     $cache['chunks'] = $this->chunks;
     $cache['user'] = Application::user()->toString();
     $data = serialize($cache);
     file_put_contents($this->cachePath(), $data);
 }
 public function main()
 {
     if (NULL === $this->base) {
         throw new BuildException('You must specify the base file!');
     }
     if (NULL === $this->update) {
         throw new BuildException('You must specify the update file!');
     }
     $baseConfiguration = (array) (include $this->base->getAbsolutePath());
     $updateConfiguration = (array) (include $this->update->getAbsolutePath());
     $mergedConfiguration = ArrayUtility::array_merge_recursive_overrule($baseConfiguration, $updateConfiguration, FALSE, $this->includeEmptyValues);
     $configuration = new ConfigurationUtility($mergedConfiguration);
     $phpCode = $configuration->getLocalConfigurationArray();
     if (NULL === $this->fileWriter) {
         $this->addFileWriter();
     }
     $this->fileWriter->write($phpCode);
     $this->fileWriter->close();
 }
 /**
  * Takes a full URL, $url, possibly with a querystring and overlays the $getParams arrays values onto the quirystring, packs it all together and returns the URL again.
  * So basically it adds the parameters in $getParams to an existing URL, $url
  *
  * @param string $url URL string
  * @param array $getParams Array of key/value pairs for get parameters to add/overrule with. Can be multidimensional.
  * @return string Output URL with added getParams.
  */
 public static function linkThisUrl($url, array $getParams = array())
 {
     $parts = parse_url($url);
     $getP = array();
     if ($parts['query']) {
         parse_str($parts['query'], $getP);
     }
     ArrayUtility::mergeRecursiveWithOverrule($getP, $getParams);
     $uP = explode('?', $url);
     $params = self::implodeArrayForUrl('', $getP);
     $outurl = $uP[0] . ($params ? '?' . substr($params, 1) : '');
     return $outurl;
 }
 /**
  * Take an array of files from a form post and copy them to the required directory
  * @param file_vars  - the $_FILES superglobal from a form post
  * @return array     - an array of file names that were uploaded
  */
 function uploadFiles($file_vars = "")
 {
     $util = FileUtility::current();
     // Get the asset group for the file
     $disp = Display::current();
     $asset_group = $disp->getValue('asset_group') . "/";
     if (!is_dir(FileUtility::UPLOAD_DIR . $asset_group)) {
         mkdir(FileUtility::UPLOAD_DIR . $asset_group);
     }
     if (!$util->uploadDone()) {
         if (!$file_vars) {
             $file_vars = $_FILES;
         }
         $pathinfo = pathinfo($file_vars['media_url']['name']);
         $extension = '.' . $pathinfo['extension'];
         $filename = $pathinfo['filename'];
         $ret = array();
         if (!empty($file_vars) && count($file_vars)) {
             foreach ($file_vars as $label => $file) {
                 // Set the filename to an md5 #
                 //$original_name = $file['name'];
                 //$file['name'] = md5($file['name']);
                 $file['name'] = str_replace(' ', '-', $filename);
                 while (file_exists(FileUtility::UPLOAD_DIR . $asset_group . $file['name'] . $extension)) {
                     $file['name'] = md5($file['name']);
                 }
                 $file['name'] = $file['name'] . $extension;
                 $error = ArrayUtility::getArrayValue($file, "error");
                 if (!$error) {
                     if (move_uploaded_file($file['tmp_name'], FileUtility::UPLOAD_DIR . $asset_group . $file['name'])) {
                         $ret[$label] = ArrayUtility::getArrayValue($file, 'name');
                     } else {
                         throw new Exception("Error uploading file " . FileUtility::UPLOAD_DIR . $asset_group . $file['name']);
                     }
                 }
             }
         }
         $util->setUploadedFiles($ret);
     } else {
         $ret = $util->uploadedFiles();
     }
     return $ret;
 }
Exemplo n.º 7
0
 /**
  * The same as {@link completeKey()} but instead of using 
  * this object's field values, it gets the values from the
  * array passed to the first argument.
  * @param arr       - an associative array of key => value pairs
  * @param use_table - (boolean) true if the field name in the array passed
  *                    has the table name in it
  * @return string   - a complete key string (see completeKey for more details)
  * @see completeKey
  */
 public function completeKeyFromArray($arr, $use_table = true)
 {
     $key_fields = $this->primaryKeys();
     $to_concat = array();
     $invalid = false;
     foreach ($key_fields as $field) {
         if ($use_table) {
             $name = $this->tableName() . '.' . $field->name();
         } else {
             $name = $field->name();
         }
         $val = ArrayUtility::getArrayValue($arr, $name);
         if (!$val && !is_numeric($val) || $val == 'NULL') {
             //throw new Exception('Value for: '.$field->name().' not present in array. Here is debug info:<br /><br />'.print_r($arr).'<br /><br />Finished');
             $invalid = true;
         }
         $to_concat[] = $val;
     }
     if (!$invalid) {
         $ret = implode('-', $to_concat);
     } else {
         $ret = false;
     }
     return $ret;
 }
 function generateInputObjects()
 {
     $ret = array();
     $tabindex_count = 0;
     foreach ($this->standard_options as $name => $values) {
         if (isset($values['value'])) {
             $value = $values['value'];
         } else {
             $value = '';
         }
         if (isset($values['label'])) {
             $label = $values['label'];
         } else {
             $label = '';
         }
         if ($this->item_link_class) {
             $secondary_get_vars = ArrayUtility::merge($this->secondary_get_vars, array($name => $value));
             $href = Display::hrefString($this->item_link_class, $secondary_get_vars);
             $label = new FormLink($href, $label);
         } else {
             $label = new FormLabel($label);
         }
         switch ($this->type) {
             case ButtonGroup::CHECK:
                 $obj = new Checkbox($name, $this->class, '', $value, $label, '');
                 break;
             case ButtonGroup::RADIO:
                 $obj = new RadioButton($name, $this->class, '', $value, $label, '');
                 break;
             case ButtonGroup::NONE:
                 $obj = $label;
                 break;
         }
         if ($obj instanceof FormInput) {
             $obj->setTabindex($this->tabindex + $tabindex_count);
         }
         $tabindex_count++;
     }
     $selected = $this->selected;
     $primary_get_string = '';
     $check_name = $this->name;
     if (!$this->options) {
         $this->options = array();
     }
     foreach ($this->options as $opt) {
         $cur_check_name = $opt->formOptionName($check_name);
         $cur_check_value = $opt->formOptionValue();
         $cur_check_label = $opt->toString();
         $opt->formLinkGetVars($this->secondary_get_vars);
         $check_selected = ArrayUtility::arrayFromString($cur_check_name, false);
         if ($this->type == ButtonGroup::CHECK || $this->type == ButtonGroup::NONE) {
             $cur_check_name .= '[]';
         }
         if ($this->item_link_class) {
             $href = Display::hrefString($this->item_link_class, $this->secondary_get_vars);
             $label = new FormLink($href, $cur_check_label);
         } else {
             $label = new FormLabel($cur_check_label);
         }
         switch ($this->type) {
             case ButtonGroup::CHECK:
                 if (count($check_selected) && is_array($check_selected)) {
                     $sel_array = ArrayUtility::getArrayValueMulti($selected, $check_selected);
                     if (!is_array($sel_array)) {
                         $sel_array = array();
                     }
                 } else {
                     $sel_array = $selected;
                 }
                 if (in_array($cur_check_value, $sel_array)) {
                     $is_selected = true;
                 } else {
                     $is_selected = false;
                 }
                 $obj = new Checkbox($cur_check_name, $this->class, '', $cur_check_value, $label, $is_selected);
                 break;
             case ButtonGroup::RADIO:
                 if ($cur_check_value == $selected) {
                     $is_selected = true;
                 } else {
                     $is_selected = false;
                 }
                 $obj = new RadioButton($cur_check_name, $this->class, '', $cur_check_value, $label, $is_selected);
                 break;
             case ButtonGroup::NONE:
                 $obj = new HiddenLabel($cur_check_name, $cur_check_value, $label, '');
                 break;
         }
         if ($obj instanceof FormInput) {
             $obj->setTabindex($this->tabindex + $tabindex_count);
         }
         $ret[] = $obj;
         $tabindex_count++;
     }
     return $ret;
 }
Exemplo n.º 9
0
 /**
  * Returns the url to the handler with the give class name
  *
  * This will return _only_ the url to the main page with the class name of the given 
  * handler and any secondary get vars
  * @param class_name         - the class name to build a site function link for 
  * @param secondary_get_vars - an associative array where the key is
  *                             the name of the variable and the element
  *                             is the value for that variable to take
  *                             when passed into the GET method query 
  *                             string of a URL
  * @access public
  */
 function hrefString($class_name, $secondary_get_vars = '')
 {
     $var_string = '';
     if (is_array($secondary_get_vars) && count($secondary_get_vars)) {
         $var_string = '&' . ArrayUtility::keyValueConcat('=', '&', $secondary_get_vars);
     }
     $ret = Application::MAIN . '?h=' . $class_name . $var_string;
     return $ret;
 }
 /**
  * This function allows the easy conversion of a string in the form:
  * string1[string2][string3]...
  * into an array:
  * array('string1','string2','string3');
  * So far it's only used once (in form.class.inc) to split up the name
  * of a form element, but I thought I'd chuck it in here just in case...
  */
 function arrayFromString($string, $return_array = true)
 {
     $arr1 = '';
     if ($string) {
         /*check that it's the type of string we are looking for*/
         if (preg_match('/.*\\[.+\\]*/', $string)) {
             /*start by splitting the bulk of the string up*/
             $arr1 = explode('][', $string);
             //StringUtility::split($string,'][');
             /*check that this was a valid string*/
             if (is_array($arr1)) {
                 /*then catch the first ']'*/
                 $first = $arr1[0];
                 unset($arr1[0]);
                 $arr2 = explode('[', $first);
                 /*and put the arrays together*/
                 $arr1 = ArrayUtility::merge($arr2, $arr1);
                 /*now get rid of a trailing ']'*/
                 if (ArrayUtility::lastElement($arr1) == ']') {
                     unset($arr1[(int) (count($arr1) - 1)]);
                 }
                 /*and a trailing ']' if there is one*/
                 $arr1[count($arr1) - 1] = str_replace(']', '', ArrayUtility::lastElement($arr1));
             }
         } else {
             if ($return_array) {
                 $arr1 = array($string);
             }
         }
     }
     return $arr1;
 }
 /**
  * Retrieve some display information for this object
  * @param name   - the name of the value to be retrieved
  * @access protected
  */
 protected function displayInfoValue($name)
 {
     $ret = ArrayUtility::getArrayValue($this->display_info_values, $name);
     return $ret;
 }
Exemplo n.º 12
0
 protected function stopPatternNode($util)
 {
     $this->stop();
     array_pop($this->pattern_name_stack);
     $this->current_pattern_name = ArrayUtility::lastElement($this->pattern_name_stack);
 }
Exemplo n.º 13
0
 /**
  * Return an associative array where the key is the value of the 
  * database field corresponding to the 'key' argument, and the
  * value of each element is the value of the field corresponding
  * to the 'element' argument
  * @param key        - the name of the field in the database query
  *                     for which the value should be used as the key
  *                     in the associative array returned
  * @param element    - the name of the field in the database query
  *                     for which the value should be used as the
  *                     value in each element of the return array
  * @return array     - an associative array of database values
  * @access public
  */
 function assocArray($key, $element)
 {
     $this->check();
     $ret = array();
     while ($row = $this->next()) {
         $ret[ArrayUtility::getArrayValue($row, $key)] = ArrayUtility::getArrayValue($row, $element);
     }
     $this->reset();
     return $ret;
 }
 /**
  * Create a value string from the fields and values
  *
  * This is the heart of the InsertQuery and is the function 
  * that allows the user to have created 'jagged' value arrays,
  * that is, it is this function that eliminates the need for the 
  * user to add a value for each field simultaneously when building
  * the query.
  *
  * The value string is created by looping through the number of 
  * times corresponding to the field with the most values. If 
  * a field does not have a value for a particular element, then
  * @access private
  */
 function createValueString()
 {
     $value_array_counts = array_map('count', $this->values);
     sort($value_array_counts, SORT_NUMERIC);
     $max = ArrayUtility::lastElement($value_array_counts);
     $ret = array();
     for ($i = 0; $i < $max; $i++) {
         $vals = array();
         foreach ($this->fields as $name) {
             /*add the value for this field if it exists*/
             if ($new_value = ArrayUtility::getArrayValueMulti($this->values, array($name, $i))) {
                 $vals[] = $new_value;
             } else {
                 if ($this->mode == InsertQuery::EMPTY_VALUE_MODE) {
                     $vals[] = '\'\'';
                 } else {
                     if ($new_value = ArrayUtility::getArrayValueMulti($this->values, array($name, 0))) {
                         $vals[] = $new_value;
                     } else {
                         $vals[] = '\'\'';
                     }
                 }
             }
         }
         $ret[] = '(' . implode(',', $vals) . ')';
     }
     return implode(',', $ret);
 }
Exemplo n.º 15
0
 public static function search($term, $page = FALSE, $num_per_page = 10)
 {
     //IF WE ARE PAGINATING
     if ($page) {
         //NEED TO FIND OUT THE LAST TITLE PAGE AND THE TAG OFFSET
         $title_object = Logbook::getTitleSearchObjectForUser(Application::user(), $term, $page, $num_per_page);
         $title_count = $title_object->loadQuery()->getCount($title_object->tableName(), $title_object->primaryKeys());
         if ($title_page = Logbook::fetchPageFromObject($title_object, $page, $num_per_page)) {
             $title_objects = $title_page->objects();
         } else {
             $title_objects = array();
         }
         Logbook::current()->excludeTitleFromTagSearch();
         $tag_object = Logbook::getTagSearchObjectForUser(Application::user(), $term, $page, $num_per_page);
         $tag_count = $tag_object->loadQuery()->getCount($tag_object->tableName(), $tag_object->primaryKeys());
         $last_title_page = ceil($title_count / $num_per_page);
         $tag_offset = $title_count % $num_per_page;
         $item_count = $title_count + $tag_count;
         $page_count = ceil($item_count / $num_per_page);
         $tag_objects = array();
         //IF WE ARE ON THE LAST TITLE PAGE
         if ($page == $last_title_page) {
             $num_title = count($title_objects);
             //IF WE NEED TO GRAB SOME FROM THE FIRST PAGE OF THE TAG RESULTS
             if ($tag_offset) {
                 //GET THE FIRST PAGE OF TAG RESULTS
                 if ($tag_page = Logbook::doTagSearchForuser(Application::user(), $term, 1, $num_per_page)) {
                     $tag_objects = $tag_page->objects();
                 }
                 $num_tag = count($tag_objects);
                 //IF WE HAVE MORE DOCUMENTS ON THE NEXT PAGE THAN REQUIRED BY THE OFFSET
                 while ($num_title + $num_tag > $num_per_page && $num_tag) {
                     ArrayUtility::keySafePop($tag_objects);
                     $num_tag = count($tag_objects);
                 }
             }
         } else {
             if ($page < $last_title_page) {
                 //GET THE TITLE RESULTS, NO NEED FOR TAG RESULTS
                 //if($title_page   = Logbook::doTitleSearchForUser(Application::user(),$term,$page,$num_per_page))
                 //    $title_objects = $title_page->objects();
                 //WE ALREADY HAVE THE TITLE OBJECTS FOR THIS PAGE
             } else {
                 if ($page > $last_title_page || !$last_title_page) {
                     //WHICH PAGE OF THE TAG RESULTS ARE WE ON?
                     $tag_page_num = $page - $last_title_page;
                     //GET THE TAG RESULTS FOR THIS PAGE
                     if ($tag_page = Logbook::doTagSearchForUser(Application::user(), $term, $tag_page_num, $num_per_page)) {
                         $tag_objects = $tag_page->objects();
                     }
                     //IF WE USED UP SOME TAGS ON THE LAST TITLE PAGE, GET THE NEXT PAGE TO TOP US UP
                     if ($tag_offset) {
                         $tag_page_next = Logbook::doTagSearchForUser(Application::user(), $term, $tag_page_num + 1, $num_per_page);
                     } else {
                         $tag_page_next = FALSE;
                     }
                     //NOW SHIFT $tag_offset TIMES
                     for ($i = 0; $i < $tag_offset; $i++) {
                         if (count($tag_objects)) {
                             ArrayUtility::keySafeShift($tag_objects);
                         } else {
                             $i = $tag_offset;
                         }
                     }
                     $tag_page = new DataPage($tag_objects, 1, count($tag_objects), count($tag_objects));
                     //GRAB ANY MATCHING TAG DOCUMENTS
                     //IF WE NEED TO GRAB ANY FROM THE NEXT PAGE
                     if ($tag_page_next && count($tag_page->objects())) {
                         $new_tag_objects = Logbook::combineEntryResults($tag_page, $tag_page_next)->objects();
                         //IF WE HAVE MORE DOCUMENTS ON THE NEXT PAGE THAN REQUIRED BY THE OFFSET
                         while (count($new_tag_objects) > $num_per_page) {
                             ArrayUtility::keySafePop($new_tag_objects);
                         }
                         $tag_objects = $new_tag_objects;
                     } else {
                         if ($tag_page) {
                             $tag_objects = $tag_page->objects();
                         }
                     }
                 }
             }
         }
         $objects = Logbook::combineEntryResults($title_objects, $tag_objects)->objects();
         $ret = new DataPage($objects, $page, $num_per_page, $item_count);
     } else {
         //NOW GET THE TAG AND TITLE RESULTS FOR THE CURRENT PAGE
         $title_results = Logbook::doTitleSearchForUser(Application::user(), $term, $page, $num_per_page);
         $tag_results = Logbook::doTagSearchForUser(Application::user(), $term, $page, $num_per_page);
         //IF WE GOT TITLE RESULTS ONLY
         if ($title_results && !$tag_results) {
             $ret = $title_results;
         }
         //OTHERWISE IF WE GOT TAG RESULTS ONLY
         if (!$title_results && $tag_results) {
             $ret = $tag_results;
         } else {
             if ($title_results && $tag_results) {
                 $ret = Logbook::combineEntryResults($tag_results, $title_results);
             } else {
                 if (!$title_results && !$tag_results) {
                     $ret = new DataPage(array(), 1, $num_per_page, 0);
                 }
             }
         }
     }
     return $ret;
 }
Exemplo n.º 16
0
 function setSelected($key)
 {
     if ($key instanceof FormOption) {
         $key = strval($key->completeKey());
     } else {
         if (is_array($key) && ArrayUtility::firstElement($key) instanceof FormOption) {
             $newsel = array();
             foreach ($key as $opt) {
                 $newsel[] = strval($opt->completeKey());
             }
             $key = $newsel;
         } else {
             if (is_array($key)) {
                 $newsel = array();
                 foreach ($key as $val) {
                     $newsel[] = strval($val);
                 }
                 $key = $newsel;
             }
         }
     }
     if (is_array($key) && !$this->multiple) {
         $key = ArrayUtility::firstElement($key);
     }
     $this->selected = $key;
 }
 protected function getExportedLocalConfigurationArray()
 {
     $sortedConfiguration = ArrayUtility::sortByKeyRecursive($this->configuration);
     $renumberedArray = ArrayUtility::renumberKeysToAvoidLeapsIfKeysAreAllNumeric($sortedConfiguration);
     return ArrayUtility::arrayExport($renumberedArray);
 }
Exemplo n.º 18
0
 /**
  * Opposite of filter where properties match - rejects any items where properties do match
  * @param array $collection A collection of arrays. Any values that are not arrays will be automatically filtered
  *     out.
  * @param array $property_list An array of properties that must NOT match for the item to be included in the final
  *     list. Comparison is run using ArrayUtility::dotRead
  * @param string $match_type Any of the available MATCH_TYPE_* constants. Affects whether value comparisons are
  *     performed on exact data types.
  * @param bool $force_key_preservation Keys are preserved for assoc arrays only by default. Set to true to ALWAYS
  *     preserve keys
  * @return array
  */
 public static function filterWhereNot(array $collection, array $property_list, $match_type = self::MATCH_TYPE_LOOSE, $force_key_preservation = false)
 {
     $preserve_keys = $force_key_preservation || ArrayUtility::isAssoc($collection);
     $filtered = array_diff_key($collection, self::filterWhere($collection, $property_list, $match_type, true));
     return $preserve_keys ? $filtered : array_values($filtered);
 }
Exemplo n.º 19
0
 /**
  * Set the value of a field
  * @param name     - The the name of the field to initialise
  * @param value    - The value to be set
  * @param required - Optional argument specifiying whether or not 
  *                   value can be empty (default is false)
  * @access public
  */
 function initialiseFieldValue($field, $value)
 {
     if ($field->date()) {
         if (is_array($value)) {
             $day = ArrayUtility::getArrayValue($value, 'day');
             $month = ArrayUtility::getArrayValue($value, 'month');
             $year = ArrayUtility::getArrayValue($value, 'year');
             //$date = new DateUtility($day,$month,$year);
             $value = $year . '-' . $month . '-' . $day;
         } else {
             $value = '';
         }
     }
     $this->setFieldValue($field->name(), $value);
 }
Exemplo n.º 20
0
 /**
  * Return all parameters, $_POST,$_GET and user parameters
  * @return array - all parameters to the application
  * @access public
  * @static
  */
 public static function parameters()
 {
     $ret = Application::post();
     $ret = ArrayUtility::merge($ret, Application::get());
     $ret = ArrayUtility::merge($ret, Session::getRegistered('userParams'));
     return $ret;
 }
Exemplo n.º 21
0
 /**
  * Get the current session
  * @return Session - the current session
  * @access public
  * @static
  */
 public static function currentSession()
 {
     global $_SESSION;
     $session = ArrayUtility::getArrayValue($_SESSION, 'session');
     return $session;
 }
Exemplo n.º 22
0
{
    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
    return $value;
}
/* Make sure we aren't getting screwed over by magic quotes. */
if (get_magic_quotes_runtime()) {
    set_magic_quotes_runtime(0);
}
if (get_magic_quotes_gpc()) {
    include_once './lib/ArrayUtility.php';
    $_GET = array_map('stripslashes_deep', $_GET);
    $_POST = array_map('stripslashes_deep', $_POST);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
    $_GET = ArrayUtility::arrayMapKeys('stripslashes_deep', $_GET);
    $_POST = ArrayUtility::arrayMapKeys('stripslashes_deep', $_POST);
    $_REQUEST = ArrayUtility::arrayMapKeys('stripslashes_deep', $_REQUEST);
}
/* Objects can't be stored in the session if session.auto_start is enabled. */
if (ini_get('session.auto_start') !== '0' && ini_get('session.auto_start') !== 'Off') {
    die('CATS Error: session.auto_start must be set to 0 in php.ini.');
}
/* Proper extensions loaded?! */
if (!function_exists('mysql_connect') || !function_exists('session_start')) {
    die('CATS Error: All required PHP extensions are not loaded.');
}
/* Make sure we have a Session object stored in the user's session. */
if (!isset($_SESSION['CATS']) || empty($_SESSION['CATS'])) {
    $_SESSION['CATS'] = new CATSSession();
}
/* Start timer for measuring server response time. Displayed in footer. */
$_SESSION['CATS']->startTimer();
Exemplo n.º 23
0
 /**
  * Add options as an associative array
  */
 function addOptions($array)
 {
     $new_options = ArrayUtility::merge($this->options, $array);
     $this->setOptions($new_options);
 }
Exemplo n.º 24
0
 function setOptions($name, $options)
 {
     if ($obj = ArrayUtility::getArrayValue($this->inputs, $name)) {
         $obj->setOptions($options);
     } else {
         throw new Exception('No object with name: ' . $name . ' exists in form: ' . $this->name);
     }
 }
Exemplo n.º 25
0
 protected function _getCityStateZipArray($cityStateZipLine)
 {
     /* Safe default values. */
     $city = '';
     $state = '';
     $zip = '';
     /* Count the number of "words" / tokens in the line. */
     $tokenCount = StringUtility::countTokens(";, \t", $cityStateZipLine);
     if ($tokenCount < 2) {
         return array('city' => '', 'state' => '', 'zip' => '');
     }
     /* Split the string into an array of tokens. */
     $tokens = StringUtility::tokenize(";, \t", $cityStateZipLine);
     if ($tokenCount == 3) {
         $city = $tokens[0];
         $state = $tokens[1];
         $zip = $tokens[2];
     } else {
         /* If we have a known two- or three-word state, recognize it. */
         $twoWordState = ArrayUtility::implodeRange(' ', $tokens, $tokenCount - 3, $tokenCount - 2);
         $threeWordState = ArrayUtility::implodeRange(' ', $tokens, $tokenCount - 4, $tokenCount - 2);
         /* Known two- and three- word states / provinces. */
         $twoWordStates = array('New Hampshire', 'New York', 'New Jersey', 'New Mexico', 'North Dakota', 'North Carolina', 'South Dakota', 'South Carolina', 'West Virginia', 'Rhode Island', 'American Samoa', 'Puerto Rico', 'British Columbia', 'New Brunswick', 'Nova Scotia', 'Northwest Territories', 'South Dekota', 'North Dekota', 'Rode Island', 'New Hamshire');
         $threeWordStates = array('District Of Columbia', 'Prince Edward Island');
         /* Do we have a two-word state? */
         if (in_array(ucwords($twoWordState), $twoWordStates)) {
             /* Yes; assume that the last token is the zip code, the two
              * proceeding tokens before are part of the state, and all
              * other preceding tokens are part of the city.
              */
             $city = ArrayUtility::implodeRange(' ', $tokens, 0, $tokenCount - 4);
             $state = $twoWordState;
             $zip = $tokens[$tokenCount - 1];
         } else {
             if ($tokenCount > 4 && in_array(ucwords($threeWordState), $threeWordStates)) {
                 /* Yes; assume that the last token is the zip code, the
                  * three proceeding tokens before are part of the state,
                  * and all other preceding tokens are part of the city.
                  */
                 $city = ArrayUtility::implodeRange(' ', $tokens, 0, $tokenCount - 5);
                 $state = $threeWordState;
                 $zip = $tokens[$tokenCount - 1];
             } else {
                 /* Assume that the last token is the zip code, the token before
                  * the last token is the state, and all other preceding tokens
                  * are part of the city.
                  */
                 $city = ArrayUtility::implodeRange(' ', $tokens, 0, $tokenCount - 3);
                 $state = $tokens[$tokenCount - 2];
                 $zip = $tokens[$tokenCount - 1];
             }
         }
     }
     /* Regular expression to match US state abbreviations. */
     $USStateABBR = 'A[AEKLPRSZ]|C[AOT]|D[CE]|F[LM]|G[AU]|HI|I[ADLN]' . '|K[SY]|LA|M[ADEHINOPST]|N[CDEH]|N[JMVY]|O[HKR]|P[ARW]|RI' . '|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]';
     /* If the state is a United States Postal Service state abbreviation,
      * we can apply additional formatting.
      */
     if (!empty($state) && strlen($state) == 3 && preg_match('/^(' . $USStateABBR . ')\\.$/i', $state)) {
         $state = strtoupper(substr($state, 0, 2));
     }
     /* Common spelling corrections. */
     $search = array('South Dekota', 'North Dekota', 'Rode Island', 'New Hamshire');
     $replace = array('South Dakota', 'North Dakota', 'Rhode Island', 'New Hampshire');
     $state = str_replace($search, $replace, $state);
     // FIXME: Convert US state names to abbreviations.
     // FIXME: Proper title case.
     return array('city' => ucwords($city), 'state' => ucwords($state), 'zip' => strtoupper($zip));
 }
Exemplo n.º 26
0
 /**
  * Merge the configuration from the other Config
  * @param \Packfire\Config\ConfigInterface $config The configuration to merge in
  * @since 1.2.0
  */
 public function merge(ConfigInterface $config)
 {
     $this->data = ArrayUtility::mergeRecursiveDistinct($this->data, $config->get());
 }
Exemplo n.º 27
0
 public function appendArgument($script, $name, $data)
 {
     if (isset($this->register[$script])) {
         $params = $this->register[$script];
         if (isset($params['args'])) {
             $args = $params['args'];
         } else {
             $args = array();
         }
         //WHEN APPENDING THE ARGUMENT, CHECK IF IT EXISTS FIRST
         //IF IT DOESN'T, THEN SIMPLY ADD IT TO THE ARRAY. IF
         //IT DOES, THEN COMBINE IT WITH OTHER ARGUMENTS OF THE
         //SAME NAME AS AN ARRAY
         if (!isset($args[$name])) {
             $args[$name] = $data;
         } else {
             if (!is_array($args[$name])) {
                 $new_array = array($args[$name]);
                 if (is_array($data)) {
                     $args[$name] = ArrayUtility::merge($new_array, $data);
                 } else {
                     $new_array[] = $data;
                     $args[$name] = $new_array;
                 }
             } else {
                 $args[$name] = ArrayUtility::merge($args[$name], $data);
             }
         }
         $this->register[$script]['args'] = $args;
         if ($this->name) {
             $this->toString();
         }
     } else {
         throw new Exception('Cannot append arguments for ' . $script . ' because it is not in the register');
     }
 }
Exemplo n.º 28
0
 function testImplodeRange()
 {
     $pieces = array('Zero', 'One', 'Two', 'Three', 'Four', 'Five');
     $result = ArrayUtility::implodeRange(' ', $pieces, 0, 5);
     $this->assertIdentical($result, 'Zero One Two Three Four Five');
     $result = ArrayUtility::implodeRange(' ', $pieces, 0, 4);
     $this->assertIdentical($result, 'Zero One Two Three Four');
     $result = ArrayUtility::implodeRange(' ', $pieces, 1, 4);
     $this->assertIdentical($result, 'One Two Three Four');
     $result = ArrayUtility::implodeRange(' ', $pieces, 1, 3);
     $this->assertIdentical($result, 'One Two Three');
     $result = ArrayUtility::implodeRange(' ', $pieces, 2, 3);
     $this->assertIdentical($result, 'Two Three');
     $result = ArrayUtility::implodeRange(' ', $pieces, 2, 2);
     $this->assertIdentical($result, 'Two');
     $result = ArrayUtility::implodeRange(' ', $pieces, 0, 6);
     $this->assertIdentical($result, 'Zero One Two Three Four Five');
     $result = ArrayUtility::implodeRange(' ', $pieces, -500, 500);
     $this->assertIdentical($result, 'Zero One Two Three Four Five');
     $result = ArrayUtility::implodeRange(', ', $pieces, -500, 500);
     $this->assertIdentical($result, 'Zero, One, Two, Three, Four, Five');
 }
Exemplo n.º 29
0
 /**
  * Return the value of a particular attribute for the current element
  */
 function attributeValue($att_name, $optional = '')
 {
     if (!$optional) {
         $optional = XmlUtility::REQUIRED;
     }
     $ret = '';
     if (array_key_exists($att_name, $this->cur_attributes)) {
         $ret = ArrayUtility::getArrayValue($this->cur_attributes, $att_name);
     } else {
         if ($optional == XmlUtility::REQUIRED) {
             $this->xmlErrorMessage('Tried to access non-existent attribute: ' . $att_name . ', in element: ' . $this->currentElementName());
         }
     }
     return $ret;
 }