/** * Temporary hack to set up the compound index, since we can't do * it yet through regular Schema interface. (Coming for 1.0...) * * @param Schema $schema * @return void */ static function fixIndexes($schema) { try { // @fixme this won't be a unique index... SIGH $schema->createIndex('profile_detail', array('profile_id', 'field', 'field_index')); } catch (Exception $e) { common_log(LOG_ERR, __METHOD__ . ': ' . $e->getMessage()); } }
/** * Will call events as close as it gets to one hour. Event handlers * which use this MUST be as quick as possible, maybe only adding a * queue item to be handled later or something. Otherwise execution * will timeout for PHP - or at least cause unnecessary delays for * the unlucky user who visits the site exactly at one of these events. */ public function callTimedEvents() { $timers = array('minutely' => 60, 'hourly' => 3600, 'daily' => 86400, 'weekly' => 604800); foreach ($timers as $name => $interval) { $run = false; $lastrun = new Config(); $lastrun->section = 'cron'; $lastrun->setting = 'last_' . $name; $found = $lastrun->find(true); if (!$found) { $lastrun->value = time(); if ($lastrun->insert() === false) { common_log(LOG_WARNING, "Could not save 'cron' setting '{$name}'"); continue; } $run = true; } elseif ($lastrun->value < time() - $interval) { $orig = clone $lastrun; $lastrun->value = time(); $lastrun->update($orig); $run = true; } if ($run === true) { // such as CronHourly, CronDaily, CronWeekly Event::handle('Cron' . ucfirst($name)); } } }
/** * logs and then displays error messages * * @return void */ function handleError($error) { if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) { return; } $logmsg = "PEAR error: " . $error->getMessage(); if (common_config('site', 'logdebug')) { $logmsg .= " : " . $error->getDebugInfo(); } // DB queries often end up with a lot of newlines; merge to a single line // for easier grepability... $logmsg = str_replace("\n", " ", $logmsg); common_log(LOG_ERR, $logmsg); // @fixme backtrace output should be consistent with exception handling if (common_config('site', 'logdebug')) { $bt = $error->getBacktrace(); foreach ($bt as $n => $line) { common_log(LOG_ERR, formatBacktraceLine($n, $line)); } } if ($error instanceof DB_DataObject_Error || $error instanceof DB_Error) { $msg = sprintf(_('The database for %s isn\'t responding correctly, ' . 'so the site won\'t work properly. ' . 'The site admins probably know about the problem, ' . 'but you can contact them at %s to make sure. ' . 'Otherwise, wait a few minutes and try again.'), common_config('site', 'name'), common_config('site', 'email')); } else { $msg = _('An important error occured, probably related to email setup. ' . 'Check logfiles for more info..'); } $dac = new DBErrorAction($msg, 500); $dac->showPage(); exit(-1); }
static function fromUpload($param = 'upload') { switch ($_FILES[$param]['error']) { case UPLOAD_ERR_OK: // success, jump out break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: throw new Exception(sprintf(_('That file is too big. The maximum file size is %s.'), ImageFile::maxFileSize())); return; case UPLOAD_ERR_PARTIAL: @unlink($_FILES[$param]['tmp_name']); throw new Exception(_('Partial upload.')); return; case UPLOAD_ERR_NO_FILE: // No file; probably just a non-AJAX submission. return; default: common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " . $_FILES[$param]['error']); throw new Exception(_('System error uploading file.')); return; } $info = @getimagesize($_FILES[$param]['tmp_name']); if (!$info) { @unlink($_FILES[$param]['tmp_name']); throw new Exception(_('Not an image or corrupt file.')); return; } return new ImageFile(null, $_FILES[$param]['tmp_name']); }
function showNotice($notice) { $profile = $notice->getProfile(); if (empty($profile)) { common_log(LOG_WARNING, sprintf("Notice %d has no profile", $notice->id)); return; } $this->out->elementStart('li', 'hentry notice'); $this->out->elementStart('div', 'entry-title'); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); $this->out->elementStart('span', 'vcard author'); $this->out->elementStart('a', array('title' => $profile->fullname ? $profile->fullname : $profile->nickname, 'href' => $profile->profileurl, 'class' => 'url')); $this->out->element('img', array('src' => $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE), 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', 'alt' => $profile->fullname ? $profile->fullname : $profile->nickname)); $this->out->text(' '); $this->out->element('span', 'fn nickname', $profile->nickname); $this->out->elementEnd('a'); $this->out->elementEnd('span'); $this->out->elementStart('p', 'entry-content'); $this->out->raw($notice->rendered); $this->out->elementEnd('p'); $this->out->elementStart('div', 'entry_content'); class_exists('NoticeList'); $nli = new NoticeListItem($notice, $this->out); $nli->showNoticeLink(); $this->out->elementEnd('div'); if (!empty($notice->value)) { $this->out->elementStart('p'); $this->out->text($notice->value); $this->out->elementEnd('p'); } $this->out->elementEnd('div'); $this->out->elementEnd('li'); }
/** * logs and then displays error messages * * @return void */ function handleError($error) { if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) { return; } $logmsg = "PEAR error: " . $error->getMessage(); if (common_config('site', 'logdebug')) { $logmsg .= " : " . $error->getDebugInfo(); } // DB queries often end up with a lot of newlines; merge to a single line // for easier grepability... $logmsg = str_replace("\n", " ", $logmsg); common_log(LOG_ERR, $logmsg); // @fixme backtrace output should be consistent with exception handling if (common_config('site', 'logdebug')) { $bt = $error->getBacktrace(); foreach ($bt as $n => $line) { common_log(LOG_ERR, formatBacktraceLine($n, $line)); } } if ($error instanceof DB_DataObject_Error || $error instanceof DB_Error) { $msg = sprintf(_('数据库维护中,请稍后再访问'), common_config('site', 'name'), common_config('site', 'email')); } else { $msg = _('网站维护中,请稍后再访问'); } $dac = new DBErrorAction($msg, 500); $dac->showPage(); exit(-1); }
static function top($transport) { $qi = new Queue_item(); $qi->transport = $transport; $qi->orderBy('created'); $qi->whereAdd('claimed is null'); $qi->limit(1); $cnt = $qi->find(true); if ($cnt) { # XXX: potential race condition # can we force it to only update if claimed is still null # (or old)? common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport); $orig = clone $qi; $qi->claimed = common_sql_now(); $result = $qi->update($orig); if ($result) { common_log(LOG_INFO, 'claim succeeded.'); return $qi; } else { common_log(LOG_INFO, 'claim failed.'); } } $qi = null; return null; }
function setNotify($user, $notify) { global $_PEAR; $user_im_prefs = new User_im_prefs(); $user_im_prefs->transport = $this->imPlugin->transport; $user_im_prefs->user_id = $user->id; if ($user_im_prefs->find() && $user_im_prefs->fetch()) { if ($user_im_prefs->notify == $notify) { //notify is already set the way they want return true; } else { $original = clone $user_im_prefs; $user_im_prefs->notify = $notify; $result = $user_im_prefs->update($original); if (!$result) { $last_error =& $_PEAR->getStaticProperty('DB_DataObject', 'lastError'); common_log(LOG_ERR, 'Could not set notify flag to ' . $notify . ' for user ' . common_log_objstring($user) . ' on transport ' . $this->imPlugin->transport . ' : ' . $last_error->message); return false; } else { common_log(LOG_INFO, 'User ' . $user->nickname . ' set notify flag to ' . $notify); return true; } } } else { common_log(LOG_ERR, 'Could not set notify flag to ' . $notify . ' for user ' . common_log_objstring($user) . ' on transport ' . $this->imPlugin->transport . ' : user preference does not exist'); return false; } }
public function onStartCheckPassword($nickname, $password, &$authenticatedUser) { if (common_is_email($nickname)) { $this->unauthed_user = User::getKV('email', common_canonical_email($nickname)); } else { $this->unauthed_user = User::getKV('nickname', Nickname::normalize($nickname)); } if (!$this->unauthed_user instanceof User) { // Unknown username continue processing StartCheckPassword (maybe uninitialized LDAP user etc?) return true; } $this->failed_attempts = (int) $this->unauthed_user->getPref(self::FAILED_LOGIN_IP_SECTION, $this->client_ip); switch (true) { case $this->failed_attempts >= 5: common_log(LOG_WARNING, sprintf('Multiple failed login attempts for user %s from IP %s - brute force attack?', $this->unauthed_user->getNickname(), $this->client_ip)); // 5 seconds is a good max waiting time anyway... sleep($this->failed_attempts % 5 + 1); break; case $this->failed_attempts > 0: common_debug(sprintf('Previously failed login on user %s from IP %s - sleeping %u seconds.', $this->unauthed_user->getNickname(), $this->client_ip, $this->failed_attempts)); sleep($this->failed_attempts); break; default: // No sleeping if it's our first failed attempt. } return true; }
function handle($args) { parent::handle($args); $secret = common_config('facebook', 'secret'); $sig = ''; ksort($_POST); foreach ($_POST as $key => $val) { if (substr($key, 0, 7) == 'fb_sig_') { $sig .= substr($key, 7) . '=' . $val; } } $sig .= $secret; $verify = md5($sig); if ($verify == $this->arg('fb_sig')) { $flink = Foreign_link::getByForeignID($this->arg('fb_sig_user'), 2); common_debug("Removing foreign link to Facebook - local user ID: {$flink->user_id}, Facebook ID: {$flink->foreign_id}"); $result = $flink->delete(); if (!$result) { common_log_db_error($flink, 'DELETE', __FILE__); $this->serverError(_('Couldn\'t remove Facebook user.')); return; } } else { # Someone bad tried to remove facebook link? common_log(LOG_ERR, "Someone from {$_SERVER['REMOTE_ADDR']} " . 'unsuccessfully tried to remove a foreign link to Facebook!'); } }
function showJsonTimeline($notice, $original) { $this->initDocument('json'); $statuses = array(); $originals = array(); if (is_array($original)) { $original = new ArrayWrapper($original); } while ($original->fetch()) { try { $twitter_status = $this->twitterStatusArray($original); $originals[$twitter_status['id']] = $twitter_status; //array_push($originals, $twitter_status); } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); continue; } } if (is_array($notice)) { $notice = new ArrayWrapper($notice); } while ($notice->fetch()) { try { $twitter_status = $this->twitterStatusArray($notice); $twitter_status['in_reply_to_status'] = $originals[$twitter_status['in_reply_to_status_id']]; array_push($statuses, $twitter_status); } catch (Exception $e) { common_log(LOG_ERR, $e->getMessage()); continue; } } $this->showJsonObjects($statuses); $this->endDocument('json'); }
/** * Handler method * * @param array $args is ignored since it's now passed in in prepare() */ function handle($args) { parent::handle($args); $data = $this->facebook->getSignedRequest(); if (isset($data['user_id'])) { $fbuid = $data['user_id']; $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); $user = $flink->getUser(); // Remove the link to Facebook $result = $flink->delete(); if (!$result) { common_log_db_error($flink, 'DELETE', __FILE__); common_log(LOG_WARNING, sprintf('Unable to delete Facebook foreign link ' . 'for %s (%d), fbuid %d', $user->nickname, $user->id, $fbuid), __FILE__); return; } common_log(LOG_INFO, sprintf('Facebook callback: %s (%d), fbuid %d has deauthorized ' . 'the Facebook application.', $user->nickname, $user->id, $fbuid), __FILE__); // Warn the user about being locked out of their account // if we can. if (empty($user->password) && !empty($user->email)) { Facebookclient::emailWarn($user); } else { common_log(LOG_WARNING, sprintf('%s (%d), fbuid %d has deauthorized his/her Facebook ' . 'connection but hasn\'t set a password so s/he ' . 'is locked out.', $user->nickname, $user->id, $fbuid), __FILE__); } } else { if (!empty($data)) { common_log(LOG_WARNING, sprintf('Facebook called the deauthorize callback ' . ' but didn\'t provide a user ID.'), __FILE__); } else { // It probably wasn't Facebook that hit this action, // so redirect to the public timeline common_redirect(common_local_url('public'), 303); } } }
function show() { $this->out->elementStart('div', array('id' => 'notices_primary')); // TRANS: Header on conversation page. Hidden by default (h2). $this->out->element('h2', null, _('Notices')); $this->out->elementStart('ol', array('class' => 'notices xoxo')); $cnt = 0; while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { if (!empty($this->notice->reply_to)) { continue; } $cnt++; if ($cnt > NOTICES_PER_PAGE) { break; } try { $this->showNoticePlus($this->newListItem($this->notice)); } catch (Exception $e) { // we log exceptions and continue print "ERROR!" . $e->getMessage(); common_log(LOG_ERR, $e->getMessage()); continue; } } $this->out->elementEnd('ol'); $this->out->elementEnd('div'); return $cnt; }
/** * Sign and post the given Atom entry as a Salmon message. * * Side effects: may generate a keypair on-demand for the given user, * which can be very slow on some systems. * * @param string $endpoint_uri * @param string $xml string representation of payload * @param Profile $actor local user profile whose keys to sign with * @return boolean success */ public function post($endpoint_uri, $xml, $actor) { if (empty($endpoint_uri)) { return false; } foreach ($this->formatClasses() as $class) { try { $envelope = $this->createMagicEnv($xml, $actor, $class); } catch (Exception $e) { common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage()); return false; } $headers = array('Content-Type: application/magic-envelope+xml'); try { $client = new HTTPClient(); $client->setBody($envelope); $response = $client->post($endpoint_uri, $headers); } catch (HTTP_Request2_Exception $e) { common_log(LOG_ERR, "Salmon ({$class}) post to {$endpoint_uri} failed: " . $e->getMessage()); continue; } if ($response->getStatus() != 200) { common_log(LOG_ERR, "Salmon ({$class}) at {$endpoint_uri} returned status " . $response->getStatus() . ': ' . $response->getBody()); continue; } // Success! return true; } return false; }
function onStartLoginAction($action, $user) { $rawotp = $action->trimmed('otp'); //may want to parse later? $otp = Auth_Yubico::parsePasswordOTP($rawotp); if (!is_array($otp)) { common_log(LOG_ERR, 'Yubikey:: Could not parse One Time Passcode.'); $action->showForm('Could not parse Yubikey One Time Passcode.'); return false; } $identity = $otp['prefix']; $key = $otp['otp']; common_log(LOG_DEBUG, 'User: '******' OTP: ' . $key . ', prefix: ' . $identity); if (!User_yubikey::verifyYubikeyID($user->id, $identity)) { common_log(LOG_DEBUG, 'Yubikey:: User: '******' does not have a Yubikey on record.'); // Return true because they dont have a yubikey associated and can continue return true; } if ($this->_checkYubikeyOTP($key)) { return true; } else { $action->showForm(_('Yubikey authentication failed.')); return false; } }
function onEndUserRegister(&$profile, &$user) { $profile->sandbox(); if ($this->debug) { common_log(LOG_WARNING, "AutoSandbox: sandboxed of {$user->nickname}"); } }
/** * @param mixed $transports name of a single queue or array of queues to pull from * If not specified, checks all queues in the system. */ static function top($transports = null) { $qi = new Queue_item(); if ($transports) { if (is_array($transports)) { // @fixme use safer escaping $list = implode("','", array_map(array($qi, 'escape'), $transports)); $qi->whereAdd("transport in ('{$list}')"); } else { $qi->transport = $transports; } } $qi->orderBy('created'); $qi->whereAdd('claimed is null'); $qi->limit(1); $cnt = $qi->find(true); if ($cnt) { // XXX: potential race condition // can we force it to only update if claimed is still null // (or old)? common_log(LOG_INFO, 'claiming queue item id = ' . $qi->id . ' for transport ' . $qi->transport); $orig = clone $qi; $qi->claimed = common_sql_now(); $result = $qi->update($orig); if ($result) { common_log(LOG_INFO, 'claim succeeded.'); return $qi; } else { common_log(LOG_INFO, 'claim failed.'); } } $qi = null; return null; }
function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice instanceof Notice) { try { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to attentions for user " . $flink->user_id); try { Attention::saveNew($notice, $flink->getProfile()); } catch (Exception $e) { // Log the exception, but make sure we don't bail out, we // still have a queue item to remove here-after. common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " . $e->getMessage()); } } catch (NoResultException $e) { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver); } } return true; }
/** * Class handler. * * @param array $args array of arguments * * @return void */ function handle($args) { parent::handle($args); $datastore = new ApiStatusNetOAuthDataStore(); $server = new OAuthServer($datastore); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $server->add_signature_method($hmac_method); $atok = $app = null; // XXX: Insist that oauth_token and oauth_verifier be populated? // Spec doesn't say they MUST be. try { $req = OAuthRequest::from_request(); $this->reqToken = $req->get_parameter('oauth_token'); $this->verifier = $req->get_parameter('oauth_verifier'); $app = $datastore->getAppByRequestToken($this->reqToken); $atok = $server->fetch_access_token($req); } catch (Exception $e) { common_log(LOG_WARNING, 'API OAuthException - ' . $e->getMessage()); common_debug(var_export($req, true)); $code = $e->getCode(); $this->clientError($e->getMessage(), empty($code) ? 401 : $code, 'text'); return; } if (empty($atok)) { // Token exchange failed -- log it $msg = sprintf('API OAuth - Failure exchanging OAuth request token for access token, ' . 'request token = %s, verifier = %s', $this->reqToken, $this->verifier); common_log(LOG_WARNING, $msg); // TRANS: Client error given from the OAuth API when the request token or verifier is invalid. $this->clientError(_('Invalid request token or verifier.'), 400, 'text'); } else { common_log(LOG_INFO, sprintf("Issued access token '%s' for application %d (%s).", $atok->key, $app->id, $app->name)); $this->showAccessToken($atok); } }
function showContent() { $notice = $this->nli->notice; $out = $this->nli->out; $nb = Bookmark::getByNotice($notice); if (empty($nb)) { common_log(LOG_ERR, "No bookmark for notice {$notice->id}"); parent::showContent(); return; } else { if (empty($nb->url)) { common_log(LOG_ERR, "No url for bookmark {$nb->id} for notice {$notice->id}"); parent::showContent(); return; } } $profile = $notice->getProfile(); $out->elementStart('p', array('class' => 'entry-content')); // Whether to nofollow $attrs = array('href' => $nb->url, 'class' => 'bookmark-title'); $nf = common_config('nofollow', 'external'); if ($nf == 'never' || ($nf == 'sometimes' and $out instanceof ShowstreamAction)) { $attrs['rel'] = 'external'; } else { $attrs['rel'] = 'nofollow external'; } $out->elementStart('h3'); $out->element('a', $attrs, $nb->title); $out->elementEnd('h3'); // Replies look like "for:" tags $replies = $notice->getReplies(); $tags = $notice->getTags(); if (!empty($replies) || !empty($tags)) { $out->elementStart('ul', array('class' => 'bookmark-tags')); foreach ($replies as $reply) { $other = Profile::staticGet('id', $reply); if (!empty($other)) { $out->elementStart('li'); $out->element('a', array('rel' => 'tag', 'href' => $other->profileurl, 'title' => $other->getBestName()), sprintf('for:%s', $other->nickname)); $out->elementEnd('li'); $out->text(' '); } } foreach ($tags as $tag) { $tag = trim($tag); if (!empty($tag)) { $out->elementStart('li'); $out->element('a', array('rel' => 'tag', 'href' => Notice_tag::url($tag)), $tag); $out->elementEnd('li'); $out->text(' '); } } $out->elementEnd('ul'); } if (!empty($nb->description)) { $out->element('p', array('class' => 'bookmark-description'), $nb->description); } $out->elementEnd('p'); }
function getUser() { $user = User::staticGet('id', $this->owner); if (empty($user)) { common_log(LOG_WARNING, sprintf("User does not exist."), __FILE__); } return $user; }
/** * See if the parent died and request a shutdown... * * @param resource $socket * @return boolean success */ function handleInput($socket) { if (feof($socket)) { common_log(LOG_INFO, "Parent process exited; shutting down child."); $this->master->requestShutdown(); } return true; }
function __call($name, $args) { $item =& $this->_items[$this->_i]; if (!is_object($item)) { common_log(LOG_ERR, "Invalid entry " . var_export($item, true) . " at index {$this->_i} of {$this->N}; calling {$name}()"); throw new ServerException("Internal error: bad entry in array wrapper list."); } return call_user_func_array(array($item, $name), $args); }
function runThread() { common_log(LOG_INFO, 'Waiting to listen to XMPP and queues'); $master = new XmppMaster($this->get_id(), $this->processManager()); $master->init($this->allsites); $master->service(); common_log(LOG_INFO, 'terminating normally'); return $master->respawn ? self::EXIT_RESTART : self::EXIT_SHUTDOWN; }
function onInitializePlugin() { if (!isset($this->private_key)) { common_log(LOG_ERR, 'Recaptcha: Must specify private_key in config.php'); } if (!isset($this->public_key)) { common_log(LOG_ERR, 'Recaptcha: Must specify public_key in config.php'); } }
function showNotice($notice) { $profile = $notice->getProfile(); if (empty($profile)) { common_log(LOG_WARNING, sprintf("Notice %d has no profile", $notice->id)); return; } $this->out->elementStart('li', 'hentry notice'); $this->out->elementStart('div', 'entry-title'); $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); $this->out->elementStart('span', 'vcard author'); $this->out->elementStart('a', array('title' => $profile->fullname ? $profile->fullname : $profile->nickname, 'href' => $profile->profileurl, 'class' => 'url')); $this->out->element('img', array('src' => $avatar ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE), 'width' => AVATAR_MINI_SIZE, 'height' => AVATAR_MINI_SIZE, 'class' => 'avatar photo', 'alt' => $profile->fullname ? $profile->fullname : $profile->nickname)); $this->out->text(' '); $this->out->element('span', 'fn nickname', $profile->nickname); $this->out->elementEnd('a'); $this->out->elementEnd('span'); $this->out->elementStart('p', 'entry-content'); $this->out->raw($notice->rendered); $notice_link_cfg = common_config('site', 'notice_link'); if ('direct' === $notice_link_cfg) { $this->out->text(' ('); $this->out->element('a', array('href' => $notice->uri), 'see'); $this->out->text(')'); } elseif ('attachment' === $notice_link_cfg) { if ($count = $notice->hasAttachments()) { // link to attachment(s) pages if (1 === $count) { $f2p = File_to_post::staticGet('post_id', $notice->id); $href = common_local_url('attachment', array('attachment' => $f2p->file_id)); $att_class = 'attachment'; } else { $href = common_local_url('attachments', array('notice' => $notice->id)); $att_class = 'attachments'; } $clip = Theme::path('images/icons/clip.png', 'base'); $this->out->elementStart('a', array('class' => $att_class, 'style' => "font-style: italic;", 'href' => $href, 'title' => "# of attachments: {$count}")); $this->out->raw(" ({$count} "); $this->out->element('img', array('style' => 'display: inline', 'align' => 'top', 'width' => 20, 'height' => 20, 'src' => $clip, 'alt' => 'alt')); $this->out->text(')'); $this->out->elementEnd('a'); } else { $this->out->text(' ('); $this->out->element('a', array('href' => $notice->uri), 'see'); $this->out->text(')'); } } $this->out->elementEnd('p'); if (!empty($notice->value)) { $this->out->elementStart('p'); $this->out->text($notice->value); $this->out->elementEnd('p'); } $this->out->elementEnd('div'); $this->out->elementEnd('li'); }
function handle($notice) { require_once INSTALLDIR . '/lib/jabber.php'; try { return jabber_public_notice($notice); } catch (XMPPHP_Exception $e) { common_log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); return false; } }
protected function saveDebug($data) { $output = var_export($data, true); if ($this->dir) { $file = $this->dir . DIRECTORY_SEPARATOR . $this->logFileName(); file_put_contents($file, $output); } else { common_log(LOG_DEBUG, "PostDebug: {$output}"); } }
/** * Returns the config settings for a site profile by name * * @param string $name name of a site profile * @return array config settings */ public static function getSettings($name) { $sprofileClass = ucfirst($name) . "Site"; if (class_exists($sprofileClass)) { return call_user_func(array($sprofileClass, 'getSettings')); } else { common_log(LOG_ERR, "Unknown site profile '{$name}' specified in config file.", __FILE__); return array(); } }
function ping_broadcast_notice($notice) { if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) { 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, common_local_url('showstream', array('nickname' => $profile->nickname)), common_local_url('shownotice', array('notice' => $notice->id)), common_local_url('userrss', array('nickname' => $profile->nickname)), $tags)); $request = HTTPClient::start(); $request->setConfig('connect_timeout', common_config('ping', 'timeout')); $request->setConfig('timeout', common_config('ping', 'timeout')); try { $httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req); } catch (Exception $e) { common_log(LOG_ERR, "Exception pinging {$notify_url}: " . $e->getMessage()); continue; } if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) { common_log(LOG_WARNING, "XML-RPC empty results for ping ({$notify_url}, {$notice->id}) "); continue; } $response = xmlrpc_decode($httpResponse->getBody()); if (is_array($response) && 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': $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: StatusNet/' . STATUSNET_VERSION)); } else { $result = $fetcher->post($notify_url, http_build_query($args), array('User-Agent: StatusNet/' . STATUSNET_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; }