Ejemplo n.º 1
0
 public function indexAction()
 {
     // Start with row 0 at the beginning...
     $range = 0;
     /**
      * Feed Pagination
      */
     if ($this->config->feed_pagination) {
         /**
          * If the config option, feed_pagination is set, we will spit up the feed into pages.
          */
         // Get total number of publically available posts
         $sql = "SELECT count(`id`) FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}'";
         $this->total_posts = (int) Pixelpost_DB::get_var($sql);
         // Determine the total number of pages
         Pixelpost_Uri::$total_pages = (int) ceil($this->total_posts / $this->config->posts_per_page);
         // Verify that we're on a legitimate page to start with
         if (Pixelpost_Uri::$total_pages < Pixelpost_Uri::$page) {
             // @todo this error displays if the database call doesn't work.
             throw new Exception("Sorry, we don't have anymore pages to show!");
         }
         // The database needs to know which row we need to start with:
         $range = (int) (Pixelpost_Uri::$page - 1) * $this->config->posts_per_page;
     }
     $posts_sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` DESC LIMIT {$range}, {$this->config->feed_items}";
     // Grab the data object from the DB.
     $this->posts = (array) Pixelpost_DB::get_results($posts_sql);
     /**
      * The RSS feed can't have altered published dates,
      * so we need to completely nuke "filter_published" 
      * before we can run processPosts().
      */
     Pixelpost_Plugin::removeFilterHook('filter_published');
     /**
      * Run the posts through the Plugin system, and apply any 
      * necessary data before sending the array to the view.
      */
     $this->processPosts();
     /**
      * If index is called, without specifying a feed type,
      * auto-run the default rss method.
      */
     if (empty($this->feed_type) || !method_exists($this, $this->feed_type . 'Action')) {
         $this->rssAction();
     }
 }
Ejemplo n.º 2
0
 public function indexAction()
 {
     if (!is_array($this->posts)) {
         // Page Title
         $this->view->title = 'The Past';
         if ($this->config->posts_per_page > 0) {
             /**
              * If the config option, posts_per_page is set, we will spit up the archive into pages.
              */
             // Get total number of publically available posts
             $sql = "SELECT count(`id`) FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}'";
             $this->total_posts = (int) Pixelpost_DB::get_var($sql);
             // Determine the total number of pages
             Pixelpost_Uri::$total_pages = (int) ceil($this->total_posts / $this->config->posts_per_page);
             // Verify that we're on a legitimate page to start with
             if (Pixelpost_Uri::$total_pages < Pixelpost_Uri::$page) {
                 throw new Exception("Sorry, we don't have anymore pages to show!");
             }
             // The database needs to know which row we need to start with:
             $range = (int) (Pixelpost_Uri::$page - 1) * $this->config->posts_per_page;
             $sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` DESC LIMIT {$range}, {$this->config->posts_per_page}";
         } else {
             /**
              * the config option, posts_per_page, isn't set, so display ALL the posts
              */
             $sql = "SELECT * FROM `pixelpost` WHERE `published` <= '{$this->config->current_time}' ORDER BY `published` DESC";
         }
         /**
          * The posts to list:
          */
         $this->posts = (array) Pixelpost_DB::get_results($sql);
     }
     // !is_array($this->posts)
     /**
      * 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->thumbnails = $this->_thumbnails();
     $this->view->posts = $this->posts;
 }
Ejemplo n.º 3
0
 /**
  * Attempt to login, and set the session
  */
 public function login($username = '', $password = '')
 {
     // convert the plaintext password to a SHA1 encoded string
     $password = hash('sha1', $password);
     $username = Pixelpost_DB::escape($username);
     $old_sess_id = session_id();
     // First check if there is a session available with a login_hash.
     if ($this->session->get('login_vars')) {
         // There is login data present in the session so compare the username and password
         // with data stored in session
         $sess_loginarr = $this->session->get('login_vars');
         if ($sess_loginarr['login'] == $username && $sess_loginarr['password'] == $password) {
             // The given data corresponds with the data stored in the session
             // Next step is to establish if the hash can be confirmed
             session_regenerate_id();
             $this->session->db_destroy($old_sess_id);
             unset($old_sess_id);
             return $this->confirmAuth();
         } else {
             // The given data is not the data in the session, do not login the user.
             // destroy the current session
             $this->logout();
             return false;
         }
     } else {
         // If there isn't any session we need to check the given credentials against the database
         // In order to do so we select the status of a user. If that status == 1 then the user can login
         $status = (int) Pixelpost_DB::get_var("SELECT `status` FROM users WHERE username = '******' AND password = '******' LIMIT 1");
         if ($status == 1) {
             // We're good to go!
             // Store the username, password and hash into the session
             session_regenerate_id();
             $this->session->db_destroy($old_sess_id);
             unset($old_sess_id);
             $this->storeAuth($username, $password);
             return true;
         } else {
             // Login invalid, or the user is banned
             return false;
         }
     }
 }
Ejemplo n.º 4
0
$config = Pixelpost_Config::getInstance();
/**
 * Initialize DB Class
 */
switch ($config->database['adapter']) {
    case 'sqlite':
        Pixelpost_DB::init('pdo');
        Pixelpost_DB::connect('sqlite:' . $config->database['sqlite']);
        break;
    case 'mysql':
    default:
        Pixelpost_DB::init('mysql');
        Pixelpost_DB::connect($config->database['username'], $config->database['password'], $config->database['database'], $config->database['host']);
        break;
}
Pixelpost_DB::set_table_prefix($config->database['prefix']);
if (!Pixelpost_DB::$connected) {
    throw new Pixelpost_Exception("Unable to connect to database", E_ERROR);
}
/**
 * Initialize Page
 */
$front = Model_Front::getInstance();
/**
 * Initialize Timezone
 */
if (!empty($config->timezone)) {
    date_default_timezone_set($config->timezone);
}
$config->current_time = date("Y-m-d H:i:s", time());
/**
Ejemplo n.º 5
0
 /**
  * Perform a query
  *
  * @param unknown_type $query
  * @return boolean/int Returns true/false, or rows affected
  */
 public static function query($query)
 {
     $ret = self::$DB->query($query);
     self::$error = self::$DB->error;
     self::$errno = self::$DB->errno;
     self::$rows_affected = self::$num_rows = self::$DB->num_rows;
     self::$insert_id = self::$DB->insert_id;
     return $ret;
     //self::$insert_id;
 }
Ejemplo n.º 6
0
 /**
  * Garbage collector for those that don't properly end 
  * a session or the session times out. 
  * 
  * It receives an integer argument for the “time to live” (TTL) 
  * value for a session. In our class method, gc, we delete any 
  * session record where the last access time is less then the 
  * current time, minus the TTL value
  * 
  * @param $ttl
  * @access public
  * @return bool
  */
 public function db_gc($ttl)
 {
     $end = time() - $ttl;
     $sql = "DELETE FROM sessions WHERE sess_last_acc < {$end}";
     $result = Pixelpost_DB::query($sql);
     //Pixelpost_DB::debug();
     // may want to consider optimizing the table at a given rate to clean up all the
     // deletes of a high traffic site - maybe use OPTIMIZE
     // Pixelpost_DB::query('OPTIMIZE sessions');
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * @Delete a node and all its children
  * @access public
  * @param string $node_name
  */
 public function deleteNodeRecursive($node_permalink)
 {
     try {
         $sql = "SELECT left_node, right_node FROM " . $this->tablename . " \n\t\t\t\tWHERE permalink = '" . Pixelpost_DB::escape($node_permalink) . "'";
         $result = (array) Pixelpost_DB::get_results($sql);
         $result[0]->width_node = $result[0]->right_node - $result[0]->left_node + 1;
         Pixelpost_DB::query("DELETE FROM " . $this->tablename . " \n\t\t\t\tWHERE left_node BETWEEN " . $result[0]->left_node . " \n\t\t\t\tAND " . $result[0]->right_node);
         Pixelpost_DB::query("UPDATE " . $this->tablename . " \n\t\t\t\tSET right_node = right_node - " . $result[0]->width_node . " \n\t\t\t\tWHERE right_node > " . $result[0]->right_node);
         Pixelpost_DB::query("UPDATE " . $this->tablename . " \n\t\t\t \tSET left_node = left_node - " . $result[0]->width_node . " \n\t\t\t\t WHERE left_node > " . $result[0]->right_node);
     } catch (exception $e) {
         throw new Exception($e);
     }
 }
Ejemplo n.º 8
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.
      */
 }