Exemplo n.º 1
0
 /**
  * Gets the data from an OPML file and turns it into a data object
  * as expected by PF
  * Prefers a post object, but can take a post ID. 
  *
  * @global $pf Used to access the feed_object() method
  *
  */
 public function get_data_object($aOPML)
 {
     set_time_limit(0);
     $feed_obj = new PF_Feeds_Schema();
     if (is_numeric($aOPML)) {
         $aOPML = get_post($aOPML);
     }
     pf_log('Invoked: PF_OPML_Subscribe::get_data_object()');
     $aOPML_url = $aOPML->guid;
     if (empty($aOPML_url) || is_wp_error($aOPML_url) || !$aOPML_url) {
         $aOPML_id = $aOPML->ID;
         $aOPML_url - get_post_meta($aOPML_id, 'feedUrl', true);
     }
     pf_log('Getting OPML Feed at ' . $aOPML_url);
     $OPML_reader = new OPML_reader();
     $opml_array = $OPML_reader->get_OPML_data($aOPML_url, false);
     $c = 0;
     $opmlObject = array();
     foreach ($opml_array as $feedObj) {
         $id = md5($aOPML_url . '_opml_sub_for_' . $feedObj['xmlUrl']);
         #if ( false === ( $rssObject['opml_' . $c] = get_transient( 'pf_' . $id ) ) ) {
         # Adding this as a 'quick' type so that we can process the list quickly.
         if ($feedObj['type'] == 'rss') {
             $feedObj['type'] = 'rss-quick';
         }
         if (!empty($feedObj['text'])) {
             $contentObj = new pf_htmlchecker($feedObj['text']);
             $feedObj['text'] = $contentObj->closetags($feedObj['text']);
         }
         if (!empty($feedObj['title'])) {
             $contentObj = new pf_htmlchecker($feedObj['title']);
             $feedObj['title'] = $contentObj->closetags($feedObj['title']);
         }
         if ($feedObj['title'] == '') {
             $feedObj['title'] = $feedObj['text'];
         }
         $check = $feed_obj->create($feedObj['xmlUrl'], array('type' => $feedObj['type'], 'title' => $feedObj['title'], 'htmlUrl' => $feedObj['htmlUrl'], 'description' => $feedObj['text'], 'type' => 'rss-quick'));
         pf_log('Creating subscription to ' . $feedObj['xmlUrl'] . ' from OPML Feed at ' . $aOPML_url);
         #var_dump($check); die();
         $content = 'Subscribed: ' . $feedObj['title'] . ' - ' . $feedObj['type'] . ' - ' . $feedObj['text'];
         $source = $feedObj['htmlUrl'];
         if (empty($source)) {
             $source = $feedObj['xmlUrl'];
         }
         $opmlObject['opml_' . $c] = pf_feed_object($feedObj['title'], 'OPML Subscription ' . $aOPML_url, date('r'), 'OPML Subscription', $content, $source, '', $id, date('r'), '');
         pf_log('Setting new transient for ' . $feedObj['xmlUrl'] . ' of ' . $source . '.');
         set_transient('pf_' . $id, $opmlObject['opml_' . $c], 60 * 10);
         $c++;
         #}
     }
     return $opmlObject;
 }
Exemplo n.º 2
0
 public function process_opml($opml)
 {
     $OPML_reader = new OPML_reader();
     $opml_array = $OPML_reader->get_OPML_data($opml);
     #print_r($opml_array); die();
     foreach ($opml_array as $key => $feedXml) {
         # Adding this as a 'quick' type so that we can process the list quickly.
         pf_log('Adding this as a quick type so that we can process the list quickly');
         $opml_array = pressforward()->pf_feeds->progressive_feedlist_transformer($opml_array, $feedXml, $key);
         # @todo Tag based on folder structure
     }
     #$check_up = update_option( PF_SLUG . '_feedlist', $opml_array );
 }
Exemplo n.º 3
0
 public static function pf_feedlist_validate($input)
 {
     set_time_limit(0);
     pf_log('Add Feed Process Invoked: PF_RSS_IMPORT::pf_feedlist_validate');
     pf_log($input);
     if (current_user_can('edit_post')) {
         pf_log('Yes, the current user can edit posts.');
     } else {
         pf_log('No, the current user can not edit posts.');
     }
     $feed_obj = pressforward()->pf_feeds;
     $subed = '';
     if (!empty($input['single'])) {
         if (!is_array($input['single'])) {
             pf_log('The feed is not an array;');
             if (!$feed_obj->has_feed($input['single'])) {
                 pf_log('The feed does not already exist.');
                 $check = $feed_obj->create($input['single'], array('type' => 'rss', 'module_added' => get_class($this)));
                 if (is_wp_error($check) || !$check) {
                     pf_log('The feed did not enter the database.');
                     #wp_die($check);
                     $description = 'Feed failed initial attempt to add to database | ' . $check->get_error_message();
                     $feed_obj->create($input['single'], array('type' => 'rss-quick', 'description' => $description, 'module_added' => get_called_class()));
                 }
             } else {
                 pf_log('The feed already exists, sending it to update.');
                 $check = $feed_obj->update_url($input['single']);
                 pf_log('Our attempt to update resulted in:');
                 pf_log($check);
             }
             $subed = 'a feed ';
         } else {
             pf_log('The feed was an array, this does not work');
             wp_die('Bad feed input. Why are you trying to place an array?');
         }
     }
     #var_dump($input);
     #die();
     //print_r($inputSingle);
     if (!empty($input['opml'])) {
         $OPML_reader = new OPML_reader();
         $opml_array = $OPML_reader->get_OPML_data($input['opml']);
         //print_r($opml_array); die();
         foreach ($opml_array as $key => $feedXml) {
             # Adding this as a 'quick' type so that we can process the list quickly.
             pf_log('Adding this as a quick type so that we can process the list quickly');
             $opml_array = $feed_obj->progressive_feedlist_transformer($opml_array, $feedXml, $key);
             # @todo Tag based on folder structure
         }
         $check_up = update_option(PF_SLUG . '_feedlist', $opml_array);
         $subed = 'an OPML file ';
     }
     if (!empty($_POST['o_feed_url'])) {
         $offender = array_search($_POST['o_feed_url'], $feedlist);
         if ($offender !== false) {
             unset($feedlist[$offender]);
         }
     }
     add_settings_error('add_pf_feeds', 'pf_feeds_validation_response', 'You have submitted ' . $subed . '.', 'updated');
     return $input;
 }