[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wiki/parse/ -> macros.php (source)

   1  <?php
   2  // $Id: macros.php 20569 2006-03-15 16:41:00Z ralfbecker $
   3  
   4  // Prepare a category list.
   5  function view_macro_category($args)
   6  {
   7      global $pagestore, $MinEntries, $DayLimit, $page, $Entity;
   8      global $FlgChr;
   9  
  10      $text = '';
  11      if(strstr($args, '*'))                // Category containing all pages.
  12      {
  13          $list = $pagestore->allpages();
  14      }
  15      else if(strstr($args, '?'))           // New pages.
  16      {
  17          $list = $pagestore->newpages();
  18      }
  19      else if(strstr($args, '~'))           // Zero-length (deleted) pages.
  20      {
  21          $list = $pagestore->emptypages();
  22      }
  23      else                                  // Ordinary list of pages.
  24      {
  25          $parsed = parseText($args, array('parse_wikiname', 'parse_freelink'), '');
  26          $pagenames = array();
  27          preg_replace('/' . $FlgChr . '(\\d+)' . $FlgChr . '/e', '$pagenames[]=$Entity[\\1][1]', $parsed);
  28          $list = $pagestore->givenpages($pagenames);
  29      }
  30  
  31      if(count($list) == 0)
  32      {
  33          return '';
  34      }
  35      usort($list, 'catSort');
  36  
  37      $now = time();
  38   
  39      //for($i = 0; $i < count($list); $i++)
  40      foreach($list as $i => $lpage)
  41      {
  42          $editTime = $lpage['time'];
  43          if($DayLimit && $i >= $MinEntries && !$_GET['full'] && ($now - $editTime) > $DayLimit * 24 * 60 * 60)
  44          {
  45              break;
  46          }
  47          $text .= html_category($lpage['time'], $lpage,$lpage['author'], $lpage['username'],$lpage['comment']);
  48          $text .= html_newline();
  49      }
  50  
  51      if($i < count($list)-1)
  52      {
  53          $text .= html_fulllist(preg_match('/^[a-z]+$/i',$_GET['wikipage']) ? $_GET['wikipage']:$page, count($list));
  54      }
  55      return $text;
  56  }
  57  
  58  function catSort($p1, $p2)
  59      { return strcmp($p2['time'], $p1['time']); }
  60  
  61  function sizeSort($p1, $p2)
  62      { return $p2['length'] - $p1['length']; }
  63  
  64  function nameSort($p1, $p2)
  65  {
  66      $titlecmp = strcmp($p1['title'], $p2['title']);
  67      return $titlecmp ? $titlecmp : strcmp($p1['lang'],$p2['lang']);
  68  }
  69  
  70  // Prepare a list of pages sorted by size.
  71  function view_macro_pagesize()
  72  {
  73      global $pagestore;
  74  
  75      $first = 1;
  76      $list = $pagestore->allpages();
  77  
  78      usort($list, 'sizeSort');
  79  
  80      $text = '';
  81  
  82      foreach($list as $page)
  83      {
  84          if(!$first)                         // Don't prepend newline to first one.
  85              { $text = $text . "\n"; }
  86          else
  87              { $first = 0; }
  88  
  89          $text = $text .
  90                          $page[4] . ' ' . html_ref($page[1], $page[1]);
  91      }
  92  
  93      return html_code($text);
  94  }
  95  
  96  // Prepare a list of pages and those pages they link to.
  97  function view_macro_linktab()
  98  {
  99      global $pagestore;
 100  
 101      $text = '';
 102      foreach($pagestore->get_links() as $page => $data)
 103      {
 104          foreach($data as $lang => $links)
 105          {
 106              $text .= ($text ? "\n" : '') . html_ref(array('page' => $page,'lang' => $lang), "$page:$lang") . ' |';
 107  
 108              foreach($links as $link)
 109              {
 110                  $text .= ' ' . html_ref($link, $link);
 111              }
 112          }
 113      }
 114      return html_code($text);
 115  }
 116  
 117  // Prepare a list of pages with no incoming links.
 118  function view_macro_orphans()
 119  {
 120      global $pagestore, $LkTbl;
 121  
 122      $text = '';
 123      $first = 1;
 124  
 125      $pages = $pagestore->allpages();
 126      usort($pages, 'nameSort');
 127  
 128      foreach($pages as $page)
 129      {
 130          $esc_page = addslashes($page[1]);
 131          $q2 = $pagestore->dbh->query("SELECT page FROM $LkTbl " .
 132                                                                   "WHERE link='$esc_page' AND page!='$esc_page'",__LINE__,__FILE__);
 133          if(!($r2 = $pagestore->dbh->result($q2)) || empty($r2[0]))
 134          {
 135              if(!$first)                       // Don't prepend newline to first one.
 136                  { $text = $text . "\n"; }
 137              else
 138                  { $first = 0; }
 139  
 140              $text = $text . html_ref($page[1], $page[1]);
 141          }
 142      }
 143  
 144      return html_code($text);
 145  }
 146  
 147  // Prepare a list of pages linked to that do not exist.
 148  function view_macro_wanted()
 149  {
 150      global $pagestore, $LkTbl, $PgTbl;
 151  
 152      $text = '';
 153      $first = 1;
 154  
 155      $q1 = $pagestore->dbh->query("SELECT l.link, SUM(l.count) AS ct, p.title " .
 156                                                               "FROM $LkTbl AS l LEFT JOIN $PgTbl AS p " .
 157                                                               "ON l.link = p.title " .
 158                                                               "GROUP BY l.link " .
 159                                                               "HAVING p.title IS NULL " .
 160                                                               "ORDER BY ct DESC, l.link",__LINE__,__FILE__);
 161  
 162      while(($result = $pagestore->dbh->result($q1)))
 163      {
 164          if(!$first)                         // Don't prepend newline to first one.
 165              { $text = $text . "\n"; }
 166          else
 167              { $first = 0; }
 168  
 169          $text = $text . '(' .
 170                          html_url(findURL($result[0]), $result[1]) .
 171                          ') ' . html_ref($result[0], $result[0]);
 172      }
 173  
 174      return html_code($text);
 175  }
 176  
 177  // Prepare a list of pages sorted by how many links they contain.
 178  function view_macro_outlinks()
 179  {
 180      global $pagestore, $LkTbl;
 181  
 182      $text = '';
 183      $first = 1;
 184  
 185      $q1 = $pagestore->dbh->query("SELECT page, SUM(count) AS ct FROM $LkTbl " .
 186                                                               "GROUP BY page ORDER BY ct DESC, page",__LINE__,__FILE__);
 187      while(($result = $pagestore->dbh->result($q1)))
 188      {
 189          if(!$first)                         // Don't prepend newline to first one.
 190              { $text = $text . "\n"; }
 191          else
 192              { $first = 0; }
 193  
 194          $text = $text .
 195                          '(' . $result[1] . ') ' . html_ref($result[0], $result[0]);
 196      }
 197  
 198      return html_code($text);
 199  }
 200  
 201  // Prepare a list of pages sorted by how many links to them exist.
 202  function view_macro_refs()
 203  {
 204      global $pagestore, $LkTbl, $PgTbl;
 205  
 206      $text = '';
 207      $first = 1;
 208  
 209  // It's not quite as straightforward as one would imagine to turn the
 210  // following code into a JOIN, since we want to avoid multiplying the
 211  // number of links to a page by the number of versions of that page that
 212  // exist.  If anyone has some efficient suggestions, I'd be welcome to
 213  // entertain them.  -- ScottMoonen
 214  
 215      $q1 = $pagestore->dbh->query("SELECT link, SUM(count) AS ct FROM $LkTbl " .
 216                                                               "GROUP BY link ORDER BY ct DESC, link",__LINE__,__FILE__);
 217      while(($result = $pagestore->dbh->result($q1)))
 218      {
 219          $esc_page = addslashes($result[0]);
 220          $q2 = $pagestore->dbh->query("SELECT MAX(version) FROM $PgTbl " .
 221                                                                   "WHERE title='$esc_page'",__LINE__,__FILE__);
 222          if(($r2 = $pagestore->dbh->result($q2)) && !empty($r2[0]))
 223          {
 224              if(!$first)                       // Don't prepend newline to first one.
 225                  { $text = $text . "\n"; }
 226              else
 227                  { $first = 0; }
 228  
 229              $text = $text . '(' .
 230                              html_url(findURL($result[0]), $result[1]) . ') ' .
 231                              html_ref($result[0], $result[0]);
 232          }
 233      }
 234  
 235      return html_code($text);
 236  }
 237  
 238  // This macro inserts an HTML anchor into the text.
 239  function view_macro_anchor($args)
 240  {
 241      preg_match('/^([A-Za-z][-A-Za-z0-9_:.]*)$/', $args, $result);
 242  
 243      if($result[1] != '')
 244          { return html_anchor($result[1]); }
 245      else
 246          { return ''; }
 247  }
 248  
 249  // This macro transcludes another page into a wiki page.
 250  function view_macro_transclude($args)
 251  {
 252      global $pagestore, $ParseEngine, $ParseObject;
 253      static $visited_array = array();
 254      static $visited_count = 0;
 255  
 256      if(!validate_page($args))
 257          { return '[[Transclude ' . $args . ']]'; }
 258  
 259      $visited_array[$visited_count++] = $ParseObject;
 260      for($i = 0; $i < $visited_count; $i++)
 261      {
 262          if($visited_array[$i] == $args)
 263          {
 264              $visited_count--;
 265              return '[[Transclude ' . $args . ']]';
 266          }
 267      }
 268  
 269      $pg = $pagestore->page($args);
 270      $pg->read();
 271      if(!$pg->exists)
 272      {
 273          $visited_count--;
 274          return '[[Transclude ' . $args . ']]';
 275      }
 276  
 277      $result = parseText($pg->text, $ParseEngine, $args);
 278      $visited_count--;
 279      return $result;
 280  }
 281  
 282  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7