public function zenodo_meta_maker($id)
 {
     //var_dump($_POST);
     //var_dump($_GET);
     //die();
     pf_log($id);
     pf_log($_POST);
     $valid_metas = array_merge($this->metas, array('zen_source_title' => array('name' => 'source_title'), 'zen_item_date' => array('name' => 'item_date')));
     $check = pressforward('controller.metas')->update_pf_meta($id, 'pf_zenodo_ready', true);
     foreach ($valid_metas as $get_key => $descript) {
         pf_log($id . '-' . $get_key . '-' . $descript['name']);
         pf_log($_POST[$get_key]);
         $check = pressforward('controller.metas')->update_pf_meta($id, $descript['name'], $_POST[$get_key]);
         pf_log($check);
     }
     return '';
 }
Example #2
0
 public function set_feed_meta($post_id, $args)
 {
     pf_log('Invoked: PF_Feeds_Schema::set_feed_meta');
     $c = 1;
     #echo '<pre>';
     #var_dump($args);
     #echo '</pre>';
     foreach ($args as $k => $a) {
         pf_log('Setting ' . $post_id . ' Feed Meta: ' . $k . ' - ' . $a);
         if (!$a) {
         } else {
             update_post_meta($post_id, $k, $a);
         }
         $c++;
     }
     if ($c + 1 == count($args)) {
         update_post_meta($post_id, 'meta_data', 'complete');
     }
 }
Example #3
0
 private function __construct()
 {
     #Stuff
     pf_log('Start up WP_to_JATS');
     $this->template_dir = PF_A_ROOT . "/templates/";
 }
Example #4
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 );
 }
Example #5
0
function pf_pass_meta($field, $id = false, $value = '', $single = true)
{
    $metas = pf_meta_structure();
    # Check if it exists.
    if (empty($metas[$field])) {
        pf_log('The field ' . $field . ' is not supported.');
        return $field;
    }
    # Check if it has been depreciated (dep). If so retrieve
    if (in_array('dep', $metas[$field]['type'])) {
        $new_field = $metas[$field]['move'];
        pf_log('You tried to use depreciated field ' . $field . ' it was moved to ' . $new_field);
        pf_transition_deped_meta($field, $id, $value, $single, $new_field);
        $field = $new_field;
    }
    return $field;
}
Example #6
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;
 }
Example #7
0
 public function fill($id, $type)
 {
     $filled = '';
     switch ($type) {
         case 'upload_type':
             $filled = 'publication';
             break;
         case 'publication_type':
             $filled = 'other';
             break;
         case 'publication_date':
             $filled = pressforward('controller.metas')->get_post_pf_meta($id, 'item_date', true);
             if (empty($filled)) {
                 $filled = date('c');
             }
             break;
         case 'title':
             $filled = get_the_title($id);
             break;
         case 'access_right':
             $filled = 'open';
             break;
         case 'license':
             $filled = 'cc-zero';
             break;
         case 'related_identifiers':
             // Always will be set, never will be filled.
             break;
         case 'references':
             $filler = $this->semicolon_split(pressforward('controller.metas')->get_post_pf_meta($id, 'pf_references', true));
             break;
         case 'communities':
             $filler = array(array('identifier' => 'arceli'));
             break;
         default:
             $filler = 'fill_' . $type;
             if (method_exists($this, $filler)) {
                 $filled = $this->{$filler}($id);
             } else {
                 pf_log('No fill for ' . $type);
                 $filled = '';
             }
             break;
     }
     return $this->enforce($type, $filled);
 }
Example #8
0
 public function trigger_source_data()
 {
     $feed_go = get_option(PF_SLUG . '_feeds_go_switch', 0);
     $feed_iteration = get_option(PF_SLUG . '_feeds_iteration', 0);
     $retrieval_state = get_option(PF_SLUG . '_iterate_going_switch', 0);
     $chunk_state = get_option(PF_SLUG . '_ready_to_chunk', 1);
     pf_log('Invoked: PF_Feed_Retrieve::trigger_source_data()');
     pf_log('Feeds go?: ' . $feed_go);
     pf_log('Feed iteration: ' . $feed_iteration);
     pf_log('Retrieval state: ' . $retrieval_state);
     pf_log('Chunk state: ' . $chunk_state);
     if ($feed_iteration == 0 && $retrieval_state == 0 && $chunk_state == 1) {
         $status = update_option(PF_SLUG . '_iterate_going_switch', 1);
         # Echo to the user.
         pf_log(__('Beginning the retrieval process', 'pf'), true, true);
         pf_iterate_cycle_state('retrieval_cycles_begun', true);
         if ($status) {
             pf_log(__('Iterate switched to going.', 'pf'));
         } else {
             pf_log(__('Iterate option not switched.', 'pf'));
         }
         pressforward()->pf_feed_items->assemble_feed_for_pull();
     } else {
         $feeds_meta_state = get_option(PF_SLUG . '_feeds_meta_state', array());
         if (empty($feeds_meta_state)) {
             $feeds_meta_state = array('feed_go' => $feed_go, 'feed_iteration' => $feed_iteration, 'retrieval_state' => $retrieval_state, 'chunk_state' => $chunk_state, 'retrigger' => time() + 2 * 60 * 60);
             update_option(PF_SLUG . '_feeds_meta_state', $feeds_meta_state);
             pf_log(__('Created new metastate.', 'pf'), true);
         } else {
             pf_log(__('Metastate saved and active for check.', 'pf'), true);
             pf_log($feeds_meta_state);
         }
         if ($feeds_meta_state['retrigger'] > time()) {
             pf_log(__('The sources are already being retrieved.', 'pf'), true);
         } else {
             if ($feed_go == $feeds_meta_state['feed_go'] && $feed_iteration == $feeds_meta_state['feed_iteration'] && $retrieval_state == $feeds_meta_state['retrieval_state'] && $chunk_state == $feeds_meta_state['chunk_state']) {
                 pf_log(__('The sources are stuck.', 'pf'), true);
                 # Wipe the checking option for use next time.
                 update_option(PF_SLUG . '_feeds_meta_state', array());
                 update_option(PF_SLUG . '_ready_to_chunk', 1);
                 update_option(PF_SLUG . '_iterate_going_switch', 1);
                 pressforward()->pf_feed_items->assemble_feed_for_pull();
             } elseif ($feeds_meta_state['retrigger'] < time() + 86400 && !empty($feeds_meta_state)) {
                 # If it has been more than 24 hours and retrieval has been frozen in place
                 # and the retrieval state hasn't been reset, reset the check values and reset
                 # the meta state. If it is actually mid-process things should progress.
                 # Otherwise next meta-state check will iterate forward.
                 update_option(PF_SLUG . '_feeds_go_switch', 0);
                 update_option(PF_SLUG . '_ready_to_chunk', 1);
                 update_option(PF_SLUG . '_feeds_meta_state', array());
                 update_option(PF_SLUG . '_iterate_going_switch', 0);
                 update_option(PF_SLUG . '_feeds_iteration', 0);
                 $double_check = array('feed_go' => 0, 'feed_iteration' => 0, 'retrieval_state' => 0, 'chunk_state' => 1, 'retrigger' => $feeds_meta_state['retrigger']);
                 update_option(PF_SLUG . '_feeds_meta_state', $double_check);
                 pf_log(__('The meta-state is too old. It is now reset. Next time, we should start over.', 'pf'), true);
             } else {
                 $double_check = array('feed_go' => $feeds_meta_state['feed_go'], 'feed_iteration' => $feed_iteration, 'retrieval_state' => $feeds_meta_state['retrieval_state'], 'chunk_state' => $feeds_meta_state['chunk_state'], 'retrigger' => $feeds_meta_state['retrigger']);
                 update_option(PF_SLUG . '_feeds_meta_state', $double_check);
                 pf_log($double_check);
                 pf_log(__('The sources are already being retrieved.', 'pf'), true);
             }
         }
     }
 }
Example #9
0
 public function extra_special_sanatize($string, $severe = false)
 {
     $search = array(chr(145), chr(146), chr(147), chr(148), chr(151), chr(150), chr(133), chr(149), chr(189));
     $replace = array("'", "'", '"', '"', '--', '-', '...', "&bull;", "1/2");
     $string = str_replace($search, $replace, $string);
     pf_log('String run through specified str_replace.');
     $string = utf8_encode($string);
     pf_log('String run through utf8_encode');
     pf_log('String returned.');
     if ($severe) {
         // ============
         // Remove MS Word Special Characters
         // From: https://gist.github.com/gcoop/701814
         // ============
         $search = array('&acirc;��', '&acirc;��', '&acirc;��', '&acirc;��', '&Acirc;&pound;', '&Acirc;&not;', '&acirc;�&cent;', '&Acirc;&nbsp;', '&Acirc;', '&amp;nbsp;', '&#8230;');
         $replace = array('-', '&ldquo;', '&lsquo;', '&rsquo;', '&pound;', '&not;', '&#8482;', '', '', '', '...');
         $string = str_replace($search, $replace, $string);
         $string = str_replace('&acirc;�', '&rdquo;', $string);
         $search = array("&#39;", "’", "–", "”", "â??", "&#8220;", "&#8221;", "#8217;", "&not;", "&#8482;");
         $resplace = array("'", "'", ' - ', '"', "'", '"', '"', "'", "-", "(TM)");
         $string = str_replace($search, $replace, $string);
         $quotes = array("«" => '"', "»" => '"', "‘" => "'", "’" => "'", "‚" => "'", "‛" => "'", "“" => '"', "”" => '"', "„" => '"', "‟" => '"', "‹" => "'", "›" => "'", "–" => "-", "°" => "�", "º" => "�", "ñ" => "&#241;", "�" => "&#241;", "⁃" => '&bull;', "�" => "'");
         $string = strtr($string, $quotes);
         $string = utf8_encode($string);
         # From: http://stackoverflow.com/questions/657643/how-to-remove-html-special-chars
         //$string = preg_replace("/&#?[a-z0-9]+;/i","", $string);
     }
     return $string;
 }
Example #10
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;
 }
Example #11
0
 function open_OPML($file)
 {
     if (1 == ini_get('allow_url_fopen')) {
         $file = simplexml_load_file($file);
     } else {
         $ch = curl_init();
         $timeout = 5;
         curl_setopt($ch, CURLOPT_URL, $file);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         $data = curl_exec($ch);
         curl_close($ch);
         $file = simplexml_load_string($data);
     }
     if (empty($file)) {
         pf_log('Received an empty file.');
         return false;
     } else {
         pf_log('Received:');
         pf_log($file);
         $opml_data = $file;
         return $opml_data;
     }
 }
Example #12
0
<?php

ignore_user_abort(true);
set_time_limit(0);
define('IC_SITEBASE', dirname(dirname(dirname(dirname(dirname(__FILE__))))));
// print_r(IC_SITEBASE . '\wp-load.php');
if (!defined('ABSPATH')) {
    /** Set up WordPress environment */
    require_once IC_SITEBASE . '\\wp-load.php';
}
$string_to_log = "\nimport-cron.php triggered.\n";
pf_log($string_to_log);
pressforward()->pf_feed_items->assemble_feed_for_pull();
pf_log("import-cron.php compleated.\n\n\n");
//do_action('get_more_feeds');
//print_r('<br /><br />Triggered <br />');
//print_r('Iteration active: ' . get_option( PF_SLUG . '_feeds_iteration') . '<br />');
 /**
  * Parses HTML and extracts Open Graph data, this assumes
  * the document is at least well formed.
  *
  * @param $HTML    HTML to parse
  * @return OpenGraph
  */
 private static function _parse($HTML)
 {
     if (empty($HTML)) {
         return false;
     }
     $old_libxml_error = libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     if (is_array($HTML)) {
         pf_log('Attempt to parse URL for OpenGraph.');
         #pf_log($HTML);
         $HTML = $HTML['body'];
         if (empty($HTML)) {
             return false;
         }
     }
     $doc->loadHTML($HTML);
     libxml_use_internal_errors($old_libxml_error);
     $tags = $doc->getElementsByTagName('meta');
     if (!$tags || $tags->length === 0) {
         return false;
     }
     $page = new self();
     $nonOgDescription = null;
     foreach ($tags as $tag) {
         if ($tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
             $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
             $page->_values[$key] = $tag->getAttribute('content');
         }
         //Added this if loop to retrieve description values from sites like the New York Times who have malformed it.
         if ($tag->hasAttribute('value') && $tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
             $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
             $page->_values[$key] = $tag->getAttribute('value');
         }
         //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
         if ($tag->hasAttribute('name') && $tag->getAttribute('name') === 'description') {
             $nonOgDescription = $tag->getAttribute('content');
         }
     }
     //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
     if (!isset($page->_values['title'])) {
         $titles = $doc->getElementsByTagName('title');
         if ($titles->length > 0) {
             $page->_values['title'] = $titles->item(0)->textContent;
         }
     }
     if (!isset($page->_values['description']) && $nonOgDescription) {
         $page->_values['description'] = $nonOgDescription;
     }
     //Fallback to use image_src if ogp::image isn't set.
     if (!isset($page->_values['image'])) {
         $domxpath = new DOMXPath($doc);
         $elements = $domxpath->query("//link[@rel='image_src']");
         if ($elements->length > 0) {
             $domattr = $elements->item(0)->attributes->getNamedItem('href');
             if ($domattr) {
                 $page->_values['image'] = $domattr->value;
                 $page->_values['image_src'] = $domattr->value;
             }
         }
     }
     if (empty($page->_values)) {
         return false;
     }
     return $page;
 }
Example #14
0
 function build_nomination()
 {
     // Verify nonce
     if (!wp_verify_nonce($_POST[PF_SLUG . '_nomination_nonce'], 'nomination')) {
         die(__("Nonce check failed. Please ensure you're supposed to be nominating stories.", 'pf'));
     }
     if ('' != get_option('timezone_string')) {
         date_default_timezone_set(get_option('timezone_string'));
     }
     //ref http://wordpress.stackexchange.com/questions/8569/wp-insert-post-php-function-and-custom-fields, http://wpseek.com/wp_insert_post/
     $time = current_time('mysql', $gmt = 0);
     //@todo Play with post_exists (wp-admin/includes/post.php ln 493) to make sure that submissions have not already been submitted in some other method.
     //Perhaps with some sort of "Are you sure you don't mean this... reddit style thing?
     //Should also figure out if I can create a version that triggers on nomination publishing to send to main posts.
     //There is some serious delay here while it goes through the database. We need some sort of loading bar.
     ob_start();
     //set up nomination check
     $item_wp_date = $_POST['item_wp_date'];
     $item_id = $_POST['item_id'];
     //die($item_wp_date);
     //Going to check posts first on the assumption that there will be more nominations than posts.
     $nom_check = $this->handle_post_nomination_status($item_id);
     pf_log('We handle the item into a nomination?');
     pf_log($nom_check);
     /** The system will only check for nominations of the item does not exist in posts. This will stop increasing the user and nomination count in nominations once they are sent to draft.
      **/
     if ($nom_check) {
         //Record first nominator and/or add a nomination to the user's count.
         $current_user = wp_get_current_user();
         if (0 == $current_user->ID) {
             //Not logged in.
             $userSlug = "external";
             $userName = __('External User', 'pf');
             $userID = 0;
         } else {
             // Logged in.
             self::user_nomination_meta();
         }
         $userID = $current_user->ID;
         $userString = $userID;
         //set up rest of nomination data
         $item_title = $_POST['item_title'];
         $item_content = $_POST['item_content'];
         $item_link = pf_retrieve_meta($_POST['item_post_id'], 'item_link');
         $readable_status = pf_retrieve_meta($_POST['item_post_id'], 'readable_status');
         $item_author = pf_retrieve_meta($_POST['item_post_id'], 'item_author');
         if ($readable_status != 1) {
             $read_args = array('force' => '', 'descrip' => $item_content, 'url' => $item_link, 'authorship' => $item_author);
             $item_content_obj = pressforward()->readability->get_readable_text($read_args);
             $item_content = htmlspecialchars_decode($item_content_obj['readable']);
         } else {
             $item_content = htmlspecialchars_decode($_POST['item_content']);
         }
         //No need to define every post arg right? I should only need the ones I'm pushing through. Well, I guess we will find out.
         $data = array('post_status' => 'draft', 'post_type' => 'nomination', 'post_title' => $item_title, 'post_content' => $item_content);
         $newNomID = wp_insert_post($data);
         if (1 == $readable_status && (!empty($item_content_obj['status']) && 'secured' != $item_content_obj['status'])) {
             pf_update_meta($_POST['item_post_id'], 'readable_status', 1);
         } elseif (1 != $readable_status) {
             pf_update_meta($_POST['item_post_id'], 'readable_status', 0);
         }
         if ($_POST['item_feat_img'] != '') {
             pressforward()->pf_feed_items->set_ext_as_featured($newNomID, $_POST['item_feat_img']);
         }
         //die($_POST['item_feat_img']);
         pf_update_meta($_POST['item_post_id'], 'nomination_count', 1);
         pf_update_meta($_POST['item_post_id'], 'submitted_by', $userString);
         pf_update_meta($_POST['item_post_id'], 'nominator_array', array($userID));
         pf_update_meta($_POST['item_post_id'], 'date_nominated', date('c'));
         pf_update_meta($_POST['item_post_id'], 'origin_item_ID', $item_id);
         pf_update_meta($_POST['item_post_id'], 'item_feed_post_id', $_POST['item_post_id']);
         pf_update_meta($_POST['item_post_id'], 'item_link', $_POST['item_link']);
         $item_date = $_POST['item_date'];
         if (empty($_POST['item_date'])) {
             $newDate = gmdate('Y-m-d H:i:s');
             $item_date = $newDate;
         }
         pf_update_meta($_POST['item_post_id'], 'posted_date', $item_date);
         pf_meta_transition_post($_POST['item_post_id'], $newNomID);
         $response = array('what' => 'nomination', 'action' => 'build_nomination', 'id' => $newNomID, 'data' => $item_title . ' nominated.', 'supplemental' => array('content' => $item_content, 'originID' => $item_id, 'nominater' => $userID, 'buffered' => ob_get_contents()));
         $xmlResponse = new WP_Ajax_Response($response);
         $xmlResponse->send();
         ob_end_flush();
         die;
     } else {
         pf_log('User nominated already.');
         die('nominated_already');
     }
 }
Example #15
0
function pf_ajax_relate()
{
    pf_log('Invoked: pf_ajax_relate()');
    $item_id = $_POST['post_id'];
    $relationship_type = $_POST['schema'];
    $switch = $_POST['isSwitch'];
    $userObj = wp_get_current_user();
    $user_id = $userObj->ID;
    $result = 'nada';
    pf_log('pf_ajax_relate - received: ID = ' . $item_id . ', Schema = ' . $relationship_type . ', isSwitch = ' . $switch . ', userID = ' . $user_id . '.');
    if (1 != pf_get_relationship_value($relationship_type, $item_id, $user_id)) {
        $result = pf_set_relationship($relationship_type, $item_id, $user_id, '1');
        pf_log('pf_ajax_relate - set: relationship on');
    } else {
        if ($switch == 'on') {
            $result = pf_delete_relationship($relationship_type, $item_id, $user_id);
            pf_log('pf_ajax_relate - set: relationship off');
        } else {
            $result = 'unswitchable';
            pf_log('pf_ajax_relate - set: relationship unswitchable');
        }
    }
    ob_start();
    $response = array('what' => 'relationships', 'action' => 'pf_ajax_relate', 'id' => $item_id, 'data' => $result, 'supplemental' => array('user' => $user_id, 'buffered' => ob_get_contents()));
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
    ob_end_flush();
    die;
}
Example #16
0
 function get_OPML_data($url, $is_array = true)
 {
     pf_log('OPML Reader process invoked: get_OPML_data');
     $opml_data = $this->open_OPML($url);
     #var_dump($opml_data); die();
     if (!$opml_data || empty($opml_data)) {
         pf_log('Could not open the OPML file.');
         pf_log('Resulted in:');
         pf_log($opml_data);
         return false;
     }
     //Site data
     $a = array();
     //Feed URI
     $b = array();
     $c = 0;
     /** Get XML data:
      * supplies:
      * [text] - Text version of title
      * [text] - Text version of title
      * [type] - Feed type (should be rss)
      * [xmlUrl] - location of the RSS feed on the site.
      * [htmlUrl] - The site home URI.
      **/
     foreach ($opml_data->body->outline as $folder) {
         pf_log($c++);
         #var_dump($folder); die();
         # Check if there are no folders.
         if (isset($folder['xmlUrl'])) {
             pf_log('Not a folder.');
             $b[] = $folder['xmlUrl']->__toString();
         }
         foreach ($folder->outline as $data) {
             pf_log('A folder.');
             $a[] = reset($data);
         }
         // Pulls out the feed location.
         foreach ($a as $outline) {
             pf_log('Feed found:');
             pf_log($outline['xmlUrl']);
             $b[] = $outline['xmlUrl'];
         }
     }
     #var_dump($a);
     #var_dump($b);
     #die();
     if ($is_array) {
         pf_log('Is array:');
         pf_log($b);
         return $b;
     } else {
         pf_log('Is not array:');
         pf_log($a);
         return $a;
     }
 }