Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: BBList
- Version: 1.0
- Plugin URI: http://www.vdfn.altervista.org/redirect/plugin_bblist.html
- Description: This plugin add the [bblist] tag to make the list of the entries. It needs BBCode.
- Author: Piero VDFN
- Author URI: http://www.vdfn.altervista.org/
- */
- /**
- * If a page is often visited it's better making a cache.
- */
- define('BBLIST_CACHEFILE', CACHE_DIR.'plugin_bblist_tag.txt');
- /**
- * This class is the main class of the BBList plugin.
- *
- * @see The description of the plugin.
- */
- class plugin_bblist {
- /**
- * This function is the constructor.
- */
- function plugin_bblist() {
- add_filter('bbcode_init', array(&$this, 'hook'));
- add_filter('publish_post', array(&$this, 'delete'), 10, 1);
- add_filter('delete_post', array(&$this, 'delete'), 10, 1);
- }
- /**
- * Delete cache. It's used as callback.
- *
- * @return boolean: True
- */
- function delete() {
- if(file_exists(BBLIST_CACHEFILE)) {
- @unlink(BBLIST_CACHEFILE);
- }
- return true;
- }
- /**
- * This function get the list of entries.
- *
- * @return array: The list
- */
- function getEntriesList() {
- if(file_exists(BBLIST_CACHEFILE)) {
- include BBLIST_CACHEFILE;
- return $list;
- }
- // Make the list
- $list=array();
- $query=new FPDB_Query(array('count'=>-1, 'fullparse'=>false), null);
- while($query->hasMore()) {
- list($id, $entry)=$query->getEntry();
- $date=date_from_id($id);
- $list[$date['y']][$date['m']][$date['d']][$id]=$entry['subject'];
- }
- system_save(BBLIST_CACHEFILE, array('list'=>$list));
- return $list;
- }
- /**
- * This function manages the bblist tag.
- *
- * @param string $action: The action
- * @param array $attributes: The attributes
- * @param string $content: The content of the tag
- * @params array $params: The parameters
- * @param mixed $node_object: Not known
- * @return string: The replacement
- */
- function tag($action, $attributes, $content, $params, $node_object) {
- if($action=='validate') {
- return true;
- }
- $list=(array)$this->getEntriesList();
- // Just an year or a month or a day
- if(isset($attributes['y'])) {
- $y=$attributes['y'];
- $list=(array)@$list[$y];
- if(isset($attributes['m'])) {
- $m=$attributes['m'];
- if(strlen($m)==1) {
- $m='0'.$m;
- }
- $list=(array)@$list[$m];
- if(isset($attributes['d'])) {
- $d=$attributes['d'];
- if(strlen($d)==1) {
- $d='0'.$d;
- }
- $list=(array)@$list[$d];
- }
- }
- }
- // If list is empty
- if(!empty($attributes['noentries']) && !count($list)) {
- return $attributes['noentries'];
- } elseif(!count($list)) {
- return 'There aren\'t entries.';
- }
- // Make the link?
- $link=true;
- if(isset($attributes['link'])) {
- // Force boolean
- $link=true && $attributes['link'];
- }
- // Sort the list
- $sort='asort';
- if(@$attributes['sort']=='desc') {
- $sort='arsort';
- }
- call_user_func($sort, &$list);
- // Finally make the list
- $return='';
- return $return;
- }
- /**
- * This function adds the bblist tag to the BBCode plugin.
- *
- * @param object $bbcode: The bbcode instance
- * @return object: $bbcode modified
- */
- function hook($bbcode) {
- $bbcode->addCode(
- 'bblist',
- 'callback_replace_single',
- array(&$this, 'tag'),
- array(
- 'usecontent_param'=>array('default')
- ),
- 'list',
- array('block', 'listitem'),
- array()
- );
- return $bbcode;
- }
- }
- new plugin_bblist();
Advertisement
Add Comment
Please, Sign In to add comment