Advertisement
jegtheme

themes-functionality.php

Jul 14th, 2014
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.22 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. function jeg_get_loading_type ()
  5. {
  6.     $loadingpage = get_theme_mod('loader_general');
  7.  
  8.     // alter page id
  9.     global $post;
  10.     $pageid = ($post !== null) ? jeg_alter_woo_page_id(get_the_ID()) : null;
  11.  
  12.     // check if loader overrided
  13.     if(vp_metabox('jkreativ_general.override_loader', null, $pageid)) {
  14.         $loadingpage = vp_metabox('jkreativ_general.override_loader_group.0.page_loader', null, $pageid);
  15.     }
  16.  
  17.     return $loadingpage;
  18. }
  19.  
  20. function jeg_is_using_loading() {
  21.     if(jeg_get_loading_type() === 'none') {
  22.         return false;
  23.     } else {
  24.         return true;
  25.     }
  26. }
  27.  
  28. function jlog($var) {
  29.     echo '<pre>';
  30.     print_r($var);
  31.     echo '</pre>';
  32. }
  33.  
  34. function jeg_get_calling_method(){
  35.     $e = new Exception();
  36.     $trace = $e->getTrace();
  37.     //position 0 would be the line that called this function so we ignore it
  38.     $last_call = $trace[1];
  39.     echo "<pre>";
  40.     print_r($last_call);
  41.     echo "</pre>";
  42. }
  43.  
  44. function jeg_check_page_type()
  45. {
  46.     $type = array();
  47.  
  48.     if(is_home())           array_push($type, 'is_home');
  49.     if(is_front_page())     array_push($type, 'is_front_page');
  50.     if(is_404())            array_push($type, 'is_404');
  51.     if(is_search())         array_push($type, 'is_search');
  52.     if(is_date())           array_push($type, 'is_date');
  53.     if(is_author())         array_push($type, 'is_author');
  54.     if(is_category())       array_push($type, 'is_category');
  55.     if(is_tag())            array_push($type, 'is_tag');
  56.     if(is_tax())            array_push($type, 'is_tax');
  57.     if(is_archive())        array_push($type, 'is_archive');
  58.     if(is_single())         array_push($type, 'is_single');
  59.     if(is_attachment())     array_push($type, 'is_attachment');
  60.     if(is_page())           array_push($type, 'is_page');
  61.  
  62.     return implode(', ', $type);
  63. }
  64.  
  65.  
  66. /** woocommerce alter page id **/
  67. function jeg_alter_woo_page_id($pageid) {
  68.     if(function_exists('is_woocommerce')) {
  69.         if(is_shop()) {
  70.             return woocommerce_get_page_id('shop');
  71.         }
  72.     } else {
  73.         return $pageid;
  74.     }
  75. }
  76.  
  77. /***
  78.  * navigation setup
  79.  **/
  80.  
  81. function jeg_get_navigation_setup($pageid = null) {
  82.     $navobj = array();
  83.     $navobj['navpos'] = get_theme_mod('default_navigation', 'side');
  84.     $navobj['navcollapse'] = get_theme_mod('default_collapse_navigator', false);
  85.     $navobj['navtopmenu'] = get_theme_mod('default_menuheader_navigator', true);
  86.     $navobj['navtopcenter'] = get_theme_mod('centering_top_navigator', false);
  87.     $navobj['navtoptwoline'] = get_theme_mod('twoline_top_navigator', false);
  88.     $navobj['navtopsmaller'] = get_theme_mod('smaller_navigator', false);
  89.     $navobj['boxedcontent'] = get_theme_mod('boxed_content', false);
  90.  
  91.     if($navobj['navpos'] === 'transparent') {
  92.         $navobj['navtoptwoline'] = 0;
  93.         $navobj['navtopcenter'] = get_theme_mod('centering_top_navigator_transparent', false);
  94.         $navobj['navtopsmaller'] = get_theme_mod('smaller_navigator_transparent', false);
  95.         $navobj['boxedcontent'] = get_theme_mod('boxed_content_transparent', false);
  96.     }
  97.  
  98.     // alter page id
  99.     $pageid = jeg_alter_woo_page_id($pageid);
  100.  
  101.     // check if page setting overrided on single page
  102.     $pageid = ($pageid === null) ? JEG_PAGE_ID : $pageid ;
  103.     if(vp_metabox('jkreativ_general.override_navigation', null, $pageid)) {
  104.         $navobj['navpos'] = vp_metabox('jkreativ_general.override_navigation_group.0.navigation_position', 'side', $pageid);
  105.         $navobj['navcollapse'] = vp_metabox('jkreativ_general.override_navigation_group.0.default_collapse_navigator', false, $pageid);
  106.         $navobj['navtopmenu'] = vp_metabox('jkreativ_general.override_navigation_group.0.default_menuheader_navigator', true, $pageid);
  107.         $navobj['navtopcenter'] = vp_metabox('jkreativ_general.override_navigation_group.0.centering_top_navigator', false, $pageid);
  108.         $navobj['navtoptwoline'] = vp_metabox('jkreativ_general.override_navigation_group.0.twoline_top_navigator', false, $pageid);
  109.         $navobj['navtopsmaller'] = vp_metabox('jkreativ_general.override_navigation_group.0.smaller_navigator', false, $pageid);
  110.         $navobj['boxedcontent'] = vp_metabox('jkreativ_general.override_navigation_group.0.boxed_content', false, $pageid);
  111.  
  112.         if($navobj['navpos'] === 'transparent') {
  113.             $navobj['navtoptwoline'] = 0;
  114.             $navobj['navtopcenter'] = vp_metabox('jkreativ_general.override_navigation_group.0.centering_top_navigator_transparent', false, $pageid);
  115.             $navobj['navtopsmaller'] = vp_metabox('jkreativ_general.override_navigation_group.0.smaller_navigator_transparent', false, $pageid);
  116.             $navobj['boxedcontent'] = vp_metabox('jkreativ_general.override_navigation_group.0.boxed_content_transparent', false, $pageid);
  117.         }
  118.  
  119.     }
  120.  
  121.     return $navobj;
  122. }
  123.  
  124.  
  125. function jeg_get_additional_body_class ()
  126. {
  127.     $classstring = array();
  128.     $navobj = jeg_get_navigation_setup();
  129.  
  130.     if($navobj['navpos'] === 'top') {
  131.         array_push($classstring, "horizontalnav");
  132.  
  133.         if($navobj['navtoptwoline']) {
  134.             array_push($classstring, "topnavtwoline");
  135.         }
  136.  
  137.         if($navobj['navtopsmaller']) {
  138.             array_push($classstring, "topnavsmaller");
  139.         }
  140.  
  141.         if($navobj['boxedcontent']) {
  142.             array_push($classstring, "boxcontent");
  143.         }
  144.     } else  if($navobj['navpos'] === 'side') {
  145.         array_push($classstring, "sidenav");
  146.  
  147.         if($navobj['navcollapse']) {
  148.             array_push($classstring, "sidebarcollapse");
  149.         }
  150.         if(!$navobj['navtopmenu']) {
  151.             array_push($classstring, "noheadermenu");
  152.         }
  153.     } else if($navobj['navpos'] === 'transparent') {
  154.         array_push($classstring, "horizontalnav");
  155.         array_push($classstring, "toptransparent");
  156.  
  157.         if($navobj['navtopsmaller']) {
  158.             array_push($classstring, "topnavsmaller");
  159.         }
  160.  
  161.         if($navobj['boxedcontent']) {
  162.             array_push($classstring, "boxcontent");
  163.         }
  164.  
  165.         global $post;
  166.  
  167.         if($post !== null) {
  168.             $template = get_post_meta($post->ID,'_wp_page_template',true);
  169.  
  170.             if($template === 'template/template-fsslider-iosslider.php' || $template === 'template/template-fsslider-kenburn.php' || $template === 'template/template-fsslider-serviceslider.php' || $template === 'template/template-fsslider-media.php') {
  171.                 array_push($classstring, "fullscreenslider");
  172.             } else if($template === 'template/template-landing-page.php' || $template === 'template/template-landing-page-vc.php'){
  173.                 array_push($classstring, "landingtransparent");
  174.             } else {
  175.                 array_push($classstring, "normaltransparent");
  176.             }
  177.         } else {
  178.             array_push($classstring, "normaltransparent");
  179.         }
  180.     }
  181.  
  182.     global $post;
  183.     if(is_single()){
  184.         if($post->post_type === 'portfolio') {
  185.             $layout = get_post_meta($post->ID, 'portfolio_layout', true);
  186.             array_push($classstring , "portfolio-" . $layout);
  187.         } else {
  188.             $layout = vp_metabox('jkreativ_blog_template.template.0.single_blog_template', vp_option('joption.single_blog_template', 'normal'));
  189.             array_push($classstring , "blog-" . $layout);
  190.         }
  191.     }
  192.  
  193.  
  194.     // append landing page style
  195.     if(jeg_is_landing_template()) {
  196.         array_push($classstring , "landingpage");
  197.     }
  198.  
  199.     array_push($classstring , "jkreativ");
  200.  
  201.     return $classstring;
  202. }
  203.  
  204.  
  205. /**
  206.  * Check if landing page
  207.  */
  208. if(!function_exists('jeg_is_landing_template'))
  209. {
  210.     function jeg_is_landing_template ()
  211.     {
  212.         global $post;
  213.  
  214.         if(is_page()) {
  215.             $template = get_post_meta($post->ID,'_wp_page_template',true);
  216.             if($template === 'template/template-landing-page.php'){
  217.                 return true;
  218.             }
  219.         } else if($post->post_type === 'portfolio') {
  220.             $layout = get_post_meta($post->ID, 'portfolio_layout', true);
  221.             if($layout === 'landingpage') {
  222.                 return true;
  223.             }
  224.         }
  225.  
  226.         return false;
  227.     }
  228. }
  229.  
  230.  
  231. /**
  232.  * Detect retina device
  233.  */
  234. function jeg_is_retina_device()
  235. {
  236.     if(isset($_COOKIE["device_pixel_ratio"])) {
  237.         return $_COOKIE["device_pixel_ratio"] > 1;
  238.     } else {
  239.         return false;
  240.     }
  241. }
  242.  
  243.  
  244. /**
  245.  * social icon
  246.  */
  247. function jeg_populate_social () {
  248.     $socialarray = array();
  249.  
  250.     // facebook
  251.     if(vp_option('joption.social_facebook')) {
  252.         $socialarray[] = array(
  253.             'icon'  => 'fa fa-facebook',
  254.             'class' => 'social-facebook',
  255.             'url'   => vp_option('joption.social_facebook'),
  256.             'text'  => 'Facebook'
  257.         );
  258.     }
  259.  
  260.     // twitter
  261.     if(vp_option('joption.social_twitter')) {
  262.         $socialarray[] = array(
  263.             'icon'  => 'fa fa-twitter',
  264.             'class' => 'social-twitter',
  265.             'url'   => vp_option('joption.social_twitter'),
  266.             'text'  => 'Twitter'
  267.         );
  268.     }
  269.  
  270.     // linked in
  271.     if(vp_option('joption.social_linkedin')) {
  272.         $socialarray[] = array(
  273.             'icon'  => 'fa fa-linkedin',
  274.             'class' => 'social-linkedin',
  275.             'url'   => vp_option('joption.social_linkedin'),
  276.             'text'  => 'Linked In'
  277.         );
  278.     }
  279.  
  280.     // Google Plus
  281.     if(vp_option('joption.social_googleplus')) {
  282.         $socialarray[] = array(
  283.             'icon'  => 'fa fa-google-plus',
  284.             'class' => 'social-googleplus',
  285.             'url'   => vp_option('joption.social_googleplus'),
  286.             'text'  => 'Google Plus'
  287.         );
  288.     }
  289.  
  290.     // Pinterest
  291.     if(vp_option('joption.social_pinterest')) {
  292.         $socialarray[] = array(
  293.             'icon'  => 'fa fa-pinterest',
  294.             'class' => 'social-pinterest',
  295.             'url'   => vp_option('joption.social_pinterest'),
  296.             'text'  => 'Pinterest'
  297.         );
  298.     }
  299.  
  300.     // Github
  301.     if(vp_option('joption.social_github')) {
  302.         $socialarray[] = array(
  303.             'icon'  => 'fa fa-github',
  304.             'class' => 'social-github',
  305.             'url'   => vp_option('joption.social_github'),
  306.             'text'  => 'Github'
  307.         );
  308.     }
  309.  
  310.     // Flickr
  311.     if(vp_option('joption.social_flickr')) {
  312.         $socialarray[] = array(
  313.             'icon'  => 'fa fa-flickr',
  314.             'class' => 'social-flickr',
  315.             'url'   => vp_option('joption.social_flickr'),
  316.             'text'  => 'Flickr'
  317.         );
  318.     }
  319.  
  320.     // Tumblr
  321.     if(vp_option('joption.social_tumblr')) {
  322.         $socialarray[] = array(
  323.             'icon'  => 'fa fa-tumblr',
  324.             'class' => 'social-tumblr',
  325.             'url'   => vp_option('joption.social_tumblr'),
  326.             'text'  => 'Tumblr'
  327.         );
  328.     }
  329.  
  330.     // Dribbble
  331.     if(vp_option('joption.social_dribbble')) {
  332.         $socialarray[] = array(
  333.             'icon'  => 'fa fa-dribbble',
  334.             'class' => 'social-dribbble',
  335.             'url'   => vp_option('joption.social_dribbble'),
  336.             'text'  => 'Dribbble'
  337.         );
  338.     }
  339.  
  340.     // Soundcloud
  341.     if(vp_option('joption.social_soundcloud')) {
  342.         $socialarray[] = array(
  343.             'icon'  => 'fa fa-soundcloud',
  344.             'class' => 'social-soundcloud',
  345.             'url'   => vp_option('joption.social_soundcloud'),
  346.             'text'  => 'Soundcloud'
  347.         );
  348.     }
  349.  
  350.     // Behance
  351.     if(vp_option('joption.social_behance')) {
  352.         $socialarray[] = array(
  353.             'icon'  => 'fa fa-behance',
  354.             'class' => 'social-behance',
  355.             'url'   => vp_option('joption.social_behance'),
  356.             'text'  => 'Behance'
  357.         );
  358.     }
  359.  
  360.     // instagram
  361.     if(vp_option('joption.social_instagram')) {
  362.         $socialarray[] = array(
  363.             'icon'  => 'fa fa-instagram',
  364.             'class' => 'social-instagram',
  365.             'url'   => vp_option('joption.social_instagram'),
  366.             'text'  => 'Instagram'
  367.         );
  368.     }
  369.  
  370.     // Vimeo
  371.     if(vp_option('joption.social_vimeo')) {
  372.         $socialarray[] = array(
  373.             'icon'  => 'fa fa-vimeo-square',
  374.             'class' => 'social-vimeo',
  375.             'url'   => vp_option('joption.social_vimeo'),
  376.             'text'  => 'Vimeo'
  377.         );
  378.     }
  379.  
  380.     // 500px
  381.     if(vp_option('joption.social_500px')) {
  382.         $socialarray[] = array(
  383.             'icon'  => 'icon-500px',
  384.             'class' => 'social-500px',
  385.             'url'   => vp_option('joption.social_500px'),
  386.             'text'  => '500px'
  387.         );
  388.     }
  389.  
  390.     return $socialarray;
  391. }
  392.  
  393. function jeg_social_icon($withtext)
  394. {
  395.     $html = "<ul>";
  396.  
  397.     $socialarray = jeg_populate_social();
  398.     foreach($socialarray as $soc) {
  399.         if($withtext) {
  400.             $html .= "<li><a href='" . $soc['url'] . "' class='" . $soc['class'] . "'><i class='" . $soc['icon'] . "'></i>" . $soc['text'] . "</a></li>";
  401.         } else {
  402.             $html .= "<li><a href='" . $soc['url'] . "' class='" . $soc['class'] . "'><i class='" . $soc['icon'] . "'></i></a></li>";
  403.         }
  404.  
  405.     }
  406.  
  407.     $html .= "</ul>";
  408.  
  409.     return $html;
  410. }
  411.  
  412.  
  413. /*** featured heading ***/
  414. if(!function_exists('jeg_get_featured_heading'))
  415. {
  416.     function jeg_get_featured_heading($postid, $w, $h)
  417.     {
  418.         $blogitemtype = vp_metabox('jkreativ_blog_format.format', null, $postid);
  419.         $featured = '';
  420.         switch ($blogitemtype) {
  421.             case 'standard':
  422.                 $imgfeatured = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full');
  423.                 if(!empty($imgfeatured)) {
  424.                     $imgfeatured = jeg_image_resizer($imgfeatured[0], $w, $h);
  425.                     $featured =
  426.                     "<a href='" . get_permalink($postid) . "'>
  427.                         <img src='" .  $imgfeatured . "' alt='" . get_the_title($postid) . "'>
  428.                     </a>";
  429.                 }
  430.                 break;
  431.             case 'imgslider':
  432.                 $imgarr = vp_metabox('jkreativ_blog_slider.binding_group');
  433.                 if(!empty($imgarr)) {
  434.                     $imghtml = '';
  435.                     foreach($imgarr as $img) {
  436.                         $imagecontent = jeg_get_image_attachment($img['image']);
  437.                         $imgfeatured = jeg_image_resizer($imagecontent, $w, $h);
  438.                         $imghtml .= "<img src='{$imgfeatured}' alt='{$img['image']}'/>";
  439.                     }
  440.  
  441.                     $featured=
  442.                     "<div class='article-slider-wrapper loading'>
  443.                         <div class='article-image-slider'>
  444.                             {$imghtml}
  445.                         </div>
  446.                     </div>";
  447.                 }
  448.                 break;
  449.             case 'vimeo':
  450.                 if(vp_metabox('jkreativ_blog_vimeo.vimeo_video_url')) {
  451.                     $featured =
  452.                     "<div data-type='vimeo' data-src='" . vp_metabox('jkreativ_blog_vimeo.vimeo_video_url') . "'>
  453.                         <div class='video-container'></div>
  454.                     </div>";
  455.                 }
  456.                 break;
  457.             case 'youtube':
  458.                 if(vp_metabox('jkreativ_blog_youtube.youtube_video_url')) {
  459.                     $featured =
  460.                     "<div data-type='youtube' data-src='" . vp_metabox('jkreativ_blog_youtube.youtube_video_url') . "'>
  461.                         <div class='video-container'></div>
  462.                     </div>";
  463.                 }
  464.                 break;
  465.             case 'soundcloud':
  466.                 if(vp_metabox('jkreativ_blog_soundcloud.soundcloud_url')) {
  467.                     $featured =
  468.                     "<div data-type='soundcloud' data-src='" . vp_metabox('jkreativ_blog_soundcloud.soundcloud_url') . "'>
  469.                         <div class='video-container'></div>
  470.                     </div>";
  471.                 }
  472.                 break;
  473.             case 'html5video':
  474.                 $featured =
  475.                 "<div data-type='html5video'
  476.                     data-mp4='"     . vp_metabox('jkreativ_blog_html5video.videomp4')   . "'
  477.                     data-webm='"    . vp_metabox('jkreativ_blog_html5video.videowebm')  . "'
  478.                     data-ogg='"     . vp_metabox('jkreativ_blog_html5video.videoogg') . "'
  479.                     data-cover='"   . jeg_get_image_attachment(vp_metabox('jkreativ_blog_html5video.cover')) . "'>
  480.                     <div class='video-container'></div>
  481.                 </div>";
  482.                 break;
  483.             case 'ads':
  484.                 break;
  485.         }
  486.  
  487.         return $featured;
  488.     }
  489. }
  490.  
  491. if(!function_exists('jeg_get_featured_masonry_heading'))
  492. {
  493.     function jeg_get_featured_masonry_heading($postid, $w, $h) {
  494.         $blogitemtype = vp_metabox('jkreativ_blog_format.format', null, $postid);
  495.         $featured = '';
  496.         switch ($blogitemtype) {
  497.             case 'standard':
  498.                 $imgfeatured = wp_get_attachment_image_src( get_post_thumbnail_id($postid), 'full');
  499.                 if(!empty($imgfeatured)) {
  500.                     $imgfeatured = jeg_image_resizer($imgfeatured[0], $w, $h);
  501.                     $featured =
  502.                     "<a href='" . get_permalink($postid) . "'>
  503.                         <div class='article-image'>
  504.                             <img src='". $imgfeatured ."' alt='" . get_the_title($postid) . "'>
  505.                         </div>
  506.                     </a>";
  507.                 }
  508.                 break;
  509.             case 'imgslider':
  510.                 $imgarr = vp_metabox('jkreativ_blog_slider.binding_group');
  511.                 if(!empty($imgarr)) {
  512.                     $imghtml = '';
  513.                     foreach($imgarr as $img) {
  514.                         $imagecontent = jeg_get_image_attachment($img['image']);
  515.                         $imgfeatured = jeg_image_resizer($imagecontent, $w, $h);
  516.                         $imghtml .= "<img src='{$imgfeatured}' alt='{$img['image']}'/>";
  517.                     }
  518.  
  519.                     $featured=
  520.                     "<div class='article-fotorama'>
  521.                         <div class='article-image-slider'>
  522.                             {$imghtml}
  523.                         </div>
  524.                     </div>";
  525.                 }
  526.                 break;
  527.             case 'vimeo':
  528.                 if(vp_metabox('jkreativ_blog_vimeo.vimeo_video_url')) {
  529.                     $featured =
  530.                     "<div data-type='vimeo' data-src='" . vp_metabox('jkreativ_blog_vimeo.vimeo_video_url') . "'>
  531.                         <div class='video-container'></div>
  532.                     </div>";
  533.                 }
  534.                 break;
  535.             case 'youtube':
  536.                 if(vp_metabox('jkreativ_blog_youtube.youtube_video_url')) {
  537.                     $featured =
  538.                     "<div data-type='youtube' data-src='" . vp_metabox('jkreativ_blog_youtube.youtube_video_url') . "'>
  539.                         <div class='video-container'></div>
  540.                     </div>";
  541.                 }
  542.                 break;
  543.             case 'soundcloud':
  544.                 if(vp_metabox('jkreativ_blog_soundcloud.soundcloud_url')) {
  545.                     $featured =
  546.                     "<div data-type='soundcloud' data-src='" . vp_metabox('jkreativ_blog_soundcloud.soundcloud_url') . "'>
  547.                         <div class='video-container'></div>
  548.                     </div>";
  549.                 }
  550.                 break;
  551.             case 'html5video':
  552.                 $featured =
  553.                 "<div data-type='html5video'
  554.                     data-mp4='"     . vp_metabox('jkreativ_blog_html5video.videomp4')   . "'
  555.                     data-webm='"    . vp_metabox('jkreativ_blog_html5video.videowebm')  . "'
  556.                     data-ogg='"     . vp_metabox('jkreativ_blog_html5video.videoogg') . "'
  557.                     data-cover='"   . jeg_get_image_attachment(vp_metabox('jkreativ_blog_html5video.cover')) . "'>
  558.                     <div class='video-container'></div>
  559.                 </div>";
  560.                 break;
  561.             case 'ads':
  562.                 break;
  563.         }
  564.  
  565.         return $featured;
  566.  
  567.     }
  568. }
  569.  
  570.  
  571. // page featured heading
  572. if(!function_exists('jeg_get_page_featured_heading'))
  573. {
  574.     function jeg_get_page_featured_heading($w, $h)
  575.     {
  576.         $blogitemtype = vp_metabox('jkreativ_page_heading.heading_type');
  577.         $featured = '';
  578.         switch ($blogitemtype) {
  579.             case 'standard':
  580.                 if(vp_metabox('jkreativ_page_heading.standard.0.image')) {
  581.                     $imagecover = jeg_get_image_attachment(vp_metabox('jkreativ_page_heading.standard.0.image'));
  582.                     $imgfeatured = jeg_image_resizer($imagecover, $w, $h);
  583.                     $featured =
  584.                     "<a href='" . get_permalink() . "'>
  585.                         <img src='" .  $imgfeatured . "' alt='" . vp_metabox('jkreativ_blog_standard.image_name') . "'>
  586.                     </a>";
  587.                 }
  588.                 break;
  589.             case 'imgslider':
  590.                 $imgarr = vp_metabox('jkreativ_page_heading.imageslider');
  591.                 if(!empty($imgarr)) {
  592.                     $imghtml = '';
  593.                     foreach($imgarr as $img) {
  594.                         $imagecover = jeg_get_image_attachment($img['image']);
  595.                         $imgfeatured = jeg_image_resizer($imagecover, $w, $h);
  596.                         $imghtml .= "<img src='{$imgfeatured}' alt='{$img['image']}'/>";
  597.                     }
  598.  
  599.                     $featured=
  600.                     "<div class='article-slider-wrapper loading'>
  601.                         <div class='article-image-slider'>
  602.                             {$imghtml}
  603.                         </div>
  604.                     </div>";
  605.                 }
  606.                 break;
  607.             case 'vimeo':
  608.                 if(vp_metabox('jkreativ_page_heading.vimeo.0.vimeo_video_url')) {
  609.                     $featured =
  610.                     "<div data-type='vimeo' data-src='" . vp_metabox('jkreativ_page_heading.vimeo.0.vimeo_video_url') . "'>
  611.                         <div class='video-container'></div>
  612.                     </div>";
  613.                 }
  614.                 break;
  615.             case 'youtube':
  616.                 if(vp_metabox('jkreativ_page_heading.youtube.0.youtube_video_url')) {
  617.                     $featured =
  618.                     "<div data-type='youtube' data-src='" . vp_metabox('jkreativ_page_heading.youtube.0.youtube_video_url') . "'>
  619.                         <div class='video-container'></div>
  620.                     </div>";
  621.                 }
  622.                 break;
  623.             case 'soundcloud':
  624.                 if(vp_metabox('jkreativ_page_heading.soundcloud.0.soundcloud_url')) {
  625.                     $featured =
  626.                     "<div data-type='soundcloud' data-src='" . vp_metabox('jkreativ_page_heading.soundcloud.0.soundcloud_url') . "'>
  627.                         <div class='video-container'></div>
  628.                     </div>";
  629.                 }
  630.                 break;
  631.             case 'html5video':
  632.                 $imagecover = jeg_get_image_attachment(vp_metabox('jkreativ_page_heading.html5video.0.cover'));
  633.                 $featured =
  634.                 "<div data-type='html5video'
  635.                     data-mp4='"     . vp_metabox('jkreativ_page_heading.html5video.0.videomp4') . "'
  636.                     data-webm='"    . vp_metabox('jkreativ_page_heading.html5video.0.videowebm') . "'
  637.                     data-ogg='"     . vp_metabox('jkreativ_page_heading.html5video.0.videoogg') . "'
  638.                     data-cover='"   . $imagecover . "'>
  639.                     <div class='video-container'></div>
  640.                 </div>";
  641.                 break;
  642.             case 'ads':
  643.                 break;
  644.         }
  645.  
  646.         return $featured;
  647.     }
  648. }
  649.  
  650.  
  651.  
  652. if(!function_exists('jeg_get_portfolio_featured_heading'))
  653. {
  654.     function jeg_get_portfolio_featured_heading($postid)
  655.     {
  656.         $portfolioitem = get_post_meta($postid, 'jkreativ_portfolio_gallery', true);
  657.         $featured = '';
  658.  
  659.         if(!empty($portfolioitem)) {
  660.             foreach($portfolioitem as $idx => $portfolio) {
  661.                 $portfoliotype = $portfolio['type'];
  662.                 $loadclass = ( $idx === 0 ) ? "loaded" : "notloaded";
  663.                 $mediacover = '';
  664.  
  665.                 if(isset($portfolio['mediacover'])) {
  666.                     $mediacover = jeg_get_image_attachment($portfolio['mediacover']);
  667.                     $mediacoversize = wp_get_attachment_image_src($portfolio['mediacover'], 'full');
  668.                 }
  669.  
  670.                 switch ($portfoliotype) {
  671.                     case 'image' :
  672.                         $image = wp_get_attachment_image_src($portfolio['imageid'], 'full');
  673.                         $thumb = jeg_image_resizer($image[0], 90, 90);
  674.  
  675.                         if($idx === 0) {
  676.                             $featured .=
  677.                             "<div class='portfolio-content-holder item' data-type='image' data-title='{$portfolio['imagename']}' data-thumb='{$thumb}'>
  678.                                 <img src='{$image[0]}' class='{$loadclass}' data-width='{$image[1]}' data-height='{$image[2]}'/>
  679.                             </div>";
  680.                         } else {
  681.                             $featured .=
  682.                             "<div class='portfolio-content-holder item' data-type='image' data-title='{$portfolio['imagename']}' data-thumb='{$thumb}'>
  683.                                 <img src='' data-src='{$image[0]}' class='{$loadclass}' data-width='{$image[1]}' data-height='{$image[2]}'/>
  684.                             </div>";
  685.                         }
  686.  
  687.                         break;
  688.                     case 'youtube' :
  689.                     case 'vimeo' :
  690.                         $thumb = jeg_image_resizer($mediacover, 90, 90);
  691.                         if($idx === 0) {
  692.                             $featured .=
  693.                             "<div class='portfolio-content-holder item' data-type='{$portfoliotype}' data-src='{$portfolio['mediaurl']}' data-title='{$portfolio['title']}' data-thumb='{$thumb}'>
  694.                                 <div class='portfoliovideo-wrapper'>
  695.                                     <img src='{$mediacover}' class='{$loadclass}' data-width='{$mediacoversize[1]}' data-height='{$mediacoversize[2]}'/>
  696.                                     <div class='videooverlay'></div>
  697.                                 </div>
  698.                                 <div class='portfoliovideo-container'><div class='video-container'></div></div>
  699.                             </div>";
  700.                         } else {
  701.                             $featured .=
  702.                             "<div class='portfolio-content-holder item' data-type='{$portfoliotype}' data-src='{$portfolio['mediaurl']}' data-title='{$portfolio['title']}' data-thumb='{$thumb}'>
  703.                                 <div class='portfoliovideo-wrapper'>
  704.                                     <img src='' data-src='{$mediacover}' class='{$loadclass}' data-width='{$mediacoversize[1]}' data-height='{$mediacoversize[2]}'/>
  705.                                     <div class='videooverlay'></div>
  706.                                 </div>
  707.                                 <div class='portfoliovideo-container'><div class='video-container'></div></div>
  708.                             </div>";
  709.                         }
  710.                         break;
  711.                     case 'html5video' :
  712.                         $thumb = jeg_image_resizer($mediacover, 90, 90);
  713.                         if($idx === 0) {
  714.                             $featured .=
  715.                             "<div class='portfolio-content-holder item' data-type='{$portfoliotype}' data-mp4='{$portfolio['videomp4']}' data-webm='{$portfolio['videowebm']}' data-ogg='{$portfolio['videoogg']}' data-title='{$portfolio['title']}' data-thumb='{$thumb}'>
  716.                                 <div class='portfoliovideo-wrapper'>
  717.                                     <img src='{$mediacover}' class='{$loadclass}' data-width='{$mediacoversize[1]}' data-height='{$mediacoversize[2]}'/>
  718.                                     <div class='videooverlay'></div>
  719.                                 </div>
  720.                                 <div class='portfoliovideo-container'><div class='html5-video-container'></div></div>
  721.                             </div>";
  722.                         } else {
  723.                             $featured .=
  724.                             "<div class='portfolio-content-holder item' data-type='{$portfoliotype}' data-cover='{$mediacover}' data-mp4='{$portfolio['videomp4']}' data-webm='{$portfolio['videowebm']}' data-ogg='{$portfolio['videoogg']}' data-title='{$portfolio['title']}' data-thumb='{$thumb}'>
  725.                                 <div class='portfoliovideo-wrapper'>
  726.                                     <img src='' data-src='{$mediacover}' class='{$loadclass}' data-width='{$mediacoversize[1]}' data-height='{$mediacoversize[2]}'/>
  727.                                     <div class='videooverlay'></div>
  728.                                 </div>
  729.                                 <div class='portfoliovideo-container'><div class='html5-video-container'></div></div>
  730.                             </div>";
  731.                         }
  732.                         break;
  733.                     case 'soundcloud' :
  734.                         $thumb = jeg_image_resizer($mediacover, 90, 90);
  735.                         $featured .=
  736.                         "<div class='portfolio-content-holder item' data-type='soundcloud' data-src='{$portfolio['mediaurl']}' data-title='{$portfolio['title']}' data-thumb='{$thumb}'>
  737.                             <div class='video-container'></div>
  738.                         </div>";
  739.                         break;
  740.                     default:
  741.                         break;
  742.                 }
  743.             }
  744.         }
  745.  
  746.         return $featured;
  747.     }
  748. }
  749.  
  750.  
  751.  
  752. /** next prev item **/
  753.  
  754. if ( ! function_exists( 'jeg_next_prev_portfolio' ) )
  755. {
  756.     function jeg_next_prev_portfolio($parentid, $currentid, $to, $category = '')
  757.     {
  758.         $portfolioquery = array(
  759.             'post_type' => 'portfolio',
  760.             'meta_query' => array(
  761.                array(
  762.                    'key' => 'portfolio_parent',
  763.                    'value' => array($parentid),
  764.                    'compare' => 'IN',
  765.                )
  766.             ),
  767.             'orderby' => 'menu_order',
  768.             'order' => 'ASC',
  769.             'nopaging' => true
  770.         );
  771.  
  772.  
  773.         if($category !== '') {
  774.             $portfolioquery['tax_query'] =
  775.             array(
  776.                 array(
  777.                     'taxonomy'  =>  'portfolio_category',
  778.                     'terms'     =>  $category,
  779.                     'field'     => 'id',
  780.                     'operator'  => 'IN'
  781.                 )
  782.             );
  783.         }
  784.  
  785.         $query = new WP_Query($portfolioquery);
  786.  
  787.         $result = $query->posts;
  788.         $currentpost = 0;
  789.  
  790.         foreach($result as $key => $res) {
  791.             if($currentid === $res->ID) {
  792.                 $currentpost = $key;
  793.                 break;
  794.             }
  795.         }
  796.  
  797.         if($to === 'next') {
  798.             $nextpost = $currentpost + 1;
  799.             if($nextpost >= sizeof($result)) {
  800.                 $nextpost = 0;
  801.             }
  802.  
  803.             $nextcontent = $result[$nextpost];
  804.             return $nextcontent->ID;
  805.         } else {
  806.             $prevpost = $currentpost - 1;
  807.             if($prevpost < 0) {
  808.                 $prevpost = sizeof($result) - 1;
  809.             }
  810.             $prevcontent = $result[$prevpost];
  811.             return $prevcontent->ID;
  812.         }
  813.     }
  814. }
  815.  
  816. /** next prev item **/
  817.  
  818.  
  819. /*** excerpt setup ***/
  820.  
  821. function jeg_excerpt_masonry_length () {
  822.     return 30;
  823. }
  824.  
  825. function jeg_excerpt_length( $length )
  826. {
  827.     return 50;
  828. }
  829.  
  830. if ( ! function_exists( 'jeg_continue_reading_link' ) )
  831. {
  832.     function jeg_continue_reading_link() {
  833.         return ' <a class="readmore" href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'jeg_textdomain' ) . '</a>';
  834.     }
  835. }
  836.  
  837. function jeg_auto_excerpt_more( $more ) {
  838.     return ' &hellip;' . jeg_continue_reading_link();
  839. }
  840.  
  841. function jeg_continue_reading_link() {
  842.     return ' <a class="readmore" href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'jeg_textdomain' ) . '</a>';
  843. }
  844.  
  845. function jeg_custom_excerpt_more( $output ) {
  846.     if ( has_excerpt() && ! is_attachment() ) {
  847.         $output .= jeg_continue_reading_link();
  848.     }
  849.     return $output;
  850. }
  851.  
  852. add_filter( 'excerpt_length', 'jeg_excerpt_length' );
  853. add_filter( 'excerpt_more', 'jeg_auto_excerpt_more' );
  854.  
  855.  
  856. /**
  857.  * Jeg Pagination
  858.  *
  859.  * @todo need to fix this functionality, on some number of page, its doesn't work as expected
  860.  **/
  861. function jlimitme ($type = "high", $point, $limit){
  862.     if($type == "high") {
  863.         return  ( $point > $limit ) ? $limit : $point;
  864.     } else {
  865.         return  ( $point > $limit ) ? $point : $limit;
  866.     }
  867. }
  868.  
  869. function jeg_posts_link_attributes() {
  870.     return 'class="btn"';
  871. }
  872.  
  873. function jeg_new_pagination($pageid, $curpage, $totalPage = 0, $step = 2)
  874. {
  875.     if($totalPage > 1) {
  876.         $pagingCount = ( $step * 2 ) + 1;
  877.  
  878.         $html = '<div class="pagedot">';
  879.  
  880.         if( $curpage > $step + 1 && $totalPage > $pagingCount ) {
  881.             $html .= "<a data-page='1' href='" . get_pagenum_link(1) . "'><span>&laquo</span></a>";
  882.         }
  883.         if( $curpage > 1 && $pagingCount < $totalPage ) {
  884.             $html .= get_previous_posts_link('<span>&lsaquo;</span>');
  885.         }
  886.  
  887.         /** loop page **/
  888.         for($i = jlimitme('low', $curpage - $step, 1) ; $i <= jlimitme('high', $totalPage , $curpage + $step) ; $i++){
  889.             if($i == $curpage) {
  890.                 $html .= '<span>'.$i.'</span>';
  891.             } else {
  892.                 $html .= "<a data-page='{$i}' href='" . get_pagenum_link($i) . "'><span>{$i}</span></a>";
  893.             }
  894.         }
  895.  
  896.         if( $curpage < $totalPage && $pagingCount < $totalPage ) {
  897.             $html .= get_next_posts_link('<span>&rsaquo;</span>');
  898.         }
  899.  
  900.         if( $curpage < $totalPage - 1 && $curpage + $step + 1 <= $totalPage && $pagingCount < $totalPage ) {
  901.             $html .= "<a data-page='{$totalPage}' href='" . get_pagenum_link($totalPage) . "'><span>&raquo;</span></a>";
  902.         }
  903.  
  904.         $html .= "</div>";
  905.  
  906.         $html .= "<div class='pagetext'>
  907.             <span class='pagenow'>" . __('Page','jeg_textdomain') . "  <strong class='curpage'>{$curpage}</strong></span>
  908.             <span class='pagetotal'>" . __('From','jeg_textdomain') . "  <strong class='totalpage'>{$totalPage}</strong></span>
  909.         </div>";
  910.  
  911.         return $html;
  912.     } else {
  913.         return ;
  914.     }
  915. }
  916.  
  917.  
  918.  
  919. /***
  920.  * Post View Count
  921.  */
  922.  function jeg_get_post_views($postID) {
  923.     $count_key = 'post_views_count';
  924.     $count = get_post_meta($postID, $count_key, true);
  925.     if($count==''){
  926.         delete_post_meta($postID, $count_key);
  927.         add_post_meta($postID, $count_key, '0');
  928.         return "0 View";
  929.     }
  930.     return $count.' Views';
  931. }
  932.  
  933. function jeg_set_post_views($postID) {
  934.     $count_key = 'post_views_count';
  935.     $count = get_post_meta($postID, $count_key, true);
  936.     if($count=='') {
  937.         $count = 0;
  938.         delete_post_meta($postID, $count_key);
  939.         add_post_meta($postID, $count_key, '0');
  940.     } else{
  941.         $count++;
  942.         update_post_meta($postID, $count_key, $count);
  943.     }
  944. }
  945.  
  946.  
  947. /** comment **/
  948. function jeg_get_wordpress_comment()
  949. {
  950.     $number = get_comments_number();
  951.  
  952.     if ( $number > 1 ) {
  953.         $output = str_replace('%', number_format_i18n($number), __('% Comments', 'jeg_textdomain'));
  954.     }
  955.     elseif ( $number == 0 ) {
  956.         $output = __('No Comments', 'jeg_textdomain');
  957.     }
  958.     else { // must be one
  959.         $output = __('1 Comment', 'jeg_textdomain');
  960.     }
  961.  
  962.     return $output;
  963. }
  964.  
  965.  
  966.  
  967. function jeg_comment($comment, $args, $depth) {
  968.     $GLOBALS['comment'] = $comment;
  969. ?>
  970. <li <?php comment_class(); ?>>
  971.     <div id="comment-<?php comment_ID(); ?>">
  972.         <div class="coment-box">
  973.             <div class="coment-box-inner">
  974.                 <div class="comment-autor">
  975.                     <?php echo get_avatar($comment,$size='80',$default='' ); ?>
  976.                 </div>
  977.  
  978.                 <div class="comment-meta">
  979.                     <ul>
  980.                         <li class="addby">
  981.                             <div class="authorcomment"><?php comment_author_link(); ?></div>
  982.                             <span data-comment-id="<?php comment_ID(); ?>" class="replycomment"><?php _e('Reply', 'jeg_textdomain'); ?></span>
  983.                             <span class="closecommentform"><?php _e('Cancel Reply', 'jeg_textdomain'); ?></span>
  984.                         </li>
  985.                         <li class="addtime"><?php echo get_comment_date('F j, Y'); ?></li>
  986.                     </ul>
  987.                 </div>
  988.  
  989.                 <div class="comment-text">
  990.                     <?php
  991.                     if($comment->comment_approved == '0') :
  992.                         echo "<em class=\"comment-moderation-text\">" . __("Your comment is awaiting moderation", "jeg_textdomain") . "</em>";
  993.                     endif;
  994.                     echo '<p>' . get_comment_text() . '</p>';
  995.                     ?>
  996.                 </div>
  997.                 <div style="clear: both;"></div>
  998.             </div>
  999.         </div>
  1000.     </div>
  1001. </li>
  1002. <?php
  1003. }
  1004.  
  1005.  
  1006. /** location builder **/
  1007.  
  1008. function jeg_location_block($idx, $location) {
  1009.     $html = '<div class="locationlist"><div data-index="'. $idx .'" class="mapitem">';
  1010.     if($location['title_leading'] !== '') {
  1011.         $html .= '<h4>' . $location['title_leading'] . ' : ' . $location['title'] . '</h4>';
  1012.     } else {
  1013.         $html .= '<h4>' . $location['title'] . '</h4>';
  1014.     }
  1015.     $html .= '<div class="mapdetail"><ul>';
  1016.  
  1017.     if($location['address'] !== '') {
  1018.         $html .= '<li><div class="detail">' . $location['address'] . '</div></li>';
  1019.     }
  1020.     if($location['address_second'] !== '') {
  1021.         $html .= '<li><div class="detail">' . $location['address_second'] . '</div></li>';
  1022.     }
  1023.     if($location['phone'] !== '') {
  1024.         $html .= '<li><div class="detail">' . $location['phone'] . '</div></li>';
  1025.     }
  1026.     if($location['email'] !== '') {
  1027.         $html .= '<li><div class="detail">' . $location['email'] . '</div></li>';
  1028.     }
  1029.     if($location['website'] !== '') {
  1030.         $html .= '<li><div class="detail"><a target="_blank" href="' . $location['website'] . '">' . $location['website'] . '</a></div></li>';
  1031.     }
  1032.  
  1033.     $html .= '</ul></div><div class="mapwrapper mapbutton"><span class="button-text">' . __('GET DIRECTION', 'jeg_textdomain') . '</span></div>';
  1034.     $html .= '</div></div>';
  1035.  
  1036.     return $html;
  1037. }
  1038.  
  1039.  
  1040. function jeg_info_window($idx, $location) {
  1041.     $html = '<div class="infowindow" data-lat="' . $location['x'] . '" data-lng="' . $location['y'] . '">';
  1042.     $html .= '<div class="infowindow-wrapper">';
  1043.     $html .= '<h4>' . $location['title'] . '</h4>';
  1044.     $html .= '<ul>';
  1045.  
  1046.     if($location['address'] !== '') {
  1047.         $html .= '<li><div class="detail">' . $location['address'] . '</div></li>';
  1048.     }
  1049.     if($location['address_second'] !== '') {
  1050.         $html .= '<li><div class="detail">' . $location['address_second'] . '</div></li>';
  1051.     }
  1052.     if($location['phone'] !== '') {
  1053.         $html .= '<li><div class="detail">' . $location['phone'] . '</div></li>';
  1054.     }
  1055.     if($location['email'] !== '') {
  1056.         $html .= '<li><div class="detail">' . $location['email'] . '</div></li>';
  1057.     }
  1058.     if($location['website'] !== '') {
  1059.         $html .= '<li><div class="detail">' . $location['website'] . '</div></li>';
  1060.     }
  1061.  
  1062.     $html .= '</ul></div><div class="closeme"></div></div>';
  1063.  
  1064.     return $html;
  1065. }
  1066.  
  1067.  
  1068. function jeg_get_all_portfolio_category ($pageid) {
  1069.     $category = array();
  1070.     $query = new WP_Query(array(
  1071.         'post_type' => 'portfolio',
  1072.         'meta_query' => array(
  1073.             array(
  1074.                'key' => 'portfolio_parent',
  1075.                'value' => array($pageid),
  1076.                'compare' => 'IN',
  1077.            )
  1078.         )
  1079.     ));
  1080.  
  1081.     $result = $query->posts;
  1082.     foreach($result as $res) {
  1083.         $termlist = get_the_terms($res->ID, JEG_PORTFOLIO_CATEGORY);
  1084.  
  1085.         if($termlist) {
  1086.             foreach($termlist as $term) {
  1087.                 $category[$term->term_id] = $term->name;
  1088.             }
  1089.         }
  1090.     }
  1091.  
  1092.     return $category;
  1093. }
  1094.  
  1095.  
  1096. function jeg_to_slug($str)
  1097. {
  1098.     $replace    = '-';
  1099.     $trans = array(
  1100.         '&\#\d+?;'              => '',
  1101.         '&\S+?;'                => '',
  1102.         '\s+'                   => $replace,
  1103.         '[^a-z0-9\-\._]'        => '',
  1104.         $replace.'+'            => $replace,
  1105.         $replace.'$'            => $replace,
  1106.         '^'.$replace            => $replace,
  1107.         '\.+$'                  => ''
  1108.     );
  1109.  
  1110.     $str = strip_tags($str);
  1111.  
  1112.     foreach ($trans as $key => $val) :
  1113.         $str = preg_replace("#".$key."#i", $val, $str);
  1114.     endforeach;
  1115.  
  1116.     return trim(stripslashes(strtolower($str)));
  1117. }
  1118.  
  1119.  
  1120. /**** woo commerce ****/
  1121.  
  1122. function jeg_share_item() {
  1123.     $html = '';
  1124.     $postid = get_the_ID();
  1125.  
  1126.     $html =
  1127.     "<div class='normal-sharrre-container normal-post-sharrre'>
  1128.         <div class='twitter-share-block'
  1129.             data-url='" . get_page_link($postid) . "'
  1130.             data-text='" . get_the_title() . "'
  1131.             data-title='" . __('Tweet','jeg_textdomain') . "'></div>
  1132.         <div class='facebook-share-block'
  1133.             data-url='" . get_page_link($postid) . "'
  1134.             data-text='" . get_the_title() . "'
  1135.             data-title='" . __('Like','jeg_textdomain') . "'></div>
  1136.         <div class='googleplus-share-block'
  1137.             data-url='" . get_page_link($postid) . "'
  1138.             data-text='" . get_the_title() . "'
  1139.             data-title='" . __('Share','jeg_textdomain') . "'></div>
  1140.         <div class='pinterest-share-block'
  1141.             data-url='" . get_page_link($postid) . "'
  1142.             data-text='" . get_the_title() . "'
  1143.             data-title='" . __('Pin','jeg_textdomain') . "'></div>
  1144.     </div>
  1145.     <div class='clearfix'></div>";
  1146.  
  1147.     echo $html;
  1148. }
  1149.  
  1150. add_filter('woocommerce_share', 'jeg_share_item');
  1151.  
  1152.  
  1153.  
  1154. if ( ! function_exists( 'jeg_woocommerce_content' ) )
  1155. {
  1156.     function jeg_woocommerce_content() {
  1157.         if ( is_singular( 'product' ) ) {
  1158.             while ( have_posts() ) {
  1159.                 the_post();
  1160.                 woocommerce_get_template_part( 'content', 'single-product' );
  1161.             }
  1162.         } else {
  1163.             if ( have_posts() ) {
  1164.                 woocommerce_get_template_part( 'content', 'shop' );
  1165.             } else {
  1166.                 woocommerce_get_template( 'loop/no-products-found.php' );
  1167.             }
  1168.         }
  1169.     }
  1170. }
  1171.  
  1172. if( ! function_exists('jeg_encodeURIComponent'))
  1173. {
  1174.     function jeg_encodeURIComponent($str) {
  1175.         $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
  1176.         return strtr(rawurlencode($str), $revert);
  1177.     }
  1178. }
  1179.  
  1180.  
  1181.  
  1182. if( ! function_exists('jeg_get_query_paged')) {
  1183.     function jeg_get_query_paged () {
  1184.         $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  1185.         $page = ( get_query_var('page') ) ? get_query_var('page') : 1;
  1186.         return ( $paged > $page ) ? $paged : $page;
  1187.     }
  1188. }
  1189.  
  1190.  
  1191. function jeg_get_google_font() {
  1192.     $font = vp_get_gwf_family();
  1193.     $fontlist = array();
  1194.     $fontlist[] = '';
  1195.     foreach($font as $fl){
  1196.         $fontlist[$fl['value']] = $fl['label'];
  1197.     }
  1198.     return $fontlist;
  1199. }
  1200.  
  1201. function jeg_hext_rgb($hex){
  1202.     return sscanf($hex, "#%02x%02x%02x");
  1203. }
  1204.  
  1205. function jeg_get_gallery_product_data($postid)
  1206. {
  1207.     $data = array();
  1208.  
  1209.     $data['overwrite_gallery']  = vp_metabox('jkreativ_product.overwrite_gallery', null, $postid);
  1210.     $data['gallery_layout']     = 'normal';
  1211.     $data['product_width']      = 400;
  1212.     $data['product_height']     = 1;
  1213.     $data['justified_height']   = 250;
  1214.     $data['user_margin']        = 1;
  1215.     $data['margin_size']        = 5;
  1216.     $data['expand_script']      = 'magnific';
  1217.     $data['scale_mode']         = 'fit';
  1218.  
  1219.     if($data['overwrite_gallery']) {
  1220.         $data['product_fullwidth'] = vp_metabox('jkreativ_product.gallery.0.single_product_fullwidth', null, $postid);
  1221.         if($data['product_fullwidth']) {
  1222.             $data['gallery_layout']     = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.product_single_type', 'normal', $postid);
  1223.             $data['product_width']      = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_product_width', 400, $postid);
  1224.             $data['product_height']     = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_item_height', 1, $postid);
  1225.             $data['justified_height']   = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_justified_height', 1, $postid);
  1226.             $data['user_margin']        = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_product_use_margin', 1, $postid);
  1227.             $data['margin_size']        = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_product_margin_size', 5, $postid);
  1228.             $data['expand_script']      = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_expand_mode', 'magnific', $postid);
  1229.             $data['scale_mode']         = vp_metabox('jkreativ_product.gallery.0.grid_gallery.0.single_scale_mode', 'fit', $postid);
  1230.         }
  1231.     } else {
  1232.         $data['product_fullwidth'] = vp_option('joption.single_product_fullwidth');
  1233.         if($data['product_fullwidth']) {
  1234.             $data['gallery_layout']     = vp_option('joption.product_single_type', 'normal', $postid);
  1235.             $data['product_width']      = vp_option('joption.single_product_width', 400);
  1236.             $data['product_height']     = vp_option('joption.single_item_height', 1);
  1237.             $data['justified_height']   = vp_option('joption.single_justified_height', 250);
  1238.             $data['user_margin']        = vp_option('joption.single_product_use_margin', 1);
  1239.             $data['margin_size']        = vp_option('joption.single_product_margin_size', 5);
  1240.             $data['expand_script']      = vp_option('joption.single_expand_mode', 'magnific');
  1241.             $data['scale_mode']         = vp_option('joption.single_scale_mode', 'fit');
  1242.         }
  1243.     }
  1244.  
  1245.     return $data;
  1246. }
  1247.  
  1248.  
  1249. function jeg_get_image_attachment($imageid)
  1250. {
  1251.     $imagedata = wp_get_attachment_image_src($imageid, "full");
  1252.     return $imagedata[0];
  1253. }
  1254.  
  1255.  
  1256. /**
  1257.  * Jkreativ cache method
  1258.  * use template base caching
  1259.  */
  1260.  
  1261. class Jeg_Fragment_Cache {
  1262.     var $key;
  1263.     var $ttl;
  1264.  
  1265.     public function __construct( $key, $ttl ) {
  1266.         $this->key = $key;
  1267.         $this->ttl = $ttl;
  1268.     }
  1269.  
  1270.     public function output()
  1271.     {
  1272.         $output = get_transient( $this->key );
  1273.         if ( !empty( $output ) ) {
  1274.             echo $output;
  1275.             return true;
  1276.         } else {
  1277.             ob_start();
  1278.             return false;
  1279.         }
  1280.     }
  1281.  
  1282.     public function store()
  1283.     {
  1284.         $output = ob_get_flush();
  1285.         set_transient( $this->key, $output, $this->ttl );
  1286.     }
  1287. }
  1288.  
  1289. function jeg_is_in_cache_list($slug, $name) {
  1290.     return apply_filters('jeg_check_in_cache_list', false, $slug, $name);
  1291. }
  1292.  
  1293. function jeg_get_template_part($slug, $name = null)
  1294. {
  1295.     if(jeg_is_in_cache_list($slug, $name)) {
  1296.         if(!is_null($name)) {
  1297.             $slug = $slug . '-' . $name;
  1298.         }
  1299.         $frag = new Jeg_Fragment_Cache( $slug, 60*60*24*7 );
  1300.         if ( !$frag->output() ) {
  1301.             get_template_part($slug, $name);
  1302.             $frag->store();
  1303.         }
  1304.     } else {
  1305.         get_template_part($slug, $name);
  1306.     }
  1307. }
  1308.  
  1309. function jeg_get_slider_id() {
  1310.     global $post;
  1311.     if($post->post_type === 'portfolio') {
  1312.         $layout = get_post_meta($post->ID, 'portfolio_layout', true);
  1313.  
  1314.         if($layout === 'landingpage') {
  1315.             $sliderid = vp_metabox('jkreativ_portfolio_landing.heading_slider');
  1316.         } else if($layout === 'landingpagevc') {
  1317.             $sliderid = vp_metabox('jkreativ_portfolio_landing_vc.heading_slider');
  1318.         }
  1319.  
  1320.     } else {
  1321.         $template = get_post_meta($post->ID,'_wp_page_template',true);
  1322.         if($template === "template/template-landing-page.php") {
  1323.             $sliderid = vp_metabox('jkreativ_page_landing.heading_slider');
  1324.         } else if($template === "template/template-landing-page-vc.php") {
  1325.             $sliderid = vp_metabox('jkreativ_page_landing_vc.heading_slider');
  1326.         }
  1327.     }
  1328.     return $sliderid;
  1329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement