Ejemplo n.º 1
0
 public function make_token($userid, $expire = null)
 {
     $user_ip = $_SERVER["REMOTE_ADDR"];
     unset($this->_f, $this->_d, $this->username, $this->password);
     $cookie_value = substr(md5(uniqid(rand(), true)), 1, 36);
     // this wont make for very simple lookups ... by any of the array values...
     $json = json_encode(array('u' => $userid, 'ts' => couchCurl::handle_couch_id(time()), 'ip' => $user_ip));
     couchCurl::put($json, $cookie_value, self::apf . '_session');
     if ($expire == null) {
         setcookie(self::apf, $cookie_value);
     } else {
         setcookie(self::apf, $cookie_value, $expire);
     }
 }
Ejemplo n.º 2
0
 function retrieve($title, $memcached = false, $db = MEMCACHED_DB)
 {
     // look up title in db, put into memcached, to make it 'secure' add a cookie/session/random generated hash unique to the user
     // to the title.
     $r = json_decode(couchCurl::get($title, false, $db), true);
     if (isset($r['d'])) {
         //if($memcached == true ){
         //$this->cache->set($title,$r['d'],time() + CMC_TIMEOUT ) ;
         //}
         foreach ($r['d'] as $loc => $item) {
             // these string replacements are mainly for the bash shell ..
             $r['d'][$loc] = str_replace(array('-#', '#-', '*@', '*$'), array('(', ')', ',', "'"), $item);
         }
         return $r['d'];
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 public static function load($object, $id = NULL, $classname = NULL, $alt_id = NULL, $required = NULL)
 {
     // uses a variable _r to define a value that will allow a record to be inserted into a database.
     // in the object class that gets passed into load, simply set the _r to the desired variables
     // inside the construct method.
     // If you have conditional fields, that depend on others, you can create a logical flow by
     // manipulating the _d variable and the _r variables to pass values to the next object selection
     // state
     if ($object->_r) {
         $_r = $object->_r;
         unset($object->_r);
     }
     // this _p is for a framework I'm developing that uses poform and a _p array structure
     // to allow developers to define conditional forms (through additional manipulation of _r,_f and
     // _d, evetually it will be put here, am having class focus issues
     unset($object->_p);
     unset($missing);
     if ($_r && $_POST && $required == NULL) {
         if ($_POST) {
             foreach ($_r as $value) {
                 if (!array_key_exists($value, $_POST) || $_POST[$value] == '') {
                     $missing[] = $value;
                 } else {
                     $missing = false;
                 }
             }
         }
         if ($missing == false) {
             // probably should abstract this more, and possibly class it, this is getting
             // verbose/specialized
             // convert 'select action' into database name
             $db = $_POST['select_action'];
             unset($_POST['select_action']);
             $id[] = time();
             // additional 'id' fields in the _id can be designated by determining the load
             // order for each class, in relation to the _d parameter
             // stores keys with _id as the doc title (_id) and unsets them from post
             // to save space
             // each structure is designated inside the class that relates to the database in couch
             if (COUCH_AUTO_ID) {
                 foreach ($_POST as $k => $v) {
                     // make option to automatically add post variables ending in _id to the couch_id...
                     if ($v != 0 && is_int($v + 0) && strpos($k, '_id', 0)) {
                         $id[] = $v;
                         if (COUCH_REMOVE_KEY) {
                             unset($_POST[$k]);
                         }
                     }
                 }
             }
             $id = implode(':', $id);
             foreach ($_POST as $key => $value) {
                 // forcing integers to store as so.. instead of quoted integers
                 if ($value != '' && is_int($int = $value + 0) && $int != 0) {
                     $_POST[$key] = $int;
                 }
             }
             $_POST = array_filter($_POST);
             // numerical values still not forcing to numbers...
             $json = json_encode($_POST);
             // create config option for number base encoding
             // to do create something to convert a encoded id to a time stamp, and eventually
             // into a displayable object ?
             $result = couchCurl::put($json, couchCurl::handle_couch_id($id, 36), $db);
             // look up new record and get the REV so we can update the record properly
             // this result gets added to the top and then displays a blank form .. need to create
             // array structures to handle this functionality after we clean this code up a loott..
             echo $result ? '<h3>Record added</h3>' : 'Problem With Insert';
             // if/when successful then take care to either hide the form or what ? for tasks we dont want people
             // to edit existing tasks ... but dont want to add that functionality in poform
         }
     }
     if ($object->_d && $_POST) {
         // refers to 'hidden' variables, those used for forms or database identification
         foreach ($_POST as $k => $v) {
             if (in_array($k, $object->_d)) {
                 // 	public $email = array('date:email_address'=> array(''=>'date') );
                 // this doesnt set the value although ...
                 $object->{$k} = array("hidden:{$k}" => array('' => 'hidden'));
                 //unset($object->$k);
             }
         }
         unset($object->_d);
     }
     $select_array = array('select', 'checkbox', 'password', 'radio', 'sumbit', 'email', 'search', 'number', 'date', 'hidden');
     unset($object->_d, $object->_f, $object->_p, $object->_r);
     if ($classname != NULL && $id != NULL) {
         $id = explode(':', $id, 2);
         if (count($id) == 2) {
             $a_id = $id[1];
         }
         $id = $id[0];
         if (is_array($object) && in_array($id, $select_array)) {
             if ($id == 'hidden') {
                 return "<input type='hidden' name ='{$alt_id}' value='" . $_POST[$alt_id] . "'/>";
             }
             return self::build_arr($object, $classname . ($a_id ? $a_id : $alt_id), $id, NULL, is_array($_r) && in_array($alt_id, $_r) ? true : NULL);
         } elseif (!is_array($object) && !is_object($object)) {
             foreach ($select_array as $s) {
                 if (!(strpos($object, "{$s} ") === false)) {
                     return self::build_arr(self::decode_string($object), $classname . $id, $s, NULL, is_array($_r) && in_array($id, $_r) ? true : NULL);
                 }
                 // need to pass build_arr a 'required' flag
             }
             // used to check for post var etc..
             unset($object->_d);
             $final_id = trim($classname . $id);
             return self::labeler($final_id, $id) . " <input type='text'" . (is_array($required) && array_key_exists($id, $required) ? ' required ' : NULL) . (!SHOW_PLACEHOLDER ? NULL : " placeholder='" . ucwords(str_replace('_', ' ', $id)) . "' ") . " name='" . $final_id . "' " . ($object != '0' || $object != '' ? ($_POST[$final_id] ? " value='" . $_POST[$final_id] . "'" : '') . " " : '') . "/>";
         }
     } elseif (is_array($object)) {
         foreach ($object as $x => $y) {
             $r[$x] = self::load($y, $x, $classname, NULL, $required);
         }
     } else {
         // to pass back to recursive functions to build the input
         $class_name = !SHOW_CLASS ? ' ' : get_class($object);
         if (is_object($object) || is_array($object)) {
             foreach ($object as $x => $y) {
                 // check to see if an entry is contained in the a parameter
                 // to do validations or create drop down menus with values
                 if (is_array($y) || is_object($y)) {
                     foreach ($y as $a => $b) {
                         $r[$x][$a] = self::load($b, $a, $class_name, $x, $required);
                     }
                 } else {
                     $r[$x] = self::load($y, $x, $class_name, $x, $required);
                 }
             }
         }
     }
     return $r;
 }