config['self_closing'] = 'yes';
$this->config['forced_load_objects'] = array( 'layerslider' ); // we must load layerslider because content might contain one
$this->config['name'] = __('Page Content', 'avia_framework' );
$this->config['tab'] = __('Content Elements', 'avia_framework' );
$this->config['icon'] = AviaBuilder::$path['imagesURL']."sc-postcontent.png";
$this->config['order'] = 30;
$this->config['target'] = 'avia-target-insert';
$this->config['shortcode'] = 'av_postcontent';
// $this->config['modal_data'] = array('modal_class' => 'flexscreen');
$this->config['tooltip'] = __('Display the content of another page (fullwidth)', 'avia_framework' );
$this->config['drag-level'] = 1;
$this->config['drop-level'] = 1;
$this->config['preview'] = false;
}
/**
* Popup Elements
*
* If this function is defined in a child class the element automatically gets an edit button, that, when pressed
* opens a modal window that allows to edit the element properties
*
* @since 4.2.7
* @return void
*/
public function popup_elements()
{
// $itemcount = array('All'=>'-1');
// for($i = 1; $i<101; $i++) $itemcount[$i] = $i;
$this->elements = array(
array(
"name" => __("Which Entry?", 'avia_framework' ),
"desc" => __("Select the Entry that should be displayed", 'avia_framework' ),
"id" => "link",
"fetchTMPL" => true,
"type" => "linkpicker",
"subtype" => array( __('Single Entry', 'avia_framework' ) =>'single'),
"posttype" => array('page','portfolio'),
"std" => "page",
'hierarchical' => 'yes', // 'yes' ( =default) | 'no'
'post_status' => 'publish,private, draft' // array | string (default = publish)
)
);
}
/**
* @since 4.2.7
*/
public function extra_assets()
{
add_filter('avia_builder_precompile', array( $this, 'handler_avia_builder_precompile' ), 1 );
}
/**
* Scan content for av_postcontent and replace it with the content of the page.
* As this inserted page might also contain this shortcode and so on we have to do thar in a loop
*
* @since 4.2.7
* @param string $content
* @return string
*/
public function handler_avia_builder_precompile( $content )
{
global $shortcode_tags;
//in case we got none/more than one postcontent elements make sure that replacement doesnt get executed/onle gets executed once
/**
* In case we have no av_postcontent we can return
*/
if( strpos( $content, '[' . $this->config['shortcode'] ) === false )
{
return $content;
}
/**
* save the "real" shortcode array and limit execution to the shortcode of this class only
*/
$old_sc = $shortcode_tags;
$shortcode_tags = array( $this->config['shortcode'] => array( $this, 'shortcode_handler' ) );
while( false !== strpos( $content, $this->config['shortcode'] ) )
{
$content = do_shortcode( $content );
}
/**
* Restore the original shortcode pattern
*/
$shortcode_tags = $old_sc;
/**
* Update the shortcode tree to reflect the current page structure.
* Prior make sure that shortcodes are balanced.
*/
Avia_Builder()->get_shortcode_parser()->set_builder_save_location( 'none' );
$content = ShortcodeHelper::clean_up_shortcode( $content, 'balance_only' );
ShortcodeHelper::$tree = ShortcodeHelper::build_shortcode_tree( $content );
//$content = preg_replace("!\[av_postcontent.*?\]!","",$content);
//now we need to re calculate the shortcode tree so that all elements that are pulled from different posts also get the correct location
// $pattern = str_replace('av_postcontent','av_psprocessed', ShortcodeHelper::get_fake_pattern());
//
// preg_match_all("/".$pattern."/s", $content, $matches);
// ShortcodeHelper::$tree = ShortcodeHelper::build_shortcode_tree($matches);
return $content;
}
/**
* Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
* Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
* Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
*
*
* @since 4.2.7
* @param array $params this array holds the default values for $content and $args.
* @return $params the return array usually holds an innerHtml key that holds item specific markup.
*/
public function editor_element($params)
{
$link = isset( $params['args']['link'] ) ? $params['args']['link'] : '';
$entry = AviaHelper::get_entry( $link );
$title = '';
if( $entry instanceof WP_Post )
{
$title = esc_html( $entry->post_title ) . " ({$entry->post_type}, {$entry->ID} )";
}
$update_template = '{{link}}';
$update = $this->update_template( 'link', $update_template );
$template = str_replace('{{link}}', $title, $update_template );
$params['innerHtml'] = "";
$params['innerHtml'].= "