[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/wiki/inc/ -> class.uiwiki.inc.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare Wiki - UserInterface                                          *
   4  * http://www.egroupware.org                                                *
   5  * -------------------------------------------------                        *
   6  * Copyright (c) 2004-6 by RalfBecker@outdoor-training.de                   *
   7  * --------------------------------------------                             *
   8  *  This program is free software; you can redistribute it and/or modify it *
   9  *  under the terms of the GNU General Public License as published by the   *
  10  *  Free Software Foundation; either version 2 of the License, or (at your  *
  11  *  option) any later version.                                              *
  12  \**************************************************************************/
  13  
  14  /* $Id: class.uiwiki.inc.php 21242 2006-04-06 18:59:47Z ralfbecker $ */
  15  
  16  require_once (EGW_INCLUDE_ROOT.'/wiki/inc/class.bowiki.inc.php');
  17  
  18  class uiwiki extends bowiki
  19  {
  20      var $public_functions = array(
  21          'edit' => True,
  22          'view' => True,    // only redirects to /wiki/index.php for the moment
  23          'search' => True,
  24      );
  25      var $anonymous;        // wiki is used anonymous
  26  
  27  	function uiwiki()
  28      {
  29          $this->bowiki($_GET['wiki_id']);
  30  
  31          $this->anonymous = $this->config['allow_anonymous'] && $this->config['anonymous_username'] == $GLOBALS['egw_info']['user']['account_lid'];
  32  
  33          $this->tpl =& CreateObject('etemplate.etemplate');
  34          $this->html =& $this->tpl->html;
  35  
  36          // should pages with wiki-syntax be converted to html automaticaly
  37          switch($this->AutoconvertPages)
  38          {
  39              case 'always':
  40              case 'never':
  41              case 'onrequest':
  42                  $this->auto_convert = $this->AutoconvertPages == 'always';
  43                  break;
  44              case 'auto':
  45              default:
  46                  $this->auto_convert = $this->tpl->html->htmlarea_availible();
  47          }
  48          if (get_magic_quotes_gpc())
  49          {
  50              foreach($_GET as $name => $val)
  51              {
  52                  $_GET[$name] = stripslashes($val);
  53              }
  54          }
  55      }
  56  
  57  	function edit($content='')
  58      {
  59          //echo "<p>uiwiki::edit() content=<pre>".print_r($content,True)."</pre>\n";
  60          $this->rateCheck('edit',$_SERVER['REMOTE_ADDR']);
  61  
  62          if (!is_array($content))
  63          {
  64              $content['name'] = $content ? $content : $_GET['page'];
  65              $content['lang'] = $_GET['lang'];
  66              $content['version'] = $_GET['version'];
  67              $start = True;
  68          }
  69          list($action) = @each($content['action']);
  70          if (empty($content['name']))
  71          {
  72              $this->tpl->location('/wiki/');
  73          }
  74          $pg = $this->page($content['name'],$content['lang']);
  75          if ($content['version'] && $action != 'load')
  76          {
  77              $pg->version = $content['version'];
  78          }
  79          if ($pg->read() === False)    // new entry
  80          {
  81              $pg->lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
  82          }
  83  
  84          // acl checks
  85          if (!$pg->acl_check())    // no edit-rights
  86          {
  87              $GLOBALS['egw']->redirect($this->ViewURL($content));
  88          }
  89          elseif (!$pg->acl_check(True))    // no read-rights
  90          {
  91              $this->tpl->location('/wiki/');
  92          }
  93          if ($start || $action == 'load')
  94          {
  95              $content = $pg->as_array();
  96              $content['is_html'] = substr($content['text'],0,7) == "<html>\n" && substr($content['text'],-8) == "</html>\n";
  97          }
  98          if ($start || $action == 'load' || $action == 'convert')
  99          {
 100              if ($content['is_html'])
 101              {
 102                  $content['text'] = substr($content['text'],7,-8);
 103              }
 104              elseif ($this->auto_convert || $action == 'convert')
 105              {
 106                  $content['text'] = $this->parse($pg,'Convert');
 107                  $content['is_html'] = True;
 108              }
 109          }
 110  
 111          if ($content['is_html'])
 112          {
 113              // some tavi stuff need to be at the line-end
 114              $content['text'] = preg_replace(array('/(.+)(<br \\/>)/i',"/(<br \\/>\n?)+$/i"),array("\\1\n\\2",''),$content['text']);
 115  
 116              $content['preview'] = $this->parse("<html>\n".$content['text']."\n</html>\n",'Parse',$content['name']);
 117          }
 118          else
 119          {
 120              $content['preview'] = $this->parse($content['text'],'Parse',$content['name']);
 121          }
 122          if (empty($content['title'])) $content['title'] = $content['name'];
 123          //echo "<p>uiwiki::edit() action='$action', content=<pre>".print_r($content,True)."</pre>\n";
 124  
 125          if ($action)
 126          {
 127              switch($action)
 128              {
 129                  case 'delete':
 130                      $content['text'] = '';
 131                      $content['comment'] = lang('deleted');
 132                      $content['is_html'] = False;    // else page is not realy empty
 133                  case 'rename':
 134                  case 'save':
 135                  case 'apply':
 136                      // do save
 137                      if ($content['is_html'])
 138                      {
 139                          $content['text'] = "<html>\n".$content['text']."\n</html>\n";
 140                      }
 141                      if ($action == 'rename')
 142                      {
 143                          $this->rename($content,$content['old_name'],$content['old_lang']);
 144                      }
 145                      else
 146                      {
 147                          $this->write($content);
 148                      }
 149                      if ($content['is_html'])
 150                      {
 151                          $content['text'] = substr($content['text'],7,-8);
 152                      }
 153              }
 154              switch($action)
 155              {
 156                  case 'delete':
 157                      $content = '';    // load the Homepage
 158                  case 'save':
 159                  case 'cancel':
 160                      // return to view
 161                      $GLOBALS['egw']->redirect($this->ViewURL($content));
 162                      break;
 163              }
 164          }
 165          $acl_values = array(
 166              WIKI_ACL_ALL =>   lang('everyone'),
 167              WIKI_ACL_USER =>  lang('users'),
 168              WIKI_ACL_ADMIN => lang('admins'),
 169          );
 170          $this->tpl->read('wiki.edit');
 171  
 172          if ($content['is_html'] || $this->AutoconvertPages == 'never' || !$this->tpl->html->htmlarea_availible())
 173          {
 174              $this->tpl->disable_cells('action[convert]');
 175  
 176              // picture upload via tinyMCE
 177              $GLOBALS['egw']->session->appsession('UploadImage','phpgwapi',array(
 178                  'app' => 'wiki',
 179                  'upload_dir'   => $this->upload_dir,
 180                  'upload_url'   => $this->upload_url,
 181                  'admin_method' => $GLOBALS['egw']->link('/index.php','menuaction=admin.uiconfig.index&appname=wiki'),
 182              ));
 183          }
 184          $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps']['wiki']['title'] . ' - ' .
 185              lang('edit') . ' ' . $content['name'] .
 186              ($content['lang'] && $content['lang'] != $GLOBALS['egw_info']['user']['preferences']['common']['lang'] ?
 187                  ':' . $content['lang'] : '').
 188              ($content['name'] != $content['title'] ? ' - ' . $content['title'] : '');
 189          $this->tpl->exec('wiki.uiwiki.edit',$content,array(
 190              'lang'     => array('' => lang('not set')) + $GLOBALS['egw']->translation->get_installed_langs(),
 191              'readable' => $acl_values,
 192              'writable' => $acl_values,
 193          ),False,array(
 194              'wiki_id'  => $content['wiki_id'],
 195              'old_name' => isset($content['old_name']) ? $content['old_name'] : $content['name'],
 196              'old_lang' => isset($content['old_lang']) ? $content['old_lang'] : $content['lang'],
 197              'version'  => $content['version'],
 198              'is_html'  => $content['is_html'],
 199          ));
 200      }
 201      
 202      /**
 203       * Show a wiki page
 204       *
 205       * redirects to /wiki/index.php for the moment
 206       */
 207  	function view($return_content=false)
 208      {
 209          $this->rateCheck('view',$_SERVER['REMOTE_ADDR']);
 210  
 211          $page =& $this->page($_GET['page'] ? $_GET['page'] : $this->config['wikihome'],$_GET['lang']);
 212          if ($_GET['version']) $page->version = $_GET['version'];
 213  
 214          if ($page->read() === false)
 215          {
 216              $html = '<p><b>'.lang("Page '%1' not found !!!",'<i>'.$this->html->htmlspecialchars($_GET['page'].
 217                  ($_GET['lang']?':'.$_GET['lang']:'')).'</i>')."</b></p>\n";
 218              $page = false;
 219          }
 220          if ($page && !$page->acl_check(True))    // no read-rights
 221          {
 222              $this->tpl->location('/wiki/');
 223          }
 224          $html = $this->header($page).$html;
 225          if ($page) $html .= $this->get($page,'',$this->wiki_id);
 226          $html .= $this->footer($page);
 227          
 228          if ($return_content) return $html;
 229  
 230          echo $html;
 231      }
 232  
 233      /**
 234       * Show the page-header for the manual
 235       *
 236       * @param object/boolean $page sowikipage object or false
 237        * @param string $title title of the search
 238       */
 239  	function header($page=false,$title='')
 240      {
 241          // anonymous sessions have no navbar !!!
 242          $GLOBALS['egw_info']['flags']['nonavbar'] = $this->anonymous;
 243          $GLOBALS['egw']->common->egw_header();
 244          
 245          if ($page)
 246          {
 247              $title = '<a href="'.$GLOBALS['egw']->link('/index.php',array(
 248                  'menuaction' => 'wiki.uiwiki.search',
 249                  'search'     => $page->name,
 250              )).'">'.$page->title.'</a>';
 251          }
 252          $html = '<h1 style="margin:0px;" class="title">'.$title."</h1>\n";
 253  
 254          $html .= '<form action="'.$GLOBALS['egw']->link('/index.php',array('menuaction'=>'wiki.uiwiki.search')).'" method="POST">'.
 255              '<a href="'.$this->viewURL($this->config['wikihome']).'">'.$this->config['wikihome'].'</a> | '.
 256              '<a href="'.$this->viewUrl('RecentChanges').'">'.lang('Recent Changes').'</a> | '.
 257              '<input name="search" value="'.$this->html->htmlspecialchars($_REQUEST['search']).'" /> '.
 258              '<input type="submit" name="go" value="'.$this->html->htmlspecialchars(lang('Search')).'" /></form>'."\n";
 259          $html .= "<hr />\n";
 260          
 261          return $html;
 262      }
 263      
 264      /**
 265       * Show the page-footer for the manual
 266       *
 267       * @param object/boolean $page sowikipage object or false
 268        */
 269  	function footer($page=false)
 270      {
 271          $parts = array();
 272  
 273          if ($page)
 274          {
 275              $parts[] = $page->acl_check() ? '<a href="'.htmlspecialchars($this->editURL($page->name,$page->lang,$page->version)).'">'.
 276                  ($page->supercede == $page->time ? lang('Edit this document') : lang('Edit this <em>ARCHIVE VERSION</em> of this document')).'</a>' :
 277                  lang('This page can not be edited.');
 278                  
 279              $parts[] = '<a href="'.htmlspecialchars($this->historyURL($page->name,false,$page->lang)).'">'.lang('View document history').'</a>';
 280  
 281              $parts[] = lang('Document last modified').': '.html_time($page->time);
 282          }
 283          return $parts ? "<hr />\n".implode(' | ',$parts) : '';
 284      }
 285  
 286      /**
 287       * search the manual and display the result
 288       */
 289  	function search($return_content=false)
 290      {
 291          $this->rateCheck('view',$_SERVER['REMOTE_ADDR']);
 292  
 293          $html = $this->header(false,lang('Search for').': '.$this->html->htmlspecialchars($_REQUEST['search']));
 294          
 295          $nothing_found = true;
 296          foreach($this->find(str_replace(array('*','?'),array('%','_'),$_REQUEST['search'])) as $page)
 297          {
 298              if ($nothing_found)
 299              {
 300                  $nothing_found = false;
 301                  $html .= "<ul>\n";
 302              }
 303              $item = '<li><a href="'.htmlspecialchars($this->viewURL($page['name'],$page['lang'])).'"><b>'.$this->html->htmlspecialchars($page['title']).'</b></a>'.
 304                  ($page['lang'] != $this->lang ? ' <i>'.$this->html->htmlspecialchars($GLOBALS['egw']->translation->lang2language($page['lang'])).'</i>' : '').'<br />'.
 305                  $this->html->htmlspecialchars($this->summary($page))."</li>\n";
 306              
 307              if ($page['lang'] != $this->lang)
 308              {
 309                  $other_langs .= $item;
 310                  continue;
 311              }
 312              $html .= $item;
 313          }
 314          if ($other_langs) $html .= $other_langs;
 315          
 316          if (!$nothing_found)
 317          {
 318              $html .= "</ul>\n";
 319          }
 320          else
 321          {
 322              $html .= '<p><i>'.lang('The search returned no result!')."</i></p>\n";
 323          }
 324          $html .= $this->footer();
 325          
 326          if ($return_content) return $html;
 327          
 328          echo $html;
 329      }
 330  }


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