Ejemplo n.º 1
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($pUser, $pOAuthToken)
 {
     $lAccessToken = $this->getAccessToken($pOAuthToken);
     // get params
     $lParams = $lAccessToken->params;
     $lParamsArray = array();
     // extract params
     parse_str($lParams, $lParamsArray);
     $lXml = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.linkedin.com/v1/people/~:(id,site-standard-profile-request,summary,picture-url,first-name,last-name,date-of-birth,location)");
     $lProfileArray = XmlUtils::XML2Array($lXml);
     //var_dump($lProfileArray);die();
     // identifier
     $lLinkedInId = $lProfileArray['id'];
     $lProfileUri = "http://www.linkedin.com/profile/view?id=" . $lLinkedInId;
     // ask for online identity
     $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lProfileUri);
     // check if user already exists
     if ($lOnlineIdentity) {
         if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) {
             if (!$lOnlineIdentity->getActive()) {
                 $lOnlineIdentity->setActive(true);
             } else {
                 throw new sfException("online identity already added", 1);
             }
         } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) {
             throw new sfException("online identity already added by someone else", 2);
         }
     } else {
         // new online identity if no exist
         $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lProfileUri, $lLinkedInId, $this->aCommunityId, $lProfileUri);
     }
     $this->completeOnlineIdentity($lOnlineIdentity, $lProfileArray, $pUser);
     AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true);
     return $lOnlineIdentity;
 }
Ejemplo n.º 2
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($pUser, $pCode)
 {
     $lAccessToken = $this->getAccessToken($pCode);
     // get params
     $lParamsArray = array();
     // extract params
     $lAccessToken = json_decode($lAccessToken, true);
     $lJsonObject = json_decode(UrlUtils::sendGetRequest("https://api.flattr.com/rest/v2/user", array("Authorization: Bearer " . $lAccessToken["access_token"])));
     // facebook identifier
     $lIdentifier = $lJsonObject->link;
     // ask for online identity
     $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier);
     // check if user already exists
     if ($lOnlineIdentity) {
         if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) {
             if (!$lOnlineIdentity->getActive()) {
                 $lOnlineIdentity->setActive(true);
             } else {
                 throw new sfException("online identity already added", 1);
             }
         } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) {
             throw new sfException("online identity already added by someone else", 2);
         }
     } else {
         // check online identity
         $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lJsonObject->link, $lJsonObject->username, $this->aCommunityId, $lIdentifier);
     }
     // use api complete informations
     $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier);
     // signup,add new
     AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lAccessToken["access_token"], null, true);
     // signup,add new
     return $lOnlineIdentity;
 }
Ejemplo n.º 3
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($pUser, $pOAuthToken)
 {
     $lAccessToken = $this->getAccessToken($pOAuthToken);
     // get params
     $lParams = $lAccessToken->params;
     $lParamsArray = array();
     // extract params
     parse_str($lParams, $lParamsArray);
     // twitter identifier
     $lIdentifier = "http://twitter.com/account/profile?user_id=" . $lParamsArray['user_id'];
     // ask for online identity
     $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier);
     // check if user already exists
     if ($lOnlineIdentity) {
         if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) {
             if (!$lOnlineIdentity->getActive()) {
                 $lOnlineIdentity->setActive(true);
             } else {
                 throw new sfException("online identity already added", 1);
             }
         } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) {
             throw new sfException("online identity already added by someone else", 2);
         }
     } else {
         // check online identity
         $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity("http://twitter.com/" . $lParamsArray['screen_name'], $lParamsArray['user_id'], $this->aCommunityId);
     }
     // get api informations
     $lJson = OAuthClient::get($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "https://api.twitter.com/1.1/users/show.json?user_id=" . $lParamsArray['user_id']);
     $lJsonObject = json_decode($lJson);
     $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier);
     AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true);
     return $lOnlineIdentity;
 }
Ejemplo n.º 4
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($pUser, $pCode)
 {
     $lAccessToken = $this->getAccessToken($pCode);
     // get params
     $lParamsArray = array();
     // extract params
     parse_str($lAccessToken, $lParamsArray);
     $lJsonObject = json_decode(UrlUtils::sendGetRequest("https://graph.facebook.com/me?access_token=" . $lParamsArray['access_token'] . "&locale=en_US"));
     // facebook identifier
     $lIdentifier = "http://www.facebook.com/profile.php?id=" . $lJsonObject->id;
     // ask for online identity
     $lOnlineIdentity = OnlineIdentityTable::retrieveByAuthIdentifier($lIdentifier);
     // check if user already exists
     if ($lOnlineIdentity) {
         if ($lOnlineIdentity->getUserId() && $pUser->getId() == $lOnlineIdentity->getUserId()) {
             if (!$lOnlineIdentity->getActive()) {
                 $lOnlineIdentity->setActive(true);
             } else {
                 throw new sfException("online identity already added", 1);
             }
         } elseif ($lOnlineIdentity->getUserId() && $pUser->getId() != $lOnlineIdentity->getUserId()) {
             throw new sfException("online identity already added by someone else", 2);
         }
     } else {
         // check online identity
         $lOnlineIdentity = OnlineIdentityTable::addOnlineIdentity($lJsonObject->link, $lJsonObject->id, $this->aCommunityId);
     }
     // use api complete informations
     $this->completeOnlineIdentity($lOnlineIdentity, $lJsonObject, $pUser, $lIdentifier);
     // signup,add new
     AuthTokenTable::saveToken($pUser->getId(), $lOnlineIdentity->getId(), $lParamsArray['access_token'], null, true);
     // signup,add new
     return $lOnlineIdentity;
 }
Ejemplo n.º 5
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($user, $pOAuthToken)
 {
     $lAccessToken = $this->getAccessToken($pOAuthToken);
     //var_dump($lAccessToken);die();
     // get params
     $lParams = $lAccessToken->params;
     $lParamsArray = array();
     // extract params
     parse_str($lParams, $lParamsArray);
     //$lConsumer = new OAuthConsumer(sfConfig::get("app_linkedin_oauth_token"), sfConfig::get("app_linkedin_oauth_secret"));
     $json = OAuthClient::post($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.tumblr.com/v2/user/info");
     $json = json_decode($json, true);
     foreach ($json['response']['user']['blogs'] as $blog) {
         $user_name = $blog['name'];
         $auth_identifier = "http://" . $user_name . ".tumblr.com";
         // ask for online identity
         $online_identity = OnlineIdentityTable::retrieveByAuthIdentifier($auth_identifier);
         // check if user already exists
         if ($online_identity) {
             if ($online_identity->getUserId() && $user->getId() == $online_identity->getUserId()) {
                 if (!$online_identity->getActive()) {
                     $online_identity->setActive(true);
                 } else {
                     //throw new sfException("online identity already added", 1);
                     continue;
                 }
             } elseif ($online_identity->getUserId() && $user->getId() != $online_identity->getUserId()) {
                 //throw new sfException("online identity already added by someone else", 2);
                 continue;
             }
         } else {
             // check online identity
             $online_identity = OnlineIdentityTable::addOnlineIdentity($auth_identifier, $user_name, $this->aCommunityId);
         }
         $this->completeOnlineIdentity($online_identity, $blog, $user, $auth_identifier);
         // save new token
         AuthTokenTable::saveToken($user->getId(), $online_identity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true);
     }
     return $user;
 }
    protected function execute($arguments = array(), $options = array())
    {
        try {
            sfContext::getInstance();
        } catch (Exception $e) {
            // aize the database connection
            $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
            sfContext::createInstance($configuration);
        }
        $databaseManager = new sfDatabaseManager($this->configuration);
        $databaseManager->loadConfiguration();
        $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
        $originalPostToServicesValue = sfConfig::get('app_settings_post_to_services');
        sfConfig::set('app_settings_post_to_services', 0);
        $this->log("Using mongo host: " . sfConfig::get('app_mongodb_host'));
        $lUserHugo = UserTable::retrieveByUsername('hugo');
        $lHugoOis = $lUserHugo->getOnlineIdentitesAsArray();
        $lUserJames = UserTable::retrieveByUsername('james');
        $lJamesOis = $lUserJames->getOnlineIdentitesAsArray();
        $lCommunityTwitter = CommunityTable::retrieveByCommunity('twitter');
        $lCommunityFb = CommunityTable::retrieveByCommunity('facebook');
        $lOiHugoTwitter = OnlineIdentityTable::retrieveByAuthIdentifier('http://twitter.com/account/profile?user_id=21092406', $lCommunityTwitter->getId());
        $lOiJamesFacebook = OnlineIdentityTable::retrieveByAuthIdentifier('james_fb', $lCommunityFb->getId());
        $urls = array('www.snirgel.de', 'notizblog.org', 'www.missmotz.de');
        $tags = array('geekstuff', 'otherthings', 'schuhe');
        $users = array($lUserHugo, $lUserJames);
        $services = array('facebook', 'twitter', 'linkedin', 'google');
        $deals = array('Campaign No. 1', 'Campaign No. 2', 'Campaign No. 3');
        $dm = MongoManager::getDM();
        for ($i = 0; $i < 100; $i++) {
            $url = $this->oneOfThese($urls);
            $tag = $this->oneOfThese($tags);
            $user = $this->oneOfThese($users);
            $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de'));
            $ra = $this->random(1000);
            $theC = mt_rand(strtotime("3 days ago"), strtotime("today"));
            $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null);
            $lActivity = new Documents\YiidActivity();
            $lActivity->fromArray($array);
            try {
                $lActivity->skipUrlCheck = true;
                $lActivity->save();
            } catch (Exception $e) {
                $this->log($e->getMessage());
            }
        }
        // same for deals
        for ($i = 0; $i < 100; $i++) {
            $url = $this->oneOfThese($urls);
            $tag = $this->oneOfThese($tags);
            $user = $this->oneOfThese($users);
            $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de'));
            $i_url = $this->oneOfThese(array('http://ard.de', 'http://bild.de', 'http://spiegel.de', 'http://tierscheisse.de'));
            $ra = $this->random(1000);
            $theC = mt_rand(strtotime("3 days ago"), strtotime("today"));
            $deal = DealTable::getInstance()->findOneByName($this->oneOfThese($deals));
            $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'd_id' => $deal->getId(), 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'i_url' => $i_url, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null);
            $lActivity = new Documents\YiidActivity();
            $lActivity->fromArray($array);
            try {
                $lActivity->skipUrlCheck = true;
                $lActivity->save();
            } catch (Exception $e) {
                $this->log($e->getMessage());
            }
        }
        $ds = new Documents\DomainSettings();
        $ds->setDomain("blog.local");
        $ds->setMute(0);
        $ds->save();
        $ds = new Documents\DomainSettings();
        $ds->setDomain("pfefferle.org");
        $ds->setDisableAds(true);
        $ds->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local"));
        $ad->setAdCode('<script type="text/javascript" src="http://a.ligatus.com/?ids=34548&t=js"></script>');
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(500);
        $ad->setAdWidth(50);
        $ad->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("blog.local"));
        $ad->setAdCode("<script type='text/javascript' src='http://imagesrv.adition.com/js/adition.js'></script>\n<script type='text/javascript' src='http://ad4.adfarm1.adition.com/js?wp_id=744125'></script>");
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(100);
        $ad->setAdWidth(800);
        $ad->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local"));
        $ad->setAdCode('<script type="text/javascript"><!--
  google_ad_client = "ca-pub-1406192967534280";
  /* spreadly */
  google_ad_slot = "7458728780";
  google_ad_width = 250;
  google_ad_height = 250;
  //-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>');
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(250);
        $ad->setAdWidth(250);
        $ad->save();
        /*
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiJamesFacebook->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => null,
          'u_id' => $lUserJames->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        if($deal[0]->canApprove()) {
          $deal[0]->approve();
        }
        
        
        $url = 'notizblog.org';
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiHugoTwitter->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => null,
          'u_id' => $lUserHugo->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        $deal = DealTable::getInstance()->findByDescription('missmotz approved description');
        if($deal[0]->canApprove()) {
          $deal[0]->approve();
        }
        
        $url = 'www.missmotz.de';
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiHugoTwitter->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => "Schuhe, Hemden",
          'u_id' => $lUserHugo->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        */
        sfConfig::set('app_settings_post_to_services', $originalPostToServicesValue);
        $this->generateErrorLog();
    }