blogger.php

Go to the documentation of this file.
00001 <?php
00010 // Register module human name, version and description.
00011 $modules_names[] = "BloggerMod2";
00012 $mopules_versions[] = "0.1";
00013 $modules_descriptions[] = "Category based blogging module - one blog per user, with both global and personal categories";
00014 
00015 // Register the module into module settings
00016 $modules_setup[] = "modulesetup_blogger";
00017 
00018 // Register the module into profile modules
00019 $profilemodules[] = "profilemodule_blogger";
00020 
00021 // Register the module into globalID
00022 $modules_globalID[] = "globalID_blogger";
00023 
00024 // Register the module's parsing function
00025 $modules[] = "parse_blogger";
00026 
00027 // Give help to using the whole blogging module system
00028 $page_help["--- in blog entry"] = "This will cause BloggerMod to cut the entry here when not showing the full entry - it will still be parsed as a horizontal line normally";
00029 $page_help["&#92;blogall(txt1, txt2, txt3)"] = "Will show you a list of blog entries by all users in the system, optionally with the space-delimited category list txt1. If txt2 is present, it is the amount of blog items to show. If txt3 is present, it is the number of items that will be rendered tiny (that is, with only the header)";
00030 $page_help["&#92;blog(txt1, txt2, txt3, txt4)"] = "Will show you a list of blog entries by the user txt1, optionally limited to the categories defined by the space-delimited list txt2. If txt3 is present, it is the amount of blog items to show. If txt4 is present, it is the number of items that will be rendered tiny (that is, with only the header)";
00031 
00032 
00033 include( "$module_folder/blogger/code/blogger_entryEditor.php" );
00034 include( "$module_folder/blogger/code/blogger_entry.php" );
00035 include( "$module_folder/blogger/code/blogger_userOptions.php" );
00036 include( "$module_folder/blogger/code/blogger_user.php" );
00037 include( "$module_folder/blogger/code/blogger_entries.php" );
00038 
00043 function parse_blogger( $page_data )
00044 {
00045         global $globalID, $page_id, $page_title, $meta_headers, $module_folder;
00046         
00047         $loopcontrol = 0;
00048         $moduleCommandName = "blogfeedall";
00049         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
00050         {
00051                 if( $parameters == " " )
00052                         $parameters = "";
00053                 
00054                 list( $users, $categories ) = split( ",", $parameters );
00055                 
00056                 $users = split( " ", trim($users) );
00057                 $categories = split( " ", trim($categories) );
00058                 
00059                 $showThis = new blogger_entries( $users, $categories );
00060                 
00061                 $replaceData = $showThis->renderFeed();
00062                 $rendered = true;
00063                 
00064                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
00065         }
00066         
00067         $loopcontrol = 0;
00068         $moduleCommandName = "blogfeed";
00069         
00070         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
00071         {
00072                 if( $parameters == " " )
00073                         $parameters = "";
00074                 
00075                 if( strpos( $parameters, "," ) > 0 )
00076                         list( $users, $categories ) = split( ",", $parameters );
00077                 else
00078                         list( $users, $categories ) = array( null, $parameters );
00079                 
00080                 $categories = split( " ", trim($categories) );
00081                 
00082                 $showThis = new blogger_entries( null, $categories );
00083                 
00084                 $replaceData = $showThis->renderFeed();
00085                 $rendered = true;
00086                 
00087                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
00088         }
00089         
00090         $loopcontrol = 0;
00091         $moduleCommandName = "blogall";
00092         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
00093         {
00094                 if( $parameters == " " )
00095                         $parameters = "";
00096                 
00097                 list( $categories, $limit, $limitTiny ) = split( ",", $parameters );
00098                 
00099                 $categories = split( " ", trim($categories) );
00100                 
00101                 $showThis = new blogger_entries( null, $categories );
00102                 
00103                 if( is_numeric($limit) && $limit > 0 )
00104                         $showThis->limit = $limit;
00105                 if( is_numeric($limitTiny) && $limitTiny > 0 )
00106                         $showThis->limitTiny = $limitTiny;
00107                 
00108                 $replaceData = $showThis->render();
00109                 $meta_headers .= "
00110 <link rel=\"alternate\" type=\"application/rss+xml\" title=\"$page_title RSS\" href=\"" . siteURL() . "?module_function=blogfeed(" . implode( " ", $categories ) . ")\" />";
00111                 $rendered = true;
00112                 
00113                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
00114         }
00115         
00116         $loopcontrol = 0;
00117         $moduleCommandName = "blog";
00118         while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
00119         {
00120                 if( $parameters == " " )
00121                         $parameters = "";
00122                 
00123                 list( $users, $categories, $limit, $limitTiny ) = split( ",", $parameters );
00124                 
00125                 $users = split( " ", trim($users) );
00126                 $categories = split( " ", trim($categories) );
00127                 
00128                 $showThis = new blogger_entries( $users, $categories );
00129                 
00130                 if( is_numeric($limit) && $limit > 0 )
00131                         $showThis->limit = $limit;
00132                 if( is_numeric($limitTiny) && $limitTiny > 0 )
00133                         $showThis->limitTiny = $limitTiny;
00134                 
00135                 $replaceData = $showThis->render();
00136                 $meta_headers .= "
00137 <link rel=\"alternate\" type=\"application/rss+xml\" title=\"$page_title RSS\" href=\"" . siteURL() . "?module_function=blogfeed(" . implode( " ", $users ) . "," . implode( " ", $categories ) . ")\" />";
00138                 $rendered = true;
00139                 
00140                 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
00141         }
00142         
00143         if( $rendered )
00144                 $meta_headers .= "
00145         <link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/blogger/blogger.css\" type=\"text/css\" />";
00146         
00147         return $page_data;
00148 }
00149 
00150 function profilemodule_blogger()
00151 {
00152         global $tabwidget, $meta_headers, $module_folder, $viewUser, $globalID, $permissionlevels_array, $setup_folder;
00153         
00154         $meta_headers .= "\n<link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/blogger/blogger.css\" type=\"text/css\" />";
00155         
00156         $splitID = split( "/", $globalID );
00157         
00158         // If we have a number, it means we want to show an entry
00159         if( array_key_exists( 3, $splitID ) && is_numeric( $splitID[3] ) )
00160         {
00161                 // Get all entries for the user $splitID[1]
00162                 $entries = new blogger_entries( array( $viewUser ) );
00163                 $renderedData = $entries->render( $viewUser, $splitID[3] );
00164         }
00165         // Otherwise, show it all
00166         else
00167         {
00168                 // If we actually do have a fourth entry anyway, it means we're either editing, or showing a category/categories
00169                 if( array_key_exists( 3, $splitID ) )
00170                 {
00171                         // Either we're editing the user's entries...
00172                         if( profileEditAllowed($viewUser) && ( $splitID[3] == "edit" || $splitID[3] == "delete" || $splitID[3] == "publish" ) )
00173                         {
00174                                 // Get all entries for the user $splitID[1]
00175                                 $entries = new blogger_entries( array( $viewUser ) );
00176                                 $entries->edit = true;
00177                                 $renderedData = $entries->render( $viewUser );
00178                         }
00179                         // We are showing an entry
00180                         else if( $splitID[3] == "entry" )
00181                         {
00182                                 if( array_key_exists( 4, $splitID ) && is_numeric( $splitID[4] ) )
00183                                 {
00184                                         // Get all entries for the user $splitID[1]
00185                                         $entries = new blogger_entries( array( $viewUser ) );
00186                                         $renderedData = $entries->render( $viewUser, $splitID[4] );
00187                                 }
00188                                 else
00189                                         header("Location: " . globalIDtoURL( "user/" . $viewUser . "/blogger") );
00190                         }
00191                         // Or we're showing categories...
00192                         else
00193                         {
00194                                 // Get all entries for the user $splitID[1] with the category $splitID[3]
00195                                 $entries = new blogger_entries( array( $viewUser ), split( " ", $splitID[3] ) );
00196                                 $renderedData = $entries->render( $viewUser );
00197                         }
00198                 }
00199                 else
00200                 {
00201                         // Get all entries for the user $splitID[1]
00202                         $entries = new blogger_entries( array( $viewUser ) );
00203                         $renderedData = $entries->render();
00204                 }
00205         }
00206         
00207         if( profileEditAllowed($viewUser) )
00208         {
00209                 $imageOn = siteURL(true) . "$setup_folder/images/selection-on.png";
00210                 $imageOff = siteURL(true) . "$setup_folder/images/selection-off.png";
00211                 
00212                 $images["categories"] = $images["external"] = $images["options"] = $images["edit"] = $images["view"] = $imageOff;
00213                 
00214                 if( $splitID[5] == "categories" )
00215                         $images["categories"] = $imageOn;
00216                 else if( $splitID[5] == "external" )
00217                         $images["external"] = $imageOn;
00218                 else if( $splitID[4] == "options" )
00219                         $images["options"] = $imageOn;
00220                 else if( $splitID[3] == "edit" || $splitID[3] == "delete" )
00221                         $images["edit"] = $imageOn;
00222                 else
00223                         $images["view"] = $imageOn;
00224                 
00225                 $tabwidget->addCommand( i18n("New entry"), i18n("Create a new blog entry"), globalIDtoURL("user/$viewUser/blogger/edit/entry/new") );
00226                 $tabwidget->addCommandSeparator();
00227                 $tabwidget->addCommand( i18n("Categories"), i18n("Manage the personal categories"), globalIDtoURL("user/$viewUser/blogger/edit/options/categories"), $images["categories"] );
00228                 $tabwidget->addCommand( i18n("External Feeds"), i18n("Manage the agregated data"), globalIDtoURL("user/$viewUser/blogger/edit/options/external"), $images["external"] );
00229                 $tabwidget->addCommand( i18n("Options"), i18n("Manage the options for the blogging module"), globalIDtoURL("user/$viewUser/blogger/edit/options"), $images["options"] );
00230                 $tabwidget->addCommandSeparator();
00231                 $tabwidget->addCommand( i18n("View"), i18n("View the blog entries"), globalIDtoURL("user/$viewUser/blogger"), $images["view"] );
00232                 $tabwidget->addCommand( i18n("Edit"), i18n("Edit the blog and its entries"), globalIDtoURL("user/$viewUser/blogger/edit"), $images["edit"] );
00233         }
00234         
00235         return $renderedData;
00236 }
00237 
00245 function globalID_blogger( $splitID )
00246 {
00247         $pageID = null;
00248 /*      
00249         // Is the globalID directly aimed at this module?
00250         // Not yet implemented - blogger mod does not know which page the blog is on...
00251         if( $splitID[0] == "blogger" )
00252         {
00253                 $_REQUEST["page_id"] = $foo_pageID;
00254                 $pageID = $foo_pageID;
00255         }
00256         else
00257         */
00258         // Or is it aimed at the module's profile module?
00259         if( $splitID[0] == "user" && $splitID[2] == "blogger" )
00260         {
00261                 $_REQUEST["module"] = "profilemodule_blogger";
00262                 $pageID = "13";
00263         }
00264         
00265         return $pageID;
00266 }
00267 
00268 function blogger_savecategories()
00269 {
00270         global $setup_folder, $blogcategories;
00271         
00272         $filename = "$setup_folder/modules/blogger/categories.php";
00273         if (file_exists($filename))
00274                 unlink($filename);
00275         
00276         natcasesort($blogcategories); // Sort categories alphabetically...
00277         
00278         file_put_contents($filename, array_export( $blogcategories, "blogcategories" ) );
00279         
00280         chmod($filename, 0664);// make sure the file is actually accessible...
00281 }
00282 
00283 $filename = "$setup_folder/modules/blogger/categories.php";
00284 if (file_exists($filename))
00285         include($filename);
00286 else
00287 {
00288         $blogcategories = array("system_category");
00289         blogger_savecategories();
00290 }
00291 
00292 function modulesetup_blogger()
00293 {
00294         global $blogcategories, $theModuleSection, $theModuleSubsection;
00295         
00298         $dialog = new SimpleListEditor( "setup/modulesetup/blogger", $theModuleSection, $blogcategories, $theModuleSubsection );
00299         $dialog->title = i18n("Category");
00300         $dialog->description = i18n("A string containing the name of the category. Please note that any spaces will be translated to underscores.");
00301         $renderedContent = renderInformationBox( i18n("Categories"), $dialog->render() );
00302         if( $dialog->changed )
00303         {
00304                 foreach( $dialog->items as $key => $value )
00305                         $dialog->items[$key] = str_replace( " ", "_", $value );
00306                 // Insert the system category item and then add all the rest of the items
00307                 $blogcategories = array( "system_category" ) + $dialog->items;
00308                 blogger_savecategories();
00309         }
00310         
00311         // We show help at the bottom of the page on the overview, not the edit subsections...
00312         if( $theModuleSection == "" )
00313                 $renderedContent .= renderInformationBox( i18n("System entries"), i18n("To create system entries, add the System category to your entries. Only administrators are able to use the System category. Use &#92;blogall(system_category) to show these entries.") );
00314         
00315         return $renderedContent;
00316 }
00317 
00326 function globalIDThumbnail_blogger( $splitID )
00327 {
00328         global $module_folder;
00329         $data = array( "uri" => siteURL(true) . "$module_folder/blogger/thumb.png", "width" => 64, "height" => 64 );
00330         return $data;
00331 }
00332 
00333 ?>

Generated on Sun Oct 26 20:33:12 2008 for The Travelsized Content Management System by  doxygen 1.5.5