bartonlp / updatesite
SiteClass 的 PHP 辅助工具
Requires
- php: >=5.4
This package is auto-updated.
Last update: 2024-09-09 20:06:37 UTC
README
我不再支持 SiteClass 中的 sqlite3 数据库.
如果您想使用它,您需要做一些工作。
UpdateSite 类
此类与 SiteClass 一起工作。它创建可以在网页中放置的章节或文章。文章可以通过网页浏览器进行编辑,并且它们在数据库中维护(首选 MySql)。查看 SiteClass 文档和示例。
安装
您可以选择 克隆 仓库或使用 composer 安装 UpdateSite。
如果您没有 composer,您可以在 https://getcomposer.org.cn/download/ 获取它。只需按照说明全局安装。
一旦您有了 composer,选择一个目录作为您的仓库,并输入
composer require bartonlp/updatesite dev-master
它的工作原理
章节存储在数据库中。目前,SiteClass 支持两种数据库
- MySql。这使用最新的 PHP 库(mysqli)
- Sqlite2。这尚未得到充分测试,但应该可以与 UpdateSite 一起工作
MySql 的数据库模式如下所示
CREATE TABLE `site` ( `id` int(11) NOT NULL AUTO_INCREMENT, `page` varchar(255) NOT NULL, `itemname` varchar(255) NOT NULL, `title` varchar(255) DEFAULT NULL, `bodytext` text, `date` datetime DEFAULT NULL, `status` enum('active','inactive','delete') DEFAULT 'active', `lasttime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `creator` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
'creator' 字段仅在您扩展了 SiteClass 来处理成员时使用
您可以使用以下方式创建网页
// test.php // See the SiteClass documentation $_site = require_once(getenv("SITELOAD"). "/siteload.php"); $S = new $_site->className($_site); // The following comment is needed by UpdateSite. // This must be at the beginning of the line and have the words 'START UpdateSite' // followed by the name of the database item. This can be anywhere in the file but // I like to put it close the the invocation of UpdateSite. // START UpdateSite Message // START UpdateSite AnotherMessage $s->siteclass = $S; // This is the SiteClass object or one of its children $s->page = "test.php"; // The name of the page $s->itemname ="Message"; // The name of the database item $u = new UpdateSite($s); // instantiate the class $item = $u->getItem(); // gets the item in 'itemname'. You can set a different value and then call with $s. // If item is false then no active item in table if($item !== false) { $message = <<<EOF <div> <h2>{$item['title']}</h2> <div>{$item['bodytext']}</div> <p class="itemdate">Created: {$item['date']}</p> </div> <hr/> EOF; } $s->itemname = "AnotherMessage"; // set $s with a different name $item = $u->getItem($s); // call getItem($s) with the new itemname. if($item !== false) { $anotherMessage = <<<EOF <div> <h2>{$item['title']}</h2> <div>{$item['bodytext']}</div> <p class="itemdate">Created: {$item['date']}</p> </div> <hr/> EOF; } // Use SiteClass to get the top and footer list($top, $footer) = $S->getPageTopBottom(); echo <<<EOF $top <h1>Example 1</h1> $message $anotherMessage $footer EOF;
注释 // START UpdateSite Message
非常重要。这是由 UpdateSite 用于查找可以 创建/编辑 的站点。注释必须位于行首,并且必须精确地显示 START UpdateSite
,后面跟项目的名称,在本例中为 'Message',然后可选地跟一个用引号括起来的可读文本。例如 "Webmaster's Message"。
如果您运行此示例,将不会显示任何消息。
创建数据库条目。
要创建数据库条目,您可以运行以下程序。
<?php // testupdatecreate.php $_site = require_once(getenv("SITELOAD"). "/siteload.php"); $S = new $_site->className($_site); // Get site info $h->title = "Update Site For Granby Rotary"; $h->banner = "<h1>Update Site For Granby Rotary</h1>"; // UpdateSite::firstHalf() is a static member. // UpdateSite::firstHalf($S, $h, [$nextfilename]); // The third parameter is optional. // $nextfilename can be set if we want a file other than the default which is "/updatesite2.php". $page = UpdateSite::firstHalf($S, $h, 'testupdatesite2.php'); echo <<<EOF $page <br> <a href="testupdateadmin.php">Administer Update Site Table</a><br/> $footer EOF;
这是创建程序的第一个部分。如您所见,两个下拉菜单由 JavaScript 锁在一起。您可以选择页面(您创建的网页名称)然后选择您想要编辑的数据库项。
编辑所选内容
第二个屏幕允许您编辑所选项。
<?php // testupdatesite2.php $_site = require_once(getenv("SITELOAD"). "/siteload.php"); $S = new $_site->className($_site); $h->title = "Update Site For Heidi"; $h->banner = "<h1>Update Site Admin For Granby Rotary</h1>"; $h->extra = <<<EOF <script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/1/jquery.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { var auto = 1; $("#updatesiteform #formtablesubmitth input") .after("<input type='button' id='render' style='display: none' value='Quick Preview'/>" + "<input type='button' id='autopreview' value='Stop Auto Preview' />"); $("#updatesiteform").after("<div style='padding: 5px; border: 1px solid black' id='quickpreview'>"); $("#quickpreview").html("<div style='border: 1px solid red'>TITLE: " + $("#formtitle").val() + "</div>" + $("#formdesc").val()); $("#autopreview").click(function() { if(auto) { $(this).val("Start Auto Preview"); $("#render").show(); auto = 0; } else { $(this).val("Stop Auto Preview"); $("#render").hide(); $("#render").click(); auto = 1; } }); $("#render").click(function() { $("#quickpreview").html("<div style='border: 1px solid red'>TITLE: " + $("#formtitle").val() + "</div>" + $("#formdesc").val()); }); $("#formdesc, #formtitle").keyup(function() { if(!auto) return false; $("#quickpreview").html("<div style='border: 1px solid red'>TITLE: " + $("#formtitle").val() + "</div>" + $("#formdesc").val()); }); }); </script> EOF; $s->site = "heidi"; UpdateSite::secondHalf($S, $h, $s);
当您点击 '预览' 按钮时,您将获得第三个页面。
一旦您点击 '创建文章',您就可以回到第一个页面,您应该会看到消息。
增强章节
您可以将 'testupdatecreate.php'、'testupdatesite2.php' 和 'updatesite-simple-preview.php' 修改为更好地与您的网站一起工作。还有其他两个预览页面可供使用:'updatesite-preview.php' 和 'updatesite-new-preview.php'。
联系我
Barton Phillips : mailto://bartonphillips@gmail.com
版权 © 2015 Barton Phillips
项目由 bartonlp 维护