/** * oik plugins settings page * * Processing depends on the button that was pressed. There should only be one! * * Selection | Validate? | Perform action | Display check | Display add | Display edit | Display select list * ----------------------------- | -------- |------------------- |------------- | ------------ | ------------ | ------------------- * check_plugin | No | n/a | Yes | - | - | - * delete_plugin | No | delete selected plugin | - | - | - | Yes * edit_plugin | No | n/a | - | - | Yes | Yes * _oik_plugins_edit_settings | Yes | update selected plugin | - | - | Yes | Yes * _oik_plugins_add_plugin | No | n/a | - | Yes | - | ? * _oik_plugins_add_settings | Yes | add selected plugin | - | - | - | ? * */ function oik_lazy_plugins_server_settings() { bw_trace2(); bw_backtrace(); oik_menu_header("plugin server settings", "w100pc"); $validated = false; $check_plugin = bw_array_get($_REQUEST, "check_plugin", null); $delete_plugin = bw_array_get($_REQUEST, "delete_plugin", null); $edit_plugin = bw_array_get($_REQUEST, "edit_plugin", null); /** These plugins override the ones from the list... but why do we need to do it? * Do we have to receive the others in the $_REQUEST **?** * */ $oik_plugins_edit_settings = bw_array_get($_REQUEST, "_oik_plugins_edit_settings", null); $oik_plugins_add_settings = bw_array_get($_REQUEST, "_oik_plugins_add_settings", null); $oik_plugins_add_plugin = bw_array_get($_REQUEST, "_oik_plugins_add_plugin", null); if ($oik_plugins_add_plugin || $oik_plugins_add_settings) { $check_plugin = null; $delete_plugin = null; $edit_plugin = null; } if ($check_plugin) { oik_box(NULL, NULL, "Check", "oik_plugins_check"); } if ($delete_plugin) { _oik_plugins_delete_settings($delete_plugin); } if ($edit_plugin) { global $bw_plugin; $bw_plugins = get_option("bw_plugins"); $bw_plugin = bw_array_get($bw_plugins, $edit_plugin, null); if ($bw_plugin == null) { $bw_plugin['server'] = null; $bw_plugin['apikey'] = null; } $bw_plugin['plugin'] = $edit_plugin; bw_trace2($bw_plugin); } if ($oik_plugins_edit_settings) { $validated = _oik_plugins_settings_validate(false); } if ($oik_plugins_add_settings) { $validated = _oik_plugins_settings_validate(true); } if ($oik_plugins_add_plugin || $oik_plugins_add_settings && !$validated) { oik_box(NULL, NULL, "Add new", "oik_plugins_add_settings"); } if ($edit_plugin || $oik_plugins_edit_settings || $validated) { oik_box(null, null, "Edit plugin", "oik_plugins_edit_settings"); } oik_box(NULL, NULL, "Settings", "oik_plugins_settings"); oik_menu_footer(); bw_flush(); }
/** * Return the array[index] or build the result by calling $callback, passing the $default as the arg. * * * Notes: dcb = deferred callback * Use this function when applying the default might take some time but would be unnecessary if the $array[$index] is already set. * * You can also use this function when the default value is a string that you want to be translated. * * 2012/10/23 - When the parameter was passed as a null value e.g. "" then it was being treated as NULL * hence the default processing took effect. * In this new verision we replace the NULLs in the code body with $default * So bw_array_get() can return a given NULL value which will then override the default. * In this case, if the parameter that is passed turns out to be the default value then this will also be translated. * Note: It could could still match a default null value * Also: We don't expect a null value for the default callback function __() * 2012/12/04 - we have to allow for the value being set as 0 which differs from a default value of NULL * so the comparison needs to be identical ( === ) rather than equal ( == ) * * 2014/02/27 - In cases where value found may be the same as the default and the dcb function could mess this up * then it's advisable to NOT use this function. * * @param array $array array from which to obtain the value * @param string $index - index of value to obtain] * @param mixed $default - parameter to the $callback function * @param string $callback - function name to invoke - defaults to invoking __() */ static function bw_array_get_dcb($array = array(), $index, $default = NULL, $callback = '__', $text_domain = "oik") { $value = bw_array_get($array, $index, $default); if ($value === $default) { if (is_callable($callback)) { $value = call_user_func($callback, $default, $text_domain); } else { bw_backtrace(); } } return $value; }
/** * Get a list of columns. The format is: * 'internal-name' => 'Title' * * @since 3.1.0 * @access public * @abstract * * @return array */ public function get_columns() { $columns = array(); $columns['cb'] = '<input type="checkbox" />'; $columns['code'] = __("Code", "schunter"); $columns['help'] = __("Help", "schunter"); $columns['status'] = __("Status", "schunter"); $columns['function'] = __('Function', 'schunter'); $columns['total_references'] = __('References', 'schunter'); bw_backtrace(); bw_trace2($columns, "columns", false); return $columns; }
/** * Query the need to shorten a select field's options * * Get the value of '#length' if available. If this is set then we truncate the options strings * * * @param array $args - * @return integer - the length to shorten to, not including the '...' * */ function bw_query_shorten($args = null) { bw_backtrace(BW_TRACE_DEBUG); $shorten = 0; if ($args) { $shorten = bw_array_get($args, "#length", 0); } return $shorten; }
/** * Implement "themes_api_result" filter to add our own themes @return unserialised object $result ( [0] => stdClass Object ( [info] => Array ( [page] => 1 [pages] => 1 [results] => 6 ) [themes] => Array ( [0] => stdClass Object ( [name] => DailyPost [slug] => dailypost [version] => 1.0.5 [author] => valeriutihai [preview_url] => http://wp-themes.com/dailypost [screenshot_url] => http://wp-themes.com/wp-content/themes/dailypost/screenshot.png [rating] => 83.4 [num_ratings] => 6 [homepage] => http://wordpress.org/themes/dailypost [description] => DailyPost is intresting theme ideal for your everyday notes and thoughts, which supports post formats and several customisation options. The theme is a special one because of it's responsive design, thus you will get the pleasure to read the post with your mobile device. ) ... one per [results] */ static function oik_lazy_themes_api_result($result, $action, $args) { bw_backtrace(); bw_trace2(); /** * We need to do this for EACH theme that is installed to find which servers to query. * http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) * */ $url = "http://www.oik-plugins.com"; //$url = "http://qw/wpit"; $url .= "/themes/info/"; $post_args = array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))); $add_result = self::bw_remote_post($url, $post_args); if ($add_result) { $response = oik_merge_result($result, $add_result); } else { $response = $result; } bw_trace2($response, "response", false); return $response; }
/** * Determine the file name from the class and path * * If no file is specified we try to make it up. * If no path is specified we assume it's been passed in the file name * * * @param object $class_file * @return string fully qualified file name */ function file($class_file) { bw_trace2(null, null, true, BW_TRACE_DEBUG); bw_backtrace(BW_TRACE_VERBOSE); $file = $class_file->file; if (!$file) { $file = str_replace("_", "-", $class_file->class); $file = strtolower($file); $file = "class-{$file}.php"; if ($class_file->path) { $file = $class_file->path . '/' . $file; } } return $file; }
/** * Get the document root suffix * * This routine finds the subdirectory under which this local version of the website is installed. * Sometimes we need to remove this from index lookups but add it to links! * * @TODO Shouldn't this function be deprecated? */ function bw_get_docroot_suffix() { bw_backtrace(BW_TRACE_DEBUG); $docroot_suffix = "/"; if ($_SERVER['SERVER_NAME'] == bw_get_option("betterbyfar")) { $exdr = explode('/', $_SERVER["DOCUMENT_ROOT"]); $exsf = explode('/', $_SERVER['SCRIPT_FILENAME']); $docroot_suffix = '/' . $exsf[count($exdr)] . '/'; // bw_debug( "_SERVER[DOCUMENT_ROOT]: " . $_SERVER["DOCUMENT_ROOT"] ); // bw_debug( "_SERVER[REQUEST_URI]: " . $_SERVER['REQUEST_URI'] ); // bw_debug( "_SERVER[SCRIPT_FILENAME]: " . $_SERVER['SCRIPT_FILENAME'] ); // bw_debug( "docroot_suffix: " . $docroot_suffix ); } return $docroot_suffix; }
/** * Require a library file * * @param string $library the library name e.g. "oik_boot" * @param string $version the required library version e.g "2.5" - with wildcard stuff * @return object the lib object loaded */ function require_lib($library, $version = null) { $this->query_libs(); $lib = $this->determine_lib($library, $version); if (!is_wp_error($lib)) { if ($lib) { $lib->src(); if (file_exists($lib->src)) { require_once $lib->src; $this->loaded($lib); } else { bw_trace2($lib, "Library file missing", true, BW_TRACE_ERROR); $lib = false; $lib = $this->error("missing", "Library file missing", $lib); } } else { bw_trace2($lib, "lib not found for {$library},{$version}", false, BW_TRACE_ERROR); bw_backtrace(BW_TRACE_ERROR); $lib = $this->error("not found", "lib not found for {$library},{$version}", "{$library},{$version}"); } } return $lib; }
/** * Require a library * * @param string $lib library name * @param string $version the required minimum version * @return bool true if the required version has been loaded */ function require_lib($lib, $version = '*') { $lib_loaded = oik_require_lib($lib); if ($lib_loaded && !is_wp_error($lib_loaded)) { $lib_loaded = $this->version_check($lib, $version); } else { bw_trace2($lib_loaded, "require_lib error", true); bw_backtrace(); $this->show_update_nag("Failed to load library: {$lib}. version: {$version} "); $lib_loaded = null; } return $lib_loaded; }
/** * Build path from lib_args * * $lib_args is a sparse array that may contain the following * * Key | Contents * ------------ | ------------------------------------------------------------------------------ * 'library' | library name - either a shareable library name or in 'vendor/package' format * 'plugin' | plugin name - the plugin's folder name * 'theme' | theme name - the theme's folder * 'vendor-dir' | See below * 'vendor' | vendor name for a Composer package * 'package' | package name for a Composer package * 'file' | file name of the main library file in the path. default $library.php for 'libs', $package.php otherwise * * * vendor-dir defaults to "libs" if 'vendor' and 'package' are not defined or 'vendor' if they are. * If the library name appears to be in the form of vendor/package then we'll err towards it being a Composer package. * * @TODO If we need to work with symlinked files we may need to cobble something up from bw_trace_anonymize_symlinked_file() * */ function path_from_lib_args() { $path_array = array(); $error = null; $plugin = bw_array_get($this->args, 'plugin', null); if ($plugin) { $path_array[] = WP_PLUGIN_DIR; $path_array[] = $plugin; } elseif ($theme = bw_array_get($this->args, 'theme', null)) { $path_array[] = WP_CONTENT_DIR; $path_array[] = 'themes'; $path_array[] = $theme; } else { bw_backtrace(); $error = $this->error("parameter error", "Missing plugin/theme", $this); } if (!$error) { $vendor = $this->vendor(); $package = $this->package(); $vendor_dir = $this->vendor_dir($vendor, $package); $path_array[] = $vendor_dir; if ($vendor) { $path_array[] = $vendor; } if ($package) { $path_array[] = $package; } } $path = implode(DIRECTORY_SEPARATOR, $path_array); return $path; }
/** * Check that the plugins that this plugin is dependent upon are active * * @param string $plugin - name of the plugin being activated * @param string $dependencies - list of plugin dependencies - in whatever order you care * @param mixed $callback the callback to invoke when the dependency is not satisfied * Notes: * The list of plugins could include oik - which should be loaded UNLESS this file is being * loaded by some other mechanism. */ function oik_lazy_depends($plugin = null, $dependencies, $callback = "oik_plugin_inactive") { bw_backtrace(BW_TRACE_DEBUG); $names = bw_get_active_plugins(); bw_trace2($names, "active plugin names", true, BW_TRACE_DEBUG); $depends = explode(",", $dependencies); foreach ($depends as $dependcolver) { list($depend, $version) = explode(":", $dependcolver . ":"); //bw_trace2( $dependcolver, "dependcolver" ); //bw_trace2( $depend, "depend" ); //bw_trace2( $version, "version" ); $problem = null; $active = bw_array_get($names, $depend, null); if ($active) { $active = oik_check_version($depend, $version); if (!$active) { $problem = "version"; } } else { $problem = "missing"; } if (!$active) { bw_trace2($depend, "{$plugin} is dependent upon {$depend}, which is not active or is the wrong version", true, BW_TRACE_WARNING); if (!is_callable($callback)) { $callback = "oik_plugin_inactive"; } call_user_func($callback, $plugin, $dependcolver, $problem); //deactivate_plugins( array( $plugin ) ); } } }
/** * Implement "init" for oik-lib * * This will load the translation strings for the plugin but the shared library files may have the wrong domain. * * @TODO Decide how to deal with the domain for shared libraries * Possibly, load each library into "oik-lib" ... but how do we build/deliver the .po and .mo files? * */ function oik_lib_init() { bw_backtrace(BW_TRACE_VERBOSE); load_plugin_textdomain('oik-lib'); }
function oik_require_lib($library, $version = null, $args = null) { $library_file = null; if (function_exists("oik_libs")) { $oik_libs = oik_libs(); $library_file = $oik_libs->require_lib($library, $version, $args); } else { if ($spos = strpos($library, "/")) { $library = substr($library, $spos + 1); } $library_file = oik_require_lib_fallback($library); } // We are dependent upon the 'bwtrace' library for these functions. Assume both are defined if bw_trace2() is. if (function_exists("bw_trace2")) { bw_trace2($library_file, "library_file: {$library}", true, BW_TRACE_VERBOSE); bw_backtrace(BW_TRACE_VERBOSE); } return $library_file; }
/** * Implement "auto_update_theme" for oik-fum * * Return true if you want auto updates to be applied to the theme * * @param bool $update * @param object $item * @return bool */ function oikf_auto_update_theme($update, $item) { bw_trace2(); bw_backtrace(); gob(); }
/** * Implement "set-screen-option" for schunter * * Note: set-screen-option is called before 'admin_init' * so this filter has to be added early on, but probably only when WP_ADMIN is true. * * @param bool $setit originally false * @param string $option option name to set * @param string $value value to be set * @return $value if the option is to be set, false otherwise */ function schunter_set_screen_option($setit, $option, $value) { $isay = $setit; if ($option == 'codes_per_page') { $value = (int) $value; if ($value > 0 && $value <= 999) { $isay = $value; } } else { bw_backtrace(); } return $isay; }