예제 #1
0
 public function activate()
 {
     $path = $this->config('location');
     $expire = (int) $this->config('expire');
     $cookiesecure = $this->config('secure');
     $name = $this->config('name') ? (string) $this->config('name') : DevString::random();
     $this->_source = HTTP::cookie($name, "", $expire, $path = null, $cookiesecure) ? $name : null;
     if (!$this->_source) {
         $this->status(self::STATUS_FAILED_INIT);
     } else {
         $this->status(self::STATUS_SUCCESSFUL_INIT);
     }
 }
예제 #2
0
 static function href($href = '', $doc = true)
 {
     if (DevValue::isNull($href)) {
         if (!defined('PAGE_EXTENSION')) {
             define('PAGE_EXTENSION', '.php');
         }
         $href = '';
         if ($doc === false) {
             $href .= $_SERVER['DOCUMENT_ROOT'];
         } else {
             $href = 'http://' . $_SERVER['SERVER_NAME'];
             $href .= $_SERVER['REQUEST_URI'];
             if (DevString::strrpos($href, PAGE_EXTENSION)) {
                 $href = substr($href, 0, DevString::strrpos($href, PAGE_EXTENSION) + strlen(PAGE_EXTENSION));
             } elseif (DevString::strrpos($href, '/')) {
                 $href = substr($href, 0, DevString::strrpos($href, '/') + strlen('/'));
             }
         }
     }
     return $href;
 }
예제 #3
0
 public function activate()
 {
     $path = $this->config('location');
     $name = $this->config('name') ? (string) $this->config('name') : DevString::random();
     $expire = (int) $this->config('expire');
     $secure = $this->config('secure');
     $this->_source = $name;
     $id = session_id();
     if ($id == "") {
         $domain = $path ? substr($path, 0, strpos($path, '/')) : HTTP::domain();
         $dir = $path ? substr($path, strpos($path, '/'), strlen($path)) : '/';
         $cookiedie = DevNumber::isValid($expire) ? time() + (int) $expire : (int) $expire;
         //expire in one hour
         $secure = (bool) $secure;
         session_set_cookie_params($cookiedie, $dir, $domain, $secure);
         session_start($this->_source);
         if (session_id()) {
             $this->_source = $name;
         }
     }
     if (!$this->_source) {
         $this->status(self::STATUS_FAILED_INIT);
     }
 }
예제 #4
0
 private function validate($field_name = null, $table = null)
 {
     $fields = $this->fields();
     // if no table is specified, used the first available entry.
     $table = $table ? $table : (isset($tables[0]) ? $tables[0] : current(DevArray::toArray($this->config(self::NAME_FIELD))));
     $passed = true;
     if (isset($fields[$field_name])) {
         $field = $fields[$field_name];
         $type = strtolower($field['Type']);
         //If duplicate entry
         if ($field['Key'] == 'PRI' || $field['Key'] == 'UNI') {
             if (self::inDB($field_name, $this->field($field_name), $table)) {
                 // In what case do we really need to know this?
                 $this->status("A row having field '{$field_name}' with value '" . $this->field($field_name) . "' already exists.");
             }
         } else {
             if ($this->field($field_name) !== 0 && $this->field($field_name) == '') {
                 if (!$field['Null'] || $field['Null'] == 'NO') {
                     if (DevString::has($type, 'date')) {
                         //$this->field($field_name, dev_join_date($field_name));
                         $this->field($field_name, date('Y-m-d'));
                         if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) {
                             $this->status("Field '{$field_name}' contains an inaccurate date format!");
                             $passed = false;
                         }
                     } else {
                         $this->status("Field '{$field_name}' cannot be empty!");
                         $passed = false;
                     }
                 }
             } else {
                 //Correct Datatype/Size
                 if (DevString::has($type, 'int') || DevString::has($type, 'double') || DevString::has($type, 'float')) {
                     if (!is_numeric($this->field($field_name))) {
                         $this->status("Field '{$field_name}' must be numeric!");
                         $passed = false;
                     }
                 }
                 if (DevString::has($type, 'char') || DevString::has($type, 'text')) {
                     if (!is_string($this->field($field_name))) {
                         $this->status("Field '{$field_name}' is not text!");
                         $passed = false;
                     }
                     if (isset($field['LENGTH']) && DevValue::isNotNull($field['LENGTH']) && strlen($this->field($field_name)) > $field['LENGTH']) {
                         $this->status("Field '{$field_name}' is greater than maximum allowed string length!");
                         $passed = false;
                     }
                 }
                 if (DevString::has($type, 'date')) {
                     if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) {
                         $this->field($field_name, dev_join_date($field_name));
                         if (!is_string($this->field($field_name)) || !DateTime::stringIsDate($this->field($field_name))) {
                             $this->status("Field '{$field_name}' contains an inaccurate date format!");
                             $passed = false;
                         }
                     }
                 }
                 if (DevString::has($type, 'set')) {
                     if (is_array($this->field($field_name))) {
                         $this->field($field_name, implode(', ', $this->field($field_name)));
                     } elseif (!is_string($this->field($field_name))) {
                         $this->status("Field '{$field_name}' contains invalid input!");
                         $passed = false;
                     }
                 }
             }
         }
     }
     return $passed;
 }