[xiph-commits] r14910 - in branches/dir.xiph.org: . inc
balbinus at svn.xiph.org
balbinus at svn.xiph.org
Sun May 18 05:47:31 PDT 2008
Author: balbinus
Date: 2008-05-18 05:47:31 -0700 (Sun, 18 May 2008)
New Revision: 14910
Modified:
branches/dir.xiph.org/by_format.php
branches/dir.xiph.org/inc/class.server.php
branches/dir.xiph.org/inc/lib.statslog.php
branches/dir.xiph.org/listen.php
Log:
Now log the searches too (first part).
Modified: branches/dir.xiph.org/by_format.php
===================================================================
--- branches/dir.xiph.org/by_format.php 2008-05-18 10:34:59 UTC (rev 14909)
+++ branches/dir.xiph.org/by_format.php 2008-05-18 12:47:31 UTC (rev 14910)
@@ -18,6 +18,17 @@
$tpl->assign('search_keyword', str_replace('_', ' ', $search_string));
$search_string = preg_replace('/[^A-Za-z0-9+_\-]/', '_', $search_string);
$search_string_hash = jenkins_hash_hex($search_string);
+
+ // Logging
+ try
+ {
+ statsLog::keywordsSearched(statsLog::SEARCH_TYPE_FORMAT, $search_string);
+ }
+ catch (SQLException $e)
+ {
+ var_dump($e);
+ // Do nothing, it's just logging after all...
+ }
// Get the data from the Memcache server
if (($results = $memcache->get(ENVIRONMENT.'_search_format_'.$search_string_hash)) === false)
Modified: branches/dir.xiph.org/inc/class.server.php
===================================================================
--- branches/dir.xiph.org/inc/class.server.php 2008-05-18 10:34:59 UTC (rev 14909)
+++ branches/dir.xiph.org/inc/class.server.php 2008-05-18 12:47:31 UTC (rev 14910)
@@ -123,54 +123,56 @@
public static function retrieveByMountpointId($mp_id, $load_servers = true)
{
// MySQL Connection
- $db = DirXiphOrgDBC::getInstance();
-
- // Memcache connection
- $mc = DirXiphOrgMCC::getInstance();
-
- // Try to get from cache
- $key = self::getListCacheKey('serversbympid_'.$mp_id);
- $servers = $mc->get($key);
- if (!$servers)
- {
- // Cache miss, hit the database
- try
- {
- $sql = "SELECT `id` FROM `%s` WHERE `mountpoint_id` = %d;";
- $sql = sprintf($sql, self::$table_name, $mp_id);
- $res = $db->selectQuery($sql);
-
- $servers = array();
- while (!$res->endOf())
- {
- $servers[] = intval($res->current('id'));
- $res->next();
- }
-
- // Save into cache
- $mc->set($key, $servers, false, self::$cache_expiration);
- }
- catch (SQLNoResultException $e)
- {
- return false;
- }
- }
-
- // If we've been asked to load the servers data, do it
- $data = array();
- if ($load_servers)
- {
+ $db = DirXiphOrgDBC::getInstance();
+
+ // Memcache connection
+ $mc = DirXiphOrgMCC::getInstance();
+
+ // Try to get from cache
+ $key = self::getListCacheKey('serversbympid_'.$mp_id);
+ $servers = $mc->get($key);
+ if (!$servers)
+ {
+ // Cache miss, hit the database
+ try
+ {
+ $sql = "SELECT `id` FROM `%s` WHERE `mountpoint_id` = %d;";
+ $sql = sprintf($sql, self::$table_name, $mp_id);
+ $res = $db->selectQuery($sql);
+
+ $servers = array();
+ while (!$res->endOf())
+ {
+ $servers[] = intval($res->current('id'));
+ $res->next();
+ }
+
+ // Save into cache
+ $mc->set($key, $servers, false, self::$cache_expiration);
+ }
+ catch (SQLNoResultException $e)
+ {
+ return false;
+ }
+ }
+
+ // If we've been asked to load the servers data, do it
+ $data = array();
+ if ($load_servers)
+ {
foreach ($servers as $s)
{
- $data[] = self::retrieveByPk($s);
- }
- }
- else
- {
- $data =& $servers;
- }
-
- return $data;
+ $server = self::retrieveByPk($s);
+ if ($server instanceOf Server)
+ $data[] = $server;
+ }
+ }
+ else
+ {
+ $data =& $servers;
+ }
+
+ return $data;
}
/**
Modified: branches/dir.xiph.org/inc/lib.statslog.php
===================================================================
--- branches/dir.xiph.org/inc/lib.statslog.php 2008-05-18 10:34:59 UTC (rev 14909)
+++ branches/dir.xiph.org/inc/lib.statslog.php 2008-05-18 12:47:31 UTC (rev 14910)
@@ -2,6 +2,10 @@
class statsLog
{
+ const SEARCH_TYPE_FREEFORM = 1;
+ const SEARCH_TYPE_GENRE = 2;
+ const SEARCH_TYPE_FORMAT = 3;
+
public static function playlistAccessed($mountpoint_id, $stream_name)
{
$db = DirXiphOrgLogDBC::getInstance();
@@ -17,6 +21,21 @@
$db->escape($ip));
$db->query($sql);
}
+
+ public static function keywordsSearched($search_type, $search_keywords)
+ {
+ $db = DirXiphOrgLogDBC::getInstance();
+
+ $ip = utils::getRealIp();
+ $ip = $ip !== false ? $ip : '127.0.0.1';
+
+ $db = DirXiphOrgLogDBC::getInstance();
+ $sql = "INSERT INTO `search_log_%s` (`search_keywords`, `search_type`, `searched_by`) "
+ ."VALUES ('%s', %d, INET_ATON('%s'));";
+ $sql = sprintf($sql, date('Ymd'), $db->escape($search_keywords),
+ intval($search_type), $db->escape($ip));
+ $db->query($sql);
+ }
}
?>
Modified: branches/dir.xiph.org/listen.php
===================================================================
--- branches/dir.xiph.org/listen.php 2008-05-18 10:34:59 UTC (rev 14909)
+++ branches/dir.xiph.org/listen.php 2008-05-18 12:47:31 UTC (rev 14910)
@@ -66,11 +66,8 @@
// Inclusions
include_once(dirname(__FILE__).'/inc/prepend.php');
-// Memcache connection
-$memcache = DirXiphOrgMCC::getInstance();
-
// Get the servers associated with this mountpoint
-$servers = Server::retrieveByMountpointId($this->mountpoint_id, false);
+$servers = Server::retrieveByMountpointId($p_id);
// Build the playlist
$playlist = array();
More information about the commits
mailing list