Changeset 372
- Timestamp:
- 03/26/08 21:35:17 (16 years ago)
- Location:
- plugins/simpleWebsite/trunk
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/simpleWebsite/trunk/_admin.php
r370 r372 67 67 68 68 // creates a menu hierarchy <ul> tag for post sidebar corresponding to a given menu level (identified by its parent) and its content 69 public static function displayMenuHierarchy( &$items,$parent_id,$currentParent,$currentPost,$isSelectable)69 public static function displayMenuHierarchy($items,$parent_id,$currentParent,$currentPost,$isSelectable) 70 70 { 71 71 $html = '<ul style="padding-left: 20px;">'; … … 73 73 if($item['parent_id'] == $parent_id) { 74 74 $itemIsSelectable = $isSelectable && ($item['id'] != $currentPost); 75 $html .= self::displayMenuItemInHierarchy( $item['id'], $item['title'], $currentParent, $itemIsSelectable, self::displayMenuHierarchy( &$items,$item['id'],$currentParent,$currentPost,$itemIsSelectable) );75 $html .= self::displayMenuItemInHierarchy( $item['id'], $item['title'], $currentParent, $itemIsSelectable, self::displayMenuHierarchy($items,$item['id'],$currentParent,$currentPost,$itemIsSelectable) ); 76 76 } 77 77 } … … 91 91 92 92 // init menu view with parent selection 93 $allMenuItems = "SELECT P.post_title title, P.post_id id, P.post_url url, M.meta_id parent_id FROM ".$blog->prefix."post P, ".$blog->prefix."meta M WHERE P.post_id = M.post_id ANDM.meta_type='swParentMenuItem' ORDER BY P.post_url";93 $allMenuItems = "SELECT P.post_title AS title, P.post_id AS id, P.post_url AS url, M.meta_id AS parent_id FROM ".$blog->prefix."post P INNER JOIN ".$blog->prefix."meta M ON P.post_id = M.post_id WHERE M.meta_type='swParentMenuItem' ORDER BY P.post_url"; 94 94 $menuView = '<ul style="padding-left: 5px;">'; 95 95 $menuView .= self::displayMenuItemInHierarchy( 'none', __('None'), $currentParent, true, '' ); 96 $menuView .= self::displayMenuItemInHierarchy( 'home', __('Home'), $currentParent, true, self::displayMenuHierarchy($blog->con->select($allMenuItems)->rows(),'home',$currentParent,$post->post_id,true) );96 $menuView .= self::displayMenuItemInHierarchy( 'home', __('Home'), $currentParent, true, @self::displayMenuHierarchy($blog->con->select($allMenuItems)->rows(),'home',$currentParent,$post->post_id,true) ); 97 97 $menuView .= '</ul>'; 98 98 ?> … … 126 126 127 127 // save a single meta information for the given post 128 public static function savePostMeta(&$meta, &$post_id,$meta_type,&$oldValue,$newValueKey,$defaultValue)128 public static function savePostMeta(&$meta,$post_id,$meta_type,$oldValue,$newValueKey,$defaultValue) 129 129 { 130 130 $meta->delPostMeta($post_id,$meta_type); … … 148 148 149 149 // saves the menu chain for a given post and all its descendants in the menu hierarchy 150 public static function saveMenuChain(&$meta,&$blog, &$post_id,&$menu_chain)150 public static function saveMenuChain(&$meta,&$blog,$post_id,$menu_chain) 151 151 { 152 152 $meta->delPostMeta($post_id, 'swMenuChain'); … … 174 174 175 175 // save menu chain 176 self::saveMenuChain($meta,$blog,$post_id,self::computeMenuChain( &$blog,&$parent_post_id,&$post_id));176 self::saveMenuChain($meta,$blog,$post_id,self::computeMenuChain($blog,$parent_post_id,$post_id)); 177 177 178 178 // save menu tag 179 179 self::savePostMeta($meta, $post_id, 'swMenuTag', self::getMenuTag($meta,$post), 'swMenuTag', ''); 180 //self::savePostMeta($meta, $post_id, 'tag', self::getMenuTag($meta,$post), 'swMenuTag', ''); 180 181 181 182 // save template file name … … 191 192 $widgets->create('swMenu',__('Simple Website Menu'),array('SimpleWebsiteTemplates','menuWidget')); 192 193 $widgets->swMenu->setting('title',__('Title:'),__('Menu')); 193 $widgets->swMenu->setting('sitemapOn',__('Display Sitemap'),1,'check'); 194 $widgets->swMenu->setting('sitemapText',__('Sitemap Text:'),__('Sitemap')); 194 $files = @glob(dirname(__FILE__).'/*.menu.html'); 195 $options = array(); 196 foreach($files as $file) { 197 $base = basename($file,'.menu.html'); 198 $options[$base] = $base; 199 } 200 $widgets->swMenu->setting('content',__('Content:'),current($options),'combo',$options); 195 201 } 196 202 } -
plugins/simpleWebsite/trunk/_define.php
r370 r372 24 24 /* Description*/ "Define a simple website (menu items, associated pages, custom templates)", 25 25 /* Author */ "Olivier Azeau", 26 /* Version */ '1. 0',26 /* Version */ '1.1', 27 27 /* Permissions */ null 28 28 ); -
plugins/simpleWebsite/trunk/_public.php
r370 r372 30 30 $core->tpl->addBlock('EntryNext',array('SimpleWebsiteTemplates','entryNext')); 31 31 $core->tpl->addBlock('EntryPrevious',array('SimpleWebsiteTemplates','entryPrevious')); 32 $core->tpl->addBlock('swSetHierarchyRef',array('SimpleWebsiteTemplates','setHierarchyRef')); 33 $core->tpl->addBlock('swEntryIfHierarchy',array('SimpleWebsiteTemplates','entryIfHierarchy')); 32 34 33 35 $core->tpl->addValue('swMenuFeedURL',array('SimpleWebsiteTemplates','menuFeedURL')); 34 36 $core->tpl->addValue('swSitemapURL',array('SimpleWebsiteTemplates','sitemapURL')); 35 37 38 $core->tpl->addValue('swShowContext',array('SimpleWebsiteTemplates','showContext')); // for debugging purpose 39 36 40 $core->addBehavior('templateBeforeBlock',array('SimpleWebsiteTemplates','beforeBlock')); 41 $core->addBehavior('templateAfterBlock',array('SimpleWebsiteTemplates','afterBlock')); 37 42 38 43 $core->url->register(SIMPLEWEBSITE_SECTION,SIMPLEWEBSITE_SECTION,'^'.SIMPLEWEBSITE_SECTION.'/(.+)$',array('SimpleWebsitePages','section')); 39 44 $core->url->register(SIMPLEWEBSITE_FEED,SIMPLEWEBSITE_FEED,'^'.SIMPLEWEBSITE_FEED.'/(.+)$',array('SimpleWebsitePages','feed')); 40 45 $core->url->register(SIMPLEWEBSITE_SITEMAP,SIMPLEWEBSITE_SITEMAP,'^'.SIMPLEWEBSITE_SITEMAP.'$',array('SimpleWebsitePages','sitemap')); 46 47 define('SIMPLEWEBSITE_PHPOPEN', '<?php require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php");'."\n"); 41 48 42 49 class SimpleWebsiteTemplates … … 46 53 public static function customPostContent($attr,$content) 47 54 { 48 return 49 '<?php 50 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 51 $swCurrentTemplateContent = SimpleWebsiteTools::GetTemplateContent(); 55 return SIMPLEWEBSITE_PHPOPEN. 56 '$swCurrentTemplateContent = SimpleWebsiteTools::GetTemplateContent(); 52 57 if ($swCurrentTemplateContent) : 53 58 echo $swCurrentTemplateContent; … … 89 94 public static function menuHierarchyEntries($attr,$content) 90 95 { 91 return 92 '<?php 93 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 94 $_ctx->posts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuHierarchy('.self::makeArray($attr).'); 96 return SIMPLEWEBSITE_PHPOPEN. 97 '$_ctx->posts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuHierarchy('.self::makeArray($attr).'); 95 98 while($_ctx->posts->fetch()) : 96 99 ?>'. … … 103 106 public static function menuLevelEntries($attr,$content) 104 107 { 105 return 106 '<?php 107 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 108 $_ctx->posts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuLevel('.self::makeArray($attr).'); 108 return SIMPLEWEBSITE_PHPOPEN. 109 '$_ctx->posts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuLevel('.self::makeArray($attr).'); 109 110 while($_ctx->posts->fetch()) : 110 111 ?>'. … … 113 114 } 114 115 115 public function entryNext($attr,$content) 116 { 117 return 118 '<?php 119 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 120 if( SimpleWebsiteTools::GetNextPost('.self::makeArray($attr).',1) ) : ?>'."\n". 116 // Used in menu widget to define the reference post, that is the one currently displayed on the page 117 // <tpl:swSetHierarchyRef></tpl:swSetHierarchyRef> 118 public static function setHierarchyRef($attr,$content) 119 { 120 return SIMPLEWEBSITE_PHPOPEN. 121 "\$_ctx->swHierarchyRef = SimpleWebsiteTools::CurrentMenuHierarchy(); ?>\n". 122 $content. 123 "<?php \$_ctx->swHierarchyRef = null; ?>\n"; 124 } 125 126 // Used in menu widget together with <tpl:swSetHierarchyRef> to test if the current iterated entry is equal to the reference post 127 // <tpl:swEntryIfHierarchy></tpl:swEntryIfHierarchy> 128 public static function entryIfHierarchy($attr,$content) 129 { 130 return SIMPLEWEBSITE_PHPOPEN. 131 'if( SimpleWebsiteTools::TestHierarchy('.self::makeArray($attr).') ) : ?>'."\n". 132 $content. 133 "<?php endif; ?>\n"; 134 } 135 136 // Overrides the standard <tpl:EntryNext> block to use additional sql parameters 137 public static function entryNext($attr,$content) 138 { 139 return SIMPLEWEBSITE_PHPOPEN. 140 'if( SimpleWebsiteTools::GetNextPost('.self::makeArray($attr).',1) ) : ?>'."\n". 121 141 '<?php while($_ctx->posts->fetch()) : 122 142 ?>'. … … 126 146 } 127 147 128 public function entryPrevious($attr,$content) 129 { 130 return 131 '<?php 132 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 133 if( SimpleWebsiteTools::GetNextPost('.self::makeArray($attr).',-1) ) : ?>'."\n". 148 // Overrides the standard <tpl:EntryPrevious> block to use additional sql parameters 149 public static function entryPrevious($attr,$content) 150 { 151 return SIMPLEWEBSITE_PHPOPEN. 152 'if( SimpleWebsiteTools::GetNextPost('.self::makeArray($attr).',-1) ) : ?>'."\n". 134 153 '<?php while($_ctx->posts->fetch()) : 135 154 ?>'. … … 143 162 if ($b == 'Entries') { 144 163 return 145 "<?php\n". 146 "require_once(\$core->plugins->moduleRoot('simpleWebsite').'/tools.php');\n". 147 //"if(SimpleWebsiteTools::CurrentPostIsMenuItem())\n". 148 "SimpleWebsiteTools::AddMenuEntriesSelection(\$params,".self::makeArray($attr).",false);\n". 149 "?>\n"; 164 SIMPLEWEBSITE_PHPOPEN. 165 "SimpleWebsiteTools::AddMenuEntriesSelection(\$params,".self::makeArray($attr).",false);\n". 166 "?>\n"; 150 167 } elseif ($b == 'Comments') { 151 168 return 169 SIMPLEWEBSITE_PHPOPEN. 170 "if(SimpleWebsiteTools::CurrentPostIsMenuItem()) {\n". 171 "SimpleWebsiteTools::AddMenuEntriesSelection(\$params,".self::makeArray($attr).",true);\n". 172 "\$_ctx->swPosts = \$_ctx->posts; \$_ctx->posts = null;\n". 173 "}\n". 174 "?>\n"; 175 } 176 } 177 178 public static function afterBlock(&$core,$b,$attr) 179 { 180 if ($b == 'Comments') { 181 return 152 182 "<?php\n". 153 " require_once(\$core->plugins->moduleRoot('simpleWebsite').'/tools.php');\n".154 "if(SimpleWebsiteTools::CurrentPostIsMenuItem())\n".155 "SimpleWebsiteTools::AddMenuEntriesSelection(\$params,".self::makeArray($attr).",true);\n".183 "if(\$_ctx->exists('swPosts')) {\n". 184 "\$_ctx->posts = \$_ctx->swPosts; \$_ctx->swPosts = null;\n". 185 "}\n". 156 186 "?>\n"; 157 187 } … … 162 192 public static function menuFeedURL($attr) 163 193 { 194 return SIMPLEWEBSITE_PHPOPEN. 195 'echo SimpleWebsiteTools::GetCurrentMenuFeedURL('.self::makeArray($attr).'); 196 ?>'; 197 } 198 199 // Sitemap URL 200 public static function sitemapURL($attr) 201 { 202 return SIMPLEWEBSITE_PHPOPEN. 203 'echo SimpleWebsiteTools::GetSitemapURL(); 204 ?>'; 205 } 206 207 // for debugging purpose : show the current context stack 208 public static function showContext($attr) 209 { 164 210 return 165 211 '<?php 166 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 167 echo SimpleWebsiteTools::GetCurrentMenuFeedURL('.self::makeArray($attr).'); 212 print_r($_ctx->stack); 168 213 ?>'; 169 214 } 170 215 171 // Sitemap URL 172 public static function sitemapURL($attr) 173 { 174 return 175 '<?php 176 require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 177 echo SimpleWebsiteTools::GetSitemapURL(); 178 ?>'; 179 } 180 181 public static function menuWidgetItem(&$record,&$content,$emphasize=false) 182 { 183 $name = html::escapeHTML($record->post_title); 184 if($emphasize) 185 $name = '<span class="swCurrentItem">'.$name.'</span>'; 186 return '<li><a href="'.$record->getURL().'">'.$name.'</a>'.$content.'</li>'; 187 } 188 189 public static function menuWidgetHierarchy(&$levels,&$posts) 190 { 191 global $_ctx; 192 $result = '<ul>'; 193 if($levels) 194 $levels->fetch(); 195 while( $posts->fetch() ) { 196 if( $posts->post_id == $levels->post_id ) { 197 $childrenPosts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuLevel(array('no_content' => '1','parent_id' => $levels->post_id)); 198 $content = self::menuWidgetHierarchy($levels,$childrenPosts); 199 $result .= self::menuWidgetItem($posts,$content,true); 200 } else { 201 $content = ''; 202 $result .= self::menuWidgetItem($posts,$content); 203 } 204 } 205 $result .= '</ul>'; 206 return $result; 207 } 208 216 // menu widget display mainly consists in evaluating the selected ".menu.html" template file 209 217 public static function menuWidget(&$widget) 210 218 { 211 $toplevelposts = SimpleWebsiteTools::GetOrderedMenuItemsInMenuLevel(array('no_content' => '1','parent_id' => 'home')); 212 if( $toplevelposts->isEmpty() ) 213 return; 214 $levels = SimpleWebsiteTools::GetOrderedMenuItemsInMenuHierarchy(array('no_content' => '1')); 219 global $core; 215 220 $result = '<div>'.($widget->title ? '<h2>'.html::escapeHTML($widget->title).'</h2>' : ''); 216 $result .= self::menuWidgetHierarchy($levels,$toplevelposts); 217 if($widget->sitemapOn) 218 $result .= '<div class="swSitemap"><a href="'.SimpleWebsiteTools::GetSitemapURL().'">'.$widget->sitemapText.'</a></div>'; 221 $core->tpl->setPath(array_merge($core->tpl->getPath(),array(dirname(__FILE__)))); 222 $result .= $core->tpl->getData($widget->content.'.menu.html'); 219 223 $result .= '</div>'; 220 224 return $result; -
plugins/simpleWebsite/trunk/tools.php
r370 r372 32 32 class SimpleWebsiteSitemapPost 33 33 { 34 public $post_ title;34 public $post_id, $post_title, $post_dt; 35 35 36 36 function __construct() { … … 91 91 } 92 92 93 public static function TestHierarchy($attr) { 94 global $core, $_ctx; 95 $wantIn = isset($attr['in']) ? ($attr['in'] == 1) : false; 96 $isIn = $_ctx->swHierarchyRef && in_array( self::CurrentPostId(), $_ctx->swHierarchyRef ); 97 return $isIn == $wantIn; 98 } 99 93 100 public static function CurrentEntriesLimit($attr) { 94 101 global $_ctx, $_page_number; … … 163 170 $params['sql'] = "AND M.meta_type='swParentMenuItem' AND M.meta_id='".$root_id."'"; 164 171 $params['order'] = 'P.post_url ASC'; 165 $params['no_content'] = $attr['no_content']; 172 if( isset($attr['no_content']) ) 173 $params['no_content'] = $attr['no_content']; 166 174 $posts = $core->blog->getPosts( $params ); 167 175 $posts->extend("SimpleWebsiteExtMenuItemPost"); … … 169 177 } 170 178 179 public static function SqlRegexpTest($value,$pattern) 180 { 181 global $core; 182 if( $core->con->driver() == 'pgsql' ) 183 return $value.' ~ '.$pattern; 184 else // mysql, sqlite 185 return $value.' REGEXP '.$pattern; 186 } 187 171 188 public static function AddMenuEntriesSelection(&$params,$attr,$comments) 172 189 { … … 174 191 $prefix = $core->blog->prefix; 175 192 $root_id = isset($attr['parent_id']) ? $attr['parent_id'] : self::CurrentPostId(); 193 if( !isset($params['sql']) ) 194 $params['sql'] = ''; 176 195 if( $root_id == 'home' ) { 177 196 $params['sql'] .= " AND P.post_id NOT IN (SELECT post_id FROM ".$prefix."meta WHERE meta_type='swMenuChain')"; 178 197 } else { 198 if( !isset($params['from']) ) 199 $params['from'] = ''; 179 200 $params['from'] .= ' INNER JOIN '.$prefix.'meta M ON P.post_id=M.post_id'; 180 201 $params['from'] .= ' INNER JOIN '.$prefix.'meta T ON T.meta_id=M.meta_id'; 181 202 $params['from'] .= ' INNER JOIN '.$prefix.'meta H ON T.post_id=H.post_id'; 182 if($comments) { 183 $params['sql'] .= " AND ( ( M.meta_type='tag' AND T.meta_type='swMenuTag'"; 184 $params['sql'] .= " AND H.meta_type='swMenuChain' AND H.meta_id REGEXP '^(.*\.)?".$root_id."(\..*)?$' )"; 185 $params['sql'] .= " OR (H.meta_type='swMenuChain' AND P.post_id=".$root_id.") )"; 186 $_ctx->posts = null; 187 } else { 188 $params['sql'] .= " AND M.meta_type='tag' AND T.meta_type='swMenuTag'"; 189 $params['sql'] .= " AND H.meta_type='swMenuChain' AND H.meta_id REGEXP '^(.*\.)?".$root_id."(\..*)?$'"; 190 } 191 } 192 } 193 194 public function GetNextPost($attr,$dir) 203 $params['sql'] .= " AND T.meta_type='swMenuTag'"; 204 $params['sql'] .= " AND H.meta_type='swMenuChain'"; 205 $params['sql'] .= " AND ".self::SqlRegexpTest("H.meta_id","'^(.*\.)?".$root_id."(\..*)?$'"); 206 if(!$comments) // when listing entries (and not comments), do not list sections 207 $params['sql'] .= " AND M.meta_type='tag'"; 208 } 209 } 210 211 public static function GetNextPost($attr,$dir) 195 212 { 196 213 global $core, $_ctx; … … 250 267 // return comments feed url if requested 251 268 $feedType = preg_match('#^(rss2|atom)$#',$attr['type']) ? $attr['type'] : 'rss2'; 252 if( $attr['comments'] )269 if( isset($attr['comments']) && $attr['comments'] ) 253 270 return $base.'/'.$currentUrl.'/'.$feedType.'/comments'; 254 271
Note: See TracChangeset
for help on using the changeset viewer.