Changeset 908 for plugins/pageless

Show
Ignore:
Timestamp:
09/11/08 19:43:23 (4 months ago)
Author:
bcse
Message:

1. Add locales
2. Change license to Apache License 2.0

Location:
plugins/pageless/trunk
Files:
9 added
4 modified

Legend:

Unmodified
Added
Removed
  • plugins/pageless/trunk/pageless.php

    r730 r908  
    1 <?php foreach ( $posts as $post ) { ?> 
     1<?php foreach ($posts as $post) { ?> 
    22        <div id="entry-<?php echo $post->slug; ?>" class="hentry entry <?php echo $post->statusname , ' ' , $post->tags_class; ?>"> 
    33            <div class="entry-head"> 
     
    66                    <li class="entry-date"><abbr class="published" title="<?php echo $post->pubdate_iso; ?>"><?php echo $post->pubdate_out; ?></abbr></li> 
    77                    <li class="entry-time"><abbr class="published" title="<?php echo $post->pubdate_iso; ?>"><?php echo $post->pubdate_time; ?></abbr></li> 
    8                     <li class="comments-link"><a href="<?php echo $post->permalink; ?>#comments" title="<?php _e('Comments to this post') ?>"><?php printf( _n('%1$d Comment', '%1$d Comments', $post->comments->approved->count), $post->comments->approved->count ); ?></a></li> 
    9 <?php if ( is_array( $post->tags ) ) { ?> 
     8                    <li class="comments-link"><a href="<?php echo $post->permalink; ?>#comments" title="<?php _e('Comments to this post', $this->class_name) ?>"><?php printf(_n('%1$d Comment', '%1$d Comments', $post->comments->approved->count, $this->class_name), $post->comments->approved->count); ?></a></li> 
     9<?php if (is_array($post->tags)) { ?> 
    1010                    <li class="entry-tags"><?php echo $post->tags_out; ?></li> 
    1111<?php } ?> 
    12 <?php if ( isset($user) && $user ) { ?> 
    13                     <li class="entry-edit"><a href="<?php URL::out( 'admin', 'page=publish&slug=' . $post->slug); ?>" title="<?php _e('Edit post') ?>"><?php _e('Edit') ?></a></li> 
     12<?php if (isset($user) && $user) { ?> 
     13                    <li class="entry-edit"><a href="<?php URL::out('admin', 'page=publish&slug=' . $post->slug); ?>" title="<?php _e('Edit post', $this->class_name) ?>"><?php _e('Edit', $this->class_name) ?></a></li> 
    1414<?php } ?> 
    1515                </ul> 
  • plugins/pageless/trunk/pageless.plugin.php

    r730 r908  
    11<?php 
    22/** 
    3  * Pageless Plugin: Make your blog pageless 
    4  * 
    5  * To use this plugin, your HTML structure must like this: 
    6  * 
    7  *   <div id="entry-post1" class="entry"> 
    8  *       blah blah... 
    9  *   </div> 
    10  *   <div id="entry-post2" class="entry"> 
    11  *       blah blah... 
    12  *   </div> 
    13  *   <div id="pager"> 
    14  *       blah blah... 
    15  *   </div> 
    16  * 
    17  * 1. Every post¡Šs container must have an ID named ¡§entry-{$slug}¡š. 
    18  *    If you are sure you won't write any post which slug is begin with 
    19  *    ¡§entry-¡š or ¡§page-¡š, then you can simply named it ¡§{$slug}¡š. 
    20  * 2. Every post must have an identical CSS class, e.g. ¡§entry¡š, and 
    21  *    this CSS class must not appear elsewhere. You have to put this 
    22  *    in ¡§Class name of posts¡š. 
    23  * 3. The page selector¡Šs container must have an ID, e.g. ¡§pager¡š. 
    24  *    You have to put this in ¡§ID of page selector¡š. 
    25  * 4. You can put custom ¡¥pageless.php¡Š in the activated theme directory. 
    26  *    The plugin will use this template instead of the default one. 
     3 * Pageless Plugin: Give your blog the ability of Infinite scrolling, instead of breaking content into ‘pages.’ 
    274 */ 
    285 
     
    4825        return array( 
    4926            'name' => 'Pageless', 
    50             'version' => '0.1', 
     27            'version' => '0.2', 
    5128            'url' => 'http://blog.bcse.info/pageless-plugin-for-habari', 
    5229            'author' => 'Joel Lee', 
    5330            'authorurl' => 'http://blog.bcse.info/', 
    54             'license' => 'MIT License', 
    55             'description' => 'Make your blog pageless', 
     31            'license' => 'Apache License 2.0', 
     32            'description' => 'Give your blog the ability of Infinite scrolling, instead of breaking content into ‘pages.’', 
    5633            'copyright' => '2008' 
    5734        ); 
     
    6340    public function action_update_check() 
    6441    { 
    65         Update::add( 'Pageless', '9b146781-0ee5-406a-aed5-90d661f76ade', $this->info->version ); 
     42        Update::add('Pageless', '9b146781-0ee5-406a-aed5-90d661f76ade', $this->info->version); 
    6643    } 
    6744 
     
    7249     * @return array The array of actions to attach to the specified $plugin_id 
    7350     **/ 
    74     public function filter_plugin_config( $actions, $plugin_id ) 
    75     { 
    76         if ( $plugin_id === $this->plugin_id() ) { 
    77             $actions[] = _t( 'Configure' ); 
     51    public function filter_plugin_config($actions, $plugin_id) 
     52    { 
     53        if ($plugin_id === $this->plugin_id()) { 
     54            $actions[] = _t('Configure', $this->class_name); 
    7855        } 
    7956 
     
    8663     * @param string $action The action string supplied via the filter_plugin_config hook 
    8764     **/ 
    88     public function action_plugin_ui( $plugin_id, $action ) 
    89     { 
    90         if ( $plugin_id === $this->plugin_id() ) { 
    91             switch ( $action ) { 
    92                 case _t( 'Configure' ): 
    93                     $ui = new FormUI( $this->class_name ); 
    94  
    95                     $num_item = $ui->append( 'text', 'num_item', 'option:' . $this->class_name . '__num_item', _t( 'How many posts to load each time?' ) ); 
    96                     $num_item->add_validator( 'validate_uint' ); 
    97                     $num_item->add_validator( 'validate_required' ); 
    98  
    99                     $post_class = $ui->append( 'text', 'post_class', 'option:' . $this->class_name . '__post_class', _t( 'Class name of posts:' ) ); 
    100                     $post_class->add_validator( 'validate_required' ); 
    101  
    102                     $pager_id = $ui->append( 'text', 'pager_id', 'option:' . $this->class_name . '__pager_id', _t( 'ID of page selector:' ) ); 
    103                     $pager_id->add_validator( 'validate_required' ); 
     65    public function action_plugin_ui($plugin_id, $action) 
     66    { 
     67        if ($plugin_id === $this->plugin_id()) { 
     68            switch ($action) { 
     69                case _t('Configure', $this->class_name): 
     70                    $ui = new FormUI($this->class_name); 
     71 
     72                    $num_item = $ui->append('text', 'num_item', 'option:' . $this->class_name . '__num_item', _t('How many posts to load each time?', $this->class_name)); 
     73                    $num_item->add_validator('validate_uint'); 
     74                    $num_item->add_validator('validate_required'); 
     75 
     76                    $post_class = $ui->append('text', 'post_class', 'option:' . $this->class_name . '__post_class', _t('CSS Class Name of Posts', $this->class_name)); 
     77                    $post_class->add_validator('validate_required'); 
     78 
     79                    $pager_id = $ui->append('text', 'pager_id', 'option:' . $this->class_name . '__pager_id', _t('ID of Page Selector', $this->class_name)); 
     80                    $pager_id->add_validator('validate_required'); 
    10481 
    10582                    // When the form is successfully completed, call $this->updated_config() 
    106                     $ui->append( 'submit', 'save', _t( 'Save' )); 
    107                     $ui->set_option( 'success_message', _t( 'Options saved' ) ); 
     83                    $ui->append('submit', 'save', _t('Save', $this->class_name)); 
     84                    $ui->set_option('success_message', _t('Options saved', $this->class_name)); 
    10885                    $ui->out(); 
    10986                    break; 
     
    11289    } 
    11390 
    114     public function validate_uint( $value ) 
    115     { 
    116         if ( ! ctype_digit($value) || ! strstr($value, '.') || $value < 0 ) { 
    117             return array( _t( 'This field must be positive integer.' ) ); 
     91    public function validate_uint($value) 
     92    { 
     93        if (!ctype_digit($value) || strstr($value, '.') || $value < 0) { 
     94            return array(_t('This field must be positive integer.', $this->class_name)); 
    11895        } 
    11996        return array(); 
     
    124101     * @return bool True if options should be stored 
    125102     **/ 
    126     public function updated_config( $ui ) 
     103    public function updated_config($ui) 
    127104    { 
    128105        return true; 
     
    132109     * On plugin activation, set the default options 
    133110     */ 
    134     public function action_plugin_activation( $file ) 
    135     { 
    136         if ( realpath( $file ) === __FILE__ ) { 
    137             $this->class_name = strtolower( get_class( $this ) ); 
    138             foreach ( $this->default_options as $name => $value ) { 
    139                 $current_value = Options::get( $this->class_name . '__' . $name ); 
    140                 if ( is_null($current_value) ) { 
    141                     Options::set( $this->class_name . '__' . $name, $value ); 
     111    public function action_plugin_activation($file) 
     112    { 
     113        if (realpath($file) === __FILE__) { 
     114            $this->class_name = strtolower(get_class($this)); 
     115            foreach ($this->default_options as $name => $value) { 
     116                $current_value = Options::get($this->class_name . '__' . $name); 
     117                if (is_null($current_value)) { 
     118                    Options::set($this->class_name . '__' . $name, $value); 
    142119                } 
    143120            } 
     
    150127    public function action_init() 
    151128    { 
    152         $this->class_name = strtolower( get_class( $this ) ); 
    153         foreach ( $this->default_options as $name => $value ) { 
    154             $this->config[$name] = Options::get( $this->class_name . '__' . $name ); 
    155         } 
    156         $this->add_template( 'pageless', dirname(__FILE__) . '/pageless.php' ); 
    157     } 
    158  
    159     public function filter_rewrite_rules( $rules ) 
     129        $this->class_name = strtolower(get_class($this)); 
     130        foreach ($this->default_options as $name => $value) { 
     131            $this->config[$name] = Options::get($this->class_name . '__' . $name); 
     132        } 
     133        $this->load_text_domain($this->class_name); 
     134        $this->add_template('pageless', dirname(__FILE__) . '/pageless.php'); 
     135    } 
     136 
     137    public function filter_rewrite_rules($rules) 
    160138    { 
    161139        $rules[] = new RewriteRule(array( 
     
    169147            'description' => 'display_pageless' 
    170148        )); 
     149        $rules[] = new RewriteRule(array( 
     150            'name' => 'display_pageless_js', 
     151            'parse_regex' => '%^scripts/jquery.pageless_(?P<config>[0-9a-f]{32}).js$%i', 
     152            'build_str' =>  'scripts/jquery.pageless_{$config}.js', 
     153            'handler' => 'UserThemeHandler', 
     154            'action' => 'display_pageless_js', 
     155            'rule_class' => RewriteRule::RULE_PLUGIN, 
     156            'is_active' => 1, 
     157            'description' => 'display_pageless_js' 
     158        )); 
    171159        return $rules; 
    172160    } 
    173161 
    174     public function theme_footer() 
    175     { 
    176         if ( count(self::$handler_vars) === 0 ) 
    177             self::$handler_vars = Controller::get_handler_vars(); 
    178  
     162    public function action_handler_display_pageless_js($handler_vars) 
     163    { 
    179164        // If 'slug' exists, then it must be single, don't do anything 
    180         if ( ! array_key_exists('slug', self::$handler_vars) ) { 
     165        if (!isset($handler_vars['slug'])) { 
    181166            // Determine act_display 
    182167            $filter_type = ''; 
    183168            $filter_param = ''; 
    184             if ( array_key_exists('tag', self::$handler_vars) ) { 
     169            if (isset($handler_vars['tag'])) { 
    185170                $filter_type = 'tag'; 
    186                 $filter_param = self::$handler_vars['tag']; 
     171                $filter_param = $handler_vars['tag']; 
    187172            } else 
    188             if ( array_key_exists('year', self::$handler_vars) ) { 
     173            if (isset($handler_vars['year'])) { 
    189174                $filter_type = 'date'; 
    190                 $filter_param = self::$handler_vars['year']; 
    191                 if ( array_key_exists('month', self::$handler_vars) ) { 
    192                     $filter_param .= '/' . self::$handler_vars['month']; 
     175                $filter_param = $handler_vars['year']; 
     176                if (isset($handler_vars['month'])) { 
     177                    $filter_param .= '/' . $handler_vars['month']; 
    193178                } 
    194                 if ( array_key_exists('day', self::$handler_vars) ) { 
    195                     $filter_param .= '/' . self::$handler_vars['day']; 
     179                if (isset($handler_vars['day'])) { 
     180                    $filter_param .= '/' . $handler_vars['day']; 
    196181                } 
    197182            } else 
    198             if ( array_key_exists('criteria', self::$handler_vars) ) { 
     183            if (isset($handler_vars['criteria'])) { 
    199184                $filter_type = 'search'; 
    200                 $filter_param = self::$handler_vars['criteria']; 
    201             } 
    202  
    203             echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>'; 
    204             echo '<script type="text/javascript" src="' . Site::get_url('scripts') . '/jquery.spinner.js"></script>'; 
    205             echo '<script type="text/javascript"> 
    206 (function($){ 
    207     $(document).ready(function() { 
     185                $filter_param = $handler_vars['criteria']; 
     186            } 
     187 
     188            $out = '(function($){ 
     189    $(function() { 
    208190        $("#' . $this->config['pager_id'] . '").hide(); 
    209191 
     
    223205 
    224206        function appendEntries() { 
    225             if ( $(window).scrollTop() >= $(document).height() - ( $(window).height() * 2 ) ) { 
     207            if ($(window).scrollTop() >= $(document).height() - ($(window).height() * 2)) { 
    226208                var slug = $(".' . $this->config['post_class'] . ':last").attr("id").replace(/^(?:entry|page)-/, ""); 
    227209                $.ajax({ 
    228                     url: "' . URL::get( 'display_pageless', array( 'type' => $filter_type, 'param' => $filter_param ) ) . '".replace("{$slug}", slug), 
     210                    url: "' . URL::get('display_pageless', array('type' => $filter_type, 'param' => $filter_param)) . '".replace("{$slug}", slug), 
    229211                    beforeSend: function() { 
    230212                        spinner.start(); 
     
    232214                    }, 
    233215                    success: function(response) { 
    234                         if ( response.length > 100 ) { 
     216                        if (response.length > 100) { 
    235217                            $(".' . $this->config['post_class'] . ':last").after(response); 
    236218                        } else { 
     
    240222                    complete: function() { 
    241223                        spinner.stop(); 
    242                         if ( ! the_end && activated ) { 
     224                        if (!the_end && activated) { 
    243225                            $(window).bind("scroll", appendEntries); 
    244226                        } 
     
    253235        function toggleScroll() { 
    254236            activated = !activated; 
    255             if ( ! the_end && activated ) { 
     237            if (!the_end && activated) { 
    256238                $(window).bind("scroll", appendEntries); 
    257239                $("#' . $this->config['pager_id'] . '").hide(); 
     
    264246        $(document).bind("dblclick", toggleScroll); 
    265247    }); 
    266 })(jQuery); 
    267 </script>'; 
     248})(jQuery);'; 
     249 
     250            ob_clean(); 
     251            header('Content-type: text/javascript'); 
     252            header('ETag: ' . md5($out)); 
     253            header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 315360000) . ' GMT'); 
     254            header('Cache-Control: max-age=315360000'); 
     255            echo $out; 
     256        } 
     257 
     258        exit; 
     259    } 
     260 
     261    public function theme_footer() 
     262    { 
     263        if (count(self::$handler_vars) === 0) 
     264            self::$handler_vars = Controller::get_handler_vars(); 
     265 
     266        // If 'slug' exists, then it must be single, don't do anything 
     267        if (!isset(self::$handler_vars['slug'])) { 
     268            Stack::add('template_footer_javascript', 'http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js', 'jquery'); 
     269            Stack::add('template_footer_javascript', Site::get_url('scripts') . '/jquery.spinner.js', 'jquery.spinner'); 
     270            Stack::add('template_footer_javascript', URL::get('display_pageless_js', array('config' => md5(serialize(array_merge($this->config, self::$handler_vars))))), 'jquery.pageless'); 
    268271        } 
    269272    } 
  • plugins/pageless/trunk/pagelesshandler.php

    r730 r908  
    2020    { 
    2121        $this->handler_vars = array_merge($this->default_fields, $this->handler_vars); 
    22         $post = Post::get( array( 'slug' => $this->handler_vars['slug'] ) ); 
    23         if ( $post instanceof Post ) { 
     22        $post = Post::get(array('slug' => $this->handler_vars['slug'])); 
     23        if ($post instanceof Post) { 
    2424            // Default params 
    2525            $params = array( 
    2626                'before' => $post->pubdate, 
    2727                'content_type' => $post->content_type, 
    28                 'limit' => Options::get( 'pageless__num_item' ), 
     28                'limit' => Options::get('pageless__num_item'), 
    2929                'orderby' => 'pubdate DESC' 
    3030                ); 
    3131 
    3232            // Additional filters, in other word, handling act_display 
    33             if ( array_key_exists('type', $this->handler_vars) ) { 
    34                 if ( $this->handler_vars['type'] === 'tag' ) { 
     33            if (isset($this->handler_vars['type'])) { 
     34                if ($this->handler_vars['type'] === 'tag') { 
    3535                    $params['tag_slug'] = $this->handler_vars['param']; 
    3636                } else 
    37                 if ( $this->handler_vars['type'] === 'date' ) { 
     37                if ($this->handler_vars['type'] === 'date') { 
    3838                    $date = explode('/', $this->handler_vars['param']); 
    3939                    $params_count = count($date); 
    40                     switch ( $params_count ) { 
     40                    switch ($params_count) { 
    4141                        case 3: 
    4242                            $params['day'] = $date[2]; 
     
    4949                    } 
    5050                } else 
    51                 if ( $this->handler_vars['type'] === 'search' ) { 
     51                if ($this->handler_vars['type'] === 'search') { 
    5252                    $params['criteria'] = $this->handler_vars['param']; 
    5353                } 
     
    5555 
    5656            // Get $posts -> Assign $posts to theme -> Display template 
    57             $posts = Posts::get( $params ); 
    58             $this->theme->assign( 'posts', $posts ); 
    59             $this->theme->display( 'pageless' ); 
     57            $posts = Posts::get($params); 
     58            $this->theme->assign('posts', $posts); 
     59            $this->theme->display('pageless'); 
    6060        } 
    6161    }