From: <sy...@us...> - 2006-08-31 12:49:35
|
Update of /cvsroot/tikiwiki/_mods/modules/most_commented In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12434/most_commented Added Files: mod-most_commented.php mod-most_commented.tpl Log Message: hall of fame modules --- NEW FILE: mod-most_commented.php --- <?php // $Header: /cvsroot/tikiwiki/_mods/modules/most_commented/mod-most_commented.php,v 1.1 2006/08/31 12:49:30 sylvieg Exp $ //this script may only be included - so its better to die if called directly. if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) { header("location: index.php"); exit; } if (!function_exists("most_commented_help")) { function most_commented_help() { return "type=wiki|wiki page|article|forum topic|blog|faq|..., max=>nb, lastdays=>nb, nonums=y, typeChoice=y, lastdaysChoice=y, lastdaysList=-1-2-"; } } if (!function_exists("most_commented")) { /* type = '' for all or 'wiki page', 'forum','faq','blog' .... */ function most_commented($limit, $type='', $nbdays='') { global $tikilib; $mid = ""; $bindvars = array(); $retu = array(); if ($type) { $mid .= " and `objectType`=? "; if ($type == "wiki") $bindvars[] = "wiki page"; else if ($type == "forum topic") { $mid .= " and `parentId` != 0 "; $bindvars[] = "forum"; } else $bindvars[] = $type; } if ($nbdays) { $mid .= " and `commentDate`>=? "; $bindvars[] = time() - 60*60*24*$nbdays; } $query = "select *, count(*) as `nb` from `tiki_comments` where 1 $mid group by `object`, `objectType` order by ".$tikilib->convert_sortmode("nb_desc").", `hits`desc"; $result = $tikilib->query($query, $bindvars, $limit); while ($res = $result->fetchRow()) { if ($res['objectType'] == "article") { $query = "select * from `tiki_articles` where `articleId`= ?"; $result2 = $tikilib->query($query, array($res['object'])); if ($res2 = $result2->fetchRow()) { $res2['nb'] = $res['nb']; $res2['objectType'] = $res['objectType']; $retu[] = $res2; } else $retu[] = $res; } elseif ($res['objectType'] == "forum") { $query = "select * from `tiki_comments` where `threadId`= ?"; $result2 = $tikilib->query($query, array($res['parentId'])); if ($res2 = $result2->fetchRow()) { $res2['nb'] = $res['nb']; $retu[] = $res2; } else $retu[] = $res; } elseif ($res['objectType'] == "faq") { $query = "select * from `tiki_faqs` where `faqId`= ?"; $result2 = $tikilib->query($query, array($res['object'])); if ($res2 = $result2->fetchRow()) { $res2['nb'] = $res['nb']; $res2['objectType'] = $res['objectType']; $retu[] = $res2; } else $retu[] = $res; } elseif ($res['objectType'] == "blog") { $query = "select * from `tiki_blogs` where `blogId`= ?"; $result2 = $tikilib->query($query, array($res['object'])); if ($res2 = $result2->fetchRow()) { $res2['nb'] = $res['nb']; $res2['objectType'] = $res['objectType']; $retu[] = $res2; } else $retu[] = $res; } else $retu[] = $res; } //echo "<pre>";print_r($retu);echo "</pre>"; return $retu; } } global $nb_mod_most_commented; ++$nb_mod_most_commented; if (isset($_REQUEST["type_commented".$nb_mod_most_commented])) $type =$_REQUEST["type_commented".$nb_mod_most_commented]; elseif (isset($module_params["type"])) { $type = $module_params["type"]; if ($type == "wiki") $type = "wiki page"; } else $type = ""; $smarty->assign('type', $type); if (isset($_REQUEST["ld_commented".$nb_mod_most_commented])) $lastdays = $_REQUEST["ld_commented".$nb_mod_most_commented]; elseif (isset($module_params["lastdays"])) $lastdays = $module_params["lastdays"]; else $lastdays = ""; $smarty->assign('lastdays', $lastdays); if (isset($module_params["lastdaysList"])) { // separator is the first char $lastdaysList = split(substr($module_params["lastdaysList"], 1, 1), $module_params["lastdaysList"]); } else $lastdaysList = array("1", "7", "14", "30", "60"); $smarty->assign('lastdaysList', $lastdaysList); $smarty->assign('typeList', array("wiki page", "forum topic", "article", "blog", "faq")); $smarty->assign('nonums', isset($module_params["nonums"]) ? $module_params["nonums"] : 'n'); $smarty->assign('typeChoice', isset($module_params["typeChoice"]) ? $module_params["typeChoice"] : ''); $smarty->assign('lastdaysChoice', isset($module_params["lastdaysChoice"]) ? $module_params["lastdaysChoice"] : ''); $comments = most_commented($module_rows, $type, $lastdays); $smarty->assign('module_rows', $module_rows); $smarty->assign('comments', $comments); $smarty->assign('url', $_SERVER["REQUEST_URI"]); $smarty->assign('nb_mod_most_commented', $nb_mod_most_commented); ?> --- NEW FILE: mod-most_commented.tpl --- {* $Header: /cvsroot/tikiwiki/_mods/modules/most_commented/mod-most_commented.tpl,v 1.1 2006/08/31 12:49:30 sylvieg Exp $ *} {eval assign="ld" var="ld_commented`$nb_mod_most_commented`"} {eval assign="t" var="type_commented`$nb_mod_most_commented`"} {if $nonums eq 'y'} {eval var="{tr}`$module_rows` Most Commented{/tr}" assign="title1"} {else} {eval var="{tr}Most Commented{/tr}" assign="title1"} {/if} {if $type} {eval var="<br />{tr}$type{/tr}" assign="title3"} {else} {eval var=" " assign="title3"} {/if} {if $lastdays == 1} {eval var="<br />{tr}(This last day){/tr}" assign="title2"} {elseif $lastdays > 1} {eval var="<br />{tr}(These last $lastdays days){/tr}" assign="title2"} {else} {eval var=" " assign="title2"} {/if} {eval var="`$title1``$title3``$title2`" assign="tpl_module_title"} {tikimodule title=$tpl_module_title name="most_commented"} {if $lastdaysChoice eq 'y' or $typeChoice eq 'y'} <div class="box-choice"> {/if} {if $lastdaysChoice eq 'y'} <form method="post" action="{$url}" name="submit_{$ld}"> <input type="hidden" name="{$t}" value="{$type}" /> {tr}Last days:{/tr} <select name="{$ld}" onchange="submit_{$ld}.submit()"> <option value="" selected="selected">{tr}All{/tr}</option> {section name=ix loop=$lastdaysList} <option value="{$lastdaysList[ix]}" {if $lastdays eq "$lastdaysList[ix]"}selected="selected"{/if}>{$lastdaysList[ix]}</option> {/section} </select> <br /> </form> {/if} {if $typeChoice eq 'y'} <form method="post" action="{$url}" name="submit_{$t}"> <input type="hidden" name="{$ld}" value="{$lastdays}" /> {tr}Type:{/tr} <select name="{$t}" onchange="submit_{$t}.submit()"> <option value="" selected="selected">{tr}All{/tr}</option> {section name=ix loop=$typeList} <option value="{$typeList[ix]}" {if $type eq "$typeList[ix]"}selected="selected"{/if}>{$typeList[ix]}</option> {/section} </select> <br /> </form> {/if} {if $lastdaysChoice eq 'y' or $typeChoice eq 'y'} </div> {/if} <table border="0" cellpadding="0" cellspacing="0"> {section name=ix loop=$comments} <tr> {if $nonums != 'y'}<td valign="top" class="module">{$smarty.section.ix.index_next}) </td>{/if} <td class="module"> {if $comments[ix].objectType eq "wiki page"} <a class="linkmodule" href="tiki-index.php?page={$comments[ix].object|escape}&comzone=show" {if $type eq ""}title="{tr}wiki page{/tr}"{/if}>{$comments[ix].object}</a> {elseif $comments[ix].objectType eq "article"} <a class="linkmodule" href="tiki-read_article.php?articleId={$comments[ix].articleId}&comzone=show" {if $type eq ""}title="{tr}article{/tr}"{/if}>{$comments[ix].title}</a> {elseif $comments[ix].objectType eq "forum"} <a class="linkmodule" href="tiki-view_forum_thread.php?forumId={$comments[ix].object}&comments_parentId={$comments[ix].threadId}" {if $type eq ""}title="{tr}forum{/tr}"{/if}>{$comments[ix].title}</a> {elseif $comments[ix].objectType eq "faq"} <a class="linkmodule" href="tiki-view_faq.php?faqId={$comments[ix].faqId}&comzone=show" {if $type eq ""}title="{tr}faq{/tr}"{/if}>{$comments[ix].title}</a> {elseif $comments[ix].objectType eq "blog"} <a class="linkmodule" href="tiki-view_blog.php?blogId={$comments[ix].blogId}&comzone=show" {if $type eq ""}title="{tr}blog{/tr}"{/if}>{$comments[ix].title}</a> {/if} <span class="module_text_small">- {$comments[ix].nb} comments</span> </td> </tr> {/section} </table> {/tikimodule} |