PukiWiki PHP Cross Reference Collaborative Wikis

Source: /plugin/new.inc.php - 92 lines - 2683 bytes - Summary - Text - Print

   1  <?php
   2  // PukiWiki - Yet another WikiWikiWeb clone.
   3  // $Id: new.inc.php,v 1.9 2005/06/16 15:04:08 henoheno Exp $
   4  //
   5  // New! plugin
   6  //
   7  // Usage:
   8  //    &new([nodate]){date};     // Check the date string
   9  //    &new(pagename[,nolink]);  // Check the pages's timestamp
  10  //    &new(pagename/[,nolink]);
  11  //        // Check multiple pages started with 'pagename/',
  12  //        // and show the latest one
  13  
  14  define('PLUGIN_NEW_DATE_FORMAT', '<span class="comment_date">%s</span>');
  15  
  16  function plugin_new_init()
  17  {
  18      // Elapsed time => New! message with CSS
  19      $messages['_plugin_new_elapses'] = array(
  20          60 * 60 * 24 * 1 => ' <span class="new1" title="%s">New!</span>',  // 1day
  21          60 * 60 * 24 * 5 => ' <span class="new5" title="%s">New</span>');  // 5days
  22      set_plugin_messages($messages);
  23  }
  24  
  25  function plugin_new_inline()
  26  {
  27      global $vars, $_plugin_new_elapses;
  28  
  29      $retval = '';
  30      $args = func_get_args();
  31      $date = strip_autolink(array_pop($args)); // {date} always exists
  32  
  33      if($date !== '') {
  34          // Show 'New!' message by the time of the $date string
  35          if (func_num_args() > 2) return '&new([nodate]){date};';
  36  
  37          $timestamp = strtotime($date);
  38          if ($timestamp === -1) return '&new([nodate]){date}: Invalid date string;';
  39          $timestamp -= ZONETIME;
  40  
  41          $retval = in_array('nodate', $args) ? '' : htmlspecialchars($date);
  42      } else {
  43          // Show 'New!' message by the timestamp of the page
  44          if (func_num_args() > 3) return '&new(pagename[,nolink]);';
  45  
  46          $name = strip_bracket(! empty($args) ? array_shift($args) : $vars['page']);
  47          $page = get_fullname($name, $vars['page']);
  48          $nolink = in_array('nolink', $args);
  49  
  50          if (substr($page, -1) == '/') {
  51              // Check multiple pages started with "$page"
  52              $timestamp = 0;
  53              $regex = '/^' . preg_quote($page, '/') . '/';
  54              foreach (preg_grep($regex, get_existpages()) as $page) {
  55                  // Get the latest pagename and its timestamp
  56                  $_timestamp = get_filetime($page);
  57                  if ($timestamp < $_timestamp) {
  58                      $timestamp = $_timestamp;
  59                      $retval    = $nolink ? '' : make_pagelink($page);
  60                  }
  61              }
  62              if ($timestamp == 0)
  63                  return '&new(pagename/[,nolink]): No such pages;';
  64          } else {
  65              // Check a page
  66              if (is_page($page)) {
  67                  $timestamp = get_filetime($page);
  68                  $retval    = $nolink ? '' : make_pagelink($page, $name);
  69              } else {
  70                  return '&new(pagename[,nolink]): No such page;';
  71              }
  72          }
  73      }
  74  
  75      // Add 'New!' string by the elapsed time
  76      $erapse = UTIME - $timestamp;
  77      foreach ($_plugin_new_elapses as $limit=>$tag) {
  78          if ($erapse <= $limit) {
  79              $retval .= sprintf($tag, get_passage($timestamp));
  80              break;
  81          }
  82      }
  83  
  84      if($date !== '') {
  85          // Show a date string
  86          return sprintf(PLUGIN_NEW_DATE_FORMAT, $retval);
  87      } else {
  88          // Show a page name
  89          return $retval;
  90      }
  91  }
  92  ?>

title

Description

title

Description

title

Description

title

title

Body