コード例 #1
0
ファイル: index.php プロジェクト: robkaper/kiki
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";
    }
コード例 #2
0
ファイル: facebook.php プロジェクト: robkaper/kiki
 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;
 }
コード例 #3
0
ファイル: mailer.php プロジェクト: robkaper/kiki
 /**
  * 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;
 }
コード例 #4
0
ファイル: kiki.php プロジェクト: robkaper/kiki
 /**
  * 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;
 }
コード例 #5
0
ファイル: twitter.php プロジェクト: robkaper/kiki
 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;
 }