[44] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * WordPressOptionsPage.php
|
---|
| 4 | *
|
---|
| 5 | * Handles everything related to the options page
|
---|
| 6 | *
|
---|
| 7 | * Copyright (C) 2007 Eric D. Hough (http://ehough.com)
|
---|
| 8 | *
|
---|
| 9 | * This program is free software; you can redistribute it and/or
|
---|
| 10 | * modify it under the terms of the GNU General Public License
|
---|
| 11 | * as published by the Free Software Foundation; either version 2
|
---|
| 12 | * of the License, or (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * This program is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with this program; if not, write to the Free Software
|
---|
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | class WordPressOptionsPage
|
---|
| 25 | {
|
---|
| 26 | /**
|
---|
| 27 | * Prints out the advanced options. Simple!
|
---|
| 28 | */
|
---|
| 29 | function printHTML_advanced($options)
|
---|
| 30 | {
|
---|
| 31 | WordPressOptionsPage::_printHTML_optionHeader(_tpMsg("ADV_GRP_TITLE"));
|
---|
| 32 |
|
---|
| 33 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_KEYWORD, $options);
|
---|
| 34 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_TIMEOUT, $options);
|
---|
| 35 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_DEVID, $options);
|
---|
| 36 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_USERNAME, $options);
|
---|
| 37 |
|
---|
| 38 | WordPressOptionsPage::_printHTML_booleanOpt($options, TP_OPT_DEBUG, "DEBUGDESC");
|
---|
| 39 | WordPressOptionsPage::_printHTML_optionFooter();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | /**
|
---|
| 43 | * Prints out the display options. Simple!
|
---|
| 44 | */
|
---|
| 45 | function printHTML_display($options) {
|
---|
| 46 | WordPressOptionsPage::_printHTML_optionHeader(_tpMsg("VIDDISP"));
|
---|
| 47 |
|
---|
| 48 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_VIDSPERPAGE, $options);
|
---|
| 49 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_VIDWIDTH, $options);
|
---|
| 50 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_VIDHEIGHT, $options);
|
---|
| 51 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_THUMBWIDTH, $options);
|
---|
| 52 | WordPressOptionsPage::_printHTML_textBoxOption(TP_OPT_THUMBHEIGHT, $options);
|
---|
| 53 |
|
---|
| 54 | WordPressOptionsPage::_printHTML_booleanOpt($options, TP_OPT_GREYBOXON,
|
---|
| 55 | "TP_OPT_GREYBOXON_DESC");
|
---|
| 56 | WordPressOptionsPage::_printHTML_booleanOpt($options, TP_OPT_LWON,
|
---|
| 57 | "TP_OPT_LWON_DESC");
|
---|
| 58 |
|
---|
| 59 | WordPressOptionsPage::_printHTML_optionFooter();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | function _printHTML_booleanOpt($options, $optName, $msg) {
|
---|
| 63 | $selected = "";
|
---|
| 64 | if ($options->getValue($optName) == true) {
|
---|
| 65 | $selected = "CHECKED";
|
---|
| 66 | }
|
---|
| 67 | printf('<tr valign="top"><th style="font-weight: bold; font-size: 1em" scope="row">' .
|
---|
| 68 | '%s</th><td><input type="checkbox" name="%s" value="%s" %s /><br />%s</td>',
|
---|
| 69 | $options->getTitle($optName), $optName, $optName, $selected,
|
---|
| 70 | _tpMsg("$msg"));
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | * Prints out the drop down menu asking where to play the videos
|
---|
| 75 | * (normally, new window, popup, in youtube, etc.)
|
---|
| 76 | */
|
---|
| 77 | function printHTML_player($options) {
|
---|
| 78 | $locationVars = $options->getPlayerLocationNames();
|
---|
| 79 |
|
---|
| 80 | WordPressOptionsPage::_printHTML_optionHeader("");
|
---|
| 81 |
|
---|
| 82 | printf('<tr> <th style="font-weight: bold; font-size: 1em">%s</th>',
|
---|
| 83 | $options->getTitle(TP_OPT_PLAYIN));
|
---|
| 84 | printf('<td><select name="%s">', TP_OPT_PLAYIN);
|
---|
| 85 |
|
---|
| 86 | foreach ($locationVars as $location) {
|
---|
| 87 | $selected = "";
|
---|
| 88 | if ($location == $options->getValue(TP_OPT_PLAYIN))
|
---|
| 89 | $selected = "selected";
|
---|
| 90 | $inputBox = "";
|
---|
| 91 |
|
---|
| 92 | $desc = "";
|
---|
| 93 | switch ($location) {
|
---|
| 94 | case TP_PLAYIN_NORMAL:
|
---|
| 95 | $desc = _tpMsg("PLAYIN_NORMAL_TITLE");
|
---|
| 96 | break;
|
---|
| 97 | case TP_PLAYIN_NW:
|
---|
| 98 | $desc = _tpMsg("PLAYIN_NW_TITLE");
|
---|
| 99 | break;
|
---|
| 100 | case TP_PLAYIN_YT:
|
---|
| 101 | $desc = _tpMsg("PLAYIN_YT_TITLE");
|
---|
| 102 | break;
|
---|
| 103 | case TP_PLAYIN_POPUP:
|
---|
| 104 | $desc = _tpMsg("PLAYIN_POPUP_TITLE");
|
---|
| 105 | break;
|
---|
| 106 | case TP_PLAYIN_LWINDOW:
|
---|
| 107 | $desc = _tpMsg("PLAYIN_LW_TITLE");
|
---|
| 108 | break;
|
---|
| 109 | case TP_PLAYIN_GREYBOX:
|
---|
| 110 | $desc = _tpMsg("PLAYIN_TB_TITLE");
|
---|
| 111 | break;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | printf('<option value="%s" %s>%s</option>', $location, $selected, $desc);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | echo "</select></td></tr>";
|
---|
| 119 |
|
---|
| 120 | WordPressOptionsPage::_printHTML_optionFooter();
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | /**
|
---|
| 126 | * Prints out the meta value checkboxes. Fascinating stuff here!
|
---|
| 127 | */
|
---|
| 128 | function printHTML_meta($options)
|
---|
| 129 | {
|
---|
| 130 | WordPressOptionsPage::_printHTML_optionHeader(_tpMsg("META"));
|
---|
| 131 |
|
---|
| 132 | $metas = TubePressVideo::getMetaNames();
|
---|
| 133 |
|
---|
| 134 | echo "<tr><td width='10%'></td><td><table cellspacing='0' " .
|
---|
| 135 | "cellpadding='0' width='100%'>";
|
---|
| 136 |
|
---|
| 137 | $colIterator = 0;
|
---|
| 138 | foreach ($metas as $meta) {
|
---|
| 139 |
|
---|
| 140 | $colCount = $colIterator % 5;
|
---|
| 141 |
|
---|
| 142 | $selected = "";
|
---|
| 143 | if ($options->getValue($meta) == true) {
|
---|
| 144 | $selected = "CHECKED";
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | if ($colCount == 0) {
|
---|
| 148 | echo "<tr>";
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | printf('<td><input type="checkbox" name="meta[]" value="%s" %s />' .
|
---|
| 152 | '</td><td><b>%s</b></td>',
|
---|
| 153 | $meta, $selected,
|
---|
| 154 | $options->getTitle($meta));
|
---|
| 155 |
|
---|
| 156 | if ($colCount == 4) {
|
---|
| 157 | echo "</tr>";
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | $colIterator++;
|
---|
| 161 | }
|
---|
| 162 | echo "</tr></table>";
|
---|
| 163 |
|
---|
| 164 | WordPressOptionsPage::_printHTML_optionFooter();
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * Prints out the mode options. Simple!
|
---|
| 171 | */
|
---|
| 172 | function printHTML_modes($options)
|
---|
| 173 | {
|
---|
| 174 | WordPressOptionsPage::_printHTML_optionHeader(_tpMsg("MODE_HEADER"));
|
---|
| 175 |
|
---|
| 176 | $modes = TubePressOptionsPackage::getModeNames();
|
---|
| 177 |
|
---|
| 178 | foreach ($modes as $mode) {
|
---|
| 179 | if ($mode == TP_MODE_REL) {
|
---|
| 180 | continue;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | $selected = "";
|
---|
| 184 |
|
---|
| 185 | if ($mode == $options->getValue(TP_OPT_MODE)) {
|
---|
| 186 | $selected = "CHECKED";
|
---|
| 187 | }
|
---|
| 188 | $inputBox = "";
|
---|
| 189 |
|
---|
| 190 | /* The idea here is only the "featured" mode doesn't need any kind of input */
|
---|
| 191 | if ($mode != TP_MODE_FEATURED) {
|
---|
| 192 | $inputBox = WordPressOptionsPage::_printHTML_quickSrchVal($mode,
|
---|
| 193 | $options, 20);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /* handle the "popular" mode */
|
---|
| 197 | if ($mode == TP_MODE_POPULAR) {
|
---|
| 198 |
|
---|
| 199 | $name = TP_OPT_POPVAL;
|
---|
| 200 | $inputBox = sprintf('<select name="%s">', $name);
|
---|
| 201 | $period = array("day", "week", "month");
|
---|
| 202 | foreach ($period as $thisPeriod) {
|
---|
| 203 | $inputBox .= sprintf('<option value="%s"', $thisPeriod);
|
---|
| 204 | if ($thisPeriod == $options->getValue(TP_OPT_POPVAL)) {
|
---|
| 205 | $inputBox .= ' SELECTED';
|
---|
| 206 | }
|
---|
| 207 | $inputBox .= sprintf('>%s</option>', $thisPeriod);
|
---|
| 208 | }
|
---|
| 209 | $inputBox .= '</select>';
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | $title = "";
|
---|
| 213 | $desc = "";
|
---|
| 214 |
|
---|
| 215 | switch($mode) {
|
---|
| 216 | case TP_MODE_POPULAR:
|
---|
| 217 | $title = _tpMsg("MODE_POPULAR_TITLE");
|
---|
| 218 | break;
|
---|
| 219 | case TP_MODE_FEATURED:
|
---|
| 220 | $title = _tpMsg("MODE_FEAT_TITLE");
|
---|
| 221 | break;
|
---|
| 222 | case TP_MODE_FAV:
|
---|
| 223 | $title = _tpMsg("MODE_FAV_TITLE");
|
---|
| 224 | $desc = _tpMsg("MODE_FAV_DESC");
|
---|
| 225 | break;
|
---|
| 226 | case TP_MODE_PLST:
|
---|
| 227 | $title = _tpMsg("MODE_PLST_TITLE");
|
---|
| 228 | $desc = _tpMsg("MODE_PLST_DESC");
|
---|
| 229 | break;
|
---|
| 230 | case TP_MODE_TAG:
|
---|
| 231 | $title = _tpMsg("MODE_TAG_TITLE");
|
---|
| 232 | break;
|
---|
| 233 | case TP_MODE_USER:
|
---|
| 234 | $title = _tpMsg("MODE_USER_TITLE");
|
---|
| 235 | break;
|
---|
| 236 | default:
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | printf('<tr><th style="font-weight: bold; font-size: 1em" valign="top">%s</th>' .
|
---|
| 240 | '<td><input type="radio" name="%s" id="%s" value="%s" %s /> %s <br />%s</td></tr>',
|
---|
| 241 | $title, TP_OPT_MODE, $mode, $mode, $selected, $inputBox,
|
---|
| 242 | $desc);
|
---|
| 243 | }
|
---|
| 244 | echo "<sup>*</sup><i>mode supports pagination</i>";
|
---|
| 245 | WordPressOptionsPage::_printHTML_optionFooter();
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | /**
|
---|
| 249 | * Prints out the success or failure message after updating
|
---|
| 250 | */
|
---|
| 251 | function printStatusMsg($msg, $cssClass)
|
---|
| 252 | {
|
---|
| 253 | printf('<div id="message" class="%s"><p><strong>%s</strong></p></div>',
|
---|
| 254 | $cssClass, $msg);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /**
|
---|
| 258 | * Go through all the post variables and update the corresponding
|
---|
| 259 | * database entries.
|
---|
| 260 | */
|
---|
| 261 | function update()
|
---|
| 262 | {
|
---|
| 263 | $errors = false;
|
---|
| 264 |
|
---|
| 265 | /* get what we have in the db */
|
---|
| 266 | $oldOpts = new WordPressOptionsPackage();
|
---|
| 267 | if (PEAR::isError($oldOpts)) {
|
---|
| 268 | WordPressOptionsPage::printStatusMsg($oldOpts->message, TP_CSS_FAILURE);
|
---|
| 269 | return;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | /* go through the post variables and try to update */
|
---|
| 273 | foreach (array_keys($oldOpts->_allOptions) as $optName) {
|
---|
| 274 | if (($optName == TP_OPT_DEBUG)
|
---|
| 275 | || ($optName == TP_OPT_GREYBOXON)
|
---|
| 276 | || ($optName == TP_OPT_LWON)
|
---|
| 277 | || in_array($optName, TubePressVideo::getMetaNames())
|
---|
| 278 | || in_array($optName, TubePressOptionsPackage::getPlayerLocationNames())
|
---|
| 279 | || in_array($optName, TubePressOptionsPackage::getModeNames())) {
|
---|
| 280 | continue;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | $result = $oldOpts->setValue($optName, $_POST[$optName]);
|
---|
| 284 |
|
---|
| 285 | if (PEAR::isError($result)) {
|
---|
| 286 | $errors = true;
|
---|
| 287 | WordPressOptionsPage::printStatusMsg($result->message, TP_CSS_FAILURE);
|
---|
| 288 | return;
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | /* Do the booleans */
|
---|
| 293 | $metaOptions = TubePressVideo::getMetaNames();
|
---|
| 294 | foreach ($metaOptions as $metaOption) {
|
---|
| 295 | if (!WordPressOptionsPage::_updateBoolean($metaOption, $oldOpts, $errors,
|
---|
| 296 | in_array($metaOption, $_POST['meta']))) {
|
---|
| 297 | return;
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | if (!WordPressOptionsPage::_updateBoolean(TP_OPT_DEBUG, $oldOpts,
|
---|
| 302 | $errors, isset($_POST[TP_OPT_DEBUG]))) {
|
---|
| 303 | return;
|
---|
| 304 | }
|
---|
| 305 | if (!WordPressOptionsPage::_updateBoolean(TP_OPT_GREYBOXON, $oldOpts,
|
---|
| 306 | $errors, isset($_POST[TP_OPT_GREYBOXON]))) {
|
---|
| 307 | return;
|
---|
| 308 | }
|
---|
| 309 | if (!WordPressOptionsPage::_updateBoolean(TP_OPT_LWON, $oldOpts,
|
---|
| 310 | $errors, isset($_POST[TP_OPT_LWON]))) {
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | /* now actually update is we didn't have any errors */
|
---|
| 315 | if (!$errors) {
|
---|
| 316 | update_option(TP_OPTION_NAME, $oldOpts->_allOptions);
|
---|
| 317 | } else {
|
---|
| 318 | return;
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | /* make sure the store happened */
|
---|
| 322 | $oldOpts = new WordPressOptionsPackage();
|
---|
| 323 | if (PEAR::isError($oldOpts)) {
|
---|
| 324 | WordPressOptionsPage::printStatusMsg($oldOpts->msg, TP_CSS_FAILURE);
|
---|
| 325 | } else {
|
---|
| 326 | WordPressOptionsPage::printStatusMsg(_tpMsg("OPTSUCCESS"), TP_CSS_SUCCESS);
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | function _updateBoolean($optName, &$options, &$errors, $newValue) {
|
---|
| 331 | $result = $options->setValue($optName, $newValue);
|
---|
| 332 | if (PEAR::isError($result)) {
|
---|
| 333 | $errors = true;
|
---|
| 334 | WordPressOptionsPage::printStatusMsg($result->message, TP_CSS_FAILURE);
|
---|
| 335 | return false;
|
---|
| 336 | }
|
---|
| 337 | return true;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | /**
|
---|
| 341 | * Spits out a bit of HTML at the bottom of each option group
|
---|
| 342 | */
|
---|
| 343 | function _printHTML_optionFooter() {
|
---|
| 344 | echo "</table></fieldset>";
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | /**
|
---|
| 348 | * Spits out a bit of HTML at the top of each option group
|
---|
| 349 | */
|
---|
| 350 | function _printHTML_optionHeader($arrayName)
|
---|
| 351 | {
|
---|
| 352 | echo "<fieldset>";
|
---|
| 353 |
|
---|
| 354 | if ($arrayName != "") {
|
---|
| 355 | printf('<h3>%s</h3>', $arrayName);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | echo '<table class="editform optiontable">';
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | /**
|
---|
| 362 | * Prints out the HTML inputs for determining which videos to play
|
---|
| 363 | * (all tags, any tags, etc.). This is really a helper function
|
---|
| 364 | * for printHTML_searchArray()
|
---|
| 365 | */
|
---|
| 366 | function _printHTML_quickSrchVal($mode, $options, $inputSize)
|
---|
| 367 | {
|
---|
| 368 | $whichValue = "";
|
---|
| 369 |
|
---|
| 370 | switch ($mode) {
|
---|
| 371 |
|
---|
| 372 | case TP_MODE_TAG:
|
---|
| 373 | $whichValue = TP_OPT_TAGVAL;
|
---|
| 374 | $inputSize = 40;
|
---|
| 375 | break;
|
---|
| 376 |
|
---|
| 377 | case TP_MODE_USER:
|
---|
| 378 | $whichValue = TP_OPT_USERVAL;
|
---|
| 379 | break;
|
---|
| 380 |
|
---|
| 381 | case TP_MODE_PLST:
|
---|
| 382 | $whichValue = TP_OPT_PLSTVAL;
|
---|
| 383 | break;
|
---|
| 384 |
|
---|
| 385 | case TP_MODE_POPULAR:
|
---|
| 386 | $whichValue = TP_OPT_POPVAL;
|
---|
| 387 | break;
|
---|
| 388 |
|
---|
| 389 | case TP_MODE_CATEGORY:
|
---|
| 390 | $whichValue = TP_OPT_CATVAL;
|
---|
| 391 | break;
|
---|
| 392 |
|
---|
| 393 | case TP_MODE_FAV:
|
---|
| 394 | $whichValue = TP_OPT_FAVVAL;
|
---|
| 395 | break;
|
---|
| 396 | }
|
---|
| 397 | return sprintf('<input type="text" name="%s" size="%s" value="%s" />',
|
---|
| 398 | $whichValue, $inputSize, $options->getValue($whichValue));
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | /**
|
---|
| 402 | * Helper function to spit out a textbox input
|
---|
| 403 | */
|
---|
| 404 | function _printHTML_textBoxOption($optionName, $options) {
|
---|
| 405 | $openBracket = "";
|
---|
| 406 | $closeBracket = "";
|
---|
| 407 | if ($optionName == TP_OPT_KEYWORD) {
|
---|
| 408 | $openBracket = '[';
|
---|
| 409 | $closeBracket = ']';
|
---|
| 410 | }
|
---|
| 411 | printf('<tr valign="top"><th style="font-weight: bold; font-size: 1em" scope="row">' .
|
---|
| 412 | '%s</th><td>%s<input name="%s" type="text" id="%s" class="code" value="%s" ' .
|
---|
| 413 | 'size="%s" />%s<br />%s</td></tr>',
|
---|
| 414 | $options->getTitle($optionName), $openBracket,
|
---|
| 415 | $optionName, $optionName,
|
---|
| 416 | $options->getValue($optionName), 20, $closeBracket,
|
---|
| 417 | $options->getDescription($optionName)
|
---|
| 418 | );
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | ?>
|
---|