Ejemplo n.º 1
0
 /**
  * Register a global variable called __fu_$var & also $var if requested.
  *
  * We use this so that we have vars we can rely upon (__fu_*) and optionally short
  * versions that the coder can use.
  *
  * Variables that have already been declared cannot be overwritten.
  *
  * @param string name of variable
  * @param mixed value of variable
  * @param bool if true will also set a global variable by the same name
  * @return mixed value of variable
  */
 function &set($k, $v, $reg_global = false)
 {
     $var_name = "__fu_{$k}";
     $GLOBALS[$var_name] =& $v;
     if ($reg_global) {
         $GLOBALS[$k] =& $GLOBALS[$var_name];
     }
     return Fu_Reg::get($k);
 }
Ejemplo n.º 2
0
 /**
  * Singleton should be used to save memory.
  * It keeps 1 global object that is used by BS for each type of DB object
  *
  * @param Fu_DB_Base based object
  * @return Fu_DB_Association object instance
  */
 public function singleton($class)
 {
     $instance = Fu_Reg::get("association_{$class}");
     if (is_null($instance)) {
         $instance = Fu_Reg::set("association_{$class}", new Fu_DB_Association($dbo));
     } else {
         // as we are restoring this object from the global register, we freeze it
         $instance->frozen = true;
     }
     return $instance;
 }
Ejemplo n.º 3
0
 public function debug($s = null, $p = array())
 {
     if (!(isset($this) && get_class($this) == __CLASS__)) {
         $instance = Fu_Reg::get("fu_db_debug");
         return $instance->debug($s, $p);
     }
     if ($this->debug) {
         if ($s) {
             $this->info[] = array('sql' => $s, 'params' => $p);
         } else {
             return $this->info;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Will return the text of the first flash message that matches the given type.
  *
  * E.g. Fu_Feedback::get_flash('warning')
  *
  * @param string type
  * @return string text
  */
 function get_flash($type = 'message')
 {
     if (!(isset($this) && get_class($this) == __CLASS__)) {
         $instance = Fu_Reg::get("fu_feedback");
         return $instance->get_flash($type);
     }
     foreach ((array) $this->flashes as $flash) {
         if ($flash['type'] == $type) {
             return $flash['text'];
         }
     }
     return '';
 }
Ejemplo n.º 5
0
Archivo: DB.php Proyecto: kelvinj/Giiki
 public static function rollback()
 {
     $depth = (int) Fu_Reg::get('Fu_DB_Transaction_Depth');
     Fu_Reg::set('Fu_DB_Transaction_Depth', $depth - 1);
     if ($depth > 1) {
         return;
     } else {
         // at the root transaction
         $dbh = Fu_Reg::get('dbh');
         $dbh->rollback();
     }
 }
Ejemplo n.º 6
0
 function _check_installation()
 {
     $errors = array();
     do {
         if (!is_writable($this->data_dir)) {
             $errors[] = "Data directory not writeable ({$this->data_dir})";
             break;
         }
         if (!is_dir($this->data_dir . '/.git')) {
             // no git install, try to fix
             if (!file_exists($this->data_dir . '/.gitignore')) {
                 // pop a git ignore file in to ignore the sql db
                 file_put_contents($this->data_dir . '/.gitignore', ".DS_Store\n*.db\n");
             }
             if ($this->git->init()) {
                 exec('chmod -R 0777 ' . $this->data_dir);
                 $this->git->add_all_commit('adding existing pages');
             } else {
                 $errors[] = "Could not initialize git repository ({$this->data_dir}/.git)";
             }
         }
         if (!file_exists($this->data_dir . '/.sqlite.db')) {
             // no sql db
             if (!copy(ROOT . '/giiki/virgin.db', $this->data_dir . '/.sqlite.db')) {
                 $errors[] = "Could not copy SQLite database ({$this->data_dir}/.sqlite.db)";
             } else {
                 Fu_Reg::set('dbh', new PDO($this->dsn));
                 $dbo = new DB_User();
                 $admin_user = $dbo->find(1);
                 $admin_user->rand_token();
                 $admin_user->save();
             }
         }
     } while (0);
     if ($errors) {
         echo implode('<br />', $errors);
         exit;
     }
 }