/** * 生成文章页面 */ function article() { //读取总数 if (!$_SESSION['article']['total']) { $_SESSION['article']['total'] = (int) sf::getModel("articles")->getTotal("`is_html` = 0"); $_SESSION['article']['num'] = 0; } //生成静态页面 if ($_SESSION['article']['total'] == 0 || $_SESSION['article']['num'] >= $_SESSION['article']['total']) { $_SESSION['article']['num'] = 0; $_SESSION['article']['total'] = 0; exit('{total:1,num:1}'); } $result = sf::getModel("articles")->selectAll("is_html = 0", '', 1); while ($article = $result->getObject()) { view::set("article", $article); view::apply("inc_body", "template/article_show"); $htmlStr = view::parse("template/page"); $path = WEBROOT . "/html/" . $article->getTypeStr(); if (!is_dir($path)) { sf::getLib("Files")->mDir($path); exit('{total:' . $_SESSION['article']['total'] . ',num:0}'); } sf::getLib("Files")->write($path . "/article-show-" . $article->getId() . ".html", $htmlStr); $article->setIsHtml(1); $article->save(); $_SESSION['article']['num']++; } exit('{total:' . $_SESSION['article']['total'] . ',num:' . $_SESSION['article']['num'] . '}'); }
public function getJson($addWhere = '', $addSql = '', $showMax = 12) { $sort = input::getInput("mix.sort") ? input::getInput("mix.sort") : 'id'; $order = input::getInput("mix.order") ? input::getInput("mix.order") : "asc"; $page = input::getInput("mix.page") ? input::getInput("mix.page") : 1; $rows = input::getInput("mix.rows") ? input::getInput("mix.rows") : 10; $db = sf::getLib("db"); if ($select) { $sql = $select . " "; } else { $sql = "SELECT * FROM `" . $this->table . "` "; } $addWhere && ($sql .= "WHERE " . $addWhere . " "); if ($addSql) { $sql .= $addSql . " "; } else { $sql .= " ORDER BY {$sort} {$order} "; } if (!router::get("totalnum" . $key)) { $query = $db->query($sql); $total = $db->num_rows($query); } else { $total = router::get("totalnum" . $key); } $sql .= "LIMIT " . $rows * ($page - 1) . "," . $rows; $query = $db->query($sql); while ($row = $db->fetch_array($query)) { $result[] = $this->fillObject($row)->toArray(); } return '{"total":' . $total . ',"rows":' . json_encode($result) . '}'; }
function getTotal($where = '') { $db = sf::getLib("db"); $sql = 'SELECT `id` FROM `' . $this->table . '` '; $where && ($sql .= 'WHERE ' . $where); $query = $db->query($sql); return $db->num_rows($query); }
function rebuildTree() { $data = $this->getFormatList(); $db = sf::getLib("db"); for ($i = 0, $n = count($data); $i < $n; $i++) { $result = array("left" => $data[$i]['left'], "right" => $data[$i]['right'], "head_str" => $data[$i]['HeadStr'], "level" => $data[$i]['level']); $db->update($result, "id = '" . $data[$i]['id'] . "'", $this->table); } }
function showFields($table = 'test') { $db = sf::getLib("db"); $query = $db->query("SELECT * FROM `{$table}` limit 1 "); while ($field = $db->fetch_fields($query)) { $fileds[] = $field; } return $fileds; }
function selectByName($userName = '') { $db = sf::getLib("db"); $result = $db->fetch_first("SELECT * FROM " . $this->table . " WHERE `user_name` = '" . $userName . "'"); if ($result) { $this->fillObject($result); return $this; } else { return false; } }
public static function parse($tpl) { foreach (self::$viewTpl as $key => $file) { self::getContent($file, $key); } self::$content = self::getContent($tpl); if (config::get("auto_create_html", false)) { $file = $_SERVER[PATH_INFO]; if ($file) { $file = WEBROOT . $file; sf::getLib("Files")->write($file, self::$content); } } return self::$content; }
function isAuth() { $db = sf::getLib("db"); $result = $db->fetch_first("SELECT * FROM " . $this->table . " WHERE `controller` = '" . router::getController() . "' AND method = '" . router::getMethod() . "'"); if ($result) { if (sf::getPlugin("authentic")->isLogin($result['user_group_ids'])) { return true; } else { return false; } } else { $this->setController(router::getController()); $this->setControllerName(router::getController()); $this->setMethod(router::getMethod()); $this->setUserGroupIds("1"); $this->save(); return false; } }
/** * 上传文件 */ function upload() { $json = $msg = ''; if ($_FILES) { $upload_type = input::getInput("post.upload_type") ? explode(",", input::getInput("post.upload_type")) : config::get("upload_type", array('jpg', 'bmp', 'gif', 'bmp', 'rar', 'doc', 'xls', 'zip', 'swf')); $upload_size = input::getInput("post.upload_size") ? input::getInput("post.upload_size") : config::get("upload_size", "2097152"); $upload = sf::getLib("upload", "upload", config::get("upload_path", "./up_files/"), $upload_size, $upload_type); if ($upload->upload()) { $result = $upload->getSaveFileInfo(); foreach ($result as $files) { $filemanager = sf::getModel("filemanager"); $filemanager->setFileName($files['name']); $filemanager->setFileSavename($files['savename']); $filemanager->setFilePath($files['path']); $filemanager->setFileSize($files['size']); $filemanager->setFileExt($files['type']); $filemanager->setFileMinetype($files['minetype']); $filemanager->setUserId(input::session('userid')); $filemanager->setUserName(input::session('username')); $filemanager->setCreatedAt(date("Y-m-d H:i:s")); input::getInput("post.file_note") && $filemanager->setFileNote(input::getInput("post.file_note")); input::getInput("post.item_id") && $filemanager->setItemId(input::getInput("post.item_id")); input::getInput("post.item_type") && $filemanager->setItemType(input::getInput("post.item_type")); $file_id = $filemanager->save(); $a_json[] = "{file_name:'" . $files['name'] . "',file_savename:'" . $files['savename'] . "',path:'" . $files['path'] . "',id:'" . $file_id . "'}"; } $a_json && ($json = "[" . implode(",", $a_json) . "]"); } else { $msg = lang::get("Failure to upload files!"); } } $data["result"] = $result; $data["json"] = $json; $data["msg"] = $msg; $data["item_id"] = input::getInput("get.item_id") ? input::getInput("get.item_id") : 0; $data["item_type"] = input::getInput("get.item_type") ? input::getInput("get.item_type") : 'project'; $data["upload_type"] = input::getInput("get.type") ? input::getInput("get.type") : "jpg,png,gif,doc,xls,swf"; $data["upload_size"] = input::getInput("get.size") ? input::getInput("get.size") : "2097152"; view::set($data); view::apply("inc_body", "common/upload"); view::display("admin/page"); }
public static function parse($tpl) { foreach (self::$viewTpl as $key => $file) { self::getContent($file, $key); } self::$content = self::getContent($tpl); if (config::get("auto_create_html", false)) { $file = trim($_SERVER['PATH_INFO'], '/'); //是否需要获取token if (config::get('token_open', false) && config::get('parse_mode', 'PATH_INFO') == 'PATH_INFO') { $info = explode("/", $file); $token = array_shift($info); $file = implode('/', $info); } if ($file) { $file = WEBROOT . '/' . $file; sf::getLib("Files")->write($file, self::$content); } } return self::$content; }
public function getPager($addWhere = '', $addSql = '', $showMax = 20, $select = '', $key = '', $form_vars = array()) { $db = sf::getLib("db"); if ($select) { $sql = $select . " "; } else { $sql = "SELECT * FROM `" . $this->table . "` "; } $addWhere && ($sql .= "WHERE " . $addWhere . " "); $addSql && ($sql .= $addSql . " "); if (!router::get("totalnum" . $key)) { $query = $db->query($sql); $total = $db->num_rows($query); } else { $total = router::get("totalnum" . $key); } $pager = sf::getLib("pager", $total, $showMax, $key, $form_vars); $sql .= "LIMIT " . $pager->getStartNum() . "," . $pager->getShowNum(); $query = $db->query($sql); $pager->setField($db->result_array($query)); $pager->setObject(clone $this); return $pager; }
public function delete($where = "") { if (!$this->id) { return false; } $db = sf::getLib("db"); $db->query("DELETE FROM `{$this->table}` WHERE `id` = '{$this->id}' {$where} "); return $db->affected_rows(); }
/** * 取得缓存对象 */ public static function getCacheHandler() { return sf::getLib("cache", config::get("cache_dir", APPPATH . 'cache')); }
public function __construct() { sf::getLib("view"); }