<?php

    include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
    include_once( PLOG_CLASS_PATH."class/data/Date.class.php" );
    
    /**
	* Plugin that offers features to get all articles from specific article cateogries 
	* as announcements and sticky articles.
	*/
    class Pluginapod extends PluginBase
    {
        var $pluginEnabled;
        
        var $width, $height;			


        function Pluginapod()
        {
			$this->PluginBase();
			
            $this->id = "apod";
            $this->author = "Jase Chen";
            $this->desc = "";
  
            $this->locales = Array( "en_UK" , "zh_TW" );
            
            $this->init();
        }

		function init()
		{
			$this->registerAdminAction( "apod", "PluginapodConfigAction" );
			$this->registerAdminAction( "updateapod", "PluginapodUpdateConfigAction" );			
            $this->addMenuEntry( "/menu/controlCenter/manageSettings", "apod", "?op=apod");
		}

		function register()
		{
		    $blogSettings = $this->blogInfo->getSettings();
		    $this->pluginEnabled = $blogSettings->getValue( "plugin_apod_enabled" );

		    $this->width = $blogSettings->getValue( "plugin_apod_width" );
		    $this->height = $blogSettings->getValue( "plugin_apod_height" );

   		}
	    
  	    function isEnabled()
    	{
        	return $this->pluginEnabled;
    	}

        /**
		* Returns the stickyposts articles object of current blog
		*/
        function getPic($web_url)
        {
        	

          if ($fp = @fopen($web_url, "r")) {
            while (!feof($fp)) $data .= fgets($fp, 128);
            fclose($fp);
          }

          $item_pic_regexp = "%<IMG SRC=\"(.+?)\"%";
          preg_match_all($item_pic_regexp, $data, $item_pic_items);
          $img = "http://antwrp.gsfc.nasa.gov/apod/".$item_pic_items[1][0]; 
  	      return $img;
        }

        function getTitle($web_url)
        {
        	
          if ($fp = @fopen($web_url, "r")) {
            while (!feof($fp)) $data .= fgets($fp, 128);
            fclose($fp);
          }

          $item_title_regexp = "%<b>(.+?)</b> <br>%";
          preg_match_all($item_title_regexp, $data, $item_title_items);
          $title = $item_title_items[1][0]; 
  	      return $title;
        }

        function width()
        {
          return $this->width;
        }                

        function height()
        {
          return $this->height;
        }                

    }
?>
