/** * * @return Conjoon_Modules_Default_Registry_Model_Registry */ public static function getInstance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * Expects a list of key/value pairs that should get saved * on the server. * Responds with the following properties: * failed - an array holding keys that were not * updated - an array with keys that were actually * */ public function setEntriesAction() { /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $facade = Conjoon_Modules_Default_Registry_Facade::getInstance(); $data = $this->_request->getParam('data'); $userId = $this->_helper->registryAccess()->getUserId(); $result = $facade->setEntriesFromDataForUserId($data, $userId); $this->view->success = true; $this->view->error = null; $this->view->updated = $result['updated']; $this->view->failed = $result['failed']; }
/** * Automatically called by the controller instance whenever * an exception was thrown and not trapped in a catch clause. * Since this controller supports conjoonContext, the format * of the values assigned to the view-variables may differ depending * on the format used (e.g. json encoded sting for context 'json'). */ public function errorAction() { /** * @see Conjoon_Controller_DispatchHelper */ require_once 'Conjoon/Controller/DispatchHelper.php'; $exception = $this->_getParam('error_handler')->exception; $result = Conjoon_Controller_DispatchHelper::transformExceptions(array($exception)); $this->getResponse()->clearBody(); $userId = $this->_helper->registryAccess()->getUserId(); /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $this->view->title = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/base/conjoon/name', $userId); foreach ($result as $key => $value) { $this->view->{$key} = $value; } }
public function indexAction() { $userId = $this->_helper->registryAccess()->getUserId(); /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $this->view->title = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/base/conjoon/name', $userId); $this->view->softwareLabel = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/base/conjoon/name', $userId); $this->view->editionLabel = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/base/conjoon/edition', $userId); /** * @see Conjoon_Version */ require_once 'Conjoon/Version.php'; $this->view->versionLabel = Conjoon_Version::VERSION; // check if there are any GET params available. If that is the case, // we won't deliver the app cache manifest with the page if (!empty($_GET)) { $this->view->enableManifest = false; } else { $this->view->enableManifest = true; } }
/** * Index action of the controller. * This action will be called whenever the application recognizes that the * user is not logged in anymore. This can be upon start, when the user has * to log in, or in another context, when the user uses the application and * his session gets lost. * Additionaly, this action will be called when the application detects that * the session of the user had been locked. * In all cases, the status code "401" will be send to * indicate that authorization is required. * * @see Conjoon_Controller_Plugin_Auth */ public function indexAction() { $this->_response->setHttpResponseCode(401); require_once 'Zend/Session/Namespace.php'; require_once 'Conjoon/Keys.php'; $receptionControllerNs = new Zend_Session_Namespace(Conjoon_Keys::SESSION_CONTROLLER_RECEPTION); $isLocked = $receptionControllerNs->locked; require_once 'Conjoon/Error.php'; $error = new Conjoon_Error(); $error->setCode(-1); $error->setLevel(Conjoon_Error::LEVEL_ERROR); $error->setFile(__FILE__); $error->setLine(__LINE__); if ($isLocked === true) { $error->setMessage("Workbench is locked. You need to log in again to access this resource."); $error->setType(Conjoon_Error::LOCKED); $this->view->locked = true; } else { $error->setMessage("Authorization required. You need to log in to access this resource."); $error->setType(Conjoon_Error::AUTHORIZATION); $this->view->authorized = false; } /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $this->view->title = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/base/conjoon/name', $this->_helper->registryAccess()->getUserId()); $this->view->success = false; $this->view->error = $error->getDto(); }
/** * Returns either a cached list of twitter accounts for a user, or * the accounts out of the database which will immediately be validated * against the twitter service (network access) * * @param array $options An associative array with the following * key value/pairs: * - userId: the id of the user to fetch al twitter accounts for * @param Conjoon_BeanContext_Decoratable $model * * @return Array anr array with instances of * Conjoon_Modules_Service_Twitter_Account_Model_Account */ protected function _build(array $options, Conjoon_BeanContext_Decoratable $model) { $userId = $options['userId']; /** * @see Conjoon_BeanContext_Decorator */ require_once 'Conjoon/BeanContext/Decorator.php'; $decoratedModel = new Conjoon_BeanContext_Decorator($model); $accounts = $decoratedModel->getAccountsForUserAsDto($userId); /** * @see Conjoon_Service_Twitter */ require_once 'Conjoon/Service/Twitter.php'; /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $protocolContext = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/server/environment/protocol', $userId); for ($i = 0, $len = count($accounts); $i < $len; $i++) { $dto =& $accounts[$i]; try { /** * @todo move to separate model */ /** * @see Zend_Oauth_Token_Access */ require_once 'Zend/Oauth/Token/Access.php'; $accessToken = new Zend_Oauth_Token_Access(); $accessToken->setParams(array('oauth_token' => $dto->oauthToken, 'oauth_token_secret' => $dto->oauthTokenSecret, 'user_id' => $dto->twitterId, 'screen_name' => $dto->name)); $twitter = new Conjoon_Service_Twitter(array('username' => $dto->name, 'accessToken' => $accessToken)); $response = $twitter->userShow($dto->name); $dto->twitterId = $response->id_str; $dto->twitterName = $response->name; $dto->twitterScreenName = $response->screen_name; $dto->twitterLocation = $response->location; $dto->twitterProfileImageUrl = $protocolContext === 'https' ? $response->profile_image_url_https : $response->profile_image_url; $dto->twitterUrl = $response->url; $dto->twitterProtected = $response->protected; $dto->twitterDescription = $response->description; $dto->twitterFollowersCount = $response->followers_count; } catch (Exception $e) { Conjoon_Log::log("Could not retrieve account information for twitter " . "account: \"" . $e->getMessage() . "\"", Zend_Log::INFO); // ignore } $dto->oauthTokenSecret = str_pad("", strlen($dto->oauthTokenSecret), '*'); } return $accounts; }
/** * @return Conjoon_Modules_Default_Registry_Facade */ private function _getRegistryFacade() { if (!$this->_registryFacade) { /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $this->_registryFacade = Conjoon_Modules_Default_Registry_Facade::getInstance(); } return $this->_registryFacade; }
/** * Helper function for fetching a single email message from a remote * server. * * @param string $id The id of the message * @param string $path The json encoded path where the message can be found * @param mixed $allowExternals whether external resources are allowed. If this is * set to NULL, the registry settings of the current user will be given precedence * * @throws \Conjoon\Argument\InvalidArgumentException */ protected function getMessageHelper($id, $path, $allowExternals = null) { $data = array('path' => $path); ArgumentCheck::check(array('path' => array('type' => 'string', 'allowEmpty' => false)), $data); $path = $data['path']; $registry = \Conjoon_Modules_Default_Registry_Facade::getInstance(); $readingKey = '/client/conjoon/modules/mail/options/reading/'; $preferredFormat = $registry->getValueForKeyAndUserId($readingKey . 'preferred_format', $this->getCurrentAppUser()->getId()); $allowExternals = $allowExternals === null ? $registry->getValueForKeyAndUserId($readingKey . 'allow_externals', $this->getCurrentAppUser()->getId()) : $allowExternals; $plainReadableStrategy = new \Conjoon\Mail\Client\Message\Strategy\DefaultPlainReadableStrategy(); $readableStrategy = null; $htmlPurifier = $this->getHtmlPurifierHelper($allowExternals); if ($preferredFormat == 'html') { $readableStrategy = new \Conjoon\Mail\Client\Message\Strategy\DefaultHtmlReadableStrategy($htmlPurifier, $plainReadableStrategy, new \Conjoon\Text\Parser\Html\ExternalResourcesParser()); } else { $readableStrategy = $plainReadableStrategy; } $serviceFacade = $this->getMessageServiceFacadeHelper(); return $serviceFacade->getMessage($id, $path, $this->getCurrentAppUser(), $readableStrategy); }
/** * This is the action to which Twitter redirects once the user has authorized * conjoon to use a specific Twitter account. * Necessary configuration will be stored in the session. The Session parameters * oauthToken and oauthTokenSecret must be available. */ public function authorizeOkayAction() { $this->view->title = "conjoon - Twitter Account Authorization"; /** * @see Zend_Session_Namespace */ require_once 'Zend/Session/Namespace.php'; /** * @see Conjoon_Keys */ require_once 'Conjoon/Keys.php'; $sessionOauth = new Zend_Session_Namespace(Conjoon_Keys::SESSION_SERVICE_TWITTER_OAUTH); if (!isset($sessionOauth->oauthToken) || !isset($sessionOauth->oauthTokenSecret)) { die("invalid data."); } /** * @see Zend_Oauth_Consumer */ require_once 'Zend/Oauth/Consumer.php'; $config = Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT); /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $registry = Conjoon_Modules_Default_Registry_Facade::getInstance(); $userId = $this->_helper->registryAccess()->getUserId(); $port = $registry->getValueForKeyAndUserId('/server/environment/port', $userId); $protocol = $registry->getValueForKeyAndUserId('/server/environment/protocol', $userId); $host = $registry->getValueForKeyAndUserId('/server/environment/host', $userId); /** * @see Conjoon_Service_Twitter_AccountService */ require_once 'Conjoon/Service/Twitter/AccountService.php'; $accountService = new Conjoon_Service_Twitter_AccountService(); $callbackUrl = $accountService->getOauthCallbackUrl(array('port' => $port, 'protocol' => $protocol, 'host' => $host, 'baseUrl' => $config->environment->base_url, 'oauthCallbackUrl' => $config->application->twitter->oauth->callbackUrl)); $siteUrl = $config->application->twitter->oauth->siteUrl; $consumerKey = $config->application->twitter->oauth->consumerKey; $consumerSecret = $config->application->twitter->oauth->consumerSecret; $options = array('callbackUrl' => $callbackUrl, 'siteUrl' => $siteUrl, 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret); $consumer = new Zend_Oauth_Consumer($options); require_once 'Zend/Oauth/Token/Request.php'; $requestToken = new Zend_Oauth_Token_Request(); $requestToken->setParams(array('oauth_token' => $sessionOauth->oauthToken, 'oauth_token_secret' => $sessionOauth->oauthTokenSecret)); $accessToken = $consumer->getAccessToken($_GET, $requestToken); require_once 'Zend/Oauth/Token/Access.php'; $screenName = $accessToken->getParam('screen_name'); $userId = $accessToken->getParam('user_id'); $oauthToken = $accessToken->getParam('oauth_token'); $oauthTokenSecret = $accessToken->getParam('oauth_token_secret'); require_once 'Conjoon/Service/Twitter/Proxy.php'; /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $protocolContext = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/server/environment/protocol', $this->_helper->registryAccess()->getUserId()); $twitter = new Conjoon_Service_Twitter_Proxy(array('screen_name' => $screenName, 'user_id' => $userId, 'oauth_token' => $oauthToken, 'oauth_token_secret' => $oauthTokenSecret, 'consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'protocol_context' => $protocolContext)); $dto = $twitter->accountVerifyCredentials(); if ($dto instanceof Conjoon_Error) { $this->view->success = false; $this->view->error = $dto->getDto(); $this->view->connectionFailure = true; return; } /** * @ticket CN-675 * We could possibly remove this due to CN-676, but decided to leave it * in here to double check... doesn't hurt */ if ($dto->twitterId != $userId) { throw new RuntimeException("userId does not equal to user id from Twitter API Service"); } unset($sessionOauth->oauthToken); unset($sessionOauth->oauthTokenSecret); $dto->oauthToken = $oauthToken; $dto->oauthTokenSecret = $oauthTokenSecret; $this->view->success = true; $this->view->account = $dto; }
/** * Returns an instance of Conjoon_Service_Twitter_Proxy. * * @param mixed $accountId * * @return Conjoon_Service_Twitter_Proxy or an instance of Conjoon_Error */ protected function getTwitterProxy($accountId) { if (isset($this->twitterProxyCache[$accountId])) { return $this->twitterProxyCache[$accountId]; } $accountDto = $this->getAccountDto($accountId); if ($accountDto instanceof Conjoon_Error) { return $accountDto; } /** * @see Conjoon_Service_Twitter_Proxy */ require_once 'Conjoon/Service/Twitter/Proxy.php'; /** * @see Zend_Registry */ require_once 'Zend/Registry.php'; /** * @see Conjoon_Keys */ require_once 'Conjoon/Keys.php'; $config = Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT); $consumerKey = $config->application->twitter->oauth->consumerKey; $consumerSecret = $config->application->twitter->oauth->consumerSecret; /** * @see Conjoon_Modules_Default_Registry_Facade */ require_once 'Conjoon/Modules/Default/Registry/Facade.php'; $protocolContext = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/server/environment/protocol', $this->_helper->registryAccess()->getUserId()); $twitter = new Conjoon_Service_Twitter_Proxy(array('oauth_token' => $accountDto->oauthToken, 'oauth_token_secret' => $accountDto->oauthTokenSecret, 'user_id' => $accountDto->twitterId, 'screen_name' => $accountDto->name, 'consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'protocol_context' => $protocolContext)); $this->twitterProxyCache[$accountId] = $twitter; return $twitter; }