Advertisement
Guest User

Untitled

a guest
May 13th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.45 KB | None | 0 0
  1. <?php
  2. /**
  3.  * TwentyTen functions and definitions
  4.  *
  5.  * Sets up the theme and provides some helper functions. Some helper functions
  6.  * are used in the theme as custom template tags. Others are attached to action and
  7.  * filter hooks in WordPress to change core functionality.
  8.  *
  9.  * The first function, twentyten_setup(), sets up the theme by registering support
  10.  * for various features in WordPress, such as post thumbnails, navigation menus, and the like.
  11.  *
  12.  * When using a child theme (see http://codex.wordpress.org/Theme_Development and
  13.  * http://codex.wordpress.org/Child_Themes), you can override certain functions
  14.  * (those wrapped in a function_exists() call) by defining them first in your child theme's
  15.  * functions.php file. The child theme's functions.php file is included before the parent
  16.  * theme's file, so the child theme functions would be used.
  17.  *
  18.  * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
  19.  * to a filter or action hook. The hook can be removed by using remove_action() or
  20.  * remove_filter() and you can attach your own function to the hook.
  21.  *
  22.  * We can remove the parent theme's hook only after it is attached, which means we need to
  23.  * wait until setting up the child theme:
  24.  *
  25.  * <code>
  26.  * add_action( 'after_setup_theme', 'my_child_theme_setup' );
  27.  * function my_child_theme_setup() {
  28.  *     // We are providing our own filter for excerpt_length (or using the unfiltered value)
  29.  *     remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  30.  *     ...
  31.  * }
  32.  * </code>
  33.  *
  34.  * For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API
  35.  *
  36.  * @package WordPress
  37.  * @subpackage Twenty_Ten
  38.  * @since Twenty Ten 1.0
  39.  */
  40.  
  41. /**
  42.  * Set the content width based on the theme's design and stylesheet.
  43.  *
  44.  * Used to set the width of images and content. Should be equal to the width the theme
  45.  * is designed for, generally via the style.css stylesheet.
  46.  */
  47. if ( ! isset( $content_width ) )
  48.     $content_width = 640;
  49.  
  50. /** Tell WordPress to run twentyten_setup() when the 'after_setup_theme' hook is run. */
  51. add_action( 'after_setup_theme', 'twentyten_setup' );
  52.  
  53. if ( ! function_exists( 'twentyten_setup' ) ):
  54. /**
  55.  * Sets up theme defaults and registers support for various WordPress features.
  56.  *
  57.  * Note that this function is hooked into the after_setup_theme hook, which runs
  58.  * before the init hook. The init hook is too late for some features, such as indicating
  59.  * support post thumbnails.
  60.  *
  61.  * To override twentyten_setup() in a child theme, add your own twentyten_setup to your child theme's
  62.  * functions.php file.
  63.  *
  64.  * @uses add_theme_support() To add support for post thumbnails and automatic feed links.
  65.  * @uses register_nav_menus() To add support for navigation menus.
  66.  * @uses add_custom_background() To add support for a custom background.
  67.  * @uses add_editor_style() To style the visual editor.
  68.  * @uses load_theme_textdomain() For translation/localization support.
  69.  * @uses add_custom_image_header() To add support for a custom header.
  70.  * @uses register_default_headers() To register the default custom header images provided with the theme.
  71.  * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  72.  *
  73.  * @since Twenty Ten 1.0
  74.  */
  75. add_action('wp_head', 'add_google_rel_author');
  76. function add_google_rel_author() {
  77. echo '<link rel="author" href="https://plus.google.com/114646391781247631808" />';
  78. }
  79.  
  80. remove_action( 'woocommerce_before_main_content',
  81.     'woocommerce_breadcrumb', 20, 0);
  82. function twentyten_setup() {
  83.  
  84.     // This theme styles the visual editor with editor-style.css to match the theme style.
  85.     add_editor_style();
  86.  
  87.     // This theme uses post thumbnails
  88.     add_theme_support( 'post-thumbnails' );
  89.  
  90.     // Add default posts and comments RSS feed links to head
  91.     add_theme_support( 'automatic-feed-links' );
  92.  
  93.     // Make theme available for translation
  94.     // Translations can be filed in the /languages/ directory
  95.     load_theme_textdomain( 'twentyten', TEMPLATEPATH . '/languages' );
  96.  
  97.     $locale = get_locale();
  98.     $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  99.     if ( is_readable( $locale_file ) )
  100.         require_once( $locale_file );
  101.  
  102.     // This theme uses wp_nav_menu() in one location.
  103.     register_nav_menus( array(
  104.         'primary' => __( 'Primary Navigation', 'twentyten' ),
  105.     ) );
  106.  
  107.     // This theme allows users to set a custom background
  108.     add_custom_background();
  109.  
  110.     // Your changeable header business starts here
  111.     define( 'HEADER_TEXTCOLOR', '' );
  112.     // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
  113.     define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
  114.  
  115.     // The height and width of your custom header. You can hook into the theme's own filters to change these values.
  116.     // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
  117.     define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
  118.     define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
  119.  
  120.     // We'll be using post thumbnails for custom header images on posts and pages.
  121.     // We want them to be 940 pixels wide by 198 pixels tall.
  122.     // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
  123.     set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
  124.  
  125.     // Don't support text inside the header image.
  126.     define( 'NO_HEADER_TEXT', true );
  127. }
  128. endif;
  129.  
  130. if ( ! function_exists( 'twentyten_admin_header_style' ) ) :
  131. /**
  132.  * Styles the header image displayed on the Appearance > Header admin panel.
  133.  *
  134.  * Referenced via add_custom_image_header() in twentyten_setup().
  135.  *
  136.  * @since Twenty Ten 1.0
  137.  */
  138. function twentyten_admin_header_style() {
  139. ?>
  140. <style type="text/css">
  141. /* Shows the same border as on front end */
  142. #headimg {
  143.     border-bottom: 1px solid #000;
  144.     border-top: 4px solid #000;
  145. }
  146. /* If NO_HEADER_TEXT is false, you would style the text with these selectors:
  147.     #headimg #name { }
  148.     #headimg #desc { }
  149. */
  150. </style>
  151. <?php
  152. }
  153. endif;
  154.  
  155. /**
  156.  * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  157.  *
  158.  * To override this in a child theme, remove the filter and optionally add
  159.  * your own function tied to the wp_page_menu_args filter hook.
  160.  *
  161.  * @since Twenty Ten 1.0
  162.  */
  163. function twentyten_page_menu_args( $args ) {
  164.     $args['show_home'] = true;
  165.     return $args;
  166. }
  167. add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );
  168.  
  169. /**
  170.  * Sets the post excerpt length to 40 characters.
  171.  *
  172.  * To override this length in a child theme, remove the filter and add your own
  173.  * function tied to the excerpt_length filter hook.
  174.  *
  175.  * @since Twenty Ten 1.0
  176.  * @return int
  177.  */
  178. function twentyten_excerpt_length( $length ) {
  179.     return 40;
  180. }
  181. add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  182.  
  183. /**
  184.  * Returns a "Continue Reading" link for excerpts
  185.  *
  186.  * @since Twenty Ten 1.0
  187.  * @return string "Continue Reading" link
  188.  */
  189. function twentyten_continue_reading_link() {
  190.     return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) . '</a>';
  191. }
  192.  
  193. /**
  194.  * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyten_continue_reading_link().
  195.  *
  196.  * To override this in a child theme, remove the filter and add your own
  197.  * function tied to the excerpt_more filter hook.
  198.  *
  199.  * @since Twenty Ten 1.0
  200.  * @return string An ellipsis
  201.  */
  202. function twentyten_auto_excerpt_more( $more ) {
  203.     return ' &hellip;' . twentyten_continue_reading_link();
  204. }
  205. add_filter( 'excerpt_more', 'twentyten_auto_excerpt_more' );
  206.  
  207. /**
  208.  * Adds a pretty "Continue Reading" link to custom post excerpts.
  209.  *
  210.  * To override this link in a child theme, remove the filter and add your own
  211.  * function tied to the get_the_excerpt filter hook.
  212.  *
  213.  * @since Twenty Ten 1.0
  214.  * @return string Excerpt with a pretty "Continue Reading" link
  215.  */
  216. function twentyten_custom_excerpt_more( $output ) {
  217.     if ( has_excerpt() && ! is_attachment() ) {
  218.         $output .= twentyten_continue_reading_link();
  219.     }
  220.     return $output;
  221. }
  222. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  223.  
  224. /**
  225.  * Remove inline styles printed when the gallery shortcode is used.
  226.  *
  227.  * Galleries are styled by the theme in Twenty Ten's style.css.
  228.  *
  229.  * @since Twenty Ten 1.0
  230.  * @return string The gallery style filter, with the styles themselves removed.
  231.  */
  232. function twentyten_remove_gallery_css( $css ) {
  233.     return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
  234. }
  235. add_filter( 'gallery_style', 'twentyten_remove_gallery_css' );
  236.  
  237. if ( ! function_exists( 'twentyten_comment' ) ) :
  238. /**
  239.  * Template for comments and pingbacks.
  240.  *
  241.  * To override this walker in a child theme without modifying the comments template
  242.  * simply create your own twentyten_comment(), and that function will be used instead.
  243.  *
  244.  * Used as a callback by wp_list_comments() for displaying the comments.
  245.  *
  246.  * @since Twenty Ten 1.0
  247.  */
  248. function twentyten_comment( $comment, $args, $depth ) {
  249.     $GLOBALS['comment'] = $comment;
  250.     switch ( $comment->comment_type ) :
  251.         case '' :
  252.     ?>
  253.     <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
  254.         <div id="comment-<?php comment_ID(); ?>">
  255.         <div class="comment-author vcard">
  256.             <?php echo get_avatar( $comment, 40 ); ?>
  257.             <?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
  258.         </div><!-- .comment-author .vcard -->
  259.         <?php if ( $comment->comment_approved == '0' ) : ?>
  260.             <em><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
  261.             <br />
  262.         <?php endif; ?>
  263.  
  264.         <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
  265.             <?php
  266.                 /* translators: 1: date, 2: time */
  267.                 printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
  268.             ?>
  269.         </div><!-- .comment-meta .commentmetadata -->
  270.  
  271.         <div class="comment-body"><?php comment_text(); ?></div>
  272.  
  273.         <div class="reply">
  274.             <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  275.         </div><!-- .reply -->
  276.     </div><!-- #comment-##  -->
  277.  
  278.     <?php
  279.             break;
  280.         case 'pingback'  :
  281.         case 'trackback' :
  282.     ?>
  283.     <li class="post pingback">
  284.         <p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'twentyten'), ' ' ); ?></p>
  285.     <?php
  286.             break;
  287.     endswitch;
  288. }
  289. endif;
  290.  
  291. /**
  292.  * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
  293.  *
  294.  * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
  295.  * function tied to the init hook.
  296.  *
  297.  * @since Twenty Ten 1.0
  298.  * @uses register_sidebar
  299.  */
  300. function twentyten_widgets_init() {
  301.     // Sidebar, column next to page content
  302.     register_sidebar( array(
  303.         'name' => __( 'Sidebar', 'twentyten' ),
  304.         'id' => 'sidebar',
  305.         'description' => __( 'The Sidebar Area', 'twentyten' ),
  306.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  307.         'after_widget' => '</li>',
  308.         'before_title' => '<h3 class="widget-title">',
  309.         'after_title' => '</h3>',
  310.     ) );
  311.  
  312.     // Footer the bottom stuff
  313.     register_sidebar( array(
  314.         'name' => __( 'Footer Bar', 'twentyten' ),
  315.         'id' => 'footerBar',
  316.         'description' => __( 'The Footer Area', 'twentyten' ),
  317.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  318.         'after_widget' => '</li>',
  319.         'before_title' => '<h3 class="widget-title">',
  320.         'after_title' => '</h3>',
  321.     ) );
  322.    
  323.     // Same as Sidebar but specific to the blog pages
  324.     register_sidebar( array(
  325.         'name' => __( 'Blog', 'twentyten' ),
  326.         'id' => 'blog',
  327.         'description' => __( 'The Sidebar Area For the Blog Area', 'twentyten' ),
  328.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  329.         'after_widget' => '</li>',
  330.         'before_title' => '<h3 class="widget-title">',
  331.         'after_title' => '</h3>',
  332.     ) );   
  333.    
  334.     // Home page sidebar
  335.     register_sidebar( array(
  336.         'name' => __( 'Home', 'twentyten' ),
  337.         'id' => 'home',
  338.         'description' => __( 'A widget Area for Home Page', 'twentyten' ),
  339.         'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  340.         'after_widget' => '</li>',
  341.         'before_title' => '<h3 class="widget-title">',
  342.         'after_title' => '</h3>',
  343.     ) );
  344.    
  345.     // Resource page sidebar
  346.     register_sidebar( array(
  347.         'name' => __( 'Resource Page Column First', 'twentyten' ),
  348.         'id' => 'resource-page-column-first',
  349.         'description' => __( 'A widget Area for Resource Page', 'twentyten' ),
  350.         'before_widget' => '<div>',
  351.         'after_widget' => '</div>',
  352.         'before_title' => '<h3 class="widget-title">',
  353.         'after_title' => '</h3>',
  354.     ) );
  355.    
  356.     register_sidebar( array(
  357.         'name' => __( 'Resource Page Column Second', 'twentyten' ),
  358.         'id' => 'resource-page-column-second',
  359.         'description' => __( 'A widget Area for Resource Page', 'twentyten' ),
  360.         'before_widget' => '<div>',
  361.         'after_widget' => '</div>',
  362.         'before_title' => '<h3 class="widget-title">',
  363.         'after_title' => '</h3>',
  364.     ) );
  365.    
  366.     register_sidebar( array(
  367.         'name' => __( 'Resource Page Column Third', 'twentyten' ),
  368.         'id' => 'resource-page-column-third',
  369.         'description' => __( 'A widget Area for Resource Page', 'twentyten' ),
  370.         'before_widget' => '<div>',
  371.         'after_widget' => '</div>',
  372.         'before_title' => '<h3 class="widget-title">',
  373.         'after_title' => '</h3>',
  374.     ) );
  375.    
  376.     register_sidebar( array(
  377.         'name' => __( 'Resource Page Column Fourth', 'twentyten' ),
  378.         'id' => 'resource-page-column-fourth',
  379.         'description' => __( 'A widget Area for Resource Page', 'twentyten' ),
  380.         'before_widget' => '<div>',
  381.         'after_widget' => '</div>',
  382.         'before_title' => '<h3 class="widget-title">',
  383.         'after_title' => '</h3>',
  384.     ) );
  385. }
  386. /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
  387. add_action( 'widgets_init', 'twentyten_widgets_init' );
  388.  
  389. /**
  390.  * Removes the default styles that are packaged with the Recent Comments widget.
  391.  *
  392.  * To override this in a child theme, remove the filter and optionally add your own
  393.  * function tied to the widgets_init action hook.
  394.  *
  395.  * @since Twenty Ten 1.0
  396.  */
  397. function twentyten_remove_recent_comments_style() {
  398.     global $wp_widget_factory;
  399.     remove_action( 'wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ) );
  400. }
  401. add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
  402.  
  403. if ( ! function_exists( 'twentyten_posted_on' ) ) :
  404. /**
  405.  * Prints HTML with meta information for the current post—date/time and author.
  406.  *
  407.  * @since Twenty Ten 1.0
  408.  */
  409. function twentyten_posted_on() {
  410.     printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
  411.         'meta-prep meta-prep-author',
  412.         sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  413.             get_permalink(),
  414.             esc_attr( get_the_time() ),
  415.             get_the_date()
  416.         ),
  417.         sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  418.             get_author_posts_url( get_the_author_meta( 'ID' ) ),
  419.             sprintf( esc_attr__( 'View all posts by %s', 'twentyten' ), get_the_author() ),
  420.             get_the_author()
  421.         )
  422.     );
  423. }
  424. endif;
  425.  
  426. if ( ! function_exists( 'twentyten_posted_in' ) ) :
  427. /**
  428.  * Prints HTML with meta information for the current post (category, tags and permalink).
  429.  *
  430.  * @since Twenty Ten 1.0
  431.  */
  432. function twentyten_posted_in() {
  433.     // Retrieves tag list of current post, separated by commas.
  434.     $tag_list = get_the_tag_list( '', ', ' );
  435.     if ( $tag_list ) {
  436.         $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  437.     } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  438.         $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  439.     } else {
  440.         $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
  441.     }
  442.     // Prints the string, replacing the placeholders.
  443.     printf(
  444.         $posted_in,
  445.         get_the_category_list( ', ' ),
  446.         $tag_list,
  447.         get_permalink(),
  448.         the_title_attribute( 'echo=0' )
  449.     );
  450. }
  451. endif;
  452.  
  453. register_taxonomy('faq_category', 'faq', array('hierarchical' => true, 'label' => 'FAQ Categories', 'query_var' => true, 'rewrite' => true));
  454.  
  455. register_post_type(
  456.         'faq',
  457.         array(
  458.             'labels' => array(
  459.                 'name' => 'FAQs',
  460.                 'singular_name' => 'FAQ'
  461.             ),
  462.             'public' => true,
  463.             'has_archive' => true,
  464.             'rewrite' => array('slug' => 'faq-items'),
  465.             'hierarchical' => false,
  466.             'supports' => array('title', 'editor', 'author','thumbnail','page-attributes','excerpt'),
  467.             'can_export' => true
  468.     ));
  469.  
  470. add_action('init', 'faq_add_default_boxes');
  471.  
  472. function faq_add_default_boxes() {
  473.     register_taxonomy_for_object_type('faq_category', 'faq');
  474.  
  475. }
  476. /*
  477. function add_faqcat_columns($columns) {
  478.     unset($columns['categories']);
  479.     return array_merge($columns,
  480.               array('categories' =>__( 'faq')));
  481. }
  482. add_filter('manage_faq_posts_columns' , 'add_faqcat_columns');
  483.  
  484. /*register_taxonomy('faq_category', 'faq', array('hierarchical' => true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true));*/
  485.    
  486. function wdblk($id)
  487. {
  488.     $pid = get_post($id);
  489.     $i = strpos($pid->post_title,'=>');
  490.    
  491.     if($i) { $title = substr($pid->post_title,$i+2); }
  492.     else { $title = $pid->post_title; }
  493.    
  494.     $img = wp_get_attachment_image_src(get_post_thumbnail_id($id),'full');
  495.    
  496.     return array(
  497.         'id'=>get_the_ID(),
  498.         'title'=>$title,
  499.         'content'=>wpautop($pid->post_content),
  500.         'img_src'=>$img[0],
  501.         'img_width'=>$img[1],
  502.         'img_height'=>$img[2],
  503.         'img'=>get_the_post_thumbnail($id,'full'),
  504.         'fields'=>get_post_custom($id),
  505.     );
  506. }
  507.  
  508. // Puts link in excerpts more tag
  509. function new_excerpt_more($more) {
  510.        global $post;
  511.     return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read More &raquo;</a>';
  512. }
  513. add_filter('excerpt_more', 'new_excerpt_more');
  514.  
  515.  
  516. function custom_excerpt_length( $length ) {
  517.     return 50;
  518. }
  519. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  520.  
  521. add_filter('mce_buttons','wysiwyg_editor');
  522. function wysiwyg_editor($mce_buttons) {
  523.     $pos = array_search('wp_more',$mce_buttons,true);
  524.     if ($pos !== false) {
  525.         $tmp_buttons = array_slice($mce_buttons, 0, $pos+1);
  526.         $tmp_buttons[] = 'wp_page';
  527.         $mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos+1));
  528.     }
  529.     return $mce_buttons;
  530. }
  531.  
  532. function current_year( ){
  533.  return date('Y');
  534. }
  535. add_shortcode( 'year', 'current_year' );
  536.  
  537. /**
  538.  * Add prev and next links to a numbered link list
  539.  */
  540. function wp_link_pages_args_prevnext_add($args)
  541. {
  542.     global $page, $numpages, $more, $pagenow;
  543.  
  544.     if (!$args['next_or_number'] == 'next_and_number')
  545.         return $args; # exit early
  546.  
  547.     $args['next_or_number'] = 'number'; # keep numbering for the main part
  548.    if (!$more)
  549.         return $args; # exit early
  550.  
  551.     if($page-1) # there is a previous page
  552.        $args['before'] .= '<div class="p_link">'. _wp_link_page($page-1)
  553.             . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a></div>'
  554.         ;
  555.  
  556.     if ($page<$numpages) # there is a next page
  557.        $args['after'] = '<div class="n_link">'._wp_link_page($page+1)
  558.             . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
  559.             . $args['after'].'</div>'
  560.         ;
  561.  
  562.     return $args;
  563. }
  564. add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
  565.  
  566. // add ajax action for users, logged in or not
  567. function add_ajax_action($action,$function){
  568.     add_action('wp_ajax_'.$action,$function);
  569.     add_action('wp_ajax_nopriv_'.$action,$function);
  570. }
  571.  
  572. // reviews
  573. add_ajax_action('post-review',function(){
  574.     // init
  575.     global $wpdb,$wpt;
  576.    
  577.     // prepare
  578.     unset($_POST['action'],$_POST['x'],$_POST['y']);
  579.    
  580.     $invalid = array();
  581.     foreach($_POST as $k=>$v) if(empty($v)) $invalid[] = $k;
  582.     if(!empty($invalid)) exit(json_encode(array('message'=>'invalid','error'=>$invalid)));
  583.    
  584.     $data = $wpt->prepare_post_data(array('table_name'=>'reviews'));
  585.    
  586.     // insert
  587.     $message = $wpdb->insert('reviews',$data) ? 'Thank you, your review has been submitted!':'Error, problem submitting form.';
  588.     $error = $wpdb->last_error;
  589.    
  590.     // return
  591.     exit(json_encode(array('message'=>$message,'error'=>$error)));
  592. });
  593.  
  594. // init opencart
  595. get_template_part('oc.class');
  596.  
  597. get_template_part('custom-comments');
  598.  
  599. // comment callback function that displays a comment in comments.php (we use this to allow stylizing the display)
  600. function comment_callback($comment, $args, $depth) {
  601.     $GLOBALS['comment'] = $comment;
  602.         extract($args, EXTR_SKIP);
  603.  
  604.         if ( 'div' == $args['style'] ) {
  605.             $tag = 'div';
  606.             $add_below = 'comment';
  607.         } else {
  608.             $tag = 'li';
  609.             $add_below = 'div-comment';
  610.         }
  611. ?>
  612.         <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
  613.         <?php if ( 'div' != $args['style'] ) : ?>
  614.         <div id="div-comment-<?php comment_ID() ?>" class="comment-body" style="border-style:dashed; border-width:1px; border-color: #FFBC73; margin-bottom:1px">
  615.         <?php endif; ?>
  616.         <div class="comment-author vcard" style="padding-left:5px">
  617.         <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  618.         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  619.         </div>
  620. <?php if ($comment->comment_approved == '0') : ?>
  621.         <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?>
  622.  
  623. <?php endif; ?>
  624.  
  625.         <div class="comment-meta commentmetadata" style="text-align:right; font-style:italic; padding-right:5px; padding-top:5px">
  626.             <?php
  627.                 /* translators: 1: date, 2: time */
  628.                 printf( __('%1$s at %2$s'), get_comment_date('j F Y'),  get_comment_time());
  629.                 edit_comment_link(__('(Edit)'),'  ','' );
  630.             ?>
  631.         </div>
  632.         <div style="padding-left:5px">
  633.         <?php comment_text() ?>
  634.         </div>
  635.         <div class="reply" style="padding-left:5px">
  636.         <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  637.         </div>
  638.         <?php if ( 'div' != $args['style'] ) : ?>
  639.         </div>
  640.         <?php endif; ?>
  641. <?php
  642. }
  643. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement