Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Plugin using OOP and wp_cron
Monday, March 24th, 2008 at 6:24:32pm MDT 

  1. <?php
  2. /*
  3. Plugin Name: Verse of the Day
  4. Version: 3.5 beta
  5. Plugin URI: http://blog.slaven.net.au/wordpress-plugins/wordpress-verse-of-the-day-plugin/
  6. Description: Places the bible 'Verse of the Day' on your site.  Defaults to the ESV feed provided by Good News Publishers, but can accept any feed url. <strong>Requires WordPress 2.2</strong>
  7. Author: Glenn Slaven
  8. Author URI: http://blog.slaven.net.au/
  9.  
  10.         Copyright 2004  Glenn Slaven  (email : gdalziel@gmail.com)
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. */
  26. include_once (ABSPATH . WPINC . "/rss-functions.php");
  27. include_once ('plugin-base.php');
  28.  
  29. if (!class_exists('wp_votd') && class_exists('plugin_base')) {
  30.         class wp_votd extends plugin_base {
  31.  
  32.                 var $name = 'Verse of the Day';
  33.                 var $filename = __FILE__;
  34.  
  35.                 function wp_votd() {
  36.                         parent::plugin_base();
  37.                        
  38.                         add_action('wp_votd_update_contents', array(&$this, 'update_contents'));
  39.                         add_action('widgets_init', array(&$this, 'widget_init'));                     
  40.                 }
  41.                
  42.                 function _install() {
  43.                         wp_schedule_event(0, 'daily', 'wp_votd_update_contents' );
  44.                         $this->set_options('RESET');
  45.                         $this->update_contents();
  46.                 }
  47.                
  48.                 function _uninstall() {
  49.                         delete_option('wp_votd_options');
  50.                         delete_option('wp_votd_cache');
  51.                         remove_action('wp_votd_update_contents', 'wp_votd_update_contents');
  52.                         wp_clear_scheduled_hook('wp_votd_update_contents');
  53.                 }
  54.  
  55.                 function widget_init() {
  56.                         if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') ) return;
  57.                                
  58.                         register_sidebar_widget(array('Verse of the Day', 'widgets'), array(&$this, 'show_widget'));
  59.                         register_widget_control(array('Verse of the Day', 'widgets'), array(&$this, 'widget_control'), 300, 80);
  60.                 }
  61.                
  62.                 function show_widget($args) {
  63.                         extract($args);
  64.                         $options = get_option('wp_votd_options');
  65.                         echo $before_widget;
  66.                         echo $before_title . $options['wp_votd_title'] . $after_title;
  67.                         echo get_option('wp_votd_cache');
  68.                         echo $after_widget;
  69.                 }
  70.                
  71.                 function widget_control() {
  72.                         $options = get_option('wp_votd_options');
  73.                         if ( $_POST["votd-submit"] ) {
  74.                                 $new_title = strip_tags(stripslashes($_POST["votd-title"]));
  75.                                 if ( $options['wp_votd_title'] != $new_title ) {
  76.                                         $this->set_options('UPDATE', false, false, false, false, false, $new_title);
  77.                                         $options['wp_votd_title'] = $new_title;
  78.                                 }
  79.                         }
  80.                         $title = attribute_escape($options['wp_votd_title']);
  81. ?>
  82.                         <p><label for="votd-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="votd-title" name="votd-title" type="text" value="<?php echo $title; ?>" /></label></p>
  83.                         <p><input style="width: 200px;" id="votd-buttontext" name="votd-buttontext" type="submit" value="Update" /></p>
  84.                                         <input type="hidden" id="votd-submit" name="votd-submit" value="1" />
  85. <?php
  86.                 }
  87.                
  88.                 function set_options($action, $version = false, $url = false, $name = false, $timeout = false, $template = false, $title = false)  {
  89.  
  90.                         $options = array(
  91.                                 'wp_votd_url'         => 'http://www.gnpcb.org/esv/share/rss2.0/daily/',
  92.                                 'wp_votd_version'                     => 'ESV',
  93.                                 'wp_votd_name'        => 'English Standard Version',
  94.                                 'wp_votd_template'                  => '<p id="votd">[TEXT] (<a href="[LINK]">[TITLE]</a>[VERSION])[ENCLOSURE]</p>',
  95.                                 'wp_votd_title'    => 'Verse of the Day'
  96.                         );
  97.  
  98.                         if ('RESET' == $action) {
  99.                                 update_option('wp_votd_options', $options);
  100.                         } elseif ('UPDATE' == $action) {
  101.                                 $options = get_option('wp_votd_options');
  102.  
  103.                                 if ($version) { $options['wp_votd_version'] = $version; }
  104.                                 if ($url) { $options['wp_votd_url'] = $url; }
  105.                                 if ($name) { $options['wp_votd_name'] = $name; }
  106.                                 if ($template) { $options['wp_votd_template'] = stripslashes($template); }
  107.                                 if ($title) { $options['wp_votd_title'] = strip_tags(stripslashes($title)); }
  108.                                
  109.                                 if (is_array($options)) {
  110.                                         update_option('wp_votd_options', $options);
  111.                                         $this->update_contents();
  112.                                         return $this->get_feed(true);
  113.                                 } else {
  114.                                         return false;
  115.                                 }
  116.                         }
  117.                 }
  118.  
  119.                 function options_page() {
  120.  
  121.                         //Set the default feeds
  122.                         $VOTD_DEFAULT_FEEDS = array(
  123.                                 'ESV'  => array('url' => 'http://www.gnpcb.org/esv/share/rss2.0/daily/',           'name' => 'English Standard Version'),
  124.                                 'NIV'  => array('url' => 'http://www.biblegateway.com/usage/votd/rss/votd.rdf?31', 'name' => 'New International Version'),
  125.                                 'KJV'  => array('url' => 'http://www.biblegateway.com/usage/votd/rss/votd.rdf?9''name' => 'King James Version')
  126.                         );
  127.  
  128.                         $post_vars = ($_POST ? $_POST : get_option('wp_votd_options'));
  129.  
  130.                         if (isset($_POST['wp_votd_update'])) {
  131.                             $this->set_options('UPDATE',
  132.                                                                     (strlen($_POST['wp_votd_version']) ? $_POST['wp_votd_version'] : $_POST['wp_votd_other_version']),
  133.                                                                 (strlen($_POST['wp_votd_version']) ? $VOTD_DEFAULT_FEEDS[$_POST['wp_votd_version']]['url'] : $_POST['wp_votd_other_url']),
  134.                                                                         (strlen($_POST['wp_votd_version']) ? $VOTD_DEFAULT_FEEDS[$_POST['wp_votd_version']]['name'] : $_POST['wp_votd_other_name']),
  135.                                                                         $_POST['wp_votd_timeout'],
  136.                                                                         $_POST['wp_votd_template']);
  137.                         } elseif (FALSE === get_option('wp_votd_options') || '' === get_option('wp_votd_options')) {
  138.                                 $this->set_options('RESET');
  139.                         }
  140.  
  141.                         $options = get_option('wp_votd_options');
  142.                         $cache_contents = $this->get_feed();
  143.  
  144.                 ?>
  145.                 <div class=wrap>
  146.                  <form method="post">
  147.                  <input type="hidden" name="wp_votd_update" value="true" />
  148.                   <h2>Verse of the Day Options</h2>
  149.                   <blockquote style="font-style:italic;">All Scripture is breathed out by God and profitable for teaching, for reproof, for correction, and for training in righteousness, that the man of God may be competent, equipped for every good work. (<a href="http://www.gnpcb.org/esv/search/?q=2+Timothy+3%3A16-17">2 Timothy 3:16-17</a>, <abbr title="English Standard Version">ESV</abbr>)</blockquote>
  150.                   <fieldset class="options">
  151.                   <legend>Select a bible version to use</legend>
  152.                   <p>You can enter the details of a different Verse of the day RSS feed if you want.  If you enter the feed details in manualy, it will over-ride a selection in the dropdown list.</p>
  153.                   <p>After selecting your options then clicking 'Update' put &lt;?php wp_votd(); ?&gt; on your template file where you want the verse to display. See the <a href="http://blog.slaven.net.au/wordpress-plugins/wordpress-verse-of-the-day-plugin/">Verse of the Day instructions page</a> for more information</p>
  154.                   <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  155.                   <tr>
  156.                    <th width="33%" scope="row" valign="top">Select version:</th>
  157.                    <td><select id="wp_votd_version" name="wp_votd_version">
  158.                 <?php
  159.                         $versions = array_keys($VOTD_DEFAULT_FEEDS);
  160.                         foreach($versions as $v) {
  161.                                 print "<option value=\"$v\"".($options['wp_votd_version'] == $v ? ' selected="selected"' : '').">{$VOTD_DEFAULT_FEEDS[$v]['name']}</option>\n";
  162.                         }
  163.                 ?>
  164.                          <option value=""<?=(array_key_exists($options['wp_votd_version'], $VOTD_DEFAULT_FEEDS) ? '' : ' selected="selected"')?>>Other...</option>
  165.                         </select>
  166.                    </td>
  167.                   </tr>
  168.                   <tr>
  169.                    <th width="33%" scope="row" valign="top"><strong style="font-size:larger; color: #FF1100">or</strong></th>
  170.                    <td></td>
  171.                   </tr>
  172.                   <tr>
  173.                    <th width="33%" scope="row" valign="top">Version Abbreviation (e.g. ESV, NIV, etc...):</th>
  174.                    <td><input style="width:3em;" type="text" name="wp_votd_other_version" id="wp_votd_other_version" value="<?=(array_key_exists($options['wp_votd_version'], $VOTD_DEFAULT_FEEDS) ? '' : $options['wp_votd_version'])?>" /></td>
  175.                   </tr>
  176.                   <tr>
  177.                    <th width="33%" scope="row" valign="top">Version Name:</th>
  178.                    <td><input style="width:20em;" type="text" name="wp_votd_other_name" id="wp_votd_other_name" value="<?=(array_key_exists($options['wp_votd_version'], $VOTD_DEFAULT_FEEDS) ? '' : $options['wp_votd_name'])?>" /></td>
  179.                   </tr>
  180.                   <tr>
  181.                    <th width="33%" scope="row" valign="top">RSS feed URL:</th>
  182.                    <td><input style="width:30em;" type="text" name="wp_votd_other_url" id="wp_votd_other_url" value="<?=(array_key_exists($options['wp_votd_version'], $VOTD_DEFAULT_FEEDS) ? '' : $options['wp_votd_url'])?>" /></td>
  183.                   </tr>
  184.                   </table>
  185.                   </fieldset>
  186.                   <fieldset class="options">
  187.                   <legend>Customization</legend>
  188.                   <table width="100%" cellspacing="2" cellpadding="5" class="editform">
  189.                   <tr>
  190.                    <th scope="row" width="33%" valign="top">Display Template:<div style="font-weight:normal;">Changing this will change how the verse displays on your site.  Use it to set class/id tags to style the verse using CSS.</div></th>
  191.                    <td><textarea rows="3" cols="55" name="wp_votd_template" id="wp_votd_template"><?=$options['wp_votd_template']?></textarea></td>
  192.                   </tr>
  193.                 <?php
  194.                 if ($show_block) {
  195.                 ?>
  196.                   <tr>
  197.                    <th width="33%" scope="row" valign="top">Create a <a href="http://warpspire.com/hemingway">Hemingway</a> block:<?=($block_error ? '<div style="color:#FF0000; font-weight: bold;">'.$block_error.'</div>' : '')?></th>
  198.                    <td>
  199.                    <input type="checkbox" name="wp_votd_create_block" id="wp_votd_create_block" value="1"<?=($options['wp_votd_create_block'] ? ' checked="checked"' : '')?> />
  200.                    </td>
  201.                   </tr>
  202.                 <?php
  203.                   }
  204.                 ?>
  205.                   <tr>
  206.                    <th scope="row" width="33%">Display Output:</th>
  207.                    <td><?=$cache_contents?></td>
  208.                   </tr>
  209.                   </table>
  210.                   </fieldset>
  211.                   <div class="submit"><input type="submit" name="info_update" value="<?php _e('Update') ?> &raquo;" /></div>
  212.                  </form>
  213.                         <div style="background-color:rgb(238, 238, 238); border: 1px solid rgb(85, 85, 85); padding: 5px; margin-top:10px;">
  214.                         <p>Did you find this plugin useful?  Please consider donating to help me continue developing it and other plugins.</p>
  215.                 <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  216.                 <input type="hidden" name="cmd" value="_xclick">
  217.                 <input type="hidden" name="business" value="paypal@slaven.net.au">
  218.                 <input type="hidden" name="item_name" value="Verse of the Day Wordpress Plugin">
  219.                 <input type="hidden" name="no_note" value="1">
  220.                 <input type="hidden" name="currency_code" value="AUD">
  221.                 <input type="hidden" name="tax" value="0">
  222.                 <input type="hidden" name="bn" value="PP-DonationsBF">
  223.                 <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
  224.                 </form></div>
  225.                 </div>
  226.                 <?php
  227.                 }       
  228.                
  229.                 function get_feed() {
  230.                         return get_option('wp_votd_cache');
  231.                 }
  232.                
  233.                 function update_contents() {
  234.                         $options = get_option('wp_votd_options');
  235.                
  236.                         if ($options['wp_votd_url'] && class_exists('Snoopy') && class_exists('MagpieRSS')) {
  237.  
  238.                                 //Grab the url & parse
  239.                                 $client = new Snoopy();
  240.                                 $client->read_timeout = 3;
  241.                                 $client->use_gzip = true;
  242.                                 @$client->fetch($options['wp_votd_url']);
  243.                                 if ($client->results) {
  244.                                         $rss = new MagpieRSS($client->results);
  245.                                         if ($rss && is_array($rss->items) && count($rss->items) > 0) {
  246.  
  247.                                                 $enclosure = preg_match('/\<enclosure.*?url="(.*?)".*?\>/i',$client->results, $matches);
  248.                                                 $enclosure = $matches[1];
  249.                                                 $enclosure = str_replace("&","&amp;",$enclosure);
  250.  
  251.                                     //Pull content out of the feed
  252.                                                 $verse_title = $rss->items[0]['title'];
  253.                                                 $verse_body = ($rss->items[0]['content']['encoded'] ? $rss->items[0]['content']['encoded'] : $rss->items[0]['description']);
  254.                                                 $verse_link = ($rss->items[0]['guid'] ? $rss->items[0]['guid'] : $rss->items[0]['link']);
  255.                                                 $verse_link = str_replace("&","&amp;",$verse_link);
  256.                                                 $verse_version = $options['wp_votd_version'];
  257.                                                 $version_name = $options['wp_votd_name'];
  258.  
  259.                                                 //Insert verse into template
  260.                                                 $content = preg_replace(
  261.                                                         array(
  262.                                                                 '/\[TEXT\]/',
  263.                                                                 '/\[TITLE\]/',
  264.                                                                 '/\[LINK\]/',
  265.                                                                 '/\[VERSION\]/',
  266.                                                                 '/\[ENCLOSURE\]/'
  267.                                                         ),
  268.                                                         array(
  269.                                                                 $verse_body,
  270.                                                                 $verse_title,
  271.                                                                 $verse_link,
  272.                                                                 ($verse_version ? ", <abbr title=\"{$options['wp_votd_name']}\">{$options['wp_votd_version']}</abbr>" : ''),
  273.                                                                 ($enclosure ? " <span class=\"votdenclosure\">(<a href=\"$enclosure\">Listen</a>)</span>" : '')
  274.                                                         ),
  275.                                                         $options['wp_votd_template']
  276.                                                 );
  277.  
  278.                                                 update_option('wp_votd_cache', $content);
  279.                                                 update_option('wp_votd_lastcache_time', time());
  280.  
  281.                                                 return $content;
  282.                                         } else {
  283.                                                 if ($_GET['dieloud']) { print "<span style=\"color:#FF0000;\"><strong>VOTD Plugin Error</strong><br />Sorry, the script cannot understand the feed from '<a href=\"{$options['wp_votd_url']}\">{$options['wp_votd_url']}</a>'.  Please check that this is a valid RSS feed.</span>\n"; }
  284.                                         }
  285.                                 } else {
  286.                                         if ($_GET['dieloud']) { print "<span style=\"color:#FF0000;\"><strong>VOTD Plugin Error</strong><br />Sorry, the script was unable to retrieve anything from '<a href=\"{$options['wp_votd_url']}\">{$options['wp_votd_url']}</a>'.  Please check that URL to ensure it is available.</span>\n"; }
  287.                                 }
  288.                         }       
  289.                 }
  290.         }
  291. }
  292.  
  293. $wp_votd = new wp_votd();
  294.  
  295. function wp_votd() {
  296.         global $wp_votd;
  297.         print $wp_votd->get_feed();
  298. }
  299.  
  300. ?>

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

fantasy-obligation