Ejemplo n.º 1
0
 public function getUniqueURLs($linkArray)
 {
     if (!is_array($linkArray) || !$linkArray) {
         throw new Exception('AppLinkModel::getUniqueURLs argument must be an array.');
     }
     $query = new Query('SELECT');
     $query->field('url');
     $query->from('links');
     foreach ($linkArray as $link) {
         $query->where('url like ?', '%' . $link . '%', 'OR');
     }
     $stmt = $query->prepare();
     $stmt->execute();
     $existing = array();
     while ($row = $stmt->fetchObj()) {
         $existing[] = $row->url;
     }
     $unique = array();
     foreach ($linkArray as $link) {
         $exists = false;
         foreach ($existing as $elink) {
             if (strtolower($link) == strtolower($elink) || in_array($link, $unique)) {
                 $exists = true;
                 break;
             }
         }
         if (!$exists) {
             $unique[] = $link;
         }
     }
     return $unique;
 }
Ejemplo n.º 2
0
 public function create($username, $password, $email, $salt = false, $group_id = 3, $psoverride = 1, $ipaddr = false, $mustValidate = true)
 {
     $user = $this->getByUsername($username);
     if ($user) {
         return self::CREATE_USERNAME_EXISTS;
     }
     $query = new Query('SELECT');
     $query->field('COUNT(*)', 'count');
     $query->from('users');
     $query->where('email like ?', $email);
     $stmt = $query->prepare();
     $stmt->execute();
     $obj = $stmt->fetchObj();
     if ($obj->count > 0) {
         return self::CREATE_EMAIL_EXISTS;
     }
     $salt = $salt ?: $this->generateSalt();
     $passhash = md5(md5($salt) . md5($password));
     $bean = new UserProfileBean();
     $bean->username = $username;
     $bean->email = $email;
     $bean->group_id = $group_id;
     $bean->permission_override_id = $psoverride;
     $bean->password = $passhash;
     $bean->salt = $salt;
     $bean->set('joindate', "NOW()", true);
     $bean->reg_ip = $ipaddr ?: $_SERVER['REMOTE_ADDR'];
     $bean->must_validate = $mustValidate ? 1 : 0;
     try {
         $bean->insert();
     } catch (QueryFailedException $e) {
         return self::CREATE_ERROR;
     }
     return self::CREATE_OK;
 }
Ejemplo n.º 3
0
 public function getByPublicKey__300_users($pubkey)
 {
     $query = new Query('SELECT');
     $query->where('publickey like ?', $pubkey);
     $result = AutoLoginBean::select($query, true);
     if (count($result) == 0) {
         return false;
     }
     return $result[0];
 }
Ejemplo n.º 4
0
 public function getByGroupName__3600_users($group)
 {
     $query = new Query('SELECT');
     $query->where('grp.group_name like ?', $group);
     $result = UsergroupBean::select($query, true);
     if (count($result) == 0) {
         return false;
     }
     return $result[0]->getMapped('permissionset');
 }
Ejemplo n.º 5
0
 public function getByName__3600($name)
 {
     $query = new Query('SELECT');
     $query->where('category_name = ?', $name);
     $cats = AppCategoryBean::select($query);
     if (!$cats) {
         return false;
     }
     return $cats[0];
 }
Ejemplo n.º 6
0
 public function getByName__3600_apiprofiles($name)
 {
     $query = new Query('SELECT');
     $query->where('name = ?', $name);
     $apip = APIProfileBean::select($query);
     if (!$apip) {
         return false;
     }
     return $apip[0];
 }
Ejemplo n.º 7
0
 public function getLogsByTime($startTimeObj, $endTimeObj)
 {
     $query = new Query("SELECT");
     $query->where("channel_name = ?", Config::getVal("general", "channel"));
     $startTimeObj->makeTimestamp();
     $endTimeObj->makeTimestamp();
     $query->where("time > ?", $startTimeObj->timestamp);
     $query->where("time < ?", $endTimeObj->timestamp, "AND");
     $messagesArray = ChannelActionBean::select($query);
     return $messagesArray;
 }
Ejemplo n.º 8
0
 public function setValue($key, $data)
 {
     $q = new Query("DELETE");
     $q->from("config");
     $q->where("key = ?", $key);
     $stmt = $q->prepare();
     $stmt->execute();
     $cvb = new ConfigValueBean();
     $cvb->key = $key;
     $cvb->data = serialize($data);
     $cvb->set("last_updated_time", "NOW()", true);
     $cvb->insert();
 }
Ejemplo n.º 9
0
 /**
  * Database template loader
  * Assumes that the table specified in the config has
  * a 'path' and 'content' field.
  * The former should contain the path as it would be
  * loaded through a controller (e.g. ucp/user_logged_in)
  * The latter should contain the Hydrogen/purephp template
  * as it would be in a file.
  *
  * @param string viewName The name of the view to be found.
  */
 public function load($viewName)
 {
     $query = new Query("SELECT");
     $query->from($this->getTableName());
     $query->where("path = ?", $viewName);
     $query->limit(1);
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchObject();
     if (!$result->content) {
         throw new NoSuchViewException("View " . $viewName . " does not exist in database.");
     }
     return $result->content;
 }
Ejemplo n.º 10
0
 public function store($key, $data, $moduleNamespace)
 {
     $moduleNamespace = str_replace("\\", "*", $moduleNamespace);
     $q = new Query("DELETE");
     $q->from("module_data");
     $q->where("title = ?", $key);
     $q->where("module = ?", $moduleNamespace);
     $stmt = $q->prepare();
     $stmt->execute();
     $mdb = new ModuleDataBean();
     $mdb->title = $key;
     $mdb->data = serialize($data);
     $mdb->module = $moduleNamespace;
     $mdb->set("last_updated_time", "NOW()", true);
     $mdb->insert();
 }
Ejemplo n.º 11
0
 public function banIPs($desc, $ips, $permissionSet = 10)
 {
     $query = new Query('INSERT');
     $query->intoTable('bans_ip');
     $query->intoField('ban_desc');
     $query->intoField('ip_low');
     $query->intoField('ip_high');
     $query->intoField('permissionset_id');
     $query->intoField('date_banned');
     foreach ($ips as $ip) {
         $intip = $this->toIntIP($ip);
         $query->values('(?, ?, ?, ?, NOW())', array($desc, $intip, $intip, $permissionSet));
     }
     $stmt = $query->prepare();
     return $stmt->execute();
 }
Ejemplo n.º 12
0
 public function create($app_id, $version, $verinfo)
 {
     $ver = $this->getByAppID($app_id, $version);
     if ($ver) {
         return false;
     }
     $query = new Query('SELECT');
     $query->field('MAX(intversion)', 'maxint');
     $query->from('versions');
     $query->where('app_id = ?', $app_id);
     $stmt = $query->prepare();
     $stmt->execute();
     if (!($row = $stmt->fetchObj())) {
         $max = false;
     } else {
         $max = $row->maxint;
     }
     if ($max) {
         $curTokens = $this->getNumTokens($max);
         $intver = $this->getIntVersion($version, $curTokens);
         $newTokens = $this->getNumTokens($intver);
         if ($newTokens > $curTokens) {
             $this->updateTokens($app_id, $newTokens);
         }
     } else {
         $intver = $this->getIntVersion($version);
     }
     $ver = new AppVersionBean();
     $ver->app_id = $app_id;
     $ver->version = $version;
     $ver->intversion = $intver;
     $ver->versioninfo = $verinfo;
     $ver->set('date_added', 'NOW()', true);
     $ver->set('last_updated', 'NOW()', true);
     try {
         $ver->insert();
     } catch (QueryFailedException $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
 public function setScreenshots($app_id, $itunes_id, $shots)
 {
     $i = 0;
     $beans = array();
     foreach ($shots as $shot) {
         if ($i) {
             $filename = "{$itunes_id}_{$i}screen.jpg";
         } else {
             $filename = "{$itunes_id}screen.jpg";
         }
         if ($this->saveScreenshotLocally($shot, $filename, $is_horiz)) {
             $bean = new ScreenshotBean();
             $bean->app_id = $app_id;
             $bean->shot_url = '%BASE_URL%/appimages/screenshots/' . $filename;
             $bean->is_horiz = $is_horiz ? 1 : 0;
             $beans[] = $bean;
             $i++;
         }
     }
     if (!$beans) {
         return false;
     }
     $query = new Query('DELETE');
     $query->from('screenshots');
     $query->where('app_id = ?', $app_id);
     $stmt = $query->prepare();
     $stmt->execute();
     foreach ($beans as $bean) {
         try {
             $bean->insert(true);
         } catch (QueryFailedException $e) {
         }
     }
     $this->cm->clear("sm_appid_{$app_id}");
     return true;
 }
Ejemplo n.º 14
0
 /**
  * Loads the contents of the specified template.
  *
  * @param string $templateName The name of the template to be loaded.
  * @return string The unaltered, unparsed contents of the specified
  * 		template.
  * @throws hydrogen\view\exceptions\NoSuchViewException if the specified
  * 		template is not found or cannot be loaded.
  */
 public function load($viewName)
 {
     $table = Config::getRequiredVal("view", "table_name");
     $nameCol = Config::getRequiredVal("view", "name_field");
     $contentCol = Config::getRequiredVal("view", "content_field");
     $query = new Query("SELECT");
     $query->field($contentCol);
     $query->from($table);
     $query->where($nameCol . " = ?", $viewName);
     $query->limit(1);
     $stmt = $query->prepare();
     $stmt->execute();
     $result = $stmt->fetchObject();
     if (!$result->{$contentCol}) {
         throw new NoSuchViewException("View " . $viewName . " does not exist in database.");
     }
     return $result->{$contentCol};
 }
Ejemplo n.º 15
0
 public function delete()
 {
     if (!isset($this->stored[static::$primaryKey])) {
         $class = get_class($this);
         throw new MissingPrimaryKeyException($class . '->delete() cannot be called until a primary key is set.');
     }
     $query = new Query('DELETE', $this->dbengine);
     $query->from(static::$tableNoPrefix);
     $query->where(static::$primaryKey . ' = ?', $this->stored[static::$primaryKey]);
     $query->limit(1);
     $stmt = $query->prepare();
     if (!$stmt->execute()) {
         $info = $stmt->errorInfo();
         $e = new QueryFailedException($info[2]);
         $e->errorInfo = $info;
         throw $e;
     }
     return true;
 }
Ejemplo n.º 16
0
 $query->table('links');
 $query->set('active = ?', 0);
 $query->where('submitter_id = ?', $banid);
 $stmt = $query->prepare();
 $stmt->execute();
 echo "All of user {$user->username}'s links have been deleted.<br />\n";
 echo "Banning the dickhead...<br />\n";
 $ipstoban = array();
 if ($user->reg_ip != 0) {
     $ipstoban[] = $user->reg_ip;
 }
 if (!is_null($user->last_ip) && $user->last_ip) {
     $ipstoban[] = $user->last_ip;
 }
 // And now, let's get all known IPs
 $query = new Query('SELECT');
 $query->field('submitter_ip');
 $query->from('links');
 $query->where('submitter_id = ?', $banid);
 $stmt = $query->prepare();
 $stmt->execute();
 while ($obj = $stmt->fetchObj()) {
     $ipstoban[] = $obj->submitter_ip;
 }
 // Filter out the dupes and query to see which are already banned
 $ipadded = array();
 $toban = array();
 $bipm = BannedIPModel::getInstance();
 foreach ($ipstoban as $ip) {
     if (!isset($ipadded[$ip])) {
         $ipadded[$ip] = true;
Ejemplo n.º 17
0
        $name = $row['name'];
        $app_id = $row['id'];
        // Pull out the words we'll need to index
        $iwords = $am->getIndexable($name);
        // Add 'em
        if (count($iwords) > 0) {
            echo "Indexing: " . implode(', ', $iwords) . "<br />\n";
            foreach ($iwords as $iword) {
                $sindex[$iword][] = $app_id;
            }
        } else {
            echo "No words to be indexed.<br />\n";
        }
    }
}
echo "<br />Saving and caching:<br />\n";
foreach ($sindex as $term => $idarray) {
    echo "<strong>{$term}</strong> ";
    echo str_replace("\n", "<br />\n", print_r($idarray, true));
    $cm->set("search_name_index:{$term}", $idarray, 0);
    $query = new Query('INSERT');
    $query->intoTable('search_name_index');
    $query->intoField('term');
    $query->intoField('app_id_array');
    $query->values("(?, ?)", array($term, serialize($idarray)));
    $stmt = $query->prepare();
    if (!$stmt->execute()) {
        echo "Error while adding term '{$term}'.<br />\n";
    }
}
echo "<br />Done!";
Ejemplo n.º 18
0
     die("You broke shit.");
 }
 $acracker = array();
 while ($row = $stmt->fetchAssoc()) {
     $acracker[$row['app_id']] = $row['cracker'];
 }
 echo "Got crackers.<br />\n";
 ob_flush();
 flush();
 // And finally, update the facades
 foreach ($aname as $key => $value) {
     $version = $aver[$key];
     $date = $adate[$key];
     $cracker = isset($acracker[$key]) && !is_null($acracker[$key]) && !empty($acracker[$key]) ? "'" . $acracker[$key] . "'" : NULL;
     echo "Updating {$key}: {$value} ({$version}) cracked by {$cracker} on {$date}... ";
     $query = new Query('UPDATE');
     $query->table('applications');
     $query->set('latest_version = ?', $version);
     $query->set('latest_version_added = ?', $date);
     if (is_null($cracker)) {
         $query->set('latest_version_first_cracker = NULL');
     } else {
         $query->set('latest_version_first_cracker = ?', $cracker);
     }
     $query->where('id = ?', $key);
     $stmt = $query->prepare();
     if ($stmt->execute()) {
         echo "Done.<br />\n";
     } else {
         echo "Failed.<br />\n";
     }
Ejemplo n.º 19
0
 /**
  * Gets the number of messages specified in $count
  * that are immediately before the given timestamp
  *
  * @param integer $timestamp unix epoch timestamp
  * @param integer $count number of messages to get
  * @return array array of ChannelActionBean objects latest
  * first
  */
 public function getMessagesBeforeTimestamp($timestamp, $count)
 {
     $query = new Query("SELECT");
     $query->where("channel_name = ?", Config::getVal("general", "channel"));
     $query->where("time < ?", $timestamp);
     $query->orderby("time", "DESC");
     $query->limit($count);
     $messages = ChannelActionBean::select($query);
     return $messages;
 }
Ejemplo n.º 20
0
 protected function indexName($name, $id)
 {
     $iwords = $this->getIndexable($name);
     if (count($iwords) > 0) {
         $sem = SemaphoreEngineFactory::getEngine();
         $sindex = array();
         $create = array();
         $docreate = false;
         $query = new Query('SELECT');
         $query->field('term');
         $query->field('app_id_array');
         $query->from('search_name_index');
         foreach ($iwords as $iword) {
             $sindex[$iword] = array();
             $create[$iword] = true;
             $docreate = true;
             $query->where('term = ?', $iword, 'OR');
         }
         $stmt = $query->prepare();
         $semkey = Config::getVal('recache', 'unique_name') . ":LOCK:sindex";
         $sem->acquire($semkey);
         $stmt->execute();
         while ($row = $stmt->fetchObj()) {
             $create[$row->term] = false;
             $sindex[$row->term] = unserialize($row->app_id_array);
         }
         unset($query);
         unset($stmt);
         $iquery = new Query('INSERT');
         $iquery->ignore();
         $iquery->intoTable('search_name_index');
         $iquery->intoField('term');
         $iquery->intoField('app_id_array');
         $uqueries = array();
         foreach ($iwords as $iword) {
             if (!in_array($id, $sindex[$iword])) {
                 $sindex[$iword][] = $id;
                 $this->cm->set("search_name_index:{$iword}", $sindex[$iword], 0);
             }
             if ($create[$iword]) {
                 $iquery->VALUES('(?, ?)', array($iword, serialize($sindex[$iword])));
             } else {
                 $query = new Query('UPDATE');
                 $query->table('search_name_index');
                 $query->set('app_id_array = ?', serialize($sindex[$iword]));
                 $query->where('term = ?', $iword);
                 $uqueries[] = $query;
             }
         }
         if ($docreate) {
             $stmt = $iquery->prepare();
             unset($iquery);
             $stmt->execute();
         }
         foreach ($uqueries as $uquery) {
             $stmt = $uquery->prepare();
             $stmt->execute();
         }
         $sem->release($semkey);
     }
 }
Ejemplo n.º 21
0
 public function getWordCount($nick, $time = false)
 {
     $query = new Query("SELECT");
     $query->where("channel_name = ?", Config::getVal("general", "channel"));
     $query->where("nickname = ?", $nick);
     $query->where("type = ?", ReceivedLineTypes::CHANMSG);
     if ($time == "hour") {
         $query->where("time > ?", time() - 60 * 60);
     } else {
         if ($time == "day") {
             $query->where("time > ?", time() - 60 * 60 * 24);
         } else {
             if ($time == "week") {
                 $query->where("time > ?", time() - 60 * 60 * 24 * 7);
             }
         }
     }
     $messages = ChannelActionBean::select($query);
     $wordCount = 0;
     foreach ($messages as $message) {
         $words = str_word_count($message->message);
         $wordCount += $words;
     }
     return $wordCount;
 }