',
'container_widgets_pieces',
'widget_corner widget_top_left',
'widget_token_left',
'widget_topbottom widget_top_center',
'widget_corner widget_top_right',
'widget_token_right',
'widget_sides widget_middle_left',
'widget_center widget_content',
'widget_sides widget_middle_right',
'widget_corner widget_bottom_left',
'widget_topbottom widget_bottom_center',
'widget_corner widget_bottom_right',
'widget_token_bottom'
);
$new_classes=array('
',
'container_widgets_pieces '.$reset_boxes,
'widget_corner widget_top_left '.$reset_boxes,
'widget_token_left '.$reset_boxes,
'widget_topbottom widget_top_center '.$reset_boxes,
'widget_corner widget_top_right '.$reset_boxes,
'widget_token_right '.$reset_boxes,
'widget_sides widget_middle_left '.$reset_boxes,
'widget_center widget_content '.$reset_boxes,
'widget_sides widget_middle_right '.$reset_boxes,
'widget_corner widget_bottom_left '.$reset_boxes,
'widget_topbottom widget_bottom_center '.$reset_boxes,
'widget_corner widget_bottom_right '.$reset_boxes,
'widget_token_bottom '.$reset_boxes
);
ob_start();
dynamic_sidebar($position);
$sidebar_contents = ob_get_clean();
echo str_replace($class_originals,$new_classes,$sidebar_contents);
}
function update_layout(){
$layout_pack=array();
foreach($GLOBALS['pages'] as $index => $page){//$GLOBALS['pages'] ver en functions/variables_load.php
if ($page->ID===0){// asignar slider para el single post,search,archive y category
$layout_pack[$page->ID]['slider_blog']=true;
$layout_pack[$page->ID]['slider_single']=true;
$layout_pack[$page->ID]['slider_search']=false;
$layout_pack[$page->ID]['slider_archive']=false;
$layout_pack[$page->ID]['slider_category']=false;
$layout_pack['themeshock_default_widget_boxes'] = true;
}
else{
$layout_pack[$page->ID]['slider_page']=true;/// asigna slider dependiendo el id del pageel blog o home el caso es el 0
}
$layout_pack[$page->ID]['footer_widget_style']=$GLOBALS['style_widgets_default'];//asignar estilos al footer
foreach($GLOBALS['sidebar_info'] as $position_widgets=> $description ){//asignar estilos y posiciones en el layout
$layout_pack[$page->ID][$position_widgets]['active']=($position_widgets==='right_1')?true:false;//define layout habilitado por default en este caso es right_1
$layout_pack[$page->ID][$position_widgets]['style']=$GLOBALS['style_widgets_default'];
}
}
update_option('themeshock_layout_options',maybe_serialize($layout_pack));//regitrar layout en los didebar
return $layout_pack;//carga todas las posiciones de los layouts;
}
function update_sidebar(){
$sidebars=array();
foreach($GLOBALS['position_lay_widgets'] as $position_widgets ){
$sidebars[$position_widgets]=$GLOBALS['register_sidebar'];
$sidebars[$position_widgets]['name']=$position_widgets;
}
update_option('themeshock_sidebar',maybe_serialize($sidebars));//registra un sidebar en las posisciones
return $sidebars;
}
function update_slider_info(){
$upload_dir=wp_upload_dir();
if (isset($upload_dir["error"]) && $upload_dir["error"]!==false ){
$GLOBALS['error_folder']= 'The option to change logo and slider is disabled, please create the following folder: /wp-content/uploads/ and allow writing by setting its permissions to 0777';
return false;
}
$directory_slider=$upload_dir['basedir']."/slider/";
if (!is_dir($directory_slider)){
mkdir($directory_slider,0777,true);
}
$directory_slider_base=get_template_directory()."/img/slider/{*.jpg,*.png,*.gif,*.bmp}";
$img_directory_pack=glob($directory_slider_base,GLOB_BRACE);
$slider_info= array();
$img_dimensions=get_option('themeshock_slider_dimensions');//carga las imagenes
foreach($img_directory_pack as $index => $img_slider_info){
// $get_info_img=getimagesize($img_slider_info);
$slider_info[$index]['active']=true;
$slider_info[$index]['link']='#';
$slider_info[$index]['url']=$upload_dir['baseurl'].'/slider/'.basename($img_slider_info);
$slider_info[$index]['path']=$upload_dir['basedir'].'/slider/'.basename($img_slider_info);//imagen original
$image = wp_get_image_editor($img_slider_info);
if ( is_wp_error( $image ) ) {
$GLOBALS['error_folder']='Please install GD 2 In your server';
return false;
}else{
$image->save( $slider_info[$index]['path'] );
}
$sld_bs_p=$upload_dir['basedir'].'/slider/';
$filename=basename($img_slider_info);
/*Hacer reingeniera con respecto a slider_images*/
foreach ($img_dimensions as $img_type => $value){
switch ($img_type){
case 'sld_hd':
$slider_info[$index]['img_hd']=$upload_dir['baseurl'].'/slider/hd_'.$filename;
$path_dst=$sld_bs_p.'hd_'.$filename;
break;
case 'sld_normal':
$slider_info[$index]['url']=$upload_dir['baseurl'].'/slider/md_'.$filename;
$path_dst=$sld_bs_p.'md_'.$filename;
break;
case 'sld_th':
$slider_info[$index]['thumbnail']=$upload_dir['baseurl'].'/slider/th_'.$filename;
$path_dst=$sld_bs_p.'th_'.$filename;
break;
}
$image = wp_get_image_editor( $slider_info[$index]['path']);
$image->resize( (int)$value['w'], (int)$value['h'],true);
$image->save( $path_dst );
}
}
// update_option('themeshock_slider_dimensions',$sld_dimensions);/// guarda las dimenssiones de la imagen
update_option('themeshock_slider_images',maybe_serialize($slider_info));
$GLOBALS['slider_img_info']=$slider_info;
return $slider_info;
}
function update_logo_info(){
$upload_dir=wp_upload_dir();
if (isset($upload_dir["error"]) && $upload_dir["error"]!==false ){
$GLOBALS['error_folder']= 'The option to change logo and slider is disabled, please create the following folder: /wp-content/uploads/ and allow writing by setting its permissions to 0777';
return false;
}
$directory_logo=$upload_dir['basedir'].'/logo/';
$get_img_logo=get_template_directory_uri().'/img/logo/logo.png';
$get_dimmensions=getimagesize($get_img_logo);
$logo_info['path']=$upload_dir['basedir'].'/logo/logo.png';
$logo_info['url']=$upload_dir['baseurl'].'/logo/logo.png';
$logo_info['size']=$get_dimmensions;
@mkdir($directory_logo,0777,true);
$image = wp_get_image_editor($get_img_logo);
$image->save($logo_info['path']);
chmod($logo_info['path'],0777);
update_option('themeshock_logo',maybe_serialize($logo_info));
return $logo_info;
}
/*
Esta funcion es exlusiva para el servidor, es para mostrar y ocultar elementos y recibe el parametro del elemento que se
va afectar
*/
function display_elements($element_block){
if(isset($GLOBALS['display_elements']) && $_SERVER['SERVER_NAME'] == 'www.wpthemegenerator.com'){
switch($GLOBALS['display_elements'][$element_block]){
case 'show':
return 'show_element';
break;
case 'hide':
return 'hide_element';
break;
}
}
}
/* funcion para traer los atributos del logo actual y aplicarlos */
function get_attr_logo(){
$eff_logo = $style_logo = $img_logo = NULL;
if($GLOBALS['logo_type'] == 'text'){
$eff_logo = 'logo_effect_'.strtolower($GLOBALS['logo_text_options']['logo_effect']);
$style_logo = 'font-size: '.$GLOBALS['logo_text_options']['logo_text_font_size'].'; display:block;';
if($GLOBALS['logo_text_options']['logo_font_family'] != 'Default'){
$style_logo .= 'font-family: "'.$GLOBALS['logo_text_options']['logo_font_family'].'", sans-serif;';
}
}
$style_attr = ($style_logo != "")?"style='".$style_logo."'":"";
$src_logo = ($GLOBALS['logo_info'])?$GLOBALS['logo_info']['url']:get_template_directory_uri();
if(!empty($GLOBALS['arg_text_logo']) && $GLOBALS['arg_text_logo'][4] == "text"){
$img_logo = '

'.$GLOBALS['arg_text_logo'][0].'
';
}else{
if($GLOBALS['logo_type'] == 'image'){
$img_logo = '
.')
';
}else{
$img_logo = '
'.$GLOBALS['logo_text_options']['logo_text'].'
';
}
}
return '
'.$img_logo.'';
}
/* funciton para quitar los puntos suspensivos del excerpt */
function trim_excerpt($text) {
return str_replace(" [...]", '...', $text);
}
add_filter('get_the_excerpt', 'trim_excerpt');
function trim_the_content( $the_contents, $read_more_tag = ' READ MORE...', $perma_link_to = '', $all_words = 45 ) {
$allowed_tags = array( 'a', 'abbr', 'b', 'blockquote', 'b', 'cite', 'code', 'div', 'em', 'fon', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'label', 'i', 'p', 'pre', 'span', 'strong', 'title', 'ul', 'ol', 'li', 'object', 'embed', 'input' );
if( $the_contents != '' ) {
$allowed_tags = '<' . implode( '><', $allowed_tags ) . '>';
$the_contents = str_replace( ']]>', ']]>', $the_contents );
$the_contents = strip_tags( $the_contents, $allowed_tags );
if( $all_words > count( preg_split( '/[\s]+/', strip_tags( $the_contents ), -1 ) ) ) return $the_contents;
$all_chunks = preg_split( '/([\s]+)/', $the_contents, -1, PREG_SPLIT_DELIM_CAPTURE );
$the_contents = '';
$count_words = 0;
$enclosed_by_tag = false;
foreach( $all_chunks as $chunk ) {
if( 0 < preg_match( '/<[^>]*$/s', $chunk ) ) $enclosed_by_tag = true;
elseif( 0 < preg_match( '/>[^<]*$/s', $chunk ) ) $enclosed_by_tag = false;
if( !$enclosed_by_tag && '' != trim( $chunk ) && substr( $chunk, -1, 1 ) != '>' ) $count_words ++;
$the_contents .= $chunk;
if( $count_words >= $all_words && !$enclosed_by_tag ) break;
}
$the_contents = $the_contents . '
' . $read_more_tag . '';
$the_contents = force_balance_tags( $the_contents );
}
return $the_contents;
}
/* funcion para actualizar el estado de los post type
recibe dos parametros el post name, y el estado nuevo */
function statusCustomPostType($wtsPostName, $wtsStatus){
global $wpdb, $post;
(isset($_POST['themeshock_enablePostTypeGallery']) || isset($_POST['themeshock_enablePostTypePortfolio']) || isset($_POST['themeshock_enablePostTypeServices']) || isset($_POST['themeshock_enablePostTypeProducts']) ||
isset($_POST['themeshock_enablePostTypeTestimonials']))?$redirect_warr = 'true':$redirect_warr = 'false';
if (is_user_logged_in()){
$wpdb->query("
UPDATE $wpdb->posts
SET post_status = '".$wtsStatus."'
WHERE post_name = '".$wtsPostName."';"
);
$menu_current = get_theme_mod('nav_menu_locations');
if($menu_current['shock_menu'] != 0){
$term_shock_menu = get_term_by('term_id', $menu_current['shock_menu'], 'nav_menu');
$idsPostNameWts = $wpdb->get_results("SELECT ID FROM wp_posts w where post_name like '%wts%' and post_status = 'trash'");
$resultMenuItems = $wpdb->get_results($wpdb->prepare("SElECT post_id, meta_value FROM wp_term_relationships rs, wp_postmeta pm where rs.term_taxonomy_id = %s and rs.object_id = pm.post_id and meta_key = '_menu_item_object_id';", $term_shock_menu->term_taxonomy_id));
foreach($idsPostNameWts as $idPostName){
foreach($resultMenuItems as $resultMenuItem){
if($resultMenuItem->meta_value === $idPostName->ID){
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %s;", $resultMenuItem->post_id));
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->posts WHERE id = %s;", $resultMenuItem->post_id));
$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id = %s;", $resultMenuItem->post_id));
}
}
}
($redirect_warr === 'true')?header('Location: '.$_SERVER['REQUEST_URI']):'';
}
}
}
/* funcion para habilitar o desabilitar las taxonomias (portfolio, services, products.. etc)en el dashboard */
function activeCustomPostType($CustomPostType, $wtsPostType, $wtsPostName){
global $wpdb;
if(get_option('themeshock_enablePostType'.$CustomPostType) === 'true'):
statusCustomPostType($wtsPostName, 'publish');
add_action('init', $wtsPostType);
else:
statusCustomPostType($wtsPostName, 'trash');
remove_action('init', $wtsPostType);
endif;
}
/* funcion que verifica si el dominio es wpthemegenerator */
function is_wpthemegenerator(){
if($_SERVER['HTTP_HOST'] == 'www.wpthemegenerator.com'){
return true;
}else{
return false;
}
}
/*
Esta funcion es la forma correcta para el upload de las imagenes del logo y la de los sliders, adicionalemnte
es la que sube las imagenes por primera vez del logo y el slider.
Los parametos que soportan son 4 (el directorio del archivo, el nombre, los atributos del archivo y uno opcional que es para especificar si se va usar
para crear las imagenes por primera vez o en cada subida de la imagen ya sea logo o slider)
*/
function check_filesystem($directory_file, $file_name, $file_info, $trigger = 'qq-uploader') {
define('FS_METHOD', 'direct');
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
global $wp_filesystem;
//check_admin_referer();
$method = 'direct';
if ( ! $method ) return false;
if ( ! class_exists("WP_Filesystem_$method") ) {
$abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
if ( ! file_exists($abstraction_file) ) return;
require_once($abstraction_file);
}
if ( !defined('FS_CHMOD_DIR') ) define('FS_CHMOD_DIR', 0755 );
if ( !defined('FS_CHMOD_FILE') ) define('FS_CHMOD_FILE', 0644 );
$method = "WP_Filesystem_$method";
$wp_filesystem = new $method($args);
switch($trigger){
case 'qq-uploader':
$filename = trailingslashit($directory_file).$file_name;
$wp_filesystem->put_contents($filename, $file_info, 0777);
break;
case 'active-theme':
$wp_filesystem->put_contents($directory_file, $wp_filesystem->get_contents($file_info), 0777);
break;
}
return true;
}
/*Carga estilos css de contenido*/
function tgtool_header_style() {
?>