PageRenderTime 101ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/presswork/functions.php

http://github.com/digibomb/PressWork
PHP | 1155 lines | 830 code | 106 blank | 219 comment | 135 complexity | eaa9aaca1fcacfa3b128c59fbd17e8de MD5 | raw file
  1. <?php
  2. // Set up PressWork Framework information
  3. if(!function_exists( 'pw_init' )):
  4. function pw_init() {
  5. $presswork_theme_data = get_theme_data(get_template_directory().'/style.css' );
  6. define( 'PW_THEME_NAME', $presswork_theme_data['Name']);
  7. define( 'PW_THEME_HOMEPAGE', $presswork_theme_data['URI']);
  8. define( 'PW_THEME_VERSION', trim($presswork_theme_data['Version']));
  9. define( 'PW_THEME_URL', get_template_directory_uri());
  10. define( 'PW_THEME_FILE', 'presswork' );
  11. define( 'PW_THEME_CODE', 'pwk' );
  12. }
  13. pw_init();
  14. endif;
  15. /**
  16. * Single save theme option
  17. *
  18. * @since PressWork 1.0
  19. */
  20. if(!function_exists( 'pw_single_save' )) :
  21. function pw_single_save($option, $value) {
  22. $savevalues = get_option(PW_THEME_FILE);
  23. $savevalues[$option] = esc_attr($value);
  24. update_option(PW_THEME_FILE, $savevalues);
  25. }
  26. endif;
  27. /**
  28. * Redirect to theme page upon theme activation
  29. *
  30. * @since PressWork 1.0
  31. */
  32. if(is_admin() && isset($_GET['activated']) && $pagenow == "themes.php" ) {
  33. global $pw_welcome;
  34. //delete_option(PW_THEME_FILE); die;
  35. $pw_welcome = false;
  36. header( 'Location: '.home_url("/")."?action=pw-activate");
  37. }
  38. /**
  39. * This is where the default themes options are set for PressWork.
  40. *
  41. * var $pw_default_options
  42. *
  43. * @since PressWork 1.0
  44. */
  45. if(empty($pw_default_options)) {
  46. $pw_default_options = array(
  47. "layout_option" => "maincontent,firstsidebar",
  48. "header_option" => "header_logo,nav",
  49. "footer_option" => "extendedfooter,copyright",
  50. "content_width" => "600",
  51. "first_sidebar_width" => "300",
  52. "second_sidebar_width" => "180",
  53. "body_margins" => "0",
  54. "content_margins" => "30",
  55. "toolbox" => "on",
  56. "dragdrop" => "off",
  57. "hooks" => "off",
  58. "functions" => "off",
  59. "header_logo" => PW_THEME_URL."/admin/images/logo_front.png",
  60. "favicon" => PW_THEME_URL."/admin/images/favicon.ico",
  61. "siteheader_color" => "#2B904E",
  62. "siteheader_color_hover" => "#444444",
  63. "description_color" => "#444444",
  64. "main_text_color" => "#444444",
  65. "a_color" => "#2b904e",
  66. "a_color_hover" => "#4fb859",
  67. "nav_color" => "#222222",
  68. "nav_color_hover" => "#444444",
  69. "nav_background_color" => "#FFFFFF",
  70. "nav_background_color_hover" => "#EEEEEE",
  71. "subnav_color" => "#222222",
  72. "subnav_color_hover" => "#222222",
  73. "subnav_background_color" => "#FFFFFF",
  74. "subnav_background_color_hover" => "#EEEEEE",
  75. "footernav_color" => "#222222",
  76. "footernav_color_hover" => "#222222",
  77. "footernav_background_color" => "#FFFFFF",
  78. "footernav_background_color_hover" => "#EEEEEE",
  79. "category_header_color" => "#222222",
  80. "post_title_color" => "#222222",
  81. "post_title_color_hover" => "#222222",
  82. "post_meta_color" => "#888888",
  83. "page_background_color" => "#FFFFFF",
  84. "body_font" => "Open Sans",
  85. "headers_font" => "Quattrocento",
  86. "body_font_size" => "12"
  87. );
  88. }
  89. // Call theme options
  90. function pw_theme_option($var) {
  91. global $pw_default_options, $pw_welcome;
  92. $pw_values = get_option(PW_THEME_FILE);
  93. if(empty($pw_values)) { pw_reset_options(); $pw_values = $pw_default_options; $pw_welcome = false; }
  94. $val = pw_get_index($pw_values, $var);
  95. return $val;
  96. }
  97. // all the includes
  98. if(!empty($_GET['action']) && $_GET['action']=="pw-activate" && empty($pw_welcome))
  99. include(get_template_directory().'/admin/inc/welcome.php' );
  100. include(get_template_directory()."/admin/inc/stylesheet.php");
  101. include(get_template_directory().'/admin/actions.php' );
  102. include(get_template_directory().'/admin/inc/toolbox.php' );
  103. include(get_template_directory().'/admin/inc/footer-scripts.php' );
  104. include(get_template_directory().'/admin/inc/action-blocks.php' );
  105. include(get_template_directory().'/admin/inc/slideshows.php' );
  106. include(get_template_directory().'/admin/inc/fullwidth.php' );
  107. include(get_template_directory().'/admin/inc/columns.php' );
  108. include(get_template_directory().'/admin/inc/google-fonts.php' );
  109. include(get_template_directory().'/admin/inc/widget-twitter.php' );
  110. include(get_template_directory().'/admin/inc/widget-featured.php' );
  111. include(get_template_directory().'/admin/inc/widget-slideshows.php' );
  112. include(get_template_directory().'/admin/inc/widget-flickr.php' );
  113. // Includes the pro folder if it exists
  114. if(!defined( 'PRO_FOLDER' ))
  115. define( 'PRO_FOLDER', get_template_directory().'/admin/pro/pro-functions.php' );
  116. if(file_exists(PRO_FOLDER))
  117. include(PRO_FOLDER);
  118. /**
  119. * Load custom-actions.php file if it exists in the uploads folder
  120. *
  121. * @since PressWork 1.0
  122. */
  123. $upload_dir = wp_upload_dir();
  124. if(!defined( 'ACTION_FILE' ))
  125. define( 'ACTION_FILE', $upload_dir['basedir'].'/custom-actions.php' );
  126. if(file_exists(ACTION_FILE))
  127. include(ACTION_FILE);
  128. /**
  129. * Load custom.css file if it exists in the uploads folder
  130. *
  131. * @since PressWork 1.0
  132. */
  133. define( 'CSS_FILE', $upload_dir['basedir'].'/custom.css' );
  134. define( 'CSS_DISPLAY', $upload_dir['baseurl'].'/custom.css' );
  135. if(file_exists(CSS_FILE))
  136. add_action("wp_print_styles", "pw_add_custom_css_file", 99);
  137. function pw_add_custom_css_file() {
  138. wp_register_style( 'pw_custom_css', CSS_DISPLAY);
  139. wp_enqueue_style( 'pw_custom_css' );
  140. }
  141. /**
  142. * Load all CSS and JavaScript to header
  143. *
  144. * @since PressWork 1.0.4.2
  145. */
  146. add_action("wp_enqueue_scripts", "pw_add_css_js");
  147. function pw_add_css_js() {
  148. if(!is_admin()) {
  149. global $pw_google_fonts;
  150. // add css
  151. if(pw_theme_option("toolbox")=="on" && current_user_can( "edit_theme_options" )) {
  152. wp_register_style( 'pw_google_font', 'http://fonts.googleapis.com/css?family='.str_replace(" ", "+", implode("|", $pw_google_fonts)));
  153. wp_register_style( 'pw_toolbox', PW_THEME_URL.'/admin/css/toolbox-styles.css' );
  154. wp_enqueue_style( 'pw_toolbox' );
  155. wp_enqueue_style( 'farbtastic' );
  156. } else {
  157. wp_register_style( 'pw_google_font', 'http://fonts.googleapis.com/css?family='.str_replace(" ", "+", pw_theme_option("body_font"))."|".str_replace(" ", "+", pw_theme_option("headers_font")));
  158. }
  159. wp_enqueue_style( 'pw_google_font' );
  160. // add js
  161. if(is_singular() && get_option( 'thread_comments' )) wp_enqueue_script( 'comment-reply' );
  162. wp_enqueue_script( 'jquery' );
  163. if(pw_theme_option( 'toolbox' )=="on" && current_user_can( "edit_theme_options" )) {
  164. wp_enqueue_script( 'jquery-ui-sortable' );
  165. wp_enqueue_script( 'farbtastic', admin_url("/js/farbtastic.js"), array( 'jquery' ),'',true );
  166. }
  167. }
  168. }
  169. // Setup the language file
  170. add_action( 'after_setup_theme', 'pw_language' );
  171. function pw_language() {
  172. // Make theme available for translation
  173. // Translations can be filed in the /languages/ directory
  174. load_theme_textdomain(PW_THEME_FILE, get_template_directory() . '/admin/languages' );
  175. $locale = get_locale();
  176. $locale_file = get_template_directory() . "/admin/languages/$locale.php";
  177. if ( is_readable( $locale_file ) )
  178. require_once( $locale_file );
  179. }
  180. /** Tell WordPress to run presswork_setup() when the 'after_setup_theme' hook is run. */
  181. add_action( 'after_setup_theme', 'presswork_setup' );
  182. if(!function_exists( 'presswork_setup' )) :
  183. /**
  184. * Sets up theme defaults and registers support for various WordPress features.
  185. *
  186. * Note that this function is hooked into the after_setup_theme hook, which runs
  187. * before the init hook. The init hook is too late for some features, such as indicating
  188. * support post thumbnails.
  189. *
  190. * To override presswork_setup() in a child theme, add your own presswork_setup to your child theme's
  191. * functions.php file.
  192. *
  193. * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  194. * @uses register_nav_menus() To add support for navigation menus.
  195. * @uses add_custom_background() To add support for a custom background.
  196. * @uses load_theme_textdomain() For translation/localization support.
  197. * @uses add_custom_image_header() To add support for a custom header.
  198. *
  199. * @since PressWork 1.0
  200. */
  201. function presswork_setup() {
  202. global $pw_site;
  203. // This theme allows users to set a custom background
  204. if(function_exists( 'add_custom_background' ))
  205. add_custom_background();
  206. // This theme uses wp_nav_menu()
  207. if(function_exists( 'register_nav_menu' )) {
  208. register_nav_menu( 'primary', __( 'Primary Nav Menu', "presswork"));
  209. register_nav_menu( 'secondary', __( 'Secondary Nav Menu', "presswork"));
  210. register_nav_menu( 'footer', __( 'Footer Nav Menu', "presswork"));
  211. }
  212. // The default message if no primary menu is set in the wp-admin
  213. function pw_menu_default() {
  214. ?>
  215. <ul id="menu-main" class="menu">
  216. <li><a href="<?php echo home_url("/"); ?>">Home</a></li>
  217. <?php wp_list_categories( 'title_li=&depth=1&number=5' ); ?>
  218. </ul>
  219. <?php
  220. if(current_user_can( 'edit_theme_options' )) {
  221. echo '<div class="warning clear fl" style="margin-bottom: 5px;"><p>';
  222. printf(__("Customize your Primary nav menu %shere%s", "presswork"), '<a href="'.admin_url( 'nav-menus.php' ).'">', '</a>' );
  223. echo '</p></div>';
  224. }
  225. }
  226. // The default message if no secondary menu is set in the wp-admin
  227. function pw_sub_menu_default() {
  228. if(current_user_can( 'edit_theme_options' )) {
  229. echo '<div class="warning clear fl"><p>';
  230. printf(__("Create your Secondary nav menu %shere%s", "presswork"), '<a href="'.admin_url( 'nav-menus.php' ).'">', '</a>' );
  231. echo '</p></div>';
  232. }
  233. }
  234. // The default message if no footer menu is set in the wp-admin
  235. function pw_footer_menu_default() {
  236. if(current_user_can( 'edit_theme_options' )) {
  237. echo '<div class="warning clear fl"><p>';
  238. printf(__("Create your Footer nav menu %shere%s", "presswork"), '<a href="'.admin_url( 'nav-menus.php' ).'">', '</a>' );
  239. echo '</p></div>';
  240. }
  241. }
  242. // Add a way for the custom header to be styled in the admin panel that controls
  243. // custom headers. See pw_admin_header_style(), below.
  244. add_custom_image_header( 'pw_header_style', 'pw_admin_header_style' );
  245. define( 'NO_HEADER_TEXT', true );
  246. define( 'HEADER_TEXTCOLOR', '' );
  247. define( 'HEADER_IMAGE_WIDTH', $pw_site); // use width and height appropriate for your theme
  248. if(!defined( 'HEADER_IMAGE_HEIGHT' ))
  249. define( 'HEADER_IMAGE_HEIGHT', 160);
  250. if(function_exists( 'add_theme_support' )) {
  251. // Add functionality for post thumbnails/featured image
  252. add_theme_support( 'post-thumbnails' );
  253. add_image_size( 'fifty', 50, 50, true );
  254. add_image_size( 'small', 80, 80, true );
  255. add_image_size( 'sticky', pw_theme_option( 'content_width' ), 240, true );
  256. //Add default posts and comments RSS feed links to head
  257. add_theme_support( 'automatic-feed-links' );
  258. //Add functionality for post formats
  259. add_theme_support( 'post-formats', array( 'aside', 'audio', 'gallery', 'image', 'link', 'video' ) );
  260. }
  261. }
  262. endif;
  263. /**
  264. * Set the content width based on the theme's design and stylesheet.
  265. *
  266. * Used to set the width of images and content. Should be equal to the width the theme
  267. * is designed for, generally via the style.css stylesheet.
  268. */
  269. if(!isset($content_width))
  270. $content_width = (pw_theme_option( 'content_width' ));
  271. // Add the theme admin
  272. add_action( 'admin_menu', 'pw_add_admin' );
  273. if(!function_exists( 'pw_add_admin' )) :
  274. /**
  275. * This is where we initialize the theme using the admin_menu hook.
  276. *
  277. * Adds the PressWork admin page into the Appearance panel.
  278. */
  279. function pw_add_admin() {
  280. global $pw_themelayout;
  281. wp_register_script( 'pw_admin_effects_js', PW_THEME_URL.'/admin/js/admin-effects.js', array( 'jquery' ), PW_THEME_VERSION, true);
  282. wp_localize_script( 'pw_admin_effects_js', 'presswork', array( 'front_url' => home_url("/") ) );
  283. $pw_themelayout = add_theme_page("presswork", "PressWork", 'edit_theme_options', "PressWork", 'pw_admin_page' );
  284. add_action( "admin_print_scripts-$pw_themelayout", 'pw_admin_css' );
  285. add_action("load-$pw_themelayout", 'pw_help' );
  286. }
  287. endif;
  288. if(!function_exists( 'pw_admin_css' )) :
  289. // load the js and css on theme options page
  290. function pw_admin_css() {
  291. echo '<link rel="stylesheet" href="'.PW_THEME_URL.'/admin/css/admin-style.css" />'."\n";
  292. wp_enqueue_script( 'pw_admin_effects_js' );
  293. }
  294. endif;
  295. if(!function_exists( 'pw_admin_page' )) :
  296. /**
  297. * This is the admin page for PressWork.
  298. *
  299. * @since PressWork 1.0
  300. */
  301. function pw_admin_page() {
  302. ?>
  303. <div id="wrap">
  304. <div id="presswork">
  305. <img src="<?php echo PW_THEME_URL; ?>/admin/images/logo_pw.png" width="557" height="122" alt="" class="pw-logo" />
  306. <?php echo '<div id="message" class="updated fade" style="display: none;"><p><strong>PressWork '.__("Toolbox Deactivated.", "presswork").'</strong></p></div>'."\n"; ?>
  307. <?php
  308. echo '<p>';
  309. printf(__("Click on the button below to activate/deactivate the %s front-end toolbox.", "presswork"), "<strong>PressWork</strong>");
  310. echo '</p>';
  311. $toolbox = pw_theme_option( 'toolbox' );
  312. if($toolbox=="on") { $class = "deactivate"; } else { $class = ''; }
  313. ?>
  314. <div id="active-button">
  315. <img src="<?php echo admin_url( '/images/wpspin_light.gif' ); ?>" alt='' />
  316. <a href="javascript:void(0)" class="pw-active <?php echo $class; ?>"></a>
  317. </div>
  318. <?php
  319. echo '<p>';
  320. printf(__("If you have any questions or feedback, please check out our %s.", "presswork"), '<a href="http://support.presswork.me/">Support Forum</a>' );
  321. echo '</p>';
  322. ?>
  323. <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  324. <input type="hidden" name="cmd" value="_s-xclick">
  325. <input type="hidden" name="hosted_button_id" value="QJ36XLEYC4J2S">
  326. <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  327. <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
  328. </form>
  329. <p><strong><?php _e("Created by", "presswork"); ?>: </strong><a href="http://bavotasan.com/">c.bavota</a>, <a href="http://dropthedigibomb.com/">Brendan Sera-Shriar</a><br />
  330. <strong><?php _e("Contributors", "presswork"); ?>: </strong><a href="http://isotrope.net/">Michal Bluma</a>, <a href="#">Michael Riethmuller</a></p>
  331. <?php
  332. if(function_exists( 'pw_check_for_update' )) {
  333. $presswork_version_check = pw_check_for_update();
  334. if(!empty($presswork_version_check)) {
  335. set_site_transient( 'update_themes', null);
  336. echo '<p class="pw-newversion">';
  337. printf(__( 'Version %1$s of %2$s is now available. Go to %3$s page.', "presswork"), $presswork_version_check, '<strong>'.PW_THEME_NAME.'</strong>', '<a href="'.admin_url( 'update-core.php' ).'">Updates</a>' );
  338. echo '</p>';
  339. }
  340. }
  341. ?>
  342. </div> <!-- end of #presswork -->
  343. <p class="pw-twitter"><a href="http://twitter.com/pressworkwp">@PressWorkWP</a></p>
  344. <p class="pw-briefcase">Want more functionality? Get <a href="http://presswork.me/briefcase/"></a></p>
  345. </div> <!-- end of #wrap -->
  346. <?php
  347. }
  348. endif;
  349. if(!function_exists( 'pw_help' )) :
  350. /**
  351. * Adds content to the help panel.
  352. *
  353. * @since PressWork 1.0.1
  354. */
  355. function pw_help() {
  356. global $pw_themelayout;
  357. $screen = get_current_screen();
  358. if($screen->id != $pw_themelayout)
  359. return;
  360. // added in PW 1.0.4 for WP 3.3
  361. $screen->add_help_tab( array( 'id' => 'pw-new',
  362. 'title' => __( 'New in v1.0.4', "presswork"),
  363. 'content' => '<p>'.__( 'PressWork v1.0.4 has been optimized to work with WordPress 3.3. Many new featured have been added to WP and the latest version of PressWork takes advantage of many of them, including this cool new help section. ', "presswork") .
  364. '<p>' . __( 'Check out the <a href="https://raw.github.com/PressWork/PressWork/master/changelog.txt">changelog</a> to see what we\'ve been up to.', "presswork") . '</p>' ));
  365. $screen->add_help_tab( array( 'id' => 'pw-toolbox',
  366. 'title' => __( 'The PressWork Toolbox', "presswork"),
  367. 'content' => '<p>'.__( 'One of the most amazing things about PressWork is the ability to customize your site without leaving the front end. This would not be possible if it weren\'t for the PressWork Toolbox. That\'s what we call the collection of tools that appear in the lower left of your screen when you are logged in as an admin.', "presswork") . '<br /><a href="http://presswork.me/2011/the-presswork-toolbox/">' . __( 'Read more', "presswork") . '</a></p>' ));
  368. $screen->add_help_tab( array( 'id' => 'pw-resources',
  369. 'title' => __( 'Customizing PressWork', "presswork"),
  370. 'content' => '<p><strong>' . __( 'Custom CSS', "presswork") . '</strong><p>' .
  371. '<p>'.__( 'PressWork has many theme options that allow you to customize how your site is styled. But what if you wanted to really delve into the design by adding some custom CSS. All you need to do is create a file called <code>custom.css</code> and upload it to your site\'s <code>/uploads</code> directory.', "presswork") . '<br /><a href="http://presswork.me/2011/custom-css-and-custom-actions/">' . __( 'Read more', "presswork") . '</a></p>' .
  372. '<p><strong>' . __( 'Custom Actions', "presswork") . '</strong><p>' .
  373. '<p>' . __( 'PressWork has been built so that all the customization happens through a file called actions.php. In order to customize or remove these actions, you need to create a <code>custom-actions.php</code> file and upload it to your site\'s <code>/uploads</code> directory.', "presswork") . '<br /><a href="http://presswork.me/2011/custom-css-and-custom-actions/">' . __( 'Read more', "presswork") . '</a></p>' ));
  374. $screen->add_help_tab( array( 'id' => 'pw-github',
  375. 'title' => __( 'Contribute on GitHub', "presswork"),
  376. 'content' => '<p><strong>' . __("Be a part of the PressWork Community", "presswork") . '</strong></p>' .
  377. '<p>' . __("If you've got mad skills when it comes to WordPress and you want to join the PressWork community, find us on <a href='https://github.com/PressWork/PressWork' target='_blank'>GitHub</a> and contribute. Together we can make PressWork the ultimate WordPress framework.", "presswork") . '</p>' ));
  378. $screen->set_help_sidebar( '<p><strong>' . __( 'For more information:', "presswork") . '</strong></p>' .
  379. '<p>' . __( '<a href="http://presswork.me/category/documentation/" target="_blank">Documentation</a>', "presswork") . '</p>' .
  380. '<p>' . __( '<a href="http://support.presswork.me" target="_blank">Support Forum</a>', "presswork") . '</p>' .
  381. '<p>' . __( '<a href="http://presswork.me" target="_blank">PressWork</a>', "presswork") . '</p>' );
  382. }
  383. endif;
  384. //add_filter( 'contextual_help', 'pw_help', 10, 3);
  385. // The pw_get_index function
  386. function pw_get_index($array, $index) {
  387. return isset($array[$index]) ? $array[$index] : null;
  388. }
  389. // Reset theme option function
  390. function pw_reset_options() {
  391. global $pw_default_options, $pw_welcome;
  392. update_option(PW_THEME_FILE, $pw_default_options);
  393. $pw_welcome = true;
  394. }
  395. // Reset theme ajax function
  396. function pw_reset_theme_options() {
  397. pw_reset_options();
  398. die();
  399. }
  400. add_action( 'wp_ajax_reset_theme_options', 'pw_reset_theme_options' );
  401. // Ajax save option function
  402. function pw_save_option() {
  403. $option = $_POST['option'];
  404. $id = $_POST['id'];
  405. pw_single_save($id, $option);
  406. die();
  407. }
  408. add_action( 'wp_ajax_save_option', 'pw_save_option' );
  409. // Turn on toolbox function
  410. function pw_turn_on_toolbox() {
  411. $option = $_POST['option'];
  412. pw_single_save( 'toolbox', $option);
  413. die();
  414. }
  415. add_action( 'wp_ajax_turn_on_toolbox', 'pw_turn_on_toolbox' );
  416. // Ajax save function
  417. function pw_save_theme_callback() {
  418. if (!wp_verify_nonce($_POST['nonce'], 'presswork_nonce' ))
  419. return;
  420. $savevalues = get_option(PW_THEME_FILE);
  421. $items = explode("&", $_POST['option']);
  422. foreach ($items as $value) {
  423. $key_value = explode("=",$value);
  424. $key = urldecode($key_value[0]);
  425. $value = esc_attr(urldecode($key_value[1]));
  426. if($key=="_wp_http_referer" || $key=="presswork_nonce") {
  427. // do nothing
  428. } else {
  429. $savevalues[$key] = $value;
  430. }
  431. }
  432. update_option(PW_THEME_FILE, $savevalues);
  433. die();
  434. }
  435. add_action( 'wp_ajax_save_theme_options', 'pw_save_theme_callback' );
  436. // Remove welcome screen function
  437. function pw_remove_welcome_screen() {
  438. global $pw_welcome;
  439. if (!wp_verify_nonce($_POST['nonce'], 'presswork_nonce' ))
  440. return;
  441. $pw_welcome = true;
  442. die();
  443. }
  444. add_action( 'wp_ajax_remove_welcome_screen', 'pw_remove_welcome_screen' );
  445. if(!function_exists( 'pw_widgets_init' )) :
  446. /**
  447. * This is where the widgetized areas and the scripts are initialized and
  448. * registered
  449. *
  450. * @since PressWork 1.0
  451. */
  452. function pw_widgets_init() {
  453. wp_register_script( 'pw_sliderota_js', PW_THEME_URL.'/admin/js/sliderota.js', array( 'jquery' ), PW_THEME_VERSION, true);
  454. wp_register_script( 'pw_scrollerota_js', PW_THEME_URL.'/admin/js/scrollerota.js', array( 'jquery' ), PW_THEME_VERSION, true);
  455. wp_register_script( 'pw_faderota_js', PW_THEME_URL.'/admin/js/faderota.js', array( 'jquery' ), PW_THEME_VERSION, true);
  456. // Initiating the sidebars
  457. register_sidebar(array( 'name' => __( 'Top Main Content on Index', "presswork"),
  458. 'id' => 'top-index-area',
  459. 'description' => __( "The area above the main content on the index page. Perfect spot for a slideshow.", "presswork" ),
  460. 'before_widget' => '<aside id="%1$s" class="content-widget %2$s">',
  461. 'after_widget' => "</aside>",
  462. 'before_title' => '<header><h1 class="catheader">',
  463. 'after_title' => '</h1></header>' ));
  464. register_sidebar(array( 'name' => __( 'Header Area', "presswork"),
  465. 'id' => 'header-area',
  466. 'description' => __( "The header area appears on every page of your site if it has been placed in the header.", "presswork" ),
  467. 'before_widget' => '<aside id="%1$s" class="header-widget %2$s">',
  468. 'after_widget' => "</aside>",
  469. 'before_title' => '<header><h3>',
  470. 'after_title' => '</h3></header>' ));
  471. register_sidebar(array( 'name' => __( 'First Sidebar', "presswork"),
  472. 'id' => 'first-sidebar',
  473. 'description' => __( "The first sidebar appears on every page of your site, unless you have selected full width for a post or page.", "presswork" ),
  474. 'before_widget' => '<aside id="%1$s" class="side-widget %2$s">',
  475. 'after_widget' => "</aside>",
  476. 'before_title' => '<header><h3>',
  477. 'after_title' => '</h3></header>' ));
  478. register_sidebar(array( 'name' => __( 'Second Sidebar', "presswork"),
  479. 'id' => 'second-sidebar',
  480. 'description' => __( "The second sidebar appears on every page of your site, unless you have selected full width for a post or page.", "presswork" ),
  481. 'before_widget' => '<aside id="%1$s" class="side-widget %2$s">',
  482. 'after_widget' => "</aside>",
  483. 'before_title' => '<header><h3>',
  484. 'after_title' => '</h3></header>' ));
  485. register_sidebar(array( 'name' => __( 'Extended Footer', "presswork"),
  486. 'id' => 'extended-footer',
  487. 'description' => __( "The extended footer appears at the bottom of your site if it has been placed in the footer.", "presswork" ),
  488. 'before_widget' => '<aside id="%1$s" class="bottom-widget %2$s">',
  489. 'after_widget' => "</aside>",
  490. 'before_title' => '<h3>',
  491. 'after_title' => '</h3>' ));
  492. }
  493. endif;
  494. add_action( 'init', 'pw_widgets_init' );
  495. if(!function_exists( 'pw_widget_first_last_classes' )) :
  496. /**
  497. * Adds a unique ordered class to widgets
  498. *
  499. * @since PressWork 1.0
  500. */
  501. function pw_widget_first_last_classes($params) {
  502. global $my_widget_num;
  503. $this_id = $params[0]['id'];
  504. if($this_id == 'extended-footer' ) {
  505. $arr_registered_widgets = wp_get_sidebars_widgets();
  506. if(!$my_widget_num)
  507. $my_widget_num = array();
  508. if(!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id]))
  509. return $params;
  510. if(isset($my_widget_num[$this_id]))
  511. $my_widget_num[$this_id] ++;
  512. else
  513. $my_widget_num[$this_id] = 1;
  514. if($my_widget_num[$this_id]==4)
  515. $my_widget_num[$this_id] = 1;
  516. $class = 'class="widget' . $my_widget_num[$this_id] . ' ';
  517. $params[0]['before_widget'] = preg_replace( '/class=\"/', "$class", $params[0]['before_widget'], 1);
  518. }
  519. return $params;
  520. }
  521. endif;
  522. add_filter( 'dynamic_sidebar_params','pw_widget_first_last_classes' );
  523. if(!function_exists( 'pw_comment_template' )) :
  524. /**
  525. * Template for comments and pingbacks.
  526. *
  527. * To override this walker in a child theme without modifying the comments template
  528. * simply create your own pw_comment_template(), and that function will be used
  529. * instead.
  530. *
  531. * Used as a callback by wp_list_comments() for displaying the comments.
  532. *
  533. * @since PressWork 1.0
  534. */
  535. function pw_comment_template($comment, $args, $depth) {
  536. $GLOBALS['comment'] = $comment;
  537. switch ( $comment->comment_type ) :
  538. case '' :
  539. ?>
  540. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  541. <div id="comment-<?php comment_ID(); ?>">
  542. <div class="comment-avatar">
  543. <?php echo get_avatar( $comment, 60 ); ?>
  544. </div>
  545. <div class="comment-content">
  546. <div class="comment-author">
  547. <?php echo get_comment_author_link()." "; ?>
  548. </div>
  549. <div class="comment-meta">
  550. <?php
  551. printf(__( '%1$s at %2$s', "presswork"), get_comment_date(),get_comment_time());
  552. edit_comment_link(__( '(edit)', "presswork"),' ','' );
  553. ?>
  554. </div>
  555. <div class="comment-text">
  556. <?php if ($comment->comment_approved == '0' ) { echo '<em>'.__( 'Your comment is awaiting moderation.', "presswork").'</em>'; } ?>
  557. <?php comment_text() ?>
  558. </div>
  559. <?php if($args['max_depth']!=$depth && comments_open() && $comment->comment_type!="pingback") { ?>
  560. <div class="reply">
  561. <?php comment_reply_link(array_merge($args, array( 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  562. </div>
  563. <?php } ?>
  564. </div>
  565. </div>
  566. <?php
  567. break;
  568. case 'pingback' :
  569. case 'trackback' :
  570. ?>
  571. <li class="pingback">
  572. <p><?php _e( 'Pingback:', "presswork" ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(edit)', "presswork" ), ' ' ); ?></p>
  573. <?php
  574. break;
  575. endswitch;
  576. }
  577. endif;
  578. /**
  579. * Adds HTML5 fields to comment form
  580. *
  581. * @since PressWork 1.0
  582. */
  583. function pw_html5_fields($fields) {
  584. $fields['author'] = '<p class="comment-form-author"><input id="author" name="author" type="text" required value="" size="30" placeholder="'.__("Your name", "presswork").' *" aria-required="true" /></p>';
  585. $fields['email'] = '<p class="comment-form-email"><input id="email" name="email" type="email" required value="" size="30" placeholder="'.__("Your email", "presswork").' *" aria-required="true" /></p>';
  586. $fields['url'] = '<p class="comment-form-url"><input id="url" name="url" type="url" value="" size="30" placeholder="'.__("Your website", "presswork").'" /></p>';
  587. return $fields;
  588. }
  589. add_filter( 'comment_form_default_fields','pw_html5_fields' );
  590. if(!function_exists( 'pw_paginate' )) :
  591. /**
  592. * Creates pagination.
  593. *
  594. * @since PressWork 1.0
  595. */
  596. function pw_paginate() {
  597. global $wp_query, $wp_rewrite;
  598. $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
  599. $pagination = array( 'base' => @add_query_arg( 'paged','%#%' ),
  600. 'format' => '',
  601. 'total' => $wp_query->max_num_pages,
  602. 'current' => $current,
  603. 'show_all' => false,
  604. 'type' => 'plain',
  605. 'next_text' => '&raquo;',
  606. 'prev_text' => '&laquo;' );
  607. if( $wp_rewrite->using_permalinks() )
  608. $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
  609. if( !empty($wp_query->query_vars['s']) )
  610. $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
  611. $pagination_return = paginate_links( $pagination );
  612. if(!empty($pagination_return)) {
  613. echo '<nav id="page-numbers">';
  614. echo '<h3 class="assistive-text">Page navigation</h3>';
  615. echo '<div class="total-pages">Page ', $current, ' of ', $wp_query->max_num_pages, '</div>';
  616. echo $pagination_return;
  617. echo '</nav>';
  618. }
  619. }
  620. endif;
  621. if(!function_exists( 'pw_header_style' )) :
  622. /**
  623. * Styles the header image.
  624. *
  625. * Referenced via add_custom_image_header()
  626. *
  627. * @since PressWork 1.0
  628. */
  629. function pw_header_style() {
  630. global $pw_site;
  631. $headerimage = get_header_image();
  632. if(!empty($headerimage)) {
  633. ?>
  634. <style type="text/css">
  635. #header_image { background: url(<?php header_image(); ?>); height: <?php echo HEADER_IMAGE_HEIGHT; ?>px; width: <?php echo $pw_site; ?>px; }
  636. </style>
  637. <?php
  638. }
  639. }
  640. endif;
  641. if(!function_exists( 'pw_admin_header_style' )) :
  642. /**
  643. * Styles the header image displayed on the Appearance > Header admin panel.
  644. *
  645. * Referenced via add_custom_image_header()
  646. *
  647. * @since PressWork 1.0
  648. */
  649. function pw_admin_header_style() {
  650. ?>
  651. <style type="text/css">
  652. #headimg { width: <?php echo HEADER_IMAGE_WIDTH; ?>px; height: <?php echo HEADER_IMAGE_HEIGHT; ?>px; }
  653. </style>
  654. <?php
  655. }
  656. endif;
  657. /**
  658. * Remove inline styles printed when the gallery shortcode is used.
  659. *
  660. * Galleries are styled by the theme in PressWork's style.css. This is just
  661. * a simple filter call that tells WordPress to not use the default styles.
  662. *
  663. * @since PressWork 1.0
  664. */
  665. add_filter( 'use_default_gallery_style', '__return_false' );
  666. if(!function_exists( 'pw_excerpt' )) :
  667. /**
  668. * Function to trim the excerpt
  669. *
  670. * @since PressWork 1.0
  671. */
  672. function pw_excerpt($excerpt_length = 55) {
  673. $excerpt = explode( ' ', get_the_excerpt(), $excerpt_length);
  674. if (count($excerpt)>=$excerpt_length) {
  675. array_pop($excerpt);
  676. $excerpt = implode(" ",$excerpt).'...';
  677. } else {
  678. $excerpt = implode(" ",$excerpt);
  679. }
  680. $excerpt = preg_replace( '`\[[^\]]*\]`','',$excerpt);
  681. echo '<p class="excerpt">', $excerpt, '</p>';
  682. }
  683. endif;
  684. /**
  685. * Adds links into the new WordPress 3.1 admin bar
  686. *
  687. * @since PressWork 1.0
  688. */
  689. function pw_add_menu_admin_bar() {
  690. global $wp_admin_bar, $wpdb;
  691. if ( !is_super_admin() || !is_admin_bar_showing() )
  692. return;
  693. /* Add the main siteadmin menu item */
  694. $wp_admin_bar->add_menu( array( 'id' => 'presswork-menu', 'title' => "PressWork", 'href' => admin_url( 'themes.php' )."?page=PressWork" ) );
  695. $wp_admin_bar->add_menu( array( 'parent' => 'presswork-menu', 'id' => 'presswork-admin', 'title' => __("PW Admin", "presswork"), 'href' => admin_url( 'themes.php' )."?page=PressWork" ) );
  696. $wp_admin_bar->add_menu( array( 'parent' => 'presswork-menu', 'id' => 'presswork-themes', 'title' => __("Browse Our Themes", "presswork"), 'href' => 'http://presswork.me/category/themes/' ) );
  697. }
  698. add_action( 'admin_bar_menu', 'pw_add_menu_admin_bar', 1000 );
  699. function pw_get_sidebar($id, $name, $action, $class = null, $parent = 'layout' ) {
  700. if(!empty($class)) $class = ' class="'.$class.'"';
  701. echo '<li id="'.$id.'" role="complementary"'.$class.'> <!-- begin '.$id.' -->'."\n";
  702. $handle = pw_handles($name, $id, true, $parent);
  703. if(!empty($handle)) echo pw_handles($name, $id, true, $parent);
  704. pw_actionBlock($action); // calling the Sidebar
  705. echo '</li> <!-- end '.$id.' -->'."\n";
  706. }
  707. function pw_handles($name, $id = null, $delete = null, $parent = 'layout' ) {
  708. $handle_on = pw_theme_option( 'dragdrop' );
  709. if(current_user_can( 'edit_theme_options' ) && $handle_on=="on" && pw_theme_option( 'toolbox' )=="on") {
  710. if(!empty($delete)) $anchor = '<a href="javascript:void(0)" class="delete_element" data-pw-ids="'.$id.'" data-pw-selectors="'.$parent.'_option"></a>'; else $anchor = '';
  711. if($handle_on=="on") $handle = '<div class="handle hand"><span></span>'.$name.$anchor.'</div>'; else $handle = '';
  712. return $handle;
  713. }
  714. }
  715. function pw_function_handle($function) {
  716. if(pw_theme_option( 'functions' )=="on" && current_user_can( 'edit_theme_options' ))
  717. return '<div class="handle clear">'.$function.'</div>';
  718. else
  719. return;
  720. }
  721. if(current_user_can( 'edit_theme_options' ) && pw_theme_option( 'toolbox' )=="on") {
  722. add_action( 'pw_body_bottom', 'pw_toolbox' );
  723. if(!empty($_GET['action']) && $_GET['action']=="pw-activate" && empty($pw_welcome))
  724. add_action( 'wp_footer', 'pw_welcome_screen', 1);
  725. add_action( 'wp_footer', 'pw_footer_scripts',99);
  726. }
  727. function pw_add_element() {
  728. if (!wp_verify_nonce($_POST['nonce'], 'presswork_nonce' ))
  729. exit();
  730. $element = $_POST['element'];
  731. $option = $_POST['option'];
  732. pw_get_element($element);
  733. die();
  734. }
  735. add_action( 'wp_ajax_add_element', 'pw_add_element' );
  736. function pw_delete_element() {
  737. if (!wp_verify_nonce($_POST['nonce'], 'presswork_nonce' ))
  738. exit();
  739. $element = $_POST['element'];
  740. $option = $_POST['option'];
  741. $all_options = get_option(PW_THEME_FILE);
  742. $three = explode( ',', $all_options[$option]);
  743. $i = 0;
  744. foreach($three as $one) {
  745. if($one==$element) { unset($three[$i]); }
  746. $i++;
  747. }
  748. $all_options[$option] = implode(",", $three);
  749. die(0);
  750. }
  751. add_action( 'wp_ajax_delete_element', 'pw_delete_element' );
  752. function pw_get_element($pw_add_name, $pw_add_class = null) {
  753. if($pw_add_name=="maincontent") {
  754. $handle = pw_handles( 'Main Content' ); ?>
  755. <li id="maincontent" role="main"<?php if(!empty($class)) echo ' class="'.$pw_add_class.'"'; ?>> <!-- begin maincontent -->
  756. <?php
  757. echo $handle;
  758. if(!have_posts()) :
  759. pw_actionBlock( 'pw_404' );
  760. elseif(is_category()) :
  761. pw_actionBlock( 'pw_category' );
  762. elseif(is_author()) :
  763. pw_actionBlock( 'pw_author' );
  764. elseif(is_archive()) :
  765. pw_actionBlock( 'pw_archive' );
  766. elseif(is_search()) :
  767. pw_actionBlock( 'pw_search' );
  768. elseif(is_page()) :
  769. pw_actionBlock( 'pw_page' );
  770. comments_template( '', true );
  771. elseif(is_single()) :
  772. pw_actionBlock( 'pw_single' );
  773. comments_template( '', true );
  774. else :
  775. pw_actionBlock( 'pw_index' );
  776. endif;
  777. ?>
  778. </li> <!-- end #maincontent -->
  779. <?php
  780. }
  781. if($pw_add_name=="firstsidebar") {
  782. pw_get_sidebar( 'firstsidebar', 'First Sidebar', 'pw_sidebar', $pw_add_class);
  783. }
  784. if($pw_add_name=="secondsidebar") {
  785. pw_get_sidebar( 'secondsidebar', 'Second Sidebar', 'pw_second_sidebar', $pw_add_class);
  786. }
  787. if($pw_add_name=="headerarea") {
  788. echo '<li id="headerarea" class="mainl" role="complementary">'."\n";
  789. $handle = pw_handles( 'Widgetized Area', 'headerarea', true, 'header' );
  790. echo $handle;
  791. if(!dynamic_sidebar("header-area") && current_user_can( 'edit_theme_options' )) :
  792. echo '<div class="warning clear fl"><p>';
  793. printf(__("Add widgets to the Header Area %shere%s", "presswork"), '<a href="'.admin_url( 'widgets.php' ).'">', '</a>' );
  794. echo '</p></div>';
  795. endif;
  796. echo '</li>'."\n";
  797. }
  798. if($pw_add_name=="blogname") {
  799. $handle = pw_handles( 'Blog Name', 'blogname', true, 'header' );
  800. ?>
  801. <li id="blogname" class="mainl">
  802. <?php echo $handle; ?>
  803. <h1 id="site-title" class="siteheader"><a href="<?php echo home_url(); ?>/"><?php bloginfo( 'name' ); ?></a></h1>
  804. </li>
  805. <?php
  806. }
  807. if($pw_add_name=="header_logo") {
  808. $handle = pw_handles( 'Header Logo', 'header_logo', true, 'header' );
  809. $logo = pw_theme_option("header_logo");
  810. if(!empty($logo)) {
  811. ?>
  812. <li id="header_logo" class="mainl">
  813. <?php echo $handle; ?>
  814. <div id="site-logo" class="siteheader"><h1><?php bloginfo( 'name' ); ?></h1><a href="<?php echo home_url(); ?>/"><img src="<?php echo $logo; ?>" alt="<?php bloginfo("name"); ?>" /></a></div>
  815. </li>
  816. <?php
  817. }
  818. }
  819. if($pw_add_name=="header_image") {
  820. $handle = pw_handles( 'Header Image', 'header_image', true, 'header' );
  821. ?>
  822. <li id="header_image" class="mainl"><?php echo $handle; ?></li>
  823. <?php
  824. }
  825. if($pw_add_name=="description") {
  826. $handle = pw_handles( 'Description', 'description', true, 'header' );
  827. ?>
  828. <li id="description" class="mainl">
  829. <?php echo $handle; ?>
  830. <?php bloginfo( 'description' ); ?>
  831. </li>
  832. <?php
  833. }
  834. if($pw_add_name=="nav") {
  835. $handle = pw_handles( 'Primary Nav Menu', 'nav', true, 'header' );
  836. if(function_exists( 'wp_nav_menu' )) {
  837. echo '<li id="nav" class="mainl">';
  838. echo $handle;
  839. echo '<nav class="clear fl" role="navigation">';
  840. echo '<h3 class="assistive-text">Main menu</h3>';
  841. wp_nav_menu( array( 'theme_location' => 'primary', 'sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => 'pw_menu_default' ) );
  842. echo '</nav>';
  843. echo '</li>';
  844. }
  845. }
  846. if($pw_add_name=="subnav") {
  847. $handle = pw_handles( 'Secondary Nav Menu', 'subnav', true, 'header' );
  848. if(function_exists( 'wp_nav_menu' )) {
  849. echo '<li id="subnav" class="mainl">';
  850. echo $handle;
  851. echo '<nav class="clear fl" role="navigation">';
  852. echo '<h3 class="assistive-text">Sub menu</h3>';
  853. wp_nav_menu( array( 'theme_location' => 'secondary', 'sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => 'pw_sub_menu_default' ) );
  854. echo '</nav>';
  855. echo '</li>';
  856. }
  857. }
  858. if($pw_add_name=="footernav") {
  859. $handle = pw_handles( 'Footer Nav Menu', 'footernav', true, 'footer' );
  860. if(function_exists( 'wp_nav_menu' )) {
  861. echo '<li id="footernav" class="foot">';
  862. echo $handle;
  863. echo '<nav class="clear fl" role="navigation">';
  864. echo '<h3 class="assistive-text">Footer menu</h3>';
  865. wp_nav_menu( array( 'theme_location' => 'footer', 'sort_column' => 'menu_order', 'container' => '', 'fallback_cb' => 'pw_footer_menu_default' ) );
  866. echo '</nav>';
  867. echo '</li>';
  868. }
  869. }
  870. if($pw_add_name=="extendedfooter") {
  871. $handle = pw_handles( 'Extended Footer', 'extendedfooter', true, 'footer' );
  872. echo '<li id="extendedfooter" class="foot" role="complementary">';
  873. echo $handle;
  874. if(!dynamic_sidebar("extended-footer") && current_user_can( 'edit_theme_options' )) :
  875. echo '<div class="warning clear fl"><p>';
  876. printf(__("Add widgets to the Extended Footer %shere%s", "presswork"), '<a href="'.admin_url( 'widgets.php' ).'">', '</a>' );
  877. echo '</p></div>';
  878. endif;
  879. echo '</li>';
  880. }
  881. if($pw_add_name=="copyright") {
  882. $handle = pw_handles( 'Copyright', 'copyright', true, 'footer' );
  883. echo '<li id="copyright" class="foot">';
  884. echo $handle;
  885. $link = '<a href="'.home_url().'">'.get_bloginfo( 'name' ).'</a>';
  886. printf(__( '&copy; %1$d %2$s. All Rights Reserved.', "presswork"), date( 'Y' ), $link);
  887. echo ' ';
  888. printf(__( 'Created using %s.', "presswork"), '<a href="http://presswork.me">PressWork</a>' );
  889. echo '</li>';
  890. }
  891. do_action( 'add_pw_get_element', $pw_add_name, $pw_add_class);
  892. }
  893. /**
  894. * Gathers the posts displayed in the featured posts widget
  895. *
  896. * @since PressWork 1.0
  897. */
  898. function pw_notin() {
  899. if(is_active_widget( '', '','pw_featured_posts' )) {
  900. global $post;
  901. $options = get_option("widget_pw_featured_posts");
  902. $sticky = get_option( 'sticky_posts' );
  903. foreach($options as $option) {
  904. if(!empty($option['number'])) {
  905. $args = array(
  906. "posts_per_page" => $option['number'],
  907. "cat" => $option['category'],
  908. "post__not_in" => $sticky
  909. );
  910. $featuredPosts = new WP_Query();
  911. $featuredPosts->query($args);
  912. while($featuredPosts->have_posts()) : $featuredPosts->the_post();
  913. $notin[] = $post->ID;
  914. endwhile;
  915. }
  916. }
  917. } else {
  918. $notin = '';
  919. }
  920. return $notin;
  921. }
  922. /**
  923. * Displays the toolbox add element button options
  924. *
  925. * @since PressWork 1.0
  926. */
  927. function pw_add_element_option($name, $id, $text, $rel) {
  928. $loc = strpos(pw_theme_option($name.'_option' ), $id);
  929. echo '<div class="addoption '.$name.'-item"><span>'.$text.'</span><a href="javascript:void(0)" class="add-item';
  930. if($loc!==false) echo " disabled";
  931. echo '" data-pw-ids="'.$id.'" data-pw-selectors="'.$rel.'">Add</a></div>';
  932. }
  933. /**
  934. * Displays the toolbox color option input
  935. *
  936. * @since PressWork 1.0
  937. */
  938. function pw_color_option($name, $id, $text, $rel) {
  939. echo '<tr class="color-item '.$name.'-item"><th>'.$text.'</th><td><input type="text" class="colorpicker" name="'.$id.'" data-pw-selectors="'.$rel.'" size="7" maxlength="7" value="'.pw_theme_option($id).'" /></td></tr>';
  940. }
  941. /**
  942. * Displays the toolbox font options
  943. *
  944. * @since PressWork 1.0
  945. */
  946. function pw_font_option($name, $text, $rel) {
  947. echo '<tr ><th>'.$text.'</th><td>'.pw_font_select($name."_font", $rel).'</td></tr>';
  948. }
  949. function pw_font_select($valueID, $rel) {
  950. global $pw_google_fonts;
  951. $ret = '
  952. <div class="font-select"><input type="hidden" name="'.$valueID.'" value="'.pw_theme_option($valueID).'" />
  953. <a href="javascript:void(0)" class="styled-select current" data-pw-selectors="'.$rel.'" style="font-family: '.pw_theme_option($valueID).';">'.pw_theme_option($valueID).'</a>
  954. <div class="font-preview">
  955. ';
  956. foreach($pw_google_fonts as $font) {
  957. $ret .= '<a href="javascript:void(0)"';
  958. if($font == pw_theme_option($valueID)) {$ret .= ' class="selected"';}
  959. $ret .= ' style="font-family: '.$font.';">'.$font.'</a>'."\n";
  960. }
  961. $ret .= '</div></div>';
  962. return $ret;
  963. }
  964. function pw_social_option($name, $text, $placeholder) {
  965. echo '<tr><th>'.$text.'</th><td><input type="text" placeholder="'.$placeholder.'" name="'.$name.'" value="'.pw_theme_option($name).'" /></td></tr>';
  966. }
  967. if(!function_exists( 'pw_html5_search_form' )) :
  968. /**
  969. * Replacing the default search form with an HTML5 version
  970. *
  971. * @since PressWork 1.0
  972. */
  973. function pw_html5_search_form( $form ) {
  974. $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
  975. <label class="assistive-text" for="s">' . __( 'Search for:', "presswork") . '</label>
  976. <input type="search" placeholder="'.__("Search...", "presswork").'" value="' . get_search_query() . '" name="s" id="s" />
  977. </form>';
  978. return $form;
  979. }
  980. endif;
  981. add_filter( 'get_search_form', 'pw_html5_search_form' );
  982. /**
  983. * Converts audio5 shortcode to HTML5 audio tag
  984. *
  985. * @since PressWork 1.0
  986. */
  987. function pw_html5_audio($atts, $content = null) {
  988. extract(shortcode_atts(array(
  989. "src" => '' ), $atts));
  990. return '<audio src="'.$src.'" controls autobuffer>';
  991. }
  992. add_shortcode( 'audio5', 'pw_html5_audio' );
  993. /**
  994. * Converts video5 shortcode to HTML5 video tag
  995. *
  996. * @since PressWork 1.0
  997. */
  998. function pw_html5_video($atts, $content = null) {
  999. extract(shortcode_atts(array(
  1000. "src" => '',
  1001. "width" => '',
  1002. "height" => '' ), $atts));
  1003. return '<video src="'.$src.'" width="'.$width.'" height="'.$height.'" controls autobuffer>';
  1004. }
  1005. add_shortcode( 'video5', 'pw_html5_video' );
  1006. /**
  1007. * Adds "odd" class to all odd posts.
  1008. *
  1009. * @since PressWork 1.0.4.2
  1010. */
  1011. global $current_class;
  1012. $current_class = 'odd';
  1013. function pw_my_post_class ( $classes ) {
  1014. if(!is_singular()) {
  1015. global $current_class;
  1016. $classes[] = $current_class;
  1017. $current_class = ($current_class == 'odd' ) ? 'even' : 'odd';
  1018. }
  1019. return $classes;
  1020. }
  1021. add_filter ( 'post_class' , 'pw_my_post_class' );
  1022. /**
  1023. * Enqueues the Video Resizer script into the footer.
  1024. *
  1025. * @since PressWork 1.0.1
  1026. */
  1027. function pw_video_resizer_footer_script() {
  1028. echo "\n<!-- PressWork Video Resizer Script -->\n";
  1029. ?>
  1030. <script type="text/javascript">
  1031. /* <![CDATA[ */
  1032. (function($) {
  1033. $("object, embed, .format-video iframe").each(function() {
  1034. var origVideo = $(this),
  1035. aspectRatio = origVideo.attr("height") / origVideo.attr("width"),
  1036. wrapWidth = origVideo.parents().find("p:last").width();
  1037. if(origVideo.attr("width") > wrapWidth) {
  1038. origVideo
  1039. .attr("width", wrapWidth)
  1040. .attr("height", (wrapWidth * aspectRatio));
  1041. }
  1042. });
  1043. })(jQuery);
  1044. /* ]]> */
  1045. </script>
  1046. <!-- eof PressWork Video Resizer Script -->
  1047. <?php
  1048. }
  1049. add_action( 'wp_footer', 'pw_video_resizer_footer_script', 99 );