From 0e93b638b5fe5a3f087c25a48dcb1bac032e400d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 18 Mar 2009 16:34:41 -0400 Subject: fix bug in profile list owner check --- lib/profilelist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/profilelist.php b/lib/profilelist.php index 766189ab4..bd9b51958 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -89,7 +89,7 @@ class ProfileList extends Widget 'id' => 'profile-' . $this->profile->id)); $user = common_current_user(); - $is_own = !is_null($user) && isset($this->user) && ($user->id === $this->user->id); + $is_own = !is_null($user) && isset($this->owner) && ($user->id === $this->owner->id); $this->out->elementStart('div', 'entity_profile vcard'); -- cgit v1.2.3-54-g00ecf From 5dc913f58951815fcaa246e675ff7d30ad93f633 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 19 Mar 2009 09:21:50 -0400 Subject: ping handler returns proper boolean response The ping queue handler wasn't returning a true value -- filling up the queue with ping requests. It now returns a true value. --- lib/ping.php | 77 ++++++++++++++++++++++++++++++++------------ scripts/pingqueuehandler.php | 4 +-- 2 files changed, 58 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/ping.php b/lib/ping.php index 32c0b9806..2cbec2f21 100644 --- a/lib/ping.php +++ b/lib/ping.php @@ -1,7 +1,7 @@ is_local) { - return; + return true; } - + # Array of servers, URL => type $notify = common_config('ping', 'notify'); $profile = $notice->getProfile(); $tags = ping_notice_tags($notice); - + foreach ($notify as $notify_url => $type) { switch ($type) { case 'xmlrpc': case 'extended': $req = xmlrpc_encode_request('weblogUpdates.ping', array($profile->nickname, # site name - common_local_url('showstream', + common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), - common_local_url('userrss', + common_local_url('userrss', array('nickname' => $profile->nickname)), $tags)); - - # We re-use this tool's fetcher, since it's pretty good - - $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); - if (!$fetcher) { - common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__); - return false; - } - - $result = $fetcher->post($notify_url, - $req); - + $context = stream_context_create(array('http' => array('method' => "POST", + 'header' => + "Content-Type: text/xml\r\n". + "User-Agent: Laconica/".LACONICA_VERSION."\r\n", + 'content' => $request))); + $file = file_get_contents($notify_url, false, $context); + $response = xmlrpc_decode($file); + if (xmlrpc_is_fault($response)) { + common_log(LOG_WARNING, + "XML-RPC error for ping ($notify_url, $notice->id) ". + "$response[faultString] ($response[faultCode])"); + } else { + common_log(LOG_INFO, + "Ping success for $notify_url $notice->id"); + } + break; + case 'get': - case 'post': + case 'post': + $args = array('name' => $profile->nickname, + 'url' => common_local_url('showstream', + array('nickname' => $profile->nickname)), + 'changesURL' => common_local_url('userrss', + array('nickname' => $profile->nickname))); + + $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); + + if ($type === 'get') { + $result = $fetcher->get($notify_url . '?' . http_build_query($args), + array('User-Agent: Laconica/'.LACONICA_VERSION)); + } else { + $result = $fetcher->post($notify_url, + http_build_query($args), + array('User-Agent: Laconica/'.LACONICA_VERSION)); + } + if ($result->status != '200') { + common_log(LOG_WARNING, + "Ping error for '$notify_url' ($notice->id): ". + "$result->body"); + } else { + common_log(LOG_INFO, + "Ping success for '$notify_url' ($notice->id): ". + "'$result->body'"); + } + break; + default: common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type); - } + } } + + return true; } - + function ping_notice_tags($notice) { $tag = new Notice_tag(); $tag->notice_id = $notice->id; diff --git a/scripts/pingqueuehandler.php b/scripts/pingqueuehandler.php index 55a266e4a..ada6ecdba 100644 --- a/scripts/pingqueuehandler.php +++ b/scripts/pingqueuehandler.php @@ -34,7 +34,7 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); class PingQueueHandler extends QueueHandler { - + function transport() { return 'ping'; } @@ -47,7 +47,7 @@ class PingQueueHandler extends QueueHandler { function handle_notice($notice) { return ping_broadcast_notice($notice); } - + function finish() { } } -- cgit v1.2.3-54-g00ecf From d1b2a9d7087ecc171f941755b4c3a420cd202842 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 19 Mar 2009 11:01:58 -0400 Subject: Somewhat better behaviour with mixed caps in search Deal somewhat better with mixed caps in people and notice search. --- actions/groupsearch.php | 11 +++-------- actions/noticesearch.php | 2 +- actions/noticesearchrss.php | 3 --- actions/peoplesearch.php | 6 +++--- lib/search_engines.php | 34 +++++++++++++++++++++++++--------- 5 files changed, 32 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/actions/groupsearch.php b/actions/groupsearch.php index 9b0026db9..109a53ce1 100644 --- a/actions/groupsearch.php +++ b/actions/groupsearch.php @@ -1,9 +1,4 @@ terms = array_map('preg_quote', + $this->terms = array_map('preg_quote', array_map('htmlspecialchars', $terms)); $this->pattern = '/('.implode('|',$terms).')/i'; } - + function highlight($text) { return preg_replace($this->pattern, '\\1', htmlspecialchars($text)); diff --git a/actions/noticesearch.php b/actions/noticesearch.php index 83e59dd9a..eb4a072de 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -103,7 +103,7 @@ class NoticesearchAction extends SearchAction function showResults($q, $page) { $notice = new Notice(); - $q = strtolower($q); + $search_engine = $notice->getSearchEngine('identica_notices'); $search_engine->set_sort_mode('chron'); // Ask for an extra to see if there's more. diff --git a/actions/noticesearchrss.php b/actions/noticesearchrss.php index 0f98ed04b..ba5276d06 100644 --- a/actions/noticesearchrss.php +++ b/actions/noticesearchrss.php @@ -62,9 +62,6 @@ class NoticesearchrssAction extends Rss10Action $notice = new Notice(); - # lcase it for comparison - $q = strtolower($q); - $search_engine = $notice->getSearchEngine('identica_notices'); $search_engine->set_sort_mode('chron'); diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php index 14177fcf0..9e515ade1 100644 --- a/actions/peoplesearch.php +++ b/actions/peoplesearch.php @@ -63,13 +63,13 @@ class PeoplesearchAction extends SearchAction $profile = new Profile(); - # lcase it for comparison - $q = strtolower($q); + // lcase it for comparison + // $q = strtolower($q); $search_engine = $profile->getSearchEngine('identica_people'); $search_engine->set_sort_mode('chron'); - # Ask for an extra to see if there's more. + // Ask for an extra to see if there's more. $search_engine->limit((($page-1)*PROFILES_PER_PAGE), PROFILES_PER_PAGE + 1); if (false === $search_engine->query($q)) { $cnt = 0; diff --git a/lib/search_engines.php b/lib/search_engines.php index 559107910..7b9dbb618 100644 --- a/lib/search_engines.php +++ b/lib/search_engines.php @@ -74,7 +74,7 @@ class SphinxSearch extends SearchEngine { //FIXME without LARGEST_POSSIBLE, the most recent results aren't returned // this probably has a large impact on performance - $LARGEST_POSSIBLE = 1e6; + $LARGEST_POSSIBLE = 1e6; if ($rss) { $this->sphinx->setLimits($offset, $count, $count, $LARGEST_POSSIBLE); @@ -109,12 +109,25 @@ class MySQLSearch extends SearchEngine { function query($q) { - if ('identica_people' === $this->table) - return $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . - 'against (\''.addslashes($q).'\')'); - if ('identica_notices' === $this->table) - return $this->target->whereAdd('MATCH(content) ' . - 'against (\''.addslashes($q).'\')'); + if ('identica_people' === $this->table) { + $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . + 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)'); + if (strtolower($q) != $q) { + $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . + 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR'); + } + return true; + } else if ('identica_notices' === $this->table) { + $this->target->whereAdd('MATCH(content) ' . + 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)'); + if (strtolower($q) != $q) { + $this->target->whereAdd('MATCH(content) ' . + 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR'); + } + return true; + } else { + throw new ServerException('Unknown table: ' . $this->table); + } } } @@ -122,10 +135,13 @@ class PGSearch extends SearchEngine { function query($q) { - if ('identica_people' === $this->table) + if ('identica_people' === $this->table) { return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')'); - if ('identica_notices' === $this->table) + } else if ('identica_notices' === $this->table) { return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')'); + } else { + throw new ServerException('Unknown table: ' . $this->table); + } } } -- cgit v1.2.3-54-g00ecf