/** * * Get value of requested param converted * to Utf8String object * * @param string $name * @param mixed $default fallback value in case * the param $name does not exist if Request * * @return object of type Utf8String representing the value * of requested param */ public function getUTF8($name, $default = null) { if (empty($this->aUTF8[$name])) { $res = $this->get($name, 's', $default); $ret = Utf8String::stringFactory($res); $this->aUTF8[$name] = $ret; } return $this->aUTF8[$name]; }
public function getHtml() { $edit = ''; $lastActive = $this->User['i_lm_ts']; $lastActive = !empty($lastActive) ? $lastActive : $this->User['i_reg_ts']; $rep = $this->User->getReputation(); d('rep: ' . $rep); $uid = $this->User->getUid(); $isSameUser = $this->Registry->Viewer->getUid() === $uid; if ($isSameUser || $this->Registry->Viewer->isModerator()) { $edit = '<div class="fl middle"><span class="icoc key"> </span><a href="{_WEB_ROOT_}/{_editprofile_}/' . $uid . '" class="edit middle">@@Edit profile@@</a></div>'; } $desc = \trim($this->User['description']); $desc = empty($desc) ? '' : Utf8String::stringFactory($desc, 'utf-8', true)->linkify()->valueOf(); $vars = array('editLink' => $edit, 'username' => $this->User->username, 'avatar' => $this->User->getAvatarImgSrc(), 'reputation' => $rep, 'name' => $this->User->getDisplayName(), 'genderLabel' => '@@Gender@@', 'gender' => $this->getGender(), 'since' => TimeFormatter::formatTime($this->Registry->Locale->getLocale(), $this->User->i_reg_ts, TimeFormatter::LONG, TimeFormatter::NONE), 'lastActivity' => TimeAgo::format(new \DateTime(date('r', $lastActive))), 'website' => $this->User->getUrl(), 'twitter' => '<div id="my_tw">' . $this->getTwitterAccount($isSameUser) . '</div>', 'age' => $this->User->getAge(), 'facebook' => '<div id="my_fb">' . $this->getFacebookAccount($isSameUser) . '</div>', 'tumblr' => '<div id="my_tm">' . $this->getTumblrAccount($isSameUser) . '</div>', 'blogger' => '<div id="my_bg">' . $this->getBloggerAccount($isSameUser) . '</div>', 'linkedin' => '<div id="my_li">' . $this->getLinkedInAccount($isSameUser) . '</div>', 'location' => $this->User->getLocation(), 'description' => \wordwrap($desc, 50), 'editRole' => Usertools::getHtml($this->Registry, $this->User), 'followButton' => $this->makeFollowButton(), 'followers' => ShowFollowers::factory($this->Registry)->getUserFollowers($this->User), 'following' => ShowFollowers::factory($this->Registry)->getUserFollowing($this->User)); return \tplUserInfo::parse($vars); }
/** * Post the title of Question or Answer to Twitter * Usually this method is called as a shutdown_function * @todo if space allows add "prefixes" to Tweets * Prefixes will be strings, in translation... * * @todo if space allows also add "via @ourname" to tweet if the * value of TWITTER_USERNAME exists if setting * * @param \Lampcms\Twitter $oTwitter * @param \Lampcms\Bitly $oBitly * @param object $Resource object of type Question or Answer * @return mixed null if exception was caught or array returned * by Twitter API */ public function post(\Lampcms\Twitter $oTwitter, \Lampcms\Bitly $oBitly, $Resource) { d('cp'); if (!$Resource instanceof \Lampcms\Question && !$Resource instanceof \Lampcms\Answer) { e('Resource not Question and not Answer'); return; } $ret = null; /** * $title is already guaranteed to be * in utf-8 */ $title = $Resource['title']; $url = $Resource->getUrl(); /** * Short url from bit.ly is guaranteed * to be in utf-8 */ $short = $oBitly->getShortUrl($url); /** * Our own url is in utf8 unless... * Unless this site is on some weird international * domain name that includes non-utf8 chars * This is super unlikely * We can assume that all components of * the tweet is already in utf-8 */ $url = $short ? $short : $Resource->getUrl(true); /** * Test what the length of tweet will be * if we concatenate title + space + url * * @var int */ $testLength = \mb_strlen($url . ' ' . $title, 'utf-8'); if ($testLength > 140) { d('need to shorten title'); $title = Utf8String::stringFactory($title, 'utf-8', true)->truncate(139 - \mb_strlen($url, 'utf-8'))->valueOf(); $text = $title . ' ' . $url; } else { $text = $title . ' ' . $url; } d('going to tweet this text: ' . $text); try { $ret = $oTwitter->postMessage($text); } catch (\Exception $e) { e('Tweet not sent because of exception: ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine()); } return $ret; }
/** * Get clean UTF8String object representing * trimmed and clean of html tags * * @param string $string * @return object of type UTF8String */ protected function getClean($string) { if (empty($string)) { return Utf8String::stringFactory('', 'ascii', true); } return Utf8String::stringFactory($string)->trim()->stripTags(); }
/** * (non-PHPdoc) * @see Lampcms.SubmittedAnswer::getBody() */ public function getBody() { if (!isset($this->Body)) { $this->Body = Utf8String::stringFactory($this->aData['qbody']); } return $this->Body; }
/** * Returns Tags which is * object of type Utf8String * * (non-PHPdoc) * @see Lampcms.SubmittedQuestion::getTags() */ public function getUtf8Tags() { if (!isset($this->Tags)) { $this->Tags = Utf8String::stringFactory($this->aData['tags']); } return $this->Tags; }