[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/sitemgr/modules/ -> class.module_forum.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare SiteMgr - Web Content Management                              *
   4      * http://www.egroupware.org                                                *
   5      * --------------------------------------------                             *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.module_forum.inc.php 20295 2006-02-15 12:31:25Z  $ */
  13  
  14  class module_forum extends Module 
  15  {
  16      var $template;
  17      var $startlevel;
  18  
  19  	function module_forum()
  20      {
  21          $this->arguments = array(
  22              'startlevel' => array(
  23                  'type' => 'select',
  24                  'label' => lang('With which view should the module be displayed in the beginning?'),
  25                  'options' => array(
  26                      1 => lang('Overview of all available categories'),
  27                      2 => lang('Overview of one specific category'),
  28                      3 => lang('Summary of one forum'),
  29                  ),
  30              ),
  31              'startcat_id' => array(
  32                  'type' => 'select',
  33                  'label' => lang('Select a category'),
  34                  'options' => Array(),
  35              ),
  36              'startforum_id' => array(
  37                  'type' => 'select',
  38                  'label' => lang('Select a forum'),
  39                  'options' => Array(),
  40              ),
  41          );
  42          $this->get = array('level','cat_id','forum_id','msg','pos','view');
  43          $this->session = array('level','cat_id','forum_id','view');
  44          $this->title = lang('Discussions');
  45          $this->description = lang('This module displays the eGW forums on the web site');
  46          $this->bo =& CreateObject('forum.boforum',1);
  47      }
  48  
  49  	function get_user_interface()
  50      {
  51          $defaults = $this->block->arguments;
  52          if ($defaults['startlevel'] == 2 || $defaults['startlevel'] == 3)
  53          {
  54              $options=array();
  55              $cats = $this->bo->get_all_cat_info();
  56              while(list($key,$cat) = @each($cats))
  57              {
  58                  $options[$cat['id']] = $cat['name'];
  59              }
  60              $this->arguments['startcat_id']['options'] = $options;
  61          }
  62          else
  63          {
  64              unset($this->arguments['startcat_id']);
  65          }
  66          if (($defaults['startlevel'] == 3) && $defaults['startcat_id'])
  67          {
  68              $options=array();
  69              $forums = $this->bo->get_forums_for_cat($defaults['startcat_id']);
  70              while (list($key,$forum) = @each($forums))
  71              {
  72                  $options[$forum['id']] = $forum['name'];
  73              }
  74              $this->arguments['startforum_id']['options'] = $options;
  75          }
  76          else
  77          {
  78              unset($this->arguments['startforum_id']);
  79          }
  80          return parent::get_user_interface();
  81      }
  82  
  83  	function get_content(&$arguments,$properties)
  84      {
  85          $this->startlevel = $arguments['startlevel'];
  86          if (!$arguments['level'] || $arguments['level'] < $this->startlevel)
  87          {
  88              $arguments['level'] = $this->startlevel;
  89          }
  90          $this->template =& CreateObject('phpgwapi.Template');
  91          $this->template->set_root($this->find_template_dir());
  92  
  93          if ($arguments['level'] == 1)
  94          {
  95              return $this->index();
  96          }
  97  
  98          //$arguments['level'] > 1
  99          $cat_id = ($this->startlevel == 1) ? $arguments['cat_id'] : $arguments['startcat_id'];
 100          $cat = $cat_id ? $this->bo->get_cat_info($cat_id) : False;
 101          if (!$cat)
 102          {
 103              $cats = array_values($this->bo->get_all_cat_info());
 104              if (!$cats)
 105              {
 106                  return lang('There are no categories');
 107              }
 108              $cat = $cats[0];
 109          }
 110          if ($arguments['level'] == 2)
 111          {
 112              return $this->forums($cat);
 113          }
 114  
 115          //$arguments['level'] > 2
 116          $forum_id = ($this->startlevel > 3) ? $arguments['forum_id'] : $arguments['startforum_id'];
 117          $forum = $forum_id ? $this->bo->get_forum_info($cat['id'],$forum_id) : False;
 118          if (!$forum)
 119          {
 120              $forums = array_values($this->bo->get_forums_for_cat($cat['id']));
 121              if (!$forums)
 122              {
 123                  return lang('There are no forums in this category');
 124              }
 125              $forum = $forums[0];
 126          }
 127          if ($arguments['level'] == 3)
 128          {
 129              return $this->threads($cat,$forum,(strcmp($arguments['view'],'collapsed') == 0));
 130          }
 131  
 132          //$arguments['level'] == 4, if msg is not defined we fall back to level 3
 133          return $arguments['msg'] ? 
 134              $this->read($cat,$forum,$arguments['msg']) : 
 135              $this->threads($cat,$forum,(strcmp($arguments['view'],'collapsed') == 0));
 136      }
 137  
 138  	function index()
 139      {
 140          $this->template->set_file(
 141              Array(
 142                  'INDEX'    => 'index.body.tpl'
 143              )
 144          );
 145          $this->template->set_block('INDEX','CategoryForum','CatF');
 146  
 147          $var = Array(
 148              'CAT_IMG'    => $GLOBALS['egw']->common->image('forum','category'),
 149          );
 150          $this->template->set_var($var);
 151  
 152          $cats = $this->bo->get_all_cat_info();
 153  
 154          $rowon = true;
 155          while(list($key,$cat) = @each($cats))
 156          {
 157              $rowon = !$rowon;
 158  
 159              $var = Array(
 160                  'ROWONOFF'    => $rowon ? 'rowon' : 'rowoff',
 161                  'CAT'    => $cat['name'],
 162                  'DESC'    => $cat['descr'],
 163                  'CAT_LINK'    => $this->link(Array(
 164                      'level'    => 2,
 165                      'cat_id'    => $cat['id']
 166                  )),
 167                  'value_last_post' => $cat['last_post'],
 168                  'value_total'=> $cat['total']
 169              );
 170              $this->template->set_var($var);
 171              $this->template->parse('CatF','CategoryForum',true);
 172          }
 173          $this->template->parse('Out','INDEX');
 174          return $this->template->get('Out');
 175      }
 176  
 177  	function forums($cat)
 178      {
 179          $this->template->set_file(
 180              Array(
 181              '_list'    => 'forums.body.tpl'
 182              )
 183          );
 184          $this->template->set_block('_list','row_empty');
 185          $this->template->set_block('_list','list');
 186          $this->template->set_block('_list','row');
 187  
 188          $var = Array(
 189              'FORUM_IMG' => $GLOBALS['egw']->common->image('forum','forum'),
 190              'CATEGORY'=> $cat['name'],
 191              'LANG_CATEGORY'=> lang('Category'),
 192              'BACKLINK'=> (($this->startlevel == 1) ? 
 193                  ('<a href="' . $this->link(array('level' => 1)) . '">' . lang('All categories') . '</a>') : 
 194                  ''
 195              )
 196          );
 197          $this->template->set_var($var);
 198  
 199          $forum_info = $this->bo->get_forums_for_cat($cat['id']);
 200  
 201          if(!$forum_info)
 202          {
 203              $this->template->set_var('lang_no_forums',lang('There are no forums in this category'));
 204              $this->template->fp('rows','row_empty');
 205          }
 206          else
 207          {
 208              $rowon = true;
 209              while (list($key,$forum) = each($forum_info))
 210              {
 211                  $rowon = !$rowon;
 212      
 213                  $this->template->set_var(
 214                      Array(
 215                          'ROWONOFF'=> $rowon ? 'rowon' : 'rowoff',
 216                          'NAME'=> $forum['name'],
 217                          'DESC'=> $forum['descr'],
 218                          'THREADS_LINK'=> $this->link(Array(
 219                              'level'    => 3,
 220                              'forum_id'    => $forum['id']
 221                          )),
 222                          'value_last_post' => $forum['last_post'],
 223                          'value_total'=> $forum['total']
 224                      )
 225                  );
 226                  $this->template->fp('rows','row',True);
 227              }
 228          }
 229          $this->template->parse('Out','list');
 230          return $this->template->get('Out');
 231      }
 232  
 233  	function threads($cat,$forum,$is_collapsed)
 234      {
 235          $pre_var    = array(
 236              'LANG_TOPIC'=> lang('Topic'),
 237              'LANG_AUTHOR'=> lang('Author'),
 238              'LANG_REPLIES'=> lang('Replies'),
 239              'LANG_LATREP'=> lang('Latest Reply'),
 240              'LANG_FORUM'=> lang('Forum'),
 241              'FORUM'=> $forum['name'],
 242              'BACKLINK'=> (($this->startlevel < 3) ? 
 243                  ('<a href="' . 
 244                      $this->link(array('level'    => 2)) . '">' . 
 245                      lang('All forums in category %1','<b>'.$cat['name'].'</b>') . '</a>'
 246                  ) : 
 247                  ''
 248              )
 249          );
 250  
 251          $thread_listing = $this->bo->get_thread($cat['id'],$forum['id'],$is_collapsed);
 252          if($is_collapsed)
 253          {
 254              $this->template->set_file(
 255                  Array(
 256                      'COLLAPSE'    => 'collapse.threads.tpl'
 257                  )
 258              );
 259              $this->template->set_block('COLLAPSE','CollapseThreads','CollapseT');
 260  
 261              $this->template->set_var($pre_var);
 262              $this->template->set_var('THREAD_IMG',$GLOBALS['egw']->common->image('forum','thread'));
 263  
 264              $rowon = true;
 265              while($thread_listing && list($key,$thread) = each($thread_listing))
 266              {
 267                  $rowon = !$rowon;
 268  
 269                  $var = Array(
 270                      'ROWONOFF'    => $rowon ? 'rowon' : 'rowoff',
 271                      'TOPIC'    => ($thread['subject']?$thread['subject']:'[No subject]'),
 272                      'AUTHOR'    => ($thread['author']?$GLOBALS['egw']->common->grab_owner_name($thread['author']):lang('Unknown')),
 273                      'REPLIES'    => $thread['replies'],
 274                      'READ_LINK'    => $this->link(Array(
 275                          'level'    => 4,
 276                          'msg' => $thread['id'],
 277                      )),
 278                      'LATESTREPLY'    => $thread['last_reply']
 279                  );
 280                  $this->template->set_var($var);
 281                  $this->template->parse('CollapseT','CollapseThreads',true);
 282              }
 283              $var = Array(
 284                  'THREADS_LINK'    => $this->link(Array(
 285                      'view' => 'threads',
 286                  )),
 287                  'LANG_THREADS' => lang('View Threads')
 288              );
 289              $this->template->set_var($var);
 290              $this->template->parse('Out','COLLAPSE');
 291          } //end if
 292          //For viewing the normal view
 293          else
 294          {
 295              $this->template->set_file(
 296                  Array(
 297                      'NORMAL'    => 'normal.threads.tpl'
 298                  )
 299              );
 300              $this->template->set_block('NORMAL','NormalThreads','NormalT');
 301              $this->template->set_var($pre_var);
 302  
 303              $rowon = true;
 304              $tr_color = $this->row_on_color; 
 305              while($thread_listing && list($key,$thread) = each($thread_listing))
 306              {
 307                  $rowon = !$rowon;
 308  
 309                  $move = '';
 310                  for($tmp = 1;$tmp <= $thread['depth']; $tmp++)
 311                  {
 312                      $move .= '&nbsp;&nbsp;';
 313                  }
 314                  $move .= '<img src="'.$GLOBALS['egw']->common->image('forum','n').'">';
 315                  $move .= '&nbsp;&nbsp;';
 316  
 317                  $var = Array(
 318                      'ROWONOFF'    => $rowon ? 'rowon' : 'rowoff',
 319                      'TOPIC'    => ($thread['subject']?$thread['subject']:'[No subject]'),
 320                      'AUTHOR'    => ($thread['author']?$GLOBALS['egw']->common->grab_owner_name($thread['author']):lang('Unknown')),
 321                      'REPLIES'    => $thread['replies'],
 322                      'READ_LINK'    => $this->link(Array(
 323                          'level'    => 4,
 324                          'msg' => $thread['id'],
 325                          'pos' => $thread['pos']
 326                      )),
 327                      'LATESTREPLY'    => $thread['last_reply'],
 328                      'DEPTH'    => $move
 329                  );
 330                  $this->template->set_var($var);
 331                  $this->template->parse('NormalT','NormalThreads',true);
 332              } //end while
 333  
 334              $var = Array(
 335                  'THREADS_LINK'    => $this->link(Array(
 336                      'view' => 'collapsed'
 337                  )),
 338                  'LANG_THREADS' => lang('Collapse Threads')
 339              );
 340              $this->template->set_var($var);
 341              $this->template->parse('Out','NORMAL');
 342          }
 343          return $this->template->get('Out');
 344      }
 345  
 346  	function read($cat,$forum,$msg)
 347      {
 348          $this->template->set_file(
 349              Array(
 350                  'READ'    => 'read.body.tpl'
 351              )
 352          );
 353  
 354          $this->template->set_block('READ','read_body','read_body');
 355          $this->template->set_block('READ','msg_template','msg_template');
 356          $this->template->set_block('READ','post_template','post_template');
 357          $var = array(
 358              'LANG_TOPIC'=> lang('Topic'),
 359              'LANG_AUTHOR'=> lang('Author'),
 360              'LANG_REPLIES'=> lang('Replies'),
 361              'LANG_LATREP'=> lang('Latest Reply'),
 362              'LANG_FORUM'=> lang('Forum'),
 363              'FORUM'=> $forum['name'],
 364              'LANG_SEARCH'=> lang('Search'),
 365              'BACKLINK' => ('<a href="' . $this->link(array('level' => 3)) . '">' . lang('Return to message list') . '</a>'),
 366              'LANG_DATE'=> lang('Date'),
 367              'LANG_SUBJECT' => lang('Subject'),
 368              'LANG_THREADS'    => lang('Return to forums')
 369          );
 370          $this->template->set_var($var);
 371  
 372      
 373  //it does not make sense to implement posting in this module, since the forum app is
 374  //too badly designed to to this in a clean way.
 375  //         $var = array(
 376  //             'POST_ACTION' => $this->link(array('level' => 5)),
 377  //             'LANG_REPLYTOPIC' => lang('Post A Message To This Thread').':',
 378  //             'LANG_MESSAGE' => lang('Message'),
 379  //             'LANG_SUBMIT'=> lang('Submit')
 380  //         );
 381  //         $this->template->set_var($var);
 382  //         $this->template->parse('POST_TEMPLATE','post_template',True);
 383  
 384          $post_ul = '';
 385          $pre_ul = '';
 386          $messages = $this->bo->read_msg($cat['id'],$forum['id'],$msg);
 387          while($messages && list($key,$message) = each($messages))
 388          {
 389              if($message['id'] == $msg)
 390              {
 391                  $var = Array(
 392                      'THREAD'=> $message['thread'],
 393                      'DEPTH'=> $message['depth'],
 394                      'RE_SUBJECT'    => (!strpos(' '.strtoupper($message['subject']),'RE: ')?'RE: ':'').$message['subject']
 395                  );
 396                  $this->template->set_var($var);
 397              }
 398  
 399              $var = Array(
 400                  'AUTHOR'=> ($message['thread_owner']?$GLOBALS['egw']->common->grab_owner_name($message['thread_owner']):lang('Unknown')),
 401                  'POSTDATE'=> $GLOBALS['egw']->common->show_date($GLOBALS['egw']->db->from_timestamp($message['postdate'])),
 402                  'SUBJECT_LINK' => $this->link(Array(
 403                      'msg' => $message['id'],
 404                      'pos' => $message['pos']
 405                  )),
 406                  'SUBJECT'=> $message['subject'],
 407                  'MESSAGE'        => nl2br($message['message']),
 408                  'NAME'=> $message['name'],
 409                  'EMAIL'=> $message['email']
 410              );
 411  
 412              if($key > 0)
 413              {
 414                  for($i=$depth,$pre_ul='',$post_ul='';$i<($message['depth'] - 1);$i++,$pre_ul.='<ul>',$post_ul.='</ul>')
 415                  {
 416                  }
 417                  $this->template->set_var('UL_PRE',$pre_ul);
 418              }
 419              else
 420              {
 421                  $depth = $message['depth'] - 1;
 422              }
 423  
 424              $this->template->set_var($var);
 425  
 426              $this->template->parse('MESSAGE_TEMPLATE','msg_template',True);
 427              $this->template->set_var('UL_PRE','');
 428          }
 429          if($post_ul)
 430          {
 431              $this->template->set_var('UL_POST',$post_ul);
 432          }
 433              
 434          $this->template->parse('Out','read_body');
 435          return $this->template->get('Out');
 436      }
 437  
 438  }


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