revert revert
This commit is contained in:
parent
700e55c9c2
commit
2eff1bf6d0
@ -7,8 +7,7 @@ require_once(CRAYON_THEMES_PHP);
|
||||
* Stores CrayonSetting objects.
|
||||
* Each Crayon instance stores an instance of this class containing its specific settings.
|
||||
*/
|
||||
class CrayonSettings
|
||||
{
|
||||
class CrayonSettings {
|
||||
// Properties and Constants ===============================================
|
||||
const INVALID = -1; // Used for invalid dropdown index
|
||||
// Plugin data
|
||||
@ -122,8 +121,7 @@ class CrayonSettings
|
||||
|
||||
private static $cache_array;
|
||||
|
||||
public static function get_cache_sec($cache)
|
||||
{
|
||||
public static function get_cache_sec($cache) {
|
||||
$values = array_values(self::$cache_array);
|
||||
if (array_key_exists($cache, $values)) {
|
||||
return $values[$cache];
|
||||
@ -138,13 +136,11 @@ class CrayonSettings
|
||||
// The settings with default values
|
||||
private static $default = NULL;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
function __construct() {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
function copy()
|
||||
{
|
||||
function copy() {
|
||||
$settings = new CrayonSettings();
|
||||
foreach ($this->settings as $setting) {
|
||||
$settings->set($setting); // Overuse of set?
|
||||
@ -154,8 +150,7 @@ class CrayonSettings
|
||||
|
||||
// Methods ================================================================
|
||||
|
||||
private function init()
|
||||
{
|
||||
private function init() {
|
||||
global $CRAYON_VERSION;
|
||||
|
||||
crayon_load_plugin_textdomain();
|
||||
@ -276,8 +271,7 @@ class CrayonSettings
|
||||
// Getter and Setter ======================================================
|
||||
|
||||
// TODO this needs simplification
|
||||
function set($name, $value = NULL, $replace = FALSE)
|
||||
{
|
||||
function set($name, $value = NULL, $replace = FALSE) {
|
||||
// Set associative array of settings
|
||||
if (is_array($name)) {
|
||||
$keys = array_keys($name);
|
||||
@ -315,8 +309,7 @@ class CrayonSettings
|
||||
}
|
||||
}
|
||||
|
||||
function get($name = NULL)
|
||||
{
|
||||
function get($name = NULL) {
|
||||
if ($name === NULL) {
|
||||
$copy = array();
|
||||
foreach ($this->settings as $name => $setting) {
|
||||
@ -331,8 +324,7 @@ class CrayonSettings
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function val($name = NULL)
|
||||
{
|
||||
function val($name = NULL) {
|
||||
if (($setting = self::get($name)) != FALSE) {
|
||||
return $setting->value();
|
||||
} else {
|
||||
@ -340,8 +332,7 @@ class CrayonSettings
|
||||
}
|
||||
}
|
||||
|
||||
function val_str($name)
|
||||
{
|
||||
function val_str($name) {
|
||||
if (($setting = self::get($name)) != FALSE) {
|
||||
$def = $setting->def();
|
||||
$index = $setting->value();
|
||||
@ -353,8 +344,7 @@ class CrayonSettings
|
||||
}
|
||||
}
|
||||
|
||||
function get_array()
|
||||
{
|
||||
function get_array() {
|
||||
$array = array();
|
||||
foreach ($this->settings as $setting) {
|
||||
$array[$setting->name()] = $setting->value();
|
||||
@ -362,15 +352,13 @@ class CrayonSettings
|
||||
return $array;
|
||||
}
|
||||
|
||||
function is_setting($name)
|
||||
{
|
||||
function is_setting($name) {
|
||||
return (is_string($name) && array_key_exists($name, $this->settings));
|
||||
}
|
||||
|
||||
/* Gets default settings, either as associative array of name=>value or CrayonSetting
|
||||
objects */
|
||||
public static function get_defaults($name = NULL, $objects = TRUE)
|
||||
{
|
||||
public static function get_defaults($name = NULL, $objects = TRUE) {
|
||||
if (self::$default === NULL) {
|
||||
self::$default = new CrayonSettings();
|
||||
}
|
||||
@ -398,8 +386,7 @@ class CrayonSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_defaults_array()
|
||||
{
|
||||
public static function get_defaults_array() {
|
||||
return self::get_defaults(NULL, FALSE);
|
||||
}
|
||||
|
||||
@ -412,8 +399,7 @@ class CrayonSettings
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function validate($name, $value)
|
||||
{
|
||||
public static function validate($name, $value) {
|
||||
if (!is_string($name)) {
|
||||
return '';
|
||||
}
|
||||
@ -484,8 +470,7 @@ class CrayonSettings
|
||||
// Takes an associative array of "smart settings" and regular settings. Smart settings can be used
|
||||
// to configure regular settings quickly.
|
||||
// E.g. 'max_height="20px"' will set 'height="20"', 'height_mode="0", height_unit="0"'
|
||||
public static function smart_settings($settings)
|
||||
{
|
||||
public static function smart_settings($settings) {
|
||||
if (!is_array($settings)) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -539,8 +524,7 @@ class CrayonSettings
|
||||
}
|
||||
|
||||
// Used for height and width smart settings, I couldn't bear to copy paste code twice...
|
||||
private static function smart_hw($name, $set, $mode, $unit, &$settings)
|
||||
{
|
||||
private static function smart_hw($name, $set, $mode, $unit, &$settings) {
|
||||
if (!is_string($name) || !is_string($set) || !is_string($mode) || !is_string($unit) || !is_array($settings)) {
|
||||
return;
|
||||
}
|
||||
@ -573,8 +557,7 @@ class CrayonSettings
|
||||
* These settings can be overriden by individual Crayons.
|
||||
* Also manages global site settings and paths.
|
||||
*/
|
||||
class CrayonGlobalSettings
|
||||
{
|
||||
class CrayonGlobalSettings {
|
||||
// The global settings stored as a CrayonSettings object.
|
||||
private static $global = NULL;
|
||||
/* These are used to load local files reliably and prevent scripts like PHP from executing
|
||||
@ -589,60 +572,50 @@ class CrayonGlobalSettings
|
||||
private static $upload_url = '';
|
||||
private static $mkdir = NULL;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
private static function init()
|
||||
{
|
||||
private static function init() {
|
||||
if (self::$global === NULL) {
|
||||
self::$global = new CrayonSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public static function get($name = NULL)
|
||||
{
|
||||
public static function get($name = NULL) {
|
||||
self::init();
|
||||
return self::$global->get($name);
|
||||
}
|
||||
|
||||
public static function get_array()
|
||||
{
|
||||
public static function get_array() {
|
||||
self::init();
|
||||
return self::$global->get_array();
|
||||
}
|
||||
|
||||
public static function get_obj()
|
||||
{
|
||||
public static function get_obj() {
|
||||
self::init();
|
||||
return self::$global->copy();
|
||||
}
|
||||
|
||||
public static function val($name = NULL)
|
||||
{
|
||||
public static function val($name = NULL) {
|
||||
self::init();
|
||||
return self::$global->val($name);
|
||||
}
|
||||
|
||||
public static function val_str($name = NULL)
|
||||
{
|
||||
public static function val_str($name = NULL) {
|
||||
self::init();
|
||||
return self::$global->val_str($name);
|
||||
}
|
||||
|
||||
public static function has_changed($input, $setting, $value)
|
||||
{
|
||||
public static function has_changed($input, $setting, $value) {
|
||||
return $input == $setting && $value != CrayonGlobalSettings::val($setting);
|
||||
}
|
||||
|
||||
public static function set($name, $value = NULL, $replace = FALSE)
|
||||
{
|
||||
public static function set($name, $value = NULL, $replace = FALSE) {
|
||||
self::init();
|
||||
self::$global->set($name, $value, $replace);
|
||||
}
|
||||
|
||||
public static function site_url($site_http = NULL)
|
||||
{
|
||||
public static function site_url($site_http = NULL) {
|
||||
if ($site_http === NULL) {
|
||||
return self::$site_http;
|
||||
} else {
|
||||
@ -650,8 +623,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function site_path($site_path = NULL)
|
||||
{
|
||||
public static function site_path($site_path = NULL) {
|
||||
if ($site_path === NULL) {
|
||||
return self::$site_path;
|
||||
} else {
|
||||
@ -659,8 +631,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function plugin_path($plugin_path = NULL)
|
||||
{
|
||||
public static function plugin_path($plugin_path = NULL) {
|
||||
if ($plugin_path === NULL) {
|
||||
return self::$plugin_path;
|
||||
} else {
|
||||
@ -668,8 +639,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function upload_path($upload_path = NULL)
|
||||
{
|
||||
public static function upload_path($upload_path = NULL) {
|
||||
if ($upload_path === NULL) {
|
||||
return self::$upload_path;
|
||||
} else {
|
||||
@ -677,8 +647,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function upload_url($upload_url = NULL)
|
||||
{
|
||||
public static function upload_url($upload_url = NULL) {
|
||||
if ($upload_url === NULL) {
|
||||
return self::$upload_url;
|
||||
} else {
|
||||
@ -686,8 +655,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function set_mkdir($mkdir = NULL)
|
||||
{
|
||||
public static function set_mkdir($mkdir = NULL) {
|
||||
if ($mkdir === NULL) {
|
||||
return self::$mkdir;
|
||||
} else {
|
||||
@ -695,8 +663,7 @@ class CrayonGlobalSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function mkdir($dir = NULL)
|
||||
{
|
||||
public static function mkdir($dir = NULL) {
|
||||
if (self::$mkdir) {
|
||||
call_user_func(self::$mkdir, $dir);
|
||||
} else {
|
||||
@ -711,17 +678,14 @@ $INT = new CrayonValidator('#\d+#');
|
||||
/**
|
||||
* Validation class.
|
||||
*/
|
||||
class CrayonValidator
|
||||
{
|
||||
class CrayonValidator {
|
||||
private $pattern = '#*#msi';
|
||||
|
||||
public function __construct($pattern)
|
||||
{
|
||||
public function __construct($pattern) {
|
||||
$this->pattern($pattern);
|
||||
}
|
||||
|
||||
public function pattern($pattern)
|
||||
{
|
||||
public function pattern($pattern) {
|
||||
if ($pattern === NULL) {
|
||||
return $pattern;
|
||||
} else {
|
||||
@ -729,13 +693,11 @@ class CrayonValidator
|
||||
}
|
||||
}
|
||||
|
||||
public function validate($str)
|
||||
{
|
||||
public function validate($str) {
|
||||
return preg_match($this->pattern, $str) !== FALSE;
|
||||
}
|
||||
|
||||
public function sanitize($str)
|
||||
{
|
||||
public function sanitize($str) {
|
||||
preg_match_all($this->pattern, $str, $matches);
|
||||
$result = '';
|
||||
foreach ($matches as $match) {
|
||||
@ -745,18 +707,14 @@ class CrayonValidator
|
||||
}
|
||||
}
|
||||
|
||||
class CrayonNonNegIntValidator extends CrayonValidator
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
class CrayonNonNegIntValidator extends CrayonValidator {
|
||||
public function __construct() {
|
||||
parent::__construct('#\d+#');
|
||||
}
|
||||
}
|
||||
|
||||
class CrayonIntValidator extends CrayonValidator
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
class CrayonIntValidator extends CrayonValidator {
|
||||
public function __construct() {
|
||||
parent::__construct('#-?\d+#');
|
||||
}
|
||||
}
|
||||
@ -765,8 +723,7 @@ class CrayonIntValidator extends CrayonValidator
|
||||
* Individual setting.
|
||||
* Can store boolean, string, dropdown (with array of strings), etc.
|
||||
*/
|
||||
class CrayonSetting
|
||||
{
|
||||
class CrayonSetting {
|
||||
private $name = '';
|
||||
/* The type of variables that can be set as the value.
|
||||
* For dropdown settings, value is int, even though value() will return a string. */
|
||||
@ -781,8 +738,7 @@ class CrayonSetting
|
||||
private $validator = NULL;
|
||||
|
||||
|
||||
public function __construct($name, $default = '', $value = NULL, $locked = NULL)
|
||||
{
|
||||
public function __construct($name, $default = '', $value = NULL, $locked = NULL) {
|
||||
$this->name($name);
|
||||
if ($default !== NULL) {
|
||||
$this->def($default); // Perform first to set type
|
||||
@ -795,35 +751,29 @@ class CrayonSetting
|
||||
}
|
||||
}
|
||||
|
||||
function __tostring()
|
||||
{
|
||||
function __tostring() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function copy()
|
||||
{
|
||||
function copy() {
|
||||
return new CrayonSetting($this->name, $this->default, $this->value, $this->locked);
|
||||
}
|
||||
|
||||
function name($name = NULL)
|
||||
{
|
||||
function name($name = NULL) {
|
||||
if (!CrayonUtil::str($this->name, $name)) {
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
function type()
|
||||
{
|
||||
function type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
function is_array()
|
||||
{
|
||||
function is_array() {
|
||||
return $this->is_array;
|
||||
}
|
||||
|
||||
function locked($locked = NULL)
|
||||
{
|
||||
function locked($locked = NULL) {
|
||||
if ($locked === NULL) {
|
||||
return $this->locked;
|
||||
} else {
|
||||
@ -838,8 +788,7 @@ class CrayonSetting
|
||||
* value() returns string value at current index for dropdown settings.
|
||||
* @param $value
|
||||
*/
|
||||
function value($value = NULL)
|
||||
{
|
||||
function value($value = NULL) {
|
||||
if ($value === NULL) {
|
||||
/*if ($this->is_array) {
|
||||
return $this->default[$this->value]; // value at index
|
||||
@ -863,8 +812,7 @@ class CrayonSetting
|
||||
}
|
||||
}
|
||||
|
||||
function array_value()
|
||||
{
|
||||
function array_value() {
|
||||
if ($this->is_array) {
|
||||
return NULL;
|
||||
}
|
||||
@ -876,8 +824,7 @@ class CrayonSetting
|
||||
* For dropdown settings, default value is array of all possible value strings.
|
||||
* @param $default
|
||||
*/
|
||||
function def($default = NULL)
|
||||
{
|
||||
function def($default = NULL) {
|
||||
// Only allow default to be set once
|
||||
|
||||
if ($this->type === NULL && $default !== NULL) {
|
||||
@ -917,8 +864,7 @@ class CrayonSetting
|
||||
* @param int|string $index
|
||||
* @return FALSE if not dropdown setting
|
||||
*/
|
||||
function index($index = NULL)
|
||||
{
|
||||
function index($index = NULL) {
|
||||
if (!$this->is_array) {
|
||||
return FALSE;
|
||||
} else if ($index === NULL) {
|
||||
@ -939,8 +885,7 @@ class CrayonSetting
|
||||
/**
|
||||
* Finds the index of a string in an array setting
|
||||
*/
|
||||
function find_index($str)
|
||||
{
|
||||
function find_index($str) {
|
||||
if (!$this->is_array || is_string($str)) {
|
||||
return FALSE;
|
||||
}
|
||||
@ -952,8 +897,7 @@ class CrayonSetting
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function validator($validator)
|
||||
{
|
||||
function validator($validator) {
|
||||
if ($validator === NULL) {
|
||||
return $this->validator;
|
||||
} else {
|
||||
@ -961,8 +905,7 @@ class CrayonSetting
|
||||
}
|
||||
}
|
||||
|
||||
function sanitize($str)
|
||||
{
|
||||
function sanitize($str) {
|
||||
if ($this->validator != NULL) {
|
||||
return $this->validator->sanitize($str);
|
||||
} else {
|
||||
@ -971,3 +914,5 @@ class CrayonSetting
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1243,9 +1243,63 @@ class Human {
|
||||
|
||||
// About Fields ===========================================================
|
||||
|
||||
public static function info()
|
||||
{
|
||||
return '';
|
||||
public static function info() {
|
||||
global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_PLUGIN_WP, $CRAYON_AUTHOR_SITE, $CRAYON_EMAIL, $CRAYON_DONATE;
|
||||
echo '<a name="info"></a>';
|
||||
$version = '<strong>' . crayon__('Version') . ':</strong> ' . $CRAYON_VERSION;
|
||||
$date = $CRAYON_DATE;
|
||||
$developer = '<strong>' . crayon__('Developer') . ':</strong> ' . '<a href="' . $CRAYON_AUTHOR_SITE . '" target="_blank">' . $CRAYON_AUTHOR . '</a>';
|
||||
$translators = '<strong>' . crayon__('Translators') . ':</strong> ' .
|
||||
'
|
||||
Arabic (<a href="http://djennadhamza.eb2a.com/" target="_blank">Djennad Hamza</a>),
|
||||
Chinese Simplified (<a href="http://smerpup.com/" target="_blank">Dezhi Liu</a>, <a href="http://neverno.me/" target="_blank">Jash Yin</a>),
|
||||
Chinese Traditional (<a href="http://www.arefly.com/" target="_blank">Arefly</a>),
|
||||
Dutch (<a href="https://twitter.com/RobinRoelofsen" target="_blank">Robin Roelofsen</a>, <a href="https://twitter.com/#!/chilionsnoek" target="_blank">Chilion Snoek</a>),
|
||||
French (<a href="https://vhf.github.io" target="_blank">Victor Felder</a>),
|
||||
Finnish (<a href="https://github.com/vahalan" target="_blank">vahalan</a>),
|
||||
German (<a href="http://www.technologyblog.de/" target="_blank">Stephan Knauß</a>),
|
||||
Italian (<a href="http://www.federicobellucci.net/" target="_blank">Federico Bellucci</a>),
|
||||
Japanese (<a href="https://twitter.com/#!/west_323" target="_blank">@west_323</a>),
|
||||
Korean (<a href="https://github.com/dokenzy" target="_blank">dokenzy</a>),
|
||||
Lithuanian (Vincent G),
|
||||
Norwegian (<a href="http://www.jackalworks.com/blogg" target="_blank">Jackalworks</a>),
|
||||
Persian (MahdiY),
|
||||
Polish (<a href="https://github.com/toszcze" target="_blank">Bartosz Romanowski</a>, <a href="http://rob006.net/" target="_blank">Robert Korulczyk</a>),
|
||||
Portuguese (<a href="http://www.adonai.eti.br" target="_blank">Adonai S. Canez</a>),
|
||||
Russian (<a href="http://simplelib.com/" target="_blank">Minimus</a>, Di_Skyer),
|
||||
Slovak (<a href="https://twitter.com/#!/webhostgeeks" target="_blank">webhostgeeks</a>),
|
||||
Slovenian (<a href="http://jodlajodla.si/" target="_blank">Jan Sušnik</a>),
|
||||
Spanish (<a href="http://www.hbravo.com/" target="_blank">Hermann Bravo</a>),
|
||||
Tamil (<a href="http://kks21199.mrgoogleglass.com/" target="_blank">KKS21199</a>),
|
||||
Turkish (<a href="http://hakanertr.wordpress.com" target="_blank">Hakan</a>),
|
||||
Ukrainian (<a href="http://getvoip.com/blog" target="_blank">Michael Yunat</a>)';
|
||||
|
||||
$links = '
|
||||
<a id="docs-icon" class="small-icon" title="Documentation" href="' . $CRAYON_WEBSITE . '" target="_blank"></a>
|
||||
<a id="git-icon" class="small-icon" title="GitHub" href="' . $CRAYON_GIT . '" target="_blank"></a>
|
||||
<a id="wp-icon" class="small-icon" title="Plugin Page" href="' . $CRAYON_PLUGIN_WP . '" target="_blank"></a>
|
||||
<a id="twitter-icon" class="small-icon" title="Twitter" href="' . $CRAYON_TWITTER . '" target="_blank"></a>
|
||||
<a id="gmail-icon" class="small-icon" title="Email" href="mailto:' . $CRAYON_EMAIL . '" target="_blank"></a>
|
||||
<div id="crayon-donate"><a href="' . $CRAYON_DONATE . '" title="Donate" target="_blank">
|
||||
<img src="' . plugins_url(CRAYON_DONATE_BUTTON, __FILE__) . '"></a>
|
||||
</div>';
|
||||
|
||||
echo '
|
||||
<table id="crayon-info" border="0">
|
||||
<tr>
|
||||
<td>' . $version . ' - ' . $date . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>' . $developer . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>' . $translators . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">' . $links . '</td>
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
}
|
||||
|
||||
public static function help_button($link)
|
||||
|
Loading…
Reference in New Issue
Block a user