예제 #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);
 }
예제 #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;
         }
     }
 }
예제 #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));
 }
예제 #4
0
 function mget_rec_count($params = NULL)
 {
     $this->db->select($params['select']);
     $this->db->from($params['table']);
     if (array_key_exists('join', $params)) {
         DBX::join($this, $params['join']);
     }
     if (array_key_exists('where', $params)) {
         $this->db->where($params['where']);
     }
     if (array_key_exists('like', $params)) {
         $this->db->where($params['like']);
     }
     $result = $this->db->get();
     $num_row = $result->num_rows() > 0 ? $result->num_rows() : 0;
     $result = $this->mget_rec($params);
     $response['total'] = $num_row;
     $response['rows'] = $result;
     return $response;
 }
예제 #5
0
 function mhas_child_tree($params, $id)
 {
     $this->db->select('COUNT(*) AS rec_count');
     $this->db->from($params['table']);
     if (array_key_exists('join', $params)) {
         DBX::join($this, $params['join']);
     }
     if (array_key_exists('where', $params)) {
         $this->db->where($params['where']);
     }
     $this->db->where('parent_id', $id);
     // $this->db->where('is_deleted', 0);
     return $this->db->get()->row()->rec_count > 0 ? TRUE : FALSE;
 }
예제 #6
0
 function gen_join()
 {
     $params['join'][] = ['a_user_config as auc', 'au.id = auc.user_id'];
     DBX::join($this, $params['join']);
 }
예제 #7
0
 function villagelist_get()
 {
     $sess = $this->_check_token();
     $params = $this->input->get();
     if (key_exists('q', $params)) {
         $params['like'] = empty($params['sf']) ? DBX::like_or('name', $params['q']) : DBX::like_or($params['sf'], $params['q']);
     }
     if (key_exists('id', $params)) {
         $params['where']['id'] = $params['id'];
     }
     if (key_exists('district_id', $params)) {
         $params['where']['district_id'] = $params['district_id'];
     }
     $result['data'] = $this->system_model->getVillage($params);
     $this->xresponse(TRUE, $result);
 }
예제 #8
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);
     }
 }
예제 #9
0
파일: wiki.php 프로젝트: noccy80/lepton-ng
 /**
  * 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);
     }
 }