public function __construct() { if (!class_exists('TwitterOAuth')) { if (isset(\Kiki\Config::$twitterOAuthPath)) { Log::error("could not instantiate TwitterOAuth class from " . \Kiki\Config::$twitterOAuthPath . "/autoload.php"); } return; } $this->enabled = true; }
public static function getInstance($service, $id = 0, $kikiUserId = 0) { // TODO: remove migration from namespaces $service = str_replace("User_", "", $service); $class = ucfirst($service); if (!strstr($class, __NAMESPACE__)) { $class = __NAMESPACE__ . "\\" . $class; } if (!class_exists($class)) { \Kiki\Log::error("Non-existant class {$class} requested"); return null; } return new $class($id, $kikiUserId); }
use Kiki\Status; use Kiki\Config; use Kiki\Core; // FIXME: add accountpage/adminpage checks here or to template $this->title = _("Kiki Status"); /* if ( !$user->isAdmin() ) { $this->template = 'pages/admin-required'; return; } */ $this->template = 'pages/admin'; $adminsExist = count(Config::$adminUsers); $dbVersion = Status::dbVersion(); Log::debug("adminUsers: " . print_r(Config::$adminUsers, true)); $checkStatus = $user->isAdmin() || !$adminsExist; if (!$checkStatus) { $this->status = 401; $this->content = "Access forbidden."; return; } $failedRequirements = Status::failedRequirements(); if (count($failedRequirements)) { ob_start(); echo "<h2>PHP modules and PEAR/PECL extensions</h2>\n"; echo "<ul>\n"; foreach ($failedRequirements as $failedRequirement) { $remedyStr = isset($failedRequirement['remedy']) ? " Potential remedy: <tt>" . $failedRequirement['remedy'] . "</tt>." : null; echo "<li><strong>" . $failedRequirement['name'] . "</strong>: <span style=\"color: red\">disabled</span>.{$remedyStr}</li>\n"; }
} } $tweets = array(); $storePublicationsAsComment = false; foreach ($connectionIds as $connectionId) { $q = $db->buildQuery("SELECT external_id, object_id FROM publications WHERE connection_id=%d AND external_id!=0", $connectionId); $rs = $db->query($q); while ($o = $db->fetchObject($rs)) { $objectIds[$o->external_id] = $o->object_id; } $apiUser = User\Factory::getInstance('Twitter', $connectionId); try { $rs = $apiUser->api()->get('application/rate_limit_status'); } catch (User\Exception $e) { echo "API call failed for user " . print_r($apiUser, true); Log::error("API call failed for user " . print_r($apiUser, true)); continue; } if (!isset($rs)) { echo "No valid result from Twitter (connection {$connectionId})." . PHP_EOL; continue; } $remainingHits = $rs->resources->application->{'/application/rate_limit_status'}->remaining; if ($remainingHits < 5) { $resetTime = $rs->resources->application->{'/application/rate_limit_status'}->reset; $wait = $resetTime - time(); echo "Less than 10 query hits remaining ({$remainingHits}), replenishes in {$wait}s." . PHP_EOL; continue; } $getMore = true; $maxId = 0;
public function getLoginUrl($params, $force = false) { if (!$params) { $params = array(); } else { if (!is_array($params)) { Log::debug("called with non-array argument"); $params = array(); } } // $params['display'] = "popup"; // Force a login URL through the app API, not the user connection. // Without first verifying the required permission Facebook otherwise // thinks everything is ok because the user is already logged in. if ($force) { $connection = Factory_ConnectionService::getInstance('Facebook'); return $connection->loginUrl($params); } return $this->api ? $this->api->getLoginUrl($params) : null; }
/** * Builds a Twitter authorisation URL using the generic application token * and referer as callback URL, then redirects to it. */ public function twitterRedirectAction() { if (isset(Config::$twitterOAuthPath)) { require_once Config::$twitterOAuthPath . "/twitteroauth/twitteroauth.php"; } else { $this->content = _("Error in Twitter configuration (TwitterOAuth path not set)."); Log::debug("SNH: called without Twitter configuration"); return false; } // Build TwitterOAuth object with app credentials. $connection = new \TwitterOAuth(Config::$twitterApp, Config::$twitterSecret); // Get temporary credentials. Even though a callback URL is specified // here, it must be set in your Twitter application settings as well to // avoid a PIN request (it can be anything actually, just not empty). $callbackUrl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $requestToken = $connection->getRequestToken($callbackUrl); // Save temporary credentials to session. $_SESSION['oauth_token'] = $token = $requestToken['oauth_token']; $_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret']; switch ($connection->http_code) { case 200: // Build authorize URL and redirect user to Twitter. $this->status = 302; $this->content = $connection->getAuthorizeURL($token); break; default: $this->content = _("Could not connect to Twitter. Try again later."); } return true; }
/** * Sends and e-mail using Net_SMTP. * * @param Email $email * @return string Error message, or null upon success. */ public static function smtp(&$email) { /* if ( isset($GLOBALS['phpmail']) && $GLOBALS['phpmail'] ) { $rfc = new \Mail_RFC822(); $pureAddresses = $rfc->parseAddressList($email->to()); foreach( $pureAddresses as $address ) { $to = $address->mailbox. "@". $address->host; mail( $to, $email->subject(), $email->body(), $email->headers() ); } return; } */ Log::debug("Mailer: subject:[" . $email->subject() . "], from:[" . $email->from() . "], to:" . print_r($email->recipients(), true)); if (!Config::$smtpHost) { $error = "Mailer: no SMTP host supplied"; Log::debug($error); return $error; } if (!($smtp = new \Net_SMTP(Config::$smtpHost, Config::$smtpPort, $_SERVER['SERVER_NAME']))) { $error = "Mailer: unable to instantiate Net_SMTP object"; Log::debug($error); return $error; } // $smtp->setDebug(true); $pear = new \PEAR(); if ($pear->isError($e = $smtp->connect())) { $error = "Mailer: connect error: " . $e->getMessage(); Log::debug($error); return $error; } if (Config::$smtpUser && $pear->isError($e = $smtp->auth(Config::$smtpUser, Config::$smtpPass, Config::$smtpAuthType))) { $error = "Mailer: authentication error: " . $e->getMessage(); Log::debug($error); return $error; } $rfc = new \Mail_RFC822(); $pureAddresses = $rfc->parseAddressList($email->from()); $from = $pureAddresses[0]->mailbox . "@" . $pureAddresses[0]->host; if ($pear->isError($e = $smtp->mailFrom($from))) { $error = "Unable to set sender to [{$from}]: " . $e->getMessage(); Log::debug($error); return $error; } foreach ($email->recipients() as $toAddress) { $pureAddresses = $rfc->parseAddressList($toAddress); foreach ($pureAddresses as $address) { $to = $address->mailbox . "@" . $address->host; if ($pear->isError($e = $smtp->rcptTo($to))) { $error = "Unable to set recipient to [{$to}]: " . $e->getMessage(); Log::debug($error); return $error; } } } if ($pear->isError($e = $smtp->data($email->data()))) { $error = "Unable to set data: " . $e->getMessage(); Log::debug($error); return $error; } Log::debug("Mailer: sent: " . $smtp->_arguments[0]); $smtp->disconnect(); return null; }
public function postAlbum(&$album, $newPictures = 0) { $pictureCount = count($newPictures); $pictureId = $pictureCount > 0 ? $newPictures[0]['id'] : $album->firstPicture(); $q = $this->db->buildQuery("SELECT storage_id FROM pictures WHERE id=%d", $pictureId); $storageId = $this->db->getSingleValue($q); $msg = null; switch ($pictureCount) { case 0: $msg = sprintf("%d new pictures in album %s (%s)", $pictureCount, $album->title(), $album->url()); break; case 1: $msg = sprintf("%d new picture in album %s (%s)", $pictureCount, $album->title(), $album->url()); break; default: $msg = sprintf("%d new pictures in album %s (%s)", $pictureCount, $album->title(), $album->url()); break; } // TODO: (also?) store publication for individual pictures $rs = $this->post($album->objectId(), $msg); \Kiki\Log::debug(print_r($rs, true)); return $rs; }