[ PHPXref.com ] [ Generated: Sun Jul 20 16:32:46 2008 ] [ AWF-CMS 2.1.3 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/inc/classes/containers/ -> AWF_Wiki.class (source)

   1  <?php
   2  /*
   3          Copyright (C) 2000-2005 Michael Mayer <michael@awf-cms.org>
   4  
   5          This file is part of the Adaptive Website Framework (AWF) Version 2
   6  
   7      License     : GNU General Public License
   8          Last update : 12.01.2006
   9  
  10      Looking for documentation? Want to maintain one of the classes?
  11      Visit www.awf-cms.org!
  12  */
  13  
  14  class AWF_Wiki extends AWF_ContentContainer {
  15      public $default_resolver    = DEFAULT_SHORTCUT_RESOLVER;
  16      public $output_format         = 'html'; // html and text so far
  17      public $resolvers         = NULL;
  18      public $resolver_start_tag    = "\[\[";
  19      public $resolver_end_tag    = "\]\]";
  20      public $use_pear_renderer    = WIKI_USE_PEAR_RENDERER;
  21      public $numbered_headings    = FALSE;
  22      public $reset_heading_counter    = FALSE;
  23      public $pear            = NULL;
  24      public $current_wiki        = NULL;
  25      public $current_page        = '';
  26  
  27  	function __construct () {
  28          $this->cms_namespace       = 'wiki';
  29          $this->shortcut_namespace = 'wiki';
  30          $this->id                 = 0;
  31          $this->permissions      = new AWF_ContentPermissions ($this);
  32          
  33          $this->request_extensions = array(
  34              'html'     => 'text/html',
  35              'xml'    => 'text/xml', 
  36              'pdf'    => 'application/pdf', 
  37              'no_extension'=> 'text/html');
  38              
  39          if(AWF_Functions::file_exists_incpath('Text/Wiki.php') && $this->use_pear_renderer) {
  40              require_once 'Text/Wiki.php';
  41  
  42              $this->pear = new Text_Wiki ();
  43              
  44              if(defined('ENABLE_WIKIWORDS') && ENABLE_WIKIWORDS == FALSE) {
  45                  $this->pear->disableRule('wikilink');
  46                  }
  47              else {
  48                  $this->pear->setRenderConf('Xhtml', 'wikilink', 'pages', NULL);
  49                  $this->pear->setRenderConf('Xhtml', 'wikilink', 'view_url', DEFAULT_WIKI.'/%s.html');
  50                  }
  51                  
  52              $this->pear->disableRule('freelink');
  53              $this->pear->disableRule('interwiki');
  54              $this->pear->setRenderConf('Xhtml', 'url', 'images', FALSE);
  55              $this->pear->setRenderConf('Xhtml', 'url', 'css_descr', 'http');
  56              $this->pear->setRenderConf('Xhtml', 'url', 'target', '_self');
  57              $this->pear->setRenderConf('Xhtml', 'table', 'css_table', 'WikiTable');
  58              $this->pear->setRenderConf('Xhtml', 'table', 'css_td', 'WikiTD');            
  59              $this->pear->setRenderConf('Xhtml', 'table', 'css_th', 'WikiTH');
  60              $this->pear->setRenderConf('Xhtml', 'table', 'css_tr', 'WikiTR');
  61              }
  62          else {
  63              $this->use_pear_renderer = FALSE;
  64              }
  65          }
  66  
  67  	function get_requested_content() {
  68          global $smarty;
  69          
  70          $preview = '';
  71  
  72          if($this->my_cms->request['extension'] == 'html') {
  73              
  74              if(isset($_REQUEST['delete']) &&$this->current_wiki->current_page->id != NULL && $this->current_wiki->current_page->permissions->is_writable()) {
  75                  $this->current_wiki->current_page->delete();
  76                  $this->current_wiki->current_page->body = '';
  77                  }
  78              
  79              if(isset($_REQUEST['save']) && isset($_REQUEST['wikibody']) && $this->current_wiki->permissions->is_writable()) {
  80                  $this->current_wiki->current_page->body = $_REQUEST['wikibody'];
  81  
  82                  // Is there a comment?
  83                  if(isset($_REQUEST['comment']) && is_string($_REQUEST['comment']) && strlen($_REQUEST['comment']) < 512) {
  84                      $comment = $_REQUEST['comment'];
  85                      }
  86                  else {
  87                      $comment = '';
  88                      }
  89  
  90                  $this->current_wiki->current_page->comment = $comment;
  91  
  92                  if((isset($_POST['no_spam']) && $_POST['no_spam'] == 'yes') || SESSION_STATUS == 'ok') {
  93                      $this->current_wiki->current_page->save(TRUE);
  94                      }
  95                  else {
  96                      $_REQUEST['edit'] = TRUE;
  97                      }
  98                  }
  99  
 100              if(isset($_REQUEST['edit']) && isset($_REQUEST['wikibody']) && $this->current_wiki->permissions->is_writable()) {
 101                  $this->current_wiki->current_page->body = $_REQUEST['wikibody'];
 102                  $preview = $this->convert_to_html($_REQUEST['wikibody']);
 103                  }
 104              }
 105              
 106          $pages = array(
 107                  WIKI_DEFAULT_PAGE => array(
 108                      'title' => LANG_MAIN_PAGE, 
 109                      'selected' => ($this->current_wiki->current_page->title == WIKI_DEFAULT_PAGE)
 110                      )
 111                  );
 112          
 113          $nav_items = $this->current_wiki->get_title_index(TRUE);
 114      
 115          foreach($nav_items as $nav_item) {
 116              $selected = ($this->current_wiki->current_page->title == $nav_item['title']);
 117              $pages[$nav_item['title']] = array('title' => $nav_item['title'], 'selected' => $selected);
 118              }
 119              
 120          
 121          $pages = array_merge($pages, array(
 122              'Special:TitleIndex' => array('title' => LANG_TITLE_INDEX, 'selected' => ($this->current_wiki->current_page->title == 'Special:TitleIndex')),
 123              'Special:RecentChanges' => array('title' => LANG_RECENT_CHANGES, 'selected' => ($this->current_wiki->current_page->title == 'Special:RecentChanges'))
 124              ));
 125          
 126          $smarty->assign('pages', $pages);
 127  
 128          if($this->current_wiki->current_page->title == 'Special:Recent Changes' 
 129                  || $this->current_wiki->current_page->title == 'Special:RecentChanges') {
 130              if(isset($_REQUEST['limit']) && is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
 131                  $limit = (int) $_REQUEST['limit'];
 132                  }
 133              else {
 134                  $limit = 20;
 135                  }
 136  
 137              $mode = 'recent_changes';
 138              $recent_changes = $this->current_wiki->get_recent_changes($limit);
 139              
 140              $smarty->assign('recent_changes', $recent_changes);
 141              }
 142          elseif($this->current_wiki->current_page->title == 'Special:Allpages' 
 143                  || $this->current_wiki->current_page->title == 'Special:TitleIndex') {
 144              $mode = 'title_index';
 145  
 146              $title_index = $this->current_wiki->get_title_index();
 147              
 148              $smarty->assign('title_index', $title_index);
 149              }
 150          elseif($this->current_wiki->current_page->id != NULL && !isset($_REQUEST['edit']) && !isset($_REQUEST['history'])) {
 151              if(isset($_REQUEST['version']) && is_numeric($_REQUEST['version'])) {
 152                  $this->current_wiki->current_page->load_version($_REQUEST['version']);
 153                  }
 154                  
 155              $mode = 'view';
 156              }
 157          elseif($this->current_wiki->current_page->id != NULL && isset($_REQUEST['history'])) {
 158              $mode = 'history';
 159              $smarty->assign('changes', $this->current_wiki->current_page->get_changes());
 160              }
 161          else {
 162              $mode = 'edit';
 163              }
 164                  
 165          $smarty->assign_by_ref("awf", $this->my_cms->my_awf);
 166                  $smarty->assign_by_ref("content_object", $this->current_wiki);
 167                  $smarty->assign_by_ref("session", $_SESSION);
 168          $smarty->assign_by_ref("profile", $this->my_cms->users->current_user->profile);
 169                  $smarty->assign('charset', LANGUAGE_CHARSET);
 170                  $smarty->assign('stylesheet', 'css/'.$this->my_cms->my_awf->designs->current_design->css);
 171                  $smarty->assign('request_string', $this->my_cms->request_string);
 172                  $smarty->assign('full_request', $this->my_cms->full_request);
 173                     $smarty->assign('mode', $mode);
 174                     $smarty->assign('preview', $preview);
 175                     
 176                     if($this->my_cms->request['extension'] == 'pdf') {
 177              $pdf = new AWF_PDF;
 178                          return $pdf->html2pdf($this->current_wiki->title,
 179                       $smarty->fetch('wiki/'.$this->current_wiki->template.'.pdf.tpl', FINGERPRINT));
 180                          }
 181                  else {
 182                         return $smarty->fetch('wiki/'.$this->current_wiki->template.'.'.OUTPUT_FORMAT.'.tpl', FINGERPRINT);
 183                         }
 184          }
 185                  
 186  
 187  	function get_requested_content_object () {
 188          return $this->current_wiki->current_page;
 189          }
 190  
 191  	function get_requested_content_metadata () {
 192          $result['title']     = $this->current_wiki->current_page->title;
 193          $result['author']     = $this->current_wiki->current_page->username;
 194          $result['doctype']     = '';
 195          $result['description']     = 'AWF Wiki Page';
 196          $result['keywords']     = '';
 197          $result['short_name']    = $this->current_wiki->short_name.'/'.urlencode($this->current_wiki->current_page->title);
 198          $result['views']    = $this->current_wiki->current_page->views;
 199          $result['created']     = date('c', $this->current_wiki->current_page->created);
 200          $result['changed']     = date('c', $this->current_wiki->current_page->changed);
 201          $result['lang']        = $this->current_wiki->lang_code;
 202          return $result;
 203                  }
 204  
 205          function get_requested_content_as_array () {
 206              $result         = array();
 207          $result['body']        = $this->current_wiki->current_page->body;
 208          $result['comment']    = $this->current_wiki->current_page->comment;
 209          return $result;
 210                  }
 211  
 212  	function handle_request ($request_string) {
 213          $result = FALSE;
 214          
 215          $request = explode('/', $request_string);
 216          
 217          $this->current_page = $request[count($request) - 1];
 218          
 219          if($this->current_page == '' && defined('WIKI_DEFAULT_PAGE')) {
 220              $this->current_page = WIKI_DEFAULT_PAGE;
 221              }
 222          elseif($this->current_page == '') {
 223              return FALSE;
 224              }
 225              
 226          unset($request[count($request) - 1]);
 227          
 228          $wiki_short_name = join('/', $request);
 229  
 230          $this->current_wiki = new AWF_WikiPages ($wiki_short_name);
 231          
 232          if($this->current_wiki->id != NULL) {
 233              $this->current_wiki->my_container = $this;
 234              $this->current_wiki->load_page($this->current_page);
 235              switch($this->my_cms->request['extension']) {
 236                  case 'pdf':
 237                      $this->my_cms->output_handler = 'raw';
 238                      break;
 239                  case 'xml':
 240                      $result = TRUE;
 241                      $this->my_cms->output_handler = 'xml';
 242                      break;
 243                  case 'html':
 244                      $this->my_cms->output_handler = 'raw';
 245                      break;
 246                  default:
 247                      $this->my_cms->output_handler = 'raw';
 248                      break;
 249                  }
 250                  
 251              if(!$result && !file_exists(TEMPLATES_PATH.'wiki/'.$this->current_wiki->template.'.'.OUTPUT_FORMAT.'.tpl')) {
 252                  $result = FALSE;
 253                  }
 254              else {
 255                  if(defined('ENABLE_WIKIWORDS') && ENABLE_WIKIWORDS) {
 256                      $this->pear->setRenderConf('Xhtml', 'wikilink', 'view_url', '/'.$this->current_wiki->short_name.'/%s.html');
 257                      }
 258                  $result = TRUE;
 259                  }
 260              }
 261          else {
 262              $this->current_wiki = NULL;
 263              }
 264  
 265          return $result;
 266          }
 267  
 268  	function init_content () {
 269          return FALSE;
 270          }
 271  
 272  	function get_wiki_page ($page_id = NULL) {
 273          $result = new AWF_WikiPage ($page_id);
 274          $result->my_container = $this;
 275          return $result;
 276          }
 277  
 278  	function get_fulltext_search_results ($search) {
 279          $results     = array();
 280          $search_results = array();    
 281          $optional_where = '';
 282          
 283          $field_list    = 'page.title, page.body, page.comment';
 284  
 285          $permission_where = "perm.class_name = 'AWF_WikiPages' AND ".
 286                                      "perm.object_id = wiki.id AND ".
 287                                      AWF_Functions::wmea_perms('read')." & perm.permissions AND";
 288  
 289              $result_ids = sql_query_array('SELECT distinct(page.id), wiki.short_name, MATCH ('.$field_list.
 290                  ') AGAINST ('.sql_quote_smart($search).' IN BOOLEAN MODE) as'.
 291              ' score FROM '.TABLE_WIKIPAGES.' page, '.TABLE_WIKIS.' wiki, '.TABLE_PERMISSIONS.' perm WHERE '.$permission_where.
 292              '(wiki.site_id = 0 OR wiki.site_id = '.SITE_ID.') AND page.wiki_id = wiki.id'.$optional_where.' AND '.'MATCH ('.$field_list.') AGAINST ('.sql_quote_smart($search).
 293              ' IN BOOLEAN MODE) LIMIT 100', 'id', FALSE);
 294  
 295              if(is_array($result_ids)) {
 296                      foreach($result_ids as $result_id => $result_value) {
 297                          $page = $this->get_wiki_page($result_id);
 298                          $result['title']        = $page->title;
 299                          $result['created']      = $page->created;
 300                          $result['changed']      = $page->changed;
 301                          $result['url']          = 'http://'.$_SERVER['SERVER_NAME'].'/'.$result_value['short_name'].'/'.urlencode($page->title).'.html';
 302                  $result['score']    = $result_value['score'];
 303                          $results[] = $result;
 304                          }
 305              }
 306      
 307          return $results;
 308          return array();
 309          }
 310  
 311      /* Resolve Shortcuts */
 312  
 313  	function callback_resolve_shortcut_as_html ($matches) { // Callback function to resolve wikipages
 314              // Callback function for preg_replace_callback()
 315              
 316              $my_match = explode('|', $matches[1]);
 317              
 318              $wikipage = new AWF_WikiPage ($my_match[0]);
 319      
 320              if($wikipage->id != NULL) {
 321                      $css_class = 'WikiPage';
 322                     }
 323              else {
 324                  $css_class = 'newWikiPage';
 325                      }
 326  
 327          if(isset($my_match[1])) {
 328              $title = $my_match[1];
 329              }
 330          else {
 331              $title = $my_match[0];
 332              }
 333              
 334          if($this->current_wiki != NULL) {
 335              $short_name = $this->current_wiki->short_name;
 336              }
 337          else {
 338              $short_name = DEFAULT_WIKI;
 339              }
 340  
 341                  $result = '<a class="'.$css_class.'" href="'.$short_name.'/'.urlencode($my_match[0]).'.html">'.$title.'</a>';
 342                  
 343              unset($wikipage);
 344              
 345              return $result;
 346              }
 347  
 348  	function resolve ($cms_namespace, $resolver, $content) {
 349          $callback = create_function('$matches', 'global $awf; return $awf->cms->'.$cms_namespace.'->callback_resolve_shortcut_as_'.
 350                      $this->output_format.'($matches);');
 351  
 352          if($this->default_resolver == $resolver) {
 353              $content = preg_replace_callback("|".$this->resolver_start_tag."([^\]]*)".$this->resolver_end_tag."|", $callback, $content);
 354              }
 355  
 356          return preg_replace_callback("|".$this->resolver_start_tag.preg_quote($resolver.':')."([^\]]*)".$this->resolver_end_tag."|", $callback, $content);
 357          }
 358  
 359  	function resolve_all ($content) {
 360          if($content == '') {
 361              return FALSE;
 362              }
 363          
 364          if(!is_array($this->resolvers)) {
 365              foreach($this->my_cms->containers as $class_name => $object) {
 366                  if(method_exists($object, 'callback_resolve_shortcut_as_'.$this->output_format) 
 367                    && $object->cms_namespace != '' 
 368                                && $object->shortcut_namespace != '') {
 369                      $this->resolvers[$object->shortcut_namespace] = $object->cms_namespace;
 370                      }
 371                  }
 372              }
 373      
 374          if(!is_array($this->resolvers)) {
 375              return $content;
 376              }
 377  
 378          foreach($this->resolvers as $resolver => $cms_namespace) {
 379              if($resolver != $this->default_resolver) {
 380                  $content = $this->resolve($cms_namespace, $resolver, $content);
 381                  }
 382              }
 383  
 384          if(isset($this->resolvers[$this->default_resolver])) {
 385              $content = $this->resolve($this->resolvers[$this->default_resolver], $this->default_resolver, $content);
 386              }
 387  
 388          return $content;
 389          }
 390  
 391      /* Convert Wiki code to HTML/TEXT */
 392  
 393  	static function callback_footnote_as_html ($matches) {
 394          static $i = 0;
 395          $i++;
 396          $result = '<sup style="font-size: 75%;">'.$i.'</sup>';
 397              
 398              return $result;    
 399          }
 400      
 401  	function render_footnotes ($content) {
 402          //$content = preg_replace("|\(\(footnote:(.*)\)\)|", "<sup>$i</sup>", $content);
 403          $content = preg_replace_callback("|\(\(footnote:(.*)\)\)|", 
 404              create_function('$matches', 'return AWF_Wiki::callback_footnote_as_'.$this->output_format.'($matches);'), $content);
 405          
 406          return $content;
 407          }
 408          
 409  	static function callback_url_as_html ($matches) {
 410          // Callback function for preg_replace_callback()
 411          
 412          $url = preg_replace("|%%(\d+)%%|", '', $matches[1].$matches[2]);
 413          
 414          if(isset($matches[3])) {
 415              // Do not show glossary link if word is part of an external link
 416              $title = preg_replace("|%%(\d+)%%|", '', $matches[3]);
 417              }
 418          else {
 419              $title = $url;
 420              }
 421  
 422              $result = '<a href="'.$url.'" class="'.$matches[1].'" rel="nofollow">'.$title.'</a>';
 423              
 424              return $result;
 425          }
 426      
 427  	static function callback_remove_lexicon_wildcards ($matches) {
 428          return preg_replace("|%%(\d+)%%|", '', $matches[0]);
 429          }
 430      
 431  	function render_urls ($content) {
 432          // Remove Lexicon/Glossary wildcards inside brackets
 433          $content = preg_replace_callback("|\[([^\]]*)\]|", 
 434              create_function('$matches', 'return AWF_Wiki::callback_remove_lexicon_wildcards($matches);'), $content);
 435  
 436          $content = preg_replace_callback("|\[([a-z]+)(://\S+)\]|", 
 437              create_function('$matches', 'return AWF_Wiki::callback_url_as_'.$this->output_format.'($matches);'), $content);
 438          
 439          // Render URL's
 440          $content = preg_replace_callback("|\[([a-z]+)(://\S+)\s([^\]]*)\]|", 
 441              create_function('$matches', 'return AWF_Wiki::callback_url_as_'.$this->output_format.'($matches);'), $content);
 442              
 443          
 444          return $content;
 445          }
 446      
 447  	static function callback_numbered_heading_as_html ($matches) {
 448              // Callback function for preg_replace_callback()
 449          $heading = preg_replace("|%%(\d+)%%|", '', $matches[2]);
 450  
 451          static $headings = array();
 452          global $awf;
 453          if($awf->cms->wiki->reset_heading_counter == TRUE) {
 454              $headings = array();
 455              $awf->cms->wiki->reset_heading_counter = FALSE;
 456              }
 457          $headings[strlen($matches[1])]++;
 458          $numbering = '';
 459  
 460          $numbering = $headings[2];
 461  
 462          foreach($headings as $heading_level => $count) {
 463              if($heading_level > strlen($matches[1])) {
 464                  $headings[$heading_level] = 0;
 465                  }
 466              elseif($heading_level <= strlen($matches[1]) && $heading_level > 2) {
 467                  $numbering = $numbering.'.'.$count;
 468                  }
 469              }
 470              
 471          $numbering .= ' ';
 472  
 473              $result = str_repeat ('+', (strlen($matches[1]) - 1)).' '.$numbering.$heading."\n";
 474  
 475              return $result;
 476              }
 477              
 478  	static function callback_heading_as_html ($matches) {
 479              // Callback function for preg_replace_callback()
 480          $heading = preg_replace("|%%(\d+)%%|", '', $matches[2]);
 481  
 482              $result = str_repeat ('+', (strlen($matches[1]) - 1)).' '.$heading."\n";
 483  
 484              return $result;
 485              }
 486  
 487  	function convert_headings ($content) {
 488          if($this->numbered_headings) {
 489              $content = preg_replace_callback("|(={2,7})\s([^\n\r]*)\s(={2,7})|",
 490                          create_function('$matches', 'return AWF_Wiki::callback_numbered_heading_as_'.$this->output_format.'($matches);'), $content);
 491                          }
 492                  else {
 493              $content = preg_replace_callback("|(={2,7})\s([^\n\r]*)\s(={2,7})|",
 494                          create_function('$matches', 'return AWF_Wiki::callback_heading_as_'.$this->output_format.'($matches);'), $content);
 495                          }
 496  
 497          return $content;
 498          }
 499  
 500  	function convert_mediawiki_to_pear_syntax ($content) {
 501          $content = preg_replace("|'''([^\']*)'''|", "**$1**", $content);
 502          $content = preg_replace("|''([^\']*)''|", "//$1//", $content);
 503          $content = $this->convert_headings($content);
 504          return $content;
 505          }
 506  
 507  	function render_escaped_shortcuts ($content) {
 508          $content = preg_replace("|\[".$this->resolver_start_tag.'([^\'\]]+)'.$this->resolver_end_tag."\]|", "&#91;&#91;$1&#93;&#93;", $content);
 509          return $content;
 510          }
 511  
 512  	function render_all ($content) {
 513          if($this->pear != NULL) {
 514              $content = $this->convert_mediawiki_to_pear_syntax($content);
 515              $content = $this->pear->transform($content, 'xhtml');
 516              $content = $this->render_footnotes($content);
 517              $content = $this->render_escaped_shortcuts($content);
 518              }
 519  
 520          return $content;
 521          }
 522  
 523      /* Extract shortcuts, URLs and headings */
 524  
 525  	function get_shortcuts_as_array ($resolver, $content) {
 526          $result = array();
 527          $matches = array();
 528          $default_matches = array();
 529  
 530          preg_match_all ("|".$this->resolver_start_tag.preg_quote($resolver.':')."(.*)".$this->resolver_end_tag."|", $content, $matches);
 531  
 532          if($this->default_resolver == $resolver) {
 533              preg_match_all ("|".$this->resolver_start_tag."(.*)".$this->resolver_end_tag."|", $content, $default_matches);
 534              $matches = array_merge($default_matches, $matches);
 535              }
 536          
 537          foreach($matches[1] as $match_key => $match) {
 538              $my_match = explode('|', $match);
 539  
 540              if(!isset($my_match[1])) {
 541                  $my_match[1] = '';
 542                  }
 543  
 544              $result[$match_key] = array('target' => $my_match[0], 'properties' => $my_match);
 545              }
 546  
 547          return $result;
 548          }
 549  
 550  	function get_urls_as_array ($content) {
 551          $result = array();
 552  
 553          preg_match_all("|\[(https://\S+)\s([^\]]*)\]|", $content, $https_matches);
 554          preg_match_all("|\[(http://\S+)\s([^\]]*)\]|", $content, $http_matches);
 555          preg_match_all("|\[(mailto:\S+)\s([^\]]*)\]|", $content, $email_matches);
 556  
 557          foreach($https_matches[1] as $match_key => $match) {
 558              $result['https'][$match_key] = array('url' => $match, 'title' => $https_matches[2][$match_key]);
 559              }
 560          foreach($http_matches[1] as $match_key => $match) {
 561              $result['http'][$match_key] = array('url' => $match, 'title' => $http_matches[2][$match_key]);;
 562              }
 563          foreach($email_matches[1] as $match_key => $match) {
 564              $result['email'][$match_key] = array('url' => $match, 'title' => $http_matches[2][$match_key]);;
 565              }
 566  
 567          return $result;
 568          }
 569  
 570  	function get_footnotes_as_array ($content) {
 571          $result = array();
 572  
 573          preg_match_all("|\(\(footnote:(.*)\)\)|", $content, $matches);
 574  
 575          static $counter = 0;
 576  
 577          foreach($matches[1] as $match_key => $match) {
 578              $counter++;
 579              $result[$match_key]['text'] = $this->render_urls($match);
 580              $result[$match_key]['number']   = $counter;
 581              }
 582  
 583          return $result;
 584          }
 585  
 586  	function get_headings_as_array ($content) {
 587          $result = array();
 588  
 589          $content = $this->convert_headings($content);
 590          preg_match_all('/^(\+{1,6}) (.*)/m', $content, $matches);
 591  
 592          $headings = array();
 593          $i = 0;
 594  
 595          foreach($matches[2] as $match_key => $match) {
 596          
 597              $headings[strlen($matches[1][$match_key])]++;
 598  
 599              $numbering = $headings[2];
 600  
 601              foreach($headings as $heading_level => $count) {
 602                  if($heading_level > strlen($matches[1][$match_key])) {
 603                      $headings[$heading_level] = 0;
 604                      }
 605                  elseif($heading_level <= strlen($matches[1][$match_key]) && $heading_level > 2) {
 606                      $numbering = $numbering.'.'.$count;
 607                      }
 608                  }
 609              
 610              $numbering .= ' ';
 611          
 612              $heading_number[strlen($matches[1][$match_key]) - 2]++;
 613              $result[$match] = array(
 614                      'anchor' => 'toc'.$i++, 
 615                      'level'  => strlen($matches[1][$match_key]) - 2, 
 616                      'number' => $heading_number[strlen($matches[1][$match_key])],
 617                      'numbering' => $numbering);
 618              }
 619  
 620          return $result;
 621          }
 622  
 623  	function get_all_as_array ($content) {
 624          if($content == '' || !is_array($this->resolvers)) {
 625              return array();
 626              }
 627      
 628          foreach($this->resolvers as $res_key => $resolver) {
 629              if($resolver != $this->default_resolver) {
 630                  $matches[$resolver] = $this->get_shortcuts_as_array($resolver, $content);
 631                  }
 632              }
 633  
 634          if(in_array($this->default_resolver, $this->resolvers)) {
 635              $matches[$this->default_resolver] = $this->get_shortcuts_as_array($this->default_resolver, $content);
 636              }
 637      
 638          $matches['urls'] = $this->get_urls_as_array ($content);
 639          $matches['headings'] = $this->get_headings_as_array ($content);
 640  
 641          return $matches;
 642          }
 643  
 644  	function make_clean ($content) {
 645          return strip_tags(htmlspecialchars($content));
 646          }
 647  
 648  	function replace_links_with_url ($content) {}
 649  	function replace_urls_with_link ($content) {}
 650  
 651  	function convert_to_html ($content, $clean = FALSE, $glossary = FALSE) {
 652          $this->output_format = 'html';
 653  
 654          if($clean) {
 655              $content = $this->make_clean($content);
 656              }
 657              
 658          // Glossary Feature    
 659          if(is_bool($glossary) && $glossary === TRUE) {
 660              
 661              $articles = $this->my_cms->lexicon->get_all_published_articles_array();
 662  
 663              if(is_array($articles)) {
 664                  foreach($articles as $article_title => $article_id) {
 665                      $content = preg_replace("|\b(".$article_title.")\b|i", "%%$article_id%%\$1", $content);
 666                      }
 667                  }
 668              }
 669          elseif(is_array($glossary) && count($glossary) > 0) {
 670              
 671              foreach($glossary as $article_id => $article) {
 672                  $content = preg_replace("|\b(".$article->title.")\b|i", "%%$article_id%%\$1", $content);
 673                  }
 674              }
 675  
 676          $content = $this->resolve_all($this->render_all($content));
 677          // Create glossary shortcuts
 678          return $this->resolve('lexicon', 'lexicon', preg_replace("|%%(\d+)%%|", '[[lexicon:$1]]', $content));
 679          }
 680  
 681  	function convert_to_text ($content) {
 682          $this->output_format = 'text';
 683          return $this->render_all($this->resolve_all($this->make_clean($content)));
 684          }
 685  
 686  	function inherit_permissions () {
 687          return $this->permissions->inherit_to_class ('AWF_WikiPages');
 688          }
 689          
 690  	function get_wiki_templates () {
 691          $files = (AWF_Functions::get_file_list(BASE_PATH.'templates/wiki/', '', FALSE));
 692          
 693          foreach($files as $file_key => $file_value) {
 694              $files[$file_key] = strtok($file_value,'.');
 695              }
 696  
 697          $files = array_unique($files);
 698  
 699          sort($files);
 700          
 701          return $files;
 702          }
 703          
 704  	function get_wiki ($id = NULL) {
 705          $result = new AWF_WikiPages;
 706          $result->my_container = $this;
 707          if($id != NULL) {
 708              $result->load($id);
 709              }
 710          return $result;
 711          }
 712      }
 713  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]