Astropix Apod

Astropix Apod is my first WordPress plugin and show the Astronomy Picture of the Day by Nasa. It work both in the posts and in the pages simply with a shortcode.

The project full code is reachable on my GitHub account

Astropix Apod plugin is available on WordPress plugin directory here.

The plugin retrieve and parse the xml code from the Astronomy Picture of the Day RSS and then retrieve and parse the page with the picture of the day to get informations about the image like its url.

To retrieve the html pages the plugin use libcurl on PHP. The following is the function that implement the call.

function get_html_page($url, $timeout = 30)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $results = curl_exec($ch);
    curl_close($ch);

    return $results;
}

To parse the html code the plugin use regular expressions like the following.

Sample regular expression

This regular expression get the url in the src property in a html img tag like the following

<img src="path/to/image.jpg" alt="Alternative text">

In the current version the plugin render a widget with the picture of the day (sometime a video), a label and the link to the original post by NASA.

Screenshot of the widget shown by Astropix Apod plugin in the version 1.0.0
Screenshot of the widget shown by Astropix Apod plugin in the version 1.0.0

The project is released under GNU General Public License v3.0.

For questions, comments or suggestions, use my contact page.

Enjoy!

  Riccardo Giovarelli    All rights reserved 

  •  
  •  
  •  
  •