Snippet: blogEntries
This snippet contains all functions that are responsible
for the appearance of the entries. The snippet has no parameter and has
no effekt without the blog snippet. It must be included before the blog
snippet.
Snippet: blogComment
The number of comments in the entry field as well as the
whole management of comments is done by this snippet.
The snippet has no parameter and has no effekt without the
blog snippet. It must be included before the blog snippet.
Snippet: blogEdit
Adding, editing and removing of blog entries is managed by
this snippet. If it is included before the blog snippet a edit field is
put on the top of the page and all entries get an edit and remove
button. The snippet has no parameter and has no effekt without the blog
snippet. It must be included before the blog snippet.
//LastChange 2007-07-07
function getEditorText($dbVars, $editorVars, $text, $phpself){
global $etomite;
$editorVars = handleEditorCommands($dbVars, $editorVars, $text, $phpself);
// Calculate path to Xinha directory
$pieces = explode("/",$_SERVER['SERVER_PROTOCOL']);
$protocol = $pieces[0];
$pieces = explode("/",$_SERVER['PHP_SELF']);
$count = count($pieces);
for($i=0; $i<$count-1; $i++) $tmpUrl .= $pieces[$i] . "/";
//***************************************************************************************//
// if the Blog should be editable ($editField == true) then the Editor has
// to be prepared
//***************************************************************************************//
if ($editorVars['editor']=="fckeditor" && is_dir("manager/media/fckeditor")){
// Create the javascript that configures the fckeditor WYSIWYG editor
$jscript = "
";
}else{
$jscript = "
";
}
//***************************************************************************************//
// get the categories from the database
//***************************************************************************************//
$categories = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"SELECT DISTINCT category FROM ".$dbVars['table']." ORDER BY category;");
//***************************************************************************************//
// get the authors from the database
//***************************************************************************************//
$authors = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"SELECT DISTINCT author FROM ".$dbVars['table']." ORDER BY author;");
//***************************************************************************************//
// Format the WYSIWYG entry form
//***************************************************************************************//
//Title and Date
$output .= '
';
$output .= $jscript;
return $output;
}
//***************************************************************************************//
// Decide what action should be taken (cancel, save, add, delete)
//***************************************************************************************//
function handleEditorCommands($dbVars, $editorVars, $text, $phpself){
global $etomite;
if(!isset($_REQUEST['cancel'])) {
if ($_REQUEST['action'] == "add_entry" || $_REQUEST['action'] == "save_entry"){
$editorVars['author'] = isset($_REQUEST['author'])?$_REQUEST['author']:$editorVars['author'];
$editorVars['title'] = isset($_REQUEST['title'])?$_REQUEST['title']:$editorVars['title'];
$editorVars['title'] = stripslashes($editorVars['title']);
$editorVars['blogText'] = isset($_REQUEST['text'])?$_REQUEST['text']:$editorVars['blogText'];
$editorVars['blogText'] = stripslashes($editorVars['blogText']);
if ($_REQUEST['newCategory'] == "yes"){
if ($_REQUEST['newCategoryName'] != ""){
$editorVars['category'] = $_REQUEST['newCategoryName'];
}else{
$editorVars['category'] = $editorVars['defaultCategory'];
}
}else{
$editorVars['category'] = isset($_REQUEST['selectedCategory'])?$_REQUEST['selectedCategory']:$editorVars['defaultCategory'];
}
if ($_REQUEST['newAuthor'] == "yes"){
if ($_REQUEST['newAuthorName'] != ""){
$editorVars['author'] = $_REQUEST['newAuthorName'];
}
}else{
$editorVars['author'] = isset($_REQUEST['selectedAuthor'])?$_REQUEST['selectedAuthor']:$editorVars['author'];
}
//we want to be able to manipulate the date by the formular
$editorVars['day'] = isset($_REQUEST['day'])?$_REQUEST['day']:date("d");
$editorVars['month'] = isset($_REQUEST['month'])?$_REQUEST['month']:date("m");
$editorVars['year'] = isset($_REQUEST['year'])?$_REQUEST['year']:"20".date("y");
$editorVars['date'] = $editorVars['year']."-".$editorVars['month']."-".$editorVars['day']." 00:00:00";
}
switch($_REQUEST['action']) {
case "edit_entry":
$editorVars['action'] = "save_entry";
$editorVars['actionText'] = $text['Save_changes'];
$perm = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"SELECT * FROM " . $dbVars['table'] . " WHERE entryid='".$_REQUEST['entryid']."'");
$entry = $etomite->fetchRow($perm);
$editorVars['date'] = $entry['date'];
list($editorVars['date']) = split("( )", $editorVars['date'], 0);
list($editorVars['year'], $editorVars['month'], $editorVars['day']) = split('[-]', $editorVars['date']);
$editorVars['entryid']=$entry['entryid'];
$editorVars['author']=$entry['author'];
$editorVars['category']=$entry['category'];
$editorVars['title']=$entry['title'];
$editorVars['blogText']=$entry['text'];
break;
case "add_entry":
$admin = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"INSERT INTO " . $dbVars['table'] . " (category,title,text,author,internalKey,date)
VALUES('" . $editorVars['category'] . "','" . addslashes($editorVars['title']) . "','"
. addslashes($editorVars['blogText']) . "','".$editorVars['author']."','" . $_SESSION['internalKey'] . "','".$editorVars['date']."' )");
break;
case "delete_entry":
$perm = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"DELETE FROM ".$dbVars['table']." WHERE entryid='" . $_REQUEST['entryid'] . "'");
break;
case "save_entry":
$admin = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'],
"UPDATE {$dbVars['table']} SET category='". addslashes($editorVars['category'])."', title='" .
addslashes($editorVars['title']) . "',text='" . addslashes($editorVars['blogText']) . "', author='" .
addslashes($editorVars['author']) . "', internalKey='" . $_SESSION['internalKey'] ."', date='".$editorVars['date']."' WHERE entryid={$_REQUEST['entryid']};");
break;
default :
$editorVars['action'] = "add_entry";
$editorVars['actionText'] = $text['Add_entry'];
break;
}
}
$editorVars['action'] = isset($editorVars['action']) ? $editorVars['action'] : "add_entry";
$editorVars['actionText'] = isset($editorVars['actionText']) ? $editorVars['actionText'] : $text['Add_entry'];
return $editorVars;
}
function getEditButtons($entryID, $text, $phpself ){
$editButton = " ".$text['Edit']." ";
$deleteButton = " : ".
$text['Delete']." ";
return $editButton.$deleteButton;
}
Snippet: blog
This is the main snippet that calls the functions of the
other ones. Moreover, all variables are set in this snippet. Hence, to
configure the blog it is enough to edit the blog snippet. All variables
can also be set as parameter. Be careful that this snippet is call after
all other blog related snippets. Moreover, the checkbox for "cacheable"
must be unchecked for the website.
// Blog Snippet
// Created By: Tina Krausser
// Based on the Blogger Snippet created by Ralph Dahlgren
// Based on the original EtoBlog snippet created by hugelmopf
// Last Modified: 2007-07-07
// Purpose: Creates and/or maintains a table of blog entries categorized by document id and can also be used
// to maintain multiple and/or shared blog tables
// Moreover, blog entries can be filtered by author and/or category. The range of displayed entries can be manipulated.
//\[[Blogger?table=geoCachingBlog&db=etShared&showMaxFull=3&showMaxEntries=8&showEntriesFromCategories=GeoCaching!\]
//***************************************************************************************//
// Database settings
// Database table to use for storage
// entries will be grouped by author and/or category so multiple blogs can use one table
//***************************************************************************************//
$dbVars['host'] = isset($host)?$host:'localhost';
$dbVars['db'] = isset($db)?$db:'etomite';
$dbVars['table'] = isset($table)?$table:'blogTable';
$dbVars['commentTable'] = isset($blogTable)?$blogTable:'blogComments';
$dbVars['dbUser'] = isset($dbUser)?$dbUser:'user';
$dbVars['dbPWD'] = isset($dbPWD)?$dbPWD:'password';
//***************************************************************************************//
// Configure display variables
//***************************************************************************************//
$blogEntryVars['showEntriesFrom'] =
isset($showEntriesFrom) ? : -1;
$blogEntryVars['showFullFrom'] =
isset($showFullFrom) ? : -1;
$blogEntryVars['showMaxEntries'] =
isset($showMaxEntries) ? : -1;
$blogEntryVars['showMaxFull'] =
isset($showMaxFull) ? : -1;
// entries from which authors should be displayed
// example: "wizard_OR_igel" returns all entries from wizard and all entries from igel
// the keyword "_ALL_" in the string overwrites all other settings and entries from all authors are displayed
$blogEntryVars['showEntriesFromAuthors'] =
isset($showEntriesFromAuthors) ? $showEntriesFromAuthors : "_ALL_";
// entries from which categories should be displayed
// example: "GeoCaching_OR_OutDoor" returns all entries from GeoCaching and all entries from OutDoor
// the keyword "_ALL_" in the string overwrites all other settings and entries from all categories are displayed
$blogEntryVars['showEntriesFromCategories'] =
isset($showEntriesFromCategories) ? $showEntriesFromCategories : "_ALL_";
// Should the authors name be displayed? Defaults to true
$blogEntryVars['showAuthor'] = isset($showAuthor) ? $showAuthor : "true";
// Should the category be displayed? Defaults to true
$blogEntryVars['showCategory'] = isset($showCategory) ? $showCategory : "true";
// Should the last modified date be displayed? Editing an entry changes the date to the current time
$blogEntryVars['showDate'] = isset($showDate) ? $showDate : "true";
// Custom date formate based on the PHP date() function
$blogEntryVars['dateFormat'] = (isset($dateFormat)) ? $dateFormat : "l d.m.y"; // Monday 20.10.05
$blogEntryVars['showAllLink'] = isset($showAllLink) ? $showAllLink : True;
//***************************************************************************************//
// Configure editor variables
//***************************************************************************************//
// defaultEditor:
$editorVars['editor'] = isset($editor) ? $editor : "fckeditor";
// Set the height of the WYSIWYG editor
$editorVars['height'] = isset($height) ? $height : "400";
// Set the width of the WYSIWYG editor (can be in px or %)
$editorVars['width'] = isset($width) ? $width : "100%";
$editorVars['defaultCategory'] = isset($category) ? $category : "-";
$editorVars['author'] = isset(\defaultAuthor) ? $defaultAuthor : "author";
//we want to be able to manipulate the date by the formular
$editorVars['day'] = isset($_REQUEST['day'])?$_REQUEST['day']:date("d");
$editorVars['month'] = isset($_REQUEST['month'])?$_REQUEST['month']:date("m");
$editorVars['year'] = isset($_REQUEST['year'])?$_REQUEST['year']:"20".date("y");
//***************************************************************************************//
// Configure comment variables
//***************************************************************************************//
$commentVars['mailTo'] = isset($mailTo) ? $mailTo : "name@domain.de";
$commentVars['manComPage'] = isset($manComPage) ? $manComPage : "manipulate.comment.net";
$commentVars['dateFormat'] = (isset($dateFormat)) ? $dateFormat : "l d.m.y"; // Monday 20.10.05
//***************************************************************************************//
// Configure text values
//***************************************************************************************//
// Text for various page elements
$text['ShowAll_Link'] = "Show all";
$text['Save_changes'] = "Save changes";
$text['Entry_added'] = "Entry added.";
$text['Entry_deleted'] = "Entry deleted.";
$text['Changes_saved'] = "Changes saved.";
$text['Action_cancelled'] = "Action Cancelled.";
$text['Add_entry'] = "Add entry";
$text['Cancel'] = "Cancel";
$text['Author'] = "Author";
$text['NewAuthor'] = "New Author";
$text['Category'] = "Category";
$text['Date'] = "Date";
$text['Edit'] = "Edit";
$text['Delete'] = "Delete";
$text['Confirm'] = "Confirm";
$text['Title'] = "Title: ";
$text['CategorizeAs'] = "Categorize as:";
$text['NewCategory'] = "Create new category:";
$text['commentNr'] = "Comments: ";
$text['commentZero'] = "Leave a Comment";
$text['addedComment'] = "Thanks for your comment. I will approve it shortly.";
$text['commentDate'] = "on ";
$text['commentAuthor'] = "Posted by ";
$text['commentTitle'] = "Comments:";
//***************************************************************************************//
// Configure css comands
//***************************************************************************************//
// Style information - can be inline styles or CSS component related
$css['entry_box'] = "class='bloggEntryBox'";
$css['entry_title'] = "class='blueTitle' style="width:100%"";
$css['title'] = "class ='bloggTitle'";
$css['author'] = "class='bloggAuthor'";
$css['category'] = "class='bloggCategory'";
$css['date'] = "class ='bloggDate'";
$css['parent'] = "class='bloggParent'";
$css['text'] = "class='bloggText'";
$css['more'] = "class='bloggMore'";
$css['bloggCom'] = "class='bloggCom'";
$css['commentAuthor'] = "class='comAuthor'";
$css['commentDate'] = "class='comDate'";
$css['commentText'] = "class='comText'";
$css['commentTitle'] = "class='comTitle'";
$css['commentBox'] = "class='comBox'";
$css['commentSubLine'] = "class='comSubLine'";
$css['commentBack'] = "class='comBack'";
//Template
//available in the next version
//***************************************************************************************//
// Prepare the Text
//***************************************************************************************//
// No variable changes should be required below this point
$phpself = $etomite->makeUrl(/71);
$phpself = "[~".\/71."~]";
//***************************************************************************************//
// Prepare the Database
//***************************************************************************************//
// If blog table has not been created yet, create it now:
$exist = $etomite->extTableExists($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'], $dbVars['table']);
if(!/) {
$sql = "CREATE TABLE ".$dbVars['table']." (
`entryid` int(10) unsigned NOT NULL auto_increment,
`category` text NOT NULL,
`title` text NOT NULL,
`text` text NOT NULL,
`author` text,
`internalKey` int(10) NOT NULL default '0',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`entryid`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;";
$create = $etomite->dbExtQuery($dbVars['host'], $dbVars['dbUser'], $dbVars['dbPWD'], $dbVars['db'], $sql);
}
if (function_exists ('handleComments')){
$commentVars = handleComments($dbVars, $commentVars, $text, $_REQUEST['entryid'], $phpself);
}
if (function_exists ('getEditorText')){
$output .= getEditorText($dbVars, $editorVars, $text, $phpself);
}
if (!isset($_REQUEST['editComment'])){
if (function_exists ('getBlogEntries')){
$output .= getBlogEntries($dbVars, $blogEntryVars, $text, $css, $phpself);
}
} else {
if (function_exists ('getBlogEntries')){
$blogEntryVars['showEntriesFrom'] = $_REQUEST['entryid'];
$blogEntryVars['showFullFrom'] = $_REQUEST['entryid'];
$blogEntryVars['showMaxEntries'] = 1;
$blogEntryVars['showMaxFull'] = 1;
$blogEntryVars['showAllLink'] = False;
$output .= getBlogEntries($dbVars, $blogEntryVars, $text, $css, $phpself);
}
if (function_exists ('showCommentPage')){
$output .=
showCommentPage($dbVars, $commentVars,
$text, $css, $phpself,
$_REQUEST['entryid']);
}
}
$status = isset($_REQUEST['status']) ? $_REQUEST['status'] : /;
if (function_exists ('alterStatus') && $status!="" && isset($_REQUEST['comID'])){
$output .=
alterStatus($dbVars, $_REQUEST['comID'], $status, $css, $text);
}
// Return the generated HTML code for display
return $output;
Snippet: blogFeed
// BlogFeed
// --------
// Creates an Atom 0.3 feed from the SharedBlog.
// Created By: Tina Krausser
// Based on the AtomFeed Version 1.7 created by john@threepoundfilms.com
// Last Change 2007-07-07
//
// Snippet Usage
// -------------
// Use this snippet to create a Atom 0.3 feed of all documents in a folder.
//
// 1. Make sure you edit the snippet's Settings section to match your site info.
//
// If the feed will be in a language other than en-US, reference the following
// page for the correct language setting:
//
// http://my.netscape.com/publish/formats/rss-spec-0.91.html
//
// 2. Make a blank template with only the following line:
//
//
//
// 3. Create a new page (preferably in an unpublished folder) that will deliver
// your Atom feed. Make sure this page is assigned to the template you created
// above, that you set the document type to text/xml, and that you disable
// "Rich text". Call this snippet ONLY using the following syntax:
//
//
//
// Ensure that there are no blank lines above the entry.
// See Runtime Options below for settings and their definitions.
//
// 4. Add a link entry to your main template so that an Atom-enabled browser can
// pick up the feed.
//
//
//
// Where ID.html is the ID of the feed page. For instance, if the feed page
// is ID 5, then 5.html would be appropriate.
//
// 5. You are done! You should have a working Atom feed available at your site.
//
//
// Runtime Options
// ---------------
// id - Folder ID of News parent; Default : Current page
// showMaxEntries - Number of items to display; Default : 10
// show_content - Include document content in the feed; Default : true
// show_editors - Include names of document editors; Default : true
// show_email - Include e-mail addresses of editors; Default : true
//
// feed_title - Title of feed
// feed_url - Base URL of website
// feed_author - Name of feed author (Company name)
// feed_copyright - Copyright notice for feed
// language - Language of feed - 2-letter acronym
//
// site_name - Name of website; Default : Etomite config
// site_home - ID of base document in website; Default : Etomite config
////////////////////////////////////////////////////////
// Setting Defaults - Customize to your site //
////////////////////////////////////////////////////////
//***************************************************************************************//
// Database settings
// Database table to use for storage
// entries will be grouped by author and/or category so multiple blogs can use one table
//***************************************************************************************//
$db = isset($db)?$db:'etShared';
$table = isset($table)?$table:'myBlogTable';
$dbUser = isset($dbUser)?$dbUser:'user';
$dbPWD = isset($dbPWD)?$dbPWD:'password';
$host = isset($host)?$host:'localhost';
//***************************************************************************************//
// Configure page location
//***************************************************************************************//
// Etomite-PageId of the feed
$page_id = isset($page_id) ? $page_id : 0;
// Web site url - must have trailing slash
if(!isset($feed_url)) { $feed_url = "myUrl"; }
//***************************************************************************************//
// Configure shown elements
//***************************************************************************************//
// entries from which authors should be displayed
// example: "me_OR_you" returns all entries from me and all entries from you
// the keyword "_ALL_" in the string overwrites all other settings and entries from all authors
// are displayed
$showEntriesFromAuthors =
isset($showEntriesFromAuthors) ? $showEntriesFromAuthors : "_ALL_";
// entries from which categories should be displayed
// example: "Etomite_OR_OutDoor" returns all entries from Etomite and all entries from OutDoor
// the keyword "_ALL_" in the string overwrites all other settings and entries from all categories
// are displayed
$showEntriesFromCategories =
isset($showEntriesFromCategories) ? $showEntriesFromCategories : "_ALL_";
// Maximum number of articles to display
$count = isset($showMaxEntries) ? $showMaxEntries : 10;
// Show Content in Feed
if(!isset($show_content)) { $show_content = "true"; }
// Show names of document editors
if(!isset($show_editors)) { $show_editors = "true"; }
// Show e-mail addressed of document editors (show_editors must be true)
if(!isset($show_email)) { $show_email = "false"; }
//***************************************************************************************//
// Configure Variables
//***************************************************************************************//
// Title of the feed
if (!isset($feed_title)) { $feed_title = "Blog";}
// Author of Feed
if(!isset($feed_author)) { $feed_author = "Me"; }
// Feed Copyright Notice
if(!isset($feed_copyright)) { $feed_copyright = "Copyleft by me."; }
// Language of Feed
if(!isset($language)) { $language = "de"; }
////////////////////////////////////////////////////////
// END OF CONFIGURATION PART //
////////////////////////////////////////////////////////
//***************************************************************************************//
// Function to convert a timestamp into ISO 8601
//***************************************************************************************//
function iso_8601 ($timestamp) {
$main_date = date("Y-m-dTH:i:s", $timestamp);
$tz = date("O", $timestamp);
$tz = substr_replace ($tz, ':', 3, 0);
$return = $main_date . $tz;
return $return;
}
//***************************************************************************************//
// generate a mysql-query that returns only entries from wanted authors and
// wanted categories
//***************************************************************************************//
// the blog can have differnt categories
// if _ALL_ is a part of the category string then all categories should be
// displayed, hence, the categorySelector must be empty
$pos = strpos($showEntriesFromCategories, "_ALL_");
if ($pos === false) {
$cats = split('_OR_',$showEntriesFromCategories);
foreach ($cats as $cat){
$categorySelector = isset ($categorySelector) ? $categorySelector." OR category LIKE '%".$cat."%'" : "category LIKE '%".$cat."%'";
}
} else {
$categorySelector = "";
}
// differnt authors can blog into the same table
// to control the entries that should be shown dependent on the author we
// use $showEntriesFromAuthors
// if _ALL_ is a part of the author string then entries from all all authors should be
// displayed, hence, the categorySelector must be empty
$pos = strpos($showEntriesFromAuthors, "_ALL_");
if ($pos === false) {
$auths = split('_OR_',$showEntriesFromAuthors);
foreach ($auths as $auth){
$authorSelector = isset ($authorSelector) ? $authorSelector." OR author LIKE '%".$auth."%'" : "author LIKE '%".$auth."%'";
}
} else {
$authorSelector = "";
}
// concatinate the selection string
$selector = "";
if ($categorySelector != "" && $authorSelector != ""){
$selector = "WHERE (".$categorySelector.") AND (".$authorSelector.")";
}elseif($authorSelector != ""){
$selector = "WHERE ".$authorSelector;
}elseif($categorySelector != ""){
$selector = "WHERE ".$categorySelector;
}
//***************************************************************************************//
// Get existing entries for this blog from the blog table based on the selector
//***************************************************************************************//
$children = $etomite->dbExtQuery($host, $dbUser, $dbPWD,
$db,
"SELECT * FROM {$table}
{$selector} ORDER BY date DESC,
entryid DESC");
////////////////////////////////////////////////////////
// //
// Begin XML Creation //
// //
////////////////////////////////////////////////////////
// Set encoding. If not set in Etomite, use iso-8859-1
$charset = $etomite->config['etomite_charset'];
if ($charset == "") { $charset = "iso-8859-1"; }
// A set of useful variables
$feed_home = $feed_url."".$page_id.".html";
// Write Atom header
$output .= "
".htmlspecialchars($feed_title)."
".htmlspecialchars($feed_copyright)."
Etomite AtomFeed Snippet
".htmlspecialchars($feed_author)."
";
// Create an entry for each article
while (($entry = $etomite->fetchRow($children)) &&
($count > 0)){
$count--;
//echo $entry['title'];
if (!isset($pubdate)){
$pubdate = $entry['date'];
$output .= "".iso_8601($pubdate)." ";
}
$entry_title = htmlspecialchars($entry['title']);
$entry_link = $feed_home."&showFullFrom=".$entry['entryid']."&showMaxFull=1";
$entry_summary = "";
$entry_id = $feed_url."index.php?".$entry['entryid'];
$entry_created = $entry['date'];
//$entry_content = htmlspecialchars($entry['text']);
$entry_content = stripslashes($entry['text']);
// If show_editors is set to true,
// then include the original author
if ($show_editors == true) {
$entry_author = $entry['author'];
}
// Add the data to the output string
$output .= "
$entry_title
$entry_summary
$entry_id
$entry_created ";
// Only add editor information if the
// variables are not empty.
if ($entry_author != "") {
$output .= "$entry_author ";
$output .= " ";
}
// If the show_content variable is set to 'true',
// then include the page content in the stream.
if ($show_content == "true") {
$output .= "
".htmlspecialchars($entry_content)."
";
}
// Close up the entry
$output .= "
";
}
// Close up the feed
$output .= " ";
// Return the output
return $output;