Beispiel #1
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+');
 }
Beispiel #2
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;
     }
 }
Beispiel #3
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>";
 }
Beispiel #4
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);
     }
 }
Beispiel #5
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);
     }
 }
 /**
  * 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));
         }
     }
 }
Beispiel #7
0
 private function export()
 {
     set_time_limit(0);
     $id = Lua::get('id');
     $id = intval($id);
     $db = Lua::get_one("select * from lua_channel where id='{$id}'");
     if (empty($db)) {
         Lua::admin_msg('错误提示', '所要导出的频道不存在');
     }
     Doo::loadHelper('DooFile');
     $fileManager = new DooFile(0777);
     Doo::cache('php')->hashing = false;
     $old_dir = LUA_ROOT . ADMIN_ROOT . '/cache/';
     // 第一步 频道数据
     Doo::cache('php')->set('channel', $db);
     // 第二步 模型数据
     $list = Lua::get_more("select * from lua_model where cid='{$id}'");
     Doo::cache('php')->set('model', $list);
     // 第三步 数据表数据
     if ($list) {
         $dumpsql = '';
         Doo::db()->query("SET SQL_QUOTE_SHOW_CREATE=1");
         foreach ($list as $v) {
             $table = Lua::get_more("select * from lua_model_table where model_id='" . $v['id'] . "'");
             Doo::cache('php')->set('model.' . $v['id'], $table);
             // 第四步 字段数据
             if ($table) {
                 foreach ($table as $k) {
                     $field = Lua::get_more("select * from lua_model_field where model_id='" . $v['id'] . "' and table_id='" . $k['id'] . "'");
                     Doo::cache('php')->set('field.' . $v['id'] . '.' . $k['id'], $field);
                     // 第五步 创建数据表
                     $r = Doo::db()->fetchRow("SHOW CREATE TABLE `" . $k['tablename'] . "`;");
                     $create = str_replace("\"", "\\\"", $r['Create Table']);
                     $dumpsql .= "\r\nDoo::db()->query(\"" . $create . "\");\r\n";
                     // 第六步 导出数据
                     $data = Lua::get_more("select * from " . $k['tablename']);
                     Doo::cache('php')->set('data.' . $k['id'], $data);
                 }
             }
         }
         $fileManager->create($old_dir . 'create.php', '<?php' . $dumpsql . '?>');
     }
     // 第七步 栏目数据
     $list = Lua::get_more("select * from lua_category where systemname='" . $db['path'] . "'");
     Doo::cache('php')->set('cate', $list);
     $list = Lua::get_more("select * from lua_piece where systemname='" . $db['path'] . "'");
     Doo::cache('php')->set('piece', $list);
     // 第八步 打包数据
     $new_dir = LUA_ROOT . $db['path'] . '/cache/update/';
     $fileManager->copy($old_dir, $new_dir);
     // 第九步 删除数据
     $fileManager->delete($old_dir, false);
     Lua::admin_msg('提示信息', '导出成功', './channel.htm');
 }
Beispiel #8
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);
 }