/** * method used to return one of the validation methods * * @param string $obj -- the name of the validation object -- Token, Cookie, etc. * @param Array $data -- the data to be validated * @access public * @static * @throws Exception -- if the validation type does not exist * @return boolean -- the result of the validation */ public static function get($obj, array $data = array()) { $validator = 'System_Request_Validation_' . ucfirst(strtolower($obj)); if (class_exists($validator)) { return System_Registry_Storage::get($validator)->reset()->setValue($data)->validate(); } else { throw new Exception('The validation method that you are attempting to use -- ' . $obj . ' -- does not exist. Check the router settings.'); } }
/** * adds a session token to the stack * will automatically pop the oldest token off of the stack * * @param String $id Form id to be assigned to the token * @throws System_Request_Exception if the id is not set * @static * @return string */ public static function register($id) { if (!isset($id)) { throw new System_Request_Exception('You must provide an ID to be used.'); } self::checkStack(); $token = System_Registry_Storage::get('Utility_String_Root')->randomString(15)->get(); $_SESSION['request']['token'][$id] = array('value' => $token, 'time' => time()); return $token; }
/** * This method dispatches the current call * * @access public * @return null */ public function dispatch() { try { echo System_Request_Call::url(false, array(), true); } catch (Exception $e) { if (System_Registry_Configuration::environment() === 'development') { echo System_Registry_Storage::get('System_View_Load')->parse('../System/Exception/Page.phtml', array('e' => $e)); } else { System_Request_Command_Abstract::setResponseStatus(401); } } }
/** * method used to send emails * * @access public * @return */ public function send() { $this->build(); $date_created = System_Registry_Storage::get('System_Utility_Date')->setValue(time())->mysqlDateTime()->get(); $count = 0; foreach ($this->_email_list as $data) { $values = array('to' => $data['to'], 'from' => $this->_from, 'subject' => $this->_subject, 'content' => $data['content'], 'date_created' => $date_created); $email = new Object_Email_Model(); $work = $email->setValue($values)->registerNew(); $count++; } if ($count) { $this->_status = $work->commit(); } return $this; }
/** * sets the values for the fields property array * checks to see if the key exists in either the virtual data frame property (_v_data_frame) if set, or the default data frame (_data_frame) * does an access level set if the key has set restrictions * validates the input * * @param array, $val_array array of key value pairs to be set and validated against * @param boolean, $mysql_variable_check flag to tell the validator to run the variables through the mysqlVariable validation method. Defaults to false * @param boolean $validate_input Flag that tells the method to validate the input or not * @access public * @return Object, instance of the class */ public function setValue(array $val_array = array(), $mysql_variable_check = false, $validate_input = true) { $frame = pick($this->_v_data_frame, $this->_data_frame); $validation_errors = false; foreach ($val_array as $key => $val) { $run = true; /** * check to see if the key is in the _frame property array * if it is, check the _set_restrictions property array */ if (array_key_exists($key, $frame)) { if (isset($frame[$key]['set'])) { if (!System_Security_Access::andThis($this->_data_frame[$key]['set'])) { $run = false; } } /** * if the user can add the value the the _fields property * validate the data and if it is valid, add it * else, skip it */ if ($run) { /** * get the rules and processed valued based on the type definition * if mysql_variable_check is set, redefine the rules to check against the mysqlVariable method */ $rules = $mysql_variable_check ? array('type' => 'mysqlVariable') : $frame[$key]; $value = $this->getProcessValue($frame[$key]['type'], $val); /** * if the rules is an array and is greater than zero * validate the values against the rules * if there are validation errors, set run to false */ if ($validate_input && is_array($rules) && count($rules)) { $error = $this->validate($key, $value, $rules); $run = $error ? false : true; if ($error) { $validation_errors = true; $this->_errors = true; } } if ($run) { /** * HACK - encodes the password field */ if ($frame[$key]['type'] == 'password') { $value = System_Registry_Storage::get('System_Utility_String')->setValue($value)->encodePassword()->get(); } $this->_fields[$key] = $value; } } } } return $this; }
/** * Utility method used to parse an phtml file * * @param string $path -- the path to the phtml file including the file extension * @param array $arguments -- an associative array used to pass variable to the phtml file * @access protected * @return string */ protected function parseHtml($path, array $arguments = array()) { return System_Registry_Storage::get('System_View_Load')->parse($path, $arguments); }
/** * orders the results based on the score * * @access private * @return Object System_Model_Reduce */ private function orderResults() { $this->_sorted_results = System_Registry_Storage::get('Utility_Array_SubKeySort')->setValue(array('array' => $this->_sorted_results, 'key' => 'score'))->sort('desc'); return $this; }
/** * converts a key:value pair from a string to an array that will be accepted by Model_New * * @access public * @return System_Utility_String */ public function keyValToObject($key, $value) { $this->keyValToArray(':'); $array = System_Registry_Storage::get('Utility_Array_Base')->setValue($this->_processed)->emptyModel($key, $value)->get(); $this->_processed = new System_Model_New($array); return $this; }
/** * Begins the search * * @access public * @return System_Search_Controller */ public function start() { $this->_search_run = true; $array_obj = System_Registry_Storage::get('Utility_Array_Base'); foreach ($this->_search_terms_grouped as $key => $grouping) { if (count($grouping)) { foreach ($grouping as $group) { preg_match_all('/' . $group . '/', $this->_search_haystack_cleaned, $matches); /** * remove the empty strings from the $matches array */ $matches_array = $array_obj->reset()->setValue($matches[0])->removeEmptyStringVals()->get(); $this->_search_terms_found[$key] = count($matches_array); } } } return $this; }
/** * method used to convert the data to html * this automatically puts the content in the frame * * @access public * @return Array */ public function processResponse() { return System_Registry_Storage::get('System_View_Load')->parse('Template/Frame.phtml'); }
/** * method used to build each message * TODO: allow for different sending types. Currently it only allows for individual emails, not mass mailings * * @access protected * @return System_Utility_Mail_Abstract */ protected function build() { $vals = array(); $count = count($this->_to); $unique = false; /** * define the content * if the content property is set, use it * if the template_data is an array with a count greater than zero, create a unique template for each email * else, parse the template once and use it throughout */ if ((bool) $this->_content) { $content = $this->_content; } elseif (count($this->_template_data)) { if (isset($this->_template_data[0]) && is_array($this->_template_data[0])) { $unique = true; } else { $content = System_Registry_Storage::get('System_View_Load')->parse($this->_template, $this->_template_data); } } else { $content = System_Registry_Storage::get('System_View_Load')->parse($this->_template); } for ($i = 0; $i < $count; $i++) { if ($unique) { $template_data = isset($this->_template_data[$i]) ? $this->_template_data[$i] : $this->_template_data; $content = System_Registry_Storage::get('System_View_Load')->parse($this->_template, $template_data); } /** * TODO: figure out a way to make the subject dynamic */ $subject = (bool) $this->_subject ? $this->_subject : $this->_subject; $vals[] = array('to' => $this->_to[$i], 'content' => $content, 'subject' => $subject); } $this->_email_list = $vals; return $this; }
/** * sets the request token * * @return string */ function requestToken() { $_SESSION['request']['token'] = $request_token = System_Registry_Storage::get('Utility_String_Root')->randomString(15)->get(); return $request_token; }
/** * copies the file and gives it a random name. This returns a new instance of System_Utility_File with the copied file as the focus * This method does not allow for moving of the file * * @access public * @return System_Utility_File|boolean */ public function copy() { $padding = System_Registry_Storage::get('System_Utility_String')->randomString()->get(); $copy = $this->getFilePath() . '/' . $this->getFileNameBody() . $padding . '.' . $this->getFileExtension(); $result = false; if (copy($this->_value, $copy)) { $result = new System_Utility_File($copy); } return $result; }