PageRenderTime 70ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/blog/wp-content/themes/prophoto2/functions/options.php

https://github.com/amoslanka/dartphotographie.com
PHP | 828 lines | 629 code | 117 blank | 82 comment | 131 complexity | e1c1bc8504b2fd70c49944f23f493e86 MD5 | raw file
  1. <?php
  2. /*
  3. Library of functions used in the "Manage Options" page
  4. */
  5. /* Draws each upload form component */
  6. function p2_option_box ($name, $params, $title = '', $comment = '', $groupkey = '') {
  7. global $p2, $p2_option_name_debug;
  8. if ( !$title ) $title = $name;
  9. extract( p2_option_box_data($name, $params, $title, $comment ) ); ?>
  10. <div id="<?php echo $name; ?>-option-section" class="self-clear option-section"<?php p2_ux_display($name, false, 'section' ); ?>>
  11. <?php p2_click_for_explain( $name ); ?>
  12. <div class="option-section-label">
  13. <?php echo $title; ?>
  14. <?php if ( $p2_option_name_debug ) echo "<br /><h3 class='debug'><span>$name</span></h3>"; ?>
  15. </div>
  16. <div id="<?php echo $name; ?>-individual-option" class="individual-option not-multiple">
  17. <?php p2_extra_explain( $name )?>
  18. <?php p2_add_inline_banner_image( $name ); ?>
  19. <?php echo $input; ?>
  20. <?php echo "<p>$comment</p>"; ?>
  21. </div>
  22. </div> <!-- .option-section --><?php
  23. }
  24. /* creates clickable "show/hide" title for advanced options */
  25. function p2_advanced_option_title ($title, $groupkey, $speed = '1000', $is_bottom = false, $db_test = '', $db_test_result = '', $more = 'more') {
  26. global $p2;
  27. if ( p2_test('show_hidden', 'show') ) { ?>
  28. <div id="<?php echo 'aot-' .$groupkey; ?>" class="self-clear option-section hidden-title">
  29. <div class="individual-option" style="padding-top:9px"><a style="float:right; margin-right:8px;"><?php echo $more; ?> <?php echo $title; ?> options <span class="aot-view">&darr;</span></a></div>
  30. </div>
  31. <?php } else {
  32. ?>
  33. <div id="<?php echo 'aot-' .$groupkey; ?>" class="self-clear option-section hidden-title"<?php if (($db_test) && (p2_option($db_test,0) == $db_test_result)) echo ' style="display:none;"'; ?>>
  34. <div class="individual-option" style="padding-top:9px"><a onclick="javascript:jQuery('.hidden-option-<?php echo $groupkey; ?>').slideToggle(<?php echo $speed; ?>); jQuery('#aot-<?php echo $groupkey; ?>').toggleClass('shown');" style="float:right; margin-right:8px; cursor:pointer;">Click to <span class="aot-view">view</span><span class="aot-hide">hide</span> <?php echo $more; ?> <?php echo $title; ?> options <span class="aot-view">&darr;</span><span class="aot-hide">&uarr;</span></a></div>
  35. </div><?php
  36. }
  37. echo '<div class="hidden-option-'. $groupkey .' hidden-option">';
  38. }
  39. /* closes out the div that gets animated for hidden options, adds an optional hide link */
  40. function p2_end_advanced_option() {
  41. echo '</div>';
  42. }
  43. /* creates a white row to use as a visual divider and echo block weight (num of fiels) if applicable */
  44. function p2_option_spacer ($weight_before=0) {
  45. // this sux, i know
  46. if (p2_debug() && $weight_before != 0) {
  47. global $p2_form_weight;
  48. $weight_after = $p2_form_weight;
  49. echo "<b style='color:#f99'>Number of fields in this block: ".($weight_after - $weight_before)."</b>";
  50. }
  51. echo '<div class="spacer"></div></div>';
  52. }
  53. /* creates a title header for option sections */
  54. function p2_option_header($title, $id, $comment="") {
  55. $display = ' style="display:none;"';
  56. //if ($id == 'general') $display = '';
  57. echo <<<HTML
  58. <div id="tab-section-$id-link" class="tabbed-sections"$display>
  59. <div class="self-clear header options-grouping-header" name="$id-link">
  60. <span class="option-section-label">$title</span>
  61. <span class="individual-option">$comment</span>
  62. </div>
  63. HTML;
  64. }
  65. /* adds "display:none" where appropriate after querying options */
  66. function p2_ux_display( $index, $hide_font, $type = "individual" ) {
  67. if ( $hide_font ) {
  68. echo ' style="display:none;"';
  69. return;
  70. }
  71. global $options_ux;
  72. if ( !$options_ux['display'][$type][$index] ) return;
  73. $params = explode( '*', $options_ux['display'][$type][$index] );
  74. // if we have a third parameter, which reverses the function
  75. if ( $params[2] ) {
  76. if ( !p2_test( $params[0], $params[1] ) ) echo ' style="display:none;"';
  77. return;
  78. }
  79. // only two parameters, standard test
  80. if ( $params[1] ) {
  81. if ( p2_test( $params[0], $params[1] ) ) echo ' style="display:none;"';
  82. } else {
  83. // only one parameter, just check for existence
  84. if ( !p2_test( $params[0] ) ) echo ' style="display:none;"';
  85. }
  86. }
  87. /* adds special classes for font/link options, used by jquery font preview */
  88. // TODO: make this suck less, so as not to incur the scorn of Ozh
  89. function p2_font_option_addclass( $name, $hide_font ) {
  90. global $preview_options;
  91. for ( $i = 0; $i <= 11; $i++ ) {
  92. if ( strpos( $name, $preview_options['name'][$i] ) !== false ) {
  93. echo $preview_options['class'][$i];
  94. $break = true;
  95. }
  96. if ( $break ) break;
  97. }
  98. if ( $hide_font ) echo " hidden-font-link-option";
  99. }
  100. /*adds class to multiple individual options for jquery and font preview */
  101. function p2_ux_addclass( $name, $hide_font = false, $one_column = false ) {
  102. global $options_ux; $not_found = true;
  103. if ( ( strpos( $name, '_font_' ) !== false ) || ( strpos( $name, '_link_' ) !== false ) || ( strpos( $name, '_transform' ) !== false ) || ( strpos( $name, '_line_height' ) !== false ) || ( strpos( $name, 'gen_margin_below' ) !== false ) ) {
  104. p2_font_option_addclass( $name, $hide_font );
  105. return;
  106. }
  107. if ( $one_column ) echo " onecolumn";
  108. if ( !$options_ux['addclass'][$name] ) return;
  109. echo " a";
  110. echo $options_ux['addclass'][$name];
  111. echo "shg"; // stands for "show/hide group" :)
  112. }
  113. /* adds class to font and link group sections */
  114. function p2_font_preview_add_section_class( $name ) {
  115. if ( strpos( $name, '_link_font_') !== false ) {
  116. echo " link-group";
  117. return true;
  118. }
  119. if ( strpos( $name, '_font_') !== false ) {
  120. echo " font-group";
  121. return true;
  122. }
  123. // other areas that get preview areas
  124. if ( strpos( 'nav_bg_color', $name) !== false ) {
  125. echo " link-group";
  126. return true;
  127. }
  128. return false;
  129. }
  130. /* adds in a contextually appropriate font preview test section, if appliciable */
  131. function p2_font_preview( $name ) {
  132. global $preview_options;
  133. if ( $preview_options['preview'][$name] ) {
  134. $content = $preview_options['preview'][$name];
  135. echo "<div class='font-preview-wrapper'><div class='font-preview-spacer'><div class='font-preview' id='$name-font-preview'>$content</div></div></div>";
  136. }
  137. }
  138. /* add a "LIVE PREVIEW" button, if applicable */
  139. function p2_live_preview_button( $name ) {
  140. global $preview_options;
  141. if ( $preview_options['preview'][$name] ) {
  142. echo "<br /><a class='live-preview-button' id='$name-lpb'></a>";
  143. }
  144. }
  145. /* A multiple-input section of certain peril */
  146. function p2_multiple_option_box($name, $params, $title = '', $comment = '', $firstlast = '', $hide_font = false, $one_column = false) {
  147. global $p2, $counter, $p2_option_name_debug;
  148. if (!$title) $title = $name;
  149. // add crappy inline style TODO: make this not suck
  150. p2_suxorz( $name );
  151. // extract the normal stuff
  152. extract( p2_option_box_data( $name, $params, $title, $comment ) );
  153. if ($firstlast == 'first') {
  154. // this is the first multiple option, so reset the counter
  155. $counter = 1;
  156. ?>
  157. <div id="<?php echo $name; ?>-option-section" class="self-clear option-section<?php $preview = p2_font_preview_add_section_class( $name ); ?>"<?php p2_ux_display($name, $hide_font, 'section' ); ?>>
  158. <?php p2_click_for_explain( $name ); ?>
  159. <div class="option-section-label">
  160. <?php echo $title; ?>
  161. <?php if ( $preview ) p2_live_preview_button( $name ); ?>
  162. <?php if ( $p2_option_name_debug ) echo "<br /><h3 class='debug'><span>$name</span></h3>"; ?>
  163. </div>
  164. <div class="multiple-option-table-wrapper">
  165. <?php p2_extra_explain( $name, true )?>
  166. <table class="multiple-option-table">
  167. <?php if ( $preview ) p2_font_preview( $name ); ?>
  168. <?php }
  169. // counter is odd? that means we start a row
  170. if ($counter & 1) echo "<tr>\n";
  171. ?>
  172. <td>
  173. <div id="<?php echo $name; ?>-individual-option" class="individual-option individual-option-multiple<?php p2_ux_addclass($name, $hide_font, $one_column);?>"<?php p2_ux_display( $name, $hide_font ); ?>><?php if ( $p2_option_name_debug ) echo "<br /><h3 class='debug'><span>$name</span></h3>"; ?>
  174. <?php p2_add_inline_banner_image( $name ); ?>
  175. <div class="iehelper"><?php echo $input; ?></div>
  176. <?php echo "<p>$comment</p>"; ?>
  177. </div>
  178. </td>
  179. <?php
  180. if ( ($counter & 0) || $one_column ) echo "</tr>\n";
  181. // done with the multiple option table/div, increment the counter
  182. $counter++;
  183. // close things up if we're done with the set
  184. if ($firstlast == 'last') echo "</table></div><!-- .individual-option -->\n</div><!-- .option-section -->\n";
  185. return $counter;
  186. } // end function p2_multiple_option_box();
  187. /* prints all the options for styling fonts */
  188. function p2_font_options($title, $key, $paragraph = '', $color_optional = false) {
  189. // conditional items
  190. $optional_comment = $optional = '';
  191. $span = '';
  192. $cspan = '';
  193. $font_comment = 'select your font';
  194. if ( $color_optional ) {
  195. $optional = '|optional';
  196. $optional_comment = 'override inherited ';
  197. $font_comment = 'override the inherited font';
  198. $span = '<span class="color-optional">';
  199. $cspan = '</span>';
  200. }
  201. $last = 'last';
  202. if ( $paragraph ) $last = '';
  203. p2_multiple_option_box($key."_font_family", 'select||select...|Arial, Helvetica, sans-serif|Arial|Times, Georgia, serif|Times|Verdana, Tahoma, sans-serif|Verdana|"Century Gothic", Helvetica, Arial, sans-serif|Century Gothic|Helvetica, Arial, sans-serif|Helvetica|Georgia, Times, serif|Georgia|"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif|Lucida Grande|Palatino, Georgia, serif|Palatino|Garamond, Palatino, Georgia, serif|Garamond|Tahoma, Verdana, Helvetica, sans-serif|Tahoma|Courier, monospace|Courier|"Trebuchet MS", Tahoma, Helvetica, sans-serif|Trebuchet MS|"Comic Sans MS", Arial, sans-serif|Comic Sans MS|Bookman, Palatino, Georgia, serif|Bookman', $title, $font_comment, 'first');
  204. p2_multiple_option_box($key."_font_size", "text|3", '', $optional_comment . 'font size (in pixels)');
  205. p2_multiple_option_box($key."_font_color", 'color' . $optional, '', $span . $optional_comment . 'font color' . $cspan );
  206. p2_multiple_option_box($key."_font_weight", 'select||select...|400|normal|700|bold', '', $optional_comment . 'font weight (bold/normal)', '', true);
  207. p2_multiple_option_box($key."_font_style", 'select||select...|normal|normal|italic|italic', '', $optional_comment . 'font style', '', true);
  208. p2_multiple_option_box($key."_text_transform", 'select||select...|none|Normal|uppercase|UPPERCASE|lowercase|lowercase', '', $optional_comment . 'text effect', $last, true);
  209. if ( $paragraph ) {
  210. if ( $paragraph == 'paragraphs') {
  211. p2_multiple_option_box($key.'_line_height', 'select||select...|1.0|single|1.25|1.25|1.5|1.5|1.75|1.75|2.0|double|2.25|2.25|2.5|2.5', '', $optional_comment . 'spacing between lines', '', true);
  212. }
  213. p2_multiple_option_box($key.'_margin_below', 'text|3', '', $optional_comment . 'margin (in pixels) below ' . $paragraph, 'last', true);
  214. }
  215. echo "<a class='font-link-more-options'></a>";
  216. } // end function p2_font_options
  217. /* prints all the options for styling a link */
  218. function p2_link_options( $title, $key, $extra_option = '', $add_nonlink_font_color = false, $color_optional = false, $extras = '', $skip_visited = false ) {
  219. $optional_comment = $optional = '';
  220. $font_comment = 'select your link font';
  221. $span = '';
  222. $cspan = '';
  223. if ( $color_optional ) {
  224. $span = '<span class="color-optional">';
  225. $cspan = '</span>';
  226. $optional = '|optional';
  227. $optional_comment = 'override inherited ';
  228. $font_comment = 'override the inherited link font';
  229. }
  230. // $extra allows for an extra, non-standard option to be passed to the function
  231. if ( $extra_option ) $params = explode( '*', $extra_option );
  232. p2_multiple_option_box($key."_link_font_size", "text|3", $title, $optional_comment . 'link font size (in pixels)', 'first', $extras);
  233. p2_multiple_option_box($key."_link_font_family", 'select||select...|Arial, Helvetica, sans-serif|Arial|Times, Georgia, serif|Times|Verdana, Tahoma, sans-serif|Verdana|"Century Gothic", Helvetica, Arial, sans-serif|Century Gothic|Helvetica, Arial, sans-serif|Helvetica|Georgia, Times, serif|Georgia|"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif|Lucida Grande|Palatino, Georgia, serif|Palatino|Garamond, Palatino, Georgia, serif|Garamond|Tahoma, Verdana, Helvetica, sans-serif|Tahoma|Courier, monospace|Courier|"Trebuchet MS", Tahoma, Helvetica, sans-serif|Trebuchet MS|"Comic Sans MS", Arial, sans-serif|Comic Sans MS|Bookman, Palatino, Georgia, serif|Bookman', '', $font_comment);
  234. if ( $add_nonlink_font_color ) p2_multiple_option_box($key.'_nonlink_font_color', 'color' . $optional, '', $span . $optional_comment . 'font color (non-link)' . $cspan );
  235. p2_multiple_option_box($key."_link_font_color", 'color' . $optional, '', $span . $optional_comment . 'link font color' . $cspan );
  236. if ( $extra_option ) p2_multiple_option_box($params[0],$params[1],$params[2], $optional_comment . $params[3],'', '');
  237. if ( !$skip_visited ) {
  238. p2_multiple_option_box($key."_link_visited_font_color", 'color|optional', '', '<span class="color-optional">set unique font color after link has been visited</span>', '', true);
  239. }
  240. p2_multiple_option_box($key."_link_hover_font_color", 'color' . $optional, '', $span . $optional_comment . 'link font color when being hovered over' . $cspan, '', true);
  241. p2_multiple_option_box($key."_link_font_style", 'select||select...|normal|normal|italic|italic', '', 'link font style', '', true);
  242. p2_multiple_option_box($key.'_link_decoration', 'select||select...|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '','normal appearance of link', '', true);
  243. p2_multiple_option_box($key.'_link_hover_decoration', 'select||select...|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '', $optional_comment . 'appearance of link when being hovered over', '', true);
  244. p2_multiple_option_box($key.'_link_text_transform', 'select||select...|none|Normal|uppercase|UPPERCASE|lowercase|lowercase', '', $optional_comment . 'link text effect', 'last', true);
  245. echo "<a class='font-link-more-options'></a>";
  246. } // end function p2_link_options
  247. /* prints a stripped down menu of link options */
  248. function p2_link_mini_options( $title, $key, $color_optional = true) {
  249. $optional_comment = $optional = '';
  250. $font_comment = 'select your link font';
  251. $span = '';
  252. $cspan = '';
  253. if ( $color_optional ) {
  254. $span = '<span class="color-optional">';
  255. $cspan = '</span>';
  256. $optional = '|optional';
  257. $optional_comment = 'override inherited ';
  258. $font_comment = 'override the inherited link font';
  259. }
  260. p2_multiple_option_box($key."_link_font_color", 'color' . $optional, $title, $span . $optional_comment . 'link font color' . $cspan, 'first' );
  261. p2_multiple_option_box($key."_link_visited_font_color", 'color' . $optional, '', $span . $optional_comment . 'link font color after being visited' . $cspan);
  262. p2_multiple_option_box($key."_link_hover_font_color", 'color' . $optional, '', $span . $optional_comment . 'link font color when being hovered over' . $cspan, '', true);
  263. p2_multiple_option_box($key.'_link_decoration', 'select||select...|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '','normal appearance of link', '', true);
  264. p2_multiple_option_box($key.'_link_hover_decoration', 'select||select...|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '', $optional_comment . 'appearance of link when being hovered over', 'last', true);
  265. echo "<a class='font-link-more-options'></a>";
  266. } // end function p2_link_options
  267. /* creates the opening tag of a conditional group of options */
  268. function p2_conditional_option_group($id, $option, $option_test) {
  269. echo '<div class="conditional-option-group" id="' . $id . '-cog"';
  270. if ( p2_test( $option, $option_test ) ) echo ' style="display:none;"';
  271. echo '>';
  272. }
  273. /* print the bio text options in all their jQuery and UX wizardry */
  274. function p2_biotext_option_box($which = 1) {
  275. if ($which == 1) {
  276. $option = 'bioheader2';
  277. $class = 'a013shg';
  278. $one = '1';
  279. $two = '2';
  280. $msg = '';
  281. $hidden = 'b2';
  282. $id = '';
  283. } else {
  284. $option = 'bioheader4';
  285. $class = 'a014shg';
  286. $one = '3';
  287. $two = '4';
  288. $msg = ' -- second column';
  289. $hidden = 'b4';
  290. $id = 'bio-second-column';
  291. }
  292. if ( p2_option( $option, 0 ) == '' ) {
  293. $reveal_hidden = '<br /><br />Want another header and text area beneath it in this column? &nbsp;<a onclick="javascript:jQuery(\'.' . $class . '\').slideToggle(200)" style="cursor:pointer;">click here &darr;</a>';
  294. $hide = '';
  295. } else {
  296. $reveal_hidden = '';
  297. $hide = 'hide';
  298. }
  299. $comment = 'the text of your bio area' . $msg . $reveal_hidden;
  300. p2_multiple_option_box('bioheader'.$one, 'text|40', 'Bio area text'.$msg, 'the headline in your bio area' . $msg, 'first', '', true);
  301. p2_multiple_option_box('biopara'.$one, 'textarea|9|74', 'Bio Paragraph 1', $comment, '', '', true);
  302. p2_multiple_option_box('bioheader'.$two, 'text|40', 'Bio area text', 'the second headline in your bio area' . $msg, '', '', true);
  303. p2_multiple_option_box('biopara'.$two, 'textarea|9|74', 'Bio Paragraph 1', 'the second text area of your bio area' . $msg, 'last', '', true);
  304. } // end function p2_biotext_option_box
  305. /* Color picker CSS in the head */
  306. function p2_options_head() {
  307. echo '<link href="'.get_bloginfo('template_directory').'/adminpages/colorpicker/farbtastic.css" rel="stylesheet" type="text/css" />'."\n";
  308. echo '<link href="'.get_bloginfo('template_directory').'/adminpages/css/common.css?05" rel="stylesheet" type="text/css" />'."\n";
  309. echo '<link href="'.get_bloginfo('template_directory').'/adminpages/css/options.css?05" rel="stylesheet" type="text/css" />'."\n";
  310. echo '<link href="'.get_bloginfo('siteurl').'/wp-includes/js/thickbox/thickbox.css" rel="stylesheet" type="text/css" />'."\n";
  311. echo '<link href="' . p2_static( 'preview', 0 ) . p2_option('randomizer', 0 ) . '" rel="stylesheet" type="text/css" />'."\n";
  312. }
  313. /* Prepare data for p2_option_box() */
  314. function p2_option_box_data ($name, $params, $title, $comment) {
  315. global $p2, $options_ux, $p2_form_weight;
  316. $params = explode('|', $params);
  317. // text|size
  318. // hidden
  319. // color|option
  320. // radio|id*which|value1|Text1|value2|Text2
  321. // select|value1|Text1|value2|Text2
  322. // dropdown|value1|Text1|value2|Text2
  323. // textarea|rows|cols
  324. // checkbox|option_var1|value1|Text1|option_var2|value2|Text2
  325. $value = p2_option($name, false); // Correct except for checkbox types, defined inline below
  326. $displayvalue = attribute_escape($value);
  327. $data = array();
  328. $type = array_shift($params);
  329. switch ($type) {
  330. case 'hidden':
  331. case 'text':
  332. $size=array_shift($params);
  333. $data['input'] = "<input type='$type' size='$size' id='p2-input-$name' name='p2_input_$name' value='$displayvalue' class='text-input' />";
  334. $p2_form_weight++;
  335. break;
  336. case 'color':
  337. $option=array_shift($params);
  338. if (!p2_validate_color($value)) $displayvalue = attribute_escape($p2['defaultsettings'][$name]);
  339. if (!$displayvalue) $displayvalue = '#000000';
  340. // Stuff to add if we have an optional color picker
  341. if ($option == 'optional') {
  342. $checked = ''; // checkbox state
  343. $jquery = 'false'; // checkbox state, 'true' or 'false'
  344. $display = 'none'; // display the binded color field, 'none' or 'block'
  345. $disabled = 'disabled="disabled"'; // state of the bound input field, '' or 'disabled="disabled"'
  346. if ('on' == p2_option("{$name}_bind", false)) {
  347. $checked='checked="checked"';
  348. $jquery = 'true';
  349. $display = 'block';
  350. $disabled = '';
  351. }
  352. $data['input'] .= "<input type='hidden' name='p2_input_{$name}_bind' value='' />";
  353. $p2_form_weight++;
  354. $data['input'] .= "<input type='checkbox' id='p2-input-{$name}-bind' name='p2_input_{$name}_bind' value='on' $checked class='optional-color-bind-checkbox' /><label for='p2-input-{$name}-bind'>$comment</label>";
  355. $p2_form_weight++;
  356. // Add a wrapping collapsible div around the color field
  357. $data['input'] .= "<div id='p2-input-{$name}-wrap' class='p2-colordiv-wrap' style='display:$display'>\n";
  358. $data['comment'] = ''; // reset the value of $comment in p2_option_box()
  359. } else {
  360. $data['input'] .= '<div>'; // this is so color pickers are same depth from parent divs no matter what for jquery
  361. }
  362. // The color picker itself
  363. $data['input'] .= "
  364. <input type='text' size='7' id='p2-input-$name' name='p2_input_$name' value='$displayvalue' $disabled class='color-picker' />
  365. <span class='p2_swatch' id='p2-swatch-$name' title='".$p2['msg']['pick_color']."'>&nbsp;</span>
  366. <div class='p2_picker_wrap' id='p2-picker-wrap-$name'>
  367. <div class='p2_picker' id='p2-picker-$name'></div>
  368. </div>
  369. ";
  370. $p2_form_weight++;
  371. // Stuff for optional color picker, part 2
  372. if ($option == 'optional') {
  373. $data['input'] .= "</div>\n"; // end of the wrapping div
  374. // Add javascript behavior: force refresh + toggle div & input field
  375. $data['input'] .= "\n<script type='text/javascript'>
  376. jQuery('#p2-input-{$name}-bind').attr('checked',$jquery).click(function(){
  377. var display = (jQuery('#p2-input-{$name}-wrap').css('display') == 'block') ? 'none' : 'block';
  378. var disabled = (display == 'none') ? true : false;
  379. jQuery('#p2-input-$name').attr('disabled', disabled);
  380. jQuery('#p2-input-{$name}-wrap').slideToggle(100);
  381. });
  382. </script>\n";
  383. } else {
  384. $data['input'] .= "</div>";// this is so color pickers are same depth from parent divs no matter what for jquery
  385. }
  386. break;
  387. case 'textarea':
  388. $rows=array_shift($params);
  389. $cols=array_shift($params);
  390. $data['input'] = "<textarea id='p2-input-$name' name='p2_input_$name' rows='$rows' cols='$cols' class='textarea-input'>$displayvalue</textarea>";
  391. $p2_form_weight++;
  392. break;
  393. case 'select':
  394. case 'dropdown':
  395. $data['input'] = "<select id='p2-input-$name' name='p2_input_$name' class='select-input'>";
  396. while ($params) {
  397. $v=array_shift($params);
  398. $t=array_shift($params);
  399. $selected='';
  400. if ($v == $value) $selected=' selected="selected"';
  401. $data['input'] .= "<option value='$v' $selected>$t</option>\n";
  402. }
  403. $data['input'] .= "</select>\n";
  404. $p2_form_weight++;
  405. break;
  406. case 'radio':
  407. // get custom javascript to attach to radio buttons
  408. $js = false;
  409. if ( $options_ux['js'][$name] ) {
  410. $js = true;
  411. $js_chunk = explode( '*', $options_ux['js'][$name] );
  412. }
  413. $radioloop = false; // Looping through radio params has not begun
  414. $counter = 0; // used as index for retrieving custom js
  415. while ($params) {
  416. $v=array_shift($params);
  417. $t=array_shift($params);
  418. $checked='';
  419. if ($v == $value) $checked='checked="checked"';
  420. if ($radioloop === false) {
  421. // Before the first radio button only, include the hidden field
  422. $data['input'] .= "<input type='hidden' name='p2_input_{$name}' value='' class='radio-input radio-input-hidden' />";
  423. $p2_form_weight++;
  424. $radioloop = true;
  425. }
  426. $data['input'] .= "<input type='radio' id=\"p2-input-{$name}-{$v}\" class='radio-input' name='p2_input_{$name}' value='$v' $checked";
  427. // add in custom javascript to control other option areas UX
  428. if ( $js ) {
  429. if ( $js_chunk[$counter] ) {
  430. $data['input'] .= " onclick=\"javascript:";
  431. $data['input'] .= $js_chunk[$counter];
  432. $data['input'] .= "\"";
  433. }
  434. }
  435. $data['input'] .= " /><label for='p2-input-{$name}-{$v}'>$t</label>";
  436. $p2_form_weight++;
  437. if (@$params) $data['input'] .= "<br />\n";
  438. $counter++;
  439. }
  440. break;
  441. case 'checkbox':
  442. while ($params) {
  443. $k=array_shift($params);
  444. $v=array_shift($params);
  445. $t=array_shift($params);
  446. $checked='';
  447. $jquery ='false';
  448. if ($v == p2_option($k, false)) {
  449. $checked='checked="checked"';
  450. $jquery = 'true';
  451. }
  452. $data['input'] .= "<input type='hidden' name='p2_input_$k' value='' class='checkbox-input checkbox-input-hidden' />";
  453. $p2_form_weight++;
  454. $data['input'] .= "<input type='checkbox' class='checkbox-input' id='p2-input-{$name}-{$k}' name='p2_input_$k' value='$v' $checked /><label for='p2-input-{$name}-{$k}'>$t</label>";
  455. $p2_form_weight++;
  456. // Add a javascript force refresh to avoid browser rendering inconsistencies between page reloads
  457. $data['input'] .= "<script type='text/javascript'>jQuery('#p2-input-{$name}-{$k}').attr('checked',$jquery);</script>";
  458. if (@$params) $data['input'] .= "<br />\n";
  459. }
  460. break;
  461. // leave one blank - for alignment purposes in multiple option areas
  462. case 'blank':
  463. $data['input'] = "<span class='blank-comment' style='height:0;display:none;' class='blank-input-explain'>&nbsp;</span>";
  464. break;
  465. default:
  466. $data['input'] = "<span style='color:red;background:#ff8;padding:5px;border:1px solid #ccc;'>Oops, wrong input type: <b>$type</b></span>";
  467. }
  468. return $data;
  469. } // end function p2_option_box_data
  470. /* Handle POST data on the Options page */
  471. function p2_process_options() {
  472. if (!isset($_POST['p2-options'])) return;
  473. global $p2;
  474. check_admin_referer('p2-options');
  475. // Debug :
  476. // echo "<pre>";echo attribute_escape(print_r($_POST,true));echo "</pre>";
  477. switch ($_POST['p2-options']) {
  478. case 'update':
  479. $update = false;
  480. $newoptions = array();
  481. foreach ($_POST as $key => $value) {
  482. // process each 'p2_input_something' entry
  483. if (strpos($key, 'p2_input_') !== false) {
  484. $key = str_replace('p2_input_', '', $key);
  485. $newoptions[$key] = $value;
  486. // randomize various filename to prevent cacheing issues
  487. $newoptions['randomizer'] = "?" . rand( 10000, 99999 );
  488. $update = true;
  489. }
  490. }
  491. if ($update) {
  492. // if $p2 is not an array yet, make it one so we don't get an array_merger error
  493. if ( !is_array( $p2['options']['settings'] ) ) {
  494. $p2['options']['settings'] = array();
  495. }
  496. // overwrite new values only
  497. $p2['options']['settings'] = array_merge( $p2['options']['settings'], $newoptions);
  498. $write_result = p2_store_options();
  499. }
  500. break;
  501. case 'reset':
  502. unset($p2['options']);
  503. $write_result = p2_store_options();
  504. }
  505. return $write_result;
  506. } // end function p2_process_options
  507. /* Validate a color code */
  508. function p2_validate_color($color) {
  509. $color = substr($color, 0, 7);
  510. return preg_match('/#[0-9a-fA-F]{6}/', $color);
  511. }
  512. /* show the banner ads options */
  513. function p2_banner_ads() {
  514. $c = 0; $which = '';
  515. // find out how many banners (and which ones) exist
  516. for ( $i = 1; $i <= 15; $i++ ) {
  517. if ( p2_image_exists( 'banner' . $i ) ) {
  518. $c++;
  519. $which .= $i . '*';
  520. }
  521. }
  522. // no banners uploaded, show the message
  523. if ( $c == 0 ) {
  524. echo $which;
  525. p2_multiple_option_box( 'no_sponsors', 'blank', 'Sponsor banners', '<span style="color:red;">[note:] To link your banners to websites, first go to the uploads page and upload at least one banner, then come back here</span>', 'last');
  526. return;
  527. // at least one banner uploaded
  528. } elseif ( $c ) {
  529. $which_ones = explode( '*', $which );
  530. for ( $i = 1; $i <= $c; $i++ ) {
  531. // only one banner? single option box and return
  532. if ( $c == 1 ) {
  533. p2_multiple_option_box('banner' . $which_ones[0] . '_link', 'text|30', 'Sponsor banner links', 'Link for sponsor banner #' . $which_ones[0], 'last');
  534. return;
  535. }
  536. // more than one banner, set up and rip multiple options
  537. if ( $i == $c ) $firstlast = 'last';
  538. else $firstlast = '';
  539. $a = $i - 1;
  540. p2_multiple_option_box('banner' . $which_ones[$a] . '_link', 'text|30', 'Sponsor banner links', 'Link for sponsor banner #' . $which_ones[$a], $firstlast);
  541. }
  542. }
  543. } // end function p2_banner_ads
  544. /* handles UI of option with an associated image */
  545. function p2_image_option( $image, $prettyname, $title = '' ) {
  546. global $continue;
  547. if ( !$title ) $title = $prettyname;
  548. // we have an image. display it inline and continue
  549. if ( p2_image_exists( $image ) ) {
  550. // shrink height, width, if necessary
  551. $h = p2_imageheight( $image, 0 );
  552. $w = p2_imagewidth( $image, 0 );
  553. $shrunk = false;
  554. if ( $w > 220 ) {
  555. $div = $w / 220;
  556. $w = 220;
  557. $h = $h / $div;
  558. $shrunk = true;
  559. }
  560. if ( $h > 150 ) {
  561. $div = $h / 150;
  562. $h = 150;
  563. $w = $w / $div;
  564. $shrunk = true;
  565. }
  566. // create the image html and rip the option
  567. $shrunk_msg = '';
  568. $img_html = '<img class="image-inline not-banner" src="' . p2_imageurl( $image, 0 ) . '"';
  569. if ( $shrunk ) {
  570. $img_html .= " height=\"$h\" width=\"$w\"";
  571. $shrunk_msg = ' Not shown <a href="' . p2_imageurl( $image, 0 ) . '">fullsize</a>.';
  572. }
  573. $img_html .= ' /><br />Current ' . $prettyname . '. Change or remove in the <a href="admin.php?page=p2-upload">Uploads Page</a>.' . $shrunk_msg;
  574. p2_multiple_option_box( $image . '_display', 'blank', $title, $img_html, 'first' );
  575. return $continue = true;
  576. }
  577. // no image, show the no image message
  578. p2_option_box( $image . '_no_img_msg', 'blank', $title, 'There is currently no ' . $prettyname . ' image uploaded. Upload one in the "uploads" page and then return here to see and select options');
  579. return $continue = false;
  580. }
  581. /* general link options */
  582. function p2_gen_link_options() {
  583. // these are always shown
  584. p2_multiple_option_box("gen_link_font_color", 'color', 'Overall link font appearance', 'link font color', 'first');
  585. p2_multiple_option_box("gen_link_hover_font_color", 'color', '', 'link font color when being hovered over');
  586. // hidden ones
  587. p2_multiple_option_box("gen_link_visited_font_color", 'color|optional', '', '<span class="color-optional">set unique font color after link has been visited</span>', '', true);
  588. p2_multiple_option_box("gen_link_font_style", 'select||select...|normal|normal|italic|italic', '', 'font style', '', true);
  589. p2_multiple_option_box('gen_link_decoration', 'select|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '','normal appearance of link', '', true);
  590. p2_multiple_option_box('gen_link_hover_decoration', 'select|none|no decoration|underline|underlined|overline|overlined|line-through|line through', '','appearance of link when being hovered over', '', true);
  591. p2_multiple_option_box('gen_link_text_transform', 'select||select...|none|Normal|uppercase|UPPERCASE|lowercase|lowercase', '', 'text effect', 'last', true);
  592. echo "<a class='font-link-more-options'></a>";
  593. }
  594. /* prints special css for post separator area */
  595. function p2_post_sep_css(){
  596. $test = p2_option( 'post_divider_onoff', 0 );
  597. echo '<style type="text/css">';
  598. if ( $test == 'line' ) echo '.for1{display:inline;}';
  599. if ( $test == 'none' ) echo '.for2{display:inline;}';
  600. if ( $test == 'image' ) echo '.for3{display:inline;}';
  601. echo '</style>';
  602. }
  603. /* prints crappy invalid inline css for jquery to use */
  604. function p2_suxorz( $shortname ) {
  605. if ( ( $shortname != 'emt_font_family' ) && ( $shortname != 'emb_font_family' ) ) return;
  606. if ( ( $shortname == 'emt_font_family' ) && ( p2_test( 'cattopbottom', 'bottom' ) ) ) {
  607. echo '<style type="text/css">.cat1 {display:none;}</style>';
  608. } else if ( ( $shortname == 'emb_font_family' ) && ( p2_test( 'cattopbottom', 'top' ) ) ){
  609. echo '<style type="text/css">.cat2 {display:none;}</style>';
  610. }
  611. } // end function p2_suxorz()
  612. /* adds extra hidden explanation (if there is one) & link to support page */
  613. function p2_extra_explain( $name, $multi = false ) {
  614. global $explain;
  615. ?>
  616. <div id="explain-<?php echo $name; ?>" class="extra-explain<?php if ( $multi ) echo ' extra-explain-multiple'; ?>">
  617. </div>
  618. <?php
  619. } // end function p2_extra_explain()
  620. /* adds clickable "?" if there is an extra explanation */
  621. function p2_click_for_explain( $name ) {
  622. echo " <a id=\"$name-cfa\" title=\"help\" class=\"click-for-explain\"></a>";
  623. } // end function p2_click_for_explain( $name )
  624. /* draws header options form, in all its glory */
  625. function p2_header_options() {
  626. $layout = p2_option('headerlayout',0);
  627. $position = array(
  628. 'default', 0,
  629. 'defaultc' => 1,
  630. 'defaultr' => 2,
  631. 'pptclassic' => 3,
  632. 'logobelowa' => 4,
  633. 'logobelowb' => 5,
  634. 'logobelowal' => 6,
  635. 'logobelowbl' => 7,
  636. 'logobelowar' => 8,
  637. 'logobelowbr' => 9,
  638. 'logotopa' => 10,
  639. 'logotopb' => 11,
  640. 'logotopal' => 12,
  641. 'logotopbl' => 13,
  642. 'logotopar' => 14,
  643. 'logotopbr' => 15,
  644. 'nologoa' => 16,
  645. 'nologob' => 17,
  646. );
  647. $options = array(
  648. 'default',
  649. 'defaultc',
  650. 'defaultr',
  651. 'logotopal',
  652. 'logotopa',
  653. 'logotopar',
  654. 'logotopbl',
  655. 'logotopb',
  656. 'logotopbr',
  657. 'logobelowal',
  658. 'logobelowa',
  659. 'logobelowar',
  660. 'logobelowbl',
  661. 'logobelowb',
  662. 'logobelowbr',
  663. 'nologoa',
  664. 'nologob',
  665. 'pptclassic',
  666. );
  667. ?>
  668. <div id="headerlayout-option-section" class="self-clear option-section">
  669. <a id="headerlayout-cfe" class="click-for-explain" tip="help"> </a> <div class="option-section-label">
  670. Header Layout </div>
  671. <div class="individual-option not-multiple">
  672. <?php p2_extra_explain('headerlayout') ?>
  673. <div style="display: none;" class="extra-explain" id="explain-headerlayout">
  674. <p style="margin-bottom: 13px;">This is the arrangement of the main portions of the blog header area: logo, masthead image(s), and navigation menu. The layout of the header area can directly affect the size of masthead image(s) that should be uploaded. Click below to see pictures of the different options if you're having trouble visualizing the options.</p>
  675. <p style="padding-top: 3px;">Still confused? <a href="http://www.prophotoblogs.com/support/header-layout/" target="_blank">Click here</a> for more help with this topic.</p>
  676. </div>
  677. <input id="headerlayout-input" type="hidden" name="p2_input_headerlayout" value="<?php echo $layout ?>">
  678. <div id="headerlayout-viewer-wrapper">
  679. <p>Currently Selected Header Layout:</p>
  680. <div id="headerlayout-viewer" style="background-position:-<?php echo $left = $position[$layout] * 200; ?>px 0"></div>
  681. </div>
  682. <div id="header-thumbs" class="self-clear">
  683. <?php
  684. for ( $i=0; $i<=17; $i++ ) {
  685. echo '<div id="';
  686. echo $options[$i];
  687. echo '" class="header-thumb-button self-clear';
  688. if ( $options[$i] == $layout ) echo ' active-thumb';
  689. echo'"><div style="cursor:pointer;background-position:-';
  690. echo $left = $position[$options[$i]] * 55;
  691. echo'px 0;"></div></div>';
  692. }
  693. ?>
  694. </div>
  695. </div>
  696. </div>
  697. <?php
  698. } // end function p2_header_options()
  699. /* calculate max recommended width for post image uploads */
  700. function p2_upload_width( $type = 'upload' ) {
  701. if ( $type == 'diff' ) {
  702. return p2_option( 'blog_width', 0 ) - p2_blogwidth();
  703. }
  704. $width = p2_blogwidth() - 62;
  705. if ( p2_test( 'inner_margin', 'zero' ) ) $width = $width + 62;
  706. return $width;
  707. }
  708. ?>