Created
March 1, 2017 15:01
-
-
Save davidwerks/17d88376b0b717d2570443567600ed87 to your computer and use it in GitHub Desktop.
vc_row custom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ThemeMountain; | |
/** Find basename */ | |
if(isset($this)) { | |
$_base = $this->settings['base']; | |
} else if (isset($tagname)) { | |
$_base = $tagname; | |
} else { | |
$_base = FALSE; | |
} | |
/** Set $_is_inner and CSS ID Prefix */ | |
if($_base === 'vc_row_inner') { | |
$_css_id_prefix = 'row_inner'; | |
$_is_inner = TRUE; | |
} else { | |
$_is_inner = FALSE; | |
$_css_id_prefix = 'row'; | |
} | |
/** default values */ | |
extract(shortcode_atts(array( | |
/** General Options */ | |
'force_fullwidth' => '', /** Note: if true, adds the classes .full-width.collapse to div.section-block.replicable-content.row */ | |
'equalize' => '', | |
'columns_on_tablet' => 'keep', | |
'el_id' => '', | |
'el_class' => '', | |
/** | |
* Spacing | |
*/ | |
'clear_all_padding' => '', /* Note: clears all section block padding by adding no-padding to div.section-block */ | |
'padding_top' => 'inherit', | |
'padding_bottom' => 'inherit', | |
/** | |
* Design Options | |
*/ | |
'use_background' => '', | |
'background_color' => 'transparent', | |
'image_id' => '', | |
/** | |
* Reserved | |
*/ | |
'set_font_color' => '', | |
'font_color' => '', | |
), $atts)); | |
/** | |
* Variables | |
*/ | |
/** blanks */ | |
$_replicable_content_class = $_full_width_class = ''; | |
/** CSS ID (Auto-serialized) */ | |
$_css_id = $_css_id_prefix.'-'.TM_shortcodes::tm_serial_number(); | |
/** Extra Classes */ | |
if( !empty($el_class) ) { | |
$el_class = " $el_class"; | |
} | |
/** Element ID (User defined) */ | |
if(!empty($el_id)) { | |
$el_id = TM_shortcodes::wrap_with_id_attr($el_id); | |
} | |
/** | |
* Detections | |
*/ | |
/** flex width elements, $_has_flex_width_elements */ | |
if( | |
strpos($content, 'slider_type="fullscreen"') > 0 || | |
strpos($content, 'slider_type="full_width"') > 0 || | |
strpos($content, '[tm_hero_') > 0 || | |
strpos($content, '[tm_testimonials') > 0 || | |
strpos($content, '[tm_parallax') > 0 || | |
strpos($content, '[tm_team') > 0 || | |
strpos($content, '[tm_stats') > 0 || | |
strpos($content, '[tm_map') > 0 || | |
strpos($content, '[tm_logos') > 0 || | |
strpos($content, '[tm_grid') > 0 || | |
strpos($content, '[tm_fullscreen_presentation') > 0 || | |
strpos($content, '[tm_clients') > 0 | |
) { | |
$_has_flex_width_elements = TRUE; | |
} else { | |
$_has_flex_width_elements = FALSE; | |
} | |
/** $_has_non_replicable_content */ | |
if( | |
strpos($content, '[tm_hero_') > 0 || | |
strpos($content, '[tm_testimonials') > 0 || | |
strpos($content, '[tm_grid') > 0 | |
) { | |
$_has_non_replicable_content = TRUE; | |
} else { | |
$_has_non_replicable_content = FALSE; | |
} | |
/** | |
* HTML Construction | |
*/ | |
/** | |
* Section Block | |
* | |
* All rows will be treated as section blocks. The user will no longer have to choose whether it's a row or section block. Every row inserted gets the classes .section-block.replicable-content with some exceptions mentioned in the specs page. | |
* Some exceptions that SHOULD NOT get the .replicable-content class includes: | |
* hero-1, hero-2, hero-3, hero-4, hero-5, tm_testimonials, tm_grid | |
*/ | |
if($_has_non_replicable_content === FALSE) { | |
$_replicable_content_class = ' replicable-content'; | |
} | |
/** | |
* Nested Section Block | |
* | |
* Since all are section blocks anyways there is no need to have the user trigger anything or a particular layout for nesting. They'll need to manually handle padding. | |
*/ | |
/** | |
* Section Block Full Width (setting: force_fullwidth) | |
* | |
* Added the option called Full Width up top under General. When checked it should add the classes .full-width.collapse to div.section-block.replicable-content.row. This will force row to be ignored. If anything, we could default this to true for the items that have previously used ignore_row. | |
* | |
* The following elements has an option not to use full width in their own VC settings (use_fullscreen_row). | |
* tm_hero_1, tm_hero_2, tm_hero_3, tm_hero_4, tm_hero_5, tm_testimonials , full width slider, fullscreen slider, tm_parallax | |
* tm_team, tm_stats, tm_map, tm_logos, tm_grid, tm_fullscreen_presentation, tm_clients | |
*/ | |
if( $_has_flex_width_elements === FALSE && strpos($content, 'use_fullscreen_row="true"') > 0 ) { | |
$_full_width_class = ' full-width collapse'; | |
} | |
/* Output row */ | |
$output = "<div{$el_id} class='{$_css_id} row section-block{$_replicable_content_class}{$_full_width_class}{$el_class}'>\n".TM_shortcodes::tm_do_shortcode($content)."\n</div><!--end themeMountain row-->\n"; | |
/* reset moored settings */ | |
if($_base === 'vc_row') { | |
TM_shortcodes::reset_vc_row_settings_to_inherit(); | |
} | |
echo $output; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use ThemeMountain\TM_shortcodes as TM_shortcodes; | |
// attributes | |
$is_section_block = $el_id = $set_font_color = $font_color = $el_class = $padding_top = $padding_bottom = $height = $use_background = $background_color = $background_image = $use_animation = $animation_preset = $animation_duration = $animation_delay = $_columns_on_tablet_class = ''; | |
$output = $el_class = $_padding_class = $_replicable_content = $_base = ''; | |
$_shortcode_count = 0; | |
$_ignore_row = false; | |
// find basename | |
if(isset($this)) { | |
$_base = $this->settings['base']; | |
} else if (isset($tagname)) { | |
$_base = $tagname; | |
} else { | |
$_base = FALSE; | |
} | |
extract(shortcode_atts(array( | |
'is_section_block' => '', // blank, yes (section block), nest (all the nested will have section block) | |
'el_id' => '', | |
'set_font_color' => '', | |
'font_color' => '', | |
'el_class' => '', | |
'padding_top' => 'inherit', | |
'padding_bottom' => 'inherit', | |
'height' => '', | |
'use_background' => '', | |
'background_color' => 'transparent', | |
'image_id' => '', | |
'equalize' => '', | |
'columns_on_tablet' => 'keep', | |
), $atts)); | |
// css ID | |
$_css_id = 'row-'.ThemeMountain\TM_shortcodes::tm_serial_number(); | |
// $column_pull | |
if( !empty($el_class) ) { | |
$el_class = " $el_class"; | |
} | |
// padding class | |
// padding top | |
if($padding_top !== '' && $padding_top !== 'inherit') { | |
$_padding_class .= " pt-".$padding_top; | |
} | |
// padding botton | |
if($padding_bottom !=='' && $padding_bottom !== 'inherit') { | |
$_padding_class .= " pb-".$padding_bottom; | |
} | |
// $_replicable_content | |
if(!empty($_replicable_content)) { | |
$_replicable_content = ' replicable-content'; | |
} | |
// equalize | |
if($equalize !== '') { | |
$equalize = ' flex'; | |
} | |
// columns_on_tablet | |
switch ($columns_on_tablet) { | |
case 'force_2': | |
$_columns_on_tablet_class =' two-columns-on-tablet'; | |
break; | |
case 'force_1': | |
$_columns_on_tablet_class =' one-column-on-tablet'; | |
break; | |
case 'keep': | |
default: | |
// do nothing | |
break; | |
} | |
/** | |
* ignore_row check up | |
* | |
* the regexpt check up if $content contains any vc_column shortcode. if there is 1 or more and vc_column, | |
* row section in the child elements will be ignored. relevant files: | |
* tm_clients.php | |
* tm_grid.php | |
* tm_logos.php | |
* tm_stats.php | |
* tm_team.php | |
* | |
* section-block for these will be retained as exception. | |
* tm_hero_1.php ~ hero_5 | |
* tm_fullscreen_presentation.php | |
* tm_parallax.php | |
*/ | |
$_shortcode_count = preg_match_all("/\[vc_column(.*?)(.+?)?\](.*?)\[\/vc_column\]/s",$content); | |
if ( strpos($content, 'ignore_row="true"') > 0 ) { | |
if( $_shortcode_count < 2) { | |
$_ignore_row = true; | |
} else { | |
$content = str_replace('ignore_row="true"','',$content); | |
} | |
} | |
/** | |
* section or row | |
*/ | |
// full screen detect | |
if($is_section_block === 'nest_all' ) { | |
$content = str_replace('ignore_row="true"','',$content); | |
TM_shortcodes::in_case_of_use_background ($use_background, $_css_id.'.section-block', $image_id, $background_color); | |
TM_shortcodes::in_case_of_set_font_color ($set_font_color, $_css_id.'.section-block', $font_color); | |
$_section_block_class = 'section-block'; | |
if( | |
strpos($_padding_class,'pb-') === FALSE && | |
strpos($_padding_class,'pt-') !== FALSE | |
) { | |
$_section_block_class .= ' replicable-content'; | |
} else if ( | |
strpos($_padding_class,'pb-') === FALSE && | |
strpos($_padding_class,'pt-') === FALSE | |
) { | |
$_section_block_class .= ' replicable-content'; | |
} | |
if($base === 'vc_row') $_padding_class = ' pt-0 pb-0'; | |
if(!empty($el_id)) { | |
$el_id = TM_shortcodes::wrap_with_id_attr($el_id); | |
} | |
// section block | |
$output = "<div{$el_id} class='{$_css_id} {$_section_block_class}{$_replicable_content}{$_padding_class}{$el_class}'><div class='row{$_columns_on_tablet_class}{$equalize}'>".TM_shortcodes::tm_do_shortcode($content, FALSE)."</div><!-- end themeMountain row -->\n</div><!--end themeMountain section block-->\n"; | |
} else if( | |
strpos($content, 'slider_type="fullscreen"') > 0 || | |
strpos($content, 'slider_type="full_width"') > 0 || | |
$_ignore_row === TRUE | |
) { | |
if($_base === 'vc_row') { | |
// send out the current settings to "set" | |
$_args = array( | |
'set_font_color' => $set_font_color, | |
'font_color' => $font_color, | |
'padding_top' => $padding_top, | |
'padding_bottom' => $padding_bottom, | |
'columns_on_tablet_class' => $_columns_on_tablet_class, | |
'height' => $height, | |
'use_background' => $use_background, | |
'background_color' => $background_color, | |
'image_id' => $image_id, | |
'equalize' => $equalize, | |
'padding_class' => $_padding_class, | |
'el_id' => $el_id | |
); | |
TM_shortcodes::set_vc_row_settings_to_inherit($_args); | |
} | |
// return as it is (because the child elements will output the section block part) | |
$output = TM_shortcodes::tm_do_shortcode($content); | |
} else if($is_section_block === 'yes' ) { | |
TM_shortcodes::in_case_of_use_background ($use_background, $_css_id.'.section-block', $image_id, $background_color); | |
TM_shortcodes::in_case_of_set_font_color ($set_font_color, $_css_id.'.section-block', $font_color); | |
$_section_block_class = 'section-block'; | |
if( | |
strpos($_padding_class,'pb-') === FALSE && | |
strpos($_padding_class,'pt-') !== FALSE | |
) { | |
$_section_block_class .= ' replicable-content'; | |
} else if ( | |
strpos($_padding_class,'pb-') === FALSE && | |
strpos($_padding_class,'pt-') === FALSE | |
) { | |
$_section_block_class .= ' replicable-content'; | |
} | |
if(!empty($el_id)) { | |
$el_id = TM_shortcodes::wrap_with_id_attr($el_id); | |
} | |
// section block | |
$output = "<div{$el_id} class='{$_css_id} {$_section_block_class}{$_replicable_content}{$_padding_class}{$el_class}'><div class='row{$_columns_on_tablet_class}{$equalize}'>".TM_shortcodes::tm_do_shortcode($content, FALSE)."</div><!-- end themeMountain row -->\n</div><!--end themeMountain section block-->\n"; | |
} else { | |
TM_shortcodes::in_case_of_use_background ($use_background, $_css_id, $image_id, $background_color); | |
TM_shortcodes::in_case_of_set_font_color ($set_font_color, $_css_id, $font_color); | |
if(!empty($el_id)) { | |
$el_id = TM_shortcodes::wrap_with_id_attr($el_id); | |
} | |
// row | |
$output = "<div{$el_id} class='{$_css_id} row{$_columns_on_tablet_class}{$equalize}{$el_class}'>".TM_shortcodes::tm_do_shortcode($content)."\n</div><!--end themeMountain row-->\n"; | |
} | |
echo $output; | |
// reset moored settings | |
if($_base === 'vc_row') { | |
TM_shortcodes::reset_vc_row_settings_to_inherit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment