array( 'name' => esc_html__( 'Meta', 'mega' ), 'description' => esc_html__( 'Meta block', 'mega' )),
'before' => '
',
'after' => '
',
'class_base'=> 'ys-meta'
);
parent::__construct( __CLASS__, $args );
}
public function settings( $form )
{
$form->add_control( 'Mega_Control_Textarea', array(
'label' => esc_html__( 'Meta', 'mega' ),
'desc' => esc_html__( 'Use [author], [date], [time], [category] and [tag] snippets to format the meta.', 'mega' ),
'pro' => 1,
'value' => esc_html__( '[author][category]', 'mega' ),//Posted
'name' => 'meta' )
);
$form->add_control( 'Mega_Control_Text', array(
'label' => esc_html__( 'Date Format', 'mega' ),
'desc' => wp_kses( __( 'Customize how your date looks like, more info on Customizing the Time and Date.', 'mega' ), array( 'a' => array( 'href' => true, 'target' => true ))),
'pro' => 1,
'value' => 'j/n/Y',
'name' => 'date_format' )
);
$form->add_control( 'Mega_Control_Text', array(
'label' => esc_html__( 'Tag Separator', 'mega' ),
'value' => '',// ', '
'name' => 'tag_sep'
));
$form->add_control( 'Mega_Control_Text', array(
'label' => esc_html__( 'Category Separator', 'mega' ),
'value' => '',//', '
'name' => 'cat_sep' )
);
$form->add_control( 'Mega_Control_Select', array(
'label' => esc_html__( 'Context', 'mega' ),
'value' => 'block',
'name' => 'context',
'choices' => array(
'sentence' => esc_html__( 'Sentence', 'mega' ),
'block' => esc_html__( 'Block', 'mega' )
)
));
$form->add_sub_control( 'Mega_Control_Select', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Elements', 'mega' ),
'value' => 'icons',
'name' => 'elements',
'choices' => array(
'both' => esc_html__( 'Both', 'mega' ),
'icons' => esc_html__( 'Icons', 'mega' ),
'labels' => esc_html__( 'Labels', 'mega' ),
'none' => esc_html__( 'None', 'mega' ),
)
));
$form->add_sub_control( 'Mega_Control_Text', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Author Label', 'mega' ),
'desc' => wp_kses( __( 'Example values:
by
Author:', 'mega' ), array( 'br' => true, 'strong' => true )),
'value' => esc_html__( 'by', 'mega' ),
'name' => 'author' )
);
$form->add_sub_control( 'Mega_Control_Text', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Date Label', 'mega' ),
'desc' => wp_kses( __( 'Example values:
on
Date:', 'mega' ), array( 'br' => true, 'strong' => true )),
'value' => esc_html__( 'on', 'mega' ),//Date?
'name' => 'date' )
);
$form->add_sub_control( 'Mega_Control_Text', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Time Label', 'mega' ),
'desc' => wp_kses( __( 'Example values:
at
Time:', 'mega' ), array( 'br' => true, 'strong' => true )),
'value' => esc_html__( 'at', 'mega' ),//Time?
'name' => 'time' )
);
$form->add_sub_control( 'Mega_Control_Text', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Category Label', 'mega' ),
'desc' => wp_kses( __( 'Example values:
in
Category:', 'mega' ), array( 'br' => true, 'strong' => true )),
'pro' => 1,
'value' => esc_html__( 'Cats:', 'mega' ),//in
'name' => 'category' )
);
$form->add_sub_control( 'Mega_Control_Text', array(
'control' => 'context',
'control_value' => 'block',
'label' => esc_html__( 'Tag Label', 'mega' ),
'desc' => wp_kses( __( 'Example values:
and tagged with
Tags:', 'mega' ), array( 'br' => true, 'strong' => true )),
'value' => esc_html__( 'Tags:', 'mega' ),//and tagged with
'name' => 'tag' )
);
//$form->add_control( 'Mega_Control_onOff', array(
//'label' => esc_html__( 'Show Icons', 'mega' ),
//'value' => 1,
//'name' => 'show_icons'
//));
}
public function callback()
{
if ( empty( $this->mega['settings']['meta'] ))
return;
parent::callback();
}
public function before()
{
extract( $this->mega['settings'] );
$this->mega['args']['class'] = array();
if ( $context === 'block' )
{
if ( $elements === 'icons' )
$this->mega['args']['class'][] = 'icons';
else if ( $elements === 'labels' )
$this->mega['args']['class'][] = 'labels';
else if ( $elements === 'both' )
$this->mega['args']['class'][] = 'icons labels';
}
else
{
$this->mega['args']['class'][] = 'sentence';
$this->mega['args']['class'][] = 'labels';
}
return parent::before();
}
public function block()
{
extract( $this->mega['settings'] );
if ( $context === 'sentence' )
$settings = wp_parse_args( array(
'author' => esc_html__( 'by', 'mega' ),
'date' => esc_html__( 'on', 'mega' ),
'time' => esc_html__( 'at', 'mega' ),
'category' => esc_html__( 'in', 'mega' ),
'tag' => esc_html__( 'and tagged with', 'mega' )
), $this->mega['settings'] );
else
$settings = $this->mega['settings'];
if ( $context === 'sentence' )
$meta = esc_html__( 'Published', 'mega' ) . ' ' . $meta;
foreach ( array( 'author', 'date', 'time', 'category', 'tag' ) as $name )
{
$meta = preg_replace( sprintf( '/\[%s\]/', $name ), $this->getMeta( $name, $settings ), $meta );
}
echo $meta;
}
public function getMeta( $item, $settings )
{
$class[] = $item;
return mega_html(
$this->getWrap( $item, $settings ),
'',
'' . ( $settings['context'] === 'sentence' ? ' ' : '' ),
false
);
}
public static function getWrap( $item, $settings )
{
extract( $settings );
$$item = ( !empty( $$item ) ? ' ' : '' ) . '%s ';
$map = array(
'author' => 'author_link'
);
$meta = ys_meta( isset( $map[$item] ) ? $map[$item] : $item, $settings );
if ( !$meta )
return false;
return sprintf( $$item, $meta );
//getMeta
}
}
function ys_meta( $type, $settings )
{
extract( $settings );
switch( $type )
{
case 'author' :
return sprintf( esc_html__( 'By %s', 'mega' ), get_the_author() );
case 'author_link' :
return '' . get_the_author() . '';
case 'category' :
return !is_page() && has_category() ? get_the_category_list( $cat_sep ) : false;
case 'tag' :
return has_tag() ? get_the_tag_list( '', $tag_sep ) : false;
case 'date' :
return get_the_date( $date_format );
case 'time' :
return get_the_time();
case 'comments' :
return !post_password_required() ? sprintf( esc_html__( '%s Comments', 'mega' ), get_comments_number() ) : false;
case 'comment_author' :
return sprintf( esc_html__( 'By %s', 'mega' ), get_comment_author() );//$comm->comment_author
case 'days_ago' :
return sprintf( esc_html__( '%s ago', 'mega' ), human_time_diff( get_comment_date( 'U', get_comment_ID() ), current_time( 'timestamp' )));//$comm->comment_ID
}
}