Advertisement
Guest User

rickcd

a guest
May 5th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.57 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage U-Design
  5. */
  6.  
  7.  
  8. // Create Text Domain For the Themes' Translations
  9. if (function_exists('load_theme_textdomain')) {
  10. load_theme_textdomain('udesign', get_template_directory().'/locale');
  11. }
  12.  
  13. // load styles
  14. function my_init_styles() {
  15. if( !is_admin() ){
  16. // get the desired color scheme
  17. global $udesign_options, $style;
  18. // Format the Google WebFonts as string
  19. if( $udesign_options['google_web_fonts_assoc'] ) {
  20. $google_fonts_string = implode( '|', array_unique($udesign_options['google_web_fonts_assoc']) );
  21. if( $google_fonts_string )
  22. printf("<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=%s' type='text/css' />\r\n", str_replace(' ', '+', $google_fonts_string));
  23. }
  24. wp_enqueue_style('reset', get_bloginfo('template_url') . '/styles/common-css/reset.css', false, '1.0', 'screen');
  25. wp_enqueue_style('text', get_bloginfo('template_url') . "/styles/{$style}/css/text.css", false, '1.0', 'screen');
  26. wp_enqueue_style('grid-960', get_bloginfo('template_url') . '/styles/common-css/960.css', false, '1.0', 'screen');
  27. wp_enqueue_style('superfish_menu', get_bloginfo('template_url') . '/scripts/superfish-1.4.8/css/superfish.css', false, '1.0', 'screen');
  28. if ( $udesign_options['enable_prettyPhoto_script'] && !WP_PRETTY_PHOTO_PLUGIN_ACTIVE ) {
  29. wp_enqueue_style('pretty_photo', get_bloginfo('template_url') . '/scripts/prettyPhoto/css/prettyPhoto.css', false, '3.1.5', 'screen');
  30. }
  31. wp_enqueue_style('style', get_bloginfo('template_url') . "/styles/{$style}/css/style.css", false, '1.9.1', 'screen');
  32. // load the appropriate custom styles file optimized for performance
  33. if ( get_theme_mod( 'udesign_custom_styles_use_css_file' ) ) { // load "custom_style.css" file
  34. wp_enqueue_style('custom-style', get_bloginfo('template_url') . '/styles/custom/custom_style.css', false, '', 'screen');
  35. } else { // otherwise use "custom_style.php" file
  36. wp_enqueue_style('custom-style', get_bloginfo('template_url') . '/styles/custom/custom_style.php', false, '', 'screen');
  37. }
  38.  
  39. if ( $udesign_options['enable_default_style_css'] ) {
  40. wp_enqueue_style('style-orig', get_stylesheet_directory_uri() . "/style.css", false, '1.0', 'screen');
  41. }
  42. }
  43. }
  44. add_action('wp_print_styles', 'my_init_styles');
  45.  
  46. // load scripts
  47. function my_init_scripts() {
  48. if( !is_admin() ){
  49. global $udesign_options, $current_slider;
  50.  
  51. // Load jQuery
  52. if( WP_PRETTY_PHOTO_PLUGIN_ACTIVE ) { // WP-prettyPhoto requires jquery 1.4.2
  53. wp_deregister_script( 'jquery' );
  54. wp_register_script( 'jquery', get_bloginfo('template_url')."/scripts/jquery-1.4.2.min.js", false, '' );
  55. }
  56. wp_enqueue_script('jquery');
  57.  
  58. // Cufon
  59. if( $udesign_options['enable_cufon'] ) {
  60. wp_enqueue_script('cufon_lib', get_bloginfo('template_url')."/scripts/cufon/cufon-yui.js", array('jquery'), '1.09i', false);
  61.  
  62. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Aubrey' )
  63. wp_enqueue_script('font_aubrey', get_bloginfo('template_url')."/scripts/cufon/Aubrey/Aubrey_400.font.js", array('cufon_lib'), '1.0', false);
  64. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Bebas' )
  65. wp_enqueue_script('font_bebas', get_bloginfo('template_url')."/scripts/cufon/Bebas/Bebas_400.font.js", array('cufon_lib'), '1.0', false);
  66. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Blue Highway' )
  67. wp_enqueue_script('font_blue_highway', get_bloginfo('template_url')."/scripts/cufon/Blue_Highway/Blue_Highway_400.font.js", array('cufon_lib'), '1.0', false);
  68. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Blue Highway D Type' )
  69. wp_enqueue_script('font_blue_highway_d_type', get_bloginfo('template_url')."/scripts/cufon/Blue_Highway/Blue_Highway_D_Type_400.font.js", array('cufon_lib'), '1.0', false);
  70. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Diavlo Book' )
  71. wp_enqueue_script('font_diavlo_book', get_bloginfo('template_url')."/scripts/cufon/Diavlo/Diavlo_Book_400.font.js", array('cufon_lib'), '1.0', false);
  72. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'eurofurence' )
  73. wp_enqueue_script('font_eurofurence', get_bloginfo('template_url')."/scripts/cufon/Eurofurence/eurofurence_500.font.js", array('cufon_lib'), '1.0', false);
  74. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'GeosansLight' )
  75. wp_enqueue_script('font_geosanslight', get_bloginfo('template_url')."/scripts/cufon/GeosansLight/GeosansLight_500.font.js", array('cufon_lib'), '1.0', false);
  76. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Oregon LDO' )
  77. wp_enqueue_script('font_oregon_ldo', get_bloginfo('template_url')."/scripts/cufon/Oregon_LDO/Oregon_LDO_400.font.js", array('cufon_lib'), '1.0', false);
  78. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Qlassik Medium' )
  79. wp_enqueue_script('font_qlassik_medium', get_bloginfo('template_url')."/scripts/cufon/Qlassik/Qlassik_Medium_500.font.js", array('cufon_lib'), '1.0', false);
  80. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Sansation' )
  81. wp_enqueue_script('font_sansation', get_bloginfo('template_url')."/scripts/cufon/Sansation/Sansation_400.font.js", array('cufon_lib'), '1.0', false);
  82. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Sniglet' )
  83. wp_enqueue_script('font_sniglet', get_bloginfo('template_url')."/scripts/cufon/Sniglet/Sniglet_400.font.js", array('cufon_lib'), '1.0', false);
  84. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Tertre Med' )
  85. wp_enqueue_script('font_tertre_med', get_bloginfo('template_url')."/scripts/cufon/Tertre/Tertre_Med_800.font.js", array('cufon_lib'), '1.0', false);
  86. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Waukegan LDO' )
  87. wp_enqueue_script('font_waukegan_ldo', get_bloginfo('template_url')."/scripts/cufon/Waukegan_LDO/Waukegan_LDO_400.font.js", array('cufon_lib'), '1.0', false);
  88. if ( $udesign_options['cufon_fonts_assoc']['title_headings_font_family'] == 'Yorkville' )
  89. wp_enqueue_script('font_yorkville', get_bloginfo('template_url')."/scripts/cufon/Yorkville/yorkville_400.font.js", array('cufon_lib'), '1.0', false);
  90. }
  91.  
  92. // swfobject scripts
  93. if( is_front_page() && $current_slider == '1' ) {
  94. wp_enqueue_script('flashmo-swfobject', get_bloginfo('template_url')."/sliders/flashmo/grid_slider/swfobject.js", '', '2.2', false);
  95. }
  96. if( is_front_page() && ( $current_slider == '2' || $current_slider == '3' ) ) {
  97. wp_enqueue_script('piecemaker-swfobject', get_bloginfo('template_url')."/sliders/piecemaker/js/swfobject.js", '', '1.5', false);
  98. }
  99.  
  100. // Cycle 1 Slider Plugin
  101. if( is_front_page() && $current_slider == '4' ) {
  102. wp_enqueue_script('cycle', get_bloginfo('template_url')."/sliders/cycle/jquery.cycle.all.min.js", array('jquery'), '2.86', false);
  103. wp_enqueue_script('cycle1', get_bloginfo('template_url')."/sliders/cycle/cycle1/cycle1_script.js", array('jquery'), '1.0.0', false);
  104. }
  105.  
  106. // Cycle 2 Slider Plugin
  107. if( is_front_page() && $current_slider == '5' ) {
  108. wp_enqueue_script('cycle', get_bloginfo('template_url')."/sliders/cycle/jquery.cycle.all.min.js", array('jquery'), '2.86', false);
  109. wp_enqueue_script('cycle2', get_bloginfo('template_url')."/sliders/cycle/cycle2/cycle2_script.js", array('jquery'), '1.0.0', false);
  110. }
  111.  
  112. // Cycle 3 Slider Plugin
  113. if( is_front_page() && $current_slider == '6' ) {
  114. wp_enqueue_script('cycle', get_bloginfo('template_url')."/sliders/cycle/jquery.cycle.all.min.js", array('jquery'), '2.99', false);
  115. wp_enqueue_script('jquery-easing', get_bloginfo('template_url')."/sliders/cycle/jquery.easing.1.3.js", array('jquery'), '1.3', false);
  116. wp_enqueue_script('cycle3', get_bloginfo('template_url')."/sliders/cycle/cycle3/cycle3_script.js", array('jquery'), '1.0.0', false);
  117. }
  118.  
  119. // PrettyPhoto script
  120. if( $udesign_options['enable_prettyPhoto_script'] && !WP_PRETTY_PHOTO_PLUGIN_ACTIVE ) {
  121. wp_enqueue_script('pretty_photo_lib', get_bloginfo('template_url')."/scripts/prettyPhoto/js/jquery.prettyPhoto.js", array('jquery'), '3.1.5', false);
  122. wp_enqueue_script('custom_pretty_photo', get_bloginfo('template_url')."/scripts/prettyPhoto/custom_params.js", array('pretty_photo_lib'), '3.1.5', true);
  123. }
  124.  
  125. // jQuery validation script
  126. if ( is_page_template('page-Contact.php') ) {
  127. wp_enqueue_script('jquery_validate_lib', get_bloginfo('template_url')."/scripts/jquery-validate/jquery.validate.min.js", array('jquery'), '1.8.1', false);
  128. wp_enqueue_script('masked_input_plugin', get_bloginfo('template_url')."/scripts/masked-input-plugin/jquery.maskedinput.min.js", array('jquery'), '1.3', false);
  129. }
  130.  
  131. // Isotope related Sortable Portfolio scripts
  132. if ( is_page_template('page-Portfolio1ColSortable.php') || is_page_template('page-Portfolio2ColSortable.php') || is_page_template('page-Portfolio3ColSortable.php') || is_page_template('page-Portfolio4ColSortable.php') ) {
  133. wp_enqueue_script('jquery-isotope-lib', get_bloginfo('template_url')."/scripts/isotope/jquery.isotope.min.js", array('jquery'), '1.5.19', false);
  134. wp_enqueue_script('isotope-custom-scripts', get_bloginfo('template_url')."/scripts/isotope/isotope-custom-scripts.js", array('jquery-isotope-lib'), '1.0.0', false);
  135. }
  136.  
  137. // Superfish Dropdown menu scripts (combined)
  138. wp_enqueue_script('superfish-menu', get_bloginfo('template_url')."/scripts/superfish-1.4.8/js/superfish.combined.js", array('jquery'), '1.0.0', false);
  139.  
  140. // Miscellaneous JS scripts
  141. wp_enqueue_script('scripts', get_bloginfo('template_url')."/scripts/script.js", array('jquery'), '1.0', false);
  142. }
  143. }
  144. add_action('wp_print_scripts', 'my_init_scripts');
  145.  
  146. // Define a global variable '$portfolio_pages_array' as an array containing all pages assigned to be Portfolio pages
  147. global $portfolio_pages_array;
  148. $portfolio_1_pages_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio1Col.php&hierarchical=0');
  149. $portfolio_2_pages_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio2Col.php&hierarchical=0');
  150. $portfolio_3_pages_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio3Col.php&hierarchical=0');
  151. $portfolio_4_pages_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio4Col.php&hierarchical=0');
  152. $portfolio_1_pages_sortable_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio1ColSortable.php&hierarchical=0');
  153. $portfolio_2_pages_sortable_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio2ColSortable.php&hierarchical=0');
  154. $portfolio_3_pages_sortable_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio3ColSortable.php&hierarchical=0');
  155. $portfolio_4_pages_sortable_array = get_pages('meta_key=_wp_page_template&meta_value=page-Portfolio4ColSortable.php&hierarchical=0');
  156. $portfolio_pages_array = array_merge($portfolio_1_pages_array, $portfolio_2_pages_array, $portfolio_3_pages_array, $portfolio_4_pages_array, $portfolio_1_pages_sortable_array, $portfolio_2_pages_sortable_array, $portfolio_3_pages_sortable_array, $portfolio_4_pages_sortable_array);
  157.  
  158.  
  159. // Menu functions with support for WordPress 3.0 menus
  160. if ( function_exists('wp_nav_menu') ) {
  161. add_theme_support( 'nav-menus' );
  162. register_nav_menus( array(
  163. 'primary' => esc_html__( 'Primary Navigation', 'udesign' ),
  164. ) );
  165. }
  166.  
  167. function udesign_nav() {
  168. if ( function_exists( 'wp_nav_menu' ) )
  169. wp_nav_menu( array( 'container_class' => 'navigation-menu',
  170. 'container_id' => 'navigation-menu',
  171. 'menu_class' => 'sf-menu',
  172. 'link_before'=> '<span>',
  173. 'link_after' => '</span>',
  174. 'theme_location' => 'primary',
  175. 'fallback_cb' => 'udesign_nav_fallback' )
  176. );
  177. else
  178. udesign_nav_fallback();
  179. }
  180.  
  181. function udesign_nav_fallback() {
  182. global $udesign_options;
  183. $menu_html = '<div id="navigation-menu" class="navigation-menu">';
  184. $menu_html .= '<ul class="sf-menu">';
  185. $menu_html .= is_front_page() ? "<li class='current_page_item'>" : "<li>";
  186. $menu_html .= '<a href="'.get_bloginfo('url').'"><span>'.esc_html__('Home', 'udesign').'</span></a></li>';
  187. $menu_html .= wp_list_pages('depth=5&title_li=0&sort_column=menu_order&link_before=<span>&link_after=</span>&exclude='.$udesign_options['excluded_paged_from_menu'].'&echo=0');
  188. $menu_html .= '</ul>';
  189. $menu_html .= '</div>';
  190. echo $menu_html;
  191. }
  192.  
  193. //Automatic Feed Links is a theme feature introduced with Version 3.0. This feature addes to HTML <head> RSS feed links.
  194. if ( function_exists('add_theme_support') ) {
  195. add_theme_support( 'automatic-feed-links' );
  196. }
  197.  
  198.  
  199. // replace the original get_search_form() with the internationalized version here:
  200. function translatable_search_form( $form ) {
  201. $form = '<form role="search" method="get" id="searchform" action="'.get_bloginfo('url').'" >
  202. <div><label class="screen-reader-text" for="s">' . __('Search for:', 'udesign') . '</label>
  203. <input type="text" value="' . get_search_query() . '" name="s" id="s" />
  204. <input type="submit" id="searchsubmit" value="'. esc_attr__('Search', 'udesign') .'" />
  205. </div>
  206. </form>';
  207. return $form;
  208. }
  209. add_filter( 'get_search_form', 'translatable_search_form' );
  210.  
  211.  
  212. /* Check for image */
  213. function findImage() {
  214. $content = get_the_content();
  215. $count = substr_count($content, '<img');
  216. if ($count > 0) return true;
  217. else return false;
  218. }
  219.  
  220. /* Get the first image from the post and return it */
  221. function get_image_url() {
  222. global $post, $posts;
  223. $first_img = '';
  224. ob_start();
  225. ob_end_clean();
  226. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  227. $first_img = $matches [1] [0];
  228.  
  229. if(empty($first_img)){ //Defines a default image
  230. $first_img = "/images/thumbnail-default.jpg";
  231. }
  232. return $first_img;
  233. }
  234.  
  235.  
  236. /**
  237. * Tests if any of a post's assigned categories are descendants of target categories
  238. *
  239. * @param int|array $cats The target categories. Integer ID or array of integer IDs
  240. * @param int|object $_post The post. Omit to test the current post in the Loop or main query
  241. * @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
  242. * @see get_term_by() You can get a category by name or slug, then pass ID to this function
  243. * @uses get_term_children() Passes $cats
  244. * @uses in_category() Passes $_post (can be empty)
  245. * @version 2.7+
  246. * @link http://codex.wordpress.org/Function_Reference/in_category#Testing_if_a_post_is_in_a_descendant_category
  247. */
  248. function test_post_is_in_descendant_category( $cats, $_post = null )
  249. {
  250. foreach ( (array) $cats as $cat ) {
  251. // get_term_children() accepts integer ID only
  252. $descendants = get_term_children( (int) $cat, 'category');
  253. if ( $descendants && in_category( $descendants, $_post ) )
  254. return true;
  255. }
  256. return false;
  257. }
  258.  
  259. /**
  260. * Tests if any of a post's assigned categories are in the target categories or in any of the descendants
  261. *
  262. * @param int|array $cats The target categories. Integer ID or array of integer IDs
  263. * @param int|object $_post The post. Omit to test the current post in the Loop or main query
  264. * @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
  265. * @see get_term_by() You can get a category by name or slug, then pass ID to this function
  266. * @uses get_term_children() Passes $cats
  267. * @uses in_category() Passes $_post (can be empty)
  268. * @version 2.7+
  269. */
  270. function post_is_in_category_or_descendants( $cats, $_post = null )
  271. {
  272. if( in_category( $cats, $_post = null ) || test_post_is_in_descendant_category( $cats, $_post = null ) ) {
  273. return true;
  274. }
  275. return false;
  276. }
  277.  
  278. /**
  279. * This function is used to generate custom breadcrumbs for single posts view. Portfolio section or regular Blog is considered
  280. * when generating the link structure.
  281. */
  282. function get_category_parents_for_breadcrumbs( $id, $link = false, $separator = '/' ) {
  283. global $udesign_options, $portfolio_pages_array;
  284. $portfolio_cats_array = explode( ',', $udesign_options['portfolio_categories'] );
  285. if ( post_is_in_category_or_descendants($portfolio_cats_array) ) { // if the current post belongs to any Porfolio category
  286. foreach ( $portfolio_pages_array as $portfolio_page_obj ) {
  287. $port_page_ID = $portfolio_page_obj->ID;
  288. if ( post_is_in_category_or_descendants( $udesign_options['portfolio_cat_for_page_'.$port_page_ID] ) ) {
  289. echo get_category_parents_for_portfolio_page( $id, $link, $separator, FALSE , $port_page_ID );
  290. break;
  291. }
  292. }
  293. } else { // if the current category is a regular blog category
  294. echo is_wp_error( $cat_parents = get_category_parents( $id, $link, $separator, FALSE ) ) ? '' : $cat_parents;
  295. }
  296. }
  297. /**
  298. * This is the modified version of the "get_category_parents()" WP function
  299. * Retrieve category parents with separator for use in the Portfolio section to generate proper breadcrumb links.
  300. * The new parameter added is $portfolio_page_id which is the id of the page assigned with the Porfolio page template.
  301. * @since 1.2.0
  302. * @param int $id Category ID.
  303. * @param bool $link Optional, default is false. Whether to format with link.
  304. * @param string $separator Optional, default is '/'. How to separate categories.
  305. * @param bool $nicename Optional, default is false. Whether to use nice name for display.
  306. * @param string $portfolio_page_id Optional. Already linked to categories to prevent duplicates.
  307. * @param array $visited Optional. Already linked to categories to prevent duplicates.
  308. * @return string
  309. */
  310. function get_category_parents_for_portfolio_page( $id, $link = false, $separator = '/', $nicename = false, $portfolio_page_id='', $visited = array() ) {
  311. global $udesign_options;
  312. $chain = '';
  313. $parent = &get_category( $id );
  314. if ( is_wp_error( $parent ) ) return $parent;
  315. $name = ( $nicename ) ? $parent->slug : $parent->cat_name;
  316. if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
  317. $visited[] = $parent->parent;
  318. $chain .= '<a href="'.get_permalink( $portfolio_page_id ).'" title="'.esc_attr( sprintf( __( "Go back to %s", 'udesign' ), get_the_title($portfolio_page_id) ) ).'">'.get_the_title($portfolio_page_id).'</a>' . $separator . ' ';
  319. }
  320. if ( $link ) { // generate comma separated list of categories' links that the current single post has been assigned to
  321. $query_string_prefix = ( get_option('permalink_structure') != '' ) ? '?' : '&amp;';
  322. $categories_names_array = array();
  323. foreach((get_the_category()) as $category) {
  324. if ( ( cat_is_ancestor_of( $udesign_options['portfolio_cat_for_page_'.$portfolio_page_id], $category->term_id ) ||
  325. $udesign_options['portfolio_cat_for_page_'.$portfolio_page_id] == $category->term_id ) ) { // belongs to a category associated with the current portfolio page
  326. if ( preg_match( '/\?/', get_permalink($portfolio_page_id) ) ) $query_string_prefix = '&amp;';
  327. $curr_cat_link = '<a href="'.get_permalink($portfolio_page_id).$query_string_prefix.'cat=' . ( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "Go back to %s", 'udesign' ), $category->cat_name ) ) . '">'.$category->cat_name.'</a>';
  328. array_push( $categories_names_array, $curr_cat_link );
  329. }
  330. }
  331. $chain .= implode( ", ", $categories_names_array ) . $separator;
  332. } else { // generate comma separated list of categories' names that the current single post has been assigned to
  333. $categories_names_array = array();
  334. foreach((get_the_category()) as $category) {
  335. if ( ( cat_is_ancestor_of( $udesign_options['portfolio_cat_for_page_'.$portfolio_page_id], $category->term_id ) ||
  336. $udesign_options['portfolio_cat_for_page_'.$portfolio_page_id] == $category->term_id ) ) { // belongs to a category associated with the current portfolio page
  337. array_push( $categories_names_array, $category->cat_name );
  338. }
  339. }
  340. $chain .= implode( ", ", $categories_names_array ) . $separator;
  341. }
  342. return $chain;
  343. }
  344.  
  345. /**
  346. * Check the validity of the given Phone Numbers (North American)
  347. * This regex will validate a 10-digit North American telephone number.
  348. * Separators are not required, but can include spaces, hyphens, or periods.
  349. * Parentheses around the area code are also optional.
  350. *
  351. * @param string $phone The phone number
  352. * @return bool true if the phone number is valid or false otherwise
  353. */
  354. function isPhoneNumberValid( $phone ) {
  355. // validate a phone number
  356. $pattern = '/^((([0-9]{1})*[- .(]*([0-9]{3})[- .)]*[0-9]{3}[- .]*[0-9]{4})+)*$/';
  357. return preg_match( $pattern, $phone );
  358. }
  359.  
  360.  
  361. // Custom Comment template
  362. function mytheme_comment( $comment, $args, $depth ) {
  363. $GLOBALS['comment'] = $comment;
  364. $template_dir_url = get_bloginfo('template_url'); ?>
  365.  
  366. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
  367. <div id="comment-<?php comment_ID(); ?>">
  368. <div class="comment-meta vcard pngfix">
  369. <div class="avatar-wrapper">
  370. <?php echo get_avatar( $comment, $size='52', $default="{$template_dir_url}/styles/common-images/mystery-man.jpg" ); ?>
  371. </div>
  372. <div class="commentmetadata">
  373. <div class="author"><?php comment_author_link() ?></div>
  374. <?php printf(__('<span class="time">%1$s</span> on <a href="#comment-%2$s" title="">%3$s</a>', 'udesign'), get_comment_time(__('g:i a', 'udesign')), get_comment_ID(), get_comment_date(__('F j, Y', 'udesign')) );
  375. edit_comment_link(esc_html__('edit', 'udesign'),'&nbsp;&nbsp;',''); ?>
  376. </div>
  377. </div>
  378.  
  379. <div class="commenttext">
  380. <?php if ($comment->comment_approved == '0') : ?>
  381. <em><?php esc_html_e('Your comment is awaiting moderation.', 'udesign') ?></em>
  382. <br />
  383. <?php endif; ?>
  384. <?php comment_text() ?>
  385. <div class="reply">
  386. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  387. </div>
  388. </div>
  389.  
  390.  
  391. </div>
  392. <?php
  393. }
  394.  
  395. // Include the posts' count under a category into the a-tag when listing the categories
  396. function posts_count_inside_the_link( $html ) {
  397. $html = preg_replace( '/\<\/a\> \((.*)\)/', ' <span class="posts-counter">($1)</span></a>', $html );
  398. return $html;
  399. }
  400. add_filter('wp_list_categories', 'posts_count_inside_the_link');
  401.  
  402. // Include the posts' count under an archive into the a-tag when listing the categories
  403. function posts_count_inside_archive_link( $html ) {
  404. $html = preg_replace( '/\<\/a\>&nbsp;\((.*)\)/', ' <span class="posts-counter">($1)</span></a>', $html );
  405. return $html;
  406. }
  407. add_filter('get_archives_link', 'posts_count_inside_archive_link');
  408.  
  409. /***************** BEGIN EXCERPTS ******************/
  410. // change the length of excerpts
  411. function new_excerpt_length( $length ) {
  412. global $udesign_options;
  413. return $udesign_options['excerpt_length_in_words'];
  414. }
  415. add_filter('excerpt_length', 'new_excerpt_length');
  416.  
  417. // remove the '[...]'
  418. function moreLink( $content ){
  419. return str_replace( '[...]', '', do_shortcode($content) );
  420. }
  421. add_filter('the_excerpt', 'moreLink');
  422.  
  423. // Custom length of the excerpt in words
  424. function custom_string_length_by_words( $string, $limit ) {
  425. $array_of_words = explode(' ', $string, ($limit + 1));
  426. if( count($array_of_words) > $limit ){
  427. array_pop($array_of_words);
  428. }
  429. return implode(' ', $array_of_words);
  430. }
  431. /***************** END EXCERPTS ******************/
  432.  
  433.  
  434. /***************** BEGIN SHORTCODES ******************/
  435. // Allows shortcodes to be displayed in sidebar widgets
  436. add_filter('widget_text', 'do_shortcode');
  437.  
  438. // Shortcode: "Read More ->" Link.
  439. // Usage: [read_more text="Read more" title="Read More..." url="http://www.some-url-goes-here.com/" align="left" target="_blank"]
  440. function read_more_func( $atts ) {
  441. extract(shortcode_atts(array(
  442. 'text' => esc_html__('Read more', 'udesign'),
  443. 'title' => '',
  444. 'url' => '#',
  445. 'align' => 'left',
  446. 'target' => '',
  447. ), $atts));
  448.  
  449. $target = ($target == '_blank') ? ' target="_blank"' : '';
  450. $align_class = ( $align == 'right' ) ? '-align-right': '-align-left';
  451. $html = '<a class="read-more'.$align_class.'" href="'.$url.'" title="'.$title.'"'.$target.'><span>'.do_shortcode($text).'</span> &rarr;</a>';
  452. return $html;
  453. }
  454. add_shortcode('read_more', 'read_more_func');
  455.  
  456. // Shortcode: Button.
  457. // Usage: [button text="Read more..." style="light" title="Nice Button" url="http://www.some-url-goes-here.com/" align="left" target="_blank"]
  458. function button_func( $atts ) {
  459. extract(shortcode_atts(array(
  460. 'text' => esc_html__('Read more...', 'udesign'),
  461. 'style' => 'dark',
  462. 'title' => '',
  463. 'url' => '#',
  464. 'align' => 'left',
  465. 'target' => '',
  466. ), $atts));
  467.  
  468. $target = ($target == '_blank') ? ' target="_blank"' : '';
  469. $align_class = ( $align == 'right' ) ? ' align-btn-right': ' align-btn-left';
  470. $style_class = ( $style == 'dark' ) ? ' dark-button': ' light-button';
  471. $html = '<div class="clear"></div>
  472. <a class="pngfix'.$style_class.$align_class.'" href="'.$url.'" title="'.$title.'"'.$target.'><span class="pngfix">'.do_shortcode($text).'</span></a>
  473. <div class="clear"></div>';
  474. return $html;
  475. }
  476. add_shortcode('button', 'button_func');
  477.  
  478. // Shortcode: Small Button.
  479. // Usage: [small_button text="Read more..." style="light" title="Nice Button" url="http://www.some-url-goes-here.com/" align="left" target="_blank"]
  480. function small_button_func( $atts ) {
  481. extract(shortcode_atts(array(
  482. 'text' => esc_html__('Read more...', 'udesign'),
  483. 'style' => 'dark',
  484. 'title' => '',
  485. 'url' => '#',
  486. 'align' => 'left',
  487. 'target' => '',
  488. ), $atts));
  489.  
  490. $target = ($target == '_blank') ? ' target="_blank"' : '';
  491. $align_class = ( $align == 'right' ) ? ' align-btn-right': ' align-btn-left';
  492. $style_class = ( $style == 'dark' ) ? ' small-dark-button': ' small-light-button';
  493. $html = '<div class="clear"></div>
  494. <a class="pngfix'.$style_class.$align_class.'" href="'.$url.'" title="'.$title.'"'.$target.'><span class="pngfix">'.do_shortcode($text).'</span></a>
  495. <div class="clear"></div>';
  496. return $html;
  497. }
  498. add_shortcode('small_button', 'small_button_func');
  499.  
  500. // Shortcode: Round Button.
  501. // Usage: [round_button text="Read more..." style="light" title="Nice Button" url="http://www.some-url-goes-here.com/" align="left" target="_blank"]
  502. function round_button_func( $atts ) {
  503. extract(shortcode_atts(array(
  504. 'text' => esc_html__('Read more...', 'udesign'),
  505. 'style' => 'dark',
  506. 'title' => '',
  507. 'url' => '#',
  508. 'align' => 'left',
  509. 'target' => '',
  510. ), $atts));
  511. $target = ($target == '_blank') ? ' target="_blank"' : '';
  512. $align_class = ( $align == 'right' ) ? ' align-btn-right': ' align-btn-left';
  513. $style_class = ( $style == 'dark' ) ? ' dark-round-button': ' light-round-button';
  514. $html = '<div class="clear"></div>
  515. <a class="pngfix'.$style_class.$align_class.'" href="'.$url.'" title="'.$title.'"'.$target.'><span class="pngfix">'.do_shortcode($text).'</span></a>
  516. <div class="clear"></div>';
  517. return $html;
  518. }
  519. add_shortcode('round_button', 'round_button_func');
  520.  
  521. // Shortcode: Custom Button.
  522. // Usage: [custom_button text="Read more..." title="Nice Button" url="http://www.some-url-goes-here.com/" size="medium" bg_color="#FF5C00" text_color="#FFFFFF" align="left" target="_blank"]
  523. // Options: align: left or right, size: small, medium, large and x-large, the rest are self explanatory...
  524. function custom_button_func( $atts ) {
  525. extract(shortcode_atts(array(
  526. 'text' => esc_html__('Read more...', 'udesign'),
  527. 'title' => '',
  528. 'url' => '#',
  529. 'size' => 'medium',
  530. 'bg_color' => '#FF5C00',
  531. 'text_color' => '#FFFFFF',
  532. 'align' => 'left',
  533. 'target' => '',
  534. ), $atts));
  535. $target = ($target == '_blank') ? ' target="_blank"' : '';
  536. $align_class = ( $align == 'right' ) ? ' align-btn-right': ' align-btn-left';
  537. $html = '
  538. <a class="'.strtolower($size).' custom-button'.$align_class.'" href="'.$url.'" title="'.$title.'"'.$target.'><span style="background-color:'.$bg_color.'; color:'.$text_color.'">'.do_shortcode($text).'</span></a>
  539. ';
  540. return $html;
  541. }
  542. add_shortcode('custom_button', 'custom_button_func');
  543.  
  544. // Shortcode: Divider with an anchor link to top of page.
  545. // Usage: [divider]
  546. function divider_func( $atts ) {
  547. return '<div class="divider"></div>';
  548. }
  549. add_shortcode('divider', 'divider_func');
  550.  
  551. // Shortcode: Divider with an anchor link to top of page.
  552. // Usage: [divider_top]
  553. function divider_top_func( $atts ) {
  554. return '<div class="divider top-of-page"><a href="#top" title="'.esc_html__('Top of Page', 'udesign').'">'.esc_html__('Back to Top', 'udesign').'</a></div>';
  555. }
  556. add_shortcode('divider_top', 'divider_top_func');
  557.  
  558. // Shortcode: Clear , used to clear an element of its neighbors, no floating elements are allowed on the left or the right side.
  559. // Usage: [clear]
  560. function clear_func( $atts ) {
  561. return '<div class="clear"></div>';
  562. }
  563. add_shortcode('clear', 'clear_func');
  564.  
  565. // Shortcode: Mesage Box. Predefined and custom.
  566. // Usage (pre-defined): [message type="info"]Your info message goes here...[/message]
  567. // there are 4 pre-set message types: "info", "success", "warning", "erroneous"
  568. // Usage (custom): [message type="custom" width="100%" start_color="#FFFFFF" end_color="#EEEEEE" border="#BBBBBB" color="#333333"]Your info message goes here...[/message]
  569. // width could be in pixels as well, e.g. width="250px"
  570. // Usage (simple): [message type="simple" bg_color="#EEEEEE" color="#333333"]Your info message goes here...[/message]
  571. function message_box_func( $atts, $content = null ) {
  572. extract(shortcode_atts(array(
  573. 'type' => 'custom',
  574. 'align' => 'left',
  575. 'start_color' => '#FFFFFF',
  576. 'end_color' => '#EEEEEE',
  577. 'border' => '#BBBBBB',
  578. 'width' => '100%',
  579. 'color' => '#333333',
  580. 'bg_color' => '#F5F5F5',
  581. ), $atts));
  582. if ($type == 'custom') {
  583. if ($align == 'center') {
  584. $margin_left = $margin_right = 'auto !important';
  585. } elseif ($align == 'right') {
  586. $margin_left = 'auto !important';
  587. $margin_right = '0 !important';
  588. } else { // default: LEFT
  589. $margin_left = $margin_right = '0 !important';
  590. }
  591. $html = '<div class="'.$type.'" style="background:-moz-linear-gradient(center top , '.$start_color.', '.$end_color.') repeat scroll 0 0 transparent;
  592. background: -webkit-gradient(linear, center top, center bottom, from('.$start_color.'), to('.$end_color.'));
  593. background: -o-linear-gradient(top, '.$start_color.' 0%,'.$end_color.' 99%); /* Opera 11.10+ */
  594. background: -ms-linear-gradient(top, '.$start_color.' 0%,'.$end_color.' 99%); /* IE10+ */
  595. margin-left:'.$margin_left.';
  596. margin-right:'.$margin_right.';
  597. border:1px solid '.$border.';
  598. background-color: '.$end_color.';
  599. width:'.$width.';
  600. color:'.$color.';"><div class="inner-padding">'.do_shortcode($content).'</div></div>';
  601. } elseif ($type == 'simple') {
  602. $html = '<div class="'.$type.'" style="background-color:'.$bg_color.'; color:'.$color.';"><div class="inner-padding">'.do_shortcode($content).'</div></div>';
  603. } else {
  604. $html = '<div class="'.$type.'"><div class="msg-box-icon pngfix">'.do_shortcode($content).'</div></div>';
  605. }
  606. return $html;
  607. }
  608. add_shortcode('message', 'message_box_func');
  609.  
  610. // Shortcode: PullQuote.
  611. // Usage: [pullquote style="left" quote="light"], style options: 'left', 'right'; quote options: 'light' (optional), otherwise defaults to dark style
  612. function pullquote_func( $atts, $content = null ) {
  613. extract(shortcode_atts(array(
  614. 'style' => 'left',
  615. 'quote' => 'dark',
  616. ), $atts));
  617. $align = ($style == 'right') ? 'alignright' : 'alignleft';
  618. $quote_color = ($quote == 'light') ? ' bq-light' : '';
  619. return '<blockquote class="'.$align.$quote_color.'">'.do_shortcode($content).'</blockquote>';
  620. }
  621. add_shortcode('pullquote', 'pullquote_func');
  622.  
  623. // Shortcode: Dropcap
  624. // Usage: [dropcap]A[/dropcap]
  625. function dropcap_func( $atts, $content = null ) {
  626. return '<span class="dropcap">'.$content.'</span>';
  627. }
  628. add_shortcode('dropcap', 'dropcap_func');
  629.  
  630. // Shortcode: one_fourth
  631. // Usage: [one_fourth]Content goes here...[/one_fourth]
  632. function one_fourth_func( $atts, $content = null ) {
  633. return '<div class="one_fourth">'.do_shortcode($content).'</div>';
  634. }
  635. add_shortcode('one_fourth', 'one_fourth_func');
  636.  
  637. // Shortcode: one_fourth_last
  638. // Usage: [one_fourth_last]Content goes here...[/one_fourth_last]
  639. function one_fourth_last_func( $atts, $content = null ) {
  640. return '<div class="one_fourth last_column">'.do_shortcode($content).'</div>';
  641. }
  642. add_shortcode('one_fourth_last', 'one_fourth_last_func');
  643.  
  644. // Shortcode: one_third
  645. // Usage: [one_third]Content goes here...[/one_third]
  646. function one_third_func( $atts, $content = null ) {
  647. return '<div class="one_third">'.do_shortcode($content).'</div>';
  648. }
  649. add_shortcode('one_third', 'one_third_func');
  650.  
  651. // Shortcode: one_third_last
  652. // Usage: [one_third_last]Content goes here...[/one_third_last]
  653. function one_third_last_func( $atts, $content = null ) {
  654. return '<div class="one_third last_column">'.do_shortcode($content).'</div>';
  655. }
  656. add_shortcode('one_third_last', 'one_third_last_func');
  657.  
  658. // Shortcode: one_half
  659. // Usage: [one_half]Content goes here...[/one_half]
  660. function one_half_func( $atts, $content = null ) {
  661. return '<div class="one_half">'.do_shortcode($content).'</div>';
  662. }
  663. add_shortcode('one_half', 'one_half_func');
  664.  
  665. // Shortcode: one_half_last
  666. // Usage: [one_half_last]Content goes here...[/one_half_last]
  667. function one_half_last_func( $atts, $content = null ) {
  668. return '<div class="one_half last_column">'.do_shortcode($content).'</div>';
  669. }
  670. add_shortcode('one_half_last', 'one_half_last_func');
  671.  
  672. // Shortcode: two_third
  673. // Usage: [two_third]Content goes here...[/two_third]
  674. function two_third_func( $atts, $content = null ) {
  675. return '<div class="two_third">'.do_shortcode($content).'</div>';
  676. }
  677. add_shortcode('two_third', 'two_third_func');
  678.  
  679. // Shortcode: two_third_last
  680. // Usage: [two_third_last]Content goes here...[/two_third_last]
  681. function two_third_last_func( $atts, $content = null ) {
  682. return '<div class="two_third last_column">'.do_shortcode($content).'</div>';
  683. }
  684. add_shortcode('two_third_last', 'two_third_last_func');
  685.  
  686. // Shortcode: three_fourth
  687. // Usage: [three_fourth]Content goes here...[/three_fourth]
  688. function three_fourth_func( $atts, $content = null ) {
  689. return '<div class="three_fourth">'.do_shortcode($content).'</div>';
  690. }
  691. add_shortcode('three_fourth', 'three_fourth_func');
  692.  
  693. // Shortcode: three_fourth_last
  694. // Usage: [three_fourth_last]Content goes here...[/three_fourth_last]
  695. function three_fourth_last_func( $atts, $content = null ) {
  696. return '<div class="three_fourth last_column">'.do_shortcode($content).'</div>';
  697. }
  698. add_shortcode('three_fourth_last', 'three_fourth_last_func');
  699.  
  700. // Shortcode: toggle_content
  701. // Usage: [toggle_content title="Title"]Your content goes here...[/toggle_content]
  702. function toggle_content_func( $atts, $content = null ) {
  703. extract(shortcode_atts(array(
  704. 'title' => '',
  705. ), $atts));
  706. $html = '<h4 class="slide_toggle"><a href="#">' .$title. '</a></h4>';
  707. $html .= '<div class="slide_toggle_content" style="display: none;">'.do_shortcode($content).'</div>';
  708. return $html;
  709. }
  710. add_shortcode('toggle_content', 'toggle_content_func');
  711.  
  712. // Shortcode: tab
  713. // Usage: [tab title="title 1"]Your content goes here...[/tab]
  714. function tab_func( $atts, $content = null ) {
  715. extract(shortcode_atts(array(
  716. 'title' => '',
  717. ), $atts));
  718. global $single_tab_array;
  719. $single_tab_array[] = array('title' => $title, 'content' => trim(do_shortcode($content)));
  720. return $single_tab_array;
  721. }
  722. add_shortcode('tab', 'tab_func');
  723.  
  724. /* Shortcode: tabs
  725. * Usage: [tabs]
  726. * [tab title="title 1"]Your content goes here...[/tab]
  727. * [tab title="title 2"]Your content goes here...[/tab]
  728. * [/tabs]
  729. */
  730. function tabs_func( $atts, $content = null ) {
  731. global $single_tab_array;
  732. $single_tab_array = array(); // clear the array
  733.  
  734. $tabs_nav = '<div class="clear"></div>';
  735. $tabs_nav .= '<div class="tabs-wrapper">';
  736. $tabs_nav .= '<ul class="tabs">';
  737. do_shortcode($content); // execute the '[tab]' shortcode first to get the title and content
  738. foreach ($single_tab_array as $tab => $tab_attr_array) {
  739. $random_id = rand(1000,2000);
  740. $default = ( $tab == 0 ) ? ' class="defaulttab"' : '';
  741. $tabs_nav .= '<li><a href="javascript:void(0)"'.$default.' rel="tab'.$random_id.'"><span>'.$tab_attr_array['title'].'</span></a></li>';
  742. $tabs_content .= '<div class="tab-content" id="tab'.$random_id.'"><div class="tabs-inner-padding">'.$tab_attr_array['content'].'</div></div>';
  743. }
  744. $tabs_nav .= '</ul>';
  745. $tabs_output .= $tabs_nav . $tabs_content;
  746. $tabs_output .= '</div><!-- tabs-wrapper end -->';
  747. $tabs_output .= '<div class="clear"></div>';
  748. return $tabs_output;
  749. }
  750. add_shortcode('tabs', 'tabs_func');
  751.  
  752. // Shortcode: accordion_toggle
  753. // Usage: [accordion_toggle title="title 1"]Your content goes here...[/accordion_toggle]
  754. function accordion_toggle_func( $atts, $content = null ) {
  755. extract(shortcode_atts(array(
  756. 'title' => '',
  757. ), $atts));
  758. global $single_accordion_toggle_array;
  759. $single_accordion_toggle_array[] = array('title' => $title, 'content' => trim(do_shortcode($content)));
  760. return $single_accordion_toggle_array;
  761. }
  762. add_shortcode('accordion_toggle', 'accordion_toggle_func');
  763.  
  764. /* Shortcode: accordion
  765. * Usage: [accordion]
  766. * [accordion_toggle title="title 1"]Your content goes here...[/accordion_toggle]
  767. * [accordion_toggle title="title 2"]Your content goes here...[/accordion_toggle]
  768. * [/accordion]
  769. */
  770. function accordion_func( $atts, $content = null ) {
  771. global $single_accordion_toggle_array;
  772. $single_accordion_toggle_array = array(); // clear the array
  773.  
  774. $accordion_output = '<div class="clear"></div>';
  775. $accordion_output .= '<div class="accordion-wrapper">';
  776. do_shortcode($content); // execute the '[accordion_toggle]' shortcode first to get the title and content
  777. foreach ($single_accordion_toggle_array as $tab => $accordion_toggle_attr_array) {
  778. $accordion_output .= '<h3 class="accordion-toggle"><a href="#">'.$accordion_toggle_attr_array['title'].'</a></h3>';
  779. $accordion_output .= '<div class="accordion-container">';
  780. $accordion_output .= ' <div class="content-block">'.$accordion_toggle_attr_array['content'].'</div>';
  781. $accordion_output .= '</div><!-- end accordion-container -->';
  782. }
  783. $accordion_output .= '</div><!-- end accordion-wrapper -->';
  784. $accordion_output .= '<div class="clear"></div>';
  785. return $accordion_output;
  786. }
  787. add_shortcode('accordion', 'accordion_func');
  788.  
  789. // Shortcode: list
  790. // Usage: [custom_list style="list-1"]List html goes here...[/custom_list]
  791. function custom_list_func( $atts, $content = null ) {
  792. extract(shortcode_atts(array(
  793. 'style' => 'list-1',
  794. ), $atts));
  795. $content = str_replace('<ul>', '<ul class="'.$style.'">', do_shortcode($content));
  796. return $content;
  797. }
  798. add_shortcode('custom_list', 'custom_list_func');
  799.  
  800. // Shortcode: custom_table
  801. // Usage: [custom_table]Table html goes here...[/custom_table]
  802. function custom_table_func( $atts, $content = null ) {
  803. $content = str_replace('<table', '<table class="custom-table" ', do_shortcode($content));
  804. return $content;
  805. }
  806. add_shortcode('custom_table', 'custom_table_func');
  807.  
  808. // Shortcode: custom_frame_left
  809. // Usage: [custom_frame_left]<img src="http://image-url-path-goes-here.jpg"/>[/custom_frame_left]
  810. // Options: shadow="on"
  811. function custom_frame_left_func( $atts, $content = null ) {
  812. extract(shortcode_atts(array(
  813. 'shadow' => 'off',
  814. ), $atts));
  815. $shadow_class = ($shadow == 'off') ? '': ' frame-shadow';
  816. $content = preg_replace('/\n|\r|<br>|<br \/>|alignleft|alignright/','',$content); // remove new line and carriage return characters accidentally added by user
  817. $content = preg_replace('/aligncenter|alignleft|alignright/','alignnone',$content); // replaces the 'aligncenter','alignleft' and 'alignright' classes added to img with 'alignnone'
  818. return '<span class="custom-frame alignleft'.$shadow_class.'">' . do_shortcode($content) . '</span>';
  819. }
  820. add_shortcode('custom_frame_left', 'custom_frame_left_func');
  821.  
  822. // Shortcode: custom_frame_right
  823. // Usage: [custom_frame_right]<img src="http://image-url-path-goes-here.jpg"/>[/custom_frame_right]
  824. // Options: shadow="on"
  825. function custom_frame_right_func( $atts, $content = null ) {
  826. extract(shortcode_atts(array(
  827. 'shadow' => 'off',
  828. ), $atts));
  829. $shadow_class = ($shadow == 'off') ? '': ' frame-shadow';
  830. $content = preg_replace('/\n|\r|<br>|<br \/>|alignleft|alignright/','',$content); // remove new line and carriage return characters accidentally added by user
  831. $content = preg_replace('/aligncenter|alignleft|alignright/','alignnone',$content); // replaces the 'aligncenter','alignleft' and 'alignright' classes added to img with 'alignnone'
  832. return '<span class="custom-frame alignright'.$shadow_class.'">' . do_shortcode($content) . '</span>';
  833. }
  834. add_shortcode('custom_frame_right', 'custom_frame_right_func');
  835.  
  836. // Shortcode: custom_frame_center
  837. // Usage: [custom_frame_center]<img src="http://image-url-path-goes-here.jpg"/>[/custom_frame_center]
  838. // Options: shadow="on"
  839. function custom_frame_center_func( $atts, $content = null ) {
  840. extract(shortcode_atts(array(
  841. 'shadow' => 'off',
  842. ), $atts));
  843. $shadow_class = ($shadow == 'off') ? '': ' frame-shadow';
  844. $content = preg_replace('/\n|\r|<br>|<br \/>|alignleft|alignright/','',$content); // remove new line and carriage return characters accidentally added by user
  845. $content = preg_replace('/aligncenter|alignleft|alignright/','alignnone',$content); // replaces the 'aligncenter','alignleft' and 'alignright' classes added to img with 'alignnone'
  846. return '<div style="text-align:center;"><span class="custom-frame aligncenter'.$shadow_class.'">' . do_shortcode($content) . '</span></div>';
  847. }
  848. add_shortcode('custom_frame_center', 'custom_frame_center_func');
  849.  
  850. /*
  851. * Shortcode: udesign_recent_posts
  852. * Usage: [udesign_recent_posts]
  853. * Options: title="Recent Posts" category_id="9" num_posts="3" post_offset="0" num_words_limit="23" show_date_author="1" show_more_link="0" show_thumbs="1" thumb_frame_shadow="1" post_thumb_width="120" post_thumb_height="60"
  854. */
  855. function udesign_recent_posts_func( $atts, $content = null) {
  856. global $wp_widget_factory;
  857. extract(shortcode_atts(array(
  858. 'title' => esc_html__('Latest Posts', 'udesign'),
  859. 'category_id' => '',
  860. 'num_posts' => 3,
  861. 'post_offset' => 0,
  862. 'num_words_limit' => 13,
  863. 'show_date_author' => false,
  864. 'show_more_link' => false,
  865. 'show_thumbs' => true,
  866. 'thumb_frame_shadow' => false,
  867. 'post_thumb_width' => 60,
  868. 'post_thumb_height' => 60
  869. ), $atts));
  870. $widget_name = esc_html('Latest_Posts_Widget');
  871. $id = $category_id;
  872. if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
  873. $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
  874.  
  875. if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  876. return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct", 'udesign'),'<strong>'.$class.'</strong>').'</p>';
  877. else:
  878. $class = $wp_class;
  879. endif;
  880. endif;
  881. ob_start();
  882. the_widget( $widget_name,
  883. array(
  884. 'title' => esc_html($title),
  885. 'category_id' => $category_id,
  886. 'num_posts' => $num_posts,
  887. 'post_offset' => $post_offset,
  888. 'num_words_limit' => $num_words_limit,
  889. 'show_date_author' => $show_date_author,
  890. 'show_more_link' => $show_more_link,
  891. 'show_thumbs' => $show_thumbs,
  892. 'thumb_frame_shadow' => $thumb_frame_shadow,
  893. 'post_thumb_width' => $post_thumb_width,
  894. 'post_thumb_height' => $post_thumb_height
  895. ),
  896. array(
  897. 'widget_id'=>'arbitrary-instance-'.$id,
  898. 'before_widget' => '<div class="widget widget_latest_posts">',
  899. 'after_widget' => '</div>',
  900. 'before_title' => '<h3 class="widgettitle">',
  901. 'after_title' => '</h3>'
  902. )
  903. );
  904. $output = ob_get_contents();
  905. ob_end_clean();
  906. return $output;
  907.  
  908. }
  909. add_shortcode('udesign_recent_posts','udesign_recent_posts_func');
  910.  
  911.  
  912. /***************** END SHORTCODES ******************/
  913.  
  914.  
  915.  
  916. /**
  917. * Checks whether a dynamic sidebar exists
  918. *
  919. * @param string $sidebar_name, sidebar name
  920. * @return bool True, if sidebar exists. False otherwise.
  921. */
  922. function sidebar_exist( $sidebar_name ) {
  923. global $wp_registered_sidebars;
  924. foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
  925. if ( in_array($sidebar_name, $sidebar) )
  926. return true;
  927. }
  928. return false;
  929. }
  930.  
  931. /**
  932. * Checks whether a dynamic sidebar exists and if is active (has any widgets)
  933. *
  934. * @param string $sidebar_name, sidebar name
  935. * @return bool True, if exists and active (using widgets). False otherwise.
  936. */
  937. function sidebar_exist_and_active( $sidebar_name ) {
  938. global $wp_registered_sidebars;
  939. foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
  940. if ( in_array($sidebar_name, $sidebar) ) {
  941. return is_active_sidebar( $sidebar['id'] );
  942. }
  943. }
  944. return false;
  945. }
  946.  
  947. /* Widget Settings */
  948.  
  949. function recent_comment_author_link( $return ) {
  950. return str_replace( $return, "<span></span>$return", $return );
  951. }
  952. add_filter('get_comment_author_link', 'recent_comment_author_link');
  953.  
  954. function filter_widget( $params ) {
  955. switch( _get_widget_id_base($params[0]['widget_id']) ) {
  956. case 'recent-posts':
  957. case 'categories':
  958. case 'archives':
  959. case 'pages':
  960. case 'links':
  961. case 'meta':
  962. case 'custom-category-widget': // U-Design: Custom Category
  963. case 'loginform-widget': // U-Design: Login Form
  964. case 'subpages-widget': // U-Design: Subpages
  965. case 'nav_menu': // WP 3 widget menu support
  966. $params[0]['before_widget'] = str_replace( 'substitute_widget_class', 'custom-formatting', $params[0]['before_widget'] ); // add the 'custom-formatting' class
  967. return $params;
  968. break;
  969. case 'rss':
  970. $params[0]['before_widget'] = str_replace( 'substitute_widget_class', 'custom-rss-formatting', $params[0]['before_widget'] ); // add the 'custom-formatting' class
  971. return $params;
  972. break;
  973. default:
  974. //var_dump( _get_widget_id_base($params[0]['widget_id']) );
  975. //var_dump( $params );
  976. return $params;
  977. }
  978. }
  979. add_filter('dynamic_sidebar_params','filter_widget');
  980.  
  981. if ( function_exists('register_sidebar') ) {
  982. register_sidebar(array(
  983. 'name' => 'Pages Sidebar',
  984. 'description' => esc_html__('A widget area, used as a sidebar for regular pages.', 'udesign'),
  985. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  986. 'after_widget' => '</div>',
  987. 'before_title' => '<h3 class="widgettitle">',
  988. 'after_title' => '</h3>',
  989. ));
  990.  
  991. register_sidebar(array(
  992. 'name' => 'PortfolioSidebar',
  993. 'description' => esc_html__('A widget area, used as a sidebar for the Portfolio section.', 'udesign'),
  994. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  995. 'after_widget' => '</div>',
  996. 'before_title' => '<h3 class="widgettitle">',
  997. 'after_title' => '</h3>',
  998. ));
  999.  
  1000. register_sidebar(array(
  1001. 'name' => 'BlogSidebar',
  1002. 'description' => esc_html__('A widget area, used as a sidebar for the Blog/News section.', 'udesign'),
  1003. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1004. 'after_widget' => '</div>',
  1005. 'before_title' => '<h3 class="widgettitle">',
  1006. 'after_title' => '</h3>',
  1007. ));
  1008.  
  1009. register_sidebar(array(
  1010. 'name' => 'ContactSidebar',
  1011. 'description' => esc_html__('A widget area, used as a sidebar for the Contact page.', 'udesign'),
  1012. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1013. 'after_widget' => '</div>',
  1014. 'before_title' => '<h3 class="widgettitle">',
  1015. 'after_title' => '</h3>',
  1016. ));
  1017.  
  1018. register_sidebar(array(
  1019. 'name' => 'SitemapSidebar',
  1020. 'description' => esc_html__('A widget area, used as a sidebar for the Sitemap page.', 'udesign'),
  1021. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1022. 'after_widget' => '</div>',
  1023. 'before_title' => '<h3 class="widgettitle">',
  1024. 'after_title' => '</h3>',
  1025. ));
  1026.  
  1027. // Front Page Before Content Widget Area
  1028. register_sidebar(array(
  1029. 'name' => esc_html__('Home Page Before Content', 'udesign'),
  1030. 'id' => 'home-page-before-content',
  1031. 'description' => esc_html__('A widget area positioned just above the Home Page Main Content area.', 'udesign'),
  1032. 'before_widget' => '<div class="cont_col_1 %2$s substitute_widget_class">',
  1033. 'after_widget' => '</div>',
  1034. 'before_title' => '<h3 class="before_cont_title">',
  1035. 'after_title' => '</h3>',
  1036. ));
  1037.  
  1038. // Front Page Content Widget Areas
  1039. register_sidebar(array(
  1040. 'name' => esc_html__('Home Page Column 1', 'udesign'),
  1041. 'id' => 'home-page-column-1',
  1042. 'description' => esc_html__('A widget area, used as the 1st column in the Main Content area.', 'udesign'),
  1043. 'before_widget' => '<div class="cont_col_1 %2$s substitute_widget_class">',
  1044. 'after_widget' => '</div>',
  1045. 'before_title' => '<h3 class="cont_col_1_title">',
  1046. 'after_title' => '</h3>',
  1047. ));
  1048.  
  1049. register_sidebar(array(
  1050. 'name' => esc_html__('Home Page Column 2', 'udesign'),
  1051. 'id' => 'home-page-column-2',
  1052. 'description' => esc_html__('A widget area, used as the 2nd column in the Main Content area.', 'udesign'),
  1053. 'before_widget' => '<div class="cont_col_2 %2$s substitute_widget_class">',
  1054. 'after_widget' => '</div>',
  1055. 'before_title' => '<h3 class="cont_col_2_title">',
  1056. 'after_title' => '</h3>',
  1057. ));
  1058.  
  1059. register_sidebar(array(
  1060. 'name' => esc_html__('Home Page Column 3', 'udesign'),
  1061. 'id' => 'home-page-column-3',
  1062. 'description' => esc_html__('A widget area, used as the 3rd column in the Main Content area.', 'udesign'),
  1063. 'before_widget' => '<div class="cont_col_3 %2$s substitute_widget_class">',
  1064. 'after_widget' => '</div>',
  1065. 'before_title' => '<h3 class="cont_col_3_title">',
  1066. 'after_title' => '</h3>',
  1067. ));
  1068.  
  1069. register_sidebar(array(
  1070. 'name' => esc_html__('Home Page Column 4', 'udesign'),
  1071. 'id' => 'home-page-column-4',
  1072. 'description' => esc_html__('A widget area, used as the 4th column in the Main Content area.', 'udesign'),
  1073. 'before_widget' => '<div class="cont_col_4 %2$s substitute_widget_class">',
  1074. 'after_widget' => '</div>',
  1075. 'before_title' => '<h3 class="cont_col_4_title">',
  1076. 'after_title' => '</h3>',
  1077. ));
  1078.  
  1079. // Front Page After Content Row 1 Widget Area
  1080. register_sidebar(array(
  1081. 'name' => esc_html__('Home Page After Content Row 1', 'udesign'),
  1082. 'id' => 'home-page-after-content-row-1',
  1083. 'description' => esc_html__('A widget area positioned just below the Home Page Main Content area.', 'udesign'),
  1084. 'before_widget' => '<div class="after_cont_row_1 %2$s substitute_widget_class">',
  1085. 'after_widget' => '</div>',
  1086. 'before_title' => '<h3 class="after_cont_row_1_title">',
  1087. 'after_title' => '</h3>',
  1088. ));
  1089.  
  1090. // Front Page After Content Row 2 Widget Area
  1091. register_sidebar(array(
  1092. 'name' => esc_html__('Home Page After Content Row 2', 'udesign'),
  1093. 'id' => 'home-page-after-content-row-2',
  1094. 'description' => esc_html__('A widget area positioned just above the Bottom Widget area.', 'udesign'),
  1095. 'before_widget' => '<div class="after_cont_row_2 %2$s substitute_widget_class">',
  1096. 'after_widget' => '</div>',
  1097. 'before_title' => '<h3 class="after_cont_row_2_title">',
  1098. 'after_title' => '</h3>',
  1099. ));
  1100.  
  1101. // Bottom Widget Areas
  1102. register_sidebar(array(
  1103. 'name' => esc_html__('Bottom 1', 'udesign'),
  1104. 'id' => 'bottom-widget-area-1',
  1105. 'description' => esc_html__('A widget area, used as the 1st column in the Bottom area (just above the footer).', 'udesign'),
  1106. 'before_widget' => '<div class="bottom-col-content %2$s substitute_widget_class">',
  1107. 'before_title' => '<h3 class="bottom-col-title">',
  1108. 'after_title' => '</h3>',
  1109. 'after_widget' => '</div>',
  1110. ));
  1111.  
  1112. register_sidebar(array(
  1113. 'name' => esc_html__('Bottom 2', 'udesign'),
  1114. 'id' => 'bottom-widget-area-2',
  1115. 'description' => esc_html__('A widget area, used as the 2nd column in the Bottom area (just above the footer).', 'udesign'),
  1116. 'before_widget' => '<div class="bottom-col-content %2$s substitute_widget_class">',
  1117. 'before_title' => '<h3 class="bottom-col-title">',
  1118. 'after_title' => '</h3>',
  1119. 'after_widget' => '</div>',
  1120. ));
  1121.  
  1122. register_sidebar(array(
  1123. 'name' => esc_html__('Bottom 3', 'udesign'),
  1124. 'id' => 'bottom-widget-area-3',
  1125. 'description' => esc_html__('A widget area, used as the 3rd column in the Bottom area (just above the footer).', 'udesign'),
  1126. 'before_widget' => '<div class="bottom-col-content %2$s substitute_widget_class">',
  1127. 'before_title' => '<h3 class="bottom-col-title">',
  1128. 'after_title' => '</h3>',
  1129. 'after_widget' => '</div>',
  1130. ));
  1131.  
  1132. register_sidebar(array(
  1133. 'name' => esc_html__('Bottom 4', 'udesign'),
  1134. 'id' => 'bottom-widget-area-4',
  1135. 'description' => esc_html__('A widget area, used as the 4th column in the Bottom area (just above the footer).', 'udesign'),
  1136. 'before_widget' => '<div class="bottom-col-content %2$s substitute_widget_class">',
  1137. 'before_title' => '<h3 class="bottom-col-title">',
  1138. 'after_title' => '</h3>',
  1139. 'after_widget' => '</div>',
  1140. ));
  1141.  
  1142. register_sidebar(array(
  1143. 'name' => 'PagesSidebar2',
  1144. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 2.', 'udesign'),
  1145. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1146. 'after_widget' => '</div>',
  1147. 'before_title' => '<h3 class="widgettitle">',
  1148. 'after_title' => '</h3>',
  1149. ));
  1150.  
  1151. register_sidebar(array(
  1152. 'name' => 'PagesSidebar3',
  1153. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 3.', 'udesign'),
  1154. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1155. 'after_widget' => '</div>',
  1156. 'before_title' => '<h3 class="widgettitle">',
  1157. 'after_title' => '</h3>',
  1158. ));
  1159.  
  1160. register_sidebar(array(
  1161. 'name' => 'PagesSidebar4',
  1162. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 4.', 'udesign'),
  1163. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1164. 'after_widget' => '</div>',
  1165. 'before_title' => '<h3 class="widgettitle">',
  1166. 'after_title' => '</h3>',
  1167. ));
  1168.  
  1169. register_sidebar(array(
  1170. 'name' => 'PagesSidebar5',
  1171. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 5.', 'udesign'),
  1172. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1173. 'after_widget' => '</div>',
  1174. 'before_title' => '<h3 class="widgettitle">',
  1175. 'after_title' => '</h3>',
  1176. ));
  1177.  
  1178. register_sidebar(array(
  1179. 'name' => 'PagesSidebar6',
  1180. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 6.', 'udesign'),
  1181. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1182. 'after_widget' => '</div>',
  1183. 'before_title' => '<h3 class="widgettitle">',
  1184. 'after_title' => '</h3>',
  1185. ));
  1186.  
  1187. register_sidebar(array(
  1188. 'name' => 'PagesSidebar7',
  1189. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 7.', 'udesign'),
  1190. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1191. 'after_widget' => '</div>',
  1192. 'before_title' => '<h3 class="widgettitle">',
  1193. 'after_title' => '</h3>',
  1194. ));
  1195.  
  1196. register_sidebar(array(
  1197. 'name' => 'PagesSidebar8',
  1198. 'description' => esc_html__('A widget area, used as a sidebar for the Page Template 8.', 'udesign'),
  1199. 'before_widget' => '<div id="%1$s" class="widget %2$s substitute_widget_class">',
  1200. 'after_widget' => '</div>',
  1201. 'before_title' => '<h3 class="widgettitle">',
  1202. 'after_title' => '</h3>',
  1203. ));
  1204.  
  1205. // Top Area Social Media Widget Area
  1206. register_sidebar(array(
  1207. 'name' => esc_html__('Top Area Social Media', 'udesign'),
  1208. 'id' => 'top-area-social-media',
  1209. 'description' => esc_html__('A widget area positioned in the top right corner of the site designated for social media links and icons.', 'udesign'),
  1210. 'before_widget' => '<div class="social_media_top %2$s substitute_widget_class">',
  1211. 'after_widget' => '</div>',
  1212. 'before_title' => '<h3 class="social_media_title">',
  1213. 'after_title' => '</h3>',
  1214. ));
  1215.  
  1216. }
  1217.  
  1218.  
  1219. /* Custom widgets... */
  1220. include ('widgets/loginForm-widget.php');
  1221. include ('widgets/customCategory-widget.php');
  1222. include ('widgets/googleMap-widget.php');
  1223. include ('widgets/latestPost-widget.php');
  1224. include ('widgets/subpages-widget.php');
  1225.  
  1226. // Return the column (widget area) HTML
  1227. function get_dynamic_column( $id = '', $class = '', $widget_area = '' ) {
  1228. return "<div id='{$id}' class='{$class}'><div class='column-content-wrapper'>".udesign_get_dynamic_sidebar( $widget_area )."</div></div><!-- end {$id} -->";
  1229. }
  1230. // Currently there is no available function to return the contents of a dynamic sidebar. Therefore use this one:
  1231. function udesign_get_dynamic_sidebar($index = '') {
  1232. $sidebar_contents = "";
  1233. ob_start();
  1234. if ( function_exists('dynamic_sidebar') && dynamic_sidebar( $index ) )
  1235. $sidebar_contents = ob_get_clean();
  1236. return $sidebar_contents;
  1237. }
  1238.  
  1239.  
  1240. /* Load the U-Design Options Page */
  1241. include( 'udesign_options_page.php' );
  1242.  
  1243. // Remove meta name="generator" content="WordPress" from the <head>
  1244. remove_action('wp_head', 'wp_generator');
  1245.  
  1246. // Add support for post featured image. To add this feature to other post types, add those new types to the array, e.g. array( 'post', 'page', 'movies' )
  1247. if ( function_exists( 'add_theme_support' ) ) {
  1248. add_theme_support( 'post-thumbnails', array( 'post', 'page', 'movie' ) );
  1249. }
  1250.  
  1251. // Filter the "Featured Image" with this theme's custom image frame with alignment. Can be enabled from the theme's "Blog Section".
  1252. if ( $udesign_options['enable_custom_featured_image'] == 'yes' ) {
  1253. function my_post_image_html( $html, $post_id, $post_image_id ) {
  1254. $html = preg_replace('/title=\"(.*?)\"/', '', $html);
  1255. preg_match( '/aligncenter|alignleft|alignright/', $html, $matches );
  1256. $image_alignment = $matches[0];
  1257. $html = preg_replace('/aligncenter|alignleft|alignright/', 'alignnone', $html);
  1258. $html = '<span class="custom-frame '.$image_alignment.'"><a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a></span>';
  1259. if( $image_alignment == 'aligncenter' ) $html = '<div style="text-align:center;">'.$html.'</div>';
  1260. return $html;
  1261. }
  1262. add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );
  1263. }
  1264. // This function is used in processing images (cutting, cropping, zoom)
  1265. if ( !function_exists('udesign_process_image') ) {
  1266. function udesign_process_image( $img_source, $img_width, $img_height, $zc = 1, $q = 100 ) {
  1267. global $udesign_options;
  1268. if ( $udesign_options['disable_timthumb'] != 'yes' ) {
  1269. $img_source = get_bloginfo("template_directory").'/scripts/timthumb.php?src='.$img_source.'&amp;w='.$img_width.'&amp;h='.$img_height.'&amp;zc='.$zc.'&amp;q='.$q;
  1270. }
  1271. return $img_source;
  1272. }
  1273. }
  1274. /**
  1275. * Customize image dimension and apply custom image frame with alignment
  1276. * @param int $post_id Post ID.
  1277. * @param string $img_src Image URL.
  1278. * @param string $width Image width.
  1279. * @param string $height Image height.
  1280. * @param string $image_alignment Image alignment in the form of 'alignleft', 'aligncenter', 'alignright'
  1281. * @param bool $linked Set to 'true' if the image should link to the post or 'false' otherwise
  1282. * @return string HTML formatted image linking (optional) to the Post with $post_id
  1283. */
  1284. function customized_featured_image( $post_id, $img_src, $width, $height, $image_alignment = 'alignleft', $linked = true ) {
  1285. $the_image_html = '<img src="'.udesign_process_image( $img_src, $width, $height, 1, 100 ).'" alt="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '" />';
  1286. if ( $linked ) $the_image_html = '<a href="'.get_permalink( $post_id ).'" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">'.$the_image_html.'</a>';
  1287. $html = '<span class="custom-frame '.$image_alignment.'">'.$the_image_html.'</span>';
  1288. if( $image_alignment == 'aligncenter' ) $html = '<div style="text-align:center;">'.$html.'</div>';
  1289. return $html;
  1290. }
  1291. /**
  1292. * Display the post image linked (optional) to the post
  1293. * @param int $post_id Post ID.
  1294. * @param bool $linked Set to 'true' if the image should link to the post or 'false' otherwise
  1295. * @return string HTML formatted post image linking (optional) to the Post with $post_id
  1296. */
  1297. function display_post_image_fn( $post_id, $linked = true) {
  1298. global $udesign_options;
  1299. $post_image_url = get_post_meta($post_id, 'post_image', true); // Grab the preview image from the custom field 'post_image', if set.
  1300. if ( !$post_image_url && has_post_thumbnail( $post_id ) ) {
  1301. $tmp_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' );
  1302. $post_image_url = $tmp_image[0];
  1303. }
  1304. if ( $post_image_url ) :
  1305. if ( $udesign_options['enable_custom_featured_image'] == 'yes' ) :
  1306. // Customize the dimension and alignment of the 'Featured Image' ...
  1307. if( ( $udesign_options['force_image_dimention'] == 'yes' ) && ( $udesign_options['disable_timthumb'] != 'yes' ) ) :
  1308. //... by a function defined in 'function.php' specifically for this theme using TimThumb
  1309. echo customized_featured_image( $post_id, $post_image_url, $udesign_options['featured_image_width'], $udesign_options['featured_image_height'], $udesign_options['featured_image_alignment'], $linked );
  1310. else :
  1311. //... by the default WP 'the_post_thumbnail()' function which doesn't stretch images if they are smaller
  1312. echo the_post_thumbnail( array($udesign_options['featured_image_width'], $udesign_options['featured_image_height']), array('class' => $udesign_options['featured_image_alignment']) );
  1313. endif;
  1314. else : ?>
  1315. <div class="post-image-holder pngfix">
  1316. <div class="post-image">
  1317. <span class="post-hover-image pngfix"> </span>
  1318. <?php if ( $linked ) : ?>
  1319. <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><img class="hover-opacity" src="<?php echo udesign_process_image( $post_image_url, 570, 172, 1, 90 ); ?>" alt="<?php the_title_attribute(); ?>" /></a>
  1320. <?php else : ?>
  1321. <img class="hover-opacity" src="<?php echo udesign_process_image( $post_image_url, 570, 172, 1, 90 ); ?>" alt="<?php the_title_attribute(); ?>" />
  1322. <?php endif; ?>
  1323. </div>
  1324. </div>
  1325. <?php endif;
  1326. endif;
  1327. }
  1328.  
  1329. /* Load breadcrumbs script */
  1330. if ($udesign_options['show_breadcrumbs'] == 'yes')
  1331. include( 'scripts/breadcrumbs.php' );
  1332.  
  1333. /* Load Portfolio Related Function */
  1334. require_once( get_template_directory() . '/scripts/portfolio-item-thumbnail.php' );
  1335.  
  1336. /* Admin area only*/
  1337. if ( is_admin() ) {
  1338. // Load Theme Notifier
  1339. if ( !$udesign_options['disable_the_theme_update_notifier'] == 'yes' ) {
  1340. require_once( get_template_directory() . '/scripts/notifier/update-notifier.php' );
  1341. }
  1342. // Load the script to register required plugins for U-Design
  1343. require_once( get_template_directory() . '/lib/plugin-activation/register-required-plugins.php' );
  1344. }
  1345.  
  1346. /* Detect Colour Brightness */
  1347. function udesign_get_color_brightness($hexStr) {
  1348. // Gets a proper hex string
  1349. $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr);
  1350. $rgbArray = array();
  1351. //If a proper hex code, convert using bitwise operation. No overhead... faster
  1352. if (strlen($hexStr) == 6) {
  1353. $colorVal = hexdec($hexStr);
  1354. $rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
  1355. $rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
  1356. $rgbArray['blue'] = 0xFF & $colorVal;
  1357. } elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations
  1358. $rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
  1359. $rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
  1360. $rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
  1361. } else { //Invalid hex color code
  1362. return false;
  1363. }
  1364. return (($rgbArray['red']*299) + ($rgbArray['green']*587) + ($rgbArray['blue']*114))/1000;
  1365. }
  1366.  
  1367. if ( $udesign_options['custom_colors_switch'] == 'enable' ) {
  1368.  
  1369. // Add specific CSS class by filter
  1370. function determine_class_names($classes) {
  1371. global $udesign_options;
  1372. // add 'class-name' to the $classes array
  1373. $classes[] = ( udesign_get_color_brightness("#{$udesign_options['top_bg_color']}") > 200 ) ? '' : 'top-bg-color-dark';
  1374. $classes[] = ( udesign_get_color_brightness("#{$udesign_options['main_content_bg']}") > 220 ) ? '' : 'main-content-bg-dark';
  1375. // return the $classes array
  1376. return $classes;
  1377. }
  1378. add_filter('body_class','determine_class_names');
  1379.  
  1380. }
  1381.  
  1382.  
  1383. // Determine whether WP-prettyPhoto plugin is acivated and assign the result to a constant
  1384. defined('WP_PRETTY_PHOTO_PLUGIN_ACTIVE')
  1385. || define('WP_PRETTY_PHOTO_PLUGIN_ACTIVE', class_exists( 'WP_prettyPhoto' ) );
  1386.  
  1387.  
  1388. // if the WP-prettyPhoto plugin is not active handle rel="wp-prettyPhoto" in links for the prettyPhoto integrated script (if enabled)
  1389. if ( !WP_PRETTY_PHOTO_PLUGIN_ACTIVE && ( $udesign_options['enable_prettyPhoto_script'] == 'yes' ) ) {
  1390. /**
  1391. * Insert rel="wp-prettyPhoto" to all links for images, movie, YouTube and iFrame.
  1392. * This function will ignore links where you have manually entered your own rel reference.
  1393. * @param string $content Post/page contents
  1394. * @return string Prettified post/page contents
  1395. * @link http://0xtc.com/2008/05/27/auto-lightbox-function.xhtml
  1396. * @access public
  1397. */
  1398. function autoinsert_rel_prettyPhoto ($content) {
  1399. global $post;
  1400. $rel = 'wp-prettyPhoto';
  1401. $image_match = '\.bmp|\.gif|\.jpg|\.jpeg|\.png';
  1402. $movie_match = '\.mov.*?';
  1403. $swf_match = '\.swf.*?';
  1404. $youtube_match = 'http:\/\/www\.youtube\.com\/watch\?v=[A-Za-z0-9]*';
  1405. $iframe_match = '.*iframe=true.*';
  1406. $pattern[0] = "/<a(.*?)href=('|\")([A-Za-z0-9\/_\.\~\:-]*?)(".$image_match."|".$movie_match."|".$swf_match."|".$youtube_match."|".$iframe_match.")('|\")([^\>]*?)>/i";
  1407. $pattern[1] = "/<a(.*?)href=('|\")([A-Za-z0-9\/_\.\~\:-]*?)(".$image_match."|".$movie_match."|".$swf_match."|".$youtube_match."|".$iframe_match.")('|\")(.*?)(rel=('|\")".$rel."(.*?)('|\"))([ \t\r\n\v\f]*?)((rel=('|\")".$rel."(.*?)('|\"))?)([ \t\r\n\v\f]?)([^\>]*?)>/i";
  1408. $replacement[0] = '<a$1href=$2$3$4$5$6 rel="'.$rel.'['.$post->ID.']">';
  1409. $replacement[1] = '<a$1href=$2$3$4$5$6$7>';
  1410. $content = preg_replace($pattern, $replacement, $content);
  1411. return $content;
  1412. }
  1413. add_filter('the_content', 'autoinsert_rel_prettyPhoto');
  1414. add_filter('the_excerpt', 'autoinsert_rel_prettyPhoto');
  1415.  
  1416.  
  1417. // Add the 'wp-prettyPhoto' rel attribute to the default WP gallery links
  1418. function gallery_prettyPhoto ($content) {
  1419. // add checks if you want to add prettyPhoto on certain places (archives etc).
  1420. return str_replace("<a", "<a rel='wp-prettyPhoto[gallery]'", $content);
  1421. }
  1422. add_filter( 'wp_get_attachment_link', 'gallery_prettyPhoto');
  1423. }
  1424.  
  1425. /*
  1426. * Plugin Name: Shortcode Empty Paragraph Fix
  1427. * Plugin URI: http://www.johannheyne.de/wordpress/shortcode-empty-paragraph-fix/
  1428. * Description: Fix issues when shortcodes are embedded in a block of content that is filtered by wpautop.
  1429. * Author URI: http://www.johannheyne.de
  1430. * Version: 0.1
  1431. * Put this in /wp-content/plugins/ of your Wordpress installation
  1432. */
  1433. function shortcode_paragraph_insertion_fix($content) {
  1434. $array = array (
  1435. '<p>[' => '[',
  1436. ']</p>' => ']',
  1437. ']<br />' => ']'
  1438. );
  1439. $content = strtr($content, $array);
  1440. return $content;
  1441. }
  1442. add_filter('the_content', 'shortcode_paragraph_insertion_fix');
  1443.  
  1444. // format "<!--more-->" tag for u-design
  1445. function udesign_more_link( $more_link, $more_link_text ) {
  1446. global $post;
  1447. $html = ' <a title="'.$more_link_text.'" href="'.get_permalink().'#more-'.$post->ID.'" class="read-more-align-left"><span>'.$more_link_text.'</span> &rarr;</a>';
  1448. $html .= '<div class="clear"></div>';
  1449. return $html;
  1450. }
  1451. add_filter('the_content_more_link', 'udesign_more_link', 10, 2);
  1452.  
  1453. // Capture the output of "the_author_posts_link()" function into a local variable and return it.
  1454. // This function must be used within 'The Loop'
  1455. if ( !function_exists('udesign_get_the_author_page_link') ) {
  1456. function udesign_get_the_author_page_link() {
  1457. ob_start();
  1458. the_author_posts_link();
  1459. $the_author_link = ob_get_contents();
  1460. ob_end_clean();
  1461. return $the_author_link;
  1462. }
  1463. }
  1464.  
  1465. if ( function_exists('icl_get_default_language') && !function_exists('udesign_wpml_replace_category_id') ) {
  1466. /**
  1467. * Replaces the the id given with corresponding one for the current language
  1468. * @global WPML $sitepress
  1469. * @param &int $id
  1470. * @return void
  1471. */
  1472. function udesign_wpml_replace_category_id(&$id) {
  1473. global $sitepress;
  1474. $deflang = $sitepress->get_default_language();
  1475. if(ICL_LANGUAGE_CODE == $deflang) return;
  1476. $cat = get_category($id);
  1477. $id = $cat->term_id;
  1478. }
  1479. }
  1480.  
  1481.  
  1482. /***** BEGIN: Page Title Business *****/
  1483. if ( !function_exists('udesign_page_title') ) {
  1484. function udesign_page_title() {
  1485. global $udesign_options;
  1486. if ( $udesign_options['page_title_position'] == 'position1' || $udesign_options['page_title_position'] == 'remove1' ) : ?>
  1487. <div id="page-content-title">
  1488. <div id="page-content-header" class="container_24">
  1489. <?php endif; ?>
  1490. <div id="page-title">
  1491. <?php if (is_page()) : ?>
  1492. <h1><?php the_title(); ?></h1>
  1493. <?php elseif ( is_single() ) : ?>
  1494. <h1><?php the_title(); ?></h1>
  1495. <?php elseif ( is_post_type_archive() ) : ?>
  1496. <h1 class="pagetitle"><?php post_type_archive_title(); ?></h1>
  1497. <?php elseif (is_tax()) : /* If this is a taxonomy archive */
  1498. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
  1499. <h1 class="pagetitle"><?php echo ucwords( $term->name); ?></h1>
  1500. <?php elseif (is_category()) : /* If this is a category archive */ ?>
  1501. <?php if ($udesign_options['show_archive_for_string'] == 'yes') : ?>
  1502. <h1 class="pagetitle"><?php single_cat_title("", true); ?></h1>
  1503. <?php else : ?>
  1504. <h1 class="pagetitle"><?php printf( __('Archive for the &#8216;%s&#8217; Category', 'udesign' ), single_cat_title("", false) ); ?></h1>
  1505. <?php endif; ?>
  1506. <?php elseif (is_search()) : /* If this is a search results page */ ?>
  1507. <h1 class="pagetitle"><?php printf( __('Search Results for &#8216;<em>%s</em>&#8217;', 'udesign' ), get_search_query() ); ?></h1>
  1508. <?php elseif (is_404()) : /* If this is a 404 page */ ?>
  1509. <h1 class="pagetitle"><?php esc_html_e('Page Not Found (Error 404)', 'udesign'); ?></h1>
  1510. <?php elseif( is_tag() ) : /* If this is a tag archive */ ?>
  1511. <h1 class="pagetitle"><?php printf( __('Posts Tagged &#8216;%s&#8217;', 'udesign' ), single_tag_title("", false) ); ?></h1>
  1512. <?php elseif (is_day()) : /* If this is a daily archive */ ?>
  1513. <h1 class="pagetitle"><?php printf( __('Archive for %s', 'udesign' ), get_the_date() ); ?></h1>
  1514. <?php elseif (is_month()) : /* If this is a monthly archive */ ?>
  1515. <h1 class="pagetitle"><?php printf( __('Archive for %s', 'udesign' ), get_the_time('F Y') ); ?></h1>
  1516. <?php elseif (is_year()) : /* If this is a yearly archive */ ?>
  1517. <h1 class="pagetitle"><?php printf( __('Archive for %s', 'udesign' ), get_the_time('Y') ); ?></h1>
  1518. <?php elseif (is_author()) : /* If this is an author archive */ ?>
  1519. <h1 class="pagetitle"><?php esc_html_e('Author Archive', 'udesign'); ?></h1>
  1520. <?php elseif (isset($_GET['paged']) && !empty($_GET['paged'])) : /* If this is a paged archive */ ?>
  1521. <h1 class="pagetitle"><?php esc_html_e('Blog Archives', 'udesign'); ?></h1>
  1522. <?php else : // the case when a Title is NOT present the height should be maintained ?>
  1523. <div class="no-title-present"></div>
  1524. <?php endif; ?>
  1525. </div>
  1526. <!-- end page-title -->
  1527. <?php if ( $udesign_options['page_title_position'] == 'position1' || $udesign_options['page_title_position'] == 'remove1' ) : ?>
  1528. </div>
  1529. <!-- end page-content-header -->
  1530. </div>
  1531. <!-- end page-content-title -->
  1532. <div class="clear"></div>
  1533. <?php endif;
  1534. }
  1535. }
  1536.  
  1537. function udesign_add_no_title_section_class($classes) {
  1538. global $udesign_options;
  1539. $classes[] = 'no_title_section';
  1540. return $classes;
  1541. }
  1542. // Assign page title position or removal method
  1543. switch ( $udesign_options['page_title_position'] ) {
  1544. case 'position1': // Position Title immediately under the Main Menu
  1545. add_action('udesign_below_menu_not_front_page', 'udesign_page_title');
  1546. break;
  1547. case 'position2': // Position Title Inside Main Content
  1548. add_filter('body_class','udesign_add_no_title_section_class');
  1549. add_action('udesign_above_page_content', 'udesign_page_title');
  1550. break;
  1551. case 'remove1': // Remove Title (SEO-Friendly)
  1552. add_filter('body_class','udesign_add_no_title_section_class');
  1553. add_action('udesign_below_menu_not_front_page', 'udesign_page_title');
  1554. break;
  1555. default: // Remove Title Completely
  1556. add_filter('body_class','udesign_add_no_title_section_class');
  1557. }
  1558. /***** END: Page Title Business *****/
  1559.  
  1560.  
  1561. // Exclude Portfolio Categories from Blog and Archive pages if enabled
  1562. if ( !is_admin() && $udesign_options['exclude_portfolio_from_blog'] == 'yes' ) {
  1563. $portfolio_cats_array = explode(',', $udesign_options['portfolio_categories']);
  1564. function add_minus_prefix_fn( $var ) { return( '-' . $var);}
  1565. $portfolio_cats_with_minus = implode(',', array_map( "add_minus_prefix_fn", $portfolio_cats_array ));
  1566.  
  1567. function udesign_exclude_category( $query ) {
  1568. global $portfolio_cats_with_minus;
  1569. if ( ( $query->is_category() || $query->is_day() || $query->is_month() || $query->is_year() ) && $query->is_main_query() ) {
  1570. $query->set( 'cat', $portfolio_cats_with_minus );
  1571. }
  1572. }
  1573. add_action( 'pre_get_posts', 'udesign_exclude_category' );
  1574.  
  1575.  
  1576.  
  1577.  
  1578. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement