[geeklog-cvs] geeklog: Introduced function LINKS_getCategorySQL and fixed visi...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Dec 22 05:51:40 EST 2008
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/529a538dbb47
changeset: 6577:529a538dbb47
user: Dirk Haun <dirk at haun-online.de>
date: Sun Dec 21 13:46:59 2008 +0100
description:
Introduced function LINKS_getCategorySQL and fixed visibility of link categories in the Top 10 Links list and site statistics
diffstat:
3 files changed, 87 insertions(+), 11 deletions(-)
plugins/links/functions.inc | 92 ++++++++++++++++++++++++++++++++++++++-----
public_html/docs/history | 4 +
public_html/links/index.php | 2
diffs (165 lines):
diff -r 7c7b50e5a41f -r 529a538dbb47 plugins/links/functions.inc
--- a/plugins/links/functions.inc Sun Dec 21 12:28:09 2008 +0100
+++ b/plugins/links/functions.inc Sun Dec 21 13:46:59 2008 +0100
@@ -220,19 +220,19 @@
* @return array(number of links, number of clicks);
*
*/
-function LINKS_countLinksAndClicks ()
+function LINKS_countLinksAndClicks()
{
global $_TABLES;
- $result = DB_query ("SELECT COUNT(*) AS count,SUM(hits) AS clicks FROM {$_TABLES['links']}" . COM_getPermSQL ());
- $A = DB_fetchArray ($result);
+ $result = DB_query("SELECT COUNT(*) AS count,SUM(hits) AS clicks FROM {$_TABLES['links']}" . COM_getPermSQL() . LINKS_getCategorySQL('AND'));
+ $A = DB_fetchArray($result);
$total_links = $A['count'];
$total_clicks = $A['clicks'];
- if (empty ($total_clicks)) {
+ if (empty($total_clicks)) {
$total_clicks = 0;
}
- return array ($total_links, $total_clicks);
+ return array($total_links, $total_clicks);
}
/**
@@ -248,11 +248,11 @@
{
global $_CONF, $_TABLES, $LANG_LINKS_STATS;
- require_once ($_CONF['path_system'] . 'lib-admin.php');
+ require_once $_CONF['path_system'] . 'lib-admin.php';
$retval = '';
- $result = DB_query ("SELECT lid,url,title,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
+ $result = DB_query("SELECT lid,url,title,hits FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL('AND') . LINKS_getCategorySQL('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$header_arr = array(
@@ -1503,9 +1503,10 @@
$permOp = 'AND';
}
if ($uid > 0) {
- $permSql = COM_getPermSql($permOp, $uid);
+ $permSql = COM_getPermSql($permOp, $uid)
+ . LINKS_getCategorySQL('AND', $uid);
} else {
- $permSql = COM_getPermSql($permOp);
+ $permSql = COM_getPermSql($permOp) . LINKS_getCategorySQL('AND');
}
$sql = "SELECT " . implode(',', $fields)
. " FROM {$_TABLES['links']}" . $where . $permSql;
@@ -1579,4 +1580,77 @@
return $retval;
}
+/**
+* Return SQL expression to check for allowed categories.
+*
+* Creates part of an SQL expression that can be used to only request links
+* from categories to which the user has access to.
+*
+* Note that this function does SQL requests, so you should cache
+* the resulting SQL expression if you need it more than once.
+*
+* @param string $type part of the SQL expr. e.g. 'WHERE', 'AND'
+* @param int $u_id user id or 0 = current user
+* @param string $table table name if ambiguous (e.g. in JOINs)
+* @return string SQL expression string (may be empty)
+* @see COM_getTopicSQL
+*
+*/
+function LINKS_getCategorySQL($type = 'WHERE', $u_id = 0, $table = '')
+{
+ global $_TABLES, $_USER, $_GROUPS;
+
+ $categorysql = ' ' . $type . ' ';
+
+ if (!empty($table)) {
+ $table .= '.';
+ }
+
+ $UserGroups = array();
+ if (($u_id <= 0) || (isset($_USER['uid']) && ($u_id == $_USER['uid']))) {
+ if (!COM_isAnonUser()) {
+ $uid = $_USER['uid'];
+ } else {
+ $uid = 1;
+ }
+ $UserGroups = $_GROUPS;
+ } else {
+ $uid = $u_id;
+ $UserGroups = SEC_getUserGroups($uid);
+ }
+
+ if (empty($UserGroups)) {
+ // this shouldn't really happen, but if it does, handle user
+ // like an anonymous user
+ $uid = 1;
+ }
+
+ if (SEC_inGroup('Root', $uid)) {
+ return '';
+ }
+
+ $parents = array('root');
+ $cids = array();
+
+ do {
+ $result = DB_query("SELECT cid FROM {$_TABLES['linkcategories']}"
+ . COM_getPermSQL('WHERE', $uid) . " AND pid IN ('"
+ . implode("','", $parents) . "')");
+
+ $parents = array();
+ while ($C = DB_fetchArray($result)) {
+ $parents[] = $C['cid'];
+ $cids[] = $C['cid'];
+ }
+ } while (count($parents) > 0);
+
+ if (count($cids) > 0) {
+ $categorysql .= "({$table}cid IN ('" . implode("','", $cids) . "'))";
+ } else {
+ $categorysql .= '0';
+ }
+
+ return $categorysql;
+}
+
?>
diff -r 7c7b50e5a41f -r 529a538dbb47 public_html/docs/history
--- a/public_html/docs/history Sun Dec 21 12:28:09 2008 +0100
+++ b/public_html/docs/history Sun Dec 21 13:46:59 2008 +0100
@@ -1,6 +1,6 @@
Geeklog History/Changes:
-??? ??, 2008 (1.5.2)
+??? ??, 2009 (1.6.0)
------------
- Fixed wrong use of COM_isAnonUser in COM_getPermSQL (since 1.5.0) [Dirk]
@@ -77,6 +77,8 @@
Links plugin
------------
+- Introduced function LINKS_getCategorySQL and fixed visibility of link
+ categories in the Top 10 Links list and site statistics [Dirk]
- Added an option to allow opening external links in a new window (feature
request #0000693). Use with care, please [Dirk]
- Only external links are marked with class="ext-link" [Dirk]
diff -r 7c7b50e5a41f -r 529a538dbb47 public_html/links/index.php
--- a/public_html/links/index.php Sun Dec 21 12:28:09 2008 +0100
+++ b/public_html/links/index.php Sun Dec 21 13:46:59 2008 +0100
@@ -267,7 +267,7 @@
if ($nrows == 0) {
if (($cid == $_LI_CONF['root']) && ($page <= 1) && $_LI_CONF['show_top10']) {
- $result = DB_query ("SELECT lid,url,title,description,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL ('AND') . " ORDER BY hits DESC LIMIT 10");
+ $result = DB_query("SELECT lid,url,title,description,hits,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['links']} WHERE (hits > 0)" . COM_getPermSQL('AND') . LINKS_getCategorySQL('AND') . " ORDER BY hits DESC LIMIT 10");
$nrows = DB_numRows ($result);
if ($nrows > 0) {
$linklist->set_var ('link_details', '');
More information about the geeklog-cvs
mailing list