Ejemplo n.º 1
0
 /**
  * Invoke the crawling.
  *
  * @since	1.0
  * @access	public
  * @author	Mark Lee <*****@*****.**>
  */
 public function crawl($url)
 {
     $tmp = str_ireplace(array('http://', 'https://'), '', $url);
     if (!EB::string()->isValidDomain($tmp)) {
         return false;
     }
     // Ensure that urls always contains a protocol
     if (stristr($url, 'http://') === false && stristr($url, 'https://') === false) {
         $url = 'http://' . $url;
     }
     // Load up the connector first.
     $connector = EB::connector();
     $connector->addUrl($url);
     $connector->execute();
     // Get the result and parse them.
     $info = parse_url($url);
     $this->contents = $connector->getResult($url);
     // Replace any href="// with href="scheme://"
     $this->contents = str_ireplace('src="//', 'src="' . $info['scheme'] . '://', $this->contents);
     // Get the final url, if there's any redirection.
     $originalUrl = $url;
     $url = $connector->getFinalUrl($url);
     $this->parse($originalUrl, $url);
     return $this;
 }
Ejemplo n.º 2
0
 public function getResult($queries = array())
 {
     $this->setQueries($queries);
     // There is 2 parts to this
     // nearbysearch
     // textsearch
     $nearbysearchUrl = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json';
     $textsearchUrl = 'https://maps.googleapis.com/maps/api/place/textsearch/json';
     $nearbysearchOptions = array('location' => $this->queries['location'], 'radius' => $this->queries['radius'], 'key' => $this->queries['key'], 'keyword' => $this->queries['keyword']);
     $textsearchOptions = array('query' => $this->queries['query'], 'key' => $this->queries['key']);
     $connector = EB::connector();
     $connector->setMethod('GET');
     $connector->addUrl($nearbysearchUrl . '?' . http_build_query($nearbysearchOptions));
     if (!empty($this->queries['query'])) {
         $connector->addUrl($textsearchUrl . '?' . http_build_query($textsearchOptions));
     }
     $connector->execute();
     $results = $connector->getResults();
     $venues = array();
     foreach ($results as $result) {
         $obj = json_decode($result->contents);
         foreach ($obj->results as $row) {
             $obj = new EasyBlogLocationData();
             $obj->latitude = $row->geometry->location->lat;
             $obj->longitude = $row->geometry->location->lng;
             $obj->name = $row->name;
             $obj->address = '';
             $venues[$row->id] = $obj;
         }
     }
     $venues = array_values($venues);
     return $venues;
 }
Ejemplo n.º 3
0
 /**
  * Discover new languages
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function discover()
 {
     $config = EB::config();
     $key = $config->get('main_apikey');
     $connector = EB::connector();
     $connector->addUrl(EBLOG_LANGUAGES_SERVER);
     $connector->addQuery('key', $key);
     $connector->setMethod('POST');
     $connector->execute();
     $contents = $connector->getResult(EBLOG_LANGUAGES_SERVER);
     if (!$contents) {
         $result = new stdClass();
         $result->message = 'No language found';
         return $result;
     }
     // Decode the result
     $result = json_decode($contents);
     if ($result->code != 200) {
         $return = base64_encode('index.php?option=com_easyblog&view=languages');
         return $result->message;
     }
     foreach ($result->languages as $language) {
         // If it does, load it instead of overwriting it.
         $table = EB::table('Language');
         $exists = $table->load(array('locale' => $language->locale));
         // We do not want to bind the id
         unset($language->id);
         // Since this is the retrieval, the state should always be disabled
         if (!$exists) {
             $table->state = EBLOG_LANGUAGES_NOT_INSTALLED;
         }
         // Then check if the language needs to be updated. If it does, update the ->state to EBLOG_LANGUAGES_NEEDS_UPDATING
         // We need to check if the language updated time is greater than the local updated time
         if ($exists && $table->state) {
             $languageTime = strtotime($language->updated);
             $localLanguageTime = strtotime($table->updated);
             if ($languageTime > $localLanguageTime && $table->state == EBLOG_LANGUAGES_INSTALLED) {
                 $table->state = EBLOG_LANGUAGES_NEEDS_UPDATING;
             }
         }
         // Set the title
         $table->title = $language->title;
         // Set the locale
         $table->locale = $language->locale;
         // Set the translator
         $table->translator = $language->translator;
         // Set the updated time
         $table->updated = $language->updated;
         // Update the progress
         $table->progress = $language->progress;
         // Update the table with the appropriate params
         $params = new JRegistry();
         $params->set('download', $language->download);
         $params->set('md5', $language->md5);
         $table->params = $params->toString();
         $table->store();
     }
     return true;
 }
Ejemplo n.º 4
0
 public function getResult($queries = array())
 {
     $this->setQueries($queries);
     $connector = EB::connector();
     $connector->setMethod('GET');
     $connector->addUrl($this->buildUrl());
     if (!empty($this->queries['query'])) {
         $this->setQuery('intent', 'global');
         $connector->addUrl($this->buildUrl());
     }
     $connector->execute();
     $result = $connector->getResults();
     $venues = array();
     foreach ($result as $row) {
         $object = json_decode($row->contents);
         if (!isset($object->meta) || !isset($object->meta->code)) {
             $this->setError(JText::_('COM_EASYBLOG_LOCATION_PROVIDERS_FOURSQUARE_UNKNOWN_ERROR'));
             return array();
         }
         if ($object->meta->code != 200) {
             $this->setError($object->meta->errorDetail);
             return array();
         }
         if (empty($object->response->venues)) {
             continue;
         }
         // We want to merge in the browse results and global results
         foreach ($object->response->venues as $venue) {
             if (!isset($venues[$venue->id])) {
                 $obj = new EasyBlogLocationData();
                 $obj->latitude = $venue->location->lat;
                 $obj->longitude = $venue->location->lng;
                 $obj->address = isset($venue->location->address) ? $venue->location->address : '';
                 $obj->name = $venue->name;
                 $venues[$venue->id] = $obj;
             }
         }
     }
     $venues = array_values($venues);
     return $venues;
 }
Ejemplo n.º 5
0
 public function getResult($queries = array())
 {
     $this->setQueries($queries);
     // If address is empty, then we only do a latlng search
     // If address is not empty, then we do an address search
     $options = array();
     if (!empty($this->queries['key'])) {
         $options['key'] = $this->queries['key'];
     }
     if (!empty($this->queries['address'])) {
         $options['address'] = $this->queries['address'];
     } else {
         $options['latlng'] = $this->queries['latlng'];
     }
     $connector = EB::connector();
     $connector->setMethod('GET');
     $connector->addUrl($this->url . '?' . http_build_query($options));
     $connector->execute();
     $result = $connector->getResult();
     $result = json_decode($result);
     if (!isset($result->status) || $result->status != 'OK') {
         $error = isset($result->error_message) ? $result->error_message : JText::_('COM_EASYBLOG_LOCATION_PROVIDERS_MAPS_UNKNOWN_ERROR');
         $this->setError($error);
         return array();
     }
     $venues = array();
     foreach ($result->results as $row) {
         $obj = new EasyBlogLocationData();
         $obj->latitude = $row->geometry->location->lat;
         $obj->longitude = $row->geometry->location->lng;
         $obj->name = $row->formatted_address;
         $obj->address = '';
         $venues[] = $obj;
     }
     return $venues;
 }
Ejemplo n.º 6
0
 public function dailymotion(&$oembed, $absoluteUrl)
 {
     $url = 'http://www.dailymotion.com/services/oembed/?url=' . urlencode($absoluteUrl);
     $connector = EB::connector();
     $connector->addUrl($url);
     $connector->execute();
     $contents = $connector->getResult($url);
     // We are retrieving json data
     $oembed = json_decode($contents);
     // Test if thumbnail_url is set so we can standardize this
     if (isset($oembed->thumbnail_url)) {
         $oembed->thumbnail = $oembed->thumbnail_url;
     }
     return $oembed;
 }
Ejemplo n.º 7
0
 /**
  * Main method to import the feed items
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function import(EasyBlogTableFeed &$feed, $limit = 0)
 {
     // Load site language file
     EB::loadLanguages();
     // Import simplepie library
     jimport('simplepie.simplepie');
     // We need DomDocument to exist
     if (!class_exists('DomDocument')) {
         return false;
     }
     // Set the maximum execution time to a higher value
     @ini_set('max_execution_time', 720);
     // Get the feed params
     $params = EB::registry($feed->params);
     // Determines the limit of items to fetch
     $limit = $limit ? $limit : $params->get('feedamount', 0);
     // Setup the outgoing connection to the feed source
     $connector = EB::connector();
     $connector->addUrl($feed->url);
     $connector->execute();
     // Get the contents
     $contents = $connector->getResult($feed->url);
     // If contents is empty, we know something failed
     if (!$contents) {
         return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_UNABLE_TO_REACH_TARGET_URL', $feed->url), EASYBLOG_MSG_ERROR);
     }
     // Get the cleaner to clean things up
     $cleaner = $this->getAdapter('Cleaner');
     $contents = $cleaner->cleanup($contents);
     // Load up the xml parser
     $parser = new SimplePie();
     $parser->strip_htmltags(false);
     $parser->set_raw_data($contents);
     @$parser->init();
     // Get a list of items
     // We need to supress errors here because simplepie will throw errors on STRICT mode.
     $items = @$parser->get_items();
     if (!$items) {
         // TODO: Language string
         return EB::exception('COM_EASYBLOG_FEEDS_NOTHING_TO_BE_IMPORTED_CURRENTLY', EASYBLOG_MSG_ERROR);
     }
     // Get the feeds model
     $model = EB::model('Feeds');
     // Determines the total number of items migrated
     $total = 0;
     foreach ($items as $item) {
         // If it reaches limit, skip processing
         if ($limit && $total == $limit) {
             break;
         }
         // Get the item's unique id
         $uid = @$item->get_id();
         // If item already exists, skip this
         if ($model->isFeedItemImported($feed->id, $uid)) {
             continue;
         }
         // Log down a new history record to avoid fetching of the same item again
         $history = EB::table('FeedHistory');
         $history->feed_id = $feed->id;
         $history->uid = $uid;
         $history->created = EB::date()->toSql();
         $history->store();
         // Get the item's link
         $link = @$item->get_link();
         // Load up the post library
         $post = EB::post();
         $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator);
         $post->create($createOption);
         // Pass this to the adapter to map the items
         $mapper = $this->getAdapter('Mapper');
         $mapper->map($post, $item, $feed, $params);
         // Now we need to get the content of the blog post
         $mapper->mapContent($post, $item, $feed, $params);
         $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator);
         // Try to save the blog post now
         try {
             $post->save($saveOptions);
             // Update the history table
             $history->post_id = $post->id;
             $history->store();
             $total++;
         } catch (EasyBlogException $exception) {
             // do nothing.
         }
     }
     return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_POSTS_MIGRATED_FROM_FEED', $total, $feed->url), EASYBLOG_MSG_SUCCESS);
 }
Ejemplo n.º 8
0
 /**
  * Maps the content
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public function mapContent(EasyBlogPost &$post, &$item, EasyBlogTableFeed &$feed, &$params)
 {
     // Initial content
     $contents = '';
     // Try to fetch the contents remotely
     if ($feed->item_get_fulltext) {
         $url = urldecode(@$item->get_link());
         $connector = EB::connector();
         $connector->addUrl($url);
         $connector->execute();
         // Fetched contents from the site
         $tmp = $connector->getResult($url);
         // Clean up fetched contents by ensuring that there's no weird text before the html declaration
         $pattern = '/(.*?)<html/is';
         $replace = '<html';
         $tmp = preg_replace($pattern, $replace, $tmp, 1);
         if (!empty($tmp)) {
             // Enforce utf-8 encoding on the content since Joomla always uses utf-8
             $tmp = EB::string()->forceUTF8($tmp);
             // Load up the readability lib
             $readability = EB::readability($tmp);
             $readability->debug = false;
             $readability->convertLinksToFootnotes = false;
             $result = $readability->init();
             if ($result) {
                 $output = $readability->getContent()->innerHTML;
                 // Tidy up the contents
                 $output = $this->tidyContent($output);
                 if (stristr(html_entity_decode($output), '<!DOCTYPE html') === false) {
                     $contents = $output;
                     $contents = $this->convertRelativeToAbsoluteLinks($contents, @$item->get_link());
                 }
             }
         }
     }
     // Get the content of the item
     if (!$contents) {
         $contents = @$item->get_content();
     }
     // Default allowed html codes
     $allowed = '<img>,<a>,<br>,<table>,<tbody>,<th>,<tr>,<td>,<div>,<span>,<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>';
     // Remove disallowed tags
     $contents = strip_tags($contents, $params->get('allowed', $allowed));
     // Append original source link into article if necessary
     if ($params->get('sourceLinks')) {
         $text .= '<div><a href="' . @$item->get_link() . '" target="_blank">' . JText::_('COM_EASYBLOG_FEEDS_ORIGINAL_LINK') . '</a></div>';
     }
     // Bind the author
     if ($feed->author) {
         $author = @$item->get_author();
         if ($author) {
             $name = @$author->get_name();
             $email = @$author->get_email();
             if ($name) {
                 $contents .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $name) . '</div>';
             } else {
                 if ($email) {
                     $segments = explode(' ', $email);
                     if (isset($segments[1])) {
                         $name = $segments[1];
                         $name = str_replace(array('(', ')'), '', $name);
                         $contents .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $name) . '</div>';
                     }
                 }
             }
         }
     }
     if ($feed->item_content == 'intro') {
         $post->intro = $contents;
     } else {
         $post->content = $contents;
     }
     // The doctype for imported post should be legacy because there are no blocks here.
     $post->doctype = 'legacy';
 }
Ejemplo n.º 9
0
 /**
  *
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 public static function getOnlineParser()
 {
     $data = new stdClass();
     // Get the xml file
     $site = 'http://stackideas.com/updater/manifests/easyblog';
     $connector = EB::connector();
     $connector->addUrl($site);
     $connector->execute();
     $contents = $connector->getResult($site);
     $obj = json_decode($contents);
     return $obj;
 }
Ejemplo n.º 10
0
 /**
  * Installs a language file
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return	
  */
 public function install()
 {
     $params = new JRegistry($this->params);
     // Get the api key
     $config = EB::config();
     $key = $config->get('main_apikey');
     if (!$key) {
         $this->setError(JText::_('COM_EASYBLOG_INVALID_API_KEY_PROVIDED'));
         return false;
     }
     // Get the download url
     $url = $params->get('download');
     if (!$url) {
         $this->setError(JText::_('COM_EASYBLOG_INVALID_DOWNLOAD_URL'));
         return false;
     }
     // Download the language file
     $connector = EB::connector();
     $connector->addUrl($url);
     $connector->addQuery('key', $key);
     $connector->setMethod('POST');
     $connector->execute();
     $result = $connector->getResult($url);
     // Generate a random hash
     $hash = md5($this->locale . JFactory::getDate()->toSql());
     // Build storage path
     $storage = JPATH_ROOT . '/tmp/' . $hash . '.zip';
     // Save the file
     $state = JFile::write($storage, $result);
     $folder = JPATH_ROOT . '/tmp/' . $hash;
     jimport('joomla.filesystem.archive');
     // Extract the language's archive file
     $state = JArchive::extract($storage, $folder);
     // Throw some errors when we are unable to extract the zip file.
     if (!$state) {
         $this->setError(JText::_('COM_EASYBLOG_UNABLE_TO_EXTRACT_ARCHIVE'));
         return false;
     }
     // Read the meta data
     $raw = JFile::read($folder . '/meta.json');
     $meta = json_decode($raw);
     foreach ($meta->resources as $resource) {
         // Get the correct path based on the meta's path
         $dest = $this->getPath($resource->path) . '/language/' . $this->locale;
         // If language folder don't exist, create it first.
         if (!JFolder::exists($dest)) {
             JFolder::create($dest);
         }
         // Build the source and target files
         $destFile = $dest . '/' . $this->locale . '.' . $resource->title;
         $sourceFile = $folder . '/' . $resource->path . '/' . $this->locale . '.' . $resource->title;
         // Ensure that the source file exists
         if (!JFile::exists($sourceFile)) {
             continue;
         }
         // If the destination file already exists, delete it first
         if (JFile::exists($destFile)) {
             JFile::delete($destFile);
         }
         // Try to copy the file
         $state = JFile::copy($sourceFile, $destFile);
         if (!$state) {
             $this->setError(JText::_('COM_EASYBLOG_LANGUAGES_ERROR_COPYING_FILES'));
             return false;
         }
     }
     // After everything is copied, ensure that the extracted folder is deleted to avoid dirty filesystem
     JFile::delete($storage);
     JFolder::delete($folder);
     // Once the language files are copied accordingly, update the state
     $this->state = EBLOG_LANGUAGES_INSTALLED;
     return $this->store();
 }
Ejemplo n.º 11
0
 function _processWPXMLAttachment($wpPostId, $content, $attachments, $authorId)
 {
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php';
     foreach ($attachments as $attachment) {
         $link = $attachment['link'];
         $attachementURL = $attachment['attachment_url'];
         if (EasyImageHelper::isImage($attachementURL)) {
             $filname = EasyImageHelper::getFileName($attachementURL);
             $extension = EasyImageHelper::getFileExtension($attachementURL);
             $folder = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'blogs' . DIRECTORY_SEPARATOR . $wpPostId;
             if (!JFolder::exists($folder)) {
                 JFolder::create($folder);
             }
             // new image location
             $newFile = $folder . DIRECTORY_SEPARATOR . $filname;
             $connector = EB::connector();
             $connector->addUrl($attachementURL);
             $connector->execute();
             $imageraw = $connector->getResult($attachementURL);
             if ($imageraw) {
                 if (JFile::write($newFile, $imageraw)) {
                     //replace the string in the content.
                     $absImagePath = rtrim(JURI::root(), '/') . '/images/blogs/' . $wpPostId . '/' . $filname;
                     $content = str_ireplace('href="' . $link . '"', 'href="' . $absImagePath . '"', $content);
                     $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i';
                     $content = preg_replace($pattern, 'src="' . $absImagePath . '"', $content);
                 }
             }
             // 				if( file_put_contents( $newFile, file_get_contents($attachementURL) ) !== false )
             // 				{
             // 				    //replace the string in the content.
             // 				    $absImagePath   = rtrim( JURI::root(), '/' ) . '/images/blogs/' . $wpPostId . '/' . $filname;
             // 				    $content		= JString::str_ireplace( 'href="' . $link . '"'  , 'href="' . $absImagePath . '"' , $content );
             //
             // 				    $pattern 		= '/src=[\"\']?([^\"\']?.*(png|jpg|jpeg|gif))[\"\']?/i';
             // 				    $content		= preg_replace( $pattern  , 'src="'.$absImagePath.'"' , $content );
             // 				}
         }
     }
     return $content;
 }
Ejemplo n.º 12
0
 /**
  * Retrieves suggestions for keywords based on the content
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public function suggestKeywords()
 {
     // ini_set('xdebug.var_display_max_depth', 5);
     // ini_set('xdebug.var_display_max_children', 256);
     // ini_set('xdebug.var_display_max_data', (1024 * 4));
     // @TODO: Check if the author has access to write and publish post
     $content = $this->input->get('data', '', 'default');
     $url = 'http://lang.stackideas.com/index.php?option=com_lang&view=keywords&layout=compute';
     // Load up the connector first.
     $connector = EB::connector();
     $connector->addUrl($url);
     $connector->addQuery('text', $content);
     $connector->setMethod('POST');
     $connector->execute();
     $result = $connector->getResult($url);
     $keywords = json_decode($result);
     $this->ajax->resolve($keywords->result);
 }
Ejemplo n.º 13
0
 function migrateBloggerComment($link, $post_id)
 {
     $connector = EB::connector();
     $connector->addUrl($link);
     $connector->execute();
     $content = $connector->getResult($link);
     $pattern = '/(.*?)<\\?xml version/is';
     $replacement = '<?xml version';
     $content = preg_replace($pattern, $replacement, $content, 1);
     $parser = simplexml_load_string($content);
     if ($parser) {
         $lft = 1;
         $rgt = 2;
         $entries = $parser->entry;
         // process each items
         foreach ($entries as $item) {
             if (strpos($item->id, '.post-') === false) {
                 continue;
             }
             $now = EB::date();
             $db = EB::db();
             $comment = EB::table('Comment');
             //we need to rename the esname and esemail back to name and email.
             $post = array();
             $post['name'] = (string) $item->author->name;
             $post['email'] = (string) $item->author->email;
             $post['post_id'] = $post_id;
             $post['comment'] = (string) $item->content;
             $post['title'] = (string) $item->title;
             $post['url'] = (string) $item->author->uri;
             $post['ip'] = '';
             $comment->bindPost($post);
             $comment->created_by = '0';
             $comment->created = (string) $item->published;
             $comment->modified = (string) $item->published;
             $comment->published = 1;
             $comment->parent_id = '0';
             $comment->sent = 1;
             $comment->lft = $lft;
             $comment->rgt = $rgt;
             if ($comment->store()) {
                 $lft++;
                 $rgt++;
             }
         }
     }
 }