[geeklog-devel] Staticpage checkin/checkout functionality; staticpage refresh option

Heather Engineering info at heatherengineering.com
Sun Jun 10 02:38:41 EDT 2007


I needed this for a site, so figured I'd send it in.

1) Checkin/checkout facility for plugins (just used for staticpages  
but could easily be extended)
2) Refresh option for staticpages (refresh to edited page on saving).

Not done yet: block on moderation page (moderation.php) showing items  
checked out, and option to check in.

Text below is also in attached text file. Suggestions welcome, or if  
someone wants to improve on this, please do.
Refresh option would also be nice for stories - some users find it  
confusing to see administration pages and like to just edit and  
return to the story/page where they started out.

Euan.

**
http://www.heatherengineering.com/




****************

config.php: add one line

$_CONF['checkout_expiry'] = 3600;      // time in seconds after which  
items automatically checked in

(Better perhaps to set this in the plugin config.php file and create  
a simple function to return the value on demand: eg  
plugin_checkout_time_staticpages returns $_SP_CONF['checkout_time'].)

****************

system/lib-database: add one line

$_TABLES['checkout']            = $_DB_table_prefix . 'checkout';

****************

staticpages/config.php: add seven lines:

// 'refresh' will refresh to the page that was just edited
// anything else will default to the staticpages admin page (page list)
$_SP_CONF['on_save'] = 'refresh';

// check in/check out staticpages
// can be 1 (use check in/out) or 0 (don't)
$_SP_CONF['checkout'] = 1;

****************

sql/mysql_tableanddata.php: new table

$_SQL[45] = "
CREATE TABLE {$_TABLES['checkout']} (
   id varchar(20) NOT NULL default '',
   plugin varchar(20) NOT NULL default '',
   uid mediumint(8) default NULL,
   date datetime default NULL
   PRIMARY KEY  (id)
) TYPE=MyISAM
";

****************

language/english.php: add one line to $LANG_ADMIN

<     'records_found' => 'Records found'
---
 >     'records_found' => 'Records found',
 >     'checked_out'   => 'Item is checked out by %user% at %date%.  
To edit, check it in first.'

****************

admin/plugins/staticpages/index.php:


iMac:~/desktop euan$ diff -c index.php index-new.php
*** index.php   Sat Dec  9 21:57:03 2006
--- index-new.php       Sun Jun 10 13:49:08 2007
***************
*** 608,615 ****
--- 608,638 ----
       } else {
           DB_delete ($_TABLES['staticpage'], 'sp_id', $sp_id,
                   $_CONF['site_admin_url'] . '/plugins/staticpages/ 
index.php');
+         // check in staticpage
+         if ($_SP_CONF['checkout']==1) {
+             COM_item_checkin ($sp_id, 'staticpages');
+         }
       }
   } else if ($mode == 'edit') {
+     // check out item
+     if ($_SP_CONF['checkout']==1) {
+         $checkout = COM_item_checkout ($sp_id, 'staticpages');
+         if (is_array ($checkout)) {
+             // item already checked out
+             $display .= COM_siteHeader ('menu', $LANG_STATIC 
['staticpagelist']);
+             $display .= COM_startBlock ($LANG_ACCESS 
['accessdenied'], '',
+                             COM_getBlockTemplate ('_msg_block',  
'header'));
+             $username = DB_getItem ($_TABLES['users'], 'username',   
'uid='.$checkout['uid']);
+             $message  = str_replace("%user%", $username, $LANG_ADMIN 
['checked_out']);
+             $message  = str_replace("%date%", $checkout['date'],  
$message);
+             $display .= $message;
+             $display .= COM_endBlock (COM_getBlockTemplate  
('_msg_block', 'footer'));
+             $display .= liststaticpages();
+             $display .= COM_siteFooter ();
+             echo $display;
+             exit;
+         }
+     }
       $display .= COM_siteHeader ('menu', $LANG_STATIC 
['staticpageeditor']);
       $editor = '';
       if (isset ($_GET['editor'])) {
***************
*** 661,669 ****
--- 684,712 ----
               $sp_help, COM_applyFilter ($_POST['sp_tid']),
               COM_applyFilter ($_POST['sp_where'], true), $_POST 
['sp_inblock'],
               COM_applyFilter ($_POST['postmode']));
+         // check in staticpage
+         if ($_SP_CONF['checkout']==1) {
+             COM_item_checkin ($sp_id, 'staticpages');
+         }
+         // check where we should return
+         if ($_SP_CONF['on_save']=='refresh') {
+             $display = COM_refresh ($_CONF['site_url'] . '/ 
staticpages/index.php?page='.$sp_id);
+         }
       } else {
           $display = COM_refresh ($_CONF['site_admin_url'] . '/ 
index.php');
       }
+ } else if ($mode==$LANG_ADMIN['cancel']) {
+     // check in staticpage
+     if ($_SP_CONF['checkout']==1) {
+         COM_item_checkin ($sp_id, 'staticpages');
+     }
+     if ($_SP_CONF['on_save']=='refresh') {
+         $display = COM_refresh ($_CONF['site_url'] . '/staticpages/ 
index.php?page='.$sp_id);
+     } else {
+         $display .= COM_siteHeader ('menu', $LANG_STATIC 
['staticpagelist']);
+         $display .= liststaticpages();
+         $display .= COM_siteFooter ();
+     }
   } else {
       $display .= COM_siteHeader ('menu', $LANG_STATIC 
['staticpagelist']);
       $display .= liststaticpages();


****************

Add two functions to lib-common.php

/**
* Check in a plugin item (ie finish editing it and release it for  
others to edit)
*
* @param    string  $sp_id    the id of the item to check in
* @return   nothing
*/
function COM_item_checkin ($id, $plugin)
{
     global $_CONF, $_TABLES;
     // delete item from checkout table
     DB_delete ($_TABLES['checkout'], array('id', 'plugin'), array 
($id, $plugin));
     return;
}

/**
* Check out a staticpage (ie start editing it and lock it so others  
cannot edit it)
*
* @param    string  $sp_id    the id of the page to check out
* @return   string            0 if item successfully checked out,  
user is if already checked out
*/
function COM_item_checkout ($id, $plugin)
{
     global $_CONF, $_TABLES,  $_USER;
     // check item not already in use
     $result = DB_query("SELECT uid,date FROM {$_TABLES['checkout']}  
WHERE id='{$id}' AND plugin='{$plugin}'");
     if ( DB_numRows ($result) > 0) {
         $A = DB_fetchArray ($result);
         // check time and user
         $difference = strtotime('now') - strtotime($A['date']);
         if (($difference > $_CONF['checkout_expiry']) || ($A['uid']== 
$_USER['uid'])) {
             // expired, or checked out by self, so check in and  
check out again
             COM_item_checkin ($id, $plugin);
             DB_query("INSERT INTO {$_TABLES['checkout']} (id,  
plugin, uid, date) VALUES ('{$id}', '{$plugin}', '{$_USER['uid']}',  
NOW())");
             return;
         }
         // in use
         return $A;
     } else {
         // not in use so check it out and return true
         DB_query("INSERT INTO {$_TABLES['checkout']} (id, plugin,  
uid, date) VALUES ('{$id}', '{$plugin}', '{$_USER['uid']}', NOW())");
         return;
     }
}


****************

This is required, but I haven't written the function yet - list up  
checked out items on the moderation page, with an option to check  
them in if required.

admin/moderation.php: add one function and the following two lines to  
commandcontrol() at about line 211


     // check for checked out items (security is handled in the  
function)
     $retval .= checkedoutlist ();


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: staticpage_mod.txt
URL: <https://pairlist8.pair.net/pipermail/geeklog-devel/attachments/20070610/38208aaa/attachment.txt>
-------------- next part --------------



More information about the geeklog-devel mailing list