PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/blog/wp-content/themes/garland/functions.php

https://bitbucket.org/sergiohzlz/reportaprod
PHP | 338 lines | 285 code | 44 blank | 9 comment | 36 complexity | 0ca7330e3ee84d25851cd8df9b1230ba MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. $themecolors = array(
  3. 'bg' => 'ffffff',
  4. 'text' => '000000',
  5. 'link' => '027ac6'
  6. );
  7. register_nav_menus( array(
  8. 'primary' => __( 'Primary Navigation', 'garland' ),
  9. ) );
  10. function garland_page_menu() { // fallback for primary navigation ?>
  11. <ul class="links primary-links">
  12. <?php wp_list_pages( 'title_li=&depth=1' ); ?>
  13. </ul>
  14. <?php }
  15. add_theme_support( 'automatic-feed-links' );
  16. if ( function_exists('register_sidebar') )
  17. register_sidebar(array('name' => __('Left Sidebar'), 'id' => 'left-sidebar'));
  18. if ( function_exists('register_sidebar') )
  19. register_sidebar(array('name' => __('Right Sidebar'), 'id' => 'right-sidebar'));
  20. function garland_admin_menu() {
  21. $page = add_theme_page(__("Theme Options"), __("Theme Options"), 'edit_theme_options', 'custom-color', 'garland_admin_page');
  22. add_action("load-$page", 'garland_save_colors' );
  23. add_action("admin_print_scripts-$page", 'garland_admin_js');
  24. add_action("admin_head-$page", 'garland_admin_head');
  25. add_action("admin_print_scripts-$page", 'kill_feedback', 1 );
  26. }
  27. function garland_admin_js() {
  28. wp_deregister_script( 'prototype' );
  29. wp_enqueue_script( 'farbtastic' );
  30. }
  31. function garland_admin_head() {
  32. $base = garland_color('base');
  33. $_base = substr($base, 1);
  34. $text = garland_color('text');
  35. $link = garland_color('link');
  36. $_top = substr(garland_color('top'), 1);
  37. $_bottom = substr(garland_color('bottom'), 1);
  38. echo "<link rel='stylesheet' href='/wp-content/themes/pub/garland/farbtastic.css' type='text/css' />";
  39. echo <<<EOHEAD
  40. <script type="text/javascript">
  41. imgObj = new Image();
  42. imgObj.src = "/wp-content/themes/pub/garland/garland-image.php?src=preview.png&top=$_top&bottom=$_bottom&base=$_base";
  43. function previewLoadImage() {
  44. if ( imgObj.complete || 'complete' == imgObj.readyState )
  45. jQuery('#preview').css({ backgroundImage: 'url("' + imgObj.src + '")' });
  46. else
  47. setTimeout("previewLoadImage();",200);
  48. }
  49. function previewUpdateDisplay() {
  50. var e = jQuery('.farbtastic', '#colorpicker');
  51. var angle = f.hsl[0] * 6.28;
  52. jQuery('.h-marker', e).css({
  53. left: Math.round(Math.sin(angle) * f.radius + f.width / 2) + 'px',
  54. top: Math.round(-Math.cos(angle) * f.radius + f.width / 2) + 'px'
  55. });
  56. jQuery('.sl-marker', e).css({
  57. left: Math.round(f.square * (.5 - f.hsl[1]) + f.width / 2) + 'px',
  58. top: Math.round(f.square * (.5 - f.hsl[2]) + f.width / 2) + 'px'
  59. });
  60. // Saturation/Luminance gradient
  61. jQuery('.color', e).css('backgroundColor', f.pack(f.HSLToRGB([f.hsl[0], 1, 0.5])));
  62. // Linked elements or callback
  63. if (typeof f.callback == 'object') {
  64. // Set background/foreground color
  65. jQuery(f.callback).each( function(i,j) {
  66. if ( 'preview' == j.id ) {
  67. var imgsrc = jQuery(j).css('backgroundImage');
  68. var oldimgsrc = imgsrc;
  69. var color = f.color.substring(1,7);
  70. if ( f.callback[0].className.match(/top/) )
  71. imgsrc = imgsrc.replace(/top=[0-9a-fA-F]{6}/, 'top=' + color);
  72. else if ( f.callback[0].className.match(/bottom/) )
  73. imgsrc = imgsrc.replace(/bottom=[0-9a-fA-F]{6}/, 'bottom=' + color);
  74. else if ( f.callback[0].className.match(/base/) )
  75. imgsrc = imgsrc.replace(/base=[0-9a-fA-F]{6}/, 'base=' + color);
  76. if ( imgsrc == oldimgsrc )
  77. return;
  78. if ( document.images ) {
  79. imgObj = new Image();
  80. imgsrc = imgsrc.match(/(http|\/)[^'")]+/);
  81. imgObj.src = imgsrc[0];
  82. previewLoadImage();
  83. } else {
  84. jQuery(j).css({ backgroundImage: imgsrc });
  85. }
  86. } else if ( j.tagName.match(/input/i) )
  87. jQuery(j).css({
  88. backgroundColor: f.color,
  89. color: f.hsl[2] > 0.5 ? '#000' : '#fff'
  90. });
  91. else
  92. jQuery(j).css({ color: f.color });
  93. } );
  94. // Change linked value
  95. jQuery(f.callback).each(function() {
  96. if (this.value && this.value != f.color)
  97. this.value = f.color;
  98. });
  99. } else if (typeof f.callback == 'function') {
  100. f.callback.call(fb, f.color);
  101. }
  102. }
  103. jQuery(document).ready( function() {
  104. f = jQuery.farbtastic('#colorpicker');
  105. f.updateDisplay = previewUpdateDisplay;
  106. jQuery('#color-table input')
  107. .each( function() { f.linkTo(this); } )
  108. .focus( function() { f.linkTo('.' + this.className); } );
  109. } );
  110. </script>
  111. <style type="text/css">
  112. #preview {
  113. width: 596px;
  114. height: 371px;
  115. background: url("/wp-content/themes/pub/garland/garland-image.php?src=preview.png&top=$_top&bottom=$_bottom&base=$_base");
  116. position: relative;
  117. margin: 0 auto;
  118. color: $text;
  119. }
  120. #preview h3 {
  121. position: absolute;
  122. top: 160px;
  123. left: 75px;
  124. font-family: Helvetica, Arial, sans-serif;
  125. font-weight: normal;
  126. font-size: 160%;
  127. line-height: 130%;
  128. margin: 0;
  129. padding: 0;
  130. }
  131. #preview p {
  132. position: absolute;
  133. top: 190px;
  134. left: 75px;
  135. width: 446px;
  136. }
  137. #preview a, #preview a:link, #preview a:visited {
  138. text-decoration: none;
  139. border: none;
  140. color: $link;
  141. }
  142. #preview a:hover {
  143. text-decoration: underline;
  144. border: none;
  145. color: $link;
  146. }
  147. </style>
  148. EOHEAD;
  149. }
  150. function garland_using_custom_colors() {
  151. if ( get_theme_mod( 'custom-colors' ) )
  152. return true;
  153. return false;
  154. }
  155. function garland_color( $color, $shift = false ) {
  156. $colors = garland_custom_colors();
  157. if ( isset($colors[$color]) )
  158. return ( $shift && $colors[$color][1] ? $colors[$color][1] : $colors[$color][0] );
  159. return $color;
  160. }
  161. function garland_custom_colors() {
  162. if ( !$colors = get_theme_mod( 'custom-colors' ) ) {
  163. $colors = array();
  164. foreach ( garland_colors() as $label => $color ) {
  165. $colors[$label] = array( $color['default'] );
  166. if ( isset($colors[$label]['shift']) )
  167. $colors[$label][] = $colors[$label]['shift'][0];
  168. }
  169. }
  170. return $colors;
  171. }
  172. function garland_colors() {
  173. return array(
  174. 'base' => array( 'label' => __('Base'), 'el' => 'body, #wrapper, .commentlist .alt', 'prop' => 'background-color', 'default' => '#0072b9', 'shift' => array( '#EDF5FA', '#ffffff' ) ),
  175. 'link' => array( 'label' => __('Link'), 'el' => 'a, a:link, a:hover, a:visited', 'prop' => 'color', 'default' => '#0062A0' ),
  176. 'top' => array( 'label' => __('Header Top'), 'default' => '#0472EC' ),
  177. 'bottom' => array( 'label' => __('Header Bottom'), 'default' => '#67AAF4' ),
  178. 'text' => array ( 'label' => __('Text'), 'el' => '#wrapper', 'prop' => 'color', 'default' => '#494949' )
  179. );
  180. }
  181. function garland_images() {
  182. return array(
  183. 'bg-navigation-item.png' => array( 'el' => array(
  184. 'ul.primary-links li a, ul.primary-links li a:link, ul.primary-links li a:visited',
  185. 'ul.primary-links li a:hover, ul.primary-links li a.active'
  186. ),
  187. 'args' => array(
  188. array( 'top', 'bottom' ),
  189. array( 'top', 'bottom' )
  190. ),
  191. 'color' => array(
  192. 'transparent',
  193. 'transparent'
  194. ),
  195. 'post' => array(
  196. 'no-repeat 50% 0',
  197. 'no-repeat 50% -48px'
  198. )
  199. ),
  200. 'bg-navigation.png' => array( 'el' => '#navigation', 'args' => 'base', 'post' => 'repeat-x 50% 100%' ),
  201. 'body.png' => array( 'el' => '#wrapper', 'args' => array( 'base', 'top', 'bottom' ), 'color' => 'base', 'post' => 'repeat-x 50% 0'),
  202. 'bg-content.png' => array( 'el' => '#wrapper #container #center #squeeze', 'args' => array( 'base', 'top', 'bottom' ), 'color' => '#fff', 'post' => 'repeat-x 50% 0'),
  203. 'bg-content-right.png' => array( 'el' => '#wrapper #container #center .right-corner', 'args' => array( 'base', 'top', 'bottom' ), 'color' => 'transparent', 'post' => 'no-repeat 100% 0'),
  204. 'bg-content-left.png' => array( 'el' => '#wrapper #container #center .right-corner .left-corner', 'args' => array( 'base', 'top', 'bottom' ), 'color' => 'transparent', 'post' => 'no-repeat 0 0')
  205. );
  206. }
  207. function garland_admin_page() {
  208. if ( isset($_GET['updated']) ) : ?>
  209. <div class="updated fade"><p><?php _e('Custom Colors Updated'); ?></p></div>
  210. <?php endif; ?>
  211. <div class="wrap">
  212. <h2><?php _e('Custom Colors'); ?></h2>
  213. <?php garland_color_form(); ?>
  214. <h2>Preview</h2>
  215. <div id="preview" class="preview-base preview-top preview-bottom">
  216. <h3 class="preview-text">Lorem ipsum dolor</h3>
  217. <p class="preview-text">
  218. Sit amet, consectetur adipisicing elit, sed do eiusmod <a href="#" class="preview-link">tempor incididunt</a> ut labore et
  219. dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
  220. nisi ut aliquip ex ea commodo consequat. Duis aute <a href="#" class="preview-link">irure dolor</a> in reprehenderit in
  221. voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
  222. cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  223. <p>
  224. </div>
  225. </div>
  226. <?php }
  227. function garland_colors_css() {
  228. if ( !garland_using_custom_colors() )
  229. return;
  230. echo "<style type='text/css'>";
  231. foreach ( garland_colors() as $label => $color )
  232. echo "\n\t{$color['el']}" . ' { ' . "{$color['prop']}: " . garland_color( $label, true ) . ' } ';
  233. foreach ( garland_images() as $src => $image ) {
  234. if ( is_array($image['el']) ) {
  235. foreach ( $image['el'] as $k => $el ) {
  236. echo "\n\t$el" . ' { background: ' . garland_color( $image['color'][$k], true ) . " url('" . get_stylesheet_directory_uri() . "/garland-image.php?src=$src";
  237. foreach ( (array) $image['args'][$k] as $color )
  238. echo "&$color=" . substr(garland_color( $color ), 1);
  239. echo "') {$image['post'][$k]}" . ' } ';
  240. }
  241. } else {
  242. echo "\n\t{$image['el']}" . ' { background: ' . garland_color( $image['color'], true ) . " url('" . get_stylesheet_directory_uri() . "/garland-image.php?src=$src";
  243. foreach ( (array) $image['args'] as $color )
  244. echo "&$color=" . substr(garland_color( $color ), 1);
  245. echo "') {$image['post']}" . ' } ';
  246. }
  247. }
  248. echo "\n</style>\n";
  249. }
  250. function garland_color_form() {
  251. $colors = garland_colors(); ?>
  252. <form name="custom-colors" id="custom-colors" action="" method="post">
  253. <table id="color-table" class="alignleft">
  254. <?php foreach ( $colors as $label => $color ) : ?>
  255. <tr>
  256. <th scope="row"><label for="<?php echo $label; ?>-color"><?php echo $color['label']; ?></th>
  257. <td><input type="text" name="custom-color[<?php echo $label; ?>]" id="<?php echo $label; ?>-color" class="preview-<?php echo $label; ?>" value="<?php echo garland_color( $label ); ?>" /></td>
  258. </tr>
  259. <?php endforeach; ?>
  260. </table>
  261. <div id="colorpicker" class="alignleft" style="padding: 0 5px;"></div>
  262. <p class="submit" style="clear: both;">
  263. <input type="submit" value="<?php esc_attr_e( 'Save Custom Colors' ); ?>" />
  264. <input type="submit" name="reset-colors" value="<?php esc_attr_e( 'Reset to Default Colors' ); ?>" class="delete" />
  265. </p>
  266. </form>
  267. <?php }
  268. function garland_save_colors() {
  269. if ( !$_POST )
  270. return;
  271. require( 'color-module.php' );
  272. $colors = garland_custom_colors();
  273. $defaults = garland_colors();
  274. if ( isset($_POST['reset-colors']) ) {
  275. remove_theme_mod( 'custom-colors' );
  276. } else {
  277. foreach ( $_POST['custom-color'] as $label => $color ) {
  278. $colors[$label] = array( preg_replace('/[^#a-fA-F0-9]/', '', $color) );
  279. if ( isset($defaults[$label]['shift']) )
  280. $colors[$label][] = _color_shift( $colors[$label][0], $defaults[$label]['default'], $defaults[$label]['shift'][0], $defaults[$label]['shift'][1] );
  281. }
  282. set_theme_mod( 'custom-colors', $colors );
  283. }
  284. wp_redirect( add_query_arg('updated', '1') );
  285. exit;
  286. }
  287. function kill_feedback() {
  288. remove_action( 'admin_head', 'feedback_hackpage' );
  289. remove_action( 'admin_print_scripts', 'feedback_scripts' );
  290. remove_action( 'admin_head', 'feedbackform_javascript' );
  291. }
  292. add_action( 'admin_menu', 'garland_admin_menu' );
  293. add_action( 'wp_head', 'garland_colors_css' );
  294. ?>