/** * Outputs the html code for Twitter button * * @since 4.0 * @access public * @param string * @return */ public function html() { if (!$this->isEnabled()) { return; } $this->addScript(); // Get the pinterest button style from the configuration $size = $this->getButtonSize(); $url = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->post->id, false, true); // Combine the introtext and the content $content = $this->post->intro . $this->post->content; // Get the media $media = $this->getMedia(); $contentLength = 350; $text = $this->post->intro . $this->post->content; $text = nl2br($text); $text = strip_tags($text); $text = trim(preg_replace('/\\s+/', ' ', $text)); $text = JString::strlen($text) > $contentLength ? JString::substr($text, 0, $contentLength) . '...' : $text; $title = $this->post->title; // Urlencode all the necessary properties. $url = urlencode($url); $text = urlencode($text); $media = urlencode($media); $placeholder = $this->getPlaceholderId(); $theme = EB::template(); $theme->set('size', $size); $theme->set('placeholder', $placeholder); $theme->set('url', $url); $theme->set('title', $title); $theme->set('media', $media); $theme->set('text', $text); $output = $theme->output('site/socialbuttons/pinterest'); return $output; }
/** * Generates the unsubscribe link for the email * * @since 5.0 * @access public * @param string * @return */ public function getUnsubscribeLink($data, $external = false) { $itemId = EBR::getItemId('latest'); // Generate the unsubscribe hash $hash = base64_encode(json_encode($data->export())); $link = EBR::getRoutedURL('index.php?option=com_easyblog&task=subscription.unsubscribe&data=' . $hash . '&Itemid=' . $itemId, false, $external); return $link; }
/** * Formats the message to be published on Twitter * * @since 4.0 * @access public * @param string * @return */ public function formatMessage(EasyBlogPost &$post, EasyBlogTableOAuth &$oauth) { // Get the message template to use to push to Twitter $content = !empty($oauth->message) ? $oauth->message : $this->config->get('main_twitter_message'); // Default vars to search / replace $search = array(); $replace = array(); // Replace the {title} tag if (JString::stristr($content, '{title}') !== false) { $search[] = '{title}'; $replace[] = $post->title; } // Replace the {introtext} tag if (JString::stristr($content, '{introtext}') !== false) { $search[] = '{introtext}'; $replace[] = $post->getIntro(EASYBLOG_STRIP_TAGS); } // Replace the {category} tag if (JString::stristr($content, '{category}') !== false) { // Get the primary category of the blog post $category = $post->getPrimaryCategory(); $search[] = '{category}'; $replace[] = $category->title; } // Get the final content $content = JString::str_ireplace($search, $replace, $content); // Replace the {link} tag if (JString::stristr($content, '{link}') !== false) { // Twitter will automatically shorten urls and a link will have a maximum of 22 chars // which leaves us with an offset of 118 characters $length = 22; $link = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $post->id, false, true); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $sh404exists = EBR::isSh404Enabled(); if ($this->app->isAdmin() && $sh404exists) { $link = rtrim(JURI::root(), '/') . '/index.php?option=com_easyblog&view=entry&id=' . $post->id; } // Get the remaining length that we can use. $remaining = 140 - $length; // Split the message $parts = explode('{link}', $content); for ($i = 0; $i < count($parts); $i++) { $tmp =& $parts[$i]; $tmpLength = JString::strlen($tmp); if ($tmpLength > $remaining) { if ($remaining <= 0) { $tmp = JString::substr($tmp, 0, 0); } else { if ($remaining < 6) { $tmp = JString::substr($tmp, 0, $remaining); } else { $tmp = JString::substr($tmp, 0, $remaining - 3) . JText::_('COM_EASYBLOG_ELLIPSES'); } $remaining = 0; } } else { $remaining -= $tmpLength; } } $content = implode($link, $parts); } else { $content = JString::substr($content, 0, 136) . JText::_('COM_EASYBLOG_ELLIPSES'); } return $content; }
/** * Retrieves the external permalink for this blog post * * @since 4.0 * @access public * @param string * @return */ public function getExternalPermalink($format = null) { $link = EBR::getRoutedURL('index.php?option=com_easyblog&view=categories&layout=listings&id=' . $this->id, false, true, true); $link = EBR::appendFormatToQueryString($link, $format); return $link; }
/** * Retrieve the extracted content of a blog post that can be formatted to Facebook * * @since 4.0 * @access public * @param string * @return */ public function extractPostData(EasyBlogPost &$post) { // Prepare the result data $data = new stdClass(); // Get the content's source $source = $this->config->get('integrations_facebook_source'); // Get the blog content $data->content = $post->getIntro(true); // Get the blog's image to be pushed to Facebook $data->image = $post->getImage('thumbnail', true, true); // var_dump($data->image);exit; // If there's no blog image, try to get the image from the content if (!$data->image) { // lets get full content. $fullcontent = $post->getContent('entry'); $data->image = EB::string()->getImage($fullcontent); } // If there's still no image, use author's avatar if (!$data->image) { $author = $post->getAuthor(); $data->image = $author->getAvatar(); } // if still no image. lets try to get from placeholder. if (!$data->image) { $data->image = EB::getPlaceholderImage(); } // Format the content so that it respects the length $max = $this->config->get('integrations_facebook_blogs_length'); // Remove adsense codes $data->content = EB::adsense()->strip($data->content); if ($max && JString::strlen($data->content) > $max) { $data->content = JString::substr($data->content, 0, $max) . JText::_('COM_EASYBLOG_ELLIPSES'); } // Get the url to the blog $data->url = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $post->id, false, true); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $sh404exists = EBR::isSh404Enabled(); if ($this->app->isAdmin() && $sh404exists) { $data->url = EB::getExternalLink('index.php?option=com_easyblog&view=entry&id=' . $post->id); } return $data; }
/** * Process email notifications * * @since 4.0 * @access public * @param string * @return */ public function processEmails($isModerated = false, $blog) { $config = EB::config(); // Fix contents of comments. $content = $this->comment; // Initialize what we need $commentAuthor = $this->name; $commentAuthorEmail = $this->email; $commentAuthorAvatar = JURI::root() . 'components/com_easyblog/assets/images/default_blogger.png'; // Get the date object $date = EB::date(); // Format the date $commentDate = $date->format(JText::_('DATE_FORMAT_LC3')); $teamLink = ''; if (isset($blog->team)) { $teamLink = '&team=' . $blog->team; } // Get the author data if ($this->created_by != 0) { $user = $this->getAuthor(); $commentAuthor = $user->getName(); $commentAuthorEmail = $user->user->email; $commentAuthorAvatar = $user->getAvatar(); } $blogAuthor = EB::user($blog->created_by); $data = array('blogTitle' => $blog->title, 'blogIntro' => $blog->intro, 'blogContent' => $blog->content, 'blogLink' => EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry' . $teamLink . '&id=' . $blog->id, false, true), 'commentTitle' => empty($comment->title) ? '-' : $comment->title, 'commentContent' => $content, 'commentAuthor' => $commentAuthor, 'commentAuthorAvatar' => $commentAuthorAvatar, 'commentDate' => $commentDate, 'commentLink' => EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry' . $teamLink . '&id=' . $blog->id, false, true) . '#comment-' . $this->id); // Get a list of emails $emails = array(); // Get the notification library $notification = EB::notification(); if ($isModerated) { $hashkey = EB::table('HashKeys'); $hashkey->uid = $this->id; $hashkey->type = 'comments'; $hashkey->store(); // Generate the approval and reject links $data['approveLink'] = EBR::getRoutedURL('index.php?option=com_easyblog&task=comments.approve&key=' . $hashkey->key, false, true); $data['rejectLink'] = EBR::getRoutedURL('index.php?option=com_easyblog&task=comments.reject&key=' . $hashkey->key, false, true); // Send email notification to admin. if ($config->get('custom_email_as_admin')) { $notification->getCustomEmails($emails); } else { $notification->getAdminEmails($emails); } // @rule: Send email notification to blog authors. if ($config->get('notification_commentmoderationauthor')) { $obj = new stdClass(); $obj->unsubscribe = false; $obj->email = $blogAuthor->user->email; $emails[$blogAuthor->user->email] = $obj; } $notification->send($emails, JText::_('COM_EASYBLOG_NEW_COMMENT_ADDED_MODERATED_TITLE'), 'comment.moderate', $data); return true; } if (!$isModerated) { // Get a list of admin emails $notification->getAdminNotificationEmails($emails); // Send notification to blog authors. if ($config->get('notification_commentauthor')) { $obj = new stdClass(); $obj->unsubscribe = false; $obj->email = $blogAuthor->user->email; $emails[$blogAuthor->user->email] = $obj; } // Send notifications to blog subscribers if ($config->get('main_subscription') && $blog->subscription == '1' && $config->get('notification_commentsubscriber')) { $notification->getBlogSubscriberEmails($emails, $blog->id); } // Do not send to the person that commented on the blog post. unset($emails[$commentAuthorEmail]); if (!$emails) { return false; } // Send the emails now. $subject = JText::sprintf('COM_EASYBLOG_NEW_COMMENT_ADDED_IN_POST', $blog->title); $notification->send($emails, $subject, 'comment.new', $data); return true; } }
/** * Indexes a post on the site * * @since 5.0 * @access public * @param FinderIndexerResult The item to index * @param string The item's format * @return void */ protected function index(FinderIndexerResult $item, $format = 'html') { // Check if the extension is enabled if (!$this->exists()) { return; } // Build the necessary route and path information. $item->url = 'index.php?option=com_easyblog&view=entry&id=' . $item->id; $item->route = EBR::getRoutedURL($item->url, false, true); // Remove any /administrator/ segments from the url since the indexer could be executed from the back end $item->route = $this->removeAdminSegment($item->route); // Get the content path $item->path = FinderIndexerHelper::getContentPath($item->route); // If there is access defined, just set it to 2 which is special privileges. if (!$item->access || $item->access == 0) { $item->access = 1; } else { if ($item->access > 0) { $item->access = 2; } } // Load up the post item $post = EB::post(); $post->load($item->id); // Get the intro text of the content $item->summary = $post->getIntro(); // Get the contents $item->body = $post->getContent('entry', false); // If the post is password protected, we do not want to display the contents if ($post->isPasswordProtected()) { $item->summary = JText::_('PLG_FINDER_EASYBLOG_PASSWORD_PROTECTED'); } else { // we want to get custom fields values. $fields = $post->getCustomFields(); $fieldlib = EB::fields(); $customfields = array(); if ($fields) { foreach ($fields as $field) { if ($field->group->hasValues($post)) { foreach ($field->fields as $customField) { $eachField = $fieldlib->get($customField->type); $customfields[] = $eachField->text($customField, $post); } } } $customfieldvalues = implode(' ', $customfields); $item->body = $item->body . ' ' . $customfieldvalues; } } // Add the author's meta data $item->metaauthor = !empty($item->created_by_alias) ? $item->created_by_alias : $item->author; $item->author = !empty($item->created_by_alias) ? $item->created_by_alias : $item->author; // If the post has an image, use it $image = $post->getImage('thumbnail', false, true); // If there's no image, try to scan the contents for an image to be used if (!$image && $post->isLegacy()) { $image = EB::string()->getImage($item->body); } // If we still can't locate any images, use the placeholder image if (!$image) { $image = EB::getPlaceholderImage(); } $registry = new JRegistry(); $registry->set('image', $image); $item->params = $registry; // Add the meta-data processing instructions. $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor'); $item->addInstruction(FinderIndexer::META_CONTEXT, 'author'); // Add the type taxonomy data. $item->addTaxonomy('Type', 'EasyBlog'); // Add the author taxonomy data. if (!empty($item->author) || !empty($item->created_by_alias)) { $item->addTaxonomy('Author', !empty($item->created_by_alias) ? $item->created_by_alias : $item->author); } // Add the category taxonomy data. $item->addTaxonomy('Category', $item->category, $item->cat_state, $item->cat_access); // Add the language taxonomy data. if (empty($item->language)) { $item->language = '*'; } $item->addTaxonomy('Language', $item->language); // Get content extras. FinderIndexerHelper::getContentExtras($item); // For Joomla 3.0, the indexer is assigned to the property // Index the item. if (EB::isJoomla30()) { return $this->indexer->index($item); } return FinderIndexer::index($item); }
/** * Retrieves the object of the subscription item * * @since 5.0 * @access public * @param string * @return */ public function getObject() { if ($this->utype == 'category') { $obj = EB::table('Category'); $obj->load($this->uid); $obj->objAvatar = $obj->getAvatar(); $obj->objPermalink = $obj->getPermalink(); } if ($this->utype == 'blogger') { $obj = EB::user($this->uid); $obj->objAvatar = $obj->getAvatar(); $obj->objPermalink = $obj->getPermalink(); } if ($this->utype == 'site') { $obj = new stdClass(); $obj->title = EB::config()->get('main_title'); $obj->permalink = EBR::getRoutedURL('index.php?option=com_easyblog', false, true); $obj->objAvatar = ''; $obj->objPermalink = $obj->permalink; } if ($this->utype == 'teamblog' || $this->utype == 'team') { $team = EB::table('Teamblog'); $team->load($this->uid); $obj = new stdClass(); $obj->title = $team->title; $obj->objAvatar = $team->getAvatar(); $obj->objPermalink = $team->getPermalink(); } if ($this->utype == 'entry') { // Get the post object $post = EB::post($this->uid); $obj = new stdClass(); $obj->title = $post->title; $obj->objPermalink = $post->getPermalink(); $obj->objAvatar = $post->getAuthor()->getAvatar(); } return $obj; }
/** * Sends notifications out * * @since 5.0 * @access public * @param string * @return */ public function notify($reject = false) { $notification = EB::notification(); // Load up the team blog $team = EB::table('TeamBlog'); $team->load($this->team_id); // Send email notifications to the requester $requester = JFactory::getUser($this->user_id); $data = array('teamName' => $team->title, 'teamDescription' => $team->getDescription(), 'teamAvatar' => $team->getAvatar(), 'teamLink' => EBR::getRoutedURL('index.php?option=com_easyblog&view=teamblog&layout=listings&id=' . $this->team_id, false, true)); $template = $reject ? 'team.rejected' : 'team.approved'; // Load site language file EB::loadLanguages(); $subject = $reject ? JText::sprintf('COM_EASYBLOG_TEAMBLOGS_REQUEST_REJECTED', $team->title) : JText::sprintf('COM_EASYBLOG_TEAMBLOGS_REQUEST_APPROVED', $team->title); $obj = new stdClass(); $obj->unsubscribe = false; $obj->email = $requester->email; $emails = array($obj); $notification->send($emails, $subject, $template, $data); }
/** * Retrieves the external permalink for this blog post * * @since 4.0 * @access public * @param string * @return */ public function getExternalPermalink() { static $link = array(); if (!isset($link[$this->id])) { // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $sh404 = EBR::isSh404Enabled(); $link[$this->id] = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->id, true, true); $app = JFactory::getApplication(); // If this is being submitted from the back end we do not want to use the sef links because the URL will be invalid if ($app->isAdmin() && $sh404) { $link[$this->id] = rtrim(JURI::root(), '/') . $link[$this->id]; } } return $link[$this->id]; }
/** * * * @since 5.0 * @access public * @param string * @return */ public function insetCommentActivity($comment, EasyBlogPost $post) { if (!$this->exists()) { return false; } // We do not want to add activities if new comment activity is disabled. if (!$this->config->get('integrations_jomsocial_comment_new_activity')) { return false; } $command = 'easyblog.comment.add'; // Get the post title $title = $this->getPostTitle($post); // Get the permalink $permalink = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $comment->post_id, false, true) . '#comment-' . $comment->id; // Get the content $content = ''; if ($this->config->get('integrations_jomsocial_submit_content')) { $content = $comment->comment; $content = EB::comment()->parseBBCode($content); $content = nl2br($content); $content = strip_tags($content); $content = JString::substr($content, 0, $this->config->get('integrations_jomsocial_comments_length')); } $obj = new stdClass(); $obj->title = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_COMMENT_ADDED', $permalink, $title); if (!$comment->created_by) { $obj->title = JText::sprintf('COM_EASYBLOG_JS_ACTIVITY_GUEST_COMMENT_ADDED', $permalink, $title); } $obj->content = $content; $obj->cmd = $command; $obj->actor = $comment->created_by; $obj->target = 0; $obj->app = 'easyblog'; $obj->cid = $comment->id; if ($this->config->get('integrations_jomsocial_activity_likes')) { $obj->like_id = $comment->id; $obj->like_type = 'com_easyblog.comments'; } if ($this->config->get('integrations_jomsocial_activity_comments')) { $obj->comment_id = $comment->id; $obj->comment_type = 'com_easyblog.comments'; } // add JomSocial activities CFactory::load('libraries', 'activities'); CActivityStream::add($obj); }
/** * Retrieves the url of the post * * @since 5.0 * @access public * @param string * @return */ public function getUrl() { $url = EBR::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->post->id, false, true); return $url; }
/** * Retrieves the external permalink for this author * * @since 4.0 * @access public * @param string * @return */ public function getExternalPermalink() { $link = EBR::getRoutedURL('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $this->id, false, true, true); return $link; }
/** * Retrieves the object of the subscription item * * @since 5.0 * @access public * @param string * @return */ public function getObject() { if ($this->utype == 'category') { $obj = EB::table('Category'); $obj->load($this->uid); } if ($this->utype == 'blogger') { $obj = EB::user($this->uid); } if ($this->utype == 'site') { $obj = new stdClass(); $obj->title = EB::config()->get('main_title'); $obj->permalink = EBR::getRoutedURL('index.php?option=com_easyblog', false, true); } if ($this->utype == 'entry') { $obj = new stdClass(); $obj->title = 'Entry'; $obj->permalink = ''; } return $obj; }
/** * Revokes the user's oauth access * * @since 5.0 * @access public * @param string * @return */ public function revoke() { // Require the user to be logged in EB::requireLogin(); // The default url $url = EBR::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false); // Get any redirection url $redirect = $this->input->get('redirect', '', 'default'); // Get the oauth client $type = $this->input->get('client', '', 'cmd'); // If redirect url is provided, we know for sure where to redirect the user to if ($redirect) { $url = base64_decode($redirect); } // Load up the oauth object $table = EB::table('OAuth'); $table->loadByUser($this->my->id, $type); // Load up the oauth client and set the access $client = EB::oauth()->getClient($type); $client->setAccess($table->access_token); // Get the callback url $callback = EBR::getRoutedURL('index.php?option=com_easyblog&task=oauth.grant&client=' . $type, false, true); // Get the consumer and secret key $key = $this->config->get('integrations_' . $type . '_api_key'); $secret = $this->config->get('integrations_' . $type . '_secret_key'); // Try to revoke the app $state = $client->revoke(); // After revoking the access, delete the oauth record $table->delete(); $this->info->set(JText::_('COM_EASYBLOG_APPLICATION_REVOKED_SUCCESSFULLY'), 'success'); return $this->app->redirect($url, false); }