Exemple #1
0
 /**
  * Puts (or updates) the item into the cache. Use duration::toMinutes()
  * to calculate a proper expiry for the item.
  *
  * @param string $name The name of the object
  * @param string $contenttype The content type of the object
  * @param string $data The object contents
  * @param int $expiry The expiry of the content in minutes
  * @return boolean True if it was successful
  */
 function set($name, $contenttype, $data, $expiry = null)
 {
     $hash = md5($name);
     $base = config::get('lepton.fscache.path', 'cache');
     if (!$expiry) {
         $expiry = config::get('lepton.fscache.defaultexpiry', '1h');
     }
     $expires = duration::toSeconds($expiry);
     $db = DBX::getInstance(DBX);
     $db->getSchemaManager()->checkSchema('fscache');
     $db->updateRow("REPLACE INTO fscache (hash,contenttype,expires) VALUES ('%s','%s','%d')", $hash, $contenttype, $expires);
     file_put_contents($base . '/' . $hash, $data);
 }
Exemple #2
0
 public function authenticate()
 {
     // TODO: Look up the cookie in the database
     $name = config::get(CookieAuthentication::KEY_COOKIE_NAME, 'leptonauth');
     $ca = Cookies::getInstance(Cookies);
     if ($ca->has($name)) {
         $kd = $ca->get($name);
         $c = $this->decryptCookie($kd);
         $db = DBX::getInstance(DBX);
         $r = $db->getSingleRow("SELECT id FROM users WHERE id='%d' AND username='******'", $c['uid'], $c['uname']);
         if ($r) {
             User::setActiveUser($r['id']);
             return true;
         }
     }
 }
Exemple #3
0
 /**
  * Post a comment to a feed.
  *
  * @param string $nsuri The namespace and URI to post to
  * @param array $item The item to post
  */
 function post($nsuri, $item)
 {
     $db = DBX::getInstance(DBX);
     // Extract namespace and URI
     list($ns, $uri) = StringUtil::getNamespaceURI(config::get('lepton.comments.defaultnamespace', 'comments'), $nsuri);
     // TODO: Implement spam filtering here
     if (Lepton::has('spamfilter')) {
         if (Spamfilter::checkContent($item)) {
             $status = 'QUARANTINED';
         } else {
             $status = 'PUBLISHED';
         }
     } else {
         $status = 'PUBLISHED';
     }
     // Check to make sure the required parameters are present
     if (!$item['message']) {
         throw new BaseException('Missing required key message for comment item');
     }
     if ((!$item['name'] || !$item['email']) && !$item['userid']) {
         throw new BaseException('Missing required key for comment item (name,email or userid)');
     }
     if (!$item['ip']) {
         $item['ip'] = request::getRemoteHost();
     }
     $ambient = array();
     foreach ($item as $k => $i) {
         switch ($k) {
             case 'ip':
             case 'subject':
             case 'message':
             case 'userid':
             case 'name':
             case 'email':
             case 'website':
             case 'status':
                 break;
             default:
                 $ambient[$k] = $i;
         }
     }
     // Save the comment
     $rs = $db->updateRow("INSERT INTO comments (ns,uri,postdate,userid,name,email,website,ip,message,status,ambient) " . "VALUES ('%s','%s',NOW(),'%d','%s','%s','%s','%s','%s','%s','%s')", $ns, $uri, $item['userid'], $item['name'], $item['email'], $item['website'], $item['ip'], $item['message'], $status, serialize($ambient));
 }
Exemple #4
0
 /**
  *
  *
  *
  */
 function __get($key)
 {
     switch ($key) {
         case 'id':
         case 'title':
         case 'isnew':
         case 'slug':
             return $this->_meta[$key];
         case 'replies':
             if (!$this->_meta['replies']) {
                 $r = DBX::getInstance(DBX)->getSingleRow("SELECT COUNT(*) FROM forumposts WHERE threadid='%d'", $this->_meta['id']);
                 $this->_meta['replies'] = $r[0] - 1;
             }
             return $this->_meta[$key];
         case 'created':
             return $this->_meta['threadcreated'];
         case 'user':
             if (!$this->_meta['createduser']) {
                 $this->_meta['createduser'] = User::getUser($this->_meta['usercreated']);
             }
             return $this->_meta['createduser'];
         default:
             throw new BaseException('Invalid request for ForumThread::__get - ' . $key);
     }
 }
Exemple #5
0
 /**
  * Revert a wiki page to a previous revision
  * @param string $pagename The namespace and page name
  * @param integer $revision The revision to revert to
  * @param string $reason The reason for revertion [TODO]
  */
 function revertPage($pagename, $revision, $reason)
 {
     $ns = String::getNamespace('default', $pagename);
     $uri = String::getLocation($pagename);
     $db = DBX::getInstance(DBX);
     try {
         $db->updateRow("UPDATE wiki SET reverted=1 WHERE ns='%s' AND uri='%s' AND revision>'%d'", $ns, $uri, $revision);
     } catch (DBXException $e) {
         die($e);
     }
 }