Ejemplo n.º 1
0
 /**
  * @brief Loads a wiki page
  *
  * Will attempt to load a wiki page from the database. If revision is not
  * specified, the latest revision will be loaded.
  *
  * @param String $page
  * @param Int $revision
  * @return Boolean True on success, false otherwise
  */
 function loadWikiPage($page, $revision = null)
 {
     $db = new DatabaseConnection();
     list($ns, $name) = $this->splitUri($page, 'wiki');
     if (!$revision) {
         $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s " . "ORDER BY revision DESC LIMIT 1;", $ns, $name);
     } else {
         $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s AND " . "revision<%d ORDER BY revision DESC LIMIT 1;", $ns, $name, $revision);
     }
     if ($pd) {
         $revs = $db->getSingleRow("SELECT revision FROM wikipages WHERE pagens=%s AND pagename=%s", $ns, $name);
         foreach ($revs as $rev) {
             $this->revisions[] = $rev['revision'];
         }
         if ($pd['format'] != NULL) {
             $this->markup = $pd['markuptype'];
             $this->parser = markup::factory($this->markup);
         }
         $this->content = $pd['content'];
         $this->pagerevision = $pd['revision'];
         $this->modified = false;
         $this->pagens = $pd['pagens'];
         $this->pagename = $pd['pagename'];
         $this->pagetitle = $pd['pagetitle'];
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 function staticText($slug)
 {
     $db = new DatabaseConnection();
     $text = $db->getSingleRow("SELECT * FROM statictext WHERE slug=%s", $slug);
     if ($text) {
         return $text['content'];
     }
 }
Ejemplo n.º 3
0
 /**
  * Create a new collection using an uri or a pattern
  *
  * f.ex.  tag:foo, category:bar, title:*, *, user:bob
  *
  */
 public function __construct($selection, Paginator $paginator = null)
 {
     // Create a collection from a tag, category, title, user etc.
     $db = new DatabaseConnection();
     $sql = $db->quote('SELECT * FROM galleryitems');
     $count = $db->quote('SELECT COUNT(*) AS numitems FROM galleryitems');
     // If we have a paginator, make use of it
     if ($paginator) {
         $sql .= ' ' . $paginator->getSqlLimit();
     }
     // Then select the rows and the total count
     $rs = $db->getRows($sql);
     $rsc = $db->getSingleRow($count);
 }
Ejemplo n.º 4
0
 /**
  * @brief Unlink an identity based on its id.
  *
  * @param int $iid The identity ID
  * @param int $userid The user ID that owns the identity
  * @return boolean True on success
  */
 static function unlinkIdentity($iid, $userid = null)
 {
     $db = new DatabaseConnection();
     // Default to the active user
     if (!$userid) {
         $userid = user::getActiveUser()->userid;
     }
     // And make sure we have an identity to unlink
     if ($iid != 0) {
         $identities = $db->getRows("SELECT * FROM userengage WHERE userid=%d", user::getActiveUser()->userid);
         $identity = $db->getSingleRow("SELECT * FROM userengage WHERE userid=%d AND id=%d", user::getActiveUser()->userid, $iid);
         if (count($identities) > 1) {
             if ($identity) {
                 $db->updateRow("DELETE FROM userengage WHERE userid=%d AND id=%d", user::getActiveUser()->userid, $iid);
                 return true;
             }
         } else {
             view::set('identity', $identity);
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * @brief Checks to see if a username is available.
  * Keep in mind that if the username is available, true is returned.
  * This is contrary to the find() methods.
  *
  * @see User::find
  * @param string $username The username to check
  * @return bool True if the username is valid, false otherwise
  */
 static function checkUsername($username)
 {
     $db = new DatabaseConnection();
     $record = $db->getSingleRow("SELECT * FROM users WHERE username=%s", $username);
     return $record == null;
 }
Ejemplo n.º 6
0
 public function export()
 {
     console::writeLn(__astr('\\b{Exporting tables and data}'));
     $db = new DatabaseConnection();
     $args = func_get_args();
     if (count($args) == 0) {
         $args[] = '%';
     }
     $drop = false;
     $data = false;
     foreach ($args as $arg) {
         try {
             if (strtolower($arg) == 'drop') {
                 $drop = true;
             } elseif (strtolower($arg) == 'data') {
                 $data = true;
             } else {
                 $tbl = $db->getRows("SHOW TABLES LIKE %s", $arg);
                 foreach ($tbl as $tblc) {
                     $c = $tblc[0];
                     console::write("  [app] %-30s ", $c);
                     // Get the create table syntax
                     $crs = $db->getSingleRow("SHOW CREATE TABLE " . $c);
                     $sqlcreate = $crs;
                     // Get the data
                     $fsql = fopen(expandpath('app:/sql/' . $c . '.sql'), 'w');
                     if ($drop) {
                         fputs($fsql, "DROP TABLE IF EXISTS " . $c . ";\n");
                     }
                     fputs($fsql, $crs[1] . "\n");
                     fclose($fsql);
                     console::write("SQL ");
                     if ($data) {
                         // Export the data as well
                         $drs = $db->getRows("SELECT * FROM " . $c);
                         foreach ($drs[0] as $k => $v) {
                             if ($k != '0' && intval($k) == 0) {
                                 $hdr[] = $k;
                             }
                         }
                         $fdat = fopen(expandpath('app:/sql/' . $c . '.csv'), 'w');
                         fputcsv($fdat, $hdr, ";", '"');
                         foreach ($drs as $row) {
                             $dout = array();
                             foreach ($row as $i => $h) {
                                 if ($i != '0' && intval($i) == 0) {
                                     $dout[] = $h;
                                 }
                             }
                             fputcsv($fdat, $dout, ";");
                         }
                         fclose($fdat);
                         console::write("CSV ");
                     }
                     console::writeLn();
                 }
             }
         } catch (DatabaseException $e) {
             console::writeLn();
             console::warn($e->getMessage());
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * @brief Load a user record from the database.
  *
  * @param int $userid The user ID
  */
 function loadUser($userid)
 {
     if (is_numeric($userid)) {
         $db = new DatabaseConnection();
         $record = $db->getSingleRow("SELECT a.*,u.*,a.id AS userid FROM " . LEPTON_DB_PREFIX . "users a LEFT JOIN " . LEPTON_DB_PREFIX . "userdata u ON a.id=u.id WHERE a.id=%d", $userid);
         if ($record) {
             $this->assign($record);
         } else {
             throw new UserException("No such user ({$userid})");
         }
     } else {
         throw new BadArgumentException("User ID must be an integer");
     }
 }
Ejemplo n.º 8
0
 /**
  * @brief Query and return a user record.
  * This can be used by the authentication providers in a number of ways
  * such as resolving user IDs or using information to look in other
  * tables.
  *
  * @param string $username The username to fetch the record from
  * @return array The user record, or null on failure.
  */
 public function queryUser($username)
 {
     $db = new DatabaseConnection();
     try {
         $userrecord = $db->getSingleRow("SELECT * FROM users WHERE username=%s", $username);
         if ($userrecord) {
             return $userrecord;
         }
         return null;
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 9
0
 /**
  *
  * @param type $key
  * @param type $value 
  */
 public function __set($key, $value)
 {
     switch ($key) {
         case 'amount':
             $this->amount = floatval($value);
         case 'symbol':
             $db = new DatabaseConnection();
             $sym = $db->getSingleRow("SELECT * FROM currencyexchange WHERE symbol=%s", $value);
             if ($sym) {
                 $this->symbol = strtoupper($value);
             } else {
                 throw new CurrencyException("No such symbol: " . $value);
             }
         default:
             throw new BadPropertyException($this, $key);
     }
 }
Ejemplo n.º 10
0
 /**
  * Update a wiki page
  * @param string $pagename The namespace and page name
  * @param string $title The page title
  * @param string $content The page content
  */
 function updatePage($pagename, $title, $content)
 {
     $ns = String::getNamespace('default', $pagename);
     $uri = String::getLocation($pagename);
     $db = new DatabaseConnection();
     $author = User::getActiveUserId();
     try {
         // pull the latest revision of the page
         $rs = $db->getSingleRow('SELECT MAX(revision) AS latest FROM wiki WHERE ns=\'%s\' AND uri=\'%s\'', $ns, $uri);
         $currev = $rs ? $rs['latest'] : 0;
         // set to 0 if no record returned
         // bump revision
         $currev++;
         // and insert the new data
         $db->updateRow("INSERT INTO wiki SET content='%s',revision='%d',title='%s',ns='%s',uri='%s',lastedit=NOW(),author='%d'", $content, $currev, $title, $ns, $uri, $author);
     } catch (DBXException $e) {
         die($e);
     }
 }
Ejemplo n.º 11
0
 function getKeyForUser($username)
 {
     $user = User::find($username);
     if ($user) {
         $userid = $user->userid;
         $db = new DatabaseConnection();
         $rs = $db->getSingleRow("SELECT * FROM userppp WHERE id=%d", $userid);
         if ($rs) {
             $codekey = $rs['secretkey'];
         } else {
             $codekey = null;
         }
         return $codekey;
     } else {
         throw new UserException('User not found.');
     }
 }
Ejemplo n.º 12
0
 private static function updateSets(callback $callback = null)
 {
     // Update the callback if one is present
     if ($callback) {
         $callback->call('Updating sets...');
     }
     // Pull the country list
     $db = new DatabaseConnection();
     $rs = $db->getRows("SELECT isocode,capital FROM geonames_countryinfo");
     foreach ($rs as $cc) {
         $f = $db->getSingleRow("SELECT * FROM geonames_datasets WHERE setkey=%s", $cc['isocode']);
         if (!$f) {
             $db->insertRow("INSERT INTO geonames_datasets (setkey,setname,url,active) VALUES (%s,%s,%s,0)", $cc['isocode'], $cc['capital'], self::getUrl($cc['isocode'] . '.zip'));
         }
     }
     if ($callback) {
         $callback->call('All sets updated');
     }
 }