Changeset 908 for plugins/pageless
- Timestamp:
- 09/11/08 19:43:23 (4 months ago)
- Location:
- plugins/pageless/trunk
- Files:
-
- 9 added
- 4 modified
-
locale (added)
-
locale/en-us (added)
-
locale/en-us/LC_MESSAGES (added)
-
locale/en-us/LC_MESSAGES/pageless.mo (added)
-
locale/en-us/LC_MESSAGES/pageless.po (added)
-
locale/zh-tw (added)
-
locale/zh-tw/LC_MESSAGES (added)
-
locale/zh-tw/LC_MESSAGES/pageless.mo (added)
-
locale/zh-tw/LC_MESSAGES/pageless.po (added)
-
pageless.php (modified) (2 diffs)
-
pageless.plugin.php (modified) (15 diffs)
-
pagelesshandler.php (modified) (3 diffs)
-
spinnersmalldark.png (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
plugins/pageless/trunk/pageless.php
r730 r908 1 <?php foreach ( $posts as $post) { ?>1 <?php foreach ($posts as $post) { ?> 2 2 <div id="entry-<?php echo $post->slug; ?>" class="hentry entry <?php echo $post->statusname , ' ' , $post->tags_class; ?>"> 3 3 <div class="entry-head"> … … 6 6 <li class="entry-date"><abbr class="published" title="<?php echo $post->pubdate_iso; ?>"><?php echo $post->pubdate_out; ?></abbr></li> 7 7 <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)) { ?> 10 10 <li class="entry-tags"><?php echo $post->tags_out; ?></li> 11 11 <?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> 14 14 <?php } ?> 15 15 </ul> -
plugins/pageless/trunk/pageless.plugin.php
r730 r908 1 1 <?php 2 2 /** 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.â 27 4 */ 28 5 … … 48 25 return array( 49 26 'name' => 'Pageless', 50 'version' => '0. 1',27 'version' => '0.2', 51 28 'url' => 'http://blog.bcse.info/pageless-plugin-for-habari', 52 29 'author' => 'Joel Lee', 53 30 '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.â', 56 33 'copyright' => '2008' 57 34 ); … … 63 40 public function action_update_check() 64 41 { 65 Update::add( 'Pageless', '9b146781-0ee5-406a-aed5-90d661f76ade', $this->info->version);42 Update::add('Pageless', '9b146781-0ee5-406a-aed5-90d661f76ade', $this->info->version); 66 43 } 67 44 … … 72 49 * @return array The array of actions to attach to the specified $plugin_id 73 50 **/ 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); 78 55 } 79 56 … … 86 63 * @param string $action The action string supplied via the filter_plugin_config hook 87 64 **/ 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'); 104 81 105 82 // 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)); 108 85 $ui->out(); 109 86 break; … … 112 89 } 113 90 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)); 118 95 } 119 96 return array(); … … 124 101 * @return bool True if options should be stored 125 102 **/ 126 public function updated_config( $ui)103 public function updated_config($ui) 127 104 { 128 105 return true; … … 132 109 * On plugin activation, set the default options 133 110 */ 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); 142 119 } 143 120 } … … 150 127 public function action_init() 151 128 { 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) 160 138 { 161 139 $rules[] = new RewriteRule(array( … … 169 147 'description' => 'display_pageless' 170 148 )); 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 )); 171 159 return $rules; 172 160 } 173 161 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 { 179 164 // 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'])) { 181 166 // Determine act_display 182 167 $filter_type = ''; 183 168 $filter_param = ''; 184 if ( array_key_exists('tag', self::$handler_vars)) {169 if (isset($handler_vars['tag'])) { 185 170 $filter_type = 'tag'; 186 $filter_param = self::$handler_vars['tag'];171 $filter_param = $handler_vars['tag']; 187 172 } else 188 if ( array_key_exists('year', self::$handler_vars)) {173 if (isset($handler_vars['year'])) { 189 174 $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']; 193 178 } 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']; 196 181 } 197 182 } else 198 if ( array_key_exists('criteria', self::$handler_vars)) {183 if (isset($handler_vars['criteria'])) { 199 184 $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() { 208 190 $("#' . $this->config['pager_id'] . '").hide(); 209 191 … … 223 205 224 206 function appendEntries() { 225 if ( $(window).scrollTop() >= $(document).height() - ( $(window).height() * 2 )) {207 if ($(window).scrollTop() >= $(document).height() - ($(window).height() * 2)) { 226 208 var slug = $(".' . $this->config['post_class'] . ':last").attr("id").replace(/^(?:entry|page)-/, ""); 227 209 $.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), 229 211 beforeSend: function() { 230 212 spinner.start(); … … 232 214 }, 233 215 success: function(response) { 234 if ( response.length > 100) {216 if (response.length > 100) { 235 217 $(".' . $this->config['post_class'] . ':last").after(response); 236 218 } else { … … 240 222 complete: function() { 241 223 spinner.stop(); 242 if ( ! the_end && activated) {224 if (!the_end && activated) { 243 225 $(window).bind("scroll", appendEntries); 244 226 } … … 253 235 function toggleScroll() { 254 236 activated = !activated; 255 if ( ! the_end && activated) {237 if (!the_end && activated) { 256 238 $(window).bind("scroll", appendEntries); 257 239 $("#' . $this->config['pager_id'] . '").hide(); … … 264 246 $(document).bind("dblclick", toggleScroll); 265 247 }); 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'); 268 271 } 269 272 } -
plugins/pageless/trunk/pagelesshandler.php
r730 r908 20 20 { 21 21 $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) { 24 24 // Default params 25 25 $params = array( 26 26 'before' => $post->pubdate, 27 27 'content_type' => $post->content_type, 28 'limit' => Options::get( 'pageless__num_item'),28 'limit' => Options::get('pageless__num_item'), 29 29 'orderby' => 'pubdate DESC' 30 30 ); 31 31 32 32 // 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') { 35 35 $params['tag_slug'] = $this->handler_vars['param']; 36 36 } else 37 if ( $this->handler_vars['type'] === 'date') {37 if ($this->handler_vars['type'] === 'date') { 38 38 $date = explode('/', $this->handler_vars['param']); 39 39 $params_count = count($date); 40 switch ( $params_count) {40 switch ($params_count) { 41 41 case 3: 42 42 $params['day'] = $date[2]; … … 49 49 } 50 50 } else 51 if ( $this->handler_vars['type'] === 'search') {51 if ($this->handler_vars['type'] === 'search') { 52 52 $params['criteria'] = $this->handler_vars['param']; 53 53 } … … 55 55 56 56 // 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'); 60 60 } 61 61 }
