get_notifications_data(
array(
'shortcode' => [$settings['nx_id']],
'inline_shortcode' => true,
)
);
}
return $return;
}
/**
* this method is responsible for output the shortcode.
*
* @param array $atts
*/
public function shortcode_inline( $atts, $content = null ) {
$atts = shortcode_atts( array(
'id' => '',
'product_id' => '',
'post_type' => '',
'show_link' => true,
), $atts, 'notificationx_inline'
);
$nx_id = $atts['id'];
if ( empty( $nx_id ) ) {
if ( ! current_user_can( 'administrator' ) ) {
return;
}
return '
' . __( 'Choose a Notification from the dropdown.', 'notificationx' ) . '
';
}
if ( ! PostType::get_instance()->is_enabled( $nx_id ) ) {
if ( ! current_user_can( 'administrator' ) ) {
return;
}
return '' . __( 'Make sure you have enabled the notification which ID you have given.', 'notificationx' ) . '
';
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
do_action( 'nx_inline' );
$settings = PostType::get_instance()->get_post($nx_id);
if( $settings['type'] == 'inline' || $settings['source'] == 'woocommerce_sales_inline' ){
$settings['shortcodeinline'] = true;
/**
* @var WooInline|EDDInline
*/
$extension = \NotificationX\Extensions\ExtensionFactory::get_instance()->get($settings['source']);
$output = $extension->show_inline_notification( $atts, $settings);
if( !empty( $output ) ) {
$output = "$output
";
}
return $output;
}
$result = FrontEnd::get_instance()->get_notifications_data( [ 'shortcode' => [ $nx_id ] ] );
$output = '';
if ( ! empty( $result['shortcode'][ $nx_id ]['entries'] ) ) {
$entries = $result['shortcode'][ $nx_id ]['entries'];
$entries = array_values( $entries );
$settings = $result['shortcode'][ $nx_id ]['post'];
$logged_in = is_user_logged_in();
$show_on_display = isset($settings['show_on_display']) ? $settings['show_on_display'] : '';
if ( ! ( ( $logged_in && 'logged_out_user' === $show_on_display ) || ( ! $logged_in && 'logged_in_user' === $show_on_display ) ) ) {
$col = array_column( $entries, 'timestamp' );
if ( count( $col ) == count( $entries ) ) {
array_multisort( $col, SORT_ASC, $entries );
}
$entry = end( $entries );
$template = Inline::get_instance()->get_template( $settings );
$_template = $template;
foreach ( $entry as $key => $val ) {
if ( ! is_array( $val ) ) {
if ( 'rating' === $key ) {
$count = $val;
$val = "";
for ( $i = 1; $i <= 5; $i++ ) {
$val .= $i <= $count
? '★'
: '★';
}
$val .= '';
} elseif (
! empty( $entry['link'] ) &&
in_array( $key, [ 'plugin_name', 'product_title', 'post_title', 'plugin_theme_name', 'course_title', 'title' ], true ) &&
'form' !== $settings['type'] &&
'email_subscription' !== $settings['type'] &&
'page_analytics' !== $settings['type']
) {
$link = $entry['link'];
$target = ! empty( $settings['link_open'] ) ? 'target="_blank"' : '';
if ( 'false' === $atts['show_link'] ) {
$target = '';
$link = 'javascript:void(0)';
}
$val = "$val";
}
$_template = str_replace( "{{{$key}}}", $val, $_template );
}
if ( ! empty( $entry['timestamp'] ) && strpos( $_template, '{{time}}' ) !== false ) {
$timestamp = $entry['timestamp'];
if ( $timestamp ) {
$diff_for_humans = sprintf(
/* translators: time */
_x( '%s ago', 'Inline Shortcode', 'notificationx' ),
human_time_diff( $timestamp )
);
$_template = str_replace( '{{time}}', $diff_for_humans, $_template );
}
}
}
$output .= $_template;
// $this->shortcode_nx_ids[] = $atts['id'];
$output = "$output
";
}
}
return $output;
}
}