PHP Classes
elePHPant
Icontem

Update Site: Create Web site pages from database content

Recommend this page to a friend!
  Info   View files Example   View files View files (25)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-11-18 (2 days ago) RSS 2.0 feedNot enough user ratingsTotal: 191 This week: 27All time: 8,101 This week: 19Up
Version License PHP version Categories
updatesite 1.0.5MIT/X Consortium ...5HTML, PHP 5, Databases, Content manag...
Description Author

This class can create Web site pages from database content.

It provides a Web interface to create, edit or delete article stored on a MySQL database.

The class can create the necessary database table to store the articles.

Name: Barton Phillips is available for providing paid consulting. Contact Barton Phillips .
Classes: 5 packages by
Country: United States United States
Age: 73
All time rank: 57469 in United States United States
Week rank: 14 Up4 in United States United States Up
Innovation award
Innovation award
Nominee: 1x

Details

UpdateSite Class

This class works with SiteClass. It creates sections or articles that can be placed within a webpage. The articles can be edited via a web browser and they are maintained in a database (MySql is prefered). Check out SiteClass Documentation and Examples.

Install

You can either clone the repository or you can use composer to install UpdateSite.

If you do not have composer you can get it at https://getcomposer.org/download/. Just follow the instruction to install it globally.

Once you have composer select a directory where you want your repository and enter:

composer require bartonlp/updatesite dev-master

How It Works

The sections are stored in a database. Currently there are two databases the SiteClass supports: * MySql. This uses the most current PHP library (mysqli) Sqlite2. This is not as well tested but should work withUpdateSite*

The database schema for MySql looks like this:

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;

The 'creator' field is only used if you have extended the SiteClass to handel members.

You can create a webpage as follows:

// 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;

The comment // START UpdateSite Message is important. This is used by UpdateSite to find the sites that can be created/edited. The comment must start at the beginning of a line and must have START UpdateSite be exactaly as shown followed by the name of the item, in this case 'Message', and then optionally a human readable text in quotes. For example "Webmaster's Message".

If you run this example it will show no messages.

Create the Database Entries.

To create the database entries you can run the following program.

<?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;

Screenshot of testupdatecreate.php

This is the first half of the creation program. As you can see the two drop downs are locked together by JavaScript. You can select the page (the name of the webpage you created) and then select the database item you want to edit.

Edit the Selection

The second screen lets you edit the selected item.

<?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="http://ajax.googleapis.com/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);

Screenshot of testupdatesite2.php

When you click on the 'preview' button you will get the third page.

Screenshot of updatesite-simple-preview.php

Once you click the 'Create Article' you can go back to your first page and you should see messages.

Enhance the Sections

You can change the 'testupdatecreate.php', 'testupdatesite2.php' and 'updatesite-simple-preview.php' to make them work better with your site. There are two other preview pages that you can use: 'updatesite-preview.php' and 'updatesite-new-preview.php'.

Contact Me

Barton Phillips : mailto://bartonphillips@gmail.com Copyright &copy; 2015 Barton Phillips Project maintained by bartonlp

  Files folder image Files  
File Role Description
Files folder imagedocs (6 files)
Files folder imageexamples (9 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file mk-html.php Aux. Auxiliary script
Accessible without login Plain text file mysitemap.json Data Auxiliary data
Accessible without login HTML file README.html Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file updatesite-preview.i.php Example Example script
Accessible without login Plain text file updatesite-preview.new.i.php Example Example script
Accessible without login Plain text file updatesite-simple-preview.i.php Example Example script
Plain text file UpdateSite.class.php Class Class source

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Image file image1.png Data Auxiliary data
  Accessible without login Image file image2.png Data Auxiliary data
  Accessible without login Image file image3.png Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file index.md Example Example script
  Accessible without login Plain text file mk-html.php Aux. Auxiliary script

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file banner.i.php Aux. Auxiliary script
  Accessible without login Plain text file footer.i.php Aux. Auxiliary script
  Accessible without login Plain text file head.i.php Aux. Auxiliary script
  Accessible without login Plain text file mysitemap.json Data Auxiliary data
  Accessible without login Plain text file test.php Example Example script
  Accessible without login Plain text file testupdateadmin.php Example Example script
  Accessible without login Plain text file testupdatecreate.php Example Example script
  Accessible without login Plain text file testupdatesite.php Example Example script
  Accessible without login Plain text file testupdatesite2.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:191
This week:27
All time:8,101
This week:19Up