Пример #1
0
 private function home()
 {
     Doo::loadHelper('DooFile');
     $f = new DooFile();
     $list = $f->getList($this->plugin_dir, DooFile::LIST_FOLDER);
     $ps = array();
     if ($list) {
         foreach ($list as $k => $v) {
             $rs['name'] = $f->readFileContents($v['path'] . '/readme.txt');
             $rs['ico'] = '/' . ADMIN_ROOT . '/' . Doo::conf()->PROTECTED_FOLDER . 'plugin/' . $v['name'] . '/ico.png';
             $rs['act'] = $v['name'];
             $ps[$v['name']] = $rs;
         }
     }
     include Lua::display('plugin', $this->dir);
 }
Пример #2
0
 /**
  * Parse and compile the template file. Templates generated in protected/viewc folder
  * @param string $file Template file name without extension .html
  * @param string $vfilename Full path of the template file
  * @param string $cfilename Full path of the compiled file to be saved
  */
 protected function compile($file, $vfilename, $cfilename)
 {
     $this->mainRenderFolder = $file;
     //--------------------------- Parsing -----------------------------
     //if no compiled file exist or compiled file is older, generate new one
     $str = $this->compileTags(file_get_contents($vfilename));
     Doo::loadHelper('DooFile');
     $fileManager = new DooFile(0777);
     $fileManager->create($cfilename, $str, 'w+');
 }
Пример #3
0
 /**
  * Provides auto loading feature. To be used with the Magic method __autoload
  * @param string $classname Class name to be loaded.
  */
 public static function autoload($classname)
 {
     //        if( class_exists($classname, false) === true )
     //			return;
     //app
     $class['DooConfig'] = 'app/DooConfig';
     $class['DooSiteMagic'] = 'app/DooSiteMagic';
     $class['DooWebApp'] = 'app/DooWebApp';
     //auth
     $class['DooAcl'] = 'auth/DooAcl';
     $class['DooAuth'] = 'auth/DooAuth';
     $class['DooDigestAuth'] = 'auth/DooDigestAuth';
     $class['DooRbAcl'] = 'auth/DooRbAcl';
     //cache
     $class['DooApcCache'] = 'cache/DooApcCache';
     $class['DooEAcceleratorCache'] = 'cache/DooEAcceleratorCache';
     $class['DooFileCache'] = 'cache/DooFileCache';
     $class['DooFrontCache'] = 'cache/DooFrontCache';
     $class['DooMemCache'] = 'cache/DooMemCache';
     $class['DooPhpCache'] = 'cache/DooPhpCache';
     $class['DooXCache'] = 'cache/DooXCache';
     //controller
     $class['DooController'] = 'controller/DooController';
     //db
     $class['DooDbExpression'] = 'db/DooDbExpression';
     $class['DooMasterSlave'] = 'db/DooMasterSlave';
     $class['DooModel'] = 'db/DooModel';
     $class['DooModelGen'] = 'db/DooModelGen';
     $class['DooSmartModel'] = 'db/DooSmartModel';
     $class['DooSqlMagic'] = 'db/DooSqlMagic';
     //db/manage
     $class['DooDbUpdater'] = 'db/manage/DooDbUpdater';
     $class['DooManageDb'] = 'db/manage/DooManageDb';
     $class['DooManageMySqlDb'] = 'db/manage/adapters/DooManageMySqlDb';
     $class['DooManagePgSqlDb'] = 'db/manage/adapters/DooManagePgSqlDb';
     $class['DooManageSqliteDb'] = 'db/manage/adapters/DooManageSqliteDb';
     //helper
     $class['DooBenchmark'] = 'helper/DooBenchmark';
     $class['DooFile'] = 'helper/DooFile';
     $class['DooFlashMessenger'] = 'helper/DooFlashMessenger';
     $class['DooForm'] = 'helper/DooForm';
     $class['DooGdImage'] = 'helper/DooGdImage';
     $class['DooMailer'] = 'helper/DooMailer';
     $class['DooPager'] = 'helper/DooPager';
     $class['DooRestClient'] = 'helper/DooRestClient';
     $class['DooTextHelper'] = 'helper/DooTextHelper';
     $class['DooTimezone'] = 'helper/DooTimezone';
     $class['DooUrlBuilder'] = 'helper/DooUrlBuilder';
     $class['DooValidator'] = 'helper/DooValidator';
     //logging
     $class['DooLog'] = 'logging/DooLog';
     //session
     $class['DooCacheSession'] = 'session/DooCacheSession';
     $class['DooSession'] = 'session/DooSession';
     //translate
     $class['DooTranslator'] = 'translate/DooTranslator';
     //uri
     $class['DooLoader'] = 'uri/DooLoader';
     $class['DooUriRouter'] = 'uri/DooUriRouter';
     //view
     $class['DooView'] = 'uri/DooView';
     $class['DooViewBasic'] = 'uri/DooViewBasic';
     if (isset($class[$classname])) {
         self::loadCore($class[$classname]);
     } else {
         if (isset(Doo::conf()->PROTECTED_FOLDER_ORI) === true) {
             $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER_ORI;
         } else {
             $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER;
         }
         if (empty(Doo::conf()->AUTOLOAD) === false) {
             if (Doo::conf()->APP_MODE == 'dev') {
                 $includeSub = Doo::conf()->AUTOLOAD;
                 $rs = array();
                 foreach ($includeSub as $sub) {
                     if (file_exists($sub) === false) {
                         if (file_exists($path . $sub) === true) {
                             $rs = array_merge($rs, DooFile::getFilePathList($path . $sub . '/'));
                         }
                     } else {
                         $rs = array_merge($rs, DooFile::getFilePathList($sub . '/'));
                     }
                 }
                 $autoloadConfigFolder = $path . 'config/autoload/';
                 $rsExisting = null;
                 if (file_exists($autoloadConfigFolder . 'autoload.php') === true) {
                     $rsExisting = (include $autoloadConfigFolder . 'autoload.php');
                 }
                 if ($rs != $rsExisting) {
                     if (!file_exists($autoloadConfigFolder)) {
                         mkdir($autoloadConfigFolder);
                     }
                     file_put_contents($autoloadConfigFolder . 'autoload.php', '<?php return ' . var_export($rs, true) . ';');
                 }
             } else {
                 $rs = (include_once $path . 'config/autoload/autoload.php');
             }
             if (isset($rs[$classname . '.php']) === true) {
                 require_once $rs[$classname . '.php'];
                 return;
             }
         }
         //autoloading namespaced class
         if (isset(Doo::conf()->APP_NAMESPACE_ID) === true && strpos($classname, '\\') !== false) {
             $pos = strpos($classname, Doo::conf()->APP_NAMESPACE_ID);
             if ($pos === 0) {
                 $classname = str_replace('\\', '/', substr($classname, strlen(Doo::conf()->APP_NAMESPACE_ID) + 1));
                 require_once $path . $classname . '.php';
             }
         }
     }
 }
Пример #4
0
 public static function genPgSQL($path = null)
 {
     if ($path === null) {
         $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . 'model/';
     }
     Doo::loadHelper('DooFile');
     $fileManager = new DooFile(0777);
     $dbconf = Doo::db()->getDefaultDbConfig();
     $dbSchema = $dbconf[6];
     $dbname = $dbconf[1];
     echo "<html><head><title>DooPHP Model Generator - DB: {$dbname}</title></head><body bgcolor=\"#2e3436\">";
     $smt = Doo::db()->query("SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = '{$dbSchema}'");
     $tables = $smt->fetchAll();
     foreach ($tables as $tbl) {
         $tblname = $tbl["name"];
         //tablename
         //Get table description
         $smt2 = Doo::db()->query("SELECT DISTINCT column_name AS name, data_type AS type, is_nullable AS null,\n                column_default AS default, ordinal_position AS position, character_maximum_length AS char_length,\n                character_octet_length AS oct_length FROM information_schema.columns\n                WHERE table_name = '{$tblname}' AND table_schema = '{$dbSchema}'   ORDER BY position");
         $fields = $smt2->fetchAll();
         //Get primary key
         $smt3 = Doo::db()->query("SELECT relname, indkey\n                  FROM pg_class, pg_index\n                 WHERE pg_class.oid = pg_index.indexrelid\n                   AND pg_class.oid IN (\n                    SELECT indexrelid\n                      FROM pg_index, pg_class\n                     WHERE pg_class.relname='{$tblname}'\n                       AND pg_class.oid=pg_index.indrelid\n                       AND indisprimary = 't')");
         //indkey
         $fields3 = $smt3->fetchAll();
         $smt4 = Doo::db()->query("SELECT t.relname, a.attname, a.attnum\n                     FROM pg_index c\n                LEFT JOIN pg_class t\n                       ON c.indrelid  = t.oid\n                LEFT JOIN pg_attribute a\n                       ON a.attrelid = t.oid\n                      AND a.attnum = ANY(indkey)\n                    WHERE t.relname = '{$tblname}'\n                      AND a.attnum = {$fields3[0]['indkey']}");
         $fields4 = $smt4->fetchAll();
         $pkey = $fields4[0]['attname'];
         //Prepare model class
         $classname = '';
         $temptbl = $tblname;
         for ($i = 0; $i < strlen($temptbl); $i++) {
             if ($i == 0) {
                 $classname .= strtoupper($temptbl[0]);
             } else {
                 if ($temptbl[$i] == '_' || $temptbl[$i] == '-' || $temptbl[$i] == '.') {
                     $classname .= strtoupper($temptbl[$i + 1]);
                     $arr = str_split($temptbl);
                     array_splice($arr, $i, 1);
                     $temptbl = implode('', $arr);
                 } else {
                     $classname .= $temptbl[$i];
                 }
             }
         }
         $filestr = "<?php\nclass {$classname}{\n";
         $fieldnames = array();
         foreach ($fields as $f) {
             $filestr .= "    public \${$f['name']};\n";
             $fieldnames[] = $f['name'];
         }
         $fieldnames = implode($fieldnames, "','");
         $filestr .= "    public \$_table = '{$tblname}';\n";
         $filestr .= "    public \$_primarykey = '{$pkey}';\n";
         $filestr .= "    public \$_fields = array('{$fieldnames}');\n";
         $filestr .= "}\n?>";
         if ($fileManager->create($path . "{$classname}.php", $filestr, 'w+')) {
             echo "<span style=\"font-size:190%;font-family: 'Courier New', Courier, monospace;\"><span style=\"color:#fff;\">Model for table </span><strong><span style=\"color:#e7c118;\">{$tblname}</span></strong><span style=\"color:#fff;\"> generated. File - </span><strong><span style=\"color:#729fbe;\">{$classname}</span></strong><span style=\"color:#fff;\">.php</span></span><br/><br/>";
         } else {
             echo "<span style=\"font-size:190%;font-family: 'Courier New', Courier, monospace;\"><span style=\"color:#f00;\">Model for table </span><strong><span style=\"color:#e7c118;\">{$tblname}</span></strong><span style=\"color:#f00;\"> could not be generated. File - </span><strong><span style=\"color:#729fbe;\">{$classname}</span></strong><span style=\"color:#f00;\">.php</span></span><br/><br/>";
         }
     }
     $total = sizeof($tables);
     echo "<span style=\"font-size:190%;font-family: 'Courier New', Courier, monospace;color:#fff;\">Total {$total} file(s) generated.</span></body></html>";
 }
Пример #5
0
 /**
  * Save the uploaded image(s) in HTTP File Upload variables
  * 
  * @param string $filename The file field name in $_FILES HTTP File Upload variables
  * @param string $rename Rename the uploaded file (without extension)
  * @return string|array The file name of the uploaded image.
  */
 public function uploadImage($filename, $rename = '')
 {
     $img = !empty($_FILES[$filename]) ? $_FILES[$filename] : null;
     if ($img == Null) {
         return;
     }
     if (!file_exists($this->uploadPath)) {
         Doo::loadHelper('DooFile');
         $fileManager = new DooFile(0777);
         $fileManager->create($this->uploadPath);
     }
     if (is_array($img['name']) === False) {
         $pic = strrpos($img['name'], '.');
         $ext = strtolower(substr($img['name'], $pic + 1));
         if ($this->timeAsName) {
             $newName = time() . '-' . mt_rand(1000, 9999) . '.' . $ext;
         } else {
             $newName = $img['name'];
         }
         if ($rename == '') {
             $imgPath = $this->uploadPath . $newName;
         } else {
             $imgPath = $this->uploadPath . $rename . '.' . $ext;
         }
         if (move_uploaded_file($img['tmp_name'], $imgPath)) {
             return $rename == '' ? $newName : $rename . '.' . $ext;
         }
     } else {
         $uploadImagesPath = array();
         foreach ($img['error'] as $k => $error) {
             if (empty($img['name'][$k])) {
                 continue;
             }
             if ($error == UPLOAD_ERR_OK) {
                 $pic = strrpos($img['name'][$k], '.');
                 $ext = strtolower(substr($img['name'][$k], $pic + 1));
                 if ($this->timeAsName) {
                     $newName = time() . '-' . mt_rand(1000, 9999) . '_' . $k . '.' . $ext;
                 } else {
                     $newName = $img['name'][$k];
                 }
                 if ($rename == '') {
                     $imgPath = $this->uploadPath . $newName;
                 } else {
                     $imgPath = $this->uploadPath . $rename . '_' . $k . '.' . $ext;
                 }
                 if (move_uploaded_file($img['tmp_name'][$k], $imgPath)) {
                     $uploadImagesPath[] = $newName;
                 }
             } else {
                 return false;
             }
         }
         return $uploadImagesPath;
     }
 }
Пример #6
0
 /**
  * Write to file.
  * If rotate file size is set, logs and profiles are automatically rotate when the file size is reached.
  * @param string $data Data string to be logged
  * @param string $filename File name for the log/profile
  */
 protected function writeToFile($data, $filename)
 {
     //only write to file if there's a record
     if ($data != NULL) {
         $mode = 'a+';
         if (isset(Doo::conf()->LOG_PATH)) {
             $filename = Doo::conf()->LOG_PATH . $filename;
         }
         if ($this->rotate_size != 0) {
             if (file_exists($filename) && filesize($filename) > $this->rotate_size) {
                 $mode = 'w+';
             }
         }
         Doo::loadHelper('DooFile');
         $file = new DooFile(0777);
         $file->create($filename, $data, $mode);
     }
 }
Пример #7
0
 /**
  * Write to file.
  * If rotate file size is set, logs and profiles are automatically rotate when the file size is reached.
  * @param string $data Data string to be logged
  * @param string $filename File name for the log/profile
  */
 protected function writeToFile($data, $filename)
 {
     //aising 20151020 logpath addpend category
     $subPath = '';
     if (isset($this->_logs[0][2])) {
         $subPath = $this->_logs[0][2];
     }
     $filename = $subPath . DIRECTORY_SEPARATOR . $filename;
     //only write to file if there's a record
     if ($data != NULL) {
         $mode = 'a+';
         if (isset(Doo::conf()->LOG_PATH)) {
             $filename = Doo::conf()->LOG_PATH . $filename;
         }
         if ($this->rotate_size != 0) {
             if (file_exists($filename) && filesize($filename) > $this->rotate_size) {
                 $mode = 'w+';
             }
         }
         Doo::loadHelper('DooFile');
         $file = new DooFile(0777);
         $file->create($filename, $data, $mode);
     }
 }
Пример #8
0
 private function _len($table)
 {
     $config = Doo::db()->getDefaultDbConfig();
     $db = Doo::db()->fetchRow("show table status from " . $config[1] . " like '{$table}'");
     $db['free'] = DooFile::formatBytes($db['Data_free']);
     $db['length'] = DooFile::formatBytes($db['Index_length'] + $db['Data_length']);
     $db['nums'] = $db['Rows'];
     return $db;
 }
 /**
  * Save the result into file system in JSON format. By default, it creates and stores in a folder named 'bdd_result'
  * @param string $path Path to store the results.
  * @param bool $flatten To flatten the result. If true, everything will be saved in a single file. Else, it will be stored seperately with its section name.
  */
 protected function saveResult($path = null, $flatten = true)
 {
     if ($path === null) {
         $path = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . 'bdd_result/';
     }
     if ($flatten) {
         $f = new DooFile();
         $f->create($path . '/all_results.json', $this->toJSON($this->flattenResult()));
     } else {
         foreach ($this->result as $section => $rs) {
             $f = new DooFile();
             $f->create($path . '/' . $section . '.json', $this->toJSON($rs));
         }
     }
 }
Пример #10
0
 private function import()
 {
     set_time_limit(0);
     $path = Lua::get('path');
     $path = LUA_ROOT . $path . '/cache/update/';
     if (!file_exists($path)) {
         Lua::admin_msg('错误提示', '安装目录不存在');
     }
     // 第一步 频道数据
     $file = $path . 'channel.php';
     include $file;
     $data = $data[1];
     unset($data['id']);
     $data['createtime'] = time();
     $data['isdefault'] = 0;
     $channel_id = Lua::insert('lua_channel', $data);
     // 第二步 导入数据结构
     $file = $path . 'create.php';
     include $file;
     // 第三步 模型数据
     unset($data);
     $file = $path . 'model.php';
     include $file;
     $models = $data[1];
     $new_models = array();
     $new_tables_1 = array();
     // 栏目
     $new_tables_2 = array();
     // 碎片
     $new_tables_3 = array();
     // 插件
     unset($data);
     foreach ($models as $v) {
         $model_id = $v['id'];
         unset($v['id']);
         $v['createtime'] = time();
         $v['cid'] = $channel_id;
         $lastid = Lua::insert('lua_model', $v);
         $new_models[$model_id] = $lastid;
         // 第四步 数据表数据
         $file = $path . 'model.' . $model_id . '.php';
         include $file;
         $table = $data[1];
         switch ($v['mtype']) {
             case 1:
                 $new_tables_1 = array_merge($new_tables_1, $table);
                 break;
             case 2:
                 $new_tables_2 = array_merge($new_tables_2, $table);
                 break;
             case 3:
                 $new_tables_3 = array_merge($new_tables_3, $table);
                 break;
         }
         $this->__import($model_id, $lastid, $table, $path);
     }
     // 第七步 栏目数据
     $file = $path . 'cate.php';
     include $file;
     $cate = $data[1];
     $this->__cate(1, $new_models, $cate, $new_tables_1);
     unset($data);
     $file = $path . 'piece.php';
     include $file;
     $cate = $data[1];
     $this->__cate(2, $new_models, $cate, $new_tables_2);
     Doo::loadHelper('DooFile');
     $fileManager = new DooFile(0777);
     $fileManager->delete($path);
     Lua::admin_msg('信息提示', '导入成功', './channel.htm');
 }
Пример #11
0
 public function _doit()
 {
     $dirs = date('Y-m-d');
     $path = $this->cache . $dirs . '/';
     $configFile = $path . 'config.php';
     Doo::loadHelper('DooFile');
     $fileManager = new DooFile(0777);
     if (!file_exists($configFile)) {
         if (!file_exists($path)) {
             $fileManager->create($path);
         }
         $tables = Doo::db()->fetchAll("SHOW TABLE STATUS");
         $b_table = $d_table = '';
         foreach ($tables as $row) {
             $b_table .= $row['Name'] . ",";
             $d_table .= "\$tb['" . $row['Name'] . "']=0;\r\n";
         }
         $b_table = substr($b_table, 0, strlen($b_table) - 1);
         $string = "<?php\r\n\$b_table=\"" . $b_table . "\";\r\n" . $d_table . "?>";
         $fileManager->create($configFile, $string);
         $this->jsonp('写入配置文件 ...');
     } else {
         include $configFile;
     }
     $btb = explode(",", $b_table);
     $count = count($btb);
     $t = intval(Lua::post('t'));
     $s = intval(Lua::post('s'));
     $p = intval(Lua::post('p'));
     $alltotal = intval(Lua::post('alltotal'));
     $fnum = intval(Lua::post('fnum'));
     $dumpsql = '';
     if ($t >= $count) {
         echo 'success';
         exit;
     }
     if (empty($s)) {
         $num = Doo::db()->fetchRow("SHOW TABLE STATUS LIKE '" . $btb[$t] . "';");
         $num = $num['Rows'];
         $dumpsql .= "self::query(\"DROP TABLE IF EXISTS `" . $btb[$t] . "`;\");\r\n";
         Doo::db()->query("SET SQL_QUOTE_SHOW_CREATE=1");
         $r = Doo::db()->fetchRow("SHOW CREATE TABLE `" . $btb[$t] . "`;");
         $create = str_replace("\"", "\\\"", $r['Create Table']);
         $dumpsql .= "self::create(\"" . $create . "\");\r\n";
     } else {
         $num = (int) $alltotal;
     }
     $fields = Doo::db()->fetchAll("SHOW FIELDS FROM `" . $btb[$t] . "`");
     if (empty($fnum)) {
         $field_num = count($fields);
     } else {
         $field_num = $fnum;
     }
     $b = 0;
     $list = Doo::db()->fetchAll("select * from `" . $btb[$t] . "` limit {$s},{$num}");
     if ($list) {
         foreach ($list as $v) {
             $b = 1;
             $s++;
             $dumpsql .= "self::query(\"replace into `" . $btb[$t] . "` values(";
             $first = 1;
             for ($i = 0; $i < $field_num; $i++) {
                 if (empty($first)) {
                     $dumpsql .= ',';
                 } else {
                     $first = 0;
                 }
                 $_field_name = $fields[$i]['Field'];
                 if (!isset($v[$_field_name])) {
                     $dumpsql .= 'NULL';
                 } else {
                     $dumpsql .= '\'' . Lua::clean($v[$_field_name]) . '\'';
                 }
             }
             $dumpsql .= ");\");\r\n";
             if (strlen($dumpsql) >= 2048 * 1024) {
                 $p++;
                 $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php";
                 $fileManager->create($sfile, "<?php\r\n" . $dumpsql . "?>");
                 $this->jsonp('Table Name&nbsp;:&nbsp;<b>' . $btb[$t] . '</b><br />Table&nbsp;:&nbsp;<b>' . ($t + 1) . '/' . $count . '</b><br />Record&nbsp;:&nbsp;<b>' . $s . '/' . $num . '</b><br />备份一组数据成功,正在进入下一组......', $s, $p, $t, $alltotal, $fnum);
             }
         }
     }
     if (empty($p) || $b == 1) {
         $p++;
         $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php";
         $fileManager->create($sfile, "<?php\r\n" . $dumpsql . "?>");
     }
     if (empty($p)) {
         $p = 0;
     }
     $text = $fileManager->readFileContents($configFile);
     $rep1 = "\$tb['" . $btb[$t] . "']=0;";
     $rep2 = "\$tb['" . $btb[$t] . "']=" . $p . ";";
     $text = str_replace($rep1, $rep2, $text);
     $fileManager->create($configFile, $text);
     $t++;
     $this->jsonp('备份' . $btb[$t - 1] . '表成功,正在进入下一个表备份......', 0, 0, $t, 0, 0);
 }