Dotclear

Changeset 372


Ignore:
Timestamp:
03/26/08 21:35:17 (16 years ago)
Author:
Oaz
Message:

simpleWebsite 1.1
 http://barrejadis.azeau.com/post/2008/03/22/Extension-Simple-Website-v11-pour-Dotclear-2

Location:
plugins/simpleWebsite/trunk
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/simpleWebsite/trunk/_admin.php

    r370 r372  
    6767   
    6868  // 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) 
    7070  { 
    7171    $html = '<ul style="padding-left: 20px;">'; 
     
    7373      if($item['parent_id'] == $parent_id) { 
    7474        $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) ); 
    7676      } 
    7777    } 
     
    9191     
    9292    // 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 AND M.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"; 
    9494    $menuView = '<ul style="padding-left: 5px;">'; 
    9595    $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) ); 
    9797    $menuView .= '</ul>'; 
    9898?> 
     
    126126   
    127127  // 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) 
    129129  { 
    130130    $meta->delPostMeta($post_id,$meta_type); 
     
    148148   
    149149  // 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) 
    151151  { 
    152152    $meta->delPostMeta($post_id, 'swMenuChain'); 
     
    174174     
    175175    // 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)); 
    177177 
    178178    // save menu tag 
    179179    self::savePostMeta($meta, $post_id, 'swMenuTag', self::getMenuTag($meta,$post), 'swMenuTag', ''); 
     180    //self::savePostMeta($meta, $post_id, 'tag', self::getMenuTag($meta,$post), 'swMenuTag', ''); 
    180181 
    181182    // save template file name 
     
    191192    $widgets->create('swMenu',__('Simple Website Menu'),array('SimpleWebsiteTemplates','menuWidget')); 
    192193    $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); 
    195201  } 
    196202} 
  • plugins/simpleWebsite/trunk/_define.php

    r370 r372  
    2424     /* Description*/         "Define a simple website (menu items, associated pages, custom templates)", 
    2525     /* Author */             "Olivier Azeau", 
    26      /* Version */            '1.0', 
     26     /* Version */            '1.1', 
    2727     /* Permissions */        null 
    2828); 
  • plugins/simpleWebsite/trunk/_public.php

    r370 r372  
    3030$core->tpl->addBlock('EntryNext',array('SimpleWebsiteTemplates','entryNext')); 
    3131$core->tpl->addBlock('EntryPrevious',array('SimpleWebsiteTemplates','entryPrevious')); 
     32$core->tpl->addBlock('swSetHierarchyRef',array('SimpleWebsiteTemplates','setHierarchyRef')); 
     33$core->tpl->addBlock('swEntryIfHierarchy',array('SimpleWebsiteTemplates','entryIfHierarchy')); 
    3234 
    3335$core->tpl->addValue('swMenuFeedURL',array('SimpleWebsiteTemplates','menuFeedURL')); 
    3436$core->tpl->addValue('swSitemapURL',array('SimpleWebsiteTemplates','sitemapURL')); 
    3537 
     38$core->tpl->addValue('swShowContext',array('SimpleWebsiteTemplates','showContext')); // for debugging purpose 
     39 
    3640$core->addBehavior('templateBeforeBlock',array('SimpleWebsiteTemplates','beforeBlock')); 
     41$core->addBehavior('templateAfterBlock',array('SimpleWebsiteTemplates','afterBlock')); 
    3742 
    3843$core->url->register(SIMPLEWEBSITE_SECTION,SIMPLEWEBSITE_SECTION,'^'.SIMPLEWEBSITE_SECTION.'/(.+)$',array('SimpleWebsitePages','section')); 
    3944$core->url->register(SIMPLEWEBSITE_FEED,SIMPLEWEBSITE_FEED,'^'.SIMPLEWEBSITE_FEED.'/(.+)$',array('SimpleWebsitePages','feed')); 
    4045$core->url->register(SIMPLEWEBSITE_SITEMAP,SIMPLEWEBSITE_SITEMAP,'^'.SIMPLEWEBSITE_SITEMAP.'$',array('SimpleWebsitePages','sitemap')); 
     46 
     47define('SIMPLEWEBSITE_PHPOPEN', '<?php require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php");'."\n"); 
    4148 
    4249class SimpleWebsiteTemplates 
     
    4653  public static function customPostContent($attr,$content) 
    4754  { 
    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(); 
    5257    if ($swCurrentTemplateContent) : 
    5358      echo $swCurrentTemplateContent; 
     
    8994  public static function menuHierarchyEntries($attr,$content) 
    9095  { 
    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).'); 
    9598    while($_ctx->posts->fetch()) : 
    9699    ?>'. 
     
    103106  public static function menuLevelEntries($attr,$content) 
    104107  { 
    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).'); 
    109110    while($_ctx->posts->fetch()) : 
    110111    ?>'. 
     
    113114  } 
    114115      
    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". 
    121141    '<?php while($_ctx->posts->fetch()) : 
    122142    ?>'. 
     
    126146     } 
    127147      
    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". 
    134153    '<?php while($_ctx->posts->fetch()) : 
    135154    ?>'. 
     
    143162    if ($b == 'Entries') { 
    144163               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"; 
    150167          } elseif ($b == 'Comments') { 
    151168               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 
    152182               "<?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". 
    156186               "?>\n"; 
    157187          } 
     
    162192  public static function menuFeedURL($attr) 
    163193  { 
     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  { 
    164210    return 
    165211    '<?php 
    166     require_once($core->plugins->moduleRoot("simpleWebsite")."/tools.php"); 
    167     echo SimpleWebsiteTools::GetCurrentMenuFeedURL('.self::makeArray($attr).'); 
     212      print_r($_ctx->stack); 
    168213    ?>'; 
    169214  } 
    170215 
    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 
    209217  public static function menuWidget(&$widget) 
    210218  { 
    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; 
    215220    $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'); 
    219223    $result .= '</div>'; 
    220224    return $result; 
  • plugins/simpleWebsite/trunk/tools.php

    r370 r372  
    3232class SimpleWebsiteSitemapPost 
    3333{ 
    34   public $post_title; 
     34  public $post_id, $post_title, $post_dt; 
    3535   
    3636     function __construct() { 
     
    9191  } 
    9292 
     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 
    93100  public static function CurrentEntriesLimit($attr) { 
    94101    global $_ctx, $_page_number; 
     
    163170    $params['sql'] = "AND M.meta_type='swParentMenuItem' AND M.meta_id='".$root_id."'"; 
    164171    $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']; 
    166174    $posts = $core->blog->getPosts( $params ); 
    167175    $posts->extend("SimpleWebsiteExtMenuItemPost"); 
     
    169177  } 
    170178 
     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 
    171188  public static function AddMenuEntriesSelection(&$params,$attr,$comments) 
    172189     { 
     
    174191    $prefix = $core->blog->prefix; 
    175192    $root_id = isset($attr['parent_id']) ? $attr['parent_id'] : self::CurrentPostId(); 
     193    if( !isset($params['sql']) ) 
     194      $params['sql'] = ''; 
    176195    if( $root_id == 'home' ) { 
    177196      $params['sql'] .= " AND P.post_id NOT IN (SELECT post_id FROM ".$prefix."meta WHERE meta_type='swMenuChain')"; 
    178197    } else { 
     198      if( !isset($params['from']) ) 
     199        $params['from'] = ''; 
    179200      $params['from'] .= ' INNER JOIN '.$prefix.'meta M ON P.post_id=M.post_id'; 
    180201      $params['from'] .= ' INNER JOIN '.$prefix.'meta T ON T.meta_id=M.meta_id'; 
    181202      $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) 
    195212     { 
    196213    global $core, $_ctx; 
     
    250267    // return comments feed url if requested 
    251268    $feedType = preg_match('#^(rss2|atom)$#',$attr['type']) ? $attr['type'] : 'rss2'; 
    252     if( $attr['comments'] ) 
     269    if( isset($attr['comments']) && $attr['comments'] ) 
    253270      return $base.'/'.$currentUrl.'/'.$feedType.'/comments'; 
    254271     
Note: See TracChangeset for help on using the changeset viewer.

Sites map