function updateGroupUrls() { printfnq("Updating group URLs...\n"); $group = new User_group(); if ($group->find()) { while ($group->fetch()) { try { printfv("Updating group {$group->nickname}..."); $orig = User_group::getKV('id', $group->id); if (!empty($group->original_logo)) { $group->original_logo = Avatar::url(basename($group->original_logo)); $group->homepage_logo = Avatar::url(basename($group->homepage_logo)); $group->stream_logo = Avatar::url(basename($group->stream_logo)); $group->mini_logo = Avatar::url(basename($group->mini_logo)); } // XXX: this is a hack to see if a group is local or not $localUri = common_local_url('groupbyid', array('id' => $group->id)); if ($group->getUri() != $localUri) { $group->mainpage = common_local_url('showgroup', array('nickname' => $group->nickname)); } $group->update($orig); printfv("DONE."); } catch (Exception $e) { echo "Can't update avatars for group " . $group->nickname . ": " . $e->getMessage(); } } } }
/** * Get the bookmarks file as a string * * Uses the -f or --file parameter to open and read a * a bookmarks file * * @return string Contents of the file */ function getBookmarksFile() { $filename = get_option_value('f', 'file'); if (empty($filename)) { show_help(); exit(1); } if (!file_exists($filename)) { // TRANS: Exception thrown when a file upload cannot be found. // TRANS: %s is the file that could not be found. throw new Exception(sprintf(_m('No such file "%s".'), $filename)); } if (!is_file($filename)) { // TRANS: Exception thrown when a file upload is incorrect. // TRANS: %s is the irregular file. throw new Exception(sprintf(_m('Not a regular file: "%s".'), $filename)); } if (!is_readable($filename)) { // TRANS: Exception thrown when a file upload is not readable. // TRANS: %s is the file that could not be read. throw new Exception(sprintf(_m('File "%s" not readable.'), $filename)); } // TRANS: %s is the filename that contains a backup for a user. printfv(_m('Getting backup from file "%s".') . "\n", $filename); $html = file_get_contents($filename); return $html; }
function cleanupChannels() { $rc = new Realtime_channel(); $rc->selectAdd(); $rc->selectAdd('channel_key'); $rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"'); if ($rc->find()) { $keys = $rc->fetchAll(); foreach ($keys as $key) { $rc = Realtime_channel::staticGet('channel_key', $key); if (!empty($rc)) { printfv("Deleting realtime channel '{$key}'\n"); $rc->delete(); } } } }
function getActivityStreamDocument() { $filename = get_option_value('f', 'file'); if (empty($filename)) { show_help(); exit(1); } if (!file_exists($filename)) { throw new Exception("No such file '{$filename}'."); } if (!is_file($filename)) { throw new Exception("Not a regular file: '{$filename}'."); } if (!is_readable($filename)) { throw new Exception("File '{$filename}' not readable."); } // TRANS: Commandline script output. %s is the filename that contains a backup for a user. printfv(_("Getting backup from file '%s'.") . "\n", $filename); $xml = file_get_contents($filename); return $xml; }
/** * Get the bookmarks file as a string * * Uses the -f or --file parameter to open and read a * a bookmarks file * * @return string Contents of the file */ function getBookmarksFile() { $filename = get_option_value('f', 'file'); if (empty($filename)) { show_help(); exit(1); } if (!file_exists($filename)) { throw new Exception("No such file '{$filename}'."); } if (!is_file($filename)) { throw new Exception("Not a regular file: '{$filename}'."); } if (!is_readable($filename)) { throw new Exception("File '{$filename}' not readable."); } // TRANS: %s is the filename that contains a backup for a user. printfv(_("Getting backup from file '%s'.") . "\n", $filename); $html = file_get_contents($filename); return $html; }
function testUser($filter, $user) { printfnq("Testing user %s\n", $user->nickname); $profile = Profile::getKV('id', $user->id); $str = new ProfileNoticeStream($profile, $profile); $offset = 0; $limit = 100; do { $notice = $str->getNotices($offset, $limit); while ($notice->fetch()) { try { printfv("Testing notice %d...", $notice->id); $result = $filter->test($notice); Spam_score::save($notice, $result); printfv("%s\n", $result->isSpam ? "SPAM" : "HAM"); } catch (Exception $e) { printfnq("ERROR testing notice %d: %s\n", $notice->id, $e->getMessage()); } } $offset += $notice->N; } while ($notice->N > 0); }
function importActivityStream($user, $doc) { $feed = $doc->documentElement; $subjectEl = ActivityUtils::child($feed, Activity::SUBJECT, Activity::SPEC); if (!empty($subjectEl)) { $subject = new ActivityObject($subjectEl); printfv(_("Backup file for user %s (%s)") . "\n", $subject->id, Ostatus_profile::getActivityObjectNickname($subject)); } else { throw new Exception("Feed doesn't have an <activity:subject> element."); } if (is_null($user)) { printfv(_("No user specified; using backup user.") . "\n"); $user = userFromSubject($subject); } $entries = $feed->getElementsByTagNameNS(Activity::ATOM, 'entry'); printfv(_("%d entries in backup.") . "\n", $entries->length); for ($i = $entries->length - 1; $i >= 0; $i--) { try { $entry = $entries->item($i); $activity = new Activity($entry, $feed); switch ($activity->verb) { case ActivityVerb::FOLLOW: subscribeProfile($user, $subject, $activity); break; case ActivityVerb::JOIN: joinGroup($user, $activity); break; case ActivityVerb::POST: postNote($user, $activity); break; default: throw new Exception("Unknown verb: {$activity->verb}"); } } catch (Exception $e) { print $e->getMessage() . "\n"; continue; } } }
function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax) { global $config; $config['site']['dupelimit'] = -1; $n = 0; $g = 0; // Make users first $preuser = min($usercount, 5); for ($j = 0; $j < $preuser; $j++) { printfv("{$i} Creating user {$n}\n"); newUser($n); $n++; } $pregroup = min($groupcount, 3); for ($k = 0; $k < $pregroup; $k++) { printfv("{$i} Creating group {$g}\n"); newGroup($g, $n); $g++; } // # registrations + # notices + # subs $events = $usercount + $groupcount + $usercount * ($noticeavg + $subsavg + $joinsavg); $events -= $preuser; $events -= $pregroup; $ut = $usercount; $gt = $ut + $groupcount; $nt = $gt + $usercount * $noticeavg; $st = $nt + $usercount * $subsavg; $jt = $st + $usercount * $joinsavg; printfv("{$events} events ({$ut}, {$gt}, {$nt}, {$st}, {$jt})\n"); for ($i = 0; $i < $events; $i++) { $e = rand(0, $events); if ($e >= 0 && $e <= $ut) { printfv("{$i} Creating user {$n}\n"); newUser($n); $n++; } else { if ($e > $ut && $e <= $gt) { printfv("{$i} Creating group {$g}\n"); newGroup($g, $n); $g++; } else { if ($e > $gt && $e <= $nt) { printfv("{$i} Making a new notice\n"); newNotice($n, $tagmax); } else { if ($e > $nt && $e <= $st) { printfv("{$i} Making a new subscription\n"); newSub($n); } else { if ($e > $st && $e <= $jt) { printfv("{$i} Making a new group join\n"); newJoin($n, $g); } else { printfv("No event for {$i}!"); } } } } } } }
function initNoticeReshare() { printfnq("Ensuring all reshares have the correct verb and object-type..."); $notice = new Notice(); $notice->whereAdd('repeat_of is not null'); $notice->whereAdd('(verb != "' . ActivityVerb::SHARE . '" OR object_type != "' . ActivityObject::ACTIVITY . '")'); if ($notice->find()) { while ($notice->fetch()) { try { $orig = Notice::staticGet('id', $notice->id); $notice->verb = ActivityVerb::SHARE; $notice->object_type = ActivityObject::ACTIVITY; $notice->update($orig); } catch (Exception $e) { printfv("Error updating verb and object_type for {$notice->id}:" . $e->getMessage()); } } } printfnq("DONE.\n"); }