/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Creates a new stream for new blog post * * @since 1.0 * @access public * @param string * @return */ public function createFeaturedBlogStream(EasyBlogPost $post) { // Check if integrations is enabled if (!$this->config->get('integrations_easysocial_stream_featurepost')) { return false; } // Check if easysocial exists on the site if (!$this->exists()) { return false; } $stream = FD::stream(); $template = $stream->getTemplate(); // Get the stream template $template->setActor($post->getAuthor()->id, SOCIAL_TYPE_USER); $template->setContext($post->id, 'blog'); $template->setContent($post->getContent()); $template->setTarget($post->getAuthor()->id); $template->setSiteWide(); $template->setVerb('featured'); // Determines if the blog post should be visible publicly $privacyVal = $post->access ? '10' : 0; $template->setAccess('easyblog.blog.view', $privacyVal); return $stream->add($template); }