Example #1
0
 public function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new SDB();
     }
     return self::$instance;
 }
 public static function getActiveApp($user)
 {
     $aid = isset($_REQUEST['aid']) ? $_REQUEST['aid'] : null;
     if ($aid === null) {
         $domain = App::$SDBDomain;
         $aaa = array();
         foreach (App::$SDBFields as $field => $meta) {
             $aaa[] = $field;
         }
         $uid = $user->id;
         $where = "where `uid` = '{$uid}' limit 1";
         $sdb = SDB::getInstance();
         if (!$sdb->select($domain, $aaa, $where, false)) {
             return null;
         }
         $app = new App();
         foreach (App::$SDBFields as $field => $meta) {
             $app->{$field} = $aaa[0][$field];
         }
         $app->id = $aaa[0]['id'];
     } else {
         $app = new App($aid);
     }
     return $app;
 }
Example #3
0
 private function __construct()
 {
     try {
         self::$instance = new PDO('mysql:dbname=' . self::DBNAME . ';host=' . self::HOSTNAME, self::USERNAME, self::PASSWORD, array(PDO::ATTR_AUTOCOMMIT => false));
     } catch (PDOException $e) {
         self::$instance = null;
         throw new Exception('PDOException', 4);
     }
 }
 function delete()
 {
     $id = $this->id;
     // fb("sdbo - delete $this->id");
     $domain = $this->getSDBDomain();
     $this->sdb = SDB::getInstance();
     $fields = array('deleted' => date('Y-m-d'));
     // Soft delete
     $this->sdb->put($domain, $id, $fields, true);
     //    $this->sdb->delete($domain, $id);
 }
Example #5
0
 public function __construct()
 {
     try {
         $this->db =& SDB::get_instance();
         $this->set_properties();
         if ($this->relationships) {
             $this->set_relation_properties($this->relationships);
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #6
0
function multiSite2_showSite()
{
    global $TEMPSDB;
    global $_GET;
    $site = multiSite2_getSite();
    $path = SDB::getValue(SDB::read($TEMPSDB), $site);
    $plugin = $_GET["plugin"];
    if (file_exists("plugins/" . $plugin . "/" . $path)) {
        return "plugins/" . $plugin . "/" . $path;
    } else {
        echo "Unknown site";
        return FALSE;
    }
}
Example #7
0
function moreColumns_deleteValue($tableName, $id)
{
    if (!file_exists("sdbs/{$tableName}/")) {
        return false;
    }
    $columns = scandir("sdbs/{$tableName}/");
    foreach ($columns as $entry) {
        if ($entry != "." && $entry != ".." && $entry != ".DS_Store" && $entry != ".htaccess" && $entry != ".htdocs") {
            $file = "{$tableName}/{$entry}";
            SDB::deleteValue($file, $id);
        }
    }
    return true;
}
 protected function add_column($table, $column, $data_type, $options = array())
 {
     $cmd = new SDBCommand('ALTER TABLE @table ADD @column ');
     $cmd->set('table', $table, SDB::TableName);
     $cmd->set('column', $column, SDB::FieldName);
     if (array_key_exists(strtolower($data_type), $this->_type_mappings)) {
         $data_type = $this->_type_mappings[strtolower($data_type)];
         if (is_array($data_type)) {
             $options = $options + $data_type[1];
             $data_type = $data_type[0];
         }
     }
     if (array_key_exists(strtolower($data_type), $this->_type_defaults)) {
         $options = $options + $this->_type_defaults[strtolower($data_type)];
     }
     $cmd->command .= strtoupper($data_type);
     if (strtolower($data_type) == 'enum') {
         $values = array();
         if (array_key_exists('values', $options)) {
             $values = $options['values'];
         } elseif (array_key_exists('options', $options)) {
             $values = $options['options'];
         }
         if (!is_array($values) || !count($values)) {
             throw new Exception('Invalid enum values');
         }
         foreach ($values as &$val) {
             $val = SDB::quote($val);
         }
         $cmd->command .= '(' . join(',', $values) . ')';
     } elseif (array_key_exists('size', $options) && $options['size'] > 0) {
         $cmd->command .= '(' . $options['size'] . ')';
     }
     if (array_key_exists('unsigned', $options) && $options['unsigned']) {
         $cmd->command .= ' UNSIGNED';
     }
     $cmd->command .= array_key_exists('null', $options) && $options['null'] ? ' NULL' : ' NOT NULL';
     $cmd->execute();
 }
 static function check_init()
 {
     if (!count(SDB::get_tables_list())) {
         $sql = file_get_contents(BASE . 'conf/simple.' . conf('db.type') . '.sql');
         if (conf('db.type') == 'mysql') {
             $spl = explode(';', $sql);
             foreach ($spl as $part) {
                 $cmd = new SDBCommand($part);
                 $cmd->execute();
             }
         } else {
             $cmd = new SDBCommand($sql);
             $cmd->execute();
         }
         SDB::reset_cached_data();
         $fl = new FileItem();
         $fl->parent_id = 0;
         $fl->name = 's';
         $fl->type = FileItem::Folder;
         $fl->save();
         Initiator::fill_db(S_BASE, $fl->id);
     }
 }
Example #10
0
 public function createSubmit()
 {
     $name = isset($_POST['name']) ? $_POST['name'] : '';
     $description = isset($_POST['description']) ? $_POST['description'] : '';
     $type = isset($_POST['type']) ? $_POST['type'] : HouseAd::HOUSEAD_TYPE_ICON;
     $link = isset($_POST['link']) ? $_POST['link'] : '';
     $linkType = isset($_POST['linkType']) ? $_POST['linkType'] : HouseAd::HOUSEAD_LINKTYPE_WEBSITE;
     $imageLink = isset($_POST['imageLink']) ? $_POST['imageLink'] : '';
     $houseAd = new HouseAd();
     $houseAd->id = SDB::uuid();
     $houseAd->uid = $_SESSION['uid'];
     $houseAd->name = $name;
     $houseAd->description = $description;
     $houseAd->type = $type;
     $houseAd->link = HouseAdUtil::getFixedLink($link, $linkType);
     $houseAd->linkType = $linkType;
     $houseAd->launchType = HouseAdUtil::getLaunchType($linkType);
     $houseAd->imageLink = $imageLink;
     $result = $houseAd->put();
     $aids_of_apps_to_add = isset($_POST['apps']) ? $_POST['apps'] : null;
     AppHouseAdUtil::addRemoveAppHouseAds($houseAd->id, $aids_of_apps_to_add, array());
     fb($houseAd);
     $this->redirect($_REQUEST['returnPage'] . '?&n_cid=' . $houseAd->id . '&n_name=' . $houseAd->name . '&n_type=' . $houseAd->type . '&n_linkType=' . $houseAd->linkType);
 }
 public static function getNetworksByAidIndexNid($aid)
 {
     $sdb = SDB::getInstance();
     $domain = Network::$SDBDomain;
     $aaa = array();
     foreach (Network::$SDBFields as $field => $meta) {
         $aaa[] = $field;
     }
     $where = "where `aid` = '{$aid}'";
     if (!$sdb->select($domain, $aaa, $where)) {
         return null;
     }
     $appNetworks = array();
     foreach ($aaa as $aa) {
         $appNetwork = new Network();
         foreach (Network::$SDBFields as $field => $meta) {
             $appNetwork->{$field} = $aa[$field];
         }
         $appNetwork->id = $aa['id'];
         $appNetwork->postGet();
         $appNetworks[$appNetwork->id] = $appNetwork;
     }
     return $appNetworks;
 }
<?php

if (!count(SDB::get_tables_list())) {
    $sql = file_get_contents(BASE . '../common/examples.' . conf('db.type') . '.sql');
    if (conf('db.type') == 'mysql') {
        $spl = explode(';', $sql);
        foreach ($spl as $part) {
            $cmd = new SDBCommand($part);
            $cmd->execute();
        }
    } else {
        $cmd = new SDBCommand($sql);
        $cmd->execute();
    }
    SDB::reset_cached_data();
}
Example #13
0
 protected function update_positions($position = 0)
 {
     $parent_childs = $this->parent_node == null ? self::get_root_nodes() : $this->parent_node->childs;
     $replace_data = array();
     $pos = 1;
     foreach ($parent_childs as $nd) {
         if ($nd->id != $this->id) {
             if ($pos == $position) {
                 $pos++;
             }
             if ($nd->position != $pos) {
                 $replace_data[] = sprintf("(%s,%s,%s,%s,%s,%s,%s)", SDB::quote($nd->id), SDB::quote($nd->path), SDB::quote($nd->name), SDB::quote($nd->title), SDB::quote($nd->type), SDB::quote($nd->flags), SDB::quote($pos));
             }
             $pos++;
         }
     }
     if (count($replace_data)) {
         $cmd = new SDBCommand("REPLACE INTO `nodes` (`id`,`path`,`name`,`title`,`type`,`flags`,`position`) VALUES " . join(',', $replace_data));
         $cmd->execute();
     }
     return $pos;
 }
 public static function getAppsByCid($cid)
 {
     $sdb = SDB::getInstance();
     $domain = self::$SDBDomain_JOIN_AID;
     $aaa = array();
     foreach (self::$SDBFields_JOIN_AID as $field => $meta) {
         $aaa[] = $field;
     }
     $where = "where `cid` = '{$cid}'";
     if (!$sdb->select($domain, $aaa, $where)) {
         return null;
     }
     $apps = array();
     foreach ($aaa as $aa) {
         $aid = $aa['aid'];
         $weight = $aa['weight'];
         $app = new App($aid);
         if ($app != null) {
             $apps[] = $app;
         }
     }
     return $apps;
 }
Example #15
0
<?php

if (!isset($permittedCall)) {
    echo "Please don't open this page directly!";
    exit;
}
SDB::requireSDB("examplePlugin.sdb", "http://bennetthollstein.de/files/synchro/plugins/examplePlugin/examplePlugin.sdb");
// Include the scriptfile (site.script.php)
include scriptfile();
// Include the packages
include package("ownLog");
include package("multiSite2");
include package("tiles");
multiSite2_addPage("main", "pages/main.php");
multiSite2_addPage("test", "pages/test.php");
multiSite2_addPage("packageTester", "pages/packageTester.php");
include multiSite2_showSite();
Example #16
0
 public function adjustHouseAdNetwork($add_ahid, $del_ahid)
 {
     $retVal = "doNothing";
     fb("adjusthouseAdNet", "start");
     $networks = $this->getNetworks();
     if ($networks != null) {
         foreach ($networks as $type => $network) {
             if ($type == Network::NETWORK_TYPE_HOUSE) {
                 $houseAdNet = $network;
             }
         }
     }
     $appHouseAds = AppHouseAdUtil::getAppHouseAdsByAid($this->id);
     $count = count($appHouseAds);
     if ($count == 0 && $add_ahid != null) {
         $count++;
     } else {
         if ($count == 1 && $appHouseAds['0']->id == $del_ahid) {
             $count--;
         }
     }
     fb("appHouseAds", $appHouseAds);
     fb($count, 'count');
     fb(isset($houseAdNet), 'hasHouseAdNet');
     if ($count > 0 && !isset($houseAdNet)) {
         // add houseAdNet
         fb("Should Add");
         $network = new Network();
         $network->id = SDB::uuid();
         $network->aid = $this->id;
         $network->type = Network::NETWORK_TYPE_HOUSE;
         $network->adsOn = 0;
         $network->weight = 0;
         $network->priority = 99;
         $network->keys = array("_CUSTOMS_");
         $network->put();
         $retVal = "add";
     } else {
         if ($count == 0 && isset($houseAdNet)) {
             // should remove or turn off
             $hasHouseAds = count(HouseAdUtil::getHouseAdsByUid($_SESSION['uid'])) > 0;
             if ($hasHouseAds) {
                 fb("should turn off");
                 $houseAdNet->adsOn = 0;
                 $houseAdNet->put();
                 $retVal = "turnOff";
             } else {
                 fb("Should Remove", $houseAdNet);
                 $houseAdNet->delete();
                 unset($networks['9']);
                 $retVal = "delete";
             }
             App::setWeights($networks);
             App::setPriorities($networks);
         }
     }
     fb("adjustHouseAdNet", "end");
     return $retVal;
 }
 public static function confirmUser($uid)
 {
     $sdb = SDB::getInstance();
     $aaa = array('email', 'firstName', 'lastName', 'password', 'allowEmail');
     $sdb->select(self::$DOMAIN_USERS_UNVERIFIED, $aaa, "where itemName() = '{$uid}' limit 1", false);
     if (empty($aaa[0])) {
         return false;
     }
     $user = new User();
     $user->id = $uid;
     $user->email = $aaa[0]['email'];
     $user->password = $aaa[0]['password'];
     $user->allowEmail = $aaa[0]['allowEmail'];
     $user->firstName = $aaa[0]['firstName'];
     $user->lastName = $aaa[0]['lastName'];
     $user->put();
     return true;
 }
 public function __construct($command = '', $db = null)
 {
     $this->command = $command;
     $this->db = $db !== null ? $db : SDB::get_current();
 }
 protected function _init_fields()
 {
     if (count($this->_db_fields)) {
         return;
     }
     $this->_init_table();
     $cols = SDB::get_table_columns($this->_db_table);
     foreach (get_object_vars($this) as $prop => $val) {
         if ($prop[0] == '_' || $prop == $this->_db_key || is_array($val) || is_object($val) || $val === null) {
             continue;
         }
         if (!array_key_exists($prop, $cols)) {
             throw new Exception("Table '{$this->_db_table}' doesn't have field '{$prop}'");
         }
         $this->map_field($prop, $prop, $cols[$prop]['t'], $cols[$prop]['s']);
     }
     // map _db_key here, because get_object_vars not returns virtual properties
     $this->map_field($this->_db_key, $this->_db_key, $cols[$this->_db_key]['t'], $cols[$this->_db_key]['s']);
 }
 public static function invalidateCustom($nid)
 {
     $sdb = SDB::getInstance();
     $aa = array('dateTime' => gmdate('Y-m-d, H:i:s'));
     $sdb->put(HouseAd::$SDBDomainInvalid, $nid, $aa, true);
 }
Example #21
0
function require_SDB($name, $dlurl)
{
    return SDB::requireSDB($name, $dlurl);
}
Example #22
0
 public static function delete($entry)
 {
     return SDB::deleteValue(REGISTRY, $entry, ";;");
 }
Example #23
0
 protected function getDBConnect()
 {
     if ($this->_connect) {
         return $this->_connect;
     }
     $db = new SDB();
     $this->_connect = $db->getInstance();
     return $this->_connect;
 }
 public function createSubmit()
 {
     if (isset($_REQUEST['n_aid']) || !isset($_REQUEST['name'])) {
         $this->redirect('/apps/apps');
     }
     $this->printHeader = false;
     $this->printFooter = false;
     $name = $_POST['name'];
     $storeUrl = $_POST['storeUrl'];
     $platform = $_POST['platform'];
     $fgColor = $_POST['fgColor'];
     $bgColor = $_POST['bgColor'];
     $cycleTime = $_POST['cycleTime'];
     $transition = $_POST['transition'];
     $locationOn = $_POST['locationOn'];
     $app = new App();
     $app->id = SDB::uuid();
     $app->uid = $this->user->id;
     $app->name = $name;
     $app->storeUrl = $storeUrl;
     $app->platform = $platform;
     $app->fgColor = $fgColor;
     $app->bgColor = $bgColor;
     $app->cycleTime = $cycleTime;
     $app->transition = $transition;
     $app->locationOn = $locationOn;
     $app->adsOn = 1;
     $app->put();
     $_POST['aid'] = $app->id;
     // before finishing, check to see if the new app has been added to th SDB
     $sdb = SDB::getInstance();
     // sleeps for half a second until we see an entry for this id
     $fields = "name";
     while (!$sdb->get($app->getSDBDomain(), $app->id, $fields)) {
         $fields = "name";
         // necessary since get overwrites $fields
         usleep(500);
     }
 }
 public static function getAppHouseAdsByCid($cid)
 {
     $sdb = SDB::getInstance();
     $domain = self::$SDBDomain;
     $aaa = array();
     foreach (self::$SDBFields as $field => $meta) {
         $aaa[] = $field;
     }
     $where = "where `cid` = '{$cid}'";
     if (!$sdb->select($domain, $aaa, $where)) {
         return null;
     }
     $appHouseAds = array();
     foreach ($aaa as $aa) {
         $id = $aa['id'];
         $appHouseAd = new AppHouseAd($id);
         if ($appHouseAd != null) {
             $appHouseAds[] = $appHouseAd;
         }
     }
     return $appHouseAds;
 }
 public static function getNetworkReportsByUid($uid, $startDate, $endDate)
 {
     $sdb = SDB::getInstance();
     $apps = AppUtil::getAppsByUid($uid);
     $reports = array();
     foreach ($apps as $app) {
         $aid = $app->id;
         $aaa = array($groupBy, 'clicks', 'impressions', 'dateTime');
         $sdb->select(Report::$SDBDomain, $aaa, "where `aid` = '{$aid}' and `dateTime` >= '{$startDate}' and `dateTime` <= '{$endDate}'");
         if (empty($aaa)) {
             continue;
         }
         foreach ($aaa as $aa) {
             $dateTime = $aa['dateTime'];
             $type = $aa[$groupBy];
             $clicks = $aa['clicks'];
             $impressions = $aa['impressions'];
             $reports['types'][$type] = 1;
             if (isset($reports[$dateTime][$type])) {
                 $reports[$dateTime][$type]['clicks'] += $clicks;
                 $reports[$dateTime][$type]['impressions'] += $impressions;
             } else {
                 $reports[$dateTime][$type]['clicks'] = $clicks;
                 $reports[$dateTime][$type]['impressions'] = $impressions;
             }
             if (isset($reports[$dateTime][0])) {
                 $reports[$dateTime][0]['clicks'] += $clicks;
                 $reports[$dateTime][0]['impressions'] += $impressions;
             } else {
                 $reports[$dateTime][0] = array();
                 $reports[$dateTime][0]['clicks'] = $clicks;
                 $reports[$dateTime][0]['impressions'] = $impressions;
             }
         }
         return $reports;
     }
 }