Пример #1
0
    /**
     */
    protected function _content()
    {
        global $page_output;
        /* Get the twitter driver */
        try {
            $twitter = $this->_getTwitterObject();
        } catch (Horde_Exception $e) {
            throw new Horde_Exception(sprintf(_("There was an error contacting Twitter: %s"), $e->getMessage()));
        }
        /* Get a unique ID in case we have multiple Twitter blocks. */
        $instance = (string) new Horde_Support_Randomid();
        /* Latest status */
        if (empty($this->_profile->status)) {
            // status might not be set if only updating the block via ajax
            try {
                $this->_profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON);
                if (empty($this->_profile)) {
                    return _("Temporarily unable to contact Twitter. Please try again later.");
                }
            } catch (Horde_Service_Twitter_Exception $e) {
                $msg = Horde_Serialize::unserialize($e->getMessage(), Horde_Serialize::JSON);
                if (is_object($msg)) {
                    $msg = $msg->errors[0]->message;
                }
                return sprintf(_("There was an error contacting Twitter: %s"), $msg);
            }
        }
        /* Build values to pass to the javascript twitter client */
        $defaultText = addslashes(_("What are you working on now?"));
        $endpoint = Horde::url('services/twitter/', true);
        $inReplyToNode = $instance . '_inReplyTo';
        $inReplyToText = addslashes(_("In reply to:"));
        $justNowText = addslashes(_("Just now..."));
        $refresh = empty($this->_params['refresh_rate']) ? 300 : $this->_params['refresh_rate'];
        /* Add the client javascript / initialize it */
        $page_output->addScriptFile('twitterclient.js', 'horde');
        $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
        $favorite = _("Favorite");
        $unfavorite = _("Unfavorite");
        $script = <<<EOT
            Horde = window.Horde = window.Horde || {};
            Horde['twitter{$instance}'] = new Horde_Twitter({
               instanceid: '{$instance}',
               getmore: '{$instance}_getmore',
               input: '{$instance}_newStatus',
               spinner: '{$instance}_loading',
               content: '{$instance}_stream',
               contenttab: '{$instance}_contenttab',
               mentiontab: '{$instance}_mentiontab',
               mentions: '{$instance}_mentions',
               endpoint: '{$endpoint}',
               inreplyto: '{$inReplyToNode}',
               refreshrate: {$refresh},
               counter: '{$instance}_counter',
               strings: { inreplyto: '{$inReplyToText}', defaultText: '{$defaultText}', justnow: '{$justNowText}', favorite: '{$favorite}', unfavorite: '{$unfavorite}' }
            });
EOT;
        $page_output->addInlineScript($script, true);
        /* Build the UI */
        $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block'));
        $view->addHelper('Tag');
        $view->instance = $instance;
        $view->defaultText = $defaultText;
        $view->loadingImg = Horde_Themes_Image::tag('loading.gif', array('attr' => array('id' => $instance . '_loading', 'style' => 'display:none;')));
        $view->latestStatus = !empty($this->_profile->status) ? htmlspecialchars($this->_profile->status->text) : '';
        $view->latestDate = !empty($this->_profile->status) ? Horde_Date_Utils::relativeDateTime(strtotime($this->_profile->status->created_at), $GLOBALS['prefs']->getValue('date_format'), $GLOBALS['prefs']->getValue('twentyFour') ? "%H:%M" : "%I:%M %P") : '';
        $view->bodyHeight = empty($this->_params['height']) ? 350 : $this->_params['height'];
        return $view->render('twitter-layout');
    }
Пример #2
0
 /**
  * Build the Horde_View object for a FB Post.
  *
  * @param stdClass $post  The Facebook post object.
  *
  * @return string  The HTML to render the $post.
  */
 protected function _buildPost($post)
 {
     global $prefs;
     $facebook = $this->_getFacebookObject();
     $instance = $this->vars->instance;
     $uid = $facebook->auth->getLoggedInUser();
     $postView = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block'));
     $postView->actorImgUrl = $facebook->users->getThumbnail($post->from->id);
     $postView->actorProfileLink = Horde::externalUrl($facebook->users->getProfileLink($post->from->id), true);
     $postView->actorName = $post->from->name;
     $postView->message = empty($post->message) ? '' : $post->message;
     $postView->likes = $post->likes->count;
     $postView->postId = $post->id;
     $postView->privacy = $post->privacy;
     $postView->postInfo = sprintf(_("Posted %s"), Horde_Date_Utils::relativeDateTime($post->created_time, $prefs->getValue('date_format'), $prefs->getValue('twentyFour') ? "%H:%M %P" : "%I %M %P")) . ' ' . sprintf(_("Comments: %d"), $post->comments->count);
     $postView->type = $post->type;
     if (!empty($post->picture)) {
         $postView->attachment = new stdClass();
         $postView->attachment->image = $post->picture;
         if (!empty($post->link)) {
             $postView->attachment->link = Horde::externalUrl($post->link, true);
         }
         if (!empty($post->name)) {
             $postView->attachment->name = $post->name;
         }
         if (!empty($post->caption)) {
             $postView->attachment->caption = $post->caption;
         }
         if (!empty($post->icon)) {
             $postView->icon = $post->icon;
         }
         if (!empty($post->description)) {
             $postView->attachment->description = $post->description;
         }
     }
     if (!empty($post->place)) {
         $postView->place = array('name' => $post->place->name, 'link' => Horde::externalUrl($facebook->getFacebookUrl() . '/' . $post->place->id, true), 'location' => $post->place->location);
     }
     if (!empty($post->with_tags)) {
         $postView->with = array();
         foreach ($post->with_tags->data as $with) {
             $postView->with[] = array('name' => $with->name, 'link' => Horde::externalUrl($facebook->users->getProfileLink($with->id), true));
         }
     }
     // Actions
     $like = '';
     foreach ($post->actions as $availableAction) {
         if ($availableAction->name == 'Like') {
             $like = '<a href="#" onclick="Horde[\'' . $instance . '_facebook\'].addLike(\'' . $post->id . '\');return false;">' . _("Like") . '</a>';
         }
     }
     $likes = '';
     if ($post->likes->count) {
         foreach ($post->likes->data as $likeData) {
             if ($likeData->id == $uid && $post->likes->count > 1) {
                 $likes = sprintf(ngettext("You and %d other person likes this", "You and %d other people like this", $post->likes->count - 1), $post->likes->count - 1);
                 break;
             } elseif ($likeData->id == $uid) {
                 $likes = _("You like this");
                 break;
             }
         }
         if (empty($likes)) {
             $likes = sprintf(ngettext("%d person likes this", "%d persons like this", $post->likes->count), $post->likes->count) . (!empty($like) ? ' ' . $like : '');
         } else {
             $likes = $likes . !empty($like) ? ' ' . $like : '';
         }
     } else {
         $likes = $like;
     }
     $postView->likesInfo = $likes;
     return $postView->render('facebook_story');
 }
Пример #3
0
echo $this->profileLink;
?>
 <strong><?php 
echo $this->authorFullname;
?>
</strong> <em><?php 
echo $this->authorName;
?>
</em></a></div>
  <div class="hordeSmStreambody">
    <?php 
echo $this->body;
?>
    <div class="hordeSmStreaminfo">
      <?php 
echo sprintf(_("Posted %s via %s"), Horde_Date_Utils::relativeDateTime(strtotime($this->createdAt), $GLOBALS['prefs']->getValue('date_format')), $this->clientText);
?>
    </div>
    <?php 
if (!empty($this->tweet->retweeted_status)) {
    ?>
    <div class="hordeSmStreaminfo">
      <?php 
    echo sprintf(_("Retweeted by %s"), Horde::externalUrl('http://twitter.com/' . $this->escape($this->tweet->user->screen_name), true)) . '@' . $this->escape($this->tweet->user->screen_name);
    ?>
</a>
    </div>
    <?php 
}
?>
    <div class="hordeSmStreaminfo">