Released under the terms of the GNU General Public License.
You should have received a copy of the GNU General Public License,
along with this software. In the main directory, see: /licensing/
If not, see: .
*/
/*
Direct access denial.
*/
if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
exit;
/*
Function for saving all options from any page.
*/
function ws_widget__ad_codes_update_all_options ()
{
if (($nonce = $_POST["ws_widget__ad_codes_options_save"]) && wp_verify_nonce ($nonce, "ws-widget--ad-codes-options-save"))
{
$options = $GLOBALS["WS_WIDGET__"]["ad_codes"]["o"]; /* Get current options. */
/**/
foreach ($_POST as $key => $value) /* Go through each post variable and look for ad_codes. */
{
if (preg_match ("/^" . preg_quote ("ws_widget__ad_codes", "/") . "/", $key)) /* Look for keys. */
{
if ($key === "ws_widget__ad_codes_configured") /* This is a special configuration option. */
{
update_option ("ws_widget__ad_codes_configured", trim (stripslashes ($value))); /* Update this option separately. */
/**/
$GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["configured"] = trim (stripslashes ($value)); /* Update configuration on-the-fly. */
}
else /* We need to place this option into the array. Here we remove the ws_widget__ad_codes_ portion on the beginning. */
{
(is_array ($value)) ? array_shift ($value) : null; /* Arrays should be padded, 1st key is removed. */
$options[preg_replace ("/^" . preg_quote ("ws_widget__ad_codes_", "/") . "/", "", $key)] = $value;
}
}
}
/**/
$options["options_version"] = $GLOBALS["WS_WIDGET__"]["ad_codes"]["o"]["options_version"] + 0.001; /* Increment options version. */
/**/
$options = ws_widget__ad_codes_configure_options_and_their_defaults ($options); /* Also updates the global options array. */
/**/
update_option ("ws_widget__ad_codes_options", $options); /* Update options in the database now as well. */
/**/
ws_widget__ad_codes_display_admin_notice ('Options saved.'); /* Display admin notice. */
}
/**/
return;
}
/*
Add options, details, info, etc.
Attach to: add_action("admin_menu");
*/
function ws_widget__ad_codes_add_admin_options ()
{
if (!$GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["is_wpmu_farm"])
{
add_filter ("plugin_action_links", "_ws_widget__ad_codes_add_details_link", 10, 2);
/**/
add_theme_page ("Ad Codes / Widget Information", "Ad Codes Widget", "edit_plugins", "theme-ws-widget--ad-codes-info", "ws_widget__ad_codes_info_page");
}
/**/
return;
}
/*
A sort of callback function to add the details link.
*/
function _ws_widget__ad_codes_add_details_link ($links = array (), $file = "")
{
if (preg_match ("/" . preg_quote ($file, "/") . "$/", $GLOBALS["WS_WIDGET__"]["ad_codes"]["l"]) && is_array ($links))
{
$details = 'Details';
array_unshift ($links, $details);
}
/**/
return $links;
}
/*
Add scripts to admin panels.
Attach to: add_action("admin_print_scripts");
*/
function ws_widget__ad_codes_add_admin_scripts ()
{
if ($_GET["page"] && preg_match ("/ws-widget--ad-codes-/", $_GET["page"]))
{
wp_enqueue_script ("jquery");
wp_enqueue_script ("thickbox");
wp_enqueue_script ("media-upload");
wp_enqueue_script ("ws-widget--ad-codes-menu-pages", get_bloginfo ("url") . "/?ws_widget__ad_codes_menu_pages_js=1", array ("jquery", "thickbox", "media-upload"), $GLOBALS["WS_WIDGET__"]["ad_codes"]["o"]["options_version"] . $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["filemtime"]);
}
/**/
return;
}
/*
Add styles to admin panels.
Attach to: add_action("admin_print_styles");
*/
function ws_widget__ad_codes_add_admin_styles ()
{
if ($_GET["page"] && preg_match ("/ws-widget--ad-codes-/", $_GET["page"]))
{
wp_enqueue_style ("thickbox");
wp_enqueue_style ("ws-widget--ad-codes-menu-pages", get_bloginfo ("url") . "/?ws_widget__ad_codes_menu_pages_css=1", array ("thickbox"), $GLOBALS["WS_WIDGET__"]["ad_codes"]["o"]["options_version"] . $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["filemtime"], "all");
}
/**/
return;
}
/*
Function that outputs the js for menu pages.
Attach to: add_action("init");
*/
function ws_widget__ad_codes_menu_pages_js ()
{
if ($_GET["ws_widget__ad_codes_menu_pages_js"] && is_user_logged_in () && current_user_can ("edit_plugins"))
{
header ("Content-Type: text/javascript; charset=utf-8");
header ("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate, max-age=0");
header ("Pragma: no-cache");
/**/
$u = $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["dir_url"];
$i = $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["dir_url"] . "/images";
/**/
include_once dirname (dirname (__FILE__)) . "/menu-pages/menu-pages.js";
/**/
exit;
}
}
/*
Function that outputs the css for menu pages.
Attach to: add_action("init");
*/
function ws_widget__ad_codes_menu_pages_css ()
{
if ($_GET["ws_widget__ad_codes_menu_pages_css"] && is_user_logged_in () && current_user_can ("edit_plugins"))
{
header ("Content-Type: text/css; charset=utf-8");
header ("Expires: " . gmdate ("D, d M Y H:i:s", strtotime ("-1 week")) . " GMT");
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate, max-age=0");
header ("Pragma: no-cache");
/**/
$u = $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["dir_url"];
$i = $GLOBALS["WS_WIDGET__"]["ad_codes"]["c"]["dir_url"] . "/images";
/**/
include_once dirname (dirname (__FILE__)) . "/menu-pages/menu-pages.css";
/**/
exit;
}
}
/*
Function for building the info page.
*/
function ws_widget__ad_codes_info_page ()
{
include_once dirname (dirname (__FILE__)) . "/menu-pages/info.inc.php";
/**/
return;
}
?>