Advertisement
terorama

WP / dk_rss_digest.php

May 29th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 60.57 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: DK RSS Digest
  4. Plugin URI: http://dmkim1.bget.ru/
  5. Description: Plugin for RSS aggregation and autoposting
  6. Version: 4.44
  7. Author: Dmitriy Kim
  8. Author URI: http://dmkim1.bget.ru/
  9.  
  10. License: GPL2
  11.  
  12. Copyright 2013.  Dmitriy Kim  (email : dmkim1979@gmail.com)
  13.  
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License, version 2, as
  16. published by the Free Software Foundation.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  26. */
  27.  
  28. //------------------------------------ error handler
  29.    
  30.  function pubHandler($number, $message, $file, $line) {
  31.      
  32.           if (($number!=E_USER_ERROR) && ($number!=E_USER_WARNING))
  33.              return;
  34.      
  35.           ob_start();
  36.                  
  37.           echo '<h2>error occured</h2>';
  38.           echo '<p>'.str_pad('error number: ',30,' ',STR_PAD_RIGHT).$number.'</p>';
  39.           echo '<p>'.str_pad('error message: ',30,' ',STR_PAD_RIGHT).$message.'</p>';
  40.           echo '<p>'.str_pad('error in file: ',30,' ',STR_PAD_RIGHT).$file.'</p>';
  41.           echo '<p>'.str_pad('error in line: ',30,' ',STR_PAD_RIGHT).$line.'</p>';
  42.          
  43.           $s = ob_get_clean();   
  44.          
  45.           $logfile = dirname(__FILE__).'/cronlog.txt';
  46.  
  47.           if (file_exists($logfile))
  48.             $fh = fopen($logfile,'a');
  49.          else
  50.             $fh = fopen($logfile,'w');
  51.  
  52.          fwrite($fh, date('d.m.Y H:i:s  ').$s);
  53.          fclose($fh);
  54.            
  55.          
  56.    };
  57.  
  58.  
  59. class Debugger {
  60.  
  61.  
  62.    private static $_prepared = false;
  63.    private static $_debugFile ='';
  64.    private static $_buffer ='';
  65.    
  66.    //---------------------------------
  67.    private static function isDebugFile() {
  68.    
  69.       return (bool)self::$_debugFile;
  70.    }
  71.    //---------------------------------
  72.    private static function prepared() {
  73.    
  74.       if (self::$_prepared)
  75.              return true;
  76.                
  77.        return false;
  78.    }
  79.  
  80.    //--------------------------------- prepare file
  81.    private static function prepare_file() {
  82.    
  83.       if (!file_exists(ROOT.DS.'logs'))
  84.              mkdir (ROOT.DS.'logs');
  85.                  
  86.       self::$_debugFile = ROOT.DS.'logs'.DS.'debugz.html';
  87.      
  88.    }
  89.    
  90.    //------------------------------------ output buffer
  91.    private static function outputBuffer() {
  92.      
  93.       if (self::isDebugFile()) {
  94.              if (!file_exists(self::$_debugFile))
  95.                  
  96.                 $f = fopen (self::$_debugFile,'w');
  97.                  else
  98.             $f = fopen (self::$_debugFile,'w');
  99.  
  100.          fwrite($f, self::$_buffer);
  101.                  fclose($f);            
  102.           } else
  103.              echo '<h2>debug information</h2><div style="font-family:courier new">'.self::$_buffer.'</div>';
  104.    }
  105.    
  106.    //------------------------------------ error handler
  107.    
  108.    public static function errorHandler($number, $message, $file, $line) {
  109.      
  110.           if (($number!=E_USER_ERROR) && ($number!=E_USER_WARNING))
  111.              return;
  112.              
  113.           ob_start();
  114.                  
  115.           echo '<h2>error occured</h2>';
  116.           echo '<p>'.str_pad('error number: ',30,' ',STR_PAD_RIGHT).$number.'</p>';
  117.           echo '<p>'.str_pad('error message: ',30,' ',STR_PAD_RIGHT).$message.'</p>';
  118.           echo '<p>'.str_pad('error in file: ',30,' ',STR_PAD_RIGHT).$file.'</p>';
  119.           echo '<p>'.str_pad('error in line: ',30,' ',STR_PAD_RIGHT).$line.'</p>';
  120.          
  121.           $s = ob_get_clean();   
  122.            self::$_buffer .= nl2br($s);
  123.            
  124.           self::outputBuffer();
  125.    }
  126.    
  127.    //----------------------------------- exception handler
  128.    
  129.    public static function exceptionHandler($exception) {
  130.      
  131.           ob_start();
  132.          
  133.           echo '<h2>exception occured</h2>';
  134.           echo '<p>'.str_pad('exception code: ',30,' ',STR_PAD_RIGHT).$exception->getCode().'</p>';
  135.           echo '<p>'.str_pad('exception message: ',30).$exception->getMessage().'</p>';
  136.           echo '<p>'.str_pad('exception in file: ',30).$exception->getFile().'</p>';
  137.           echo '<p>'.str_pad('exception in line: ',30).$exception->getLine().'</p>';
  138.          
  139.           //echo '<h3>exception trace</h3>';    
  140.           //echo '<pre>'.print_r($exception->getTrace(),true).'</pre>';
  141.          
  142.           $s = ob_get_clean();
  143.            self::$_buffer .= nl2br($s);
  144.          
  145.           self::outputBuffer();
  146.    }
  147.    
  148.    //----------------------------------- shutdown handler
  149.    
  150.    public static function shutdownHandler() {
  151.    
  152.        ob_start();
  153.        
  154.       $error = error_get_last();
  155.          
  156.           echo '<h2>script finished</h2>';
  157.           echo 'error: <pre>'.print_r($error,true).'</pre>';
  158.          
  159.            $s = ob_get_clean();
  160.            self::$_buffer .= nl2br($s);
  161.          
  162.           self::outputBuffer();
  163.    }
  164.    
  165.    //--------------------------------- prepare debugger
  166.    public static function prepare() {
  167.      
  168.       if (!defined('DEBUG_MODE') || (!DEBUG_MODE))
  169.              return;
  170.          
  171.       if (self::prepared())
  172.              return;
  173.        
  174.           error_reporting(E_ERROR | E_WARNING);
  175.           ini_set('display_errors','On');
  176.    
  177.           set_error_handler (array('Debugger','errorHandler'));
  178.           set_exception_handler (array('Debugger','exceptionHandler'));
  179.           register_shutdown_function (array('Debugger','shutdownHandler'));
  180.          
  181.           if (defined('DEBUG_FILE') && (DEBUG_FILE==true))
  182.              self::prepare_file();
  183.                
  184.       self::$_buffer = '';
  185.       self::$_prepared = true;
  186.            
  187.    }
  188.    //--------------------------------- handle & write info
  189.    
  190.    public static function writeInfo($info, $className, $method) {
  191.    
  192.       if (!defined('DEBUG_MODE') || (!DEBUG_MODE))
  193.              return;
  194.                        
  195.           self::prepare();
  196.          
  197.                  
  198.           $s = str_repeat('-',50)."\r\n";        
  199.       $s  .= date('d.m.Y H:i:s').'  class: '.$className.' method: '.$method. "\r\n";
  200.           $s  .= str_repeat('-',50)."\r\n";
  201.          
  202.           $inf = array();
  203.           if (!is_array($info)) {
  204.              $inf[] = $info;
  205.           } else
  206.              $inf = $info;
  207.        
  208.       $s .= '<pre>'.print_r($inf, true).'</pre>';
  209.          
  210.          
  211.              
  212.           self::$_buffer .= nl2br($s);
  213.    }
  214. }
  215.  
  216. //--------------------------------------------------------
  217. define ('DS',DIRECTORY_SEPARATOR);
  218. define ('ROOT', dirname(__FILE__));
  219. //define ('DEBUG_MODE', true);
  220. //define ('DEBUG_FILE', true);
  221.  
  222. Debugger::prepare();
  223. //--------------------------------------------------------
  224. class DKRSSDigest {
  225.  
  226.    private $wp_url;
  227.    private $wp_dir;
  228.    
  229.    private $plugin_url;
  230.    private $plugin_dir;
  231.    
  232.    private $template_url;
  233.    private $template_dir;
  234.    
  235.    private $stylesheet_url;
  236.    private $stylesheet_dir;
  237.    
  238.    private $upload_url;
  239.    private $upload_dir;
  240.    
  241.    private $wp_charset;
  242.    private $wp_version;
  243.    
  244.    private $ajax_url;
  245.    
  246.    private $_options;
  247.    
  248.    //---------------------------- debug information
  249.    protected function _w($info, $method) {
  250.    
  251.       $className = get_class($this);
  252.       Debugger::writeInfo($info, $className, $method);
  253.    }
  254.  
  255.    //------------------------------------
  256.    public function __construct() {
  257.    
  258.       $this->_options = get_option('dk_rss_digest_options');
  259.  
  260.       //register_activation_hook(__FILE__, array(&$this, 'install'));
  261.       add_action('activate_dk_rss_digest/dk_rss_digest.php', array(&$this,'install'));
  262.      
  263.       register_deactivation_hook(__FILE__, array(&$this, 'uninstall'));
  264.      
  265.       add_action ('init', array(&$this,'dk_redir'));
  266.      
  267.       if ($this->_options['pub_register_custom_post']==1)
  268.          add_action ('init', array(&$this,'dk_posttype'));
  269.          
  270.       add_action ('admin_init', array(&$this, 'dk_init'));
  271.       add_action('plugins_loaded', array(&$this,'dk_plugins_loaded'));
  272.       add_action ('admin_menu', array(&$this,'dk_register_admin_menu'));
  273.      
  274.       add_action('wp_ajax_rss-management',array(&$this,'dk_ajax_rss_management'));
  275.       add_action('wp_ajax_post_types', array(&$this,'dk_ajax_post_types'));
  276.       add_action('wp_ajax_taxz', array(&$this,'dk_ajax_taxz'));
  277.       add_action('wp_ajax_catz', array(&$this,'dk_ajax_catz'));
  278.      
  279.       //add_filter('cron_schedules', array(&$this,'dk_schedule_intervals'));
  280.      
  281.       add_action('sc_check_feeds', array(&$this,'check_feeds'));
  282.       //add_action('sc_check_feeds', array(&$this,'publish_posts'));
  283.    }
  284.    
  285.    //------------------------------------------------------
  286.    //                cron_schedules
  287.    //------------------------------------------------------
  288.    public function dk_schedule_intervals($schedules) {
  289.    
  290.      $periods = $this->_options['pub_schedule_periods'];
  291.    
  292.      foreach ($periods as $period) {
  293.          $schedules[$period.'days'] = array(
  294.               'interval' => 3600*24*$period,
  295.               'display' => __( $period.' days' )
  296.           );
  297.        }
  298.     return $schedules;
  299.    }
  300.    //------------------------------------------------------
  301.    //                Plugin Activation
  302.    //------------------------------------------------------
  303.    public function install() {
  304.          
  305.          
  306.       require_once(dirname(__FILE__).'/inc/rss.inc.php');
  307.       $rss = new Rss();
  308.       $rss->mk_tables();
  309.      
  310.       $default_options = array (
  311.          'pub_post_type' => 'post',
  312.          'pub_taxonomy' => 'category',
  313.          'pub_category' => 0,
  314.          'pub_register_custom_post'=> 0,
  315.          'pub_schedule_hooks'=>array()
  316.       );
  317.       add_option('dk_rss_digest_options', $default_options);
  318.  
  319.       wp_schedule_event( time(), 'hourly', 'sc_check_feeds');
  320.      
  321.  
  322.    }
  323.    
  324.    //------------------------------------------------------
  325.    //                Plugin Deactivation
  326.    //------------------------------------------------------
  327.    public function uninstall() {
  328.    
  329.    
  330.       wp_clear_scheduled_hook('sc_check_feeds');
  331.       delete_option('dk_rss_digest_options');
  332.    }
  333.    //------------------------------------------------------
  334.    //       scheduled event [sc_check_feeds]
  335.    //------------------------------------------------------
  336.    public function check_feeds() {
  337.    
  338.       $prevh = set_error_handler("pubHandler");
  339.    
  340.       require_once(dirname(__FILE__).'/inc/rss.inc.php');
  341.       $logfile = dirname(__FILE__).'/cronlog.txt';
  342.      
  343.       if (file_exists($logfile))
  344.          $fh = fopen($logfile,'a');
  345.       else
  346.          $fh = fopen($logfile,'w');
  347.          
  348.       $rss = new Rss;
  349.       $res = $rss->get_rsslines();  
  350.  
  351.       foreach ($res as $line) {  
  352.          try {
  353.             $s = $rss->update_rssline($line);
  354.             fwrite ($fh,date('d.m.Y H:i:s  ').$s."\r\n");
  355.          } catch
  356.            (Exception $e) {
  357.             fwrite ($fh,date('d.m.Y H:i:s  ').$e->getMessage()."\r\n");
  358.          }
  359.       }
  360.      
  361.       fclose ($fh);
  362.      
  363.       $this-> publish_posts();
  364.    }
  365.    
  366.    //------------------------------------------
  367.    //      publich scheduled posts
  368.    //------------------------------------------
  369.    public function publish_posts() {
  370.      
  371.       $logfile = dirname(__FILE__).'/cronlog.txt';
  372.      
  373.       if (file_exists($logfile))
  374.          $fh = fopen($logfile,'a');
  375.       else
  376.          $fh = fopen($logfile,'w');
  377.      
  378.       require_once(dirname(__FILE__).'/inc/base.inc.php');
  379.       require (dirname(__FILE__).'/inc/classmap.php');
  380.    
  381.          foreach ($classmap as $incfile) {
  382.          
  383.             if (file_exists(dirname(__FILE__).'/inc/'.$incfile))
  384.                require_once(dirname(__FILE__).'/inc/'.$incfile);
  385.          }
  386.          
  387.          require_once (dirname(__FILE__).'/inc/app/digest.inc.php');
  388.          require_once (dirname(__FILE__).'/inc/app/digestelement.inc.php');
  389.      
  390.          $injector = new Injector();
  391.          $dbconn = new DBConn();
  392.          $injector->set($dbconn);
  393.          $dbmodel = new DBModel($injector);
  394.          $injector->set($dbmodel);
  395.      
  396.          $model = new Digest($injector);
  397.          //------------------------------------
  398.  
  399.          $hooks = $this->_options['pub_schedule_hooks'];
  400.          
  401.          foreach ($hooks as $key=>$value) {
  402.          
  403.             $inf = $model->getSingle($key);
  404.             $period = $inf['digest_schedule_period'];
  405.             fwrite ($fh, date('d.m.Y H:i:s  ').'post '.$inf['digest_title'].' scheduled '.date('d.m.Y H:i',$hooks[$key])."\r\n");
  406.            
  407.             if (($value-time()<60*15) || (5==5)) {
  408.            
  409.                
  410.                $model->publish($key);
  411.                $hooks[$key] = strtotime("+".$period." days", $value);
  412.                
  413.                fwrite ($fh, date('d.m.Y H:i:s  ').'post '.$inf['digest_title'].' published ');
  414.                fwrite ($fh, ' next scheduled time: '. date('d.m.Y H:i',$hooks[$key])."\r\n");
  415.             }      
  416.          }
  417.          $this->_options['pub_schedule_hooks'] = $hooks;
  418.          update_option('dk_rss_digest_options', $this->_options);
  419.          
  420.          fclose ($fh);
  421.          
  422.    }
  423.    
  424.    //------------------------------------------------------
  425.    //                      init
  426.    //------------------------------------------------------
  427.    public function dk_redir() {
  428.    
  429.     $this->_w('hook triggered', __METHOD__);
  430.    
  431.     if( preg_match('/\/about\/?$/',$_SERVER['REQUEST_URI'])){
  432.        $af = (dirname(__FILE__)).'/about.php';  
  433.  
  434.        if (file_exists($af)) {  
  435.             include $af;
  436.             exit;
  437.         }
  438.     }
  439.    }
  440.    
  441.    //------------------------------------------------------
  442.    //                      init
  443.    //------------------------------------------------------
  444.    public function dk_posttype() {
  445.    
  446.        $args = array( 'public' => true,
  447.    
  448.        'labels' => array(
  449.                    'name' => __( 'Digests' ),
  450.                    'singular_name' => __( 'Digest' )
  451.             ),
  452.        'has_archive' => true,
  453.        'supports'=> array('title','editor','author','excerpt','comments','thumbnail'),
  454.        'rewrite' => array('slug' => 'digest')   );
  455.    
  456.        register_post_type( 'digest', $args );
  457.    
  458.    
  459.        register_taxonomy(
  460.          'direction',
  461.          'digest',
  462.          array(
  463.             'label' => __( 'Direction' ),
  464.             'rewrite' => array( 'slug' => 'direction' ),
  465.             'hierarchical' => true
  466.          )
  467.       );
  468.    
  469.       //flush_rewrite_rules();
  470.    }
  471.    
  472.    //------------------------------------------------------
  473.    //                   admin_init
  474.    //------------------------------------------------------
  475.    public function dk_init() {
  476.    
  477.       //global $pagenow, $current_screen;
  478.       $this->_w('hook triggered', __METHOD__);
  479.      
  480.       $this->wp_url = home_url();
  481.       $this->wp_dir = ABSPATH;
  482.      
  483.       $this->plugin_url = trailingslashit (WP_PLUGIN_URL .'/'.dirname(plugin_basename(__FILE__)));
  484.       $this->plugin_dir = trailingslashit (WP_PLUGIN_DIR .'/'.dirname(plugin_basename(__FILE__)));
  485.      
  486.       $this->template_url = trailingslashit (get_template_directory_uri());
  487.       $this->template_dir = trailingslashit (get_template_directory());
  488.      
  489.       $this->stylesheet_url = trailingslashit (get_stylesheet_directory_uri());
  490.       $this->stylesheet_dir = trailingslashit (get_stylesheet_directory());
  491.      
  492.       $tmp = wp_upload_dir();
  493.       $this->upload_url = trailingslashit ($tmp['baseurl']);
  494.       $this->upload_dir = trailingslashit ($tmp['basedir']);
  495.      
  496.       $this->wp_charset = get_bloginfo('charset');
  497.       $this->wp_version = get_bloginfo('version');
  498.      
  499.       $this->ajax_url = admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http'));
  500.      
  501.       //-------------------------------------------------
  502.      
  503.       add_settings_section('main_section',__('General settings'), array($this,'main_settings_section'),'dk-main-menu');
  504.      
  505.       add_settings_field('pub_post_type',__('Post type for publications'),array($this,'pub_post_type_setting'),
  506.                        'dk-main-menu','main_section');
  507.    
  508.       add_settings_field('pub_taxonomy',__(''),array($this,'pub_taxonomy_setting'),'dk-main-menu','main_section'); 
  509.    
  510.       add_settings_field('pub_category',__('Category for publications'),array($this,'pub_category_setting'),
  511.                        'dk-main-menu','main_section'); 
  512.                        
  513.       add_settings_field('pub_register_custom_post',
  514.                   __('Register custom post type (Digests) for publications ?'),array($this,'pub_custom_post_setting'),
  515.                        'dk-main-menu','main_section');                     
  516.                        
  517.       register_setting('dk_rss_digest_options','dk_rss_digest_options', array($this,'validate_options'));
  518.      
  519.      
  520.      
  521.       //-------------------------------------------------
  522.       if (isset($_GET['page']) && ($_GET['page']=='dk-rss-management')) {
  523.      
  524.          //wp_deregister_script('jquery');
  525.          //wp_register_script('jquery',$this->plugin_url.'inc/jquery.min.js', false);
  526.          //add_action('admin_print_scripts', array(&$this,'dk_inline_script'));
  527.          
  528.          add_action('admin_enqueue_scripts', array(&$this,'dk_scripts'));
  529.          add_action('admin_print_styles', array(&$this,'dk_inline_style'));
  530.          add_action('admin_head', array(&$this,'dk_inline_script'));
  531.  
  532.          }
  533.          
  534.      if (isset($_GET['page']) && ($_GET['page']=='dk-digest-management')) {
  535.      
  536.  
  537.          add_action('admin_enqueue_scripts', array(&$this,'dk_scripts'));
  538.          add_action('admin_print_styles', array(&$this,'dk_inline_style4'));
  539.          add_action('admin_head', array(&$this,'dk_inline_script4'));
  540.  
  541.          }
  542.          
  543.       if (isset($_GET['page']) && ($_GET['page']=='dk-main-menu')) {
  544.      
  545.          add_action('admin_enqueue_scripts', array(&$this,'dk_scripts'));
  546.          add_action('admin_head', array(&$this,'dk_inline_script5'));
  547.        }
  548.    
  549.    }
  550.    //------------------------------------------------------
  551.    //                plugins_loaded
  552.    //------------------------------------------------------
  553.    public function dk_plugins_loaded() {
  554.    
  555.       $this->_w('hook triggered', __METHOD__);
  556.       if (is_admin()) {
  557.          //load_plugin_textdomain('dk_rss', $this->plugin_dir.'lang/');
  558.          }
  559. }
  560.    //------------------------------------------------------
  561.    //             admin_enqueue_scripts
  562.    //------------------------------------------------------
  563.    public function dk_scripts() {
  564.    
  565.       $this->_w('hook triggered', __METHOD__);
  566.       wp_enqueue_script('jquery');
  567.      
  568.      
  569.    }
  570.  
  571.    //------------------------------------------------------
  572.    //             admin_head (dk-rss-management)
  573.    //------------------------------------------------------
  574.    public function dk_inline_script() {
  575.    
  576.        $this->_w('hook triggered', __METHOD__);
  577.        $ajax_nonce = wp_create_nonce('rss-test88');
  578.        
  579.    ?>
  580.    
  581.    <script type="text/javascript">
  582.     jQuery(document).ready(init);
  583.      
  584.        ajax_get='';
  585.        ajax_post='';
  586.        
  587.       //------------------------------------------
  588.       function init() {
  589.      
  590.        
  591.          //-------------------
  592.          jQuery('#dkrss_container a[rel^="_"], #dkrss_container input:button[rel^="_"]').unbind('click').click ( function(ev) {
  593.            
  594.             var ev = ev || event;
  595.            
  596.             if (jQuery(this).get(0).tagName=='A')
  597.                if  (jQuery(this).get(0).hasAttribute("rel")) {
  598.                   jQuery(this).prev().attr('checked','checked');
  599.                }
  600.                        
  601.             //--------------------------------
  602.             if (this.hasAttribute('lnname'))
  603.                var line_name = this.getAttribute('lnname');
  604.             else
  605.                var line_name = '';
  606.             //--------------------------------
  607.             if (this.hasAttribute('pg'))
  608.                var page_id = this.getAttribute('pg');
  609.             else
  610.                var page_id = 'z';
  611.             //--------------------------------
  612.             if (!ajax_get)
  613.                ajax_get = new Ajax_get();
  614.        
  615.             ajax_get.query(jQuery(this).attr('rel').slice(1), line_name, page_id);
  616.            
  617.             if (ev.preventDefault)
  618.                ev.preventDefault();
  619.             else
  620.                ev.returnValue = false;
  621.              
  622.          });
  623.          //-------------------
  624.          jQuery('#dkrss_container form').filter(
  625.             function(index) {
  626.                return (this.hasAttribute('rel')) && (jQuery(this).attr('rel').substr(0,1)=='_');})
  627.                .unbind('submit')
  628.                .submit( function(ev) {
  629.                  
  630.                   var ev = ev || event;
  631.                  
  632.                   if (!ajax_post)
  633.                      ajax_post = new Ajax_post();
  634.                    
  635.                   var data8 = {};
  636.                   jQuery(this).find('input[name]').each (
  637.                      function(i) {
  638.                         data8[this.name]=this.value;
  639.                      }
  640.                   );
  641.                  
  642.                   jQuery.when (ajax_post.query(jQuery(this).attr('rel').slice(1), data8))
  643.                   .done(function(){updateState();});
  644.                  
  645.                  
  646.                  
  647.                   if (ev.preventDefault)
  648.                      ev.preventDefault();
  649.                   else
  650.                      ev.returnValue = false;
  651.                      
  652.                });
  653.                
  654.          //----------------------------------
  655.          jQuery('#dkrss_contentheader').unbind().ajaxStart(
  656.             function() {
  657.                jQuery(this).html('ajax request started...');
  658.             }
  659.          );
  660.          //----------------------------------
  661.          jQuery('#dkrss_contentheader').unbind().ajaxStop(
  662.             function() {
  663.                jQuery(this).html('ajax request finished');
  664.             }
  665.          );
  666.          //----------------------------------
  667.                  
  668.       };
  669.  
  670.       //------------------------------------------
  671.       Ajax_get = function () {
  672.      
  673.          var _self = this;
  674.          
  675.          //----------------------
  676.          this.onSuccess = function(inf, status, xhr) {
  677.            
  678.             jQuery('#dkrss_ajaxblock').empty().html(inf);
  679.             init();
  680.          }
  681.      
  682.          //----------------------
  683.          this.onError = function(xhr, status, exception) {
  684.            
  685.             var inf = [];
  686.             inf.push ('ajaxResponse: <pre>'+xhr.responseText+'</pre>');
  687.             inf.push ('status: '+xhr.status);
  688.             inf.push ('ready state: '+xhr.readyState);
  689.             inf.push ('text status: '+status);
  690.             inf.push ('exception: '+exception);
  691.            
  692.             s = inf.join('<br/>');
  693.            
  694.             jQuery('#dkrss_ajaxblock').empty().html(s);
  695.          }
  696.          
  697.          //----------------------
  698.          this.query = function (action, line_name, page_id) {
  699.          
  700.             var line_name = line_name || jQuery('#lineform input:radio:checked').val();
  701.            
  702.             var data = {
  703.                   action: 'rss-management',
  704.                   security: '<?php echo $ajax_nonce; ?>',
  705.                   action4: action,
  706.                   line_name: line_name
  707.                };
  708.    
  709.             if (!isNaN(page_id)) {
  710.            
  711.                data['page'] = page_id
  712.             }
  713.              
  714.  
  715.             return jQuery.ajax ( {       
  716.                type: 'GET',
  717.                url: "<?php echo $this->ajax_url; ?>",
  718.                    
  719.                data: data,
  720.                success: _self.onSuccess,
  721.                error: _self.onError
  722.             })
  723.          }
  724.       };
  725.      
  726.       //------------------------------------------
  727.       Ajax_post = function () {
  728.      
  729.          var _self = this;
  730.          
  731.          //----------------------
  732.          this.onSuccess = function (inf, status, xhr) {
  733.          
  734.             jQuery('#dkrss_ajaxblock').empty().html(inf);
  735.          }
  736.          
  737.          //----------------------
  738.          this.onError = function (xhr, status, exception) {
  739.          
  740.             var inf = [];
  741.             inf.push ('ajaxResponse: <pre>'+xhr.responseText+'</pre>');
  742.             inf.push ('exception: '+exception);
  743.            
  744.             s = inf.join('<br/>');
  745.            
  746.             jQuery('#dkrss_ajaxblock').empty().html(s);
  747.            
  748.          }
  749.          
  750.          //----------------------
  751.          this.query = function (action, data) {
  752.          
  753.             return jQuery.ajax ( {
  754.                type: 'POST',
  755.                
  756.                url: "<?php echo $this->ajax_url; ?>" +'?action=rss-management&action4='+action+
  757.                '&security=<?php echo $ajax_nonce; ?>',
  758.                
  759.                data : data,
  760.                success: _self.onSuccess,
  761.                error: _self.onError
  762.             });
  763.          }
  764.          
  765.       }
  766.      
  767.       //-------------------------------------------------
  768.       function updateState() {
  769.      
  770.          var addr = '<?php echo $this->ajax_url; ?>';
  771.          
  772.  
  773.          jQuery.when (jQuery.get( addr, {action:'rss-management',action4: 'show_rsslines',
  774.                                  security: '<?php echo $ajax_nonce ?>'})).done(
  775.             function(tx) {
  776.                jQuery('#dkrss_twitlines').empty().html(tx);
  777.                init();             
  778.             }
  779.          )
  780.          
  781.          
  782.            
  783.       }
  784.    </script>
  785.    
  786.    
  787.    <?php
  788.    }
  789.    //------------------------------------------------------
  790.    //         admin_head (dk-digest-management)
  791.    //------------------------------------------------------
  792.    public function dk_inline_script4() {
  793.  
  794.       $ajax_url8 = $this->plugin_url.'inc/ajax_ind4.php';
  795.       $ajax_nonce = wp_create_nonce('digest-test88');
  796.      
  797.       ?>
  798.      
  799.       <script type="text/javascript">
  800.      
  801.    var gl_current_digest = 0;
  802.    
  803.    //-----------------------------------------
  804.    function init() {
  805.       jQuery('#all_ajax_status').ajaxStart( function() {
  806.          
  807.          jQuery(this).html('Request started, Please wait...');
  808.       });
  809.       //--------------------
  810.       jQuery('#all_ajax_status').ajaxStop( function() {
  811.          jQuery(this).html('Request finished.');
  812.       });
  813.       //--------------------
  814.       jQuery('#all_ajax_status').ajaxSend( function (ev, xhr, options) {
  815.      
  816.          jQuery(this).html('Request sent, status:'+xhr.status);
  817.          
  818.          
  819.       });
  820.       //--------------------
  821.       jQuery('#all_ajax_status').ajaxSuccess (function( ev, xhr, options) {
  822.      
  823.          jQuery(this).html('Request success, status:'+xhr.status+', readystate:'+xhr.readyState);
  824.          
  825.          jQuery(options.statusblock).html('');
  826.  
  827.          
  828.       });
  829.       //--------------------
  830.       jQuery('#all_ajax_status').ajaxError( function( ev, xhr, options, err) {
  831.      
  832.          jQuery(this).html('Error occured: '+err+', status:'+xhr.status);
  833.          
  834.          jQuery(options.statusblock).html('error occured :'+err);    
  835.          jQuery(options.targetblock).html('response: '+xhr.responseText+'<br/>'+
  836.          ' xhr status:'+xhr.status+'<br/>xhr ready state:'+xhr.readyState+'<br/>');
  837.          
  838.       });
  839.       //--------------------
  840.       jQuery('#all_ajax_status').ajaxComplete( function( ev, xhr, options) {
  841.       });  
  842.    }
  843.    
  844.    //-----------------------------------------
  845.    function ajaxBeforeSend (xhr, options) {
  846.    
  847.       jQuery(options.statusblock).html('request started, please wait...');
  848.    }
  849.  
  850.    //-----------------------------------------
  851.    function ajaxSuccess (target_block) {
  852.    
  853.       return function(inf, status, xhr) {
  854.          jQuery(target_block).html(inf);
  855.          
  856.          redir_links(target_block);
  857.          
  858.          if (target_block=='#digests_ajax')
  859.             master_detail_events(target_block);
  860.            
  861.          
  862.       }
  863.    }
  864.    
  865.    //-----------------------------------------
  866.    function ajaxError (xhr, status, err) {
  867.    }
  868.    
  869.    //-----------------------------------------
  870.    function ajaxComplete (xhr, status) {
  871.    }
  872.    //-----------------------------------------
  873.    function master_detail_events(target_block) {
  874.    
  875.       jQuery('.entrytitle a',jQuery(target_block)).unbind('click').click(
  876.          function() {
  877.             var re = /digest_id=(\d+)/;
  878.             var zid = re.exec(this.href);
  879.             gl_current_digest = zid[1];
  880.            
  881.             ajax_request('#digests_details_ajax_info',
  882.             '#digests_details_ajax', "<?php echo $ajax_url8; ?>?controller=digestelements&filterdigestelements="+
  883.             encodeURIComponent('digest_id='+gl_current_digest));
  884.            
  885.             return false;
  886.          }
  887.       )
  888.      
  889.       jQuery('.entrytitle a',jQuery(target_block)).eq(0).trigger('click');
  890.    
  891.      
  892.    }
  893.    //-----------------------------------------
  894.    function redir_links(target_block) {
  895.      
  896.       jQuery('a',target_block).click( function() {
  897.      
  898.          var route = jQuery(this).attr('href')
  899.          
  900.          if (target_block=='#digests_details_ajax')      
  901.             route += "&filterdigestelements="+encodeURIComponent('digest_id='+gl_current_digest);
  902.            
  903.          if (this.innerHTML=='publish') {
  904.             var dt = new Date();
  905.             var defstr = dt.getFullYear()+'-'+(dt.getMonth()+1)+'-'+dt.getDate();
  906.             var s = prompt("Enter publishing date", defstr );
  907.             if ((s==null) || (s=="")) {
  908.                s =defstr;
  909.             }
  910.             route +='&pubdate='+s;
  911.          }
  912.                      
  913.            
  914.          ajax_request(target_block+'_info', target_block, route );
  915.          return false;
  916.       });
  917.      
  918.       jQuery('input:hidden[name=digest_id]').attr('value', gl_current_digest);
  919.      
  920.       var frm =jQuery('form',target_block);
  921.       if (frm.length>0) {
  922.          var events = frm.data("events");  
  923.          var fnz = events.submit[0]['handler'];
  924.          frm.unbind('submit', events.submit[0]);
  925.       }      
  926.        
  927.       jQuery('form',target_block).bind('submit', function() {
  928.    
  929.          if (fnz.call(this)==false)
  930.             return false;
  931.        
  932.          var data = {};
  933.          jQuery(this).find('input[name],select[name],textarea[name]').each(
  934.             function(ind, el4) {
  935.                data[el4.name] = el4.value;
  936.             })
  937.            
  938.           if (target_block=='#digests_details_ajax')
  939.              this.action += "&filterdigestelements="+encodeURIComponent('digest_id='+gl_current_digest);     
  940.          
  941.          ajax_request(target_block+'_info', target_block, this.action, 'POST', data);
  942.          return false;
  943.       });
  944.      
  945.       jQuery('input:button[name="cancel"]',target_block).attr('onclick','').click( function() {
  946.      
  947.          var route = jQuery(this).parent().find('input:hidden[name="cancelroute"]').attr('value');
  948.          
  949.          if (target_block=='#digests_details_ajax')
  950.              route +=   "&filterdigestelements="+encodeURIComponent('digest_id='+gl_current_digest);   
  951.          
  952.          ajax_request(target_block+'_info', target_block, route);
  953.          return false;
  954.       });
  955.  
  956.    }
  957.    //-----------------------------------------
  958.    function ajax_request(status_block, target_block, inurl, intype, indata) {
  959.    
  960.       var intype = intype || 'GET';
  961.       var indata = indata || {};
  962.      
  963.       indata['security']='<?php echo $ajax_nonce; ?>';
  964.          
  965.       jQuery.ajax ( {
  966.      
  967.          url: inurl,
  968.          type: intype,
  969.          data: indata,
  970.          dataType: 'html',
  971.          
  972.          statusblock: status_block,
  973.          targetblock: target_block,
  974.          
  975.          beforeSend: ajaxBeforeSend,
  976.          success: ajaxSuccess(target_block),
  977.          error: ajaxError,
  978.          complete: ajaxComplete
  979.       })
  980.    }
  981.    //-----------------------------------------
  982.    jQuery(document).ready ( function() {
  983.       init();
  984.      
  985.       ajax_request('#digests_ajax_info', '#digests_ajax', "<?php echo $ajax_url8; ?>?controller=digests");
  986.    });
  987.      
  988. </script>
  989.  
  990.       <?php
  991.    }
  992.    
  993.  
  994. //------------------------------------------------------
  995. //         admin_head (dk-main-menu)
  996. //------------------------------------------------------
  997.    public function dk_inline_script5() {
  998.       ?>  
  999.       <script type="text/javascript">
  1000.  
  1001.      jQuery(document).ready (
  1002.         function() {
  1003.        
  1004.         //----------------------------------
  1005.         var handler = function() {
  1006.          
  1007.             var value4 = jQuery(this).val();
  1008.            
  1009.             jQuery.ajax ( {
  1010.             url: "<?php echo $this->ajax_url;?>", type: 'POST',  dataType: 'html',
  1011.             data: {action: 'taxz', ptype: value4 },
  1012.             success: function(inf) {
  1013.                jQuery('#tax_sel_inp').replaceWith(inf);
  1014.          }});
  1015.          
  1016.          jQuery('#cat_sel_inp').attr('disabled',true);
  1017.          jQuery.ajax ( {
  1018.             url: "<?php echo $this->ajax_url;?>", type: 'POST',  dataType: 'html',
  1019.             data: {action: 'catz', ptype: value4 },
  1020.             success: function(inf) {
  1021.                jQuery('#cat_sel_inp').replaceWith(inf);
  1022.          }});
  1023.          
  1024.          }
  1025.        
  1026.     //----------------------------------
  1027.     jQuery('input[name="dk_rss_digest_options[pub_register_custom_post]"]').change(
  1028.               function() {
  1029.              
  1030.                  var value4 = jQuery(this).val();
  1031.        
  1032.         jQuery.ajax ( {
  1033.          url: "<?php echo $this->ajax_url;?>", type: 'POST',  dataType: 'html',
  1034.          data: {action: 'post_types', reg_post: value4 },
  1035.          success: function(inf) {
  1036.          
  1037.             //var events = jQuery(this).data("events");  
  1038.             //jQuery('#post_type_sel_inp').unbind('change', events.change[0]);
  1039.              
  1040.             jQuery('#post_type_sel_inp').replaceWith(inf);
  1041.             jQuery('#post_type_sel_inp').bind('change', handler);
  1042.             jQuery('#post_type_sel_inp').trigger('change');
  1043.          }});
  1044.       });
  1045.       //----------------------------------
  1046.       jQuery('#post_type_sel_inp').bind('change', handler);
  1047.      
  1048.       //----------------------------------
  1049.      
  1050.         })
  1051.  
  1052.     </script>    
  1053.  
  1054. <?php    
  1055.    }
  1056.    //------------------------------------------------------
  1057.    //      admin_print_styles (dk-rss-management)
  1058.    //------------------------------------------------------
  1059.    public function dk_inline_style() {
  1060.    
  1061.       $this->_w('hook triggered', __METHOD__);
  1062.    ?>
  1063.     <style type="text/css">
  1064.    
  1065.      
  1066.       #dkrss_container ul {
  1067.          list-style-type: none;
  1068.       }
  1069.      
  1070.       #dkrss_container a {
  1071.          color:inherit;      
  1072.       }
  1073.      
  1074.       #dkrss_container {
  1075.          width: 90%;
  1076.        
  1077.          margin: 0 auto;
  1078.          
  1079.          font-family: verdana, helvetica, sans-serif;
  1080.          font-size: 1em;
  1081.       }
  1082.      
  1083.       #dkrss_header {
  1084.          height: 200px;
  1085.          /*background: #800;
  1086.          color: white;*/
  1087.          position:relative;
  1088.       }
  1089.          
  1090.       #dkrss_sidebar {
  1091.          float:left;
  1092.          width: 300px;
  1093.          padding: 20px 0 0 0;
  1094.       }
  1095.      
  1096.      
  1097.      
  1098.       #dkrss_twitlines li {
  1099.          height: 1.5em;
  1100.          line-height:1.5em;
  1101.          border-bottom: dotted 1px;
  1102.       }
  1103.      
  1104.       #dkrss_twitlines input[type=radio] {
  1105.          width:50px;
  1106.       }
  1107.      
  1108.       #dkrss_twitlines li a {
  1109.          text-decoration: none;
  1110.       }
  1111.      
  1112.       #dkrss_container .controls {
  1113.          overflow: auto;
  1114.          margin: 10px 0 0 0;
  1115.          padding: 0 0 20px 0;
  1116.  
  1117.       }
  1118.      
  1119.       #dkrss_container .controls li {
  1120.          float:left;
  1121.          margin-top: 5px;
  1122.          margin-right:10px;
  1123.          border: solid 1px #500;
  1124.          border-radius: 10px;
  1125.          background: #ffe;
  1126.          padding: 5px 10px;
  1127.          /*font-size: 0.75em;*/
  1128.       }
  1129.      
  1130.       #dkrss_container .controls li a {
  1131.      
  1132.          text-decoration: none;
  1133.       }
  1134.      
  1135.       #dkrss_container .controls li a:hover {
  1136.      
  1137.          text-decoration: underline;
  1138.       }
  1139.      
  1140.       #dkrss_content {
  1141.          margin-left: 320px;
  1142.          
  1143.       }
  1144.      
  1145.       #dkrss_contentheader {
  1146.          height: 0px;
  1147.          /*background: #400;*/
  1148.          color: white;
  1149.       }
  1150.      
  1151.       #dkrss_ajaxblock {
  1152.  
  1153.          border: dotted 1px #888;
  1154.       }
  1155.      
  1156.       #dkrss_footer {
  1157.      
  1158.          height: 50px;
  1159.          background: #444;
  1160.          clear:left;
  1161.       }
  1162.      
  1163.       /*-------------------------*/
  1164.       #dkrss_container .twitfeed {
  1165.          font-size: 0.75em;
  1166.       }  
  1167.      
  1168.       #dkrss_container .twitfeed li {
  1169.              overflow: auto;
  1170.              margin-top: 5px;
  1171.          position: relative;
  1172.          border-bottom: dotted 1px #888;
  1173.          padding-bottom: 3px;
  1174.          padding-right: 160px;
  1175.       }
  1176.  
  1177.       #dkrss_container .twitfeed li a {
  1178.              text-decoration: none;
  1179.              color: #800;
  1180.           }
  1181.      
  1182.       #dkrss_container .twitid {
  1183.          display:none;
  1184.       }
  1185.       #dkrss_container .twittitle {
  1186.          line-height:1.5;
  1187.       }
  1188.       #dkrss_container .twitdesc {
  1189.  
  1190.          width:60%;
  1191.              float:left;
  1192.              margin-right:5px;
  1193.       }
  1194.      
  1195.       #dkrss_container .twitlink {
  1196.  
  1197.              float: left;
  1198.              font-size: 10px;
  1199.              
  1200.              width: 39%;
  1201.              word-wrap: break-word;
  1202.              
  1203.       }
  1204.           li .twitlink  a {
  1205.              color: #999;
  1206.           }
  1207.       #dkrss_container .twitpubdate {
  1208.        
  1209.         position:absolute; 
  1210.         right:0;
  1211.         bottom:0;
  1212.         background: #ffe;
  1213.         border: solid 1px #f5f5f5;
  1214.         color: #555;   
  1215.         padding: 0 10px;
  1216.         width: 130px;
  1217.        
  1218.         border-radius: 5px;
  1219.         -moz-border-radius: 5px;
  1220.         -webkit-border-radius: 5px;
  1221.       }
  1222.      
  1223.       #dkrss_container .pager {
  1224.          overflow: auto;
  1225.          padding: 10px 0 15px 0;
  1226.       }
  1227.       #dkrss_container .pager li {
  1228.          
  1229.          float:left;
  1230.          margin: 0 5px 4px 0;
  1231.          border: solid 1px #500;
  1232.          
  1233.          border-radius: 10px;
  1234.          -moz-border-radius: 10px;
  1235.          -webkit-border-radius: 10px;
  1236.          
  1237.          background: #ffe;
  1238.          font-size:0.75em;
  1239.          overflow:hidden;
  1240.          
  1241.       }
  1242.       #dkrss_container .pager li a {
  1243.          
  1244.          display:block;
  1245.        
  1246.          height: 100%;
  1247.          padding: 0.5em 10px;
  1248.          text-decoration: none;
  1249.          
  1250.       }
  1251.       #dkrss_container .pager li a:hover {
  1252.      
  1253.          background: #444;
  1254.          color: white;
  1255.       }
  1256.       /*-------------------------*/
  1257.       #dkrss_container form {
  1258.          overflow: auto;
  1259.          padding: 5px;
  1260.          margin:5px;
  1261.          
  1262.       }
  1263.      
  1264.       #dkrss_container form p {
  1265.        
  1266.       }
  1267.      
  1268.       #dkrss_container form input[type=text] {
  1269.          margin-left:20px;
  1270.       }
  1271.      
  1272.       #dkrss_container form input[type=button],
  1273.       #dkrss_container form input[type=submit],
  1274.       #dkrss_container form input[type=reset] {
  1275.      
  1276.          display:block;
  1277.          float: left;
  1278.          margin: 5px 5px 0 0;
  1279.          padding: 5px 8px;
  1280.          background: #f0f0f0;
  1281.          cursor:pointer;
  1282.          border: solid 1px #444;
  1283.          
  1284.          border-radius: 10px;
  1285.          -moz-border-radius: 10px;
  1286.          -webkit-border-radius: 10px;
  1287.       }
  1288.      
  1289.       #dkrss_container form input[type=submit] {
  1290.          clear: left;
  1291.       }
  1292.      
  1293.      
  1294.    </style>
  1295.    
  1296.    <?php
  1297.    }
  1298.    
  1299.     //------------------------------------------------------
  1300.    //      admin_print_styles (dk-digest-management)
  1301.    //------------------------------------------------------
  1302.    public function dk_inline_style4() {
  1303.    
  1304.    ?>
  1305.    
  1306.    <style type="text/css">
  1307.            
  1308.      #dkdigest_container {
  1309.              font-family: verdana, sans-serif;
  1310.              font-size:100%;
  1311.           }
  1312.          
  1313.      #dkdigest_container  #container {      
  1314.              width:1000px;
  1315.              margin:0 auto;
  1316.           }
  1317.          
  1318.    
  1319.          
  1320.      #dkdigest_container .header {          
  1321.                  display: none;        
  1322.           }
  1323.          
  1324.      #dkdigest_container .content {
  1325.      
  1326.              float:left;
  1327.                  width:1100px;
  1328.                  margin-bottom: 5px;
  1329.                  margin-top: 20px;
  1330.           }
  1331.          
  1332.      #dkdigest_container .page {
  1333.              float:left;
  1334.           }
  1335.          
  1336.      #dkdigest_container .page>div {
  1337.              float:left;
  1338.              margin:0 0 0;         
  1339.              height: 30px;
  1340.              width: 130px;
  1341.              padding: 4px 10px;
  1342.              border: solid 1px #aaa;     
  1343.              border-left: none;
  1344.              font-size: 12px;
  1345.           }
  1346.          
  1347.      #dkdigest_container div.entrytitle {
  1348.              margin-top: 0;
  1349.              font-size:1.2em;
  1350.              font-weight:bold;
  1351.              width:200px;    
  1352.              height:30px;
  1353.              line-height:30px;
  1354.              text-align:center;
  1355.                  
  1356.              background: #eee;
  1357.                
  1358.              border-radius:10px;
  1359.              -moz-border-radius:10px;
  1360.              -webkit-border-radius:10px;
  1361.                  
  1362.              float: left;
  1363.              clear:left;
  1364.              padding: 4px 50px;  
  1365.           }
  1366.          
  1367.      #dkdigest_container .page>div.caption {
  1368.         border-bottom: none;
  1369.      }   
  1370.      #dkdigest_container div.caption:first-child {
  1371.      
  1372.            width: 200px;
  1373.            padding: 4px 50px;
  1374.      }   
  1375.          
  1376.      #dkdigest_container .entrytitle a {
  1377.              color:#999;
  1378.                  text-decoration: none;
  1379.                  
  1380.           }
  1381.      #dkdigest_container .entrytitle a:hover {
  1382.              color:#555;
  1383.           }
  1384.          
  1385.          
  1386.      #dkdigest_container .entryeditpanel {      
  1387.              margin-top:10px;
  1388.              overflow:hidden;
  1389.              /*position: relative;*/
  1390.              top: -40px;
  1391.              height: 80px!important;
  1392.              
  1393.           }
  1394.      
  1395.      #dkdigest_container .entryeditpanel>div {
  1396.          margin-top:4px;
  1397.      }   
  1398.      #dkdigest_container .editpanel {
  1399.               overflow:hidden;
  1400.              
  1401.           }
  1402.       #dkdigest_container .editbutton,
  1403.       #dkdigest_container .deletebutton,
  1404.       #dkdigest_container .addbutton,
  1405.       #dkdigest_container .backtolistbutton {
  1406.          
  1407.              background:#ff9;
  1408.                  font-weight:bold;
  1409.                  font-size: 12px;
  1410.                  text-align:center;
  1411.                  padding:1px 10px;
  1412.                  margin-right:5px;
  1413.                  
  1414.                  border: solid 2px #800;
  1415.                  -moz-border-radius: 8px;
  1416.                  -webkit-border-radius: 8px;
  1417.                  border-radius: 8px;              
  1418.                  float:left;
  1419.           }
  1420.          
  1421.        #dkdigest_container .editbutton a,
  1422.        #dkdigest_container .deletebutton a,
  1423.        #dkdigest_container .addbutton a,
  1424.        #dkdigest_container .backtolistbutton a{
  1425.          
  1426.              color:#c00;
  1427.                  text-decoration: none;
  1428.           }
  1429.    
  1430.          
  1431.        #dkdigest_container .sidebar {
  1432.              
  1433.                  display:none;
  1434.           }
  1435.          
  1436.         #dkdigest_container .footer {
  1437.                  clear:both;              
  1438.                  background: #f0f0f0;
  1439.                  padding:0;
  1440.                  margin-bottom:20px;        
  1441.           }
  1442.  
  1443.         #dkdigest_container div.clearfix {
  1444.            clear: left;  
  1445.            width:0;
  1446.            height:0;
  1447.            padding:0;
  1448.            border:none;
  1449.         }
  1450.          
  1451.         #dkdigest_container .navigation {
  1452.              margin-top:4px;
  1453.              overflow: hidden;
  1454.           }
  1455.          
  1456.          #dkdigest_container .navigation ul {
  1457.              list-style-type:none;
  1458.           }
  1459.           #dkdigest_container .navigation li {
  1460.              float:left;
  1461.                  margin-right: 5px;
  1462.                  text-align:center;
  1463.                  height:40px;
  1464.                  line-height:40px;
  1465.                  background: white;
  1466.                  font-weight: bold;
  1467.                  width: 40px;
  1468.                  border: solid 1px #555;
  1469.                  -moz-border-radius:4px;
  1470.                  -webkit-border-radius:4px;
  1471.           }
  1472.          
  1473.     #dkdigest_container .navigation li a,
  1474.     #dkdigest_container .navigation li a:visited {
  1475.    
  1476.              text-decoration:none;
  1477.                  color: #800;
  1478.           }
  1479.      #dkdigest_container .navigation li a:hover {
  1480.              text-decoration: underline;
  1481.           }
  1482.          
  1483.       #dkdigest_container form {
  1484.              
  1485.                  padding:20px 40px 10px 20px;
  1486.           }
  1487.          
  1488.       #dkdigest_container fieldset {
  1489.              padding-top:10px;
  1490.           }
  1491.          
  1492.       #dkdigest_container legend {
  1493.            
  1494.                  display: none;
  1495.           }
  1496.       #dkdigest_container label {
  1497.                  display:block;
  1498.                  float:left;
  1499.                  clear:left;
  1500.                  width:200px;
  1501.                  margin-right:10px;
  1502.                  margin-top: 5px;
  1503.           }
  1504.       #dkdigest_container input,  
  1505.       #dkdigest_container select {
  1506.      
  1507.              display: block;
  1508.                  
  1509.                  border: solid 1px #aaa;
  1510.                  border-radius: 4px;
  1511.                  -moz-border-radius: 4px;
  1512.                  -webkit-border-radius: 4px;
  1513.                  padding:2px 5px;
  1514.                  margin-top:5px;
  1515.           }
  1516.          
  1517.       #dkdigest_container input[type=text] {
  1518.              width:400px;
  1519.           }
  1520.          
  1521.        #dkdigest_container input[type=submit],
  1522.        #dkdigest_container input[type=button] {
  1523.          
  1524.              background:#ffa;
  1525.                  float:left;
  1526.                  border:solid 2px #a00;
  1527.                  border-radius 8px;
  1528.                  -moz-border-radius 8px;
  1529.                  -webkit-border-radius 8px;
  1530.                  color:#b00;
  1531.                  cursor:pointer;
  1532.                  padding:4px 20px;
  1533.                  
  1534.                  font-size:1em;
  1535.                  margin-right:10px;
  1536.                  margin-top:10px;
  1537.                  
  1538.           }
  1539.          
  1540.       #dkdigest_container #all_ajax_status {
  1541.          
  1542.              display: none;
  1543.           }
  1544.    </style>
  1545.    
  1546.    
  1547.    <?php
  1548.    }
  1549.    
  1550.    //------------------------------------------------------
  1551.    //                    admin_menu
  1552.    //------------------------------------------------------
  1553.    public function dk_register_admin_menu() {
  1554.    
  1555.       $this->_w('hook triggered', __METHOD__);
  1556.      
  1557.       add_menu_page(__('DK RSS Digest Settings'), __('DK RSS Digest Settings'),
  1558.       'activate_plugins','dk-main-menu', array(&$this,'dk_menu_page'));
  1559.    
  1560.       add_submenu_page('dk-main-menu', __('RSS setup'), __('RSS setup'),
  1561.       'activate_plugins', 'dk-rss-management', array(&$this,'dk_rss_page'));
  1562.    
  1563.       add_submenu_page('dk-main-menu', __('Publishing'),__('Publishing'),
  1564.       'activate_plugins', 'dk-digest-management', array(&$this,'dk_digest_page'));
  1565.      
  1566.        add_submenu_page('dk-main-menu', __('Help'),__('Help'),
  1567.       'activate_plugins', 'dk-help', array(&$this,'dk_help'));
  1568. }
  1569.  
  1570.    //------------------------------------------------------
  1571.    //         settings_section [main_section]
  1572.    //------------------------------------------------------
  1573.    public function main_settings_section() {
  1574.    
  1575.       echo '<h3>'.__('DK RSS Digest Settings').'</h3>';
  1576.    }
  1577.    //------------------------------------------------------
  1578.    //            settings_field [pub_post_type]
  1579.    //------------------------------------------------------
  1580.    public function pub_post_type_setting() {
  1581.    
  1582.       $excl = array('page','attachment','revision','nav_menu_item');
  1583.    
  1584.       if (isset($_POST['reg_post'])) {
  1585.          if ($_POST['reg_post']==1) {
  1586.             $this->dk_posttype();
  1587.          }
  1588.          else {
  1589.             array_push($excl, 'digest');
  1590.          }
  1591.       }  
  1592.       $inf = get_post_types();
  1593.    
  1594.       $inf = array_diff($inf, $excl);
  1595.      
  1596.       echo '<select id="post_type_sel_inp" name="dk_rss_digest_options[pub_post_type]">';
  1597.       foreach ($inf as $ptype) {
  1598.          echo '<option value="'.$ptype.
  1599.                   '" '.selected($this->_options['pub_post_type'],$ptype,false).' >'.$ptype.'</option>';
  1600.       }
  1601.       echo '</select>';
  1602.      
  1603.                
  1604.    }  
  1605.    
  1606.    //------------------------------------------------------
  1607.    //           settings_field [pub_taxonomy]  
  1608.    //------------------------------------------------------
  1609.    public function pub_taxonomy_setting() {
  1610.    
  1611.        if (isset($_POST['ptype'])) {
  1612.        
  1613.           $this->dk_posttype();
  1614.        
  1615.           $ptype = $_POST['ptype'];
  1616.  
  1617.           $args = array('object_type'=>array($ptype));
  1618.           $output = 'names';
  1619.           $operator = 'and';
  1620.           $taxz = get_taxonomies($args, $output, $operator);
  1621.          
  1622.           $tax = reset($taxz);       
  1623.        }
  1624.        else {
  1625.              $tax = $this->_options['pub_taxonomy'];
  1626.           }
  1627.    
  1628.        echo '<input id="tax_sel_inp" type="hidden" '.
  1629.             'name="dk_rss_digest_options[pub_taxonomy]" value="'.
  1630.              $tax.'" />';
  1631.    }  
  1632.    //------------------------------------------------------
  1633.    //           settings_field [pub_category]  
  1634.    //------------------------------------------------------
  1635.    public function pub_category_setting() {
  1636.    
  1637.       if (isset($_POST['ptype'])) {
  1638.      
  1639.              $this->dk_posttype();
  1640.          
  1641.              $ptype = $_POST['ptype'];
  1642.          
  1643.              $args = array('object_type'=>array($ptype));
  1644.              $output = 'names';
  1645.              $operator = 'and';
  1646.              $taxz = get_taxonomies($args, $output, $operator);
  1647.              $tax = reset($taxz);  
  1648.          
  1649.          } else {
  1650.            
  1651.             $ptype = $this->_options['pub_post_type'];
  1652.             $tax = $this->_options['pub_taxonomy'];
  1653.          }
  1654.       $cats = get_categories('taxonomy='.$tax.'&type='.$ptype.'&hide_empty=0');
  1655.        
  1656.       echo '<select id="cat_sel_inp" name="dk_rss_digest_options[pub_category]">';
  1657.      
  1658.       foreach ($cats as $cat) {
  1659.          echo '<option value="'.$cat->term_id.
  1660.                   '" '.selected($this->_options['pub_category'],$cat->term_id,false).' >'.$cat->name.'</option>';
  1661.       }
  1662.       echo '</select></div>';
  1663.    }  
  1664.    
  1665.  
  1666.    //------------------------------------------------------
  1667.    //      settings_field [pub_register_custom_post]
  1668.    //------------------------------------------------------
  1669.    public function pub_custom_post_setting() {
  1670.    
  1671.       echo '<input id="reg_custom_post" type="radio"
  1672.             name="dk_rss_digest_options[pub_register_custom_post]"
  1673.             value="1" '.checked($this->_options["pub_register_custom_post"],1,false).' /> Yes<br/>';
  1674.            
  1675.        echo '<input id="unreg_custom_post" type="radio"
  1676.             name="dk_rss_digest_options[pub_register_custom_post]"
  1677.             value="0" '.checked($this->_options["pub_register_custom_post"],0,false).' /> No<br/>';
  1678.    }
  1679.    //-----------------------------------------------------------------
  1680.    //   main-settings-group [dk_rss_digest_options] validate
  1681.    //-----------------------------------------------------------------
  1682.    public function validate_options($input) {
  1683.    
  1684.       return $input;
  1685.    }
  1686.    //------------------------------------------------------
  1687.    //           Menu Page [dk-main-menu]
  1688.    //------------------------------------------------------
  1689.    public function dk_menu_page() {
  1690.  
  1691.       $this->_w('hook triggered', __METHOD__);
  1692.      
  1693.       echo '<h3>DK RSS Digest</h3>';
  1694.       echo '<ul><li><a href="'.admin_url('admin.php?page=dk-rss-management').'">'.__('RSS management').'</a></li>';
  1695.       echo '<li><a href="'.admin_url('admin.php?page=dk-digest-management').'">'.__('Publishing management').'</a></li>';
  1696.       echo '<li><a href="'.admin_url('admin.php?page=dk-help').'">'.__('Help').'</a></li>';
  1697.       echo '</ul>';
  1698.      
  1699.       ?>
  1700.      
  1701.          <form action="options.php" method="post">
  1702.             <?php settings_fields( 'dk_rss_digest_options' ); ?>
  1703.             <?php do_settings_sections('dk-main-menu'); ?>
  1704.             <p class="submit">
  1705.                 <input name="Submit" type="submit" value="<?php echo __('Save Changes'); ?>" />
  1706.             </p>
  1707.             </form>
  1708.      
  1709.       <?php
  1710.    
  1711. }
  1712.  
  1713.    //------------------------------------------------------
  1714.    //           Menu Page [dk-rss-management]
  1715.    //------------------------------------------------------
  1716.    public function dk_rss_page() {
  1717.    
  1718.       $this->_w('hook triggered', __METHOD__);
  1719.          
  1720.       require_once($this->plugin_dir.'inc/rss.inc.php');
  1721.       $rss = new Rss();
  1722.      
  1723.       //-----------
  1724.       ?>
  1725.      
  1726.       <div id="dkrss_container">
  1727.    <div id="dkrss_header">
  1728.      Here you can register RSS feeds you want use to create aggregations<br/>
  1729.      <ul><li> Click "add rss feed" and in appeared form fill the name and address of RSS feed
  1730.      (the "name" is the alias you will use later to relate to this feed). Submit the form</li>
  1731.      <li>If you want to retrieve RSS content immediately click "update RSS feed"
  1732.       then click the link with the name of feed at the left. You will see the latest retrieved content of the feed</li>
  1733.      <li>After you registered RSS feed its content will be retrieved automatically every hour and saved into WordPress database </li>
  1734.      <li>If you want to alter name or address of RSS feed select the feed you want to change at the left
  1735.      and click "edit rss feed". Make changes and submit the form</li>
  1736.      <li>To delete all retrieved content of RSS feed from WordPress database select the feed and click "clear rss feed"  </li>
  1737.      <li>To delete RSS feed from the list of registered feeds select the feed and click "delete RSS feed"</li>
  1738.      </ul>   
  1739.          
  1740.    </div>
  1741.  
  1742.    <div id="dkrss_sidebar">      
  1743.       <div id="dkrss_twitlines">
  1744.          <?php try {echo $rss->show_rsslines();} catch (Exception $e) {echo $e->getMessage();} ?>
  1745.       </div>
  1746.       <div id="dkrss_controls">
  1747.          <?php try {echo $rss->show_controls();} catch( Exception $e) {echo $e->getMessage();} ?>
  1748.       </div>
  1749.    </div>
  1750.    
  1751.    <div id="dkrss_content">
  1752.       <div id="dkrss_contentheader">
  1753.       </div>
  1754.      
  1755.       <div id="dkrss_ajaxblock">
  1756.       </div>
  1757.    </div>
  1758.    
  1759.    <div id="dkrss_footer">
  1760.    </div>
  1761. </div>
  1762.      
  1763.       <?php
  1764.       //-----------
  1765.    }
  1766.    
  1767.    //------------------------------------------------------
  1768.    //            wp_ajax_rss-management
  1769.    //------------------------------------------------------
  1770.    public function dk_ajax_rss_management() {
  1771.      
  1772.       $this->_w('hook triggered', __METHOD__);
  1773.  
  1774.       if (!check_ajax_referer('rss-test88','security',false)) {
  1775.      
  1776.          _e('Failed to verify referer');
  1777.          exit();
  1778.       }
  1779.      
  1780.       require_once($this->plugin_dir.'inc/rss.inc.php');
  1781.  
  1782.       $action= (isset($_GET['action4'])) ? $_GET['action4'] : '';
  1783.       $line_name =(isset($_GET['line_name'])) ? $_GET['line_name'] : '';
  1784.    
  1785.       $rss = new Rss();
  1786.  
  1787.       if ($action) {
  1788.          echo $rss->$action($line_name);
  1789.          exit();
  1790.       }
  1791.    }
  1792.    
  1793.    //------------------------------------------------------
  1794.    //            wp_ajax_post_types
  1795.    //------------------------------------------------------
  1796.    public function dk_ajax_post_types() {
  1797.    
  1798.       $this->pub_post_type_setting();
  1799.       exit();
  1800.    }
  1801.    //------------------------------------------------------
  1802.    //            wp_ajax_taxz
  1803.    //------------------------------------------------------
  1804.    public function dk_ajax_taxz() {
  1805.    
  1806.       $this->pub_taxonomy_setting();
  1807.       exit();
  1808.    }
  1809.    //------------------------------------------------------
  1810.    //            wp_ajax_catz
  1811.    //------------------------------------------------------
  1812.    public function dk_ajax_catz() {
  1813.    
  1814.       $this->pub_category_setting();
  1815.       exit();
  1816.    }  
  1817.    
  1818.  
  1819.    //------------------------------------------------------
  1820.    //             Menu Page [dk-digest-management]
  1821.    //------------------------------------------------------
  1822.    public function dk_digest_page() {
  1823.  
  1824.        @ini_set('display_errors',true);
  1825.        
  1826.        
  1827.        if (!empty($_POST['test_s']) && ($_POST['test_s']=="inf")) {
  1828.             $this->publish_posts();
  1829.            
  1830.          }
  1831.       else
  1832.       if (!empty($_POST['do_update'])) {
  1833.        
  1834.          check_admin_referer('add-test88');
  1835.          
  1836.        
  1837.          
  1838.          require_once($this->plugin_dir.'inc/base.inc.php');
  1839.    
  1840.          require ($this->plugin_dir.'inc/classmap.php');
  1841.    
  1842.          foreach ($classmap as $incfile) {
  1843.          
  1844.             if (file_exists($this->plugin_dir.'inc/'.$incfile))
  1845.                require_once($this->plugin_dir.'inc/'.$incfile);
  1846.          }
  1847.          
  1848.          require_once ($this->plugin_dir.'inc/app/digest.inc.php');
  1849.      
  1850.          $injector = new Injector();
  1851.          $dbconn = new DBConn();
  1852.          $injector->set($dbconn);
  1853.          $dbmodel = new DBModel($injector);
  1854.          $injector->set($dbmodel);
  1855.      
  1856.          $model = new Digest($injector);
  1857.          //------------------------------------
  1858.          $els = $model->getAll();
  1859.          //------------------------------------
  1860.          
  1861.          $hooks = array();
  1862.          echo '<h3>Elements scheduled for automatic publishing</h3>';
  1863.          echo '<ul>';
  1864.          
  1865.          foreach ($els as $el) {
  1866.             if ($el['digest_is_active']==1) {
  1867.            
  1868.                $tm = strtotime($el['digest_schedule_time']);               
  1869.                if ($tm<time())
  1870.                    $tm = strtotime("+1 days", $tm);
  1871.      
  1872.                $hooks[$el['digest_id']] = $tm;
  1873.                
  1874.                echo '<li>'.$el['digest_title'].' next publishing: '.date('d.m.Y H:i',$tm).'</li>';
  1875.             }
  1876.          }   
  1877.          echo '</ul>';
  1878.          //------------------------------------
  1879.          $this->_options['pub_schedule_hooks']=$hooks;
  1880.          update_option('dk_rss_digest_options', $this->_options);
  1881.       }
  1882.  
  1883. ?>
  1884.  
  1885.    <div id="dkdigest_container">
  1886.    
  1887.       <h3>List of schedules</h3>
  1888.       <div id="all_ajax_status"></div>
  1889.       <div id="digests_ajax_info"></div>
  1890.       <div id="digests_ajax"></div>
  1891.  
  1892.       <h3 id="current_digest">Schedule details</h3>
  1893.       <div id="digests_details_ajax_info"></div>
  1894.       <div id="digests_details_ajax"></div>
  1895.      
  1896.       <form name="savef" action="<?php echo admin_url('admin.php?page=dk-digest-management');?>" method="POST">
  1897.      
  1898.       <?php wp_nonce_field('add-test88'); ?>
  1899.          <input type="checkbox" name="test_s" value="inf" /> Test schedule<br/>
  1900.          <input type="submit" name="do_update" value="update schedule" />
  1901.          
  1902.       </form>
  1903.    </div>
  1904. <?php
  1905.    }
  1906.    
  1907.    
  1908.      //------------------------------------------------------
  1909.    //             Menu Page [dk-help]
  1910.    //------------------------------------------------------
  1911.    public function dk_help() {
  1912.    
  1913. ?>
  1914.  
  1915.    <p>The plugin is contrived as tool for filling the WordPress blog automatically, using  the content of various sites, provided through RSS feeds. Final output supposed to be some mixture of this information and plugin provides tools for gathering information, combining it in different ways and setting up the schedule for automatic publishings. For example it might be information about certain subject from the various news sites combined with comments about it from blogs or social networks supplemented with photos from somewhere else. Or you can setup the daily or weekly announcements about updates at number of interesting sites. By now the plugin is in an experimental stage and my objective here is to provide maximum flexibility in combining information so it could be used for wide range of tasks concerning aggregation. Any suggestions about improvements are welcome.</p>
  1916.  
  1917. <p>After activating the plugin you will see two additional pages in WordPress admin menu. First named "RSS setup" allows you to register RSS feeds you are going to use. Each registered feed will be automatically scheduled for checks for updates. Checks for updates will be conducted each hour and retrieved information will be stored in your WordPress database. (This procedure will prevent you from missing some information in cases when the feed updates are much more frequent then your scheduled post updates. For example you publish some post every week and want to include into it the content of the feed for this period. Likely that the actual feed at this moment will not contain all information for such a long period especially if it has frequent or massive updates. Therefore plugin takes  information saved beforehead into WordPress database instead)</p>
  1918.  
  1919. <p>
  1920. The second menu named "Publishing" purposed for assembling initial information from RSS feeds into form in which it will appear in WordPress posts and for scheduling automatic publishing. </p>
  1921.  
  1922. <p>
  1923. The setup of automatic publishing includes three steps.</p>
  1924.  
  1925. <p>
  1926. First you should register RSS feeds you want to get the content from. On the page "RSS setup" click link "add new feed". In the appeared form fill the name and address of the feed. The "name" is the alias which you will be using futher while assembling feeds for publishing. (It is only allowed to use alphanumeric characters or underscore in the "name") In the "address" field place actual url address of the feed. After submitting the form the RSS feed will be scheduled for checks for updates as mentioned above.  Repeat the procedure for all feeds you want to use.
  1927. </p>
  1928.  
  1929. <img src="<?php echo $this->plugin_url.'help/1.png';?>" /><br/>
  1930.  
  1931.  <ul>
  1932.  
  1933.      <li>If you want to retrieve RSS content immediately click "update RSS feed"
  1934.       then click the link with the name of feed at the left. You will see the latest retrieved content of the feed</li>
  1935.      <li>After you registered RSS feed its content will be retrieved automatically every hour and saved into WordPress database </li>
  1936.      <li>If you want to alter name or address of RSS feed select the feed you want to change at the left
  1937.      and click "edit rss feed". Make changes and submit the form</li>
  1938.      <li>To delete all retrieved content of RSS feed from WordPress database select the feed and click "clear rss feed"  </li>
  1939.      <li>To delete RSS feed from the list of registered feeds select the feed and click "delete RSS feed"</li>
  1940.      </ul>   
  1941.  
  1942. <p>
  1943. At the second step you create the publishing schedule. Suppose you want to publish once a month content of certain photo blogs .  Click the "Publishing". In the opened page you will see two tables. Upper table, containing schedule items, and lower, which contains the details for each schedule item, including information about what feeds will be included into post, in what order, the period of time for which the information will be retrieved for each feed, the html template for each feed.
  1944. </p>
  1945. <br/>
  1946.  
  1947. <p>
  1948.  Click the "add" button below the upper table and in appeared form specify the name of schedule item and period of publishing. In our example these will be Publication title: "Photo Blogs" , Publishing period (days) : 30. You can also specify the time of day for publications
  1949.  and post type and category in which these publications will be posted.
  1950.  </p>
  1951.  
  1952.  <img src="<?php echo $this->plugin_url.'help/5.png';?>" /><br/>
  1953.  
  1954.  When you activate schedule element
  1955.  (you can do it during creation by assigning "Active" for "Is publication active field" or later by clicking "Activate" button)
  1956.  this element will be automatically scheduled for publishing according to its settings.<br/>
  1957.  Below the element you will see exact time when next publication will occur<br/>
  1958.  
  1959.  <img src="<?php echo $this->plugin_url.'help/3.png';?>" /><br/>
  1960.  
  1961. <p>
  1962. At the next step you will determine how the RSS content will be combined for publishing. <br/>
  1963. In lower table "schedule details" you should create element for each RSS feed whose content you want include in the post.<br/>
  1964. For each element you should specify the name of RSS feed (which you assigned while registering the feed)<br/>
  1965. Specify the order ("Element order") in which content of this feed will be printed in post<br/>
  1966. In field "Request period in days" specify the period  for which feed content would be retrieved
  1967. (starting back from the day of publication)<br/><br/>
  1968. Specify the PHP template for processing the content. <br/>
  1969. This template will be processed for each feed item.
  1970. Using PHP will give you ability to perform complex operations on feed content.
  1971. (For example you can retrieve images from rss description as in the example below )
  1972. The template maintains conditional tags %title%, %description%, %link%, %pubdate%<br/>
  1973. While processing the template these tags are replaced with PHP variables containing corresponding values of feed<br/>
  1974. To create the output use "echo"<br/><br/>
  1975.  
  1976. Also specify "html template before elements", which will be printed before output of RSS items and
  1977. "html template after elements", which will be printed after output of RSS items<br/>
  1978. (these are html templates)<br/>
  1979. </p>
  1980.  
  1981.  <img src="<?php echo $this->plugin_url.'help/6.png';?>" /><br/>
  1982.  
  1983. Repeat the procedure for each RSS feed you want include in the post<br/><br/>
  1984.  
  1985.  <img src="<?php echo $this->plugin_url.'help/4.png';?>" /><br/>
  1986.  
  1987.  Tip: if you want content of some RSS feeds mixed together
  1988.  just specify for these feeds equal value in "Element order" field.<br/><br/>
  1989.  
  1990.  Note: In this version of plugin RSS items always ordered by date
  1991.  
  1992. <?php
  1993.    }
  1994.  
  1995. }
  1996.  
  1997. $digest = new DKRSSDigest();
  1998.  
  1999.  
  2000.  
  2001.  
  2002. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement