/** * 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; }
/** * 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); } }
/** * 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; }