Esempio n. 1
0
/**
 * Render the ticker
 *
 * @since 1.5.0
 */
function render_mtphr_dnt_ticker($id = '', $class = '', $atts = false)
{
    // Switch the post based on the selected language
    if (function_exists('icl_object_id')) {
        $id = icl_object_id($id, 'ditty_news_ticker', true);
    }
    // Get the post
    $ticker = get_post($id);
    if ($ticker && $ticker->post_status == 'publish') {
        // Save the original $wp_query
        global $wp_query, $mtphr_dnt_ticker_types, $mtphr_dnt_meta_data;
        $original_query = $wp_query;
        $wp_query = null;
        $wp_query = new WP_Query();
        // Get all the custom data
        $custom_fields = get_post_custom($id);
        $meta_data = array();
        foreach ($custom_fields as $key => $value) {
            $meta_data[$key] = maybe_unserialize($value[0]);
        }
        // Override meta data with supplied attributes
        if (is_array($atts)) {
            foreach ($atts as $key => $value) {
                $meta_data["_mtphr_dnt_{$key}"] = $value;
            }
        }
        // Extract the metadata array into variables
        extract($meta_data);
        // Add to the global ticker types
        $mtphr_dnt_ticker_types[$_mtphr_dnt_type] = $_mtphr_dnt_type;
        // Get the ticks to display
        if ($_mtphr_dnt_type == 'mixed') {
            $dnt_ticks = mtphr_dnt_mixed_ticks($id, $meta_data);
        } else {
            $dnt_ticks = apply_filters('mtphr_dnt_tick_array', array(), $id, $meta_data);
        }
        // Transform the tick array
        $dnt_ticks = apply_filters('mtphr_dnt_tick_array_transform', $dnt_ticks, $id, $meta_data);
        // Add the post amount of ticks to the metadata
        $total_ticks = count($dnt_ticks);
        // Add the post id & total ticks to the metadata
        $meta_data['_mtphr_dnt_id'] = $id;
        $meta_data['_mtphr_dnt_total_ticks'] = $total_ticks;
        // Save the metadata in a global variable
        $mtphr_dnt_meta_data = $meta_data;
        ob_start();
        // Add a unique id
        $tick_id = 'mtphr-dnt-' . $id;
        if (isset($_mtphr_dnt_unique_id) && $_mtphr_dnt_unique_id != '') {
            $tick_id = 'mtphr-dnt-' . $id . '-' . sanitize_html_class($_mtphr_dnt_unique_id);
        }
        // Check for a set width
        $ticker_width = '';
        if (isset($_mtphr_dnt_ticker_width) && $_mtphr_dnt_ticker_width != 0) {
            $ticker_width = ' style="width:' . intval($_mtphr_dnt_ticker_width) . 'px"';
        }
        echo '<div' . $ticker_width . ' id="' . $tick_id . '" ' . mtphr_dnt_ticker_class($id, $class, $meta_data) . '>';
        echo '<div class="mtphr-dnt-wrapper mtphr-dnt-clearfix">';
        // Create and save element styles
        $margin = '';
        $padding = '';
        $width = '';
        $height = '';
        $spacing = '';
        if ($_mtphr_dnt_mode == 'scroll') {
            $padding = intval($_mtphr_dnt_scroll_padding) != 0 ? 'padding-top:' . intval($_mtphr_dnt_scroll_padding) . 'px;padding-bottom:' . intval($_mtphr_dnt_scroll_padding) . 'px;' : '';
            $margin = intval($_mtphr_dnt_scroll_margin) != 0 ? 'margin-top:' . intval($_mtphr_dnt_scroll_margin) . 'px;margin-bottom:' . intval($_mtphr_dnt_scroll_margin) . 'px;' : '';
            $width = intval($_mtphr_dnt_scroll_width) != 0 ? 'white-space:normal;width:' . intval($_mtphr_dnt_scroll_width) . 'px;' : '';
            $height = intval($_mtphr_dnt_scroll_height) != 0 ? 'height:' . intval($_mtphr_dnt_scroll_height) . 'px;' : '';
        } elseif ($_mtphr_dnt_mode == 'rotate') {
            $padding = intval($_mtphr_dnt_rotate_padding) != 0 ? 'padding-top:' . intval($_mtphr_dnt_rotate_padding) . 'px;padding-bottom:' . intval($_mtphr_dnt_rotate_padding) . 'px;' : '';
            $margin = intval($_mtphr_dnt_rotate_margin) != 0 ? 'margin-top:' . intval($_mtphr_dnt_rotate_margin) . 'px;margin-bottom:' . intval($_mtphr_dnt_rotate_margin) . 'px;' : '';
            $height = intval($_mtphr_dnt_rotate_height) != 0 ? 'height:' . intval($_mtphr_dnt_rotate_height) . 'px;' : '';
        } elseif ($_mtphr_dnt_mode == 'list') {
            $padding = intval($_mtphr_dnt_list_padding) != 0 ? 'padding-top:' . intval($_mtphr_dnt_list_padding) . 'px;padding-bottom:' . intval($_mtphr_dnt_list_padding) . 'px;' : '';
            $margin = intval($_mtphr_dnt_list_margin) != 0 ? 'margin-top:' . intval($_mtphr_dnt_list_margin) . 'px;margin-bottom:' . intval($_mtphr_dnt_list_margin) . 'px;' : '';
        }
        // Filter the variables
        $padding = apply_filters('mtphr_dnt_tick_container_padding', $padding);
        $margin = apply_filters('mtphr_dnt_tick_container_margin', $margin);
        $width = apply_filters('mtphr_dnt_tick_width', $width);
        $height = apply_filters('mtphr_dnt_tick_height', $height);
        // Create the container style
        $container_style = $padding != '' || $margin != '' ? ' style="' . $padding . $margin . '"' : '';
        // Open the ticker container
        do_action('mtphr_dnt_before', $id, $meta_data);
        echo '<div class="mtphr-dnt-tick-container"' . $container_style . '>';
        do_action('mtphr_dnt_contents_before', $id, $meta_data);
        echo '<div class="mtphr-dnt-tick-contents">';
        do_action('mtphr_dnt_top', $id, $meta_data);
        // Print out the ticks
        if (is_array($dnt_ticks)) {
            // Grab the paged ticks
            if ($_mtphr_dnt_mode == 'list' && (isset($_mtphr_dnt_list_tick_paging) && $_mtphr_dnt_list_tick_paging)) {
                $page = isset($_GET['tickpage']) ? $_GET['tickpage'] : 1;
                $offset = ($page - 1) * $_mtphr_dnt_list_tick_count;
                $dnt_ticks = array_slice($dnt_ticks, $offset, $_mtphr_dnt_list_tick_count);
            }
            // Randomize the ticks
            if (isset($_mtphr_dnt_shuffle) && $_mtphr_dnt_shuffle) {
                shuffle($dnt_ticks);
            }
            $total = count($dnt_ticks);
            foreach ($dnt_ticks as $i => $tick) {
                $type = $_mtphr_dnt_type == 'mixed' ? $tick['type'] : $_mtphr_dnt_type;
                $tick = $_mtphr_dnt_type == 'mixed' ? $tick['tick'] : $tick;
                // Set the list spacing depending on the tick position
                if ($_mtphr_dnt_mode == 'list') {
                    $spacing = $i != intval($total - 1) ? 'margin-bottom:' . intval($_mtphr_dnt_list_tick_spacing) . 'px;' : '';
                }
                $spacing = apply_filters('mtphr_dnt_list_tick_spacing', $spacing, $i, $total);
                $tick_style = $width != '' || $height != '' || $spacing != '' ? ' style="' . $width . $height . $spacing . '"' : '';
                do_action('mtphr_dnt_tick_before', $id, $meta_data, $total, $i);
                echo '<div' . $tick_style . ' ' . mtphr_dnt_tick_class('mtphr-dnt-' . $type . '-tick mtphr-dnt-clearfix') . '>';
                do_action('mtphr_dnt_tick_top', $id, $meta_data);
                echo $tick;
                do_action('mtphr_dnt_tick_bottom', $id, $meta_data);
                echo '</div>';
                do_action('mtphr_dnt_tick_after', $id, $meta_data, $total, $i);
            }
        }
        // Close the ticker container
        do_action('mtphr_dnt_bottom', $id, $meta_data);
        echo '</div>';
        do_action('mtphr_dnt_contents_after', $id, $meta_data, $total_ticks);
        echo '</div>';
        do_action('mtphr_dnt_after', $id, $meta_data, $total_ticks);
        echo '</div>';
        echo '</div>';
        // Restore the original $wp_query
        $wp_query = null;
        $wp_query = $original_query;
        wp_reset_postdata();
    }
    // Return the output
    return ob_get_clean();
}
Esempio n. 2
0
 function mtphr_dnt_tick_open($tick_obj, $i, $id, $meta_data, $total = false)
 {
     extract($meta_data);
     // Create and save element styles
     $width = '';
     $height = '';
     $spacing = '';
     if ($_mtphr_dnt_mode == 'scroll') {
         $width = intval($_mtphr_dnt_scroll_width) != 0 ? 'white-space:normal;width:' . intval($_mtphr_dnt_scroll_width) . 'px;' : '';
         $height = intval($_mtphr_dnt_scroll_height) != 0 ? 'height:' . intval($_mtphr_dnt_scroll_height) . 'px;' : '';
     } elseif ($_mtphr_dnt_mode == 'rotate') {
         $height = intval($_mtphr_dnt_rotate_height) != 0 ? 'height:' . intval($_mtphr_dnt_rotate_height) . 'px;' : '';
     }
     // Filter the variables
     $width = apply_filters('mtphr_dnt_tick_width', $width);
     $height = apply_filters('mtphr_dnt_tick_height', $height);
     $type = is_array($tick_obj) && isset($tick_obj['type']) ? $tick_obj['type'] : $_mtphr_dnt_type;
     $tick_class = is_array($tick_obj) && isset($tick_obj['tick_class']) ? $tick_obj['tick_class'] : '';
     $data_attributes = '';
     if (is_array($tick_obj) && isset($tick_obj['data']) && is_array($tick_obj['data'])) {
         if (is_array($tick_obj['data']) && count($tick_obj['data']) > 0) {
             foreach ($tick_obj['data'] as $i => $data) {
                 $data_attributes .= ' data-' . $i . '="' . $data . '"';
             }
         }
     }
     // Set the list spacing depending on the tick position
     $spacing = $_mtphr_dnt_mode == 'list' && $i != intval($total - 1) ? 'margin-bottom:' . intval($_mtphr_dnt_list_tick_spacing) . 'px;' : '';
     $spacing = apply_filters('mtphr_dnt_list_tick_spacing', $spacing, $i, $total);
     $tick_style = $width != '' || $height != '' || $spacing != '' ? ' style="' . $width . $height . $spacing . '"' : '';
     do_action('mtphr_dnt_tick_before', $id, $meta_data, $total, $i);
     echo '<div' . $tick_style . ' ' . mtphr_dnt_tick_class('mtphr-dnt-' . $type . '-tick mtphr-dnt-clearfix ' . $tick_class) . $data_attributes . '>';
     do_action('mtphr_dnt_tick_top', $id, $meta_data);
 }