mirror of
https://github.com/KevinMidboe/rohnenedre.git
synced 2025-10-29 17:50:37 +00:00
Initial commit. State 04.2021.
This commit is contained in:
367
wp-content/plugins/wpclef/includes/lib/Settings_API_Util.inc
Normal file
367
wp-content/plugins/wpclef/includes/lib/Settings_API_Util.inc
Normal file
@@ -0,0 +1,367 @@
|
||||
<?php if(!class_exists('Settings_API_Util')) {
|
||||
|
||||
/**
|
||||
* Utility class to bring some sanity to WordPress's Settings API
|
||||
* @version 0.2 - custom w/introHTML
|
||||
* @author Dave Ross <dave@davidmichaelross.com>
|
||||
* @license BSD
|
||||
*/
|
||||
class Settings_API_Util {
|
||||
|
||||
const ICON_THEMES = 'icon-themes';
|
||||
const ICON_COMMENTS = 'icon-edit-comments';
|
||||
const ICON_INDEX = 'icon-index';
|
||||
const ICON_LINKS = 'icon-link-manager';
|
||||
const ICON_UPLOAD = 'icon-upload';
|
||||
const ICON_PAGES = 'icon-edit-pages';
|
||||
const ICON_PLUGIN = 'icon-plugins';
|
||||
const ICON_TOOLS = 'icon-tools';
|
||||
const ICON_SETTINGS = 'icon-options-general';
|
||||
const ICON_POSTS = 'icon-edit';
|
||||
const ICON_USERS = 'icon-users';
|
||||
|
||||
public $id;
|
||||
public $optionName;
|
||||
public $values;
|
||||
|
||||
private $sections;
|
||||
public $introHTML;
|
||||
|
||||
/**
|
||||
* Fetch/create a form object with the given ID
|
||||
* @staticvar SN_Tracker_Admin $instance Stores Singleton instances
|
||||
* @param string $id Form ID
|
||||
* @param string $optionName Name to store settings under in the WordPress wp_options table. Defaults to $id.
|
||||
* @return SN_Tracker_Admin instance
|
||||
*/
|
||||
public static function forID($id, $optionName = null, $rest=null) {
|
||||
|
||||
if(null === $optionName) {
|
||||
$optionName = $id;
|
||||
}
|
||||
|
||||
static $instances;
|
||||
|
||||
if(!isset($instances)) {
|
||||
$instances = array();
|
||||
}
|
||||
|
||||
if(!isset($instances[$id])) {
|
||||
$instances[$id] = new Settings_API_Util($id, $optionName);
|
||||
}
|
||||
|
||||
return $instances[$id];
|
||||
|
||||
}
|
||||
|
||||
private function __construct($id, $optionName) {
|
||||
|
||||
$this->id = $id;
|
||||
$this->optionName = $optionName;
|
||||
$this->sections = array();
|
||||
$this->introHTML = '';
|
||||
$this->outroHTML = '';
|
||||
|
||||
register_setting( $id, $optionName, array(__CLASS__, 'validate'));
|
||||
|
||||
$this->values = get_option($optionName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic form validation/sanitization
|
||||
* @param array $input
|
||||
* @return array validated/filtered input
|
||||
*/
|
||||
public static function validate(array $input) {
|
||||
$output = array();
|
||||
|
||||
foreach($input as $key=>$value) {
|
||||
$output[$key] = trim($value);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a standard WordPress settings form
|
||||
* @param type $title Settings page title
|
||||
* @param type $icon Settings_API_Util::ICON_* constant
|
||||
* @todo Get HTML out of this PHP code
|
||||
*/
|
||||
public function renderBasicForm($title, $icon) {
|
||||
|
||||
if (MULTISITE && is_network_admin()) {
|
||||
$url = "edit.php?action=" . $this->id;
|
||||
} else {
|
||||
$url="options.php";
|
||||
}
|
||||
echo '<div class="wrap" id="' . $this->id . '">';
|
||||
echo '<div id="'.$icon.'" class="frmicon icon32"><br></div>';
|
||||
echo '<h2>'.$title.'</h2>';
|
||||
if(!empty($this->introHTML)) {
|
||||
echo '<div class="intro">' . $this->introHTML . '</div>';
|
||||
}
|
||||
echo '<form id="' . $this->id . '" action="' . $url . '" method="POST">';
|
||||
settings_fields($this->id);
|
||||
do_settings_sections($this->id);
|
||||
|
||||
echo '<p class="submit">';
|
||||
echo '<input type="submit" name="submit" class="button-primary" value="'.__('Save').'" />';
|
||||
echo '</p>';
|
||||
|
||||
echo '</form>';
|
||||
echo '<div class="outro">' . $this->outroHTML . '</div>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new setting to this form
|
||||
* @param type $id
|
||||
* @param type $title
|
||||
* @param type $sectionHeadCallback
|
||||
* @return Settings_API_Util_Section
|
||||
*/
|
||||
public function addSection($id, $title, $sectionHeadCallback = null) {
|
||||
|
||||
$section = new Settings_API_Util_Section($this, $id, $title, $sectionHeadCallback);
|
||||
$this->sections[$id] = $section;
|
||||
return $section;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an existing section with the given ID
|
||||
* @param string $id
|
||||
* @return Settings_API_Util_Section
|
||||
*/
|
||||
public function getSection($id) {
|
||||
|
||||
return $this->sections[$id];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Settings_API_Util_Section {
|
||||
|
||||
public $settings;
|
||||
public $id;
|
||||
public $title;
|
||||
private $fields;
|
||||
|
||||
function __construct($settings, $id, $title, $sectionHeadCallback = null) {
|
||||
|
||||
if($sectionHeadCallback === null) {
|
||||
$sectionHeadCallback = array(__CLASS__, 'renderEmptySectionHead');
|
||||
}
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
$this->fields = array();
|
||||
|
||||
add_settings_section($id, $title, $sectionHeadCallback, $settings->id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $title
|
||||
* @param string $type Settings_API_Util_Field::TYPE_* constant
|
||||
* @param string $defaultValue
|
||||
* @return Settings_API_Util_Field
|
||||
*/
|
||||
public function addField($id, $title, $type, $defaultValue = null, $additionalArgs = null) {
|
||||
|
||||
$field = new Settings_API_Util_Field($this, $id, $title, $type, $defaultValue, $additionalArgs);
|
||||
|
||||
$this->fields[$id] = $field;
|
||||
|
||||
return $field;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an existing field with the given ID
|
||||
* @param string $id
|
||||
* @return Settings_API_Util_Field
|
||||
*/
|
||||
public function getField($id) {
|
||||
|
||||
return $this->fields[$id];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default callback for rendering the section heading
|
||||
*/
|
||||
public static function renderEmptySectionHead() { echo ''; }
|
||||
}
|
||||
|
||||
class Settings_API_Util_Field {
|
||||
|
||||
const TYPE_TEXTFIELD = 'textfield';
|
||||
const TYPE_TEXTAREA = 'textarea';
|
||||
const TYPE_CHECKBOX = 'checkbox';
|
||||
const TYPE_RADIO = 'radio';
|
||||
const TYPE_SELECT = 'select';
|
||||
const TYPE_HIDDEN = 'hidden';
|
||||
|
||||
public $section;
|
||||
|
||||
function __construct($section, $id, $title, $type, $defaultValue, $additionalArgs) {
|
||||
|
||||
$this->section = $section;
|
||||
$this->name = $id;
|
||||
$this->optionID = $section->id.'_'.$id;
|
||||
$this->defaultValue = $defaultValue;
|
||||
$this->type = $type;
|
||||
|
||||
$values = array(
|
||||
'id' =>$section->settings->optionName.'_'.$this->optionID,
|
||||
'name' => $section->settings->optionName.'['.$this->optionID.']',
|
||||
);
|
||||
|
||||
if (isset($this->section->settings->values[$this->optionID])) {
|
||||
$values['value'] = $this->section->settings->values[$this->optionID];
|
||||
}
|
||||
else {
|
||||
$values['value'] = $defaultValue;
|
||||
}
|
||||
|
||||
if ($additionalArgs) {
|
||||
$values = array_merge($values, $additionalArgs);
|
||||
}
|
||||
|
||||
$this->values = $values;
|
||||
|
||||
add_settings_field($section->id.'_'.$id, __( $title, 'clef' ), array(__CLASS__, $type), $section->settings->id, $section->id, $values);
|
||||
}
|
||||
|
||||
function render($opts = array()) {
|
||||
call_user_func(array(__CLASS__, $this->type), array_merge($opts, $this->values));
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Field renderers
|
||||
///////////////////
|
||||
|
||||
/**
|
||||
* Textfield
|
||||
* @param array $options
|
||||
*/
|
||||
public static function textfield(array $options) {
|
||||
if (!isset($options['placeholder'])) $options['placeholder'] = '';
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_textfield');
|
||||
echo "<input type=\"text\" name=\"{$options['name']}\" value=\"{$options['value']}\" id=\"{$options['name']}\" class=\"regular-text\" placeholder=\"{$options['placeholder']}\" />";
|
||||
do_action('settings_api_util_after_textfield');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_textfield', $html);
|
||||
echo $html;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Textarea
|
||||
* @param array $options
|
||||
*/
|
||||
public static function textarea(array $options) {
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_textarea');
|
||||
echo "<textarea name=\"{$options['name']}\">{$options['value']}</textarea>";
|
||||
do_action('settings_api_util_after_textarea');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_textarea', $html);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox
|
||||
* @param array $options
|
||||
*/
|
||||
public static function checkbox(array $options) {
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_checkbox');
|
||||
if($options['value']) {
|
||||
echo "<input type=\"checkbox\" name=\"{$options['name']}\" value=\"1\" checked>";
|
||||
} else {
|
||||
echo "<input type=\"checkbox\" name=\"{$options['name']}\" value=\"1\">";
|
||||
}
|
||||
do_action('settings_api_util_after_checkbox');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_checkbox', $html);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Radio
|
||||
* @param array $options
|
||||
*/
|
||||
public static function radio(array $options) {
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_radio');
|
||||
echo "<input type=\"radio\" name=\"{$options['name']}\" value=\"{$options['value']}\" />";
|
||||
do_action('settings_api_util_after_radio');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_radio', $html);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select
|
||||
* @param array $options
|
||||
*/
|
||||
public static function select(array $options) {
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_select');
|
||||
echo "<select name=\"{$options['name']}\">";
|
||||
foreach ($options['options'] as &$opt) {
|
||||
if (gettype($opt) == "array") {
|
||||
$display = $opt[0];
|
||||
$value = $opt[1];
|
||||
} else {
|
||||
$display = $value = $opt;
|
||||
}
|
||||
|
||||
if ($value == $options['value']) {
|
||||
echo "<option selected";
|
||||
} else {
|
||||
echo "<option";
|
||||
}
|
||||
echo " value='". $value . "'>" . $display . "</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
do_action('settings_api_util_after_select');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_select', $html);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hidden
|
||||
* @param array $options
|
||||
*/
|
||||
public static function hidden(array $options) {
|
||||
ob_start();
|
||||
do_action('settings_api_util_pre_hidden');
|
||||
echo "<input type=\"hidden\" name=\"{$options['name']}\" value=\"{$options['value']}\"/>";
|
||||
do_action('settings_api_util_after_hidden');
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
apply_filters('settings_api_util_hidden', $html);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
class AjaxSettings {
|
||||
const VERSION = '0.0.1';
|
||||
static $DEFAULTS = array(
|
||||
"network_wide" => false
|
||||
);
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
private function __construct( $opts ) {
|
||||
$this->options = array_merge(self::$DEFAULTS, $opts);
|
||||
|
||||
|
||||
add_action('admin_enqueue_scripts', array($this, "enqueue_scripts"));
|
||||
add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
|
||||
|
||||
add_action(
|
||||
'wp_ajax_ajax_settings_save_' . $this->name(),
|
||||
array($this, 'handle_settings_save')
|
||||
);
|
||||
}
|
||||
|
||||
function enqueue_scripts() {
|
||||
$ident = $this->identifier();
|
||||
wp_register_script(
|
||||
$ident,
|
||||
$this->options['base_url'] . "js/ajax-settings.min.js",
|
||||
array('backbone'),
|
||||
self::VERSION,
|
||||
TRUE
|
||||
);
|
||||
wp_localize_script($ident, 'ajaxSetOpt', $this->options);
|
||||
wp_enqueue_script($ident);
|
||||
}
|
||||
|
||||
function enqueue_styles() {
|
||||
$ident = $this->identifier();
|
||||
wp_register_style(
|
||||
$ident,
|
||||
$this->options['base_url'] . 'css/ajax-settings.min.css',
|
||||
false,
|
||||
self::VERSION
|
||||
);
|
||||
wp_enqueue_style($ident);
|
||||
}
|
||||
|
||||
function handle_settings_save() {
|
||||
global $HTTP_RAW_POST_DATA;
|
||||
if (!isset($HTTP_RAW_POST_DATA)) {
|
||||
$HTTP_RAW_POST_DATA = file_get_contents( "php://input" );
|
||||
}
|
||||
|
||||
// strip off any leading characters before json starts and then parse
|
||||
$stripped = preg_replace('/^.*?{/', '{', $HTTP_RAW_POST_DATA);
|
||||
$settings = json_decode($stripped, true);
|
||||
|
||||
if (!$settings) wp_die(__('Settings could not be parsed — this may be caused by a plugin conflict.'));
|
||||
|
||||
$option_page = $settings['option_page'];
|
||||
$is_network_wide = isset($_REQUEST['network_wide']) && $_REQUEST['network_wide'];
|
||||
|
||||
if (!wp_verify_nonce($settings['_wpnonce'], $option_page . "-options")) {
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
}
|
||||
|
||||
// if it's network request, we want to check that the current user is
|
||||
// a network admin
|
||||
if ($is_network_wide && !is_super_admin()) wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
// verify that the user has the permissions to edit the clef page
|
||||
$capability = 'manage_options';
|
||||
$capability = apply_filters( "option_page_capability_{$option_page}", $capability );
|
||||
if ( !current_user_can( $capability ) )
|
||||
wp_die(__('Cheatin’ uh?'));
|
||||
|
||||
$whitelist_options = apply_filters( 'whitelist_options', array() );
|
||||
$options = $whitelist_options[$settings['option_page']];
|
||||
if (empty($options[0]) || $options[0] != $this->name()) {
|
||||
wp_die("You can't do that!");
|
||||
}
|
||||
|
||||
$to_be_saved = array();
|
||||
foreach ($settings as $key => &$value) {
|
||||
$match = preg_match('/(.+)\[(.+)\]$/', $key, $output);
|
||||
if ($match) {
|
||||
$nester_key = $output[1];
|
||||
if ($nester_key == $this->name()) {
|
||||
$nested_key = $output[2];
|
||||
$to_be_saved[$nested_key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$to_be_saved = apply_filters('ajax_settings_pre_save', $to_be_saved);
|
||||
|
||||
if ($is_network_wide) {
|
||||
update_site_option($this->name(), $to_be_saved);
|
||||
} else {
|
||||
update_option($this->name(), $to_be_saved);
|
||||
}
|
||||
|
||||
$errors = get_settings_errors();
|
||||
$response = array();
|
||||
|
||||
if (!empty($errors)) {
|
||||
$error_messages = array();
|
||||
foreach ($errors as &$error) {
|
||||
$error_messages[$error['code']] = $error['message'];
|
||||
}
|
||||
$response['errors'] = $error_messages;
|
||||
header('HTTP/1.0 400');
|
||||
wp_send_json_error($response);
|
||||
} else {
|
||||
$response['success'] = true;
|
||||
wp_send_json($response);
|
||||
}
|
||||
}
|
||||
|
||||
function identifier() {
|
||||
return $this->name() . '-ajax-settings';
|
||||
}
|
||||
|
||||
function name() {
|
||||
return $this->options['options_name'];
|
||||
}
|
||||
|
||||
function update_options($options) {
|
||||
$this->options = array_merge($this->options, $options);
|
||||
}
|
||||
|
||||
public static function start($options = array()) {
|
||||
if (!isset(self::$instance) || self::$instance === null) {
|
||||
self::$instance = new self($options);
|
||||
} else {
|
||||
self::$instance->update_options($options);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
|
||||
1
wp-content/plugins/wpclef/includes/lib/ajax-settings/css/ajax-settings.min.css
vendored
Normal file
1
wp-content/plugins/wpclef/includes/lib/ajax-settings/css/ajax-settings.min.css
vendored
Normal file
@@ -0,0 +1 @@
|
||||
div.ajax-settings-updated{width:20px;height:20px;background:#fff;position:absolute;border-radius:20px;right:0;top:0;margin-left:10px;opacity:1;-webkit-animation:blink 2s infinite;animation:blink 2s infinite}div.ajax-settings-updated.success{background-color:#2ecc71;-webkit-transition:500ms;transition:500ms}@-webkit-keyframes blink{0%,100%{opacity:1}50%{opacity:.4}}@keyframes blink{0%,100%{opacity:1}50%{opacity:.4}}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
2
wp-content/plugins/wpclef/includes/lib/ajax-settings/js/ajax-settings.min.js
vendored
Normal file
2
wp-content/plugins/wpclef/includes/lib/ajax-settings/js/ajax-settings.min.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
(function(e,t){var i;return i=t.Model.extend({url:ajaxurl+"?action=ajax_settings_save",sync:function(e,i,s){return s=s||{},s.emulateHTTP=!0,t.Model.prototype.sync.call(this,e,i,s)},parse:function(e,t){return t.form?(this.optionsName=t.options_name,this.url=ajaxurl+("?action=ajax_settings_save_"+this.optionsName),t.url&&(this.url=t.url),t.network_wide&&(this.url+="&network_wide=true"),this.$form=t.form,_.extend(e,this.$form.serializeObject())):void 0},isNew:function(){return!1},update:function(t){var i;return i=e(t),i.is(":checkbox")&&(t.value=i.is(":checked")?1:0),this.saving=!0,this.save(t.name,t.value,{success:this.saveSuccess.bind(this),error:this.saveError.bind(this)})},saveSuccess:function(e,t){return this.saving=!1},saveError:function(e,t){return this.saving=!1},findInput:function(e,t){return null==t&&(t={}),this._is||(this._is={}),this._is[e]||(this._is[e]=this.$form.find("input, select, textarea").filter("[name='"+e+"']")),this._is[e]}}),e.fn.serializeObject=function(t){var i,s,n,r,a;for(s={},a=e(this).serializeArray(),n=0,r=a.length;r>n;n++)i=a[n],s[i.name]=i.value;return s},i.extend=t.Model.extend,this.AjaxSettingsModel=i}).call(this,jQuery,Backbone);
|
||||
(function(e,t){var s;return s=t.View.extend({messageTemplate:_.template("<div class='<%=type%> ajax-settings-msg'><p><%= message %></p></div>"),events:{"change input:not(.ajax-ignore)":"persistChanges","change select:not(.ajax-ignore)":"persistChanges","change textarea:not(.ajax-ignore)":"persistChanges"},modelClass:AjaxSettingsModel,el:'form[action="options.php"]',genericErrorMessage:"Something went wrong: ",successMessageDisplayTime:3e3,initialize:function(t){return this.opts=t,this.opts.formSelector&&this.setElement(e(t.formSelector)),this.hide(),this.model=new this.modelClass({},_.extend({form:this.$el,parse:!0},this.opts)),this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"change",this.startUpdating),this.listenTo(this.model,"sync",this.updated),this.listenTo(this.model,"error",this.error),this.listenTo(this.model,"change",this.clearErrors)},hide:function(){return this.$el.hide()},render:function(){var e,t,s,r,i;r=this.model.attributes,i=[];for(t in r)s=r[t],e=this.model.findInput(t),e?e.is(":checkbox")?i.push(e.prop("checked",parseInt(s))):i.push(e.val(s)):i.push(void 0);return i},show:function(){return this.$el.fadeIn()},persistChanges:function(e){return e.preventDefault(),this.model.update(e.currentTarget)},startUpdating:function(e,t){var s,r,i,n;i=e.changed,n=[];for(s in i)r=i[s],n.push(this.settingUpdateSent(this.model.findInput(s)));return n},updated:function(e,t){var s,r,i,n;this.render(),i=e.changed,n=[];for(s in i)r=i[s],n.push(this.settingUpdateSuccess(this.model.findInput(s)));return n},error:function(e,t){var s,r,i,n;if(!t.responseJSON||!t.responseJSON.data)return void this.showMessage({message:""+this.genericErrorMessage+" "+t.responseText,type:"error"});if(!t.responseJSON.data.errors&&t.responseJSON.data.error)return void this.showMessage({message:t.responseJSON.data.error,type:"error"});i=t.responseJSON.data.errors,n=[];for(s in i)r=i[s],n.push(this.settingsUpdateError(this.model.findInput(""+this.opts.options_name+"["+s+"]"),r));return n},clearErrors:function(e,t){var s,r,i,n,a;this.globalError&&(this.globalError.remove(),this.globalError=null),n=e.changed,a=[];for(r in n)i=n[r],s=this.model.findInput(r),s.data("errorEl")?(s.data("errorEl").remove(),a.push(s.data("errorEl",null))):a.push(void 0);return a},settingUpdateSent:function(e){},settingUpdateSuccess:function(t){var s;if(t.length&&!t.data("successEl"))return s=e(this.messageTemplate({message:"Setting saved.",type:"updated"})).hide(),t.data("successEl",s.insertAfter(t).slideDown()),setTimeout(function(){return s.slideUp(),t.data("successEl",null)},this.successMessageDisplayTime)},settingsUpdateError:function(t,s){var r;return t.data("errorEl")?t.data("errorEl").find("p").html(s):(r=e(this.messageTemplate({message:s,type:"error"})).hide(),t.data("errorEl",r.insertAfter(t).slideDown()))},showMessage:function(t){var s;return s=e(this.messageTemplate(t)).hide(),this.globalError=s.prependTo(this.$el).slideDown(),e("html, body").animate({scrollTop:this.$el.scrollTop()},"slow")}},{extend:t.View.extend}),this.AjaxSettingsView=s,e(document).ready(function(){var e;return ajaxSetOpt.initialize?(e=""+ajaxSetOpt.options_name+"AjaxSettingsView",window[e]=new s(ajaxSetOpt)):void 0}),e.fn.leftPositionWithPadding=function(){var e;return e=this.position().left,e+=this.width(),this.css("padding-left")&&(e+=parseInt(this.css("padding-left"))),this.css("padding-right")&&(e+=parseInt(this.css("padding-right"))),this.css("border-left")&&(e+=parseInt(this.css("border-left"))),this.css("border-right")&&(e+=parseInt(this.css("border-right"))),e}}).call(this,jQuery,Backbone);
|
||||
12
wp-content/plugins/wpclef/includes/lib/symlink-fix.php
Normal file
12
wp-content/plugins/wpclef/includes/lib/symlink-fix.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
function plugin_symlink_fix( $url, $path, $plugin ) {
|
||||
// Do it only for this plugin
|
||||
|
||||
if ( strstr( $plugin, 'wpclef' ) ) {
|
||||
return str_replace( dirname( $plugin ), '/' . basename( dirname( $plugin ) ), $url );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
add_filter( 'plugins_url', 'plugin_symlink_fix', 10, 3 );
|
||||
5
wp-content/plugins/wpclef/includes/lib/utils.inc
Normal file
5
wp-content/plugins/wpclef/includes/lib/utils.inc
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
|
||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Multidimensional ArrayAccess
|
||||
*
|
||||
* Allows ArrayAccess-like functionality with multidimensional arrays. Fully supports
|
||||
* both sets and unsets.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Session
|
||||
* @since 3.7.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Recursive array class to allow multidimensional array access.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 3.7.0
|
||||
*/
|
||||
class Recursive_ArrayAccess implements ArrayAccess {
|
||||
/**
|
||||
* Internal data collection.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $container = array();
|
||||
|
||||
/**
|
||||
* Flag whether or not the internal collection has been changed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $dirty = false;
|
||||
|
||||
/**
|
||||
* Default object constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
protected function __construct( $data = array() ) {
|
||||
foreach ( $data as $key => $value ) {
|
||||
$this[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow deep copies of objects
|
||||
*/
|
||||
public function __clone() {
|
||||
foreach ( $this->container as $key => $value ) {
|
||||
if ( $value instanceof self ) {
|
||||
$this[ $key ] = clone $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the data container as a multidimensional array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray() {
|
||||
$data = $this->container;
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( $value instanceof self ) {
|
||||
$data[ $key ] = $value->toArray();
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/* ArrayAccess Implementation */
|
||||
/*****************************************************************/
|
||||
|
||||
/**
|
||||
* Whether a offset exists
|
||||
*
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
|
||||
*
|
||||
* @param mixed $offset An offset to check for.
|
||||
*
|
||||
* @return boolean true on success or false on failure.
|
||||
*/
|
||||
public function offsetExists( $offset ) {
|
||||
return isset( $this->container[ $offset ]) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to retrieve
|
||||
*
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetget.php
|
||||
*
|
||||
* @param mixed $offset The offset to retrieve.
|
||||
*
|
||||
* @return mixed Can return all value types.
|
||||
*/
|
||||
public function offsetGet( $offset ) {
|
||||
return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to set
|
||||
*
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetset.php
|
||||
*
|
||||
* @param mixed $offset The offset to assign the value to.
|
||||
* @param mixed $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet( $offset, $data ) {
|
||||
if ( is_array( $data ) ) {
|
||||
$data = new self( $data );
|
||||
}
|
||||
if ( $offset === null ) { // don't forget this!
|
||||
$this->container[] = $data;
|
||||
} else {
|
||||
$this->container[ $offset ] = $data;
|
||||
}
|
||||
|
||||
$this->dirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to unset
|
||||
*
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
|
||||
*
|
||||
* @param mixed $offset The offset to unset.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset( $offset ) {
|
||||
unset( $this->container[ $offset ] );
|
||||
|
||||
$this->dirty = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress session managment.
|
||||
*
|
||||
* Standardizes WordPress session data using database-backed options for storage.
|
||||
* for storing user session information.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Session
|
||||
* @since 3.7.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* WordPress Session class for managing user session data.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 3.7.0
|
||||
*/
|
||||
final class WP_Session extends Recursive_ArrayAccess implements Iterator, Countable {
|
||||
/**
|
||||
* ID of the current session.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $session_id;
|
||||
|
||||
/**
|
||||
* Unix timestamp when session expires.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expires;
|
||||
|
||||
/**
|
||||
* Unix timestamp indicating when the expiration time needs to be reset.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $exp_variant;
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*
|
||||
* @var bool|WP_Session
|
||||
*/
|
||||
private static $instance = false;
|
||||
|
||||
/**
|
||||
* Retrieve the current session instance.
|
||||
*
|
||||
* @param bool $session_id Session ID from which to populate data.
|
||||
*
|
||||
* @return bool|WP_Session
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Will rebuild the session collection from the given session ID if it exists. Otherwise, will
|
||||
* create a new session with that ID.
|
||||
*
|
||||
* @param $session_id
|
||||
* @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire.
|
||||
*/
|
||||
protected function __construct() {
|
||||
if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) {
|
||||
$cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] );
|
||||
$cookie_crumbs = explode( '||', $cookie );
|
||||
|
||||
$this->session_id = $cookie_crumbs[0];
|
||||
$this->expires = $cookie_crumbs[1];
|
||||
$this->exp_variant = $cookie_crumbs[2];
|
||||
|
||||
// Update the session expiration if we're past the variant time
|
||||
if ( time() > $this->exp_variant ) {
|
||||
$this->set_expiration();
|
||||
delete_option( "_wp_session_expires_{$this->session_id}" );
|
||||
add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
|
||||
}
|
||||
} else {
|
||||
$this->session_id = $this->generate_id();
|
||||
$this->set_expiration();
|
||||
}
|
||||
|
||||
$this->read_data();
|
||||
|
||||
$this->set_cookie();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both the expiration time and the expiration variant.
|
||||
*
|
||||
* If the current time is below the variant, we don't update the session's expiration time. If it's
|
||||
* greater than the variant, then we update the expiration time in the database. This prevents
|
||||
* writing to the database on every page load for active sessions and only updates the expiration
|
||||
* time if we're nearing when the session actually expires.
|
||||
*
|
||||
* By default, the expiration time is set to 30 minutes.
|
||||
* By default, the expiration variant is set to 24 minutes.
|
||||
*
|
||||
* As a result, the session expiration time - at a maximum - will only be written to the database once
|
||||
* every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by
|
||||
* the browser, and the old session will be queued for deletion by the garbage collector.
|
||||
*
|
||||
* @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data.
|
||||
* @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
|
||||
*/
|
||||
protected function set_expiration() {
|
||||
$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
|
||||
$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the session cookie
|
||||
*/
|
||||
protected function set_cookie() {
|
||||
setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a cryptographically strong unique ID for the session token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_id() {
|
||||
require_once( ABSPATH . 'wp-includes/class-phpass.php');
|
||||
$hasher = new PasswordHash( 8, false );
|
||||
|
||||
return md5( $hasher->get_random_bytes( 32 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from a transient for the current session.
|
||||
*
|
||||
* Automatically resets the expiration time for the session transient to some time in the future.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function read_data() {
|
||||
$this->container = get_option( "_wp_session_{$this->session_id}", array() );
|
||||
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the data from the current session to the data storage system.
|
||||
*/
|
||||
public function write_data() {
|
||||
$option_key = "_wp_session_{$this->session_id}";
|
||||
|
||||
// Only write the collection to the DB if it's changed.
|
||||
if ( $this->dirty ) {
|
||||
if ( false === get_option( $option_key ) ) {
|
||||
add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
|
||||
add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' );
|
||||
} else {
|
||||
delete_option( "_wp_session_{$this->session_id}" );
|
||||
add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the current container contents as a JSON-encoded string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function json_out() {
|
||||
return json_encode( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
|
||||
*
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function json_in( $data ) {
|
||||
$array = json_decode( $data );
|
||||
|
||||
if ( is_array( $array ) ) {
|
||||
$this->container = $array;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the current session's ID.
|
||||
*
|
||||
* @param bool $delete_old Flag whether or not to delete the old session data from the server.
|
||||
*/
|
||||
public function regenerate_id( $delete_old = false ) {
|
||||
if ( $delete_old ) {
|
||||
delete_option( "_wp_session_{$this->session_id}" );
|
||||
}
|
||||
|
||||
$this->session_id = $this->generate_id();
|
||||
|
||||
$this->set_cookie();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a session has been initialized.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function session_started() {
|
||||
return !!self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the read-only cache expiration value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function cache_expiration() {
|
||||
return $this->expires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes all session variables.
|
||||
*/
|
||||
public function reset() {
|
||||
$this->container = array();
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/* Iterator Implementation */
|
||||
/*****************************************************************/
|
||||
|
||||
/**
|
||||
* Current position of the array.
|
||||
*
|
||||
* @link http://php.net/manual/en/iterator.current.php
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current() {
|
||||
return current( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Key of the current element.
|
||||
*
|
||||
* @link http://php.net/manual/en/iterator.key.php
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function key() {
|
||||
return key( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the internal point of the container array to the next item
|
||||
*
|
||||
* @link http://php.net/manual/en/iterator.next.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function next() {
|
||||
next( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the internal point of the container array.
|
||||
*
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rewind() {
|
||||
reset( $this->container );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the current key valid?
|
||||
*
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function valid() {
|
||||
return $this->offsetExists( $this->key() );
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
/* Countable Implementation */
|
||||
/*****************************************************************/
|
||||
|
||||
/**
|
||||
* Get the count of elements in the container array.
|
||||
*
|
||||
* @link http://php.net/manual/en/countable.count.php
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count( $this->container );
|
||||
}
|
||||
}
|
||||
169
wp-content/plugins/wpclef/includes/lib/wp-session/wp-session.php
Normal file
169
wp-content/plugins/wpclef/includes/lib/wp-session/wp-session.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* WordPress session managment.
|
||||
*
|
||||
* Standardizes WordPress session data and uses either database transients or in-memory caching
|
||||
* for storing user session information.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Session
|
||||
* @since 3.7.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return the current cache expire setting.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function wp_session_cache_expire() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
return $wp_session->cache_expiration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of wp_session_write_close()
|
||||
*/
|
||||
function wp_session_commit() {
|
||||
wp_session_write_close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a JSON-encoded string into the current session.
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
function wp_session_decode( $data ) {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
return $wp_session->json_in( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the current session's data as a JSON string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function wp_session_encode() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
return $wp_session->json_out();
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the session ID.
|
||||
*
|
||||
* @param bool $delete_old_session
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function wp_session_regenerate_id( $delete_old_session = false ) {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
$wp_session->regenerate_id( $delete_old_session );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start new or resume existing session.
|
||||
*
|
||||
* Resumes an existing session based on a value sent by the _wp_session cookie.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function wp_session_start() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
do_action( 'wp_session_start' );
|
||||
|
||||
return $wp_session->session_started();
|
||||
}
|
||||
add_action( 'plugins_loaded', 'wp_session_start' );
|
||||
|
||||
/**
|
||||
* Return the current session status.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function wp_session_status() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
if ( $wp_session->session_started() ) {
|
||||
return PHP_SESSION_ACTIVE;
|
||||
}
|
||||
|
||||
return PHP_SESSION_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset all session variables.
|
||||
*/
|
||||
function wp_session_unset() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
$wp_session->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write session data and end session
|
||||
*/
|
||||
function wp_session_write_close() {
|
||||
$wp_session = WP_Session::get_instance();
|
||||
|
||||
$wp_session->write_data();
|
||||
do_action( 'wp_session_commit' );
|
||||
}
|
||||
add_action( 'shutdown', 'wp_session_write_close' );
|
||||
|
||||
/**
|
||||
* Clean up expired sessions by removing data and their expiration entries from
|
||||
* the WordPress options table.
|
||||
*
|
||||
* This method should never be called directly and should instead be triggered as part
|
||||
* of a scheduled task or cron job.
|
||||
*/
|
||||
function wp_session_cleanup() {
|
||||
global $wpdb;
|
||||
|
||||
if ( defined( 'WP_SETUP_CONFIG' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! defined( 'WP_INSTALLING' ) ) {
|
||||
$expiration_keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%'" );
|
||||
|
||||
$now = time();
|
||||
$expired_sessions = array();
|
||||
|
||||
foreach( $expiration_keys as $expiration ) {
|
||||
// If the session has expired
|
||||
if ( $now > intval( $expiration->option_value ) ) {
|
||||
// Get the session ID by parsing the option_name
|
||||
$session_id = substr( $expiration->option_name, 20 );
|
||||
|
||||
$expired_sessions[] = $expiration->option_name;
|
||||
$expired_sessions[] = "_wp_session_$session_id";
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all expired sessions in a single query
|
||||
if ( ! empty( $expired_sessions ) ) {
|
||||
$option_names = implode( "','", $expired_sessions );
|
||||
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
|
||||
}
|
||||
}
|
||||
|
||||
// Allow other plugins to hook in to the garbage collection process.
|
||||
do_action( 'wp_session_cleanup' );
|
||||
}
|
||||
add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' );
|
||||
|
||||
/**
|
||||
* Register the garbage collector as a twice daily event.
|
||||
*/
|
||||
function wp_session_register_garbage_collection() {
|
||||
if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' );
|
||||
}
|
||||
}
|
||||
add_action( 'wp', 'wp_session_register_garbage_collection' );
|
||||
Reference in New Issue
Block a user