[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/include/ -> functions_permalinks.inc.php (source)

   1  <?php # $Id: functions.inc.php 85 2005-05-10 10:11:05Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  if (IN_serendipity !== true) {
   6      die ("Don't hack!");
   7  }
   8  
   9  if (defined('S9Y_FRAMEWORK_PERMALINKS')) {
  10      return;
  11  }
  12  @define('S9Y_FRAMEWORK_PERMALINKS', true);
  13  
  14  /**
  15   * Converts a string into a filename that can be used safely in HTTP URLs
  16   *
  17   * @access public
  18   * @param   string  input string
  19   * @param   boolean Shall dots in the filename be removed? (Required for certain regex rules)
  20   * @return  string  output string
  21   */
  22  function serendipity_makeFilename($str, $stripDots = false) {
  23      static $from = array(
  24                       ' ',
  25  
  26                       'Ä',
  27                       'ä',
  28  
  29                       'Ö',
  30                       'ö',
  31  
  32                       'Ü',
  33                       'ü',
  34  
  35                       'ß',
  36  
  37                       'é',
  38                       'è',
  39                       'ê',
  40  
  41                       'í',
  42                       'ì',
  43                       'î',
  44  
  45                       'á',
  46                       'à',
  47                       'â',
  48                       'å',
  49  
  50                       'ó',
  51                       'ò',
  52                       'ô',
  53                       'õ',
  54  
  55                       'ú',
  56                       'ù',
  57                       'û',
  58  
  59                       'ç',
  60                       'Ç',
  61  
  62                       'ñ',
  63  
  64                       'ý');
  65  
  66      static $to   = array(
  67                       '-',
  68  
  69                       'AE',
  70                       'ae',
  71  
  72                       'OE',
  73                       'oe',
  74  
  75                       'UE',
  76                       'ue',
  77  
  78                       'ss',
  79  
  80                       'e',
  81                       'e',
  82                       'e',
  83  
  84                       'i',
  85                       'i',
  86                       'i',
  87  
  88                       'a',
  89                       'a',
  90                       'a',
  91                       'a',
  92  
  93                       'o',
  94                       'o',
  95                       'o',
  96                       'o',
  97  
  98                       'u',
  99                       'u',
 100                       'u',
 101  
 102                       'c',
 103                       'C',
 104  
 105                       'n',
 106  
 107                       'y');
 108  
 109      if (isset($GLOBALS['i18n_filename_from'])) {
 110          // Replace international chars not detected by every locale.
 111          // The array of chars is defined in the language file.
 112          $str = str_replace($GLOBALS['i18n_filename_from'], $GLOBALS['i18n_filename_to'], $str);
 113  
 114          if (LANG_CHARSET == 'UTF-8') {
 115              // URLs need to be 7bit - since this function takes care of the most common ISO-8859-1
 116              // characters, try to UTF8-decode the string first.
 117              $str = utf8_decode($str);
 118          }
 119      } else {
 120          // Replace international chars not detected by every locale
 121          if (LANG_CHARSET == 'UTF-8') {
 122              // URLs need to be 7bit - since this function takes care of the most common ISO-8859-1
 123              // characters, try to UTF8-decode the string first.
 124              $str = utf8_decode($str);
 125          }
 126  
 127          $str = str_replace($from, $to, $str);
 128      }
 129  
 130      // Nuke chars not allowed in our URI
 131      $str = preg_replace('#[^' . PAT_FILENAME . ']#i', '', $str);
 132  
 133      // Check if dots are allowed
 134      if ($stripDots) {
 135          $str = str_replace('.', '', $str);
 136      }
 137  
 138      // Remove consecutive separators
 139      $str = preg_replace('#'. $to[0] .'{2,}#s', $to[0], $str);
 140  
 141      // Remove excess separators
 142      $str = trim($str, $to[0]);
 143  
 144      if (empty($str)) {
 145          if (isset($GLOBALS['i18n_unknown'])) {
 146              $str = $GLOBALS['i18n_unknown'];
 147          } else {
 148              $str = 'unknown';
 149          }
 150      }
 151  
 152      return $str;
 153  }
 154  
 155  /**
 156   * Initialize permalinks, if the user did not specify those yet
 157   *
 158   * @access public
 159   * @return null
 160   */
 161  function serendipity_initPermalinks() {
 162      global $serendipity;
 163  
 164      if (!isset($serendipity['permalinkStructure'])) {
 165          $serendipity['permalinkStructure'] = 'archives/%id%-%title%.html';
 166      }
 167  
 168      if (!isset($serendipity['permalinkFeedAuthorStructure'])) {
 169          $serendipity['permalinkFeedAuthorStructure'] = 'feeds/authors/%id%-%realname%.rss';
 170      }
 171  
 172      if (!isset($serendipity['permalinkFeedCategoryStructure'])) {
 173          $serendipity['permalinkFeedCategoryStructure'] = 'feeds/categories/%id%-%name%.rss';
 174      }
 175  
 176      if (!isset($serendipity['permalinkCategoryStructure'])) {
 177          $serendipity['permalinkCategoryStructure'] = 'categories/%id%-%name%';
 178      }
 179  
 180      if (!isset($serendipity['permalinkAuthorStructure'])) {
 181          $serendipity['permalinkAuthorStructure'] = 'authors/%id%-%realname%';
 182      }
 183  
 184      if (!isset($serendipity['permalinkArchivesPath'])) {
 185          $serendipity['permalinkArchivesPath'] = 'archives';
 186      }
 187  
 188      if (!isset($serendipity['permalinkArchivePath'])) {
 189          $serendipity['permalinkArchivePath'] = 'archive';
 190      }
 191  
 192      if (!isset($serendipity['permalinkCategoriesPath'])) {
 193          $serendipity['permalinkCategoriesPath'] = 'categories';
 194      }
 195  
 196      if (!isset($serendipity['permalinkAuthorsPath'])) {
 197          $serendipity['permalinkAuthorsPath'] = 'authors';
 198      }
 199  
 200      if (!isset($serendipity['permalinkUnsubscribePath'])) {
 201          $serendipity['permalinkUnsubscribePath'] = 'unsubscribe';
 202      }
 203  
 204      if (!isset($serendipity['permalinkDeletePath'])) {
 205          $serendipity['permalinkDeletePath'] = 'delete';
 206      }
 207  
 208      if (!isset($serendipity['permalinkApprovePath'])) {
 209          $serendipity['permalinkApprovePath'] = 'approve';
 210      }
 211  
 212      if (!isset($serendipity['permalinkFeedsPath'])) {
 213          $serendipity['permalinkFeedsPath'] = 'feeds';
 214      }
 215  
 216      if (!isset($serendipity['permalinkPluginPath'])) {
 217          $serendipity['permalinkPluginPath'] = 'plugin';
 218      }
 219  
 220      if (!isset($serendipity['permalinkAdminPath'])) {
 221          $serendipity['permalinkAdminPath'] = 'admin';
 222      }
 223  
 224      if (!isset($serendipity['permalinkSearchPath'])) {
 225          $serendipity['permalinkSearchPath'] = 'search';
 226      }
 227  
 228      if (!isset($serendipity['permalinkCommentsPath'])) {
 229          $serendipity['permalinkCommentsPath'] = 'comments';
 230      }
 231  
 232      /* URI paths
 233       * These could be defined in the language headers, except that would break
 234       * backwards URL compatibility
 235       */
 236      @define('PATH_ARCHIVES',    $serendipity['permalinkArchivesPath']);
 237      @define('PATH_ARCHIVE',     $serendipity['permalinkArchivePath']);
 238      @define('PATH_CATEGORIES',  $serendipity['permalinkCategoriesPath']);
 239      @define('PATH_UNSUBSCRIBE', $serendipity['permalinkUnsubscribePath']);
 240      @define('PATH_DELETE',      $serendipity['permalinkDeletePath']);
 241      @define('PATH_APPROVE',     $serendipity['permalinkApprovePath']);
 242      @define('PATH_FEEDS',       $serendipity['permalinkFeedsPath']);
 243      @define('PATH_PLUGIN',      $serendipity['permalinkPluginPath']);
 244      @define('PATH_ADMIN',       $serendipity['permalinkAdminPath']);
 245      @define('PATH_SEARCH',      $serendipity['permalinkSearchPath']);
 246      @define('PATH_COMMENTS',    $serendipity['permalinkCommentsPath']);
 247  
 248      /* URI patterns
 249       * Note that it's important to use @ as the pattern delimiter. DO NOT use shortcuts
 250       * like \d or \s, since mod_rewrite will use the regexps as well and chokes on them.
 251       * If you add new patterns, remember to add the new rules to the *.tpl files and
 252       * function serendipity_installFiles().
 253       */
 254      @define('PAT_FILENAME',       '0-9a-z\.\_!;,\+\-\%');
 255      @define('PAT_FILENAME_MATCH', '[' . PAT_FILENAME . ']+');
 256      @define('PAT_CSS',            '@/(serendipity\.css|serendipity_admin\.css)@');
 257      @define('PAT_FEED',           '@/(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml)@');
 258      @define('PAT_COMMENTSUB',     '@/([0-9]+)[_\-][' . PAT_FILENAME . ']*\.html@i');
 259  
 260      return true;
 261  }
 262  
 263  /**
 264   * Build an array containing all regular expression permalinks
 265   *
 266   * @access public
 267   * @param   boolean     If set to true, the list of permalinks will be returned. If false, all permalinks will be applied as Constants
 268   * @return  array       (conditional on $return) List of permalinks
 269   */
 270  function &serendipity_permalinkPatterns($return = false) {
 271      global $serendipity;
 272  
 273      $PAT = array();
 274  
 275      $PAT['UNSUBSCRIBE']              = '@/'  . $serendipity['permalinkUnsubscribePath'].'/(.*)/([0-9]+)@';
 276      $PAT['APPROVE']                  = '@/'  . $serendipity['permalinkApprovePath'].'/(.*)/(.*)/([0-9]+)@';
 277      $PAT['DELETE']                   = '@/'  . $serendipity['permalinkDeletePath'].'/(.*)/(.*)/([0-9]+)@';
 278      $PAT['ARCHIVES']                 = '@/'  . $serendipity['permalinkArchivesPath'].'([/A-Za-z0-9]+)\.html@';
 279      $PAT['FEEDS']                    = '@/'  . $serendipity['permalinkFeedsPath'].'/@';
 280      $PAT['ADMIN']                    = '@/(' . $serendipity['permalinkAdminPath'] . '|entries)(/.+)?@';
 281      $PAT['ARCHIVE']                  = '@/'  . $serendipity['permalinkArchivePath'] . '/?@';
 282      $PAT['CATEGORIES']               = '@/'  . $serendipity['permalinkCategoriesPath'].'/([0-9;]+)@';
 283      $PAT['PLUGIN']                   = '@/(' . $serendipity['permalinkPluginPath'] . '|plugin)/(.*)@';
 284      $PAT['SEARCH']                   = '@/'  . $serendipity['permalinkSearchPath'] . '/(.*)@';
 285      $PAT['COMMENTS']                 = '@/'  . $serendipity['permalinkCommentsPath'] . '/(.*)@';
 286      $PAT['PERMALINK']                = '@('  . serendipity_makePermalinkRegex($serendipity['permalinkStructure'], 'entry') . ')/?@i';
 287      $PAT['PERMALINK_CATEGORIES']     = '@'   . serendipity_makePermalinkRegex($serendipity['permalinkCategoryStructure'], 'category') . '@i';
 288      $PAT['PERMALINK_FEEDCATEGORIES'] = '@'   . serendipity_makePermalinkRegex($serendipity['permalinkFeedCategoryStructure'], 'category') . '@i';
 289      $PAT['PERMALINK_FEEDAUTHORS']    = '@'   . serendipity_makePermalinkRegex($serendipity['permalinkFeedAuthorStructure'], 'author') . '@i';
 290      $PAT['PERMALINK_AUTHORS']        = '@'   . serendipity_makePermalinkRegex($serendipity['permalinkAuthorStructure'], 'author') . '@i';
 291  
 292      if ($return) {
 293          return $PAT;
 294      } else {
 295          foreach($PAT AS $constant => $value) {
 296              define('PAT_' . $constant, $value);
 297          }
 298  
 299          $return = true;
 300          return $return;
 301      }
 302  }
 303  
 304  /**
 305   * Search the reference to a specific permalink
 306   *
 307   * This query will show the Entry/Category/Author-ID to a permalink, if that permalink
 308   * does not contain %id%.
 309   *
 310   * @access public
 311   * @param   string      The permalink configuration string
 312   * @param   string      The URL to check
 313   * @param   string      A default return value if no permalink is found
 314   * @param   string      The type of a permalink (entry|category|author)
 315   * @return  string      The ID of the permalink type
 316   */
 317  function serendipity_searchPermalink($struct, $url, $default, $type = 'entry') {
 318      global $serendipity;
 319  
 320      if (stristr($struct, '%id%') === FALSE) {
 321          $url = preg_replace('@^(' . preg_quote($serendipity['serendipityHTTPPath'], '@') . '(' . preg_quote($serendipity['indexFile'], '@') . ')?\??(url=)?/?)([^&?]+).*@', '\4', $url);
 322          // If no entryid is submitted, we rely on a new DB call to fetch the permalink.
 323          $pq = "SELECT entry_id, data
 324                   FROM {$serendipity['dbPrefix']}permalinks
 325                  WHERE (permalink = '" . serendipity_db_escape_string($url) . "'
 326                     OR permalink = '" . serendipity_db_escape_string($default) . "')
 327                    AND type      = '" . serendipity_db_escape_string($type) . "'
 328                    AND entry_id  > 0
 329                  LIMIT 1";
 330  // echo $pq; // DEBUG
 331  // die($pq); // DEBUG
 332          $permalink = serendipity_db_query($pq, true, 'both', false, false, false, true);
 333  
 334          if (is_array($permalink)) {
 335              return $permalink['entry_id'];
 336          }
 337      }
 338  
 339      return $default;
 340  }
 341  
 342  /**
 343   * Create a permalink for the given input data
 344   *
 345   * You can pass an entry array, or an author array to this function
 346   * and then get a permalink valid for that array
 347   *
 348   * @access public
 349   * @param   array       The input data used for building the permalink
 350   * @param   string      The type of the permalink (entry|category|author)
 351   * @return  string      The permalink
 352   */
 353  function serendipity_getPermalink(&$data, $type = 'entry') {
 354      switch($type) {
 355          case 'entry':
 356              return serendipity_archiveURL(
 357                          $data['id'],
 358                          $data['title'],
 359                          '',
 360                          false,
 361                          array('timestamp' => $data['timestamp'])
 362              );
 363              break;
 364  
 365          case 'category':
 366              return serendipity_categoryURL($data, '', false);
 367              break;
 368  
 369          case 'author':
 370              return serendipity_authorURL($data, '', false);
 371              break;
 372      }
 373  
 374      return false;
 375  }
 376  
 377  /**
 378   * Update a permalink with new data
 379   *
 380   * @access public
 381   * @param   array       The input data used for building the permalink
 382   * @param   string      The type of the permalink (entry|category|author)
 383   * @return  string      The database result
 384   */
 385  function serendipity_updatePermalink(&$data, $type = 'entry') {
 386      global $serendipity;
 387  
 388      $link = serendipity_getPermalink($data, $type);
 389      return(serendipity_db_query(sprintf("UPDATE {$serendipity['dbPrefix']}permalinks
 390                                              SET permalink = '%s'
 391                                            WHERE entry_id  = %s
 392                                              AND type      = '%s'",
 393  
 394                                              serendipity_db_escape_string($link),
 395                                              (int)$data['id'],
 396                                              serendipity_db_escape_string($type))));
 397  }
 398  
 399  /**
 400   * Insert a new Permalink into the database for latter retrieval
 401   *
 402   * This function is basically only used if you have no '%id%' value in your permalink config.
 403   *
 404   * @access public
 405   * @param   array       The input data used for building the permalink
 406   * @param   string      The type of the permalink (entry|category|author)
 407   * @return  string      The permalink
 408   */
 409  function serendipity_insertPermalink(&$data, $type = 'entry') {
 410      global $serendipity;
 411  
 412      $link = serendipity_getPermalink($data, $type);
 413  
 414      switch($type) {
 415          case 'entry':
 416              $idfield = 'id';
 417              break;
 418  
 419          case 'author':
 420              $idfield = 'authorid';
 421              break;
 422  
 423          case 'category':
 424              $idfield = 'categoryid';
 425              break;
 426      }
 427  
 428      return(serendipity_db_query(sprintf("INSERT INTO {$serendipity['dbPrefix']}permalinks
 429                                                      (permalink, entry_id, type)
 430                                               VALUES ('%s', '%s', '%s')",
 431  
 432                                              serendipity_db_escape_string($link),
 433                                              (int)$data[$idfield],
 434                                              serendipity_db_escape_string($type))));
 435  }
 436  
 437  /**
 438   * Build all permalinks for all current entries, authors and categories
 439   *
 440   * @access public
 441   * @return null
 442   */
 443  function serendipity_buildPermalinks() {
 444      global $serendipity;
 445  
 446      $entries = serendipity_db_query("SELECT id, title, timestamp FROM {$serendipity['dbPrefix']}entries");
 447  
 448      if (is_array($entries)) {
 449          serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}permalinks WHERE type = 'entry'");
 450  
 451          foreach($entries AS $entry) {
 452              serendipity_insertPermalink($entry, 'entry');
 453          }
 454      }
 455  
 456      $authors = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}authors");
 457  
 458      if (is_array($authors)) {
 459          serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}permalinks WHERE type = 'author'");
 460  
 461          foreach($authors AS $author) {
 462              serendipity_insertPermalink($author, 'author');
 463          }
 464      }
 465  
 466      $categories = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}category");
 467  
 468      if (is_array($categories)) {
 469          serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}permalinks WHERE type = 'category'");
 470  
 471          foreach($categories AS $category) {
 472              serendipity_insertPermalink($category, 'category');
 473          }
 474      }
 475  }
 476  
 477  /**
 478   * Uses logic to figure out how the URI should look, based on current rewrite rule
 479   *
 480   * @access public
 481   * @param   string      The URL part that you want to format to "pretty urls"
 482   * @param   string      The path/URL you want as a prefix for your pretty URL
 483   * @param   boolean     If set to TRUE this will bypass all pretty URLs and format the link so that it works everywhere
 484   * @return  string      The rewritten URL
 485   */
 486  function serendipity_rewriteURL($path, $key='baseURL', $forceNone = false) {
 487      global $serendipity;
 488      return $serendipity[$key] . ($serendipity['rewrite'] == 'none' || ($serendipity['rewrite'] != 'none' && $forceNone) ? $serendipity['indexFile'] . '?/' : '') . $path;
 489  }
 490  
 491  /**
 492   * Format a permalink according to the configured format
 493   *
 494   * @access public
 495   * @param   string      The URL format to use
 496   * @param   array       The input data to format a permalink
 497   * @param   string      The type of the permalink (entry|category|author)
 498   * @return  string      The formatted permalink
 499   */
 500  function serendipity_makePermalink($format, $data, $type = 'entry') {
 501      global $serendipity;
 502      static $entryKeys    = array('%id%', '%lowertitle%', '%title%', '%day%', '%month%', '%year%');
 503      static $authorKeys   = array('%id%', '%username%', '%realname%', '%email%');
 504      static $categoryKeys = array('%id%', '%name%', '%description%');
 505  
 506      switch($type) {
 507          case 'entry':
 508              if (!isset($data['entry']['timestamp']) && preg_match('@(%day%|%month%|%year%)@', $format)) {
 509                  // We need the timestamp to build the URI, but no timestamp has been submitted. Thus we need to fetch the data.
 510                  $ts = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries WHERE id = " . (int)$data['id'], true);
 511                  if (is_array($ts)) {
 512                      $data['entry']['timestamp'] = $ts['timestamp'];
 513                  } else {
 514                      $data['entry']['timestamp'] = time();
 515                  }
 516              }
 517  
 518              $ts = serendipity_serverOffsetHour($data['entry']['timestamp']);
 519  
 520              $ftitle  = serendipity_makeFilename($data['title']);
 521              $fltitle = strtolower($ftitle);
 522  
 523              $replacements =
 524                  array(
 525                      (int)$data['id'],
 526                      $fltitle,
 527                      $ftitle,
 528                      date('d', $ts),
 529                      date('m', $ts),
 530                      date('Y', $ts)
 531                  );
 532              return str_replace($entryKeys, $replacements, $format);
 533              break;
 534  
 535          case 'author':
 536              $replacements =
 537                  array(
 538                      (int)$data['authorid'],
 539                      serendipity_makeFilename($data['username'], true),
 540                      serendipity_makeFilename($data['realname'], true),
 541                      serendipity_makeFilename($data['email'], true)
 542                  );
 543              return str_replace($authorKeys, $replacements, $format);
 544              break;
 545  
 546          case 'category':
 547              $replacements =
 548                  array(
 549                      (int)$data['categoryid'],
 550                      serendipity_makeFilename($data['category_name'], true),
 551                      serendipity_makeFilename($data['category_description'], true)
 552                  );
 553              return str_replace($categoryKeys, $replacements, $format);
 554              break;
 555      }
 556  
 557      return false;
 558  }
 559  
 560  /**
 561   * Convert a permalink configuration into a regular expression for use in rewrite rules
 562   *
 563   * @access public
 564   * @param   string      The URL format to use
 565   * @param   string      The type of the permalink (entry|category|author)
 566   * @return  string      The regular expression to a permalink URL
 567   */
 568  function serendipity_makePermalinkRegex($format, $type = 'entry') {
 569      static $entryKeys           = array('%id%',     '%lowertitle%',     '%title%',          '%day%',      '%month%',    '%year%');
 570      static $entryRegexValues    = array('([0-9]+)', PAT_FILENAME_MATCH, PAT_FILENAME_MATCH, '[0-9]{1,2}', '[0-9]{1,2}', '[0-9]{4}');
 571  
 572      static $authorKeys          = array('%id%',     '%username%',           '%realname%',           '%email%');
 573      static $authorRegexValues   = array('([0-9]+)', PAT_FILENAME_MATCH, PAT_FILENAME_MATCH, PAT_FILENAME_MATCH);
 574  
 575      static $categoryKeys        = array('%id%',     '%name%',               '%description%');
 576      static $categoryRegexValues = array('([0-9;]+)', PAT_FILENAME_MATCH, PAT_FILENAME_MATCH);
 577  
 578      switch($type) {
 579          case 'entry':
 580              return str_replace($entryKeys, $entryRegexValues, preg_quote($format));
 581              break;
 582  
 583          case 'author':
 584              return str_replace($authorKeys, $authorRegexValues, preg_quote($format));
 585              break;
 586  
 587          case 'category':
 588              return str_replace($categoryKeys, $categoryRegexValues, preg_quote($format));
 589              break;
 590      }
 591  }
 592  
 593  /**
 594   * Create a permalink for an entry permalink
 595   *
 596   * @access public
 597   * @param   int     The entry ID
 598   * @param   string  The entry title
 599   * @param   string  The base URL/path key
 600   * @param   boolean Shall the link be rewritten to a pretty URL?
 601   * @param   array   Additional entry data
 602   * @return  string  The permalink
 603   */
 604  function serendipity_archiveURL($id, $title, $key = 'baseURL', $checkrewrite = true, $entryData = null) {
 605      global $serendipity;
 606      $path = serendipity_makePermalink($serendipity['permalinkStructure'], array('id'=> $id, 'title' => $title, 'entry' => $entryData));
 607      if ($checkrewrite) {
 608          $path = serendipity_rewriteURL($path, $key);
 609      }
 610      return $path;
 611  }
 612  
 613  /**
 614   * Create a permalink for an authors permalink
 615   *
 616   * @access public
 617   * @param   array   The author data
 618   * @param   string  The base URL/path key
 619   * @param   boolean Shall the link be rewritten to a pretty URL?
 620   * @return  string  The permalink
 621   */
 622  function serendipity_authorURL(&$data, $key = 'baseURL', $checkrewrite = true) {
 623      global $serendipity;
 624      $path = serendipity_makePermalink($serendipity['permalinkAuthorStructure'], $data, 'author');
 625      if ($checkrewrite) {
 626          $path = serendipity_rewriteURL($path, $key);
 627      }
 628      return $path;
 629  }
 630  
 631  /**
 632   * Create a permalink for an category permalink
 633   *
 634   * @access public
 635   * @param   array   The category data
 636   * @param   string  The base URL/path key
 637   * @param   boolean Shall the link be rewritten to a pretty URL?
 638   * @return  string  The permalink
 639   */
 640  function serendipity_categoryURL(&$data, $key = 'baseURL', $checkrewrite = true) {
 641      global $serendipity;
 642      $path = serendipity_makePermalink($serendipity['permalinkCategoryStructure'], $data, 'category');
 643      if ($checkrewrite) {
 644          $path = serendipity_rewriteURL($path, $key);
 645      }
 646      return $path;
 647  }
 648  
 649  /**
 650   * Create a permalink for an RSS feed permalink
 651   *
 652   * @access public
 653   * @param   array   The entry data
 654   * @param   string  The base URL/path key
 655   * @param   boolean Shall the link be rewritten to a pretty URL?
 656   * @return  string  The permalink
 657   */
 658  function serendipity_feedCategoryURL(&$data, $key = 'baseURL', $checkrewrite = true) {
 659      global $serendipity;
 660      $path = serendipity_makePermalink($serendipity['permalinkFeedCategoryStructure'], $data, 'category');
 661      if ($checkrewrite) {
 662          $path = serendipity_rewriteURL($path, $key);
 663      }
 664      return $path;
 665  }
 666  
 667  /**
 668   * Create a permalink for an RSS authors' feed permalink
 669   *
 670   * @access public
 671   * @param   array   The entry data
 672   * @param   string  The base URL/path key
 673   * @param   boolean Shall the link be rewritten to a pretty URL?
 674   * @return  string  The permalink
 675   */
 676  function serendipity_feedAuthorURL(&$data, $key = 'baseURL', $checkrewrite = true) {
 677      global $serendipity;
 678      $path = serendipity_makePermalink($serendipity['permalinkFeedAuthorStructure'], $data, 'author');
 679      if ($checkrewrite) {
 680          $path = serendipity_rewriteURL($path, $key);
 681      }
 682      return $path;
 683  }
 684  
 685  /**
 686   * Create a permalink for an archive date
 687   *
 688   * @access public
 689   * @param   string  The archive's date
 690   * @param   boolean If true, only summary archive
 691   * @param   string  The base URL/path key
 692   * @return  string  The permalink
 693   */
 694  function serendipity_archiveDateUrl($range, $summary=false, $key='baseURL') {
 695      return serendipity_rewriteURL(PATH_ARCHIVES . '/' . $range . ($summary ? '/summary' : '') . '.html', $key);
 696  }
 697  
 698  /**
 699   * Returns the URL to the current page that is being viewed
 700   *
 701   * @access public
 702   * @return string   the current URL
 703   */
 704  function serendipity_currentURL($strict = false) {
 705      global $serendipity;
 706  
 707      // All that URL getting humpty-dumpty is necessary to allow a user to change the template in the
 708      // articles view. POSTing data to that page only works with mod_rewrite and not the ErrorDocument
 709      // redirection, so we need to generate the ErrorDocument-URI here.
 710  
 711      $uri = parse_url($_SERVER['REQUEST_URI']);
 712      $qst = '';
 713      if (!empty($uri['query'])) {
 714          $qst = '&amp;' . str_replace('&', '&amp;', $uri['query']);
 715      }
 716      $uri['path'] = preg_replace('@^' . preg_quote($serendipity['serendipityHTTPPath']) . '@i', ($strict ? '/' : ''), $uri['path']);
 717      $uri['path'] = preg_replace('@^(&amp;)?' . preg_quote($serendipity['indexFile']) . '(&amp;)@i', '', $uri['path']);
 718      $url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?' . $uri['path'] . $qst;
 719      $url = str_replace(
 720          array(
 721              $serendipity['indexFile'] . '&amp;',
 722              '"',
 723              "'",
 724              '<',
 725              '>',
 726              '`'
 727          ),
 728  
 729          array(
 730              '',
 731              '',
 732              '',
 733              '',
 734              ''
 735          ),
 736  
 737          $url); // Kill possible looped repitions and bad characters which could occur
 738  
 739      if ($strict) {
 740          $url = preg_replace('@(//+)@', '/', $url);
 741      }
 742  
 743      return $url;
 744  }
 745  
 746  /**
 747   * Get the URI Arguments for the current HTTP Request
 748   *
 749   * @access public
 750   * @param   string      The URI made for this request
 751   * @param   boolean     If enabled, then no Dots are allowed in the URL for permalinks
 752   * @return
 753   */
 754  function serendipity_getUriArguments($uri, $wildcard = false) {
 755  global $serendipity;
 756  static $indexFile = null;
 757  
 758      if ($indexFile === null) {
 759          $_indexFile = explode('.', $serendipity['indexFile']);
 760          $indexFile = $_indexFile[0];
 761      }
 762  
 763      /* Explode the path into sections, to later be able to check for arguments and add our own */
 764      preg_match('/^'. preg_quote($serendipity['serendipityHTTPPath'], '/') . '(' . preg_quote($serendipity['indexFile'], '/') . '\?\/)?(' . ($wildcard ? '.+' : '[;,_a-z0-9\-*\/%\+]+') . ')/i', $uri, $_res);
 765      if (strlen($_res[2]) != 0) {
 766          $args = explode('/', $_res[2]);
 767          if ($args[0] == $indexFile || $args[0] == $serendipity['indexFile']) {
 768              unset($args[0]);
 769          }
 770          return $args;
 771      } else {
 772          return array();
 773      }
 774  }
 775  


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics