コード例 #1
0
 /**
  * Post a Link to this question or answer
  * To User's Facebook Wall
  *
  */
 protected function post()
 {
     try {
         $reward = \Lampcms\Points::SHARED_CONTENT;
         $User = $this->Registry->Viewer;
         $oFB = $this->Registry->Facebook;
         $Resource = $this->obj;
         $Mongo = $this->Registry->Mongo;
         $logo = !empty($this->aFB['SITE_LOGO']) ? $this->aFB['SITE_LOGO'] : null;
         /**
          * @todo Translate String(s) of caption
          * It appears on Facebook Wall under the link
          * @var string
          */
         $caption = $this->obj instanceof \Lampcms\Question ? 'Please click if you can answer this question' : 'I answered this question';
         $description = Utf8String::factory($this->obj['b'], 'utf-8', true)->asPlainText()->valueOf();
     } catch (\Exception $e) {
         d('Unable to post to facebook because of this exception: ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
         return;
     }
     $func = function () use($oFB, $Resource, $User, $reward, $Mongo, $logo, $caption, $description) {
         $result = null;
         $aData = array('link' => $Resource->getUrl(), 'name' => $Resource['title'], 'message' => $caption, 'description' => $description);
         if (!empty($logo) && 'http' == substr($logo, 0, 4)) {
             $aData['picture'] = $logo;
         }
         try {
             $result = $oFB->postUpdate($User, $aData);
         } catch (\Exception $e) {
             // does not matter
         }
         if (!empty($result) && false !== ($decoded = json_decode($result, true))) {
             /**
              * If status is OK
              * then reward the user with points!
              */
             if (!empty($decoded['id'])) {
                 $status_id = (string) $decoded['id'];
                 $User->setProfitPoint($reward);
                 /**
                  * Now need to also record Facebook id
                  * to FB_STATUSES collection
                  */
                 try {
                     /**
                      * Also save fb_status to QUESTIONS or ANSWERS
                      * collection.
                      * This way later on (maybe way later...)
                      * We can add a function so that if user edits
                      * Post on the site we can also edit it
                      * on Tumblr via API
                      * 
                      */
                     $Resource['fb_status'] = $status_id;
                     $Resource->save();
                 } catch (\Exception $e) {
                     if (function_exists('e')) {
                         e('Unable to save data to FB_STATUSES collection because of ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
                     }
                 }
             }
         }
     };
     \Lampcms\runLater($func);
 }
コード例 #2
0
 /**
  *
  * What if email address provided from Facebook
  * already belongs to some other user?
  *
  * This would mean that existing user is just
  * trying to signup with Facebook.
  *
  * In this case we should allow it but ONLY create
  * a record in the USERS_FACEBOOK table and use users_id
  * of use that we find by email address
  *
  * and then also insert avatar_external into USERS
  *
  * @todo create username for user based on Facebook username
  * Facebook does not really have username, so we can use fn_ln
  *
  */
 protected function createNewUser()
 {
     $extAuth = new \Lampcms\ExternalAuth($this->Registry);
     d('cp');
     $this->Registry->Mongo->USERS->ensureIndex(array('fb_id' => 1));
     /**
      * Time zone offset in seconds
      * @var int
      */
     $tzo = array_key_exists('timezone', $this->aFbUserData) ? $this->aFbUserData['timezone'] * 3600 : Cookie::get('tzo', 0);
     /**
      * User language
      * @var string
      */
     $lang = !empty($this->aFbUserData['locale']) ? \strtolower(\substr($this->aFbUserData['locale'], 0, 2)) : $this->Registry->getCurrentLang();
     /**
      * User locale
      * @var string
      */
     $locale = !empty($this->aFbUserData['locale']) ? $this->aFbUserData['locale'] : $this->Registry->Locale->getLocale();
     $this->tempPassword = String::makePasswd();
     /**
      * Sid value use existing cookie val
      * if possible, otherwise create a new one
      * @var string
      */
     $sid = false === ($sid = Cookie::getSidCookie()) ? String::makeSid() : $sid;
     $displayName = !empty($this->aFbUserData['name']) ? $this->aFbUserData['name'] : $this->aFbUserData['first_name'] . ' ' . $this->aFbUserData['last_name'];
     $username = $extAuth->makeUsername($displayName);
     /**
      * Create new record in USERS table
      * do this first because we need uid from
      * newly created record
      */
     $aUser = array('username' => $username, 'username_lc' => \mb_strtolower($username, 'utf-8'), 'fn' => $this->aFbUserData['first_name'], 'ln' => $this->aFbUserData['last_name'], 'rs' => $sid, 'email' => Utf8String::factory($this->aFbUserData['email'])->toLowerCase()->valueOf(), 'fb_id' => (string) $this->aFbUserData['id'], 'fb_token' => $this->aFbUserData['token'], 'pwd' => String::hashPassword($this->tempPassword), 'avatar_external' => 'http://graph.facebook.com/' . $this->aFbUserData['id'] . '/picture', 'i_reg_ts' => time(), 'date_reg' => date('r'), 'role' => 'external_auth', 'lang' => $lang, 'i_pp' => 1, 'tz' => TimeZone::getTZbyoffset($tzo), 'i_fv' => false !== ($intFv = Cookie::getSidCookie(true)) ? $intFv : time());
     if (!empty($this->aFbUserData['gender'])) {
         $aUser['gender'] = 'male' === $this->aFbUserData['gender'] ? 'M' : 'F';
     }
     $aUser = \array_merge($this->Registry->Geo->Location->data, $aUser);
     if (!empty($this->aFbUserData['locale'])) {
         $aUser['locale'] = $this->aFbUserData['locale'];
     }
     if (!empty($this->aFbUserData['link'])) {
         $aUser['fb_url'] = $this->aFbUserData['link'];
     }
     d('aUser: '******'$this->User after insert: ' . print_r($this->User->getArrayCopy(), 1));
     $this->Registry->Dispatcher->post($this->User, 'onNewUser');
     $this->Registry->Dispatcher->post($this->User, 'onNewFacebookUser');
     d('cp');
     $this->saveEmailAddress();
     d('cp');
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $this->User);
     return $this;
 }
コード例 #3
0
 /**
  * Unlike normal WWW request, 
  * In API call we may not have 'tags' in Request,
  * so we need to fallback to default empty string here
  *
  * (non-PHPdoc)
  * @see Lampcms.SubmittedQuestionWWW::getUtf8Tags()
  */
 public function getUtf8Tags()
 {
     if (!isset($this->Tags)) {
         $tags = $this->Registry->Request->get('tags', 's', '');
         $this->Tags = Utf8String::factory($tags);
     }
     return $this->Tags;
 }
コード例 #4
0
ファイル: Editor.php プロジェクト: netconstructor/LampCMS
 /**
  * Make new value of title
  *
  * @param string $title
  *
  * @return object of type Utf8String
  */
 protected function makeTitle($title)
 {
     $oTitle = Utf8String::factory($title)->htmlentities()->trim();
     d('$oTitle ' . $oTitle);
     return $oTitle;
 }
コード例 #5
0
 /**
  * Get count of words in this html document
  * This is the right way to get word count
  * from HTML doc. The simple way of strip_tags and
  * then explode by spaces will not work if
  * html string is just one long
  * string run together without white spaces
  * and using regex is usually not the best way
  * to deal with html string.
  *
  * Each Text Node element is then treated
  * as separate UTF8String object
  *
  * This way each text node is split by UTF-8 specific word
  * delimeters, making it return correct word count
  * for Any type of language (not only splitting by spaces but
  * by other accepted delimiters)
  *
  * The resulting word count will be accurate for arabic, chinese,
  * and probably all other languages
  *
  * @return int count of words in this html string
  */
 public function getWordsCount()
 {
     $count = 0;
     $Nodes = $this->getTextNodes();
     $len = $Nodes->length;
     if (!$Nodes || 0 === $len) {
         return 0;
     }
     for ($i = 0; $i < $len; $i += 1) {
         $UTF8String = Utf8String::factory($Nodes->item($i)->data, 'utf-8', true);
         $count += $UTF8String->getWordsCount();
     }
     return $count;
 }
コード例 #6
0
 /**
  * @return object of type Utf8string representing
  * the title string of question
  */
 public function getTitle()
 {
     return Utf8String::factory('Quick brown fox');
 }