Commit 86b8b7b2 authored by Dave Lane's avatar Dave Lane
Browse files

added admin interface for implementation-specific settings, added full...

added admin interface for implementation-specific settings, added full language support for all user visible text strings, bumped version to 2.0.0
parent df05b2bf
......@@ -7,7 +7,7 @@ Plugin Name: Blog Feed Finder
Plugin URI: https://github.com/oeru/bff
Description: Provides a widget that helps a user figure out the valid URL for
their personal course blog feed
Version: 1.0.3
Version: 2.0.0
Author: Dave Lane
Author URI: https://oeru.org, http://WikiEducator.org/User:Davelane
License: AGPLv3 or later
......@@ -30,7 +30,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
define( 'BFF_VERSION', '1.0.3' );
define( 'BFF_VERSION', '2.0.0' );
// plugin computer name
define('BFF_NAME', 'BFF');
// current version
......@@ -50,13 +50,18 @@ define('BFF_ID', 'blog-feed-finder');
define('BFF_CLASS', 'bff-form');
define('BFF_OERU_THEME_NAME', 'OERu Course');
define('BFF_REGISTER_ENROL_PLUGIN', 'register-enrol/register-enrol.php');
define('BFF_PREFIX', 'bff_');
// support link for users of this plugin...
define('BFF_ORG_NAME', 'OERu');
define('BFF_ORG_PREFIX', false); // this should be true if the org's name starts with "The"
define('BFF_SUPPORT_FORUM', 'https://forums.oeru.org/t/blog-feed-finder');
define('BFF_SUPPORT_BLOG', 'https://course.oeru.org/support/studying-courses/course-blog/');
// admin details
define('BFF_ADMIN_SLUG', 'BFF_settings');
define('BFF_ADMIN_TITLE', 'Blog Feed Finder Settings');
define('BFF_ADMIN_MENU', 'BFF Settings');
define('BFF_ADMIN_SCRIPT', 'bff-admin-script');
define('BFF_ADMIN_STYLE', 'bff-admin-style');
// other useful parameters
define('BFF_MAX_FILE_READ_CHAR', 1000000); // limit max size of the file to read to 1mb
// turn on debugging with true, off with false
......@@ -68,7 +73,7 @@ require BFF_PATH . '/includes/bff-app.php';
if ( function_exists( 'add_action' ) ) {
// this starts everything up!
add_action('plugins_loaded', array(BFFForm::get_instance(), 'init'));
add_action('wp_loaded', array(BFFForm::get_instance(), 'init'));
} else {
echo 'This only works as a WordPress plugin.';
exit;
......
<?php
require BFF_PATH . '/includes/bff-course.php';
require BFF_PATH . '/includes/bff-strings.php';
class BFFForm extends BFFCourse {
protected static $instance = NULL; // this instance
private $errors = array();
// the default values for this are set in the main blog-feed-finder.php file
protected $default_settings = array(
'organisation_code' => null,
'organisation_name' => BFF_ORG_NAME,
'organisation_prefix' => BFF_ORG_PREFIX,
'support_forum' => BFF_SUPPORT_FORUM,
'support_blog' => BFF_SUPPORT_BLOG
);
protected $settings = array();
// returns an instance of this class if called, instantiating if necessary
public static function get_instance() {
NULL === self::$instance and self::$instance = new self();
......@@ -31,28 +43,279 @@ class BFFForm extends BFFCourse {
add_action('wp_ajax_nopriv_bff_submit', array($this, 'ajax_submit'));
// this enables the setblogfeed service for authenticated users...
add_action('wp_ajax_bff_set', array($this, 'ajax_set'));
// stuff related to the WEnotes plugin...
//add_action('wenotes_update_feed', array($this, 'update_user_feed_meta'), 10, 4);
add_action('wenotes_remove_feed', array($this, 'cleanup_user_feed_meta'), 10, 2);
// Admin Settings
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
add_action('network_admin_menu', array($this, 'multisite_menu'));
add_action('wp_ajax_bff_settings_submit', array($this, 'ajax_settings_submit'));
$this->log('finished setting up scripts');
}
public function enqueue_scripts() {
global $bff_strings;
wp_enqueue_script('bff-script', BFF_URL.'js/bff_script.js', array(
'jquery', 'jquery-form'));
wp_localize_script('bff-script', 'bff_data', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce_submit' => wp_create_nonce('bff-submit-nonce'),
'nonce_set' => wp_create_nonce('bff-set-nonce'),
));
$data = array(
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce_submit' => wp_create_nonce('bff-submit-nonce'),
'nonce_set' => wp_create_nonce('bff-set-nonce')
);
$data['strings'] = $bff_strings;
wp_localize_script('bff-script', 'bff_data', $data);
// our css
wp_register_style('bff-style', BFF_URL.'css/bff_style.css');
wp_enqueue_style('bff-style');
}
public function enqueue_admin_scripts() {
$this->log('_GET: '. print_r($_GET, true));
if (isset( $_GET['page']) && $_GET['page'] == BFF_ADMIN_SLUG) {
$this->log('enabling admin script...');
wp_enqueue_script(BFF_ADMIN_SCRIPT, BFF_URL.'js/bff_admin.js', array(
'jquery', 'jquery-validate'));
$bff_admin_data = array(
'ajaxurl' => admin_url('admin-ajax.php'),
'site_id' => get_current_blog_id(),
'nonce' => wp_create_nonce('bff-admin-nonce')
);
wp_localize_script(BFF_ADMIN_SCRIPT, 'bff_data', $bff_admin_data);
wp_register_style(BFF_ADMIN_STYLE, BFF_URL.'css/bff_admin.css');
wp_enqueue_style(BFF_ADMIN_STYLE);
}
}
public function multisite_menu() {
$this->log('in multisite_menu');
add_menu_page(__(BFF_ADMIN_TITLE, 'oeru-bff'),
BFF_ADMIN_MENU, 'manage_options', BFF_ADMIN_SLUG,
array($this, 'multisite_settings_admin'));
}
// called when the ajax form is successfully submitted
public function ajax_settings_submit() {
$this->log('in ajax_submit: '.print_r($_POST, true));
// check if the submitted nonce matches the generated nonce created in the auth_init functionality
if (! wp_verify_nonce( $_POST['nonce'], 'bff-admin-nonce')) {
die (__("Someone is using this form without permission!", 'oeru-bff'));
}
// generate the response
header( "Content-Type: application/json" );
$this->ajax_response(array('success'=> $this->save_settings()));
exit;
}
public function save_option($sid, $option, $val) {
$this->log('saving option '.$option.' = '.$val.' for site '.$sid.'.');
$fulloption = BFF_PREFIX.$option;
if (update_network_option($sid, $fulloption, $val)) {
$this->log('updated value for site '.$sid.' of '.$fulloption.' to '.$val.'...');
} else {
if (add_network_option($sid, $fulloption, $val)) {
$this->log('added value for site '.$sid.' of '.$fulloption.' = '.$val.'...');
} else {
$this->log('failed to add value for site '.$sid.' of '.$fulloption.' = '.$val.'...');
return false;
}
}
return true;
}
public function delete_option($sid, $option) {
$this->log('deleting option '.$option.' for site '.$sid.'.');
if (delete_network_option($sid, BFF_PREFIX.$option)) {
return true;
}
return false;
}
public function save_settings() {
$this->log('save_settings for site '.$sid.': '. print_r($_POST, true));
// check to make sure the minimum necessary values are included.
if ($_POST && isset($_POST['site_id']) && isset($_POST['organisation_name']) &&
isset($_POST['organisation_prefix'])) {
$sid = $_POST['site_id'];
$settings = $this->get_settings($sid);
$rebuild_bff_page = false;
foreach ($settings as $option => $value) {
// check if the new option is the same as the default.
// if so, delete the option altogether (so that the settings
// will adopt the default if they're updated by us at some later
// time...)
if ($_POST[$option] == $this->default_settings[$option]) {
$this->log('option: '.$option.' = '.$_POST[$option].' is the same as the default. Deleting the option ('.$this->default_settings[$option].').');
$this->delete_option($sid, $option);
} else {
if (isset($_POST[$option]) && $_POST[$option] != $value) {
$this->log('updating '.$option.' from '.$value.' to '.$_POST[$option].'...');
$clean = sanitize_text_field($_POST[$option]);
if ($option === 'organisation_code' && ($_POST[$option] == "" || $_POST[$option] == null)) {
$this->delete_option($sid, $option);
} else {
if ($option === 'support_forum' || $option === 'support_blog') {
$rebuild_bff_page = true;
}
$this->save_option($sid, $option, $clean);
}
}
}
}
// now we'll recreate the default page for the BFF in case the URLs have been altered...
if ($rebuild_bff_page) {
$this->log('rebuilt the default BFF page...');
if ($post_id = $this->create_post(BFF_SLUG)) {
$this->log('(Re)Created the default BFF page ('.$post_id.')...');
} else {
$this->log('Failed to rebuild the default BFF page...');
}
}
// translators: %s = the name of this plugin, BFF or Blog Feed Finder by default
$message = sprintf(__('Updated %s admin settings.', 'oeru-bff'), BFF_NAME);
$this->ajax_response(array(
'success' => true,
'message' => $message
));
}
return true;
}
public function multisite_settings_admin() {
$sid = 1;
$settings = $this->get_settings($sid);
echo '<div class="wrap" id="bff-settings">';
echo '<h2>'.__(BFF_ADMIN_TITLE, 'oeru-bff').'</h2>';
echo '<p>'.__('These are the default site settings on this WordPress multisite', 'oeru-bff').'</p>';
$this->print_settings_form($settings);
echo '</div>';
}
protected function print_settings_form($settings) {
$this->log('printing settings: '. print_r($settings, true));
?>
<form method="post" action="" id="bff-settings-form">
<table class="form-table">
<?php
//if (function_exists('MauticSync::get_partners')) {
// pull in useful data from a different plugin, Mautic Sync, if it's available!
$partners = false;
if (class_exists('MauticSync')) {
$ms = new MauticSync;
$partners = $ms->get_partners();
//$this->log('returning partners: '. print_r($partners, true));
} else {
$this->log('MauticSync not available...');
}
if ($partners) {
?>
<tr valign="top">
<th scope="row"><?php echo __('Select an OERu partner', 'oeru-bff'); ?></th>
<td><?php
$selector = '<select id="bff-partner" name="bff-partner" class="bff-partner">';
// if a partner has been selected for this site, then pre-select it...
$saved_code = false;
if ($code = get_site_option('bff_partner_code') && array_key_exists($code, $partners)) {
$saved_code=$code;
$this->log('We found a saved code: '.$saved_code);
$selector .= ' <option value="default">'.__('Select a partner or enter details below', 'oeru-bff').'</option>';
} else {
$selector .= ' <option value="default" selected="true">'.__('Select a partner or enter details below', 'oeru-bff').'</option>';
}
foreach($partners as $code => $partner) {
$article = '';
$val = $code;
$partner_name = $partner['name'];
if ($partner['article']) {
$article = __('The', 'oeru-bff').' ';
$val = $code.'-article';
$partner_name = $article.$partner_name;
}
if ($saved_code && $code === $saved_code) {
$selector .= ' <option value="'.$val.'" selected="true">'.$partner_name.'</option>';
} else {
$selector .= ' <option value="'.$val.'" >'.$partner_name.'</option>';
}
}
$selector .= '</select>';
echo $selector;
echo '<span class="description">'.__('If the organisation or institution is a partner, find their details here to pre-populate the following fields. <br/>Otherwise, leave this unset!', 'oeru-bff').'</span>';
$code = '';
if (isset($settings['organisation_code']) && $settings['organisation_code']!=null) {
$code = $settings['organisation_code'];
}
echo '<input type="hidden" id="organisation-code" value="'.$code.'"/>';
?>
</td>
</tr>
<?php
}
?>
<tr valign="top">
<th scope="row"><?php echo __('Organisation Name', 'oeru-bff'); ?></th>
<td><input type="text" id="organisation-name" name="organisation-name"
value="<?php echo $settings['organisation_name']; ?>" style="width: 30em;" />
<span class="description"><?php echo __('The name of your organisation as you want to see it. If your organisation starts off with "The", leave that off here.', 'oeru-bff'); ?></span>
</td>
</tr>
<?php
$prefix = $settings['organisation_prefix'];
$this->log('prefix = '.$prefix);
?>
<tr valign="top">
<th scope="row"><?php echo __('Organisation Prefix', 'oeru-bff'); ?></th>
<td><input type="checkbox" id="organisation-prefix" name="organisation-prefix" <?php if ($prefix != false && $prefix != "false") echo "checked=\"bob\""; ?>/>
<span class="description"><?php echo __('If your organisation name is preceded by "The" when it is written, check this.', 'oeru-bff'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Support forum', 'oeru-bff'); ?></th>
<td><input type="text" id="support-forum-url" name="support-forum-url"
value="<?php echo $settings['support_forum']; ?>" style="width: 30em;" />
<span class="description"><?php echo __('The web address (URL) of the support forum for users of this site. Should start with "https://".', 'oeru-bff'); ?></span>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php echo __('Support blog', 'oeru-bff'); ?></th>
<td><input type="text" id="support-blog-url" name="support-blog-url"
value="<?php echo $settings['support_blog']; ?>" style="width: 30em;" />
<span class="description"><?php echo __('The web address (URL) of the support forum for users of this site. Should start with "https://".', 'oeru-bff'); ?></span>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" id="bff-submit" class="button-primary" value="<?php echo __('Save Changes', 'oeru-bff'); ?>" />
</p>
<p id="bff-status" style="color: red">&nbsp;</p>
</form>
<?php
}
// get thet settings for a specific blog, defaulting to the main/default one, of '1'
protected function get_settings($sid = 1) {
$this->log('default settings: '. print_r($this->default_settings, true));
$settings = array();
$default_settings = array();
if ($sid == 1) {
$this->log('sid = 1, so using default_settings.');
$default_settings = $this->default_settings;
} else {
$this->log('site != 1, so using multisite settings as default_settings');
$default_settings = $this->get_settings();
}
foreach ($default_settings as $setting => $default) {
$settings[$setting] = get_network_option($sid, BFF_PREFIX.$setting, $default);
}
$this->settings = $settings;
//$this->log('resulting settings: '. print_r($this->settings, true));
return $settings;
}
// the function called after the bff-submit button is clicked in our form
public function ajax_submit() {
$this->log('in ajax_submit: '.print_r($_POST, true));
// check if the submitted nonce matches the generated nonce created in the auth_init functionality
if ( ! wp_verify_nonce(sanitize_text_field($_POST['nonce_submit']), 'bff-submit-nonce') ) {
die ("Busted - someone's trying something funny in submit!");
die (__("Busted - someone's trying something funny in submit!", 'oeru-bff'));
} else {
$this->log('bff-submit-nonce all good.');
}
......@@ -70,7 +333,7 @@ class BFFForm extends BFFCourse {
// check if the submitted nonce matches the generated nonce created in the auth_init functionality
if ( ! wp_verify_nonce(sanitize_text_field($_POST['nonce_set']), 'bff-set-nonce') ) {
$this->log('bff-set-nonce ain\'t right!');
die ("Busted - someone's trying something funny in set!");
die (__("Busted - someone's trying something funny in set!", 'oeru-bff'));
} else {
$this->log('bff-set-nonce all good.');
}
......@@ -88,7 +351,7 @@ class BFFForm extends BFFCourse {
if (isset($_POST['action']) && $_POST['action'] == 'bff_submit') {
$url = $_POST['url'];
$this->log('looking at URL = '. $url);
$this->process_url($url);
$this->process_url($url, $this->get_settings());
// update the response object with the courses array...
$this->response = $this->list_courses();
// alert script.js that the user is not logged in!
......@@ -149,9 +412,9 @@ class BFFForm extends BFFCourse {
// outputs the options form on admin
?>
<form id="<?php echo BFF_ID; ?>" class="<?php echo BFF_CLASS; ?>" target="#">
<label class="<?php echo BFF_CLASS; ?>"><?php echo __('Find your blog\'s feed address!'); ?></label><br/>
<label class="<?php echo BFF_CLASS; ?>"><?php echo __('Find your blog\'s feed address!', 'oeru-bff'); ?></label><br/>
<input data-role="none" id="bff-url" class="url" type="text" name="bff-url" value="" />
<button id="bff-submit" class="submit" href="#">Submit</button><br/>
<button id="bff-submit" class="submit" href="#"><?php echo __('Submit', 'oeru-bff'); ?></button><br/>
<div id="bff-feedback" class="feedback">
<p>Feedback...</p>
</div>
......@@ -165,23 +428,42 @@ class BFFForm extends BFFCourse {
// create a default post to hold our form...
public function create_post($slug) {
$post_id = -1; // this is non-post right now...
if (!($post_id = $this->slug_exists($slug))) {
$this->log('Creating a post at '.$slug.'...');
$post = $this->get_post($slug);
// check to see if this page title is already used...
// create the new post content
$this->log('Creating a post at '.$slug.'...');
$post = $this->get_post($slug);
// check to see if this page title is already used...
$blog_page_check = get_page_by_title($post['post_title']);
$post_id = -1;
// if it already exists, we'll delete it now so we can recreate it
if (isset($blog_page_check->ID) && $post_id = $blog_page_check->ID) {
$removed = wp_delete_post($post_id, true);
$this->log('Result of attempt to delete post '.$post_id.': '. print_r($removed, true));
if ($removed != false || $removed != null) {
$this->log('Successfully deleted old post ('.$post_id.')...');
} else {
$this->log('Failed to fully delete old post ('.$post_id.')...');
}
$this->log('Recreating post (replacing previous version)...');
}
// check again to make sure the post is gone...
$blog_page_check = get_page_by_title($post['post_title']);
if (!isset($blog_page_check->ID)) {
$this->log('Creating post...');
if (!($post_id = wp_insert_post($post))) {
$this->log('Inserting post at '.$slug.' failed!');
return false;
}
$this->log('Created post...');
$blog_page_check = get_page_by_title($post['post_title']);
if (!isset($blog_page_check->ID)) {
if (!($post_id = wp_insert_post($post))) {
$this->log('Inserting post at '.$slug.' failed!');
return false;
}
if (isset($blog_page_check->ID) && $post_id = $blog_page_check->ID) {
$this->log('we created a new page, "'.$post['post_title'].'" and id '.$post_id.'!');
} else {
$this->log('Already have a page with this title - id: '.$blog_page_check->ID);
$this->log('Failed to create a new page, "'.$post['post_title'].'"...');
return false;
}
} else {
$this->log('Not creating the content again.');
$this->log('Already have a page with this title - id: '.$blog_page_check->ID);
return false;
}
$this->log('returing post id '.$post_id);
return $post_id;
......@@ -210,6 +492,7 @@ class BFFForm extends BFFCourse {
private function get_post($slug) {
$this->log('in get_post');
$settings = $this->get_settings();
// create the post array with boilerplate settings...
$post = array(
'comment_status' => 'closed',
......@@ -221,15 +504,16 @@ class BFFForm extends BFFCourse {
$post['post_author'] = 1; // the default
$post['post_name'] = $slug;
$post['post_slug'] = $slug;
$post['post_title'] = 'Blog Feed Finder';
$post['post_content'] = "<p>The Blog Feed Finder helps you work out the exact web address (URL) for your blog's feed.</p>"
."<p>Start by going to <strong>your own</strong> blog - use another browser tab or window. "
."Copy the blog's web address - the text in your browser's 'address bar' which starts with '<strong>http://</strong>' or '<strong>https://</strong>' - "
."and paste it into the text box below.</p>"
."<p>Need help? Consult the OERu <a href=".BFF_SUPPORT_BLOG.">support site</a>, or post your question on our <a href=".BFF_SUPPORT_FORUM.">support forum</a>.</p>"
$post['post_title'] = __('Blog Feed Finder', 'oeru-bff');
$post['post_content'] = "<p>".__("The Blog Feed Finder helps you work out the exact web address (URL) for your blog's feed.", 'oeru-bff')."</p>"
."<p>".__("Start by going to <strong>your own</strong> blog - use another browser tab or window. ", 'oeru-bff')
.__("Copy the blog's web address - the text in your browser's 'address bar' which starts with '<strong>http://</strong>' or '<strong>https://</strong>' - ", 'oeru-bff')
.__("and paste it into the text box below.", 'oeru-bff')."</p>";
// translators: %1$s below is the web address for the 'support site' and %2$s is for the 'support forum'.
$post['post_content'] .= "<p>".sprintf(__("Need help? Consult the OERu <a href=\"%1$s\">support site</a>, or post your question on our <a href=\"%2$s\">support forum</a>.", 'oeru-bff'), $settings['support_blog'], $settings['support_forum'])."</p>"
."[".BFF_SHORTCODE."]"
."<div class='credits'>"
."<p class='credit'>Credits: Emoji icons from the <a href='https://commons.wikimedia.org/wiki/Category:Noto_Color_Emoji_Oreo'>Noto Color Emoji Oreo</a> set (under Apache 2.0 license).</p>"
."<p class='credit'>".__("Credits: Emoji icons from the <a href='https://commons.wikimedia.org/wiki/Category:Noto_Color_Emoji_Oreo'>Noto Color Emoji Oreo</a> set (under Apache 2.0 license).", 'oeru-bff')."</p>"
."</div>";
return $post;
}
......
......@@ -17,15 +17,17 @@ class BFFCourse extends BFFFinder {
// show the user info if they're not logged in...
public function alert_anon_user() {
$message = '<p class="bff-notice">You are not currently logged in. As such, you will not be able to link any blog feed addresses you find to your profile.</p>';
$message = '<p class="bff-notice">'.__('You are not currently logged in. As such, you will not be able to link any blog feed addresses you find to your profile.', 'oeru-bff').'</p>';
// if this is a multisite, recommend a user log in to get the most functionality from the plugin.
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
if ($this->is_using_oeru_theme() && is_plugin_active(BFF_REGISTER_ENROL_PLUGIN)) {
$message .= '<p class="bff-notice">You can <a data-toggle="modal" title="Click to log in or register for Courses" href="/'.BFF_SLUG.'#login" onclick="login();"><span
class="glyphicon glyphicon-user"></span>log in</a> to link your feed(s) to any courses for which you\'re registered.</p>';
// translators: the %s is the web address required to log into this site
$message .= '<p class="bff-notice">'.sprintf(__('You can <a data-toggle="modal" title="Click to log in or register for Courses" href="%s#login" onclick="login();"><span
class="glyphicon glyphicon-user"></span>log in</a> to link your feed(s) to any courses for which you\'re registered.', 'oeru-bff'), BFF_SLUG).'</p>';
} else {
$message .= '<p class="bff-notice">You can <a title="Click to log in or register for Courses" href="'.wp_login_url(BFF_SLUG).'"><span
class="glyphicon glyphicon-user"></span>log in or register</a> to link your feed(s) to any courses for which you\'re registered.</p>';
// translators: the %s is the web address required to log into this site
$message .= '<p class="bff-notice">'.sprintf(__('You can <a title="Click to log in or register for Courses" href="%s"><span
class="glyphicon glyphicon-user"></span>log in or register</a> to link your feed(s) to any courses for which you\'re registered.', 'oeru-bff'), wp_login_url(BFF_SLUG)).'</p>';
}
}
// put out
......@@ -47,7 +49,7 @@ class BFFCourse extends BFFFinder {
public function inform_auth_user() {
?>
<div id="bff-auth-notice" class="bff-auth bff-info bff-alert-box">
<p class="bff-notice">You can link any blog feeds addresses you find to any courses for which you are registered.</p>
<p class="bff-notice"><?php _e('You can link any blog feeds addresses you find to any courses for which you are registered.'); ?></p>
</div>
<?php
}
......@@ -98,7 +100,7 @@ class BFFCourse extends BFFFinder {
'url' => $url,
'type' => $type
);
do_action('bff_update_user_feed', $args);
//do_action('bff_update_user_feed', $args);
//
return true;
} else {
......@@ -125,4 +127,21 @@ class BFFCourse extends BFFFinder {
return strtolower(substr($site->path,1,-1));
}
// this is from blog-feed-finder plugin - git.oeru.org/oeru/blog-feed-finder !! See includes/bff-course.php
public function cleanup_user_feed_meta($user_id, $site_id) {
if (delete_user_meta($user_id, 'url_'.$site_id)) {
delete_user_meta($user_id, 'feedtype_'.$site_id);
$this->log('tidying up after ourselves, removed associated user meta data');
}
}
// this is from blog-feed-finder plugin - git.oeru.org/oeru/blog-feed-finder !! See includes/bff-course.php
/*public function update_user_feed_meta($user_id, $site_id, $url, $type) {
if (update_user_meta($user_id, 'url_'.$site_id, $url)) {
delete_user_meta($user_id, 'feedtype_'.$site_id);
$this->log('tidying up after ourselves, removed associated user meta data');
}
}*/
}
......@@ -35,8 +35,8 @@ abstract class BFFFinder extends BFFFeed {
$this->log('selected feed['.$feed_id.']: '. print_r($feeds[$feed_id], true));
}
// process the URL provided by the user
public function process_url($entered_url) {
// process the URL provided by the user, requires settings array defined in the descendent class...
public function process_url($entered_url, $settings) {
// make sure we're not a vector for XSS
$url = sanitize_text_field($entered_url);
$this->log('entered url: '.$entered_url.', sanitised: '.$url);
......@@ -64,7 +64,7 @@ abstract class BFFFinder extends BFFFeed {
// check if this URL, though valid, falls into a common
// mistaken pattern, e.g. it's just the course's URL
// if so, continue on to the next URL
if ($this->valid_blog_url($url)) {
if ($this->valid_blog_url($url, $settings)) {
$this->log('looking for a feed in the page content of '.$url.', or if that fails, in the "usual places."');
// we've got a valid URL, so let's look for a feed...
$this->log('**** response content_type = '.$this->response['content_type']);
......@@ -80,9 +80,11 @@ abstract class BFFFinder extends BFFFeed {
$succeeded = true;
} else {
$this->log('failed to find a feed at: '. $url);
// translators: the %s below is replaced by the web address (URL) of the selected blog site.
$message = sprintf(__('Perhaps there is no feed at the site you specified, %s,', 'oeru-bff'), $url);
$this->set_response(true, $response['orig_url'], $response['path'],
'No feed found', $response['redirect'],
'We weren\'t able to find a feed on this site.', 'Perhaps there is no feed at the site you specified, '.$url, 'problem');
__('No feed found', 'oeru-bff'), $response['redirect'],
__('We weren\'t able to find a feed on this site.', 'oeru-bff'), $message, 'problem');
}
}
}
......@@ -101,8 +103,9 @@ abstract class BFFFinder extends BFFFeed {
if (array_key_exists($this->response['content_type'], $this->feed_types)) {
$content_type = $this->feed_types[$this->response['content_type']];
$this->log('***** bingo! We\'ve got a valid feed type '.$content_type);
$this->add_message('Yay! we found a valid feed!', 'The address '.$url.
' points to a valid "'.$content_type.'" feed!', 'good');
// translators: %1$s is a web address pointing to a feed, and %2$s is a feed 'type'
$message = sprintf(__('The address %1%s points to a valid "%2$s" feed!', 'oeru-bff'), $url, $content_type);
$this->add_message(__('Yay! we found a valid feed!', 'oeru-bff'), $message, 'good');
$this->add_feed($url, $this->response['content_type']);
return true;
} else {
......@@ -147,26 +150,25 @@ abstract class BFFFinder extends BFFFeed {
$type_name = $this->feed_types[$type];
if ($title) {
// allow feeds that don't have "Comments Feed" in the title...
// translators: %1$s is a feed type, the %2$s is the feed's title, and %3$s is the feed web address (URL)
$detail= sprintf(__(' "%1$s" feed "%2$s" found at %3$s...', 'oeru-bff'), $type_name, $title, $feed);
if (strpos($title, 'Comments Feed') == false) {
$msg = ' Feed "'.$title.'" found.';
$detail= ' "'.$type_name.'" feed "'
.$title.'" found at '.$feed.'...';
// translators: %s is the title of the feed that has been found.
$msg = sprintf(__(' Feed "%s" found.', 'oeru-bff'), $title);
// add this feed...
$this->add_feed($feed, $type, $title);
$type = 'good';
} else {
// don't add this feed
$msg = ' Comment feed "'.$title.
'" found - <em>probably not what you want</em>.';
$detail = ' "'.$type_name.'" feed "'
.$title.'" found at '
.$feed.'. This is probably not what we want, as it\'s specific to comments to your posts...';
// translators: %s is the title of a 'comment' feed.
$msg = sprintf(__(' Comment feed "%s" found - <em>probably not what you want</em>.', 'oeru-bff'), $title);
$detail .= __('. This is probably not what we want, as it\'s specific to comments to your posts...', 'oeru-bff');