Ejemplo n.º 1
0
 public static function incrementViews($paste)
 {
     $longIP = findIPLong();
     /* need to select from user_views where ip adress  = ours and paste id */
     /* we need to add in an initial view for the creator ip without incrmentingf count */
     $row = Lunor::$base->dbi->selectAllFrom(PASTE_TABLE_PREFIX . 'paste_view', array('paste_id' => $paste->id, 'ip_address' => $longIP));
     if (empty($row)) {
         Lunor::$base->dbi->beginTransaction();
         Lunor::$base->dbi->setAdditionalPrefix(PASTE_TABLE_PREFIX);
         /* the user hasn't view this paste before ! increment count */
         $paste->views++;
         Lunor::$base->dbi->update('paste')->map(array('views' => $paste->views))->where(array('id' => $paste->id))->go();
         Lunor::$base->dbi->insert('paste_view')->map(array('paste_id' => $paste->id, 'ip_address' => $longIP))->go();
         Lunor::$base->dbi->endTransaction();
     }
 }
Ejemplo n.º 2
0
 public static function getLoggedIn()
 {
     if (isset($_SESSION['user']) && isset($_SESSION['ip'])) {
         /* need to verify the ip hasn't changed */
         if ($_SESSION['ip'] === findIPLong()) {
             /* if the user variable is set then they are logged in for this session */
             /* we can assume the pw's are right as the session variable is server side */
             return true;
         } else {
         }
         /* ip has changed need to create new session for them based on cookies or log them out */
     }
     /* else we need to check cookies for the id & hash */
     $pl = new Account_PersistantLogin();
     /* fill the class with data from cookie data */
     $pl->fromCookies();
     /* if the persistant login is valid we can have them logged in */
     if ($pl->isValid()) {
         $user = new Account_User();
         $user->read(array('name' => $pl->username));
         $_SESSION['user'] = $user;
         $_SESSION['ip'] = findIPLong();
         return true;
     } else {
     }
     return false;
 }