⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cms.class.inc

📁 groupoffice
💻 INC
📖 第 1 页 / 共 3 页
字号:
	{		$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)	{		$disabled = $disabled ? '1' : '0';		$folder_id = $this->nextid('cms_folders');		if ($folder_id > 0)		{			$priority = $this->get_next_priority($parent_id);			$mtime = get_gmt_time();			if($this->query("INSERT INTO cms_folders (id, parent_id, name, mtime, priority, disabled) VALUES ('$folder_id', '$parent_id', '$name', '$mtime', '$priority', '$disabled')"))			{				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)	{		$sql = "UPDATE cms_folders SET name='$name', mtime='".get_gmt_time().		"', disabled='$disabled', ".		"multipage='$multipage' 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 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_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='', $auto_meta='1')	{		$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 = get_gmt_time();			$sql  = "INSERT INTO cms_files (id, folder_id, name, extension, mtime, size, content, title, description, keywords, priority, auto_meta) ";			$sql .= "VALUES ('$file_id', '$folder_id', '$name', '$extension', '$mtime', '$size', '$content', '$title', '$description', '$keywords', '$priority', '$auto_meta')";			if ($this->query($sql))			{				return $file_id;			}		}		return false;	}	function update_file($file_id, $name, $content, $auto_meta, $title='', $description='', $keywords='', $hot_item='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'  ".		"WHERE id='$file_id'";		return $this->query($sql);	}	//template functions	function add_template($user_id, $name, $style, $additional_style, $print_style, $restrict_editor, $activate_frontpage, $acl_read, $acl_write)	{		//create the template		$template_id = $this->nextid('cms_templates');		if ($template_id > 0)		{			$restrict_editor = ($restrict_editor == "true") ? '1' : '0';			if($this->query("INSERT INTO cms_templates (id, user_id, name, style, additional_style, print_style, restrict_editor, activate_frontpage, acl_read, acl_write) VALUES ('$template_id', '$user_id', '$name', '$style', '$additional_style', '$print_style', '$restrict_editor', '$activate_frontpage', '$acl_read', '$acl_write')"))			{				return $template_id;			}		}		return false;	}	function update_template($template_id, $name, $style, $additional_style, $print_style, $restrict_editor, $activate_frontpage)	{		return $this->query("UPDATE cms_templates SET restrict_editor='$restrict_editor', activate_frontpage='$activate_frontpage', name='$name', style='$style', additional_style='$additional_style', print_style='$print_style' WHERE id='$template_id'");	}	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, acl, users_groups WHERE ".		"(cms_templates.acl_write = acl.acl_id OR cms_templates.acl_read = acl.acl_id)".		" AND (( acl.group_id = users_groups.group_id AND users_groups.user_id = ".$user_id." AND acl.user_id = 0 ) OR (".		"acl.group_id = 0 AND acl.user_id = ".$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'");			$this->query("DELETE FROM cms_template_files WHERE template_id='$template_id'");			return $this->query("DELETE FROM cms_templates WHERE id='$template_id'");		}		}	function add_template_item($template_id, $name, $content)	{		//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) VALUES ('$template_item_id', '$template_id', '$name', '$content')"))			{				return $template_item_id;			}		}		return false;	}	function update_template_item($template_item_id, $name, $content)	{		return $this->query("UPDATE cms_template_items SET name='$name',content='$content' WHERE id='$template_item_id'");	}	function get_template_items($template_id)	{		$this->query("SELECT * FROM cms_template_items WHERE template_id='$template_id'");		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 '"':						if($in_value && $escape_char == '"')						{							if(file_exists($GO_CONFIG->local_path.'cms/templates/'.$template_id.'/'.basename($url)))							{																$replacement['old'] = $url;								$replacement['new'] = $GO_CONFIG->local_url.'cms/templates/'.$template_id.'/'.basename($url);																$replacements[] = $replacement;							}							$url = '';							$end=true;							break;						}elseif(!$in_value)						{							$escape_char = '"';							$in_value = true;						}						break;						case "'":						if($in_value && $escape_char == "'")						{							if(file_exists($GO_CONFIG->local_path.'cms/templates/'.$template_id.'/'.basename($url)))							{																$replacement['old'] = $url;																$replacement['new'] = $GO_CONFIG->local_url.'cms/templates/'.$template_id.'/'.basename($url);								$replacements[] = $replacement;							}							$url = '';							$end=true;							break;						}elseif(!$in_value)						{							$escape_char = "'";							$in_value = true;						}						break;						default:						if($in_value)						{							$url .= $char;						}						break;					}					if($end)					{							$end=false;							break;					}				}			}		}		while($replacement = array_shift($replacements))		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -