/** * Renders the maps for a blog post * * @since 4.0 * @access public * @param string * @return */ public function html(EasyBlogPost &$post) { static $loaded = false; if (!$post->hasLocation()) { return; } $language = $this->config->get('main_locations_blog_language'); if (!$loaded) { $this->doc->addScript('https://maps.googleapis.com/maps/api/js?sensor=true&language=' . $language); } // Get the map configuration $static = $this->config->get('main_locations_static_maps'); $type = $this->config->get('main_locations_map_type'); $maxZoom = $this->config->get('main_locations_max_zoom_level'); $minZoom = $this->config->get('main_locations_min_zoom_level'); $defaultZoom = $this->config->get('main_locations_default_zoom_level', '17'); // Generate a unique id $uid = uniqid(); $template = EB::template(); $template->set('uid', $uid); $template->set('defaultZoom', $defaultZoom); $template->set('minZoom', $minZoom); $template->set('maxZoom', $maxZoom); $template->set('defaultZoom', $defaultZoom); $template->set('type', $type); $template->set('language', $language); $template->set('post', $post); $namespace = 'site/maps/static'; if (!$this->config->get('main_locations_static_maps')) { $namespace = 'site/maps/interactive'; } $output = $template->output($namespace); return $output; }
/** * New method to retrieve ratings form * * @since 5.0 * @access public * @param string * @return */ public function html(EasyBlogPost $post, $elementId, $text = '', $disabled = false) { // If ratings has been disabled, do not proceed here. if (!$this->config->get('main_ratings')) { return false; } // Generate the hash for the current user $hash = !$this->my->guest ? '' : JFactory::getSession()->getId(); // Determines if the current user has already voted $voted = $post->hasVoted($this->my->id); $locked = false; if ($voted || ($this->my->guest && !$this->config->get('main_ratings_guests') || $disabled)) { $locked = true; } // Get the rating value for the post $value = $post->getRatings(); // Only display ratings on entry view $entry = $this->input->get('view', '', 'cmd') == 'entry' ? true : false; $template = EB::template(); $template->set('entry', $entry); $template->set('voted', $voted); $template->set('elementId', $elementId); $template->set('rating', $value->ratings); $template->set('total', $value->total); $template->set('locked', $locked); $template->set('text', $text); $template->set('uid', $post->id); $template->set('type', EASYBLOG_RATINGS_ENTRY); return $template->output('site/ratings/form'); }
/** * Auto post to social network sites * * @since 5.0 * @access public * @param string * @return */ public function shareSystem(EasyBlogPost &$post, $force = false) { // Determines if the primary category of this post requires auto posting or not $category = $post->getPrimaryCategory(); if (!$category->autopost) { return; } // Get a list of system oauth clients. $model = EB::model('Oauth'); $clients = $model->getSystemClients(); foreach ($clients as $client) { // If this is a new post, ensure that it respects the settings before auto posting if ($post->isNew() && !$this->config->get('integrations_' . $client->type . '_centralized_auto_post') && !$force) { continue; } // If the post is updated, ensure that it respects the settings before auto posting if (!$post->isNew() && !$this->config->get('integrations_' . $client->type . '_centralized_send_updates') && !$force) { continue; } $table = EB::table('OAuth'); $table->bind($client); // Push the item now $table->push($post); } }
/** * Generates the html codes for adsense * * @since 5.0 * @access public * @param string * @return */ public function html(EasyBlogPost $post) { $result = new stdClass(); $result->header = ''; $result->beforecomments = ''; $result->footer = ''; // Standard code $code = $this->config->get('integration_google_adsense_code'); // Responsive code $responsiveCode = $this->config->get('integration_google_adsense_responsive_code'); if (!$code || $responsiveCode && $this->config->get('integration_google_adsense_responsive')) { $code = $responsiveCode; } // Determines the location of the ads $location = $this->config->get('integration_google_adsense_display'); // Ensure that adsense is enabled if (!$this->config->get('integration_google_adsense_enable')) { return $result; } // Determines who should we display the ads to $displayAccess = $this->config->get('integration_google_adsense_display_access'); // If user is a guest and guest visibilty for ads are disabled, hide it. if ($displayAccess == 'members' && $this->my->guest) { return $result; } // If user is a guest, and settings is configured to be displayed to guests only, hide it. if ($this->config->get('integration_google_adsense_display_access') == 'guests' && !$this->my->guest) { return $result; } // Check if author enabled their own adsense $adsense = EB::table('Adsense'); $adsense->load($post->getAuthor()->id); if ($adsense->code && $adsense->published) { $code = $adsense->code; $location = $adsense->display; } if ($location == 'userspecified') { return $result; } // If we can't find any adsense code, skip this if (!$code) { return $result; } $responsive = $this->config->get('integration_google_adsense_responsive'); $theme = EB::template(); $theme->set('code', $code); $namespace = 'site/adsense/responsive'; if (!$responsive) { $namespace = 'site/adsense/code'; } $html = $theme->output($namespace); if ($location == 'both') { $result->header = $html; $result->footer = $html; } else { $result->{$location} = $html; } return $result; }
/** * Attaches the open graph tags in the header * * @since 4.0 * @access public * @param string * @return */ public function addOpenGraphTags(EasyBlogPost &$post) { if (!$this->config->get('main_facebook_opengraph')) { return; } // Get the absolute permalink for this blog item. $url = $post->getExternalPermalink(); // Get the image of the blog post. $image = self::getImage($post); // Add the blog image. $this->doc->addCustomTag('<meta property="og:image" content="' . $image . '"/> '); // If app id is provided, attach it on the head $appId = $this->config->get('main_facebook_like_appid'); $adminId = $this->config->get('main_facebook_like_admin'); if ($appId) { $this->doc->addCustomTag('<meta property="fb:app_id" content="' . $appId . '"/> '); } if ($adminId) { $this->doc->addCustomTag('<meta property="fb:admins" content="' . $adminId . '"/>'); } // Convert double quotes to html entities. $title = htmlspecialchars($post->title, ENT_QUOTES); // Add the title tag $this->doc->addCustomTag('<meta property="og:title" content="' . $title . '" />'); // Load any necessary meta data for the blog $meta = $post->loadMeta(); // If there's a meta set for the blog, use the stored meta version $description = !empty($post->description) ? $post->description : $post->getIntro(); // Remove unwanted tags $description = EB::stripEmbedTags($description); // Remove newlines $description = str_ireplace("\r\n", "", $description); // Replace with spaces $description = JString::str_ireplace(' ', ' ', $description); // Remove any html tags $description = strip_tags($description); // Ensure that newlines wouldn't affect the header $description = trim($description); // Replace htmlentities with the counterpert // Perhaps we need to explicitly replace with a space? $description = html_entity_decode($description); // Remove any quotes (") from the content $description = str_ireplace('"', '', $description); // If there's a maximum length specified, we should respect it. $max = $this->config->get('integrations_facebook_blogs_length'); if ($max) { if (JString::strlen($description) > $max) { $description = JString::substr($description, 0, $max) . JText::_('COM_EASYBLOG_ELLIPSES'); } } $this->doc->addCustomTag('<meta property="og:description" content="' . $description . '" />'); $this->doc->addCustomTag('<meta property="og:type" content="article" />'); $this->doc->addCustomTag('<meta property="og:url" content="' . $url . '" />'); return true; }
/** * Renders the comment count for Komento * * @since 5.0 * @access public * @param string * @return */ public function getCount(EasyBlogPost $post) { if (!$this->exists()) { return; } FD::language()->load('com_easysocial', JPATH_ROOT); $url = $post->getPermalink(); $comments = FD::comments($post->id, 'blog', SOCIAL_APPS_GROUP_USER, $url); $count = $comments->getCount(); return $count; }
/** * Pushes to the oauth site * * @since 4.0 * @access public * @param string * @return */ public function push(EasyBlogPost &$post) { // When there is no access token set on this oauth record, we shouldn't do anything if (!$this->access_token) { $this->setError(JText::sprintf('No access token available for autoposting on %1$s', $this->type)); return false; } $config = EB::config(); // Determines if this user is really allowed to auto post $author = $post->getAuthor(); // Check the author's acl $acl = EB::acl($author->id); $rule = 'update_' . $this->type; if (!$acl->get($rule) && !EB::isSiteAdmin($post->created_by)) { $this->setError(JText::sprintf('No access to autopost on %1$s', $this->type)); return false; } // we only check if the autopost on blog edit is disabled. if (!$config->get('integrations_' . $this->type . '_centralized_send_updates')) { // Check if the blog post was shared before. if ($this->isShared($post->id)) { $this->setError(JText::sprintf('Post %1$s has been shared to %2$s before.', $post->id, $this->type)); return false; } } // Ensure that the oauth data has been set correctly $config = EB::config(); $key = $config->get('integrations_' . $this->type . '_api_key'); $secret = $config->get('integrations_' . $this->type . '_secret_key'); // If either of this is empty, skip this if (!$key || !$secret) { return false; } // Set the callback URL $callback = JURI::base() . 'index.php?option=com_easyblog&task=oauth.grant&type=' . $this->type; // Now we do the real thing. Get the library and push $lib = EB::oauth()->getClient($this->type, $key, $secret, $callback); $lib->setAccess($this->access_token); // Try to share the post now $state = $lib->share($post, $this); if ($state === true) { $history = EB::table('OAuthPost'); $history->load(array('oauth_id' => $this->id, 'post_id' => $post->id)); $history->post_id = $post->id; $history->oauth_id = $this->id; $history->created = EB::date()->toSql(); $history->modified = EB::date()->toSql(); $history->sent = EB::date()->toSql(); $history->store(); return true; } return false; }
/** * Attaches the Twitter card into the page header * * @since 4.0 * @access public * @param EasyBlogTableBlog * @return */ public static function addCard(EasyBlogPost &$blog) { $config = EB::config(); $doc = JFactory::getDocument(); // Check if the current settings would want to display the twitter cards if (!$config->get('main_twitter_cards')) { return; } // Get the absolute permalink for this blog item. $url = $blog->getExternalPermalink(); // Get the image of the blog post. $image = self::getImage($blog); if ($image) { $doc->addCustomTag('<meta property="twitter:image" content="' . $image . '"/>'); } // @task: Get Joomla's document object. $doc = JFactory::getDocument(); // Convert double quotes to html entity in blog title. $title = htmlspecialchars($blog->title, ENT_QUOTES); // Add card definition. $doc->addCustomTag('<meta property="twitter:card" content="summary" />'); $doc->addCustomTag('<meta property="twitter:url" content="' . $url . '" />'); $doc->addCustomTag('<meta property="twitter:title" content="' . $title . '" />'); // Retrieve the stored meta for the blog post $meta = $blog->loadMeta(); // If there's a meta set for the blog, use the stored meta version $description = !empty($meta->description) ? $meta->description : $blog->getIntro(); // Remove unwanted tags $description = EB::stripEmbedTags($description); // Add any slashes $description = addslashes($description); // Remove any html tags $description = strip_tags($description); // Ensure that newlines wouldn't affect the header $description = trim($description); // Replace htmlentities with the counterpert // Perhaps we need to explicitly replace with a space? $description = html_entity_decode($description); // Remove any quotes (") from the content $description = str_ireplace('"', '', $description); // Twitter's card maximum length is only set to 137 $maxLength = 137; if (JString::strlen($description) > $maxLength) { $description = JString::substr($description, 0, $maxLength) . JText::_('COM_EASYBLOG_ELLIPSES'); } $doc->addCustomTag('<meta property="twitter:description" content="' . $description . '" />'); return true; }
/** * Sends a ping to pingomatic servers * * @since 5.0 * @access public * @param string * @return */ public function ping(EasyBlogPost &$post) { // If this is disabled, don't do anything if (!$this->config->get('main_pingomatic')) { return false; } // Get the title of the blog post $title = EB::string()->escape($post->title); // Get the permalink to the post $link = $post->getExternalPermalink(); $link = urlencode($link); // Construct the xml content to send to pingomatic $content = '<?xml version="1.0"?>' . '<methodCall>' . ' <methodName>weblogUpdates.ping</methodName>' . ' <params>' . ' <param>' . ' <value>' . $title . '</value>' . ' </param>' . ' <param>' . ' <value>' . $url . '</value>' . ' </param>' . ' </params>' . '</methodCall>'; $headers = "POST / HTTP/1.0\r\n" . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)\r\n" . "Host: rpc.pingomatic.com\r\n" . "Content-Type: text/xml\r\n" . "Content-length: " . strlen($content); $request = $headers . "\r\n\r\n" . $content; $response = ""; $fs = fsockopen('rpc.pingomatic.com', 80, $errno, $errstr); if ($fs) { fwrite($fs, $request); while (!feof($fs)) { $response .= fgets($fs); } if ($debug) { echo "<xmp>" . $response . "</xmp>"; } fclose($fs); preg_match_all("/<(name|value|boolean|string)>(.*)<\\/(name|value|boolean|string)>/U", $response, $ar, PREG_PATTERN_ORDER); for ($i = 0; $i < count($ar[2]); $i++) { $ar[2][$i] = strip_tags($ar[2][$i]); } return array('status' => $ar[2][1] == 1 ? 'ko' : 'ok', 'msg' => $ar[2][3]); } else { if ($debug) { echo "<xmp>" . $errstr . " (" . $errno . ")</xmp>"; } return array('status' => 'ko', 'msg' => $errstr . " (" . $errno . ")"); } }
/** * Notifies the site owners when a new report is made on the site * * @since 5.0 * @access public * @param string * @return */ public function notify(EasyBlogPost &$post) { $config = EB::config(); // Send notification to site admins when a new blog post is reported $data = array(); $data['blogTitle'] = $post->title; $data['blogLink'] = $post->getExternalPermalink(); // Get the author of this reporter $author = $this->getAuthor(); $data['reporterAvatar'] = $author->getAvatar(); $data['reporterName'] = $author->getName(); $data['reporterLink'] = $author->getProfileLink(); $data['reason'] = $this->reason; $data['reportDate'] = EB::date()->format(JText::_('DATE_FORMAT_LC2')); // If blog post is being posted from the back end and SH404 is installed, we should just use the raw urls. $app = JFactory::getApplication(); if ($app->isAdmin() && EBR::isSh404Enabled()) { $data['blogLink'] = JURI::root() . 'index.php?option=com_easyblog&view=entry&id=' . $post->id; } // Set the title of the email $subject = JString::substr($post->title, 0, $config->get('main_mailtitle_length')); $subject = JText::sprintf('COM_EASYBLOG_EMAIL_TITLE_NEW_REPORT', $subject) . ' ...'; // Get the notification library $notification = EB::notification(); $recipients = array(); // Fetch custom emails defined at the back end. if ($config->get('notification_blogadmin')) { if ($config->get('custom_email_as_admin')) { $notification->getCustomEmails($recipients); } else { $notification->getAdminEmails($recipients); } } if (!empty($recipients)) { $notification->send($recipients, $subject, 'post.reported', $data); } }
/** * Retrieves the next post in line * * @since 5.0 * @access public * @param string * @return */ public function getPostNavigation(EasyBlogPost $post, $navigationType) { $db = EB::db(); $my = JFactory::getUser(); $config = EB::config(); $keys = array('prev', 'next'); $nav = new stdClass(); // Get the active menu $active = JFactory::getApplication()->getMenu()->getActive(); $catAccess = array(); $queryInclude = ''; $teamId = $post->getTeamAssociation(); $author = $post->getAuthor(); // // If there is an active menu for EasyBlog, check if there's any filtering by categories // if ($active) { // $cats = EB::getCategoryInclusion($active->params->get('inclusion')); // if ($cats && !is_array($cats)) { // $cats = array($cats); // } // $catAccess['include'] = $cats; // } // // sql for category access // $catLib = EB::category(); // $catAccessSQL = $catLib->genAccessSQL( 'a.`id`', $catAccess); foreach ($keys as $key) { $query = array(); $query[] = 'SELECT a.`id`, a.`title`'; $query[] = ' FROM `#__easyblog_post` AS `a`'; $query[] = ' WHERE a.`published` = ' . $db->Quote(EASYBLOG_POST_PUBLISHED); $query[] = ' AND a.`state` = ' . $db->Quote(EASYBLOG_POST_NORMAL); // EasySocial integrations $query[] = EB::easysocial()->buildPrivacyQuery('a'); // Jomsocial integrations $query[] = EB::jomsocial()->buildPrivacyQuery(); // Blog privacy settings if ($my->guest) { $query[] = 'AND a.' . $db->qn('access') . '=' . $db->Quote(BLOG_PRIVACY_PUBLIC); } // Exclude private categories // $query[] = 'AND (' . $catAccessSQL . ')'; // If the current menu is blogger mode, we need to respect this by only loading author related items $isBloggerMode = EBR::isBloggerMode(); if ($isBloggerMode !== false) { $query[] = 'AND a.' . $db->qn('created_by') . '=' . $db->Quote($isBloggerMode); $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE); } // Filter the next / previous link by team if ($navigationType == 'team' && $teamId) { $query[] = 'AND (a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_TEAM) . ' AND a.' . $db->qn('source_id') . '=' . $db->Quote($teamId) . ')'; } // Filter the next / previous by author if ($navigationType == 'author') { $query[] = 'AND a.' . $db->qn('created_by') . '=' . $db->Quote($author->id); $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE); } // Filter the next / previous post items from site wide if ($navigationType == 'site') { $query[] = 'AND a.' . $db->qn('source_type') . '=' . $db->Quote(EASYBLOG_POST_SOURCE_SITEWIDE); } // When language filter is enabled, we need to detect the appropriate contents $filterLanguage = JFactory::getApplication()->getLanguageFilter(); if ($filterLanguage) { $query[] = EBR::getLanguageQuery('AND', 'a.language'); } if ($key == 'prev') { $query[] = ' AND a.`created` < ' . $db->Quote($post->created); $query[] = ' ORDER BY a.`created` DESC'; } if ($key == 'next') { $query[] = ' AND a.`created` > ' . $db->Quote($post->created); $query[] = ' ORDER BY a.`created` ASC'; } $query[] = 'LIMIT 1'; $query = implode(' ', $query); $db->setQuery($query); $result = $db->loadObject(); $nav->{$key} = $result; } return $nav; }
/** * 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; }
/** * Binds the post data * * @since 5.0 * @access public * @param string * @return */ public static function bindPost(EasyBlogPost &$post, $data, $publish) { $config = EB::config(); $acl = EB::acl(); $my = JFactory::getUser(); $postData = array(); // Default properties $postData['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY; $postData['title'] = ''; $postData['intro'] = ''; $postData['content'] = ''; $postData['tags'] = array(); $postData['allowcomment'] = true; $postData['published'] = EASYBLOG_POST_PUBLISHED; $postData['created'] = EB::date()->toSql(); $postData['publish_up'] = $postData['created']; $postData['created_by'] = $my->id; $postData['access'] = false; // Should these be read from configuration? $postData['frontpage'] = true; $postData['send_notification_emails'] = true; // Post title // title if (isset($data['title']) && !empty($data['title'])) { $postData['title'] = $data['title']; } // Tags from marsedit // mt_tags if (isset($data['mt_tags']) && !empty($data['mt_tags'])) { if (is_array($data['mt_tags'])) { $data['mt_tags'] = implode(',', $data['mt_tags']); } $postData['tags'] = $data['mt_tags']; } // Keywords could possibly be used as tags // mt_keywords if (!$postData['tags'] && isset($data['mt_keywords']) && $data['mt_keywords']) { $postData['tags'] = $data['mt_keywords']; } // Post status from mars edit // post_status if (isset($data['post_status'])) { $status = $data['post_status']; if ($status == 'publish' || $status == 'private') { $postData['published'] = EASYBLOG_POST_PUBLISHED; } if ($status == 'private' || $status == 'pending') { $postData['private'] = true; } if ($status == 'draft') { $postData['published'] = EASYBLOG_POST_UNPUBLISHED; } if ($status == 'schedule') { $postData['published'] = EASYBLOG_POST_SCHEDULED; } } // Determines if the post allow comments // mt_allow_comments if (isset($data['mt_allow_comments'])) { if (is_numeric($data['mt_allow_comments'])) { $postData['allowcomment'] = $data['mt_allow_comments'] == 1; } else { $postData['allowcomment'] = $data['mt_allow_comments'] == 'open'; } } // Post content // description if (isset($data['description']) && !empty($data['description'])) { $postData['intro'] = $data['description']; } // If intro text is still empty, try to check for mt_excerpt if (!$postData['intro'] && isset($data['mt_excerpt']) && !empty($data['mt_excerpt'])) { $postData['intro'] = $data['mt_excerpt']; } // Main content // mt_text_more if (isset($data['mt_text_more']) && !empty($data['mt_text_more'])) { $postData['content'] = $data['mt_text_more']; } if (!$postData['content'] && isset($data['more_text']) && $data['more_text']) { $postData['content'] = $data['more_text']; } // Wordpress API? Doesn't seem like we need this // mt_convert_breaks // Wordpress API? Permalink? // wp_slug if (isset($data['wp_slug']) && !empty($data['wp_slug'])) { $postData['permalink'] = $data['wp_slug']; } // Get the timestamp from the post if (isset($data['date_created_gmt']) && $data['date_created_gmt']) { $date = EB::date($data['date_created_gmt']); $postData['created'] = $date->toSql(); } // If user wants to set a custom date for the creation date if (isset($data['dateCreated']) && $data['dateCreated']) { $now = EB::date(); $tsNow = $now->toUnix(); $date = EB::date($data['dateCreated']); // We need to add additional 10 seconds becuse blogsy is always 5s faster $tsDate = $date->toUnix() + 10; if ($tsDate > $tsNow) { $postData['published'] = EASYBLOG_POST_SCHEDULED; $postData['created'] = $now->toSql(); $postData['publish_up'] = $date->toSql(); } else { $postData['created'] = $date->toSql(); } } // Bind the post data now $post->bind($postData); }
/** * Retrieves the custom permalink * * @since 5.0 * @access public * @param string * @return */ public static function getCustomPermalink(EasyBlogPost $post) { $config = EB::config(); $custom = $config->get('main_sef_custom'); $date = EB::date($data->created); $fallback = $date->toFormat('%Y') . '/' . $date->toFormat('%m') . '/' . $date->toFormat('%d') . '/' . $data->permalink; // If the user didn't enter any values for the custom sef, we'll just load the default one which is the 'date' based if (!$custom) { return $fallback; } // Break down parts of the url defined by the admin $pieces = explode('/', $custom); if (!$pieces) { return $fallback; } $result = array(); foreach ($pieces as $piece) { $piece = str_ireplace('%year_num%', $date->format('Y'), $piece); $piece = str_ireplace('%month_num%', $date->format('m'), $piece); $piece = str_ireplace('%day_num%', $date->format('d'), $piece); $piece = str_ireplace('%day%', $date->format('A'), $piece); $piece = str_ireplace('%month%', $date->format('b'), $piece); $piece = str_ireplace('%blog_id%', $post->id, $piece); $piece = str_ireplace('%category%', $post->getPrimaryCategory()->getPermalink(), $piece); $piece = str_ireplace('%category_id%', $post->getPrimaryCategory()->id, $piece); $result[] = $piece; } $url = implode('/', $result); $url .= '/' . $post->permalink; return $url; }
/** * Determines if the current post is protected * * @since 4.0 * @access public * @param string * @return */ public function isProtected(EasyBlogPost &$blog) { // Password protection disabled if (!$this->config->get('main_password_protect')) { return false; } // Site admin should not be restricted if (EB::isSiteAdmin()) { return false; } // Blog does not contain any password protection if (empty($blog->blogpassword)) { return false; } // User already entered password if ($blog->verifyPassword()) { return false; } // Set the return url to the current url $return = base64_encode(JRequest::getURI()); $category = $blog->getPrimaryCategory(); $blog->category = $category; $blog->categories = $blog->getCategories(); // Get the blogger object $blogger = EB::user($blog->created_by); // Set the author object into the table. $blog->author = $blogger; $this->set('blogger', $blog->author); $this->set('return', $return); $this->set('blog', $blog); $this->set('category', $category); parent::display('blogs/entry/default.protected'); return; }
/** * Determines if the current post is protected * * @since 4.0 * @access public * @param string * @return */ public function isProtected(EasyBlogPost &$post) { // Password protection disabled if (!$this->config->get('main_password_protect')) { return false; } // Site admin should not be restricted if (EB::isSiteAdmin()) { return false; } // Blog does not contain any password protection if (!$post->isPasswordProtected()) { return false; } // User already entered password if ($post->verifyPassword()) { return false; } $post = EB::formatter('entry', $post); // Set the return url to the current url $return = base64_encode($post->getPermalink(false)); // Get the menu params associated with this post $this->theme->params = $post->getMenuParams(); $this->set('post', $post); parent::display('blogs/entry/default.protected'); return; }
/** * Notify site subscribers whenever a new blog post is created * * @since 1.0 * @access public * @param string * @return */ public function notifySubscribers(EasyBlogPost $blog, $action, $comment = null) { if (!$this->exists()) { return false; } // We don't want to notify via e-mail $emailOptions = false; $recipients = array(); $rule = ''; // Get the permalink of the post $permalink = $blog->getPermalink(); // Get the blog image $image = $blog->getImage() ? $blog->getImage('frontpage') : ''; // New post created on the site if ($action == 'new.post') { $rule = 'blog.create'; $recipients = $blog->getRegisteredSubscribers('new', array($blog->created_by)); $options = array('uid' => $blog->id, 'actor_id' => $blog->created_by, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_BLOG_POST', $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } // New comment posted on the site if ($action == 'new.comment') { if (!$this->config->get('integrations_easysocial_notifications_newcomment')) { return false; } $rule = 'blog.comment'; // Get a list of recipients that we should notify $recipients = $comment->getSubscribers($blog, array($comment->created_by)); $recipients = array_merge($recipients, array($blog->created_by)); // Format the comment's content $content = $comment->getContent(true); $options = array('uid' => $blog->id, 'actor_id' => $comment->created_by, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_COMMENT_ON_THE_BLOG_POST', $content, $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } // New ratings added on the post if ($action == 'ratings.add' && $this->config->get('integrations_easysocial_notifications_ratings')) { $rule = 'blog.ratings'; // @TODO: Perhaps notify everyone else that subscribed to this post? // Notify the blog author $recipients = array($blog->created_by); $options = array('uid' => $blog->id, 'actor_id' => $this->my->id, 'title' => JText::sprintf('COM_EASYBLOG_EASYSOCIAL_NOTIFICATION_NEW_RATINGS_FOR_YOUR_BLOG_POST', $blog->title), 'type' => 'blog', 'url' => $permalink, 'image' => $image); } if (!$rule) { return false; } // Send notifications to the receivers when they unlock the badge FD::notify($rule, $recipients, $emailOptions, $options); }
/** * @param array $attributes * * @return array */ public static function getArticles($attributes) { $articles = array(); switch ($attributes['articlelist_source']) { case self::PB_ARTICLE_SOURCE_K2: // Check Com K2 Enabled if (!JSNPagebuilderHelpersPagebuilder::checkComponentEnabled("com_k2")) { return array(); } $k2ArticleModel = new JSNPbK2ArticlesModel(); $result = $k2ArticleModel->jsnGetData($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(K2HelperRoute::getItemRoute($_value['id'], $_value['catid'])); $articles[$_key]['category_direct_url'] = JRoute::_(K2HelperRoute::getCategoryRoute($_value['catid'])); $articles[$_key]['category_title'] = $_value['category']; $imageName = md5("Image" . $_value['id']); if (JFile::exists(JPATH_ROOT . '/media/k2/items/src/' . $imageName . '.jpg')) { $images = array('image_intro' => JRoute::_(JUri::root() . 'media/k2/items/cache/' . $imageName . '_XL.jpg'), 'image_intro_alt' => $_value['title']); $articles[$_key]['images'] = json_encode($images); } } break; case self::PB_ARTICLE_SOURCE_EASY: // Check EasyBlog Enabled if (!JSNPagebuilderHelpersPagebuilder::checkComponentEnabled("com_easyblog")) { return array(); } // Get version EasyBlog $attributes['is_old_version'] = self::checkOldVersionEasyBlog(); if (!$attributes['is_old_version']) { include_once JPATH_ROOT . '/administrator/components/com_easyblog/includes/post/post.php'; } $easyArticleModel = new JSNPbEasyblogArticlesModel(); $result = $easyArticleModel->jsnGetData($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $_value['id'])); $articles[$_key]['category_direct_url'] = JRoute::_(EasyBlogRouter::_('index.php?option=com_easyblog&view=categories&layout=listings&id=' . $_value['category_id'])); if ($attributes['is_old_version']) { $articles[$_key]['introtext'] = $_value['intro']; $imageData = json_decode($_value['image'], true); if (!is_null($imageData) && isset($imageData['title']) && isset($imageData['url'])) { $images = array('image_intro' => JRoute::_($imageData['url']), 'image_intro_alt' => $imageData['title']); $articles[$_key]['images'] = json_encode($images); } } else { $_blog = new EasyBlogPost((int) $_value['id']); $articles[$_key]['introtext'] = $_blog->getIntro(); $images = array('image_intro' => JRoute::_($_blog->getImage('original', true, true)), 'image_intro_alt' => $_value['title']); $articles[$_key]['images'] = json_encode($images); } } break; default: $articlesModel = new JSNPbArticlesModel(); $result = $articlesModel->getArticlesByAttributes($attributes); foreach ($result as $_key => $_value) { $articles[$_key] = $_value; $articles[$_key]['direct_url'] = JRoute::_(ContentHelperRoute::getArticleRoute($_value['id'], $_value['catid'])); $articles[$_key]['category_direct_url'] = JRoute::_(ContentHelperRoute::getCategoryRoute($_value['catid'])); } break; } return $articles; }
/** * 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; }
/** * Posts a message on linkedin * * @since 5.0 * @access public * @param string * @return */ public function share(EasyBlogPost &$post, EasyBlogTableOAuth &$oauth) { // Get the content $content = $post->getIntro(EASYBLOG_STRIP_TAGS); // Get the blog image $image = $post->getImage('thumbnail', true, true); // If there's no blog image, try to get the image from the content if (!$image) { $fullcontent = $post->getContent('entry'); $image = EB::string()->getImage($fullcontent); } // If there's still no image, just use the author's avatar if (!$image) { $image = $post->getAuthor()->getAvatar(); } $options = array('title' => $post->title, 'comment' => $oauth->message, 'submitted-url' => $post->getExternalPermalink(), 'submitted-image-url' => $image, 'description' => $content, 'visibility' => 'anyone'); // Satisfy linkedin's criteria $options['description'] = trim(htmlspecialchars(strip_tags(stripslashes($options['description'])))); $options['comment'] = htmlspecialchars(trim(strip_tags(stripslashes($options['comment'])))); // Linkedin now restricts the message and text size. // To be safe, we'll use 380 characters instead of 400. $options['description'] = trim(JString::substr($options['description'], 0, 395)); $options['comment'] = JString::substr($options['comment'], 0, 256); // Share to their account now $status = parent::sharePost('new', $options, true, false); // Determines if we should auto post to the company pages. if ($oauth->system && $this->config->get('integrations_linkedin_company')) { $companies = trim($this->config->get('integrations_linkedin_company')); if (!empty($companies)) { $companies = explode(',', $companies); foreach ($companies as $company) { $status = parent::sharePost('new', $options, true, false, array($company)); } } } return true; }
public function format(EasyBlogPost &$blog) { $blog->isFeatured = $blog->isFeatured(); }
/** * Truncates the content of the blog post * * @since 4.0 * @access public * @param string * @return */ public function truncate(EasyBlogPost &$post) { if (!$post->isLegacy()) { return; } // Get the maximum allowed characters in the content $max = $this->config->get('layout_maxlengthasintrotext', 200); $max = $max <= 0 ? 200 : $max; // Default to truncate the post's content $truncate = true; // If introtext and content is already present, we don't need to truncate anything since it should respect the user's settings if ($post->intro && $post->content) { $truncate = false; $post->text = $post->intro; } // If we do not need to run any truncation, just run a simple formatting if (!$truncate || !$this->config->get('layout_blogasintrotext')) { // Process videos EB::videos()->format($post); // Process audio files EB::audio()->format($post); // Format gallery items EB::gallery()->format($post); // Format albums EB::album()->format($post); // Remove known codes $this->stripCodes($post); // Need to remove images, and videos. if ($this->config->get('main_truncate_image_position') == 'hidden') { $post->intro = $this->strip_only($post->intro, '<img>'); $post->content = $this->strip_only($post->content, '<img>'); } // Determine the correct content to display $contents = empty($post->intro) ? $post->content : $post->intro; return $contents; } // For normal posts, we will need to get a list of items included in the post if (isset($post->posttype) && $post->posttype == 'standard' || !$post->posttype) { $post->videos = EB::videos()->getItems($post->text); $post->galleries = EB::gallery()->getItems($post->text); $post->audios = EB::audio()->getItems($post->text); $post->albums = EB::album()->getItems($post->text); } // Strip out known codes $this->stripCodes($post); // Truncation by characters if ($this->config->get('main_truncate_type') == 'chars') { $this->truncateByChars($post); } // Truncation by break tags if ($this->config->get('main_truncate_type') == 'break') { $this->truncateByParagraph($post); } // Truncation by words if ($this->config->get('main_truncate_type') == 'words') { $this->truncateByWords($post); } // Truncation by paragraph if ($this->config->get('main_truncate_type') == 'paragraph') { $this->truncateByParagraph($post); } // Append ellipses to the content if necessary if ($this->config->get('main_truncate_ellipses') && isset($post->readmore) && $post->readmore) { $post->text .= JText::_('COM_EASYBLOG_ELLIPSES'); } // Only process standard posts if ($post->posttype == 'standard') { // Determine the position of media items that should be included in the content. $embedHTML = ''; $embedVideoHTML = ''; $imgHTML = ''; if (!empty($post->galleries)) { $embedHTML .= $post->galleries; } if (!empty($post->audios)) { $embedHTML .= implode('', $post->audios); } if (!empty($post->videos)) { $embedVideoHTML = implode('', $post->videos); } if (!empty($post->albums)) { $embedHTML .= implode('', $post->albums); } // images if ($this->config->get('main_truncate_image_position') == 'top' && !empty($imgHTML)) { $post->text = $imgHTML . $post->text; } if ($this->config->get('main_truncate_image_position') == 'bottom' && !empty($imgHTML)) { $post->text = $post->text . $imgHTML; } // Videos if ($this->config->get('main_truncate_video_position') == 'top' && !empty($embedVideoHTML)) { $post->text = $embedVideoHTML . '<br />' . $post->text; } if ($this->config->get('main_truncate_video_position') == 'bottom' && !empty($embedVideoHTML)) { $post->text = $post->text . '<br />' . $embedVideoHTML; } // Prepend the other media items in the start of the blog posts. if ($this->config->get('main_truncate_media_position') == 'top' && !empty($embedHTML)) { $contents = $embedHTML . $post->text; } if ($this->config->get('main_truncate_media_position') == 'bottom' && !empty($embedHTML)) { $post->text = $post->text . $embedHTML; } } }
/** * Prepares a blog content before submitting to JomSocial's stream * * @since 5.0 * @access public * @param string * @return */ private function prepareBlogContent(EasyBlogPost $post, $permalink) { $content = ''; // If the stream is configured to not display any contents at all, skip this if (!$this->config->get('integrations_jomsocial_submit_content')) { return $content; } // Check if the post requires verification if ($this->config->get('main_password_protect', true) && !empty($blog->blogpassword)) { $template = EB::template(); $template->set('id', $blog->id); $template->set('return', base64_encode($blogLink)); $content = $template->output('site/blogs/protected'); return $content; } // Get the content $content = $post->getContent(); $image = ''; // If there's no post image, search for the first image if (!$post->hasImage()) { // This will return a string of img tag if exist. $image = EB::string()->searchImage($content); if (!is_array($image)) { // We need to extract the src attribute preg_match('/src="([^"]*)"/i', $image, $matches); if ($matches) { $image = $matches[1]; } } } else { $image = $post->getImage(); } // Normalize the content of the post $content = $this->normalizeContent($content); $template = EB::template(); $template->set('permalink', $permalink); $template->set('image', $image); $template->set('content', $content); $output = $template->output('site/jomsocial/stream'); return $output; }
/** * Determines if the user is allowed to view this post if this post is associated with a team. * * @since 4.0 * @access public * @param string * @return */ public function checkTeamPrivacy(EasyBlogPost &$blog) { $id = $blog->getTeamAssociation(); // This post is not associated with any team, so we do not need to check anything on the privacy if (!$id) { return true; } $team = EB::table('TeamBlog'); $team->load($id); // If the team access is restricted to members only if ($team->access == EBLOG_TEAMBLOG_ACCESS_MEMBER && !$team->isMember($this->my->id) && !EB::isSiteAdmin()) { return false; } // If the team access is restricted to registered users, ensure that they are logged in. if ($team->access == EBLOG_TEAMBLOG_ACCESS_REGISTERED && $this->my->guest) { echo EB::showLogin(); return false; } return true; }
/** * Prepares a blog content before submitting to JomSocial's stream * * @since 5.0 * @access public * @param string * @return */ private function prepareBlogContent(EasyBlogPost $post, $permalink) { $content = ''; // If the stream is configured to not display any contents at all, skip this if (!$this->config->get('integrations_jomsocial_submit_content')) { return $content; } // Check if the post requires verification if ($this->config->get('main_password_protect', true) && !empty($blog->blogpassword)) { $template = EB::template(); $template->set('id', $blog->id); $template->set('return', base64_encode($blogLink)); $content = $template->output('site/blogs/protected'); return $content; } // Get the content $content = $post->getContent(); $image = $post->getImage(); // If there's no post image, search for the first image if (!$image) { $image = EB::string()->searchImage($content); } // Normalize the content of the post $content = $this->normalizeContent($content); $template = EB::template(); $template->set('permalink', $permalink); $template->set('image', $image); $template->set('content', $content); $output = $template->output('site/jomsocial/stream'); return $output; }