/**
  * Calculate post reading time.
  *
  * Cache the post reading time under post meta for better performance.
  *
  * @uses stag_get_post_meta()
  * @uses stag_update_post_meta()
  * @since 1.0.0.
  * @param int $post_id Post ID of which to calculate the post reading time.
  * @return mixed
  */
 function stag_post_reading_time($post_id = null)
 {
     if (0 === absint($post_id)) {
         $post_id = get_the_ID();
     }
     // Use cached value if available
     $char_count = stag_get_post_meta('cache', $post_id, 'char-count');
     if (false !== $char_count) {
         $char_count = absint($char_count);
     } else {
         $content = wp_strip_all_tags(strip_shortcodes(get_post($post_id)->post_content), true);
         /**
          * Use - count( preg_split( '/\s+/', $content ) )
          * for compatibility with cyrillic or other characters which are not assumed words.
          *
          * @since 1.1.0
          */
         $char_count = apply_filters('post_words_count', str_word_count($content));
         // Cache the value
         stag_update_post_meta('cache', $post_id, 'char-count', $char_count);
     }
     $wpm = apply_filters('ink_words_per_minute', 200);
     // Get Estimated time
     $minutes = floor($char_count / $wpm);
     $seconds = floor($char_count / ($wpm / 60) - $minutes * 60);
     // If less than a minute
     if ($minutes < 1) {
         $estimated_time = __('1 minuto', 'stag');
     }
     // If more than a minute
     if ($minutes > 1) {
         if ($seconds > 30) {
             $minutes++;
         }
         /* translators: %d = minute count */
         $estimated_time = sprintf(__('%d minutos', 'stag'), $minutes);
     }
     return $estimated_time;
 }
/**
 * Create content for the custom meta box
 *
 * @param array $meta_box Meta box input data
 * @return void
 */
function stag_create_meta_box($post, $meta_box)
{
    if (!is_array($meta_box)) {
        return false;
    }
    if (isset($meta_box['description']) && $meta_box['description'] != '') {
        echo '<p>' . $meta_box['description'] . '</p>';
    }
    wp_nonce_field(basename(__FILE__), 'stag_meta_box_nonce');
    echo '<table class="form-table stag-metabox-table">';
    foreach ($meta_box['fields'] as $field) {
        $meta = stag_get_post_meta('settings', $post->ID, $field['id']);
        echo '<tr><th><label for="' . $field['id'] . '"><strong>' . $field['name'] . '</strong>
			 <span>' . $field['desc'] . '</span></label></th>';
        switch ($field['type']) {
            case 'text':
            case 'default':
                echo '<td><input type="text" name="stag_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" /></td>';
                break;
            case 'number':
                $min = isset($field['min']) ? $field['min'] : '1';
                $max = isset($field['max']) ? $field['max'] : '100';
                $step = isset($field['step']) ? $field['step'] : '1';
                echo '<td><input type="number" name="stag_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" min="' . $min . '" max="' . $max . '" step="' . $step . '" /></td>';
                break;
            case 'textarea':
                $rows = isset($field['rows']) ? $field['rows'] : '8';
                echo '<td><textarea name="stag_meta[' . $field['id'] . ']" id="' . $field['id'] . '" rows="' . $rows . '" cols="5">' . ($meta ? $meta : $field['std']) . '</textarea></td>';
                break;
            case 'file':
                $multiple = isset($field['multiple']) ? true : false;
                $library_type = isset($field['library']) ? $field['library'] : false;
                ?>

				<script>
				jQuery(function($){
					var frame,
						isMultiple = "<?php 
                echo $multiple;
                ?>
";

					$('#<?php 
                echo $field['id'];
                ?>
_button').on('click', function(e) {
						e.preventDefault();

						var options = {
							state: 'insert',
							frame: 'post',
							multiple: isMultiple,
							library: {
								type: '<?php 
                echo $library_type;
                ?>
'
							}
						};

						frame = wp.media(options).open();

						frame.menu.get('view').unset('gallery');
						frame.menu.get('view').unset('featured-image');
						frame.menu.get('view').unset('playlist');
						frame.menu.get('view').unset('video-playlist');

						frame.toolbar.get('view').set({
							insert: {
								style: 'primary',
								text: '<?php 
                _e("Insert", "stag");
                ?>
',

								click: function() {
									var models = frame.state().get('selection'),
										url = models.first().attributes.url,
										files = [];

									if( isMultiple ) {
										models.map (function( attachment ) {
											attachment = attachment.toJSON();
											files.push(attachment.url);
											url = files;
										});
									}

									$('#<?php 
                echo $field['id'];
                ?>
').val( url );

									frame.close();
								}
							}
						});
					});
				});
				</script>

				<?php 
                echo '<td><input type="text" name="stag_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" class="file" /> <input type="button" class="button" name="' . $field['id'] . '_button" id="' . $field['id'] . '_button" value="Browse" /></td>';
                break;
            case 'images':
                ?>
			    <script>
			    jQuery(function($){
			        var frame,
			            images = '<?php 
                echo stag_get_post_meta("settings", $post->ID, "stag_image_ids");
                ?>
',
			            selection = loadImages(images);

			        $('#stag_images_upload').on('click', function(e) {
			            e.preventDefault();
			            var options = {
			                title: '<?php 
                _e("Create Featured Gallery", "stag");
                ?>
',
			                state: 'gallery-edit',
			                frame: 'post',
			                selection: selection
			            };

			            if( frame || selection ) {
			                options['title'] = '<?php 
                esc_attr_e("Edit Featured Gallery", "stag");
                ?>
';
			            }

			            frame = wp.media(options).open();

			            // Tweak Views
			            frame.menu.get('view').unset('cancel');
			            frame.menu.get('view').unset('separateCancel');
			            frame.menu.get('view').get('gallery-edit').el.innerHTML = '<?php 
                esc_attr_e("Edit Featured Gallery", "stag");
                ?>
';
			            frame.content.get('view').sidebar.unset('gallery'); // Hide Gallery Settings in sidebar

			            // when editing a gallery
			            overrideGalleryInsert();
			            frame.on( 'toolbar:render:gallery-edit', function() {
			                overrideGalleryInsert();
			            });

			            frame.on( 'content:render:browse', function( browser ) {
			                if ( !browser ) return;
			                // Hide Gallery Settings in sidebar
			                browser.sidebar.on('ready', function(){
			                    browser.sidebar.unset('gallery');
			                });
			                // Hide filter/search as they don't work
			                browser.toolbar.on('ready', function(){
			                    if(browser.toolbar.controller._state == 'gallery-library'){
			                        browser.toolbar.$el.hide();
			                    }
			                });
			            });

			            // All images removed
			            frame.state().get('library').on( 'remove', function() {
			                var models = frame.state().get('library');
			                if(models.length == 0){
			                    selection = false;
			                    $.post(ajaxurl, { ids: '', action: 'stag_save_images', post_id: stag_ajax.post_id, nonce: stag_ajax.nonce });
			                }
			            });

			            function overrideGalleryInsert(){
			                frame.toolbar.get('view').set({
			                    insert: {
			                        style: 'primary',
			                        text: '<?php 
                _e("Save Featured Gallery", "stag");
                ?>
',
			                        click: function(){
			                            var models = frame.state().get('library'),
			                                ids = '';

			                            models.each( function( attachment ) {
			                                ids += attachment.id + ','
			                            });

			                            this.el.innerHTML = '<?php 
                esc_attr_e("Saving...", "stag");
                ?>
';

			                            $.ajax({
			                                type: 'POST',
			                                url: ajaxurl,
			                                data: {
			                                    ids: ids,
			                                    action: 'stag_save_images',
			                                    post_id: stag_ajax.post_id,
			                                    nonce: stag_ajax.nonce
			                                },
			                                success: function(){
			                                    selection = loadImages(ids);
			                                    $('#_stag_image_ids').val( ids );
			                                    frame.close();
			                                },
			                                dataType: 'html'
			                            }).done( function( data ) {
			                                $('.stag-gallery-thumbs').html( data );
			                                console.log(data);
			                            });
			                        }
			                    }
			                });
			            }

			        });

			        function loadImages(images){
			            if (images){
			                var shortcode = new wp.shortcode({
			                    tag:      'gallery',
			                    attrs:    { ids: images },
			                    type:     'single'
			                });

			                var attachments = wp.media.gallery.attachments( shortcode );

			                var selection = new wp.media.model.Selection( attachments.models, {
			                    props:    attachments.props.toJSON(),
			                    multiple: true
			                });

			                selection.gallery = attachments.gallery;

			                selection.more().done( function() {
			                    // Break ties with the query.
			                    selection.props.set({ query: false });
			                    selection.unmirror();
			                    selection.props.unset('orderby');
			                });

			                return selection;
			            }
			            return false;
			        }
			    });
			    </script>

			    <?php 
                $meta = stag_get_post_meta('settings', $post->ID, 'stag_image_ids');
                $thumbs_output = '';
                $button_text = $meta ? __('Edit Gallery', 'stag') : $field['std'];
                if ($meta) {
                    $field['std'] = __('Edit Gallery', 'stag');
                    $thumbs = explode(',', $meta);
                    $thumbs_output = '';
                    foreach ($thumbs as $thumb) {
                        $thumbs_output .= '<li>' . wp_get_attachment_image($thumb, array(75, 75)) . '</li>';
                    }
                }
                echo '<td class="stag-box-' . $field['type'] . '">
			            <input type="button" class="button" name="' . $field['id'] . '" id="stag_images_upload" value="' . $button_text . '" />
			            <input type="hidden" name="stag_meta[_stag_image_ids]" id="_stag_image_ids" value="' . ($meta ? $meta : 'false') . '" />
			            <ul class="stag-gallery-thumbs">' . $thumbs_output . '</ul>
			        </td>';
                break;
            case 'select':
                echo '<td><select name="stag_meta[' . $field['id'] . ']" id="' . $field['id'] . '">';
                foreach ($field['options'] as $key => $option) {
                    echo '<option value="' . $key . '"';
                    if ($meta) {
                        if ($meta == $key) {
                            echo ' selected="selected"';
                        }
                    } else {
                        if ($field['std'] == $key) {
                            echo ' selected="selected"';
                        }
                    }
                    echo '>' . $option . '</option>';
                }
                echo '</select></td>';
                break;
            case 'radio':
                echo '<td>';
                foreach ($field['options'] as $key => $option) {
                    echo '<label class="radio-label"><input type="radio" name="stag_meta[' . $field['id'] . ']" value="' . $key . '" class="radio"';
                    if ($meta) {
                        if ($meta == $key) {
                            echo ' checked="checked"';
                        }
                    } else {
                        if ($field['std'] == $key) {
                            echo ' checked="checked"';
                        }
                    }
                    echo ' /> ' . $option . '</label> ';
                }
                echo '</td>';
                break;
            case 'color':
                echo '<td class="stag-box-' . $field['type'] . '"><input data-default-color="' . @$field['std'] . '" type="text" id="' . $field['id'] . '" name="stag_meta[' . $field['id'] . ']" value="' . ($meta ? $meta : $field['std']) . '" class="colorpicker"></td>';
                ?>
				<script type="text/javascript">
					jQuery(document).ready(function($){
						jQuery("#<?php 
                echo $field['id'];
                ?>
").wpColorPicker();
					});
				</script>
				<?php 
                break;
            case 'checkbox':
                echo '<td>';
                $val = '';
                if ($meta) {
                    if ($meta == 'on') {
                        $val = ' checked="checked"';
                    }
                } else {
                    if ($field['std'] == 'on') {
                        $val = ' checked="checked"';
                    }
                }
                echo '<input type="hidden" name="stag_meta[' . $field['id'] . ']" value="off" />
	            <input type="checkbox" id="' . $field['id'] . '" name="stag_meta[' . $field['id'] . ']" value="on"' . $val . ' /> ';
                echo '</td>';
                break;
        }
        echo '</tr>';
    }
    echo '</table>';
}
/**
 * Outputs post specific CSS for post background image, color and opacity.
 *
 * @param  int $post_id Post ID.
 * @param  string $sel1 CSS Selector 1.
 * @param  string $sel2 CSS Selector 1.
 * @return mixed
 */
function stag_post_background_css($post_id = null, $sel1 = '.article-cover--', $sel2 = '.article-cover__background')
{
    if (0 === absint($post_id)) {
        $post_id = get_the_ID();
    }
    $thumb_id = get_post_thumbnail_id($post_id);
    if ($thumb_id != '') {
        $thumb_url = wp_get_attachment_image_src($thumb_id, 'full', true);
        $background_image = $thumb_url[0];
    } else {
        $background_image = '';
    }
    $background_color = stag_get_post_meta('settings', $post_id, 'post-background-color');
    $background_opacity = stag_get_post_meta('settings', $post_id, 'post-background-opacity');
    $text_color = stag_get_post_meta('settings', $post_id, 'post-text-color');
    $link_color = stag_get_post_meta('settings', $post_id, 'post-link-color');
    // Set a default background opacity
    if (empty($background_opacity)) {
        $background_opacity = 40;
    }
    ob_start();
    ?>

	<style type="text/css" scoped>
		<?php 
    if (!empty($background_color)) {
        ?>
		<?php 
        echo $sel1 . $post_id;
        ?>
 { background-color: <?php 
        echo stag_maybe_hash_hex_color($background_color);
        ?>
; }
		<?php 
    }
    ?>

		.background-video { opacity: <?php 
    echo absint($background_opacity) / 100;
    ?>
; }

		<?php 
    if (!empty($background_image)) {
        ?>
		<?php 
        echo $sel2;
        ?>
 { background-image: url(<?php 
        echo esc_url($background_image);
        ?>
); opacity: <?php 
        echo absint($background_opacity) / 100;
        ?>
; }
		<?php 
    }
    ?>

		<?php 
    if (is_page()) {
        ?>

		<?php 
        if (!empty($text_color)) {
            ?>
		<?php 
            echo $sel1 . $post_id;
            ?>
 { color: <?php 
            echo stag_maybe_hash_hex_color($text_color);
            ?>
; }
		<?php 
            echo $sel1 . $post_id;
            ?>
 input { color: <?php 
            echo stag_maybe_hash_hex_color($text_color);
            ?>
; border-color: <?php 
            echo stag_maybe_hash_hex_color($text_color);
            ?>
; }
		<?php 
        }
        ?>

		<?php 
        if (!empty($link_color)) {
            ?>
		<?php 
            echo $sel1 . $post_id;
            ?>
 a:not(.stag-button):not(.ui-tabs-anchor) { color: <?php 
            echo stag_maybe_hash_hex_color($link_color);
            ?>
; }
		<?php 
        }
        ?>

		<?php 
    }
    ?>
	</style>

	<?php 
    echo ob_get_clean();
}
 *
 * @package Stag_Customizer
 * @subpackage Ink
 */
$post_id = get_the_ID();
// Get post Categories
$categories_list = get_the_category_list(', ');
// Get Featured Image's caption
$thumb_post = get_post(get_post_thumbnail_id());
$caption = $thumb_post->post_excerpt;
$videos = array('video/mp4' => stag_get_post_meta('settings', $post_id, 'post-video-mp4'), 'video/webm' => stag_get_post_meta('settings', $post_id, 'post-video-webm'), 'video/ogv' => stag_get_post_meta('settings', $post_id, 'post-video-ogv'));
$videos = array_filter($videos);
// Hide videos if the post is restricted or password protected
$restricted_condition = count($videos) && !stag_rcp_user_has_no_access() && !post_password_required();
// Get CSS3 background filter option
$background_filter = stag_get_post_meta('settings', $post_id, 'post-background-filter');
if (!$background_filter) {
    $background_filter = 'none';
}
// Output post cover CSS
stag_post_background_css();
?>

<div class="article-cover article-cover--<?php 
echo esc_attr(get_the_ID());
if ($restricted_condition) {
    echo ' has-video';
}
?>
">
	<div class="article-cover__background stag-image--<?php 
Beispiel #5
0
<?php

/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Stag_Customizer
 * @subpackage Ink
 */
$background_filter = stag_get_post_meta('settings', get_the_ID(), 'post-background-filter');
if (!$background_filter) {
    $background_filter = 'none';
}
get_header();
?>

	<div id="main" class="site-main page-cover page-cover--<?php 
echo get_the_ID();
?>
">

		<div class="page-cover__background stag-image--<?php 
echo esc_attr($background_filter);
?>
"></div>

		<?php 
<?php

/**
 * Template Name: Widgetized
 *
 * Widgetized template, outputs sidebar area with a shortcode.
 * Requires Stag Custom Sidebars plugin.
 *
 * @see https://wordpress.org/plugins/stag-custom-sidebars/
 *
 * @package Stag_Customizer
 * @subpackage Ink
 */
// Get selected sidebar
$sidebar = stag_get_post_meta('settings', get_the_ID(), 'page-sidebar');
get_header();
?>

	<div id="main" class="site-main page-cover page-cover--<?php 
echo get_the_ID();
?>
">

		<div class="page-cover__background"></div>

		<?php 
stag_post_background_css(get_the_ID(), '.page-cover--', '.page-cover__background');
?>

		<?php 
while (have_posts()) {
Beispiel #7
0
/**
 * Display Subscribe/Login button on restricted pages.
 *
 * @return void
 */
function stag_rcp_locked_options($atts)
{
    if (!stag_is_rcp_active()) {
        return;
    }
    $args = shortcode_atts(array('button' => ''), $atts, 'locked_options');
    global $user_ID, $rcp_options;
    $is_displayed = $show_login_button = false;
    $registration_page = $rcp_options['registration_page'];
    if (!is_user_logged_in()) {
        $show_login_button = true;
    }
    $has_access = !rcp_is_paid_user($user_ID) && isset($registration_page) && $registration_page != '' ? true : false;
    if (isset($args['button']) && $args['button'] != '') {
        $button_color = $args['button'];
    } else {
        $background_color = stag_get_post_meta('settings', get_the_ID(), 'post-background-color');
        $button_color = $background_color === '' && !has_post_thumbnail() ? 'black' : 'white';
        if (is_single()) {
            $button_color = 'black';
        }
    }
    ob_start();
    ?>

	<div class="locked-options<?php 
    echo $has_access ? ' no-access' : ' has-access';
    ?>
 <?php 
    echo $button_color;
    ?>
-buttons">
		<?php 
    if ($has_access) {
        ?>
			<a href="<?php 
        echo get_permalink($registration_page);
        ?>
" class="stag-button stag-button--stroke stag-button--<?php 
        echo esc_attr($button_color);
        ?>
"><?php 
        _e('Subscribe', 'stag');
        ?>
</a>
			<?php 
        $is_displayed = true;
        ?>
		<?php 
    }
    ?>
		<?php 
    if ($show_login_button) {
        ?>
			<?php 
        if ($is_displayed) {
            echo '<span class="form-divider"></span>';
        }
        ?>
			<a href="<?php 
        echo wp_login_url();
        ?>
" class="stag-button stag-button--stroke stag-button--<?php 
        echo esc_attr($button_color);
        ?>
"><?php 
        _e('Login', 'stag');
        ?>
</a>
		<?php 
    }
    ?>
	</div>

	<?php 
    return ob_get_clean();
}