<?php
   /* 
   * Theme: PREMIUMPRESS CORE FRAMEWORK FILE
   * Url: www.premiumpress.com
   * Author: Mark Fail
   *
   * THIS FILE WILL BE UPDATED WITH EVERY UPDATE
   * IF YOU WANT TO MODIFY THIS FILE, CREATE A CHILD THEME
   *
   * http://codex.wordpress.org/Child_Themes
   */
   if (!defined('THEME_VERSION')) {	header('HTTP/1.0 403 Forbidden'); exit; }
   
   global $CORE, $userdata, $settings, $post; 
    
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////// 

$page = "search";
if(isset($GLOBALS['flag-taxonomy-type']) && in_array($GLOBALS['flag-taxonomy-type'] ,array("store")) ){
$page = "store";
} 
 
$widgets = ppt_theme_main_widgets($page);
$search_order  = _ppt('searchwidgets_'.$page.'_order');
 
if(is_array($search_order) && !empty($search_order)){
	
   $customWidgets = 1;
	$newFilters = array();
	foreach($widgets as $k => $f){
		$newFilters[$k] = $f;
		$newFilters[$k]['order'] = 100;
	}
	
	$i=1;
	foreach($search_order as $kg => $gg){
		if(isset($newFilters[$kg])){
			$newFilters[$kg]['order'] = $i;
			$i++;
		}
	}  

  $order = array_column($newFilters, 'order'); 
	array_multisort( $order, SORT_ASC, $newFilters);  
  $widgets = $newFilters; 
 
}else{

   $widgets = ppt_theme_main_widgets($page, true); 

} 
 

if( is_array($widgets) && !empty($widgets) ){
 
   foreach($widgets as $widget => $widget_on ){      

         $wn = str_replace($page."_","",$widget);
   
         if( isset($customWidgets) && _ppt(array('searchwidgets', $page."_".$wn)) != 1){
            continue;
         }
         
         _ppt_template( 'widgets/widget-'.$wn ); 
       
   }
}
 
?>
