📄 cms.class.inc
字号:
{ $this->get_folders($folder_id); } while($this->next_record()) { if($this->f('acl')==0 || $GO_SECURITY->has_permission($user_id, $this->f('acl'))) { $folders[]=$this->Record; } } return $folders; } function get_authorized_items($folder_id, $user_id, $only_visible=false) { $items = array(); $folders = $this->get_authorized_folders($folder_id, $user_id, $only_visible); foreach($folders as $folder) { $items[$folder['priority']] = $folder; } $files = $this->get_authorized_files($folder_id, $user_id); foreach($files as $file) { $items[$file['priority']] = $file; } ksort($items); return $items; } function get_items($folder_id, $only_visible=false) { $items = array(); if($only_visible) { $this->get_visible_folders($folder_id); }else { $this->get_folders($folder_id); } while($this->next_record()) { $items[$this->f('priority')] = $this->Record; } $this->get_files($folder_id); while($this->next_record()) { $items[$this->f('priority')] = $this->Record; } ksort($items); return $items; } function add_folder($parent_id, $name, $disabled=false, $template_item_id=0) { $disabled = $disabled ? '1' : '0'; $folder_id = $this->nextid('cms_folders'); if ($folder_id > 0) { $priority = $this->get_next_priority($parent_id); $mtime = $ctime = get_gmt_time(); if($this->query("INSERT INTO cms_folders (id, parent_id, name, ctime, mtime, priority, ". "disabled, template_item_id) VALUES ('$folder_id', '$parent_id', '$name', '$ctime', ". "'$mtime', '$priority', '$disabled', '$template_item_id')")) { return $folder_id; } } return false; } function get_folder($folder_id) { $this->query("SELECT * FROM cms_folders WHERE id='$folder_id';"); if ($this->next_record()) { return $this->Record; } return false; } function update_folder($folder_id, $name, $disabled, $multipage=false, $template_item_id=0, $acl=0) { $sql = "UPDATE cms_folders SET name='$name', mtime='".get_gmt_time(). "', disabled='$disabled', ". "multipage='$multipage', template_item_id='$template_item_id', acl='$acl' WHERE id='$folder_id'"; return $this->query($sql); } function folder_exists($parent_id, $name) { $this->query("SELECT id FROM cms_folders WHERE parent_id='$parent_id' AND name='$name'"); if($this->next_record()) { return $this->f('id'); } return false; } function delete_folder($folder_id) { if ($folder_id > 0) { //add a second cms object for simultanious select and delete from the db $cms2 = new cms(); //get all folders $this->get_folders($folder_id); while($this->next_record()) { if (!$cms2->delete_folder($this->f('id'))) { return false; } } $this->get_files($folder_id); while ($this->next_record()) { if(!$cms2->delete_file($this->f('id'))) { return false; } } return $this->query("DELETE FROM cms_folders WHERE id='$folder_id'"); }else { return false; } } function delete_file($file_id) { return $this->query("DELETE FROM cms_files WHERE id='$file_id'"); } function get_file($file_id) { $this->query("SELECT * FROM cms_files WHERE id='$file_id'"); if ($this->next_record()) { return $this->Record; } return false; } function reset_priorities($folder_id) { $items = $this->get_items($folder_id); $newpriority=0; foreach($items as $item) { $update_item['id']=$item['id']; $update_item['priority']=$newpriority; if (isset ($item['extension'])) { $this->update_row('cms_files','id',$update_item); }else { $this->update_row('cms_folders','id',$update_item); } $newpriority++; } } function get_next_priority($folder_id) { $sql = "SELECT max(priority) FROM cms_folders WHERE parent_id='$folder_id'"; $this->query($sql); if($this->next_record()) { $max_folder_priority = $this->f(0); } $sql = "SELECT max(priority) FROM cms_files WHERE folder_id='$folder_id'"; $this->query($sql); if($this->next_record()) { $max_file_priority = $this->f(0); } $priority = $max_file_priority > $max_folder_priority ? $max_file_priority : $max_folder_priority; return $priority+1; } function update_file_priority($file_id, $priority) { $sql = "UPDATE cms_files SET priority='$priority' WHERE id='$file_id'"; return $this->query($sql); } function update_folder_priority($folder_id, $priority) { $sql = "UPDATE cms_folders SET priority='$priority' WHERE id='$folder_id'"; return $this->query($sql); } function move_folder_up($folder_id) { if($folder = $this->get_folder($folder_id)) { $old_priority = $folder['priority']; $new_priority = $folder['priority']-1; $hp = $this->find_priority($folder['parent_id'], $new_priority); $sql = "UPDATE cms_folders SET priority='$new_priority' WHERE id='$folder_id'"; $this->query($sql); if($hp) { $sql = "UPDATE cms_".$hp['type']."s SET priority='$old_priority' WHERE id='".$hp['id']."'"; $this->query($sql); } } } function move_folder_top($folder_id) { $update_folder['id']=$folder_id; $update_folder['priority']=-1; $this->update_row('cms_folders','id',$update_folder); $folder = $this->get_folder($folder_id); $this->reset_priorities($folder['parent_id']); } function move_file_top($file_id) { $update_file['id']=$file_id; $update_file['priority']=-1; $this->update_row('cms_files','id',$update_file); $file = $this->get_file($file_id); $this->reset_priorities($file['folder_id']); } function move_file_up($file_id) { if($file = $this->get_file($file_id)) { $old_priority = $file['priority']; $new_priority = $file['priority']-1; $hp = $this->find_priority($file['folder_id'], $new_priority); $sql = "UPDATE cms_files SET priority='$new_priority' WHERE id='$file_id'"; $this->query($sql); if($hp) { $sql = "UPDATE cms_".$hp['type']."s SET priority='$old_priority' WHERE id='".$hp['id']."'"; $this->query($sql); } } } function find_priority($folder_id, $new_priority) { $sql = "SELECT id FROM cms_folders WHERE priority='$new_priority' AND parent_id='$folder_id'"; $this->query($sql); if($this->next_record()) { return array('type'=>'folder', 'id'=>$this->f('id')); }else { $sql = "SELECT id FROM cms_files WHERE priority='$new_priority' AND folder_id='$folder_id'"; $this->query($sql); if($this->next_record()) { return array('type'=>'file', 'id'=>$this->f('id')); } } return false; } function add_file($folder_id, $name, $content, $title='', $description='', $keywords='', $template_item_id, $auto_meta='1', $hot_item=0, $acl=0) { $file_id = $this->nextid('cms_files'); if ($file_id > 0) { $priority = $this->get_next_priority($folder_id); $size = strlen($content); $extension = get_extension($name); $mtime =$ctime = get_gmt_time(); $sql = "INSERT INTO cms_files (id, folder_id, name, extension, ctime, mtime, size, content, title, description, keywords, priority, auto_meta, template_item_id, hot_item, acl) "; $sql .= "VALUES ('$file_id', '$folder_id', '$name', '$extension', '$ctime', '$mtime', '$size', '$content', '$title', '$description', '$keywords', '$priority', '$auto_meta', '$template_item_id', '$hot_item', '$acl')"; if ($this->query($sql)) { return $file_id; } } return false; } function update_file($file_id, $name, $content, $auto_meta, $title='', $description='', $keywords='', $hot_item='0', $template_item_id, $acl, $unregistered_comments='0',$registered_comments='0') { $size = strlen($content); $extension = get_extension($name); $mtime = get_gmt_time(); $sql = "UPDATE cms_files SET name='$name', extension='$extension', ". "mtime='$mtime', size='$size', content='$content', ". "title='$title', description='$description', ". "keywords='$keywords', hot_item='$hot_item', auto_meta='$auto_meta', template_item_id='$template_item_id', acl='$acl' ". "WHERE id='$file_id'"; return $this->query($sql); } function add_comment($comment) { $comment['id']=$this->nextid('cms_comments'); $comment['ctime']=get_gmt_time(); if($this->insert_row('cms_comments', $comment)) { return $comment['id']; } return false; } function get_comments($file_id) { $sql = "SELECT * FROM cms_comments WHERE file_id=$file_id ORDER BY ctime DESC"; $this->query($sql); return $this->num_rows(); } function delete_comment($comment_id) { $sql = "DELETE FROM cms_comments WHERE id=$comment_id"; return $this->query($sql); } function __update_file($file) { $file['mtime']=get_gmt_time(); return $this->update_row('cms_files', 'id', $file); } //template functions function add_template($template) { //create the template $template['id'] = $this->nextid('cms_templates'); if ($template['id'] > 0) { if($this->insert_row('cms_templates', $template)) { return $template['id']; } } return false; } function update_template($template) { return $this->update_row('cms_templates','id', $template); } function get_templates() { $this->query("SELECT * FROM cms_templates"); return $this->num_rows(); } function get_authorized_templates($user_id) { $sql = "SELECT DISTINCT cms_templates.*". "FROM cms_templates ". " INNER JOIN acl ON ( cms_templates.acl_read = acl.acl_id ". "OR cms_templates.acl_write = acl.acl_id ) ". "LEFT JOIN users_groups ON acl.group_id = users_groups.group_id ". "WHERE acl.user_id=$user_id ". "OR users_groups.user_id=$user_id". " ORDER BY cms_templates.name ASC"; $this->query($sql); return $this->num_rows(); } function get_template($template_id) { $this->query("SELECT * FROM cms_templates WHERE id='$template_id'"); if ($this->next_record()) { return $this->Record; } return false; } function get_template_by_name($user_id, $name) { $this->query("SELECT * FROM cms_templates WHERE user_id='$user_id' AND name='$name'"); if ($this->next_record()) { return $this->Record; } return false; } function delete_template($template_id) { global $GO_SECURITY; if($template = $this->get_template($template_id)) { $GO_SECURITY->delete_acl($template['acl_read']); $GO_SECURITY->delete_acl($template['acl_write']); $this->query("DELETE FROM cms_template_items WHERE template_id='$template_id'"); return $this->query("DELETE FROM cms_templates WHERE id='$template_id'"); } } function add_template_item($template_id, $name, $content, $page='0') { //create the template $template_item_id = $this->nextid('cms_template_items'); if ($template_item_id > 0) { if($this->query("INSERT INTO cms_template_items (id, template_id, name, content, page) VALUES ('$template_item_id', '$template_id', '$name', '$content', '$page')")) { return $template_item_id; } } return false; } function update_template_item($template_item_id, $name, $content, $page) { return $this->query("UPDATE cms_template_items SET page='$page', name='$name',content='$content' WHERE id='$template_item_id'"); } function get_template_items($template_id, $page_templates_only=false) { $sql = "SELECT * FROM cms_template_items WHERE template_id='$template_id'"; if($page_templates_only) { $sql .= " AND page='1'"; } $this->query($sql); return $this->num_rows(); } function get_template_item($template_item_id) { $this->query("SELECT * FROM cms_template_items WHERE id='$template_item_id'"); if ($this->next_record()) { return $this->Record; } return false; } function delete_template_item($template_item_id) { return $this->query("DELETE FROM cms_template_items WHERE id='$template_item_id'"); } function get_template_item_by_name($template_id, $name) { $this->query("SELECT * FROM cms_template_items WHERE template_id='$template_id' AND name='$name'"); if ($this->next_record()) { return $this->Record; } return false; } function replace_template_items($template_id) { $cms = new cms(); $this->get_template_items($template_id); while($this->next_record()) { $content = $this->replace_template_files($template_id, $this->f('content')); $cms->update_template_item($this->f('id'), $this->f('name'), $content); } } function replace_template_files($template_id, $content) { global $GO_MODULES, $GO_CONFIG; $cms = new cms(); $cms_module = $GO_MODULES->get_module('cms'); $attributes[] = 'src'; $attributes[] = 'href'; $attributes[] = 'url('; $length = strlen($content); $replacements = array(); while($attribute = array_shift($attributes)) { $offset = 0; $url = ''; $end=false; while($pos = strpos($content, $attribute, $offset)) { $in_value = false; for($offset=$pos;$offset<$length;$offset++) { $char = $content[$offset]; switch ($char) { case '"':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -