XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
comments.php
Go to the documentation of this file.
1 <?php
2 // $Id: comments.php 1015 2012-08-23 05:36:42Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortes <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
12 
13  $db = XoopsDatabaseFactory::getDatabaseConnection();
14 
15  $sql = "SELECT * FROM ".$db->prefix("rmc_comments")." ORDER BY id_com DESC";
16  $limit = $options[0]>0 ? $options[0] : 10;
17  $sql .= " LIMIT 0,$limit";
18  $result = $db->query($sql);
19  $comments = array();
20 
21  $ucache = array();
22  $ecache = array();
23  $mods = array();
24 
25  while($row = $db->fetchArray($result)){
26  $com = new RMComment();
27  $com->assignVars($row);
28 
29  if($options[3]){
30  // Editor data
31  if(!isset($ecache[$com->getVar('user')])){
32  $ecache[$com->getVar('user')] = new RMCommentUser($com->getVar('user'));
33  }
34 
35  $editor = $ecache[$com->getVar('user')];
36 
37  if($editor->getVar('xuid')>0){
38 
39  if(!isset($ucache[$editor->getVar('xuid')])){
40  $ucache[$editor->getVar('xuid')] = new XoopsUser($editor->getVar('xuid'));
41  }
42 
43  $user = $ucache[$editor->getVar('xuid')];
44 
45  $poster = array(
46  'id' => $user->getVar('uid'),
47  'name' => $user->getVar('uname'),
48  'email' => $user->getVar('email'),
49  'posts' => $user->getVar('posts'),
50  'avatar'=> $user->getVar('user_avatar')!='' && $user->getVar('user_avatar')!='blank.gif' ? XOOPS_UPLOAD_URL.'/'.$user->getVar('user_avatar') : RMCURL.'/images/avatar.gif',
51  'rank' => $user->rank(),
52  );
53 
54  } else {
55 
56  $poster = array(
57  'id' => 0,
58  'name' => $editor->getVar('name'),
59  'email' => $editor->getVar('email'),
60  'posts' => 0,
61  'avatar'=> RMCURL.'/images/avatar.gif',
62  'rank' => ''
63  );
64 
65  }
66  }
67 
68  // Get item
69  $cpath = XOOPS_ROOT_PATH.'/modules/'.$row['id_obj'].'/class/'.$row['id_obj'].'controller.php';
70 
71  if(is_file($cpath)){
72  if(!class_exists(ucfirst($row['id_obj']).'Controller'))
73  include_once $cpath;
74 
75  $class = ucfirst($row['id_obj']).'Controller';
76  $controller = new $class();
77  $item = $controller->get_item($row['params'], $com);
78  $item_url = $controller->get_item_url($row['params'], $com);
79  } else {
80 
81  $item = __('Unknow','rmcommon');
82  $item_url = '';
83 
84  }
85 
86  if(isset($mods[$row['id_obj']])){
87  $mod = $mods[$row['id_obj']];
88  } else {
89  $m = RMFunctions::load_module($row['id_obj']);
90  $mod = $m->getVar('name');
91  $mods[$row['id_obj']] = $mod;
92  }
93 
94  $comments[] = array(
95  'id' => $row['id_com'],
96  'text' => TextCleaner::truncate(TextCleaner::getInstance()->clean_disabled_tags(TextCleaner::getInstance()->popuplinks(TextCleaner::getInstance()->nofollow($com->getVar('content')))), 50),
97  'poster' => isset($poster) ? $poster : null,
98  'posted' => formatTimestamp($com->getVar('posted'), 'l'),
99  'item' => $item,
100  'item_url' => $item_url,
101  'module' => $row['id_obj'],
102  'status' => $com->getVar('status'),
103  'module' => $mod
104  );
105  }
106 
107  $comments = RMEvents::get()->run_event('rmcommon.loading.block.comments', $comments);
108  $block['comments'] = $comments;
109  $block['show_module'] = $options[1];
110  $block['show_name'] = $options[2];
111  $block['show_user'] = $options[3];
112  $block['show_date'] = $options[4];
113 
114  $num = $options[2] + $options[3] + $options[4];
115  $block['data_width'] = floor(100/$num);
116 
117  RMTemplate::get()->add_xoops_style('bk_comments.css', 'rmcommon');
118 
119  return $block;
120 
121 }
122 
124 
125  $form = '';
126 
127  if(defined('RMCLOCATION')){
128  $form .= '<table><tr><td></td><td>';
129  }
130 
131  $form .= '</td></tr>';
132  $form .= '<tr><td class="head">'.__('Number of Comments:','rmcommon').'</td><td class="odd">';
133  $form .= '<input type="text" size="5" name="options[0]" value="'.$options[0].'" />';
134  $form .= '<tr><td class="head">'.__('Show module name:','rmcommon').'</td><td class="odd">';
135  $form .= '<label><input type="radio" name="options[1]" value="1"'.($options[1]==1?' checked="checked"':'').' />'.__('Yes','rmcommon').'</label>';
136  $form .= '<label><input type="radio" name="options[1]" value="0"'.($options[1]==0?' checked="checked"':'').' />'.__('No','rmcommon').'</label></td></tr>';
137  $form .= '<tr><td class="head">'.__('Show item name:','rmcommon').'</td><td class="odd">';
138  $form .= '<label><input type="radio" name="options[2]" value="1"'.($options[2]==1?' checked="checked"':'').' />'.__('Yes','rmcommon').'</label>';
139  $form .= '<label><input type="radio" name="options[2]" value="0"'.($options[2]==0?' checked="checked"':'').' />'.__('No','rmcommon').'</label></td></tr>';
140  $form .= '<tr><td class="head">'.__('Show user name:','rmcommon').'</td><td class="odd">';
141  $form .= '<label><input type="radio" name="options[3]" value="1"'.($options[3]==1?' checked="checked"':'').' />'.__('Yes','rmcommon').'</label>';
142  $form .= '<label><input type="radio" name="options[3]" value="0"'.($options[3]==0?' checked="checked"':'').' />'.__('No','rmcommon').'</label></td></tr>';
143  $form .= '<tr><td class="head">'.__('Show date:','rmcommon').'</td><td class="odd">';
144  $form .= '<label><input type="radio" name="options[4]" value="1"'.($options[4]==1?' checked="checked"':'').' />'.__('Yes','rmcommon').'</label>';
145  $form .= '<label><input type="radio" name="options[4]" value="0"'.($options[4]==0?' checked="checked"':'').' />'.__('No','rmcommon').'</label>';
146 
147  if(defined('RMCLOCATION')){
148  $form .= '</td></tr></table>';
149  }
150 
151  return $form;
152 
153 }