예제 #1
0
 public function __construct($config = array())
 {
     // Set the config
     $this->config = $config;
     // Set a filename, if we don't have one
     if (str::e($this->config['filename'])) {
         $this->config['filename'] = date("Y-m-d_g-ia");
     }
     // Build driver class
     $driver = "Export_Driver_" . trim(strtoupper($config['driver']));
     // Load the driver
     if (!Eight::auto_load($driver)) {
         throw new Export_Exception('export.driver_not_supported', $config['driver']);
     }
     // Initialize the driver
     $this->driver = new $driver($this->config);
     // Validate the driver
     if (!$this->driver instanceof Export_Driver) {
         throw new Export_Exception('export.driver_not_supported', 'Export drivers must use the Export_Driver interface.');
     }
     // Set the columns
     if (!arr::e($this->config['columns'])) {
         $this->driver->set_columns($this->config['columns']);
     }
 }
예제 #2
0
 public function valid()
 {
     if (isset($this->data[$this->primary_key]) && !str::e($this->data[$this->primary_key])) {
         $this->loaded = TRUE;
         return TRUE;
     }
     return $this->loaded;
 }
예제 #3
0
파일: csv.php 프로젝트: enormego/EightPHP
 public function __construct($config = array())
 {
     if (!str::e($config['delimiter'])) {
         $this->delimiter = $config['delimiter'];
     }
     if (!str::e($config['enclosure'])) {
         $this->enclosure = $config['enclosure'];
     }
     $this->tmp_fname = tempnam(sys_get_temp_dir(), "export");
     $this->tmp_fhandle = fopen($this->tmp_fname, 'rw+');
 }
예제 #4
0
 public static function logged_in()
 {
     if (str::e($_COOKIE[Eight::config('facebook.api_key') . '_user'])) {
         return FALSE;
     } else {
         if (intval(Eight::instance()->fb->user) > 0) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
 }
예제 #5
0
파일: cli.php 프로젝트: enormego/EightPHP
 /**
  * Finds out how many of the current script are running
  */
 public static function how_many_of_me($cmd = NULL)
 {
     // Get the launch command
     if (str::e($cmd) && !str::e($cmd = self::launch_cmd())) {
         return FALSE;
     }
     // Find all the processes with the same args
     $procs = shell_exec('ps -A -o pid,args | grep "' . $cmd . '$"');
     $procs = explode("\n", $procs);
     if (is_array($procs)) {
         foreach ($procs as $k => $v) {
             if (str::e($v)) {
                 unset($procs[$k]);
             }
         }
         return count($procs);
     } else {
         return FALSE;
     }
 }
예제 #6
0
파일: auth.php 프로젝트: enormego/EightPHP
 /**
  * Verifies the given password against the known hash that's stored.
  * 
  * @param	string	Password in plaintext
  * @param	string	Hashed password
  * @return	boolean
  */
 public function verify($password, $hash)
 {
     if (str::e($password)) {
         return FALSE;
     }
     if (str::e($hash)) {
         return FALSE;
     }
     $valid = FALSE;
     // Check password depending on hash_method
     if ($this->config['hash_method'] == 'bcrypt') {
         $valid = $this->bcrypt->verify($password, $hash) === TRUE;
     } else {
         $valid = $this->hash($password) === $hash;
     }
     return $valid;
 }
예제 #7
0
 /**
  * Finds a token for the given user
  * 
  * 		Accepts a user ID or user object
  */
 public static function find_token_for_user($user)
 {
     if (is_null($user) or str::e($user)) {
         return FALSE;
     }
     if (!is_object($user)) {
         $user = new Model_User($user);
     }
     $data = self::db()->where('user_token_user_id', $user->id)->get('user_tokens')->row_array();
     if ($data === FALSE) {
         return FALSE;
     } else {
         $token = new Model_UserToken(NULL, TRUE);
         $token->set($data);
         return $token;
     }
 }
예제 #8
0
 /**
  * Method compiled_select_query
  *  Compiles and returns an SQL select statement
  * 
  * Parameters:
  *  table - table to select from, optional (can be set via from())
  *  reset - if true, resets the select statement
  * 
  * Returns:
  *  An SQL Statement
  */
 public function compiled_select_query($table = '', $reset = NO)
 {
     if (!str::e($table)) {
         $this->from($table);
     }
     $sql = $this->driver->compile_select(get_object_vars($this));
     if ($reset) {
         $this->reset_select();
     }
     return $sql;
 }
예제 #9
0
파일: zip.php 프로젝트: enormego/EightPHP
 public static function is_valid($src_file)
 {
     $output = trim(shell_exec('unzip -T "' . $src_file . '"'));
     return str::e($output);
 }
예제 #10
0
파일: xml.php 프로젝트: enormego/EightPHP
 public function __construct($config = array())
 {
     if (!str::e($config['container'])) {
         $this->container = $config['container'];
     }
 }
예제 #11
0
 /**
  * Populates the cURL handle with proxy info
  * 
  * @param	resources	curl handle
  */
 protected function populate_proxy($ch)
 {
     if (!str::e(self::$proxy_host) && self::$proxy_port > 0) {
         curl_setopt($ch, CURLOPT_PROXY, self::$proxy_host . ':' . self::$proxy_port);
         curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
         if (!str::e(self::$proxy_user) && !str::e(self::$proxy_pass)) {
             curl_setopt($ch, CURLOPT_PROXYUSERPWD, self::$proxy_user . ':' . self::$proxy_pass);
         }
     }
 }
예제 #12
0
 <?php 
    echo $input->class;
    ?>
" <?php 
    echo str::e($input->style) ? '' : "style='" . $input->style . "'";
    ?>
>
	<table class="group <?php 
    echo $input->class;
    ?>
">
		<?php 
    if (isset($input)) {
        ?>
			<?php 
        if (!str::e($input->label())) {
            ?>
			<tr>
				<th colspan="<?php 
            echo count($inputs);
            ?>
">
					<?php 
            echo $input->label();
            ?>
				</th>
			</tr>
			<?php 
        }
        ?>
		<?php 
예제 #13
0
 /**
  * Returns the salted key, if necessary
  *
  * @param   string  salt to use with key
  * @return  string  salted key, if salt provided, standard key otherwise
  */
 private function salted_key($salt = NULL)
 {
     $key = $this->config['key'];
     if (is_null($salt) || !is_string($salt) || str::e($salt)) {
         return $key;
     }
     // Find the max length of the key, based on cipher and mode
     $size = mcrypt_get_key_size($this->config['cipher'], $this->config['mode']);
     // If salt is too big, we'll just use the salt as the key, since we can't salt the key
     if (strlen($salt) >= $size) {
         return substr($salt, 0, $size);
     }
     // If the salt+key is too long, we'll pad the beginning of the salt with as much of the key as possible
     if (strlen($key) + strlen($salt) > $size) {
         return substr($key, 0, $size - strlen($salt)) . $salt;
     }
     // Append the salt to the key and return
     return $key . $salt;
 }
예제 #14
0
 /**
  * Creates the form HTML
  *
  * @param   string   form view template name
  * @param   boolean  use a custom view
  * @return  string
  */
 public function render($template = 'formation/wrapper', $custom = NO)
 {
     // Load template
     $form = new View($template);
     if ($custom) {
         // Using a custom view
         $data = array();
         foreach (array_merge($this->hidden, $this->inputs) as $input) {
             $data[$input->name] = $input;
             // Groups will never have errors, so skip them
             if ($input instanceof Formation_Group) {
                 continue;
             }
             // Compile the error messages for this input
             $messages = '';
             $errors = $input->error_messages();
             if (is_array($errors) and !empty($errors)) {
                 foreach ($errors as $error) {
                     // Replace the message with the error in the html error string
                     $messages .= str_replace('{message}', $error, $this->error_format) . $this->newline_char;
                 }
             }
             $data[$input->name . '_errors'] = $messages;
         }
         $form->set($data);
     } else {
         // Using a template view
         $form->set($this->template);
         $hidden = array();
         if (!empty($this->hidden)) {
             foreach ($this->hidden as $input) {
                 $hidden[$input->name] = $input->value;
             }
         }
         $form_type = 'open';
         // See if we need a multipart form
         foreach ($this->inputs as $input) {
             if ($input instanceof Formation_Upload) {
                 $form_type = 'open_multipart';
             }
         }
         // Tack on the "formation" class
         $space = str::e($this->attr['class']) ? '' : ' ';
         $this->attr['class'] = 'formation' . $space . $this->attr['class'];
         // Set the form open and close
         $form->open = form::$form_type(arr::remove('action', $this->attr), $this->attr, $hidden);
         $form->close = form::close();
         // Set the inputs
         $form->inputs = $this->inputs;
     }
     return $form;
 }
예제 #15
0
파일: input.php 프로젝트: enormego/EightPHP
 /**
  * Validate this input based on the set rules.
  *
  * @return  bool
  */
 public function validate()
 {
     // Validation has already run
     if (is_bool($this->is_valid)) {
         return $this->is_valid;
     }
     // No data to validate
     if ($this->input_value() == NO) {
         return $this->is_valid = NO;
     }
     // Load the submitted value
     $this->load_value();
     // No rules to validate
     if (count($this->rules) == 0 and count($this->matches) == 0 and count($this->callbacks) == 0) {
         return $this->is_valid = YES;
     }
     if (!empty($this->rules)) {
         foreach ($this->rules as $rule) {
             if (str::e($rule)) {
                 continue;
             }
             if (($offset = strpos($rule, '[')) !== NO) {
                 // Get the args
                 $args = preg_split('/, ?/', trim(substr($rule, $offset), '[]'));
                 // Remove the args from the rule
                 $rule = substr($rule, 0, $offset);
             }
             if (is_callable($rule)) {
                 $this->value = $rule($this->value);
             } elseif (substr($rule, 0, 6) === 'valid_' and method_exists('valid', substr($rule, 6))) {
                 $func = substr($rule, 6);
                 if ($this->value and !valid::$func($this->value)) {
                     $this->errors[$rule] = YES;
                 }
             } elseif (str::starts_with($rule, "callback_")) {
                 if (method_exists(Eight::instance(), substr($rule, 9))) {
                     if (is_array($args)) {
                         $new_args = array_merge(array(&$this), $args);
                     } else {
                         $new_args = array(&$this);
                     }
                     call_user_func_array(array(Eight::instance(), substr($rule, 9)), $new_args);
                 } else {
                     throw new Eight_Exception('validation.invalid_callback', substr($rule, 9));
                 }
             } elseif (method_exists($this, 'rule_' . $rule)) {
                 // The rule function is always prefixed with rule_
                 $rule = 'rule_' . $rule;
                 if (isset($args)) {
                     // Manually call up to 2 args for speed
                     switch (count($args)) {
                         case 1:
                             $this->{$rule}($args[0]);
                             break;
                         case 2:
                             $this->{$rule}($args[0], $args[1]);
                             break;
                         default:
                             call_user_func_array(array($this, $rule), $args);
                             break;
                     }
                 } else {
                     // Just call the rule
                     $this->{$rule}();
                 }
                 // Prevent args from being re-used
                 unset($args);
             } else {
                 throw new Eight_Exception('validation.invalid_rule', $rule);
             }
             // Stop when an error occurs
             if (!empty($this->errors)) {
                 break;
             }
         }
     }
     if (!empty($this->matches)) {
         foreach ($this->matches as $input) {
             if ($this->value != $input->value) {
                 // Field does not match
                 $this->errors['matches'] = array($input->label ? utf8::strtolower($input->label) : $input->name);
                 break;
             }
         }
     }
     if (!empty($this->callbacks)) {
         foreach ($this->callbacks as $callback) {
             call_user_func($callback, $this);
             // Stop when an error occurs
             if (!empty($this->errors)) {
                 break;
             }
         }
     }
     // If there are errors, validation failed
     return $this->is_valid = empty($this->errors);
 }