Ejemplo n.º 1
0
/**
 * Gets info about the current site.
 *
 * @since  1.0.0
 * @access private
 *
 * @param array $atts The attributes sent to the shortcode.
 *
 * @return string The desired blog info.
 */
function _render_sc_site_info($atts = array())
{
    $atts = shortcode_atts(array('info' => 'name'), $atts);
    // Escape atts
    render_esc_atts($atts);
    $output = get_bloginfo($atts['info']);
    // Default bloginfo is the name, so if it returns name, but we didn't ask for name, it was an invalid option
    if ($output == get_bloginfo('name') && $atts['info'] !== 'name') {
        $output = render_sc_error('Not a valid option.');
    }
    return $output;
}
Ejemplo n.º 2
0
/**
 * Runs a WP_Query to provide a drop-down of posts.
 *
 * @since  0.3.0
 * @access private
 *
 * @param array $atts The attributes sent to the shortcode.
 *
 * @return string The drop-down HTML.
 */
function _render_query($atts = array())
{
    $atts = shortcode_atts(array('post_type' => 'any', 'author' => '', 'cat' => '', 'tag' => '', 's' => '', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_status' => '', 'order' => '', 'orderby' => '', 'suppress_filters' => '1'), $atts);
    // Escape atts
    render_esc_atts($atts);
    // Convert to boolean
    $atts['suppress_filters'] = $atts['suppress_filters'] == '1';
    $output = '';
    $posts = get_posts($atts);
    if (!empty($posts)) {
        $output .= '<ul>';
        foreach ($posts as $post) {
            $output .= '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
        }
        $output .= '</ul>';
    } else {
        $output = 'No posts found';
    }
    return $output;
}
Ejemplo n.º 3
0
/**
 * Gets the specified date format.
 *
 * @since  1.0.0
 * @access private
 *
 * @param array $atts The attributes sent to the shortcode.
 *
 * @return string The specified date format.
 */
function _render_sc_custom_date($atts)
{
    $atts = shortcode_atts(array('format' => 'default_date', 'timezone' => get_option('timezone_string', 'UTC')), $atts);
    // Escape atts
    render_esc_atts($atts);
    $orig_timezone = date_default_timezone_get();
    date_default_timezone_set($atts['timezone']);
    // Output in the specified format
    switch ($atts['format']) {
        case 'default_date':
            $output = date(get_option('date_format', 'F j, Y'));
            break;
        case 'default_time':
            $output = date(get_option('time_format', 'g:i a'));
            break;
        default:
            $output = date($atts['format']);
    }
    date_default_timezone_set($orig_timezone);
    return $output;
}
Ejemplo n.º 4
0
/**
 * Wraps content in a tabbed layout.
 *
 * @since  1.1-beta-2
 * @access private
 *
 * @param array  $atts    The attributes sent to the shortcode.
 * @param string $content The content inside the shortcode.
 * @return string The tabs wrapper HTML.
 */
function _render_sc_tabs_wrapper($atts = array(), $content = '')
{
    $atts = shortcode_atts(array('nested_children' => false, 'navigation_tab_color' => RENDER_PRIMARY_COLOR, 'navigation_tab_hover_color' => RENDER_PRIMARY_COLOR_LIGHT, 'navigation_tab_font_color' => RENDER_PRIMARY_FONT_COLOR, 'border_color' => RENDER_PRIMARY_COLOR_DARK, 'content_border' => 'show'), $atts);
    // Escape atts
    render_esc_atts($atts);
    // This shouldn't be possible, but just in case it somehow happens
    if ($atts['nested_children'] === false) {
        return 'Error in shortcode';
    }
    $tabs = render_associative_atts($atts, 'nested_children');
    // Open wrapper
    $output = '<div class="render-tabs-wrapper">';
    // Navigation tabs
    $output .= '<ul class="render-tabs-navigation">';
    $i = 0;
    foreach ($tabs as $tab) {
        $i++;
        // Classes
        $classes = array();
        $classes[] = 'render-tabs-navigation-tab';
        $classes[] = $i === 1 ? 'render-tabs-navigation-tab-active' : '';
        // Styles
        $styles = array("background: {$atts['navigation_tab_color']};", "color: {$atts['navigation_tab_font_color']};", "border-color: {$atts['border_color']};");
        $output .= "<li class='" . implode(' ', array_filter($classes)) . "'";
        $output .= " style='" . implode(' ', $styles) . "'>";
        $output .= "<span class='render-tabs-navigation-tab-hover' style='background: {$atts['navigation_tab_hover_color']};'></span>";
        $output .= "<span class='render-tabs-navigation-tab-content'>{$tab['navigation_label']}</span>";
        $output .= '</li>';
    }
    $output .= '</ul>';
    // Content
    $styles = array('border-width: ' . ($atts['content_border'] !== 'hide' ? '1px' : '0') . ';', "border-color: {$atts['border_color']};");
    $output .= '<div class="render-tabs-section-wrapper" style="' . implode(' ', $styles) . '"">';
    $output .= do_shortcode($content);
    $output .= '</div>';
    // .render-tabs-section-wrapper
    // Close wrapper
    $output .= '</div>';
    // .render-tabs-wrapper
    return $output;
}
Ejemplo n.º 5
0
/**
 * Returns the content if the specified users are or are not logged in.
 *
 * @since  1.0.0
 * @access private
 * @param array  $atts    The attributes sent to the shortcode.
 * @param string $content The content inside the shortcode.
 * @return string The content, if it's returned
 */
function _render_sc_hide_for_users($atts = array(), $content = '')
{
    $atts = shortcode_atts(array('users' => false, 'visibility' => 'hide'), $atts);
    $atts = render_esc_atts($atts);
    $output = '';
    if (empty($atts['users'])) {
        return 'ERROR: No users entered!';
    }
    $users = explode(',', $atts['users']);
    if ($atts['visibility'] === 'show') {
        if (in_array(get_current_user_id(), $users)) {
            $output = $content;
        }
    } else {
        if (!in_array(get_current_user_id(), $users)) {
            $output = $content;
        }
    }
    return $output;
}
Ejemplo n.º 6
0
/**
 * Gets the post word count.
 *
 * @since  0.3.0
 * @access private
 *
 * @param array $atts The attributes sent to the shortcode.
 *
 * @return string The post word count.
 */
function _render_sc_post_word_count($atts = array())
{
    $atts = shortcode_atts(array('post' => get_the_ID()), $atts);
    // Escape atts
    render_esc_atts($atts);
    // Get the post object
    if (($post = get_post($atts['post'])) === null) {
        return render_sc_error('Cannot get post object.');
    }
    // Get the filtered content
    $content = $post->post_content;
    // Strip this shortcode out to count the rest
    $content = preg_replace("/\\[render_post_word_count]/s", '', $content);
    $content = do_shortcode($content);
    // Strip tags
    $content = strip_tags($content);
    // Convert nbsp to real space
    $content = preg_replace('/&nbsp;/', ' ', $content);
    // And then count it!
    return str_word_count($content);
}
Ejemplo n.º 7
0
/**
 * Outputs a login form for logged out users
 *
 * @since 1.0.0
 *
 * @param array $atts The attributes sent to the shortcode.
 *
 * @return string The HTML login form
 */
function _render_sc_login_form($atts = array())
{
    $atts = shortcode_atts(array('message' => __('You are already logged in.', 'Render'), 'echo' => false, 'redirect' => '', 'form_id' => '', 'label_username' => '', 'label_password' => '', 'label_remember' => '', 'label_log_in' => '', 'id_username' => '', 'id_password' => '', 'id_remember' => '', 'id_submit' => '', 'remember' => false, 'value_username' => '', 'value_remember' => ''), $atts);
    $atts = render_esc_atts($atts);
    // Don't allow empty atts to be passed through
    foreach ($atts as $i => $att) {
        if ($att === '') {
            unset($atts[$i]);
        }
    }
    // Strip out message
    $message = $atts['message'];
    unset($atts['message']);
    if (is_user_logged_in()) {
        return "<p class='render-logged-in-message'>{$message}</p>";
    } else {
        return wp_login_form($atts);
    }
}