function module_wiki_last_comments($mod_reference, $module_params) { if (!function_exists('module_last_comments')) { function module_last_comments($limit, $type='wiki page') { global $tikilib, $user; $bindvars = array($type); $where = ''; switch ($type) { case 'article': $join = 'left join `tiki_articles` ta on (tc.`object` = ta.`articleId`)'; $get = ', ta.`title` as name'; global $tiki_p_admin_cms; if ($tiki_p_admin_cms != 'y') { $where = 'and `approved`!=?'; $bindvars[] = 'n'; } break; case 'wiki page': $join = ''; $get = ', tc.`object` as name'; global $tiki_p_admin_wiki; if ($tiki_p_admin_wiki != 'y') { $where = 'and `approved`!=?'; $bindvars[] = 'n'; } break; } $query = "select tc.* $get from `tiki_comments` as tc $join where `objectType`=? $where order by `commentDate` desc"; $result = $tikilib->query($query, $bindvars, $limit, 0); $ret = array(); while ($res = $result->fetchRow()) { switch ($type) { case 'wiki page': $perm = 'tiki_p_view'; break; case 'article': $perm = 'tiki_p_read_article'; break; default: return null; } if ($tikilib->user_has_perm_on_object($user, $res['object'], $res['type'], $perm)) { $ret[] = $res; } } return $ret; } } global $smarty, $prefs; if (!isset($module_params['type'])) $module_params['type'] = "wiki page"; switch ($module_params['type']) { case 'cms': case 'article': case 'articles': if (!$prefs['feature_articles']) return; $module_params['type'] = 'article'; $smarty->assign('tpl_module_title', tra('Last article comments')); break; default: if (!$prefs['feature_wiki']) return; $module_params['type'] = 'wiki page'; $smarty->assign('tpl_module_title', tra('Last wiki comments')); break; } $comments = module_last_comments($mod_reference['rows'], $module_params['type']); $smarty->assign_by_ref('comments', $comments); $smarty->assign('moretooltips', isset($module_params['moretooltips']) ? $module_params['moretooltips'] : 'n'); $smarty->assign('type', $module_params['type']); }
/** * @param $mod_reference * @param $module_params */ function module_wiki_last_comments($mod_reference, $module_params) { if (!function_exists('module_last_comments')) { /** * @param $limit * @param string $type * @return array|null */ function module_last_comments($limit, array $params) { global $tikilib, $user; $bindvars = array($params['type']); $where = ''; switch ($params['type']) { case 'article': $join = 'left join `tiki_articles` ta on (tc.`object` = ta.`articleId`)'; $get = ', ta.`title` as name'; if (!empty($params['language'])) { $where .= ' and ta.`lang`=?'; $bindvars[] = $params['language']; } global $tiki_p_admin_cms; if ($tiki_p_admin_cms != 'y') { $where .= ' and tc.`approved`!=?'; $bindvars[] = 'n'; } break; case 'wiki page': if (empty($params['language'])) { $join = ''; } else { $join = 'left join `tiki_pages` tp on (tc.`object` = tp.`pageName`)'; $where .= ' and tp.`lang`=?'; $bindvars[] = $params['language']; } $get = ', tc.`object` as name'; global $tiki_p_admin_wiki; if ($tiki_p_admin_wiki != 'y') { $where .= ' and tc.`approved`!=?'; $bindvars[] = 'n'; } break; } $query = "select tc.* {$get} from `tiki_comments` as tc {$join} where `objectType`=? {$where} order by `commentDate` desc"; $result = $tikilib->query($query, $bindvars, $limit, 0); $ret = array(); while ($res = $result->fetchRow()) { switch ($params['type']) { case 'wiki page': $perm = 'tiki_p_view'; break; case 'article': $perm = 'tiki_p_read_article'; break; default: return null; } if ($tikilib->user_has_perm_on_object($user, $res['object'], $res['type'], $perm)) { $res['title'] = TikiLib::lib('comments')->process_comment_title($res, $params['commentlength']); $ret[] = $res; } } return $ret; } } global $prefs; if (!isset($module_params['type'])) { $module_params['type'] = "wiki page"; } if (!isset($module_params['commentlength'])) { $module_params['commentlength'] = 40; } if (!isset($module_params['avatars'])) { $module_params['avatars'] = 'n'; } $smarty = TikiLib::lib('smarty'); switch ($module_params['type']) { case 'cms': case 'article': case 'articles': if (!$prefs['feature_articles']) { return; } $module_params['type'] = 'article'; $smarty->assign('tpl_module_title', tra('Last article comments')); break; default: if (!$prefs['feature_wiki']) { return; } $module_params['type'] = 'wiki page'; $smarty->assign('tpl_module_title', tra('Last wiki comments')); break; } $comments = module_last_comments($mod_reference['rows'], $module_params); $smarty->assign_by_ref('comments', $comments); $smarty->assign('moretooltips', isset($module_params['moretooltips']) ? $module_params['moretooltips'] : 'n'); $smarty->assign('type', $module_params['type']); }