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; /* This is the function for registering the widget. Attach to: add_action("widgets_init"); */ function ws_widget__ad_squares_register () { register_widget("ws_widget__ad_squares"); /**/ return; } /* The extended WP_Widget class that handles several things. */ class ws_widget__ad_squares /* < Register this widget class. */ extends WP_Widget /* See: /wp-includes/widgets.php for further details. */ { /* Constructor function. */ function ws_widget__ad_squares () /* Builds the classname, id_base, description, etc. */ { $widget_ops = array("classname" => "ad-squares", "description" => $GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["description"]); $control_ops = array("width" => $GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["control_w"], "id_base" => "ws_widget__ad_squares"); $this->WP_Widget($control_ops["id_base"], $GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["name"], $widget_ops, $control_ops); /**/ return; } /* Widget display function. This is where the widget actually does something. */ function widget ($args = FALSE, $instance = FALSE) { $options = ws_widget__ad_squares_configure_options_and_their_defaults(false, (array)$instance); /**/ echo $args["before_widget"]; /* Ok, here we go into this widget. /**/ if (strlen($options["title"])) /* If there is. */ echo $args["before_title"] . apply_filters("widget_title", $options["title"]) . $args["after_title"]; /**/ $options["code_1"] = preg_split("/\<\!--rotate--\>/", $options["code_1"]); $options["code_2"] = preg_split("/\<\!--rotate--\>/", $options["code_2"]); $options["code_3"] = preg_split("/\<\!--rotate--\>/", $options["code_3"]); $options["code_4"] = preg_split("/\<\!--rotate--\>/", $options["code_4"]); $options["code_5"] = preg_split("/\<\!--rotate--\>/", $options["code_5"]); $options["code_6"] = preg_split("/\<\!--rotate--\>/", $options["code_6"]); $options["code_7"] = preg_split("/\<\!--rotate--\>/", $options["code_7"]); $options["code_8"] = preg_split("/\<\!--rotate--\>/", $options["code_8"]); /**/ shuffle($options["code_1"]) . shuffle($options["code_2"]) . shuffle($options["code_3"]) . shuffle($options["code_4"]); shuffle($options["code_5"]) . shuffle($options["code_6"]) . shuffle($options["code_7"]) . shuffle($options["code_8"]); /**/ $codes = array (); /* Initialize the array of codes so we can push. */ /**/ if ($options["squares"] >= 2) /* Push codes 1 and 2 onto array. */ array_push($codes, $options["code_1"][0], $options["code_2"][0]); /**/ if ($options["squares"] >= 4) /* Push codes 3 and 4 onto array. */ array_push($codes, $options["code_3"][0], $options["code_4"][0]); /**/ if ($options["squares"] >= 6) /* Push codes 5 and 6 onto array. */ array_push($codes, $options["code_5"][0], $options["code_6"][0]); /**/ if ($options["squares"] >= 8) /* Push codes 7 and 8 onto array. */ array_push($codes, $options["code_7"][0], $options["code_8"][0]); /**/ if ($options["shuffle"]) /* Shuffle? ( problems w/ cache engines. ) */ shuffle ($codes); /* This way they show up differently each time. /**/ echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; /**/ if ($options["squares"] >= 2) echo '' . "\n" . /* If they have chosen to show 2 or more ad squares here. */ '' . "\n" ./**/ '' . "\n" ./**/ '' . "\n"; /**/ if ($options["squares"] >= 4) echo '' . "\n" . /* If they have chosen to show 4 or more ad squares here. */ '' . "\n" ./**/ '' . "\n" ./**/ '' . "\n"; /**/ if ($options["squares"] >= 6) echo '' . "\n" . /* If they have chosen to show 6 or more ad squares here. */ '' . "\n" ./**/ '' . "\n" ./**/ '' . "\n"; /**/ if ($options["squares"] >= 8) echo '' . "\n" . /* If they have chosen to show 8 or more ad squares here. */ '' . "\n" ./**/ '' . "\n" ./**/ '' . "\n"; /**/ echo '' . "\n"; echo '
', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[0]) : eval("?>" . trim($codes[0]))), '', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[1]) : eval("?>" . trim($codes[1]))), '
', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[2]) : eval("?>" . trim($codes[2]))), '', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[3]) : eval("?>" . trim($codes[3]))), '
', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[4]) : eval("?>" . trim($codes[4]))), '', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[5]) : eval("?>" . trim($codes[5]))), '
', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[6]) : eval("?>" . trim($codes[6]))), '', (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? trim($codes[7]) : eval("?>" . trim($codes[7]))), '
' . "\n"; echo '
' . "\n"; /**/ echo $args["after_widget"]; /**/ return; } /* Widget form control function. This is where options are made configurable. */ function form ($instance = FALSE) { $options = ws_widget__ad_squares_configure_options_and_their_defaults(false, (array)$instance); /* Ok, here is where we need to handle the widget control form. This allows a user to further customize the widget. */ echo '
' . "\n"; echo '

' . "\n"; /**/ echo '' . "\n"; echo '' . "\n"; /**/ echo '' . "\n"; echo '

' . "\n"; /**/ echo 'Paste Code Into These Squares:
' . "\n"; echo '' . "\n"; echo 'Feel free to paste any type of ad code into the squares. AdSense®, XHTML' . (($GLOBALS["WS_WIDGET__"]["ad_squares"]["c"]["is_multisite_farm"]) ? '' : ', PHP') . ', IFrame, JavaScript, whatever. The recommended size is 125x125, but it does not have to be that exact size. Just be sure to stick with the same size in each square so things remain symmetrical.' . "\n"; echo '
' . "\n"; /* Try to provide labels for each form element. */ /**/ echo '' . "\n"; echo '' . "\n"; /**/ echo '= 2) ? '' : 'none') . ';">' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; /**/ echo '= 4) ? '' : 'none') . ';">' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; /**/ echo '= 6) ? '' : 'none') . ';">' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; /**/ echo '= 8) ? '' : 'none') . ';">' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; /**/ echo '' . "\n"; echo '
'; echo '' . "\n"; echo ''; echo '' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '

' . "\n"; /**/ echo '' . "\n"; echo '
' . "\n"; /**/ echo '' . "\n"; echo 'OR: If you would like to rotate a few different ad codes ( inside a particular square ), just insert this special tag: ' . esc_html("") . ' between every ad code. In other words, one or all of your squares can contain multiple ad codes separated by this rotation tag.' . "\n"; echo '' . "\n"; /**/ echo '
' . "\n"; /**/ return; } /* Widget update function. This is where an updated instance is configured/stored. */ function update ($instance = FALSE, $old = FALSE) { return ws_widget__ad_squares_configure_options_and_their_defaults(false, (array)$instance); } } ?>