Exemplo n.º 1
0
 /**
  * Insert or update session data in the DB.
  * Return true or false.
  * 
  * @param $sess_id
  * @param $data
  * @access public
  * @return bool
  */
 public function db_write($sess_id, $data)
 {
     $sess_id = Pixelpost_DB::escape($sess_id);
     $datetime = Pixelpost_DB::sysdate();
     // use datetime('now','localtime') to store it not in UTC
     // get the data associated with the session from the table
     $row = Pixelpost_DB::get_row("SELECT `sess_data` FROM `sessions` WHERE `sess_id` = '{$sess_id}' LIMIT 1");
     //Pixelpost_DB::debug();
     if ($row) {
         $sql = "UPDATE `sessions` SET `sess_last_acc` = {$datetime}, `sess_data` = '{$data}' WHERE `sess_id` = '{$sess_id}'";
         $result = Pixelpost_DB::query($sql);
         //Pixelpost_DB::debug();
     } else {
         $ip = $this->getIP();
         // we store the $servervars so we can check various things while resuming a session from
         // a cookie, in this case we only check against the HTTP_USER_AGENT
         $servervars = Pixelpost_DB::escape($_SERVER['HTTP_USER_AGENT']);
         // should be an if statement here to check if the session vars of the login have been set
         // so we can grab the username and store it in the table. Reason being you can easily see
         // all open sessions in a sessionmanager by selecting on username.
         $sql = "INSERT INTO `sessions`(`sess_id`, `sess_start`, `sess_last_acc`, `sess_data`, `sess_ip`, `sess_servervars`) VALUES ('{$sess_id}', {$datetime}, {$datetime}, '{$data}', '{$ip}', '{$servervars}')";
         $result = Pixelpost_DB::query($sql);
         //Pixelpost_DB::debug();
     }
     return $result;
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     /**
      * Determine the image ID we need to lookup, and verify that it is a positive integer:
      */
     $this->id = (int) Pixelpost_Uri::fragment(1);
     $this->id = $this->id > 0 ? $this->id : 0;
     /**
      * Check if there is a Current Image, else get Current image
      */
     if (!is_object($this->posts['current'])) {
         if (empty($this->id)) {
             // If no ID is specified, grab the latest image:
             $sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` DESC LIMIT 0,1";
         } else {
             $sql = "SELECT * FROM `pixelpost` WHERE `id` = '{$this->id}' AND `published` <= '{$this->config->current_time}' LIMIT 0,1";
         }
         // Assign the current image to the $posts array
         $this->posts['current'] = Pixelpost_DB::get_row($sql);
     }
     /**
      * Verify that the image exists, either from a plugin or from the code above:
      */
     if (!is_object($this->posts['current'])) {
         // Error? Splash Screen?
         throw new Exception("Whoops, we don't have anything to show on this page right now, please to back to the <a href=\"?\">home page</a>.");
     }
     /**
      * Check if Next Image exists, else get Next image
      */
     if (!is_object($this->posts['next'])) {
         $sql = "SELECT * FROM `pixelpost` WHERE (`published` < '{$this->posts['current']->published}') and (`published` <= '{$this->config->current_time}') ORDER BY `published` DESC LIMIT 0,1";
         $this->posts['next'] = Pixelpost_DB::get_row($sql);
         /**
          * If we are on the last image, there isn't a next image, 
          * so we can wrap around to the first image:
          */
         if (!is_object($this->posts['next'])) {
             $sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` DESC LIMIT 0,1";
             $this->posts['next'] = Pixelpost_DB::get_row($sql);
         }
     }
     /**
      * Check if Previous Image exists, else get Previous image
      */
     if (!is_object($this->posts['previous'])) {
         $sql = "SELECT * FROM `pixelpost` WHERE (`published` > '{$this->posts['current']->published}') and (`published` <= '{$this->config->current_time}') ORDER BY `published` ASC LIMIT 0,1";
         $this->posts['previous'] = Pixelpost_DB::get_row($sql);
         /**
          * If the first image, we can't go back any further, 
          * so we can wrap around to the last image:
          */
         if (!is_object($this->posts['previous'])) {
             $sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` ASC LIMIT 0,1";
             $this->posts['previous'] = Pixelpost_DB::get_row($sql);
         }
     }
     /**
      * Run the posts through the Plugin system, and apply any 
      * necessary data before sending the array to the view.
      */
     $this->processPosts();
     /**
      * Assign the variables to be used in the view
      * $this->view->myVar can be accessed in the template as $myVar
      */
     $this->view->title = $this->posts['current']->title;
     $this->view->posts = $this->posts;
     /**
      * Inclusion of the actual template needed is handled in the destruct
      * function of the base controller.
      */
 }