function smd_lately($atts, $thing=NULL) { global $prefs, $thisarticle, $permlink_mode; // Check logging is on if ( $prefs['logging'] != 'all') { trigger_error(smd_rv_gTxt('logging_enabled'), E_USER_NOTICE); return; } extract(lAtts(array( 'by' => 'SMD_CURRENT', // Default is the IP address of the current visitor. Can be empty for 'all' visitors 'section' => '', 'show_current' => 0, 'form' => '', 'limit' => 10, 'sort' => 'time desc', 'wraptag' => '', 'break' => 'br', 'class' => '__FUNCTION__', 'label' => '', 'labeltag' => '', 'debug' => 0, ), $atts)); // Sanitize sort options $sortBits = do_list($sort, " "); if (!isset($sortBits[1]) || !in_array($sortBits[1], array('desc', 'asc'))) { $sortBits[1] = 'desc'; $sort = join(" ", $sortBits); } // IP address clause $ip = ''; if ($by == 'SMD_CURRENT') { $ip = remote_addr(); if ($ip) { $ip = " AND ip='".doSlash($ip)."'"; } } else if ($by == 'SMD_ALL') { $by = ''; } // Make sure we don't include the current article // Note the regexp is anchored to the end with a $ $thisicle = ''; if (isset($thisarticle)) { if (!$show_current) { $urltitle = $thisarticle['url_title']; $thisicle = " AND page NOT REGEXP '$urltitle$'"; } } // Filter out article_list pages and other (un)desirables $rules = array( "page NOT REGEXP '^/$'", // Goodbye front page "page NOT REGEXP 'q='", // Goodbye searches "page NOT REGEXP 'c='", // Goodbye cat lists "page NOT REGEXP 'category='", "page NOT REGEXP '^/category/'", "page NOT REGEXP 'author='", "page NOT REGEXP '^/author/'", ); if ($section) { $section = do_list($section); $subrule = array(); foreach ($section as $sec) { if ($permlink_mode == 'messy') { $subrule[] = "page REGEXP 's=$sec'"; } else { $subrule[] = "page REGEXP '^/$sec' AND page NOT REGEXP '^/$sec/?$'"; } } $subrule = '(' . join(' OR ', $subrule) . ')'; $rules[] = $subrule; } else { // Exclude any rows that just contain the section (i.e. article list pages) $allSecs = safe_column('name', 'txp_section', "1=1", $debug); $rules[] = "page NOT REGEXP '^/(" . join("|", $allSecs) . ")/?$'"; } $rules = ' AND ' . join(' AND ', $rules); $query = 'SELECT count(page) as popularity, page, MAX(time) as time FROM '.PFX.'txp_log WHERE 1=1'.$ip.$thisicle.$rules.' AND status = 200 GROUP BY page ORDER BY '.$sort; $rs = getRows($query, $debug); if ($debug > 1) { dmp($rs); } // Loop until limit reached $count = 0; $out = array(); if ($rs) { foreach ($rs as $row) { if ($limit > 0 && is_numeric($limit) && $count == $limit) break; $urlparts = explode('/', $row['page']); $darticle = safe_row('*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod', 'textpattern', "url_title='".$urlparts[count($urlparts)-1]."'"); article_push(); populateArticleData($darticle); $out[] = ($thing) ? parse($thing) : (($form) ? parse_form($form) : href($darticle['Title'], permlinkurl($darticle))); article_pop(); $count++; } } return ($out) ? doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class) : ''; } // ------------------------ // Plugin-specific replacement strings - localise as required function smd_rv_gTxt($what, $atts = array()) { $lang = array( 'logging_enabled' => 'Logging must be set to "All hits" in Basic Pefs.', ); return strtr($lang[$what], $atts); }