public function __construct($args)
 {
     if (!is_array($args)) {
         return;
     }
     $this->post_id = null === $args['post_id'] ? null : (int) $args['post_id'];
     $this->size = isset($args['size']) ? sanitize_key($args['size']) : false;
     $this->crop = isset($args['crop']) ? wp_validate_boolean($args['crop']) : (bool) 0;
     $this->img_class = isset($args['img_class']) ? sanitize_html_class($args['img_class']) : '';
     $this->img_default = isset($args['default']) ? esc_url_raw($args['default']) : '';
     $this->img_src = isset($args['src']) && '' != $args['src'] ? esc_url_raw($args['src']) : '';
     $this->img_src = isset($args['full_src']) ? esc_url_raw($args['full_src']) : $this->img_src;
     $this->direct_src_external = '' != $this->img_src ? $this->img_src : '';
     $this->post = get_post($this->post_id);
     $this->attachment_id = intval(get_post_thumbnail_id($this->post_id));
     if (!is_admin()) {
         $image = $this->thumbnail_meta_data();
         if (0 == $this->attachment_id) {
             $this->attachment_id = $image['attachment_id'];
             if (!is_admin()) {
                 $this->img_src = $image['src'];
             }
             if (-1 == $this->attachment_id) {
                 $this->img_src_ext = $image['src'];
             }
         }
     }
     $this->attachment = get_post($this->attachment_id);
     add_filter('icon_dir', array($this, 'filter_icon_dir'));
 }
예제 #2
0
파일: init.php 프로젝트: ka215/wp-qiita
/**
 * Instance factory for WP Qiita plugin
 *
 * @since v1.0.0
 *
 * @param boolean $set_global [optional] Default is true
 * @return void
 */
function wpqt_factory($set_global = true)
{
    if (wp_validate_boolean($set_global)) {
        global $wpqt;
        $wpqt = WpQiitaMain::instance();
    } else {
        return WpQiitaMain::instance();
    }
}
예제 #3
0
 /**
  * Callback for the [_playlist] shortcode
  *
  * @uses wp_validate_boolean() from WordPress 4.0
  */
 public function playlist_shortcode($atts = array(), $content = '')
 {
     global $content_width;
     // Theme dependent content width
     $this->instance++;
     // Counter to activate the 'wp_playlist_scripts' action only once
     $atts = shortcode_atts(array('type' => 'audio', 'style' => 'light', 'tracklist' => 'true', 'tracknumbers' => 'true', 'images' => 'true', 'artists' => 'true', 'current' => 'true', 'autoplay' => 'false', 'class' => 'wpse-playlist', 'width' => '', 'height' => '', 'outer' => '20', 'default_width' => '640', 'default_height' => '380'), $atts, 'wpse_playlist_shortcode');
     // Autoplay:
     $autoplay = wp_validate_boolean($atts['autoplay']) ? 'autoplay="yes"' : '';
     // Nested shortcode support:
     $this->type = in_array($atts['type'], $this->types, TRUE) ? esc_attr($atts['type']) : 'audio';
     // Enqueue default scripts and styles for the playlist.
     1 === $this->instance && do_action('wp_playlist_scripts', esc_attr($atts['type']), esc_attr($atts['style']));
     //----------
     // Height & Width - Adjusted from the WordPress core
     //----------
     $width = esc_attr($atts['width']);
     if (empty($width)) {
         $width = empty($content_width) ? intval($atts['default_width']) : $content_width - intval($atts['outer']);
     }
     $height = esc_attr($atts['height']);
     if (empty($height) && intval($atts['default_height']) > 0) {
         $height = empty($content_width) ? intval($atts['default_height']) : round(intval($atts['default_height']) * $width / intval($atts['default_width']));
     }
     //----------
     // Output
     //----------
     $html = '';
     // Start div container:
     $html .= sprintf('<div class="wp-playlist wp-%s-playlist wp-playlist-%s ' . esc_attr($atts['class']) . '">', $this->type, esc_attr($atts['style']));
     // Current audio item:
     if ($atts['current'] && 'audio' === $this->type) {
         $html .= '<div class="wp-playlist-current-item"></div>';
     }
     // Video player:
     if ('video' === $this->type) {
         $html .= sprintf('<video controls="controls" ' . $autoplay . ' preload="none" width="%s" height="%s"></video>', $width, $height);
     } else {
         $html .= sprintf('<audio controls="controls" ' . $autoplay . ' preload="none" width="%s" style="visibility: hidden"></audio>', $width);
     }
     // Next/Previous:
     $html .= '<div class="wp-playlist-next"></div><div class="wp-playlist-prev"></div>';
     // JSON
     $html .= sprintf('
         <script class="wp-playlist-script" type="application/json">{
             "type":"%s",
             "tracklist":%s,
             "tracknumbers":%s,
             "images":%s,
             "artists":%s,
             "tracks":[%s]
         }</script>', esc_attr($atts['type']), wp_validate_boolean($atts['tracklist']) ? 'true' : 'false', wp_validate_boolean($atts['tracknumbers']) ? 'true' : 'false', wp_validate_boolean($atts['images']) ? 'true' : 'false', wp_validate_boolean($atts['artists']) ? 'true' : 'false', $this->get_tracks_from_content($content));
     // Close div container:
     $html .= '</div>';
     return $html;
 }
예제 #4
0
function extrp_bail_noimage()
{
    global $extrp_settings, $extrp_sanitize;
    $extrp_noimage = [];
    $args = array('post_id' => null, 'src' => esc_url_raw(EXTRP_URL_PLUGIN_IMAGES . 'default.png'), 'size' => 'thumbnail');
    $thumbnail = extrp_thumbnail($args);
    $extrp_noimage = $thumbnail->attachment_external();
    $output['noimage'] = array('attachment_id' => absint($extrp_noimage['attachment_id']), 'default' => esc_url_raw($extrp_noimage['default']), 'full_src' => esc_url_raw($extrp_noimage['default']), 'size' => $extrp_sanitize->size($extrp_noimage['size']), 'src' => esc_url_raw($extrp_noimage['src']), 'width' => intval($extrp_noimage['width']), 'height' => intval($extrp_noimage['height']), 'crop' => wp_validate_boolean($extrp_noimage['crop']));
    $args = wp_parse_args($output, $extrp_settings);
    return $args;
}
 /**
  * Builds the Video shortcode output.
  *
  * This implements the functionality of the Video Shortcode for displaying
  * WordPress mp4s in a post.
  *
  *
  * @param array  $attr {
  *     Attributes of the shortcode.
  *
  *     @type string $src      URL to the source of the video file. Default empty.
  *     @type int    $height   Height of the video embed in pixels. Default 360.
  *     @type int    $width    Width of the video embed in pixels. Default $content_width or 640.
  *     @type string $poster   The 'poster' attribute for the `<video>` element. Default empty.
  *     @type string $loop     The 'loop' attribute for the `<video>` element. Default empty.
  *     @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
  *     @type string $preload  The 'preload' attribute for the `<video>` element.
  *                            Default 'metadata'.
  *     @type string $class    The 'class' attribute for the `<video>` element.
  *                            Default 'simple-fb-video-shortcode'.
  * }
  * @param string $content Shortcode content.
  * @return string|void HTML content to display video.
  */
 function video($attr, $content = '')
 {
     /**
      * Filter the default video shortcode output.
      *
      * If the filtered output isn't empty, it will be used instead of generating
      * the default video template.
      *
      * @since 3.6.0
      *
      * @see wp_video_shortcode()
      *
      * @param string $html     Empty variable to be replaced with shortcode markup.
      * @param array  $attr     Attributes of the video shortcode.
      * @param string $content  Video shortcode content.
      */
     $override = apply_filters('simple_fb_video_shortcode_override', '', $attr, $content);
     if ('' !== $override) {
         return $override;
     }
     $video = null;
     $default_types = wp_get_video_extensions();
     $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360);
     foreach ($default_types as $type) {
         $defaults_atts[$type] = '';
     }
     // Boom, atts.
     $atts = shortcode_atts($defaults_atts, $attr, 'video');
     $primary = false;
     foreach ($default_types as $ext) {
         if (!empty($atts[$ext])) {
             $type = wp_check_filetype($atts[$ext], wp_get_mime_types());
             if (strtolower($type['ext']) === $ext) {
                 $primary = true;
             }
         }
     }
     if (!$primary) {
         $videos = get_attached_media('video', $post_id);
         if (empty($videos)) {
             return;
         }
         $video = reset($videos);
         $atts['src'] = wp_get_attachment_url($video->ID);
         if (empty($atts['src'])) {
             return;
         }
         array_unshift($default_types, 'src');
     }
     $html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'simple-fb-video-shortcode'), 'id' => sprintf('video-%d', $post_id), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload']);
     // These ones should just be omitted altogether if they are blank
     foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
         if (empty($html_atts[$a])) {
             unset($html_atts[$a]);
         }
     }
     $attr_strings = array();
     foreach ($html_atts as $k => $v) {
         $attr_strings[] = $k . '="' . esc_attr($v) . '"';
     }
     $html = '';
     $html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
     $fileurl = '';
     $source = '<source type="%s" src="%s" />';
     foreach ($default_types as $fallback) {
         if (!empty($atts[$fallback])) {
             if (empty($fileurl)) {
                 $fileurl = $atts[$fallback];
             }
             if ('src' === $fallback && $is_youtube) {
                 $type = array('type' => 'video/youtube');
             } elseif ('src' === $fallback && $is_vimeo) {
                 $type = array('type' => 'video/vimeo');
             } else {
                 $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
             }
             $url = add_query_arg('_', $instance, $atts[$fallback]);
             $html .= sprintf($source, $type['type'], esc_url($url));
         }
     }
     if (!empty($content)) {
         if (false !== strpos($content, "\n")) {
             $content = str_replace(array("\r\n", "\n", "\t"), '', $content);
         }
         $html .= trim($content);
     }
     $html .= '</video>';
     /**
      * Filter the output of the video shortcode.
      *
      * @since 3.6.0
      *
      * @param string $output  Video shortcode HTML output.
      * @param array  $atts    Array of video shortcode attributes.
      * @param string $video   Video file.
      * @param int    $post_id Post ID.
      */
     return apply_filters('simple_fb_video_shortcode', $output, $atts, $video, $post_id);
 }
 /**
  * @ticket 30238
  */
 public function test_string_false_mixedcase()
 {
     // Differs from (bool) conversion.
     $this->assertFalse(wp_validate_boolean('FaLsE'));
 }
예제 #7
0
파일: main.php 프로젝트: ka215/wp-qiita
 /**
  * Retrieve authenticated item stocks
  *
  * @since 1.0.0
  *
  * @param string $item_id [required]
  * @param int $post_id [optional] This processing performance is improved when specified the synchronizing post ID.
  * @return int $stocks
  */
 public function get_item_stocks($item_id = null, $post_id = null)
 {
     $_message_type = $this->message_type['err'];
     $_message = null;
     $stocks = 0;
     if (empty($item_id)) {
         return $stocks;
     }
     if (empty($post_id) || $post_id < 1) {
         $_posts = get_posts(array('numberposts' => -1, 'post_type' => $this->domain_name, 'author' => $this->current_user, 'meta_key' => 'wpqt_item_id', 'meta_value' => $item_id));
         if (!empty($_posts)) {
             $post_id = $_posts[0]->ID;
         }
     }
     if (empty($post_id) || $post_id < 1) {
         return $stocks;
     }
     if ($item_id === get_post_meta($post_id, 'wpqt_item_id', true)) {
         $reference_item_stocks = get_post_meta($post_id, 'wpqt_stocks', true);
     }
     $reference_item_stocks = isset($reference_item_stocks) && wp_validate_boolean($reference_item_stocks) ? intval($reference_item_stocks) : $stocks;
     //$this->token = empty( $this->token ) ? $current_user_meta['access_token'] : $this->token;
     $this->token = empty($this->token) ? $this->user_options['access_token'] : $this->token;
     $start_page = floor($reference_item_stocks / 100);
     $start_page = $start_page > 1 ? $start_page - 1 : 1;
     $stocks = ($start_page - 1) * 100;
     for ($i = $start_page; $i <= 100; $i++) {
         $url = $this->get_api_url(array('items', $item_id, 'stockers'), array('page' => $i, 'per_page' => 100));
         if (method_exists($this, 'request_api')) {
             $request_args = array('method' => 'GET', 'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $this->token));
             $response = wp_remote_request($url, $request_args);
             if ($this->validate_response_code($response)) {
                 // Success
                 $_parse_response = json_decode(wp_remote_retrieve_body($response));
                 if (count($_parse_response) > 0) {
                     $stocks += count($_parse_response);
                 } else {
                     break;
                 }
             } else {
                 // Fails
                 break;
             }
         }
     }
     update_post_meta($post_id, 'wpqt_stocks', $stocks);
     return $stocks;
 }
예제 #8
0
    /**
     * Renders a shortcode from either AJAX or paramenter and returns rendered html
     * @param string $shortcode shortcode to render
     * @param string $comments
     * @return string html content
     */
    public function wa_render_shortcode($shortcode = false, $comments = false)
    {
        $is_ajax = false;
        if (!$shortcode) {
            $shortcode = stripslashes($_POST['shortcode']);
            $comments = wp_validate_boolean($_POST['comments']);
            $is_ajax = true;
        }
        preg_match('/(?>\\[)([^\\s|^\\]]+)/s', $shortcode, $sub_matches);
        if (!empty($sub_matches) && $sub_matches[1] !== '') {
            $html = ($comments ? '<!-- shortcode -->' : '') . '
					<div
						class="wa-shortcode-wrap"
						data-shortcode-base="' . $sub_matches[1] . '"
						data-shortcode="' . rawurlencode($shortcode) . '">
						' . do_shortcode($shortcode) . '
					</div>
				' . ($comments ? '<!-- /shortcode -->' : '');
        } else {
            $html = '';
        }
        if ($is_ajax) {
            echo $html;
            die;
        } else {
            return $html;
        }
    }
예제 #9
0
                  </div>
                </div>
              </div><!-- /.form-horizontal -->

                  </div>
                </div>
              </div>
              
            </div><!-- /.panel-body -->
          </div><!-- /.panel-collapse -->
        </div><!-- /.panel -->
      </div><!-- /#accordion-->
<?php 
    } else {
        // Set defaults
        extract(array('_load_jquery' => isset($_qiita_user_meta['load_jquery']) ? wp_validate_boolean($_qiita_user_meta['load_jquery']) : true, '_show_posttype' => isset($_qiita_user_meta['show_posttype']) ? wp_validate_boolean($_qiita_user_meta['show_posttype']) : false, '_autosync' => isset($_qiita_user_meta['autosync']) ? wp_validate_boolean($_qiita_user_meta['autosync']) : false, '_autosync_interval' => isset($_qiita_user_meta['autosync_interval']) && intval($_qiita_user_meta['autosync_interval']) > 0 ? intval($_qiita_user_meta['autosync_interval']) : '', '_autosync_status' => __('Undefined', $this->domain_name), '_autopost' => isset($_qiita_user_meta['autopost']) ? wp_validate_boolean($_qiita_user_meta['autopost']) : false, '_remove_post' => isset($_qiita_user_meta['remove_post']) ? wp_validate_boolean($_qiita_user_meta['remove_post']) : false, '_deactivate_qiita' => isset($_qiita_user_meta['deactivate_qiita']) ? wp_validate_boolean($_qiita_user_meta['deactivate_qiita']) : false));
        foreach ($this->options as $_key => $_val) {
            $_[$_key] = $_val;
        }
        if (isset($this->options['autosync_datetime']) && !empty($this->options['autosync_datetime'])) {
            $_timezone = get_option('timezone_string');
            date_default_timezone_set($_timezone);
            $_next_autosync = date_i18n('Y-m-d H:i', $this->options['autosync_datetime'], false);
            $_autosync_status = sprintf(__('Next autosync will be executed at %s.', $this->domain_name), '<time>' . $_next_autosync . '</time>');
        }
        ?>
      <h3 class="text-success"><?php 
        _e('Currently, already Activated.', $this->domain_name);
        ?>
</h3>
      
 /**
  * create admin plugin page
  *
  * @since 1.1
  *
  */
 public function create_page()
 {
     global $stt2extat_screen_id, $current_screen;
     if ($current_screen->id != $stt2extat_screen_id) {
         return;
     }
     add_filter('admin_footer_text', array($this, 'admin_footer_text'));
     add_filter('update_footer', array($this, 'update_footer'), 20);
     $error = false;
     if (isset($_REQUEST['message']) && ($code = (int) $_REQUEST['message'])) {
         $error = isset($_GET['error']) ? wp_validate_boolean($_GET['error']) : $error;
         do_action('stt2extat_notice', $code, $error, $add_setting_error = false);
     }
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('message', 'error'), $_SERVER['REQUEST_URI']);
     $this->create_mb();
 }
 public function ajx_noimg_view_cb()
 {
     global $extrp_sanitize, $extrp_screen_id;
     if (!wp_verify_nonce($_REQUEST['nonce'], 'heartbeat-nonce') || !check_ajax_referer('heartbeat-nonce', 'nonce', false)) {
         $noperm = array('result' => array('msg' => __('You do not have permission to do that.', 'extrp'), 'tokenid' => (int) 3));
         $msg = wp_json_encode($noperm);
         wp_die($msg);
     }
     if (isset($_POST['chk']) && 'settings_page_extrp' == sanitize_key($_POST['chk'])) {
         $thumb = $extrp_sanitize->data_thumb(array('size' => $extrp_sanitize->size($_POST['size']), 'src' => esc_url($_POST['src']), 'crop' => wp_validate_boolean($_POST['crop'])));
         if (!$thumb) {
             $fail = array('result' => array('msg' => __('Fail to generate image. Refresh your page and try again.', 'extrp'), 'tokenid' => (int) 2));
             $msg = wp_json_encode($fail);
             wp_die($msg);
         }
         if (!$thumb['src']) {
             $noperm = array('result' => array('msg' => __('Image not exists. Please check your image from media library. You can add new one or push &#39;Save Changes&#39; button to get default image directly.', 'extrp'), 'tokenid' => (int) 4));
             $msg = wp_json_encode($noperm);
             wp_die($msg);
         }
         $success = array('result' => array('title' => get_the_title(intval($_POST['attach_id'])), 'src' => esc_url($_POST['src']), 'thumbnail' => esc_url($thumb['src']), 'size' => sanitize_key($thumb['size']), 'width' => intval($thumb['width']), 'height' => intval($thumb['height']), 'crop' => wp_validate_boolean($thumb['crop']), 'shape' => $extrp_sanitize->shape($_POST['shape']), 'msg' => __('Success', 'extrp'), 'tokenid' => (int) 1));
         $result = wp_json_encode($success);
         wp_die($result);
     } else {
         $noperm = array('result' => array('msg' => __('You do not have permission to do that.', 'extrp'), 'tokenid' => (int) 3));
         $msg = wp_json_encode($noperm);
         wp_die($msg);
     }
 }
예제 #12
0
 /**
  * Builds the Playlist shortcode output.
  *
  * This implements the functionality of the playlist shortcode for
  * displaying a collection of WordPress audio or video files in a
  * post.
  *
  * This method is based on the WordPress core function
  * `wp_playlist_shortcode` but has been modified to add VTT data.
  *
  * @param array $attr {
  *     Array of default playlist attributes.
  *
  *     @type string  $type         Type of playlist to display. Accepts 'audio' or 'video'. Default 'audio'.
  *     @type string  $order        Designates ascending or descending order of items in the playlist.
  *                                 Accepts 'ASC', 'DESC'. Default 'ASC'.
  *     @type string  $orderby      Any column, or columns, to sort the playlist. If $ids are
  *                                 passed, this defaults to the order of the $ids array ('post__in').
  *                                 Otherwise default is 'menu_order ID'.
  *     @type int     $id           If an explicit $ids array is not present, this parameter
  *                                 will determine which attachments are used for the playlist.
  *                                 Default is the current post ID.
  *     @type array   $ids          Create a playlist out of these explicit attachment IDs. If empty,
  *                                 a playlist will be created from all $type attachments of $id.
  *                                 Default empty.
  *     @type array   $exclude      List of specific attachment IDs to exclude from the playlist. Default empty.
  *     @type string  $style        Playlist style to use. Accepts 'light' or 'dark'. Default 'light'.
  *     @type bool    $tracklist    Whether to show or hide the playlist. Default true.
  *     @type bool    $tracknumbers Whether to show or hide the numbers next to entries in the playlist. Default true.
  *     @type bool    $images       Show or hide the video or audio thumbnail (Featured Image/post
  *                                 thumbnail). Default true.
  *     @type bool    $artists      Whether to show or hide artist name in the playlist. Default true.
  * }
  * @return string Playlist output. Empty string if the passed type is unsupported.
  * @since 1.3.0
  * @global int $content_width
  * @staticvar int $instance
  * @see wp_playlist_shortcode
  */
 function wp_playlist_shortcode($attr)
 {
     static $instance = 0;
     $instance++;
     if (!empty($attr['ids'])) {
         $attr['include'] = $attr['ids'];
         // 'ids' is explicitly ordered, unless you specify otherwise.
         if (empty($attr['orderby'])) {
             $attr['orderby'] = 'post__in';
         }
     }
     $output = apply_filters('post_playlist', '', $attr, $instance);
     if ('' !== $output) {
         return $output;
     }
     unset($output);
     $atts = shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => get_the_ID() ?: 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist');
     if ('audio' !== $atts['type']) {
         $atts['type'] = 'video';
     }
     $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $atts['type'], 'order' => $atts['order'], 'orderby' => $atts['orderby']);
     if ('' !== $atts['include']) {
         $args['include'] = $atts['include'];
     } else {
         $args['post_parent'] = intval($atts['id']);
         if ('' !== $atts['exclude']) {
             $args['exclude'] = $atts['exclude'];
         }
     }
     if (!($attachments = get_posts($args))) {
         return '';
     }
     if (is_feed()) {
         ob_start();
         echo "\n";
         foreach ($attachments as $a) {
             echo wp_get_attachment_link($a->ID), "\n";
         }
         return ob_get_clean();
     }
     $outer = 22;
     // default padding and border of wrapper
     global $content_width;
     $default_width = 640;
     $default_height = 360;
     $theme_width = empty($content_width) ? $default_width : $content_width - $outer;
     $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width);
     ob_start();
     if (1 === $instance) {
         do_action('wp_playlist_scripts', $atts['type'], $atts['style']);
     }
     echo '<div class="wp-playlist wp-', $atts['type'], '-playlist wp-playlist-', esc_attr($atts['style']), '">';
     if ('audio' === $atts['type']) {
         echo '<div class="wp-playlist-current-item"></div><audio';
     } else {
         echo '<video height="', $theme_height, '"';
     }
     echo ' controls="controls" preload="none" width="', $theme_width, '">', '</', $atts['type'], '>';
     echo '<div class="wp-playlist-next"></div>', '<div class="wp-playlist-prev"></div>', '<noscript>', '<ol>';
     $atts['images'] = wp_validate_boolean($atts['images']);
     $tracks = array();
     foreach ($attachments as $a) {
         // For <noscript>.
         echo '<li>', wp_get_attachment_link($a->ID), '</li>';
         // Remaining is for JSON data.
         $track = array('src' => wp_get_attachment_url($a->ID), 'title' => $a->post_title);
         if ($a->post_excerpt) {
             $track['caption'] = $a->post_excerpt;
         }
         if ($a->post_content) {
             $track['description'] = $a->post_content;
         }
         if ($meta = $this->get_tracks_json_data($track['src'])) {
             $track['webvtt'] = $meta;
         }
         if ($meta = wp_get_attachment_metadata($a->ID)) {
             foreach (wp_get_attachment_id3_keys($a) as $key => $label) {
                 if (!empty($meta[$key])) {
                     $track['meta'][$key] = $meta[$key];
                 }
             }
             if ('video' === $atts['type']) {
                 if (!empty($meta['width']) && !empty($meta['height'])) {
                     $width = $meta['width'];
                     $height = $meta['height'];
                     $theme_height = round($height * $theme_width / $width);
                 } else {
                     $width = $default_width;
                     $height = $default_height;
                 }
                 $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height));
             }
         }
         if (true === $atts['images'] && ($thumb_id = get_post_thumbnail_id($a->ID))) {
             $track['image'] = wp_get_attachment_image_src($thumb_id, 'full');
             $track['thumb'] = wp_get_attachment_image_src($thumb_id);
         }
         $tracks[] = $track;
     }
     echo '</ol>', '</noscript>', '<script type="application/json" class="wp-playlist-script">', wp_json_encode(array('type' => $atts['type'], 'tracklist' => wp_validate_boolean($atts['tracklist']), 'tracknumbers' => wp_validate_boolean($atts['tracknumbers']), 'images' => $atts['images'], 'artists' => wp_validate_boolean($atts['artists']), 'tracks' => $tracks)), '</script>', '</div>';
     return ob_get_clean();
 }
예제 #13
0
/**
 * Convert string to boolean
 *
 * @since   0.2.1
 * @param   string  $value  Value to validate. Default: false.
 * @return  bool            True or false.
 */
function wp_bc_bool($value = false)
{
    if (function_exists('wp_validate_boolean')) {
        return wp_validate_boolean($value);
    }
    return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
 public function sanitize($input)
 {
     $new_input = array();
     $keys = array_keys($this->default_setting);
     if (isset($input['activate']) && wp_validate_boolean($input['activate'])) {
         if ('' == sanitize_user($input['aff'])) {
             $msg = __('Your affiliate ID still empty. Try to add yours.', 'klikbayi');
             $flag = 'error';
             $new_input = false;
         } else {
             if ('' !== sanitize_user($this->options['aff'])) {
                 $text = __('Your Affiliate ID was added.', 'klikbayi');
                 $msg = $text . $this->options['aff'];
                 $flag = 'notice-warning';
                 $new_input = false;
             } else {
                 $text = __('Success to add your affiliate ID.', 'klikbayi');
                 $msg = $text . '<kbd>' . sanitize_user($input['aff']) . '</kbd>';
                 $flag = 'updated';
                 $input['active'] = (bool) 1;
                 $new_input = wp_parse_args($input, $this->default_setting);
             }
         }
         add_settings_error('klikbayi-notices', 'active-notice', $msg, esc_attr($flag));
         return $this->validate->sanitize($new_input);
     }
     if (isset($input['reset']) && 'Reset' == sanitize_text_field($input['reset'])) {
         $new_input = wp_parse_args(array('active' => (bool) 1, 'aff' => sanitize_user($this->options['aff'])), $this->default_setting);
         $msg = __('Success to reset your data.', 'klikbayi');
         add_settings_error('klikbayi-notices', 'reset-notice', $msg, 'updated');
         return $new_input;
     }
     if (isset($input['size_1']) || isset($input['size_2'])) {
         $input['size'] = array(absint($input['size_1']), absint($input['size_2']), 'px' == sanitize_text_field($input['size_3']) ? 'px' : '%%');
     }
     foreach ($keys as $k) {
         $new_input[$k] = $input[$k];
     }
     return $this->validate->sanitize($new_input);
 }
예제 #15
0
파일: utils.php 프로젝트: ka215/wp-qiita
 /**
  * Get the URL of the current page with the full path
  *
  * @since 1.0.0
  *
  * @param boolean $absolute [required] Default is TRUE
  * @return string $url
  */
 public function get_current_url($absolute = true)
 {
     if ($_SERVER['SERVER_PROTOCOL']) {
         list($scheme, ) = explode('/', $_SERVER['SERVER_PROTOCOL']);
     }
     if ($_SERVER['HTTP_HOST']) {
         $hostname = $_SERVER['HTTP_HOST'];
     }
     if ($_SERVER['REQUEST_URI']) {
         $request_uri = $_SERVER['REQUEST_URI'];
     } else {
         if ($_SERVER['PHP_SELF'] && $_SERVER['QUERY_STRING']) {
             $request_uri = $_SERVER['PHP_SELF'] . (!empty($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
         }
     }
     if (wp_validate_boolean($absolute)) {
         $_host = isset($scheme) && !empty($scheme) && isset($hostname) && !empty($hostname) ? strtolower($scheme) . '://' . $hostname : site_url();
         $url = rtrim($_host, '/') . $request_uri;
     } else {
         $url = $request_uri;
     }
     return $url;
 }
 public function sanitize($c = '')
 {
     $default = $this->array_default_setting();
     $a = array_keys($default);
     if (empty($c)) {
         $c = $default;
     }
     $key = array_keys($c);
     $b = wp_parse_args($c, $default);
     $args = array($a[0] => wp_validate_boolean($b['active']), $a[1] => $this->post_types($b['post_type']), $a[2] => $this->relatedby($b['relatedby']), $a[3] => wp_validate_boolean($b['single']), $a[4] => absint($b['posts']), $a[5] => $this->post_date($b['post_date']), $a[6] => $this->heading($b['heading']), $a[7] => $this->heading($b['postheading']), $a[8] => sanitize_text_field($b['subtitle']), $a[9] => wp_validate_boolean($b['randomposts']), $a[10] => sanitize_text_field($b['titlerandom']), $a[11] => wp_validate_boolean($b['post_title']), $a[12] => wp_validate_boolean($b['desc']), $a[13] => $this->data_textarea($b['stopwords']), $a[14] => $this->display($b['display']), $a[15] => $this->post_ids($b['post__in']), $a[16] => $this->post_ids($b['post__not_in']), $a[17] => wp_validate_boolean($b['css']), $a[18] => wp_validate_boolean($b['thumb']), $a[19] => wp_validate_boolean($b['ext_thumb']), $a[20] => $this->size($b['image_size']), $a[21] => $this->customsize($b['customsize']), $a[22] => $this->shape($b['shape']), $a[23] => wp_validate_boolean($b['crop']), $a[24] => $this->data_thumb($b['noimage']), $a[25] => wp_validate_boolean($b['post_excerpt']), $a[26] => $this->highlight($b['highlight']), $a[27] => absint($b['maxchars']), $a[28] => $this->relevanssi($b['relevanssi']), $a[29] => wp_validate_boolean($b['cache']), $a[30] => absint($b['expire']), $a[31] => absint($b['schedule']));
     foreach ($args as $k => $v) {
         if (!in_array($k, $key)) {
             unset($args[$k]);
         }
     }
     return $args;
 }
 public function sanitize($c = '')
 {
     $default = $this->array_default_setting();
     $a = array_keys($default);
     if (empty($c)) {
         $c = $default;
     }
     $key = array_keys($c);
     $b = wp_parse_args($c, $default);
     $args = array($a[0] => $this->domain($b['domain']), $a[1] => $this->domain($b['blog']), $a[2] => wp_validate_boolean($b['active']), $a[3] => $this->post_ids($b['post__in']), $a[4] => $this->post_ids($b['post__not_in']), $a[5] => sanitize_user($b['aff']), $a[6] => $this->type($b['type']), $a[7] => sanitize_text_field($b['form_title']), $a[8] => sanitize_text_field($b['button_text']), $a[9] => $this->size($b['size']), $a[10] => $this->style($b['style']), $a[11] => $this->editor($b['editor']));
     foreach ($args as $k => $v) {
         if (!in_array($k, $key)) {
             unset($args[$k]);
         }
     }
     return $args;
 }
예제 #18
0
 public function widget($args, $instance)
 {
     $cache = array();
     if (!$this->is_preview()) {
         $cache = wp_cache_get('stt2extat_widget_terms_list', 'widget');
     }
     if (!is_array($cache)) {
         $cache = array();
     }
     if (!isset($args['widget_id'])) {
         $args['widget_id'] = $this->id;
     }
     if (isset($cache[$args['widget_id']])) {
         echo $cache[$args['widget_id']];
         return;
     }
     ob_start();
     $title = __('Popular Terms', 'stt2extat');
     $post_id = null;
     $sort = isset($instance['sort']) ? $instance['sort'] : 'count';
     $obj = get_queried_object();
     $tax = $cloud = false;
     $tax_query = $args_cloud = array();
     switch ($sort) {
         case 'taxonomy':
             if (!isset($obj->term_id)) {
                 return null;
             }
             $title .= ' in ' . $obj->name;
             $tax_query = array('tax_query' => array('tax_query' => array(array('taxonomy' => $obj->taxonomy, 'terms' => $obj->term_id))));
             $sort = 'count';
             $tax = true;
             break;
         case 'post_id':
             if (!is_single()) {
                 return null;
             }
             $title .= __(' Post', 'stt2extat');
             $post_id = $obj->ID;
             $sort = 'count';
             break;
         case 'term_id':
             $title = __('Recent Terms', 'stt2extat');
             break;
         case 'recent':
             if (!is_single()) {
                 return null;
             }
             $title = __('Recent Terms Post', 'stt2extat');
             $post_id = $obj->ID;
             $sort = 'term_id';
             break;
         case 'term_cloud':
             $title = __('Term Cloud', 'stt2extat');
             $args_cloud = apply_filters('stt2extat_tag_cloud_args', array());
             $sort = 'count';
             $cloud = true;
             break;
         default:
             $title = $title;
             break;
     }
     $title = apply_filters('widget_title', empty($instance['title']) ? $title : $instance['title'], $instance, $this->id_base);
     $interval = isset($instance['interval']) ? $instance['interval'] : 'all';
     $number = isset($instance['number']) ? $instance['number'] : 5;
     $count = isset($instance['count']) ? $instance['count'] : 'tooltips';
     $convert = isset($instance['convert']) ? $instance['convert'] : 'n';
     $args_query = array('sort' => $sort, 'number' => $number, 'order' => 'DESC', 'p' => $post_id);
     $args_interval = apply_filters('stt2extat_widget_interval_time', array('date_query' => array('after' => $interval)));
     if ('all' != $interval) {
         $args_query = wp_parse_args($args_interval, $args_query);
     }
     if ('count' == $sort && $tax) {
         $args_query = wp_parse_args($tax_query, $args_query);
     }
     $set = array('text_header' => '', 'html_heading' => '', 'display' => 'ul', 'count' => $count, 'convert' => $convert);
     $args_query = wp_parse_args($args_query, $set);
     $result = stt2extat_terms_list($args_query, $widget = (object) array('is_widget' => true, 'cloud' => wp_validate_boolean($cloud)));
     if ('count' == $sort && $cloud) {
         unset($args_cloud['number']);
         // use args_query['number']
         $args_cloud['filter'] = false;
         $args_cloud['topic_count_text'] = _n_noop('%s hit', '%s hits');
         if (has_filter('stt2extat_term_count', 'stt2extat_count_posts')) {
             $args_cloud['topic_count_text'] = _n_noop('%s topic', '%s topics');
         }
         if ('n' == $args_query['count']) {
             $args_cloud['topic_count_text'] = '';
         }
         $result = wp_generate_tag_cloud($result, $args_cloud);
     }
     if (!empty($result)) {
         echo $args['before_widget'];
         if ($title) {
             echo $args['before_title'] . $title . $args['after_title'];
         }
         echo $result;
         echo $args['after_widget'];
     }
     if (!$this->is_preview()) {
         $cache[$args['widget_id']] = ob_get_flush();
         wp_cache_set('stt2extat_widget_terms_list', $cache, 'widget', 3600);
     } else {
         ob_end_flush();
     }
 }
예제 #19
0
/**
 * The playlist shortcode.
 *
 * This implements the functionality of the playlist shortcode for displaying
 * a collection of WordPress audio or video files in a post.
 *
 * @since 3.9.0
 *
 * @param array $attr {
 *     Array of default playlist attributes.
 *
 *     @type string  $type         Type of playlist to display. Accepts 'audio' or 'video'. Default 'audio'.
 *     @type string  $order        Designates ascending or descending order of items in the playlist.
 *                                 Accepts 'ASC', 'DESC'. Default 'ASC'.
 *     @type string  $orderby      Any column, or columns, to sort the playlist. If $ids are
 *                                 passed, this defaults to the order of the $ids array ('post__in').
 *                                 Otherwise default is 'menu_order ID'.
 *     @type int     $id           If an explicit $ids array is not present, this parameter
 *                                 will determine which attachments are used for the playlist.
 *                                 Default is the current post ID.
 *     @type array   $ids          Create a playlist out of these explicit attachment IDs. If empty,
 *                                 a playlist will be created from all $type attachments of $id.
 *                                 Default empty.
 *     @type array   $exclude      List of specific attachment IDs to exclude from the playlist. Default empty.
 *     @type string  $style        Playlist style to use. Accepts 'light' or 'dark'. Default 'light'.
 *     @type bool    $tracklist    Whether to show or hide the playlist. Default true.
 *     @type bool    $tracknumbers Whether to show or hide the numbers next to entries in the playlist. Default true.
 *     @type bool    $images       Show or hide the video or audio thumbnail (Featured Image/post
 *                                 thumbnail). Default true.
 *     @type bool    $artists      Whether to show or hide artist name in the playlist. Default true.
 * }
 *
 * @return string Playlist output. Empty string if the passed type is unsupported.
 */
function wp_playlist_shortcode($attr)
{
    global $content_width;
    $post = get_post();
    static $instance = 0;
    $instance++;
    if (!empty($attr['ids'])) {
        // 'ids' is explicitly ordered, unless you specify otherwise.
        if (empty($attr['orderby'])) {
            $attr['orderby'] = 'post__in';
        }
        $attr['include'] = $attr['ids'];
    }
    /**
     * Filter the playlist output.
     *
     * Passing a non-empty value to the filter will short-circuit generation
     * of the default playlist output, returning the passed value instead.
     *
     * @since 3.9.0
     *
     * @param string $output Playlist output. Default empty.
     * @param array  $attr   An array of shortcode attributes.
     */
    $output = apply_filters('post_playlist', '', $attr);
    if ($output != '') {
        return $output;
    }
    /*
     * We're trusting author input, so let's at least make sure it looks
     * like a valid orderby statement.
     */
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }
    $atts = shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist');
    $id = intval($atts['id']);
    $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $atts['type'], 'order' => $atts['order'], 'orderby' => $atts['orderby']);
    if (!empty($atts['include'])) {
        $args['include'] = $atts['include'];
        $_attachments = get_posts($args);
        $attachments = array();
        foreach ($_attachments as $key => $val) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif (!empty($atts['exclude'])) {
        $args['post_parent'] = $id;
        $args['exclude'] = $atts['exclude'];
        $attachments = get_children($args);
    } else {
        $args['post_parent'] = $id;
        $attachments = get_children($args);
    }
    if (empty($attachments)) {
        return '';
    }
    if (is_feed()) {
        $output = "\n";
        foreach ($attachments as $att_id => $attachment) {
            $output .= wp_get_attachment_link($att_id) . "\n";
        }
        return $output;
    }
    $outer = 22;
    // default padding and border of wrapper
    $default_width = 640;
    $default_height = 360;
    $theme_width = empty($content_width) ? $default_width : $content_width - $outer;
    $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width);
    $data = array('type' => $atts['type'], 'tracklist' => wp_validate_boolean($atts['tracklist']), 'tracknumbers' => wp_validate_boolean($atts['tracknumbers']), 'images' => wp_validate_boolean($atts['images']), 'artists' => wp_validate_boolean($atts['artists']));
    $tracks = array();
    foreach ($attachments as $attachment) {
        $url = wp_get_attachment_url($attachment->ID);
        $ftype = wp_check_filetype($url, wp_get_mime_types());
        $track = array('src' => $url, 'type' => $ftype['type'], 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content);
        $track['meta'] = array();
        $meta = wp_get_attachment_metadata($attachment->ID);
        if (!empty($meta)) {
            foreach (wp_get_attachment_id3_keys($attachment) as $key => $label) {
                if (!empty($meta[$key])) {
                    $track['meta'][$key] = $meta[$key];
                }
            }
            if ('video' === $atts['type']) {
                if (!empty($meta['width']) && !empty($meta['height'])) {
                    $width = $meta['width'];
                    $height = $meta['height'];
                    $theme_height = round($height * $theme_width / $width);
                } else {
                    $width = $default_width;
                    $height = $default_height;
                }
                $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height));
            }
        }
        if ($atts['images']) {
            $thumb_id = get_post_thumbnail_id($attachment->ID);
            if (!empty($thumb_id)) {
                list($src, $width, $height) = wp_get_attachment_image_src($thumb_id, 'full');
                $track['image'] = compact('src', 'width', 'height');
                list($src, $width, $height) = wp_get_attachment_image_src($thumb_id, 'thumbnail');
                $track['thumb'] = compact('src', 'width', 'height');
            } else {
                $src = wp_mime_type_icon($attachment->ID);
                $width = 48;
                $height = 64;
                $track['image'] = compact('src', 'width', 'height');
                $track['thumb'] = compact('src', 'width', 'height');
            }
        }
        $tracks[] = $track;
    }
    $data['tracks'] = $tracks;
    $safe_type = esc_attr($atts['type']);
    $safe_style = esc_attr($atts['style']);
    ob_start();
    if (1 === $instance) {
        /**
         * Print and enqueue playlist scripts, styles, and JavaScript templates.
         *
         * @since 3.9.0
         *
         * @param string $type  Type of playlist. Possible values are 'audio' or 'video'.
         * @param string $style The 'theme' for the playlist. Core provides 'light' and 'dark'.
         */
        do_action('wp_playlist_scripts', $atts['type'], $atts['style']);
    }
    ?>
<div class="wp-playlist wp-<?php 
    echo $safe_type;
    ?>
-playlist wp-playlist-<?php 
    echo $safe_style;
    ?>
">
	<?php 
    if ('audio' === $atts['type']) {
        ?>
	<div class="wp-playlist-current-item"></div>
	<?php 
    }
    ?>
	<<?php 
    echo $safe_type;
    ?>
 controls="controls" preload="none" width="<?php 
    echo (int) $theme_width;
    ?>
"<?php 
    if ('video' === $safe_type) {
        echo ' height="', (int) $theme_height, '"';
    } else {
        echo ' style="visibility: hidden"';
    }
    ?>
></<?php 
    echo $safe_type;
    ?>
>
	<div class="wp-playlist-next"></div>
	<div class="wp-playlist-prev"></div>
	<noscript>
	<ol><?php 
    foreach ($attachments as $att_id => $attachment) {
        printf('<li>%s</li>', wp_get_attachment_link($att_id));
    }
    ?>
</ol>
	</noscript>
	<script type="application/json" class="wp-playlist-script"><?php 
    echo json_encode($data);
    ?>
</script>
</div>
	<?php 
    return ob_get_clean();
}
/**
 * Outputs the first embedded item in the activity oEmbed template.
 *
 * @since 2.6.0
 */
function bp_activity_embed_media()
{
    // Bail if oEmbed request explicitly hides media.
    if (isset($_GET['hide_media']) && true == wp_validate_boolean($_GET['hide_media'])) {
        /**
         * Do something after media is rendered for an activity oEmbed item.
         *
         * @since 2.6.0
         */
        do_action('bp_activity_embed_after_media');
        return;
    }
    /**
     * Should we display media in the oEmbed template?
     *
     * @since 2.6.0
     *
     * @param bool $retval Defaults to true.
     */
    $allow_media = apply_filters('bp_activity_embed_display_media', true);
    // Find oEmbeds from only WP registered providers.
    bp_remove_all_filters('oembed_providers');
    $media = bp_core_extract_media_from_content($GLOBALS['activities_template']->activity->content, 'embeds');
    bp_restore_all_filters('oembed_providers');
    // oEmbeds have precedence over inline video / audio.
    if (isset($media['embeds']) && true === $allow_media) {
        // Autoembed first URL.
        $oembed_defaults = wp_embed_defaults();
        $oembed_args = array('width' => $oembed_defaults['width'], 'height' => $oembed_defaults['height'], 'discover' => true);
        $url = $media['embeds'][0]['url'];
        $cachekey = '_oembed_response_' . md5($url . serialize($oembed_args));
        // Try to fetch oEmbed response from meta.
        $oembed = bp_activity_get_meta(bp_get_activity_id(), $cachekey);
        // No cache, so fetch full oEmbed response now!
        if ('' === $oembed) {
            $o = _wp_oembed_get_object();
            $oembed = $o->fetch($o->get_provider($url, $oembed_args), $url, $oembed_args);
            // Cache oEmbed response.
            bp_activity_update_meta(bp_get_activity_id(), $cachekey, $oembed);
        }
        $content = '';
        /**
         * Filters the default embed display max width.
         *
         * This is used if the oEmbed response does not return a thumbnail width.
         *
         * @since 2.6.0
         *
         * @param int $width.
         */
        $width = (int) apply_filters('bp_activity_embed_display_media_width', 550);
        // Set thumbnail.
        if ('photo' === $oembed->type) {
            $thumbnail = $oembed->url;
        } elseif (isset($oembed->thumbnail_url)) {
            $thumbnail = $oembed->thumbnail_url;
            /* Non-oEmbed standard attributes */
            // Mixcloud
        } elseif (isset($oembed->image)) {
            $thumbnail = $oembed->image;
            // ReverbNation
        } elseif (isset($oembed->{'thumbnail-url'})) {
            $thumbnail = $oembed->{'thumbnail-url'};
        }
        // Display thumb and related oEmbed meta.
        if (true === isset($thumbnail)) {
            $play_icon = $caption = '';
            // Add play icon for non-photos.
            if ('photo' !== $oembed->type) {
                /**
                 * ion-play icon from Ionicons.
                 *
                 * @link    http://ionicons.com/
                 * @license MIT
                 */
                $play_icon = <<<EOD
<svg id="Layer_1" style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M405.2,232.9L126.8,67.2c-3.4-2-6.9-3.2-10.9-3.2c-10.9,0-19.8,9-19.8,20H96v344h0.1c0,11,8.9,20,19.8,20  c4.1,0,7.5-1.4,11.2-3.4l278.1-165.5c6.6-5.5,10.8-13.8,10.8-23.1C416,246.7,411.8,238.5,405.2,232.9z"/></svg>
EOD;
                $play_icon = sprintf('<a rel="nofollow" class="play-btn" href="%1$s" onclick="top.location.href=\'%1$s\'">%2$s</a>', esc_url($url), $play_icon);
            }
            // Thumb width
            $thumb_width = isset($oembed->thumbnail_width) && 'photo' !== $oembed->type && (int) $oembed->thumbnail_width < 550 ? (int) $oembed->thumbnail_width : $width;
            $float_width = 350;
            // Set up thumb.
            $content = sprintf('<div class="thumb" style="max-width:%1$spx">%2$s<a href="%3$s" rel="nofollow" onclick="top.location.href=\'%3$s\'"><img src="%4$s" /></a></div>', $thumb_width, $play_icon, esc_url($url), esc_url($thumbnail));
            // Show title.
            if (isset($oembed->title)) {
                $caption .= sprintf('<p class="caption-title"><strong>%s</strong></p>', apply_filters('single_post_title', $oembed->title));
            }
            // Show description (non-oEmbed standard)
            if (isset($oembed->description)) {
                $caption .= sprintf('<div class="caption-description">%s</div>', apply_filters('bp_activity_get_embed_excerpt', $oembed->description));
            }
            // Show author info.
            if (isset($oembed->provider_name) && isset($oembed->author_name)) {
                /* translators: By [oEmbed author] on [oEmbed provider]. eg. By BuddyPress on YouTube. */
                $anchor_text = sprintf(__('By %1$s on %2$s', 'buddypress'), $oembed->author_name, $oembed->provider_name);
            } elseif (isset($oembed->provider_name)) {
                $anchor_text = sprintf(__('View on %s', 'buddypress'), $oembed->provider_name);
            }
            if (true === isset($anchor_text)) {
                $caption .= sprintf('<a rel="nofollow" href="%1$s" onclick="top.location.href=\'%1$s\'">%2$s</a>', esc_url($url), apply_filters('the_title', $anchor_text));
            }
            // Set up caption.
            if ('' !== $caption) {
                $css_class = isset($oembed->provider_name) ? sprintf(' provider-%s', sanitize_html_class(strtolower($oembed->provider_name))) : '';
                $caption = sprintf('<div class="caption%1$s" style="width:%2$s">%3$s</div>', $css_class, $thumb_width > $float_width ? 100 . '%' : round(($width - (int) $thumb_width) / $width * 100) . '%', $caption);
                $content .= $caption;
            }
        }
        // Print rich content.
        if ('' !== $content) {
            printf('<div class="bp-activity-embed-display-media %s" style="max-width:%spx">%s</div>', $thumb_width < $float_width ? 'two-col' : 'one-col', $thumb_width < $float_width ? $width : $thumb_width, $content);
        }
        // Video / audio.
    } elseif (true === $allow_media) {
        // Call BP_Embed if it hasn't already loaded.
        bp_embed_init();
        // Run shortcode and embed routine.
        $content = buddypress()->embed->run_shortcode($GLOBALS['activities_template']->activity->content);
        $content = buddypress()->embed->autoembed($content);
        // Try to find inline video / audio.
        $media = bp_core_extract_media_from_content($content, 96);
        // Video takes precedence. HTML5-only.
        if (isset($media['videos']) && 'shortcodes' === $media['videos'][0]['source']) {
            printf('<video controls preload="metadata"><source src="%1$s"><p>%2$s</p></video>', esc_url($media['videos'][0]['url']), esc_html__('Your browser does not support HTML5 video', 'buddypress'));
            // No video? Try audio. HTML5-only.
        } elseif (isset($media['audio']) && 'shortcodes' === $media['audio'][0]['source']) {
            printf('<audio controls preload="metadata"><source src="%1$s"><p>%2$s</p></audio>', esc_url($media['audio'][0]['url']), esc_html__('Your browser does not support HTML5 audio', 'buddypress'));
        }
    }
    /** This hook is documented in /bp-activity/bp-activity-embeds.php */
    do_action('bp_activity_embed_after_media');
}
 /**
  * Encapsulate the logic for sticking a post
  * and determining if the user has permission to do so
  *
  * @since 4.3.0
  * @access private
  *
  * @param array $post_data
  * @param bool  $update
  * @return void|IXR_Error
  */
 private function _toggle_sticky($post_data, $update = false)
 {
     $post_type = get_post_type_object($post_data['post_type']);
     // Private and password-protected posts cannot be stickied.
     if ('private' === $post_data['post_status'] || !empty($post_data['post_password'])) {
         // Error if the client tried to stick the post, otherwise, silently unstick.
         if (!empty($post_data['sticky'])) {
             return new IXR_Error(401, __('Sorry, you cannot stick a private post.'));
         }
         if ($update) {
             unstick_post($post_data['ID']);
         }
     } elseif (isset($post_data['sticky'])) {
         if (!current_user_can($post_type->cap->edit_others_posts)) {
             return new IXR_Error(401, __('Sorry, you are not allowed to stick this post.'));
         }
         $sticky = wp_validate_boolean($post_data['sticky']);
         if ($sticky) {
             stick_post($post_data['ID']);
         } else {
             unstick_post($post_data['ID']);
         }
     }
 }
예제 #22
0
 /**
  * Rendering the Qiita side permalink of specified post
  *
  * @since 1.0.0
  *
  * @param array $attributes [required] Array of attributes in shortcode
  * @param string $content [optional] For default is empty
  * @return string $html_content The formatted content
  */
 public function get_qiita_link()
 {
     list($attributes, $content) = func_get_args();
     extract(shortcode_atts(array('pid' => null, 'iid' => null, 'html' => true, 'target' => '_self', 'class' => ''), $attributes));
     $shortcode_name = 'wpqt-permalink';
     $_post = null;
     if (!empty($pid) && intval($pid) > 0) {
         $_post = get_post(intval($pid));
     } else {
         if (!empty($iid)) {
             $_tmp = get_posts(array('post_type' => $this->domain_name, 'meta_key' => 'wpqt_item_id', 'meta_value' => $iid));
             $_post = $_tmp[0];
         } else {
             if (is_main_query()) {
                 $_post = get_post();
             }
         }
     }
     if (!empty($_post)) {
         $_qiita_url = get_post_meta($_post->ID, 'wpqt_origin_url', true);
         if (!empty($_qiita_url)) {
             if (wp_validate_boolean($html)) {
                 $content = empty($content) ? $_qiita_url : $content;
                 return sprintf('<a href="%s" target="%s" class="%s">%s</a>', esc_url($_qiita_url), esc_attr($target), esc_attr($class), esc_html($content));
             } else {
                 return $_qiita_url;
             }
         }
     }
     return '';
 }
예제 #23
0
/**
 * Builds the Video shortcode output.
 *
 * This implements the functionality of the Video Shortcode for displaying
 * WordPress mp4s in a post.
 *
 * @since 3.6.0
 *
 * @global int $content_width
 * @staticvar int $instance
 *
 * @param array  $attr {
 *     Attributes of the shortcode.
 *
 *     @type string $src      URL to the source of the video file. Default empty.
 *     @type int    $height   Height of the video embed in pixels. Default 360.
 *     @type int    $width    Width of the video embed in pixels. Default $content_width or 640.
 *     @type string $poster   The 'poster' attribute for the `<video>` element. Default empty.
 *     @type string $loop     The 'loop' attribute for the `<video>` element. Default empty.
 *     @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
 *     @type string $preload  The 'preload' attribute for the `<video>` element.
 *                            Default 'metadata'.
 *     @type string $class    The 'class' attribute for the `<video>` element.
 *                            Default 'wp-video-shortcode'.
 * }
 * @param string $content Shortcode content.
 * @return string|void HTML content to display video.
 */
function wp_video_shortcode($attr, $content = '')
{
    global $content_width;
    $post_id = get_post() ? get_the_ID() : 0;
    static $instance = 0;
    $instance++;
    /**
     * Filter the default video shortcode output.
     *
     * If the filtered output isn't empty, it will be used instead of generating
     * the default video template.
     *
     * @since 3.6.0
     *
     * @see wp_video_shortcode()
     *
     * @param string $html     Empty variable to be replaced with shortcode markup.
     * @param array  $attr     Attributes of the video shortcode.
     * @param string $content  Video shortcode content.
     * @param int    $instance Unique numeric ID of this video shortcode instance.
     */
    $override = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instance);
    if ('' !== $override) {
        return $override;
    }
    $video = null;
    $default_types = wp_get_video_extensions();
    $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360);
    foreach ($default_types as $type) {
        $defaults_atts[$type] = '';
    }
    $atts = shortcode_atts($defaults_atts, $attr, 'video');
    if (is_admin()) {
        // shrink the video so it isn't huge in the admin
        if ($atts['width'] > $defaults_atts['width']) {
            $atts['height'] = round($atts['height'] * $defaults_atts['width'] / $atts['width']);
            $atts['width'] = $defaults_atts['width'];
        }
    } else {
        // if the video is bigger than the theme
        if (!empty($content_width) && $atts['width'] > $content_width) {
            $atts['height'] = round($atts['height'] * $content_width / $atts['width']);
            $atts['width'] = $content_width;
        }
    }
    $is_vimeo = $is_youtube = false;
    $yt_pattern = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#';
    $vimeo_pattern = '#^https?://(.+\\.)?vimeo\\.com/.*#';
    $primary = false;
    if (!empty($atts['src'])) {
        $is_vimeo = preg_match($vimeo_pattern, $atts['src']);
        $is_youtube = preg_match($yt_pattern, $atts['src']);
        if (!$is_youtube && !$is_vimeo) {
            $type = wp_check_filetype($atts['src'], wp_get_mime_types());
            if (!in_array(strtolower($type['ext']), $default_types)) {
                return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src']));
            }
        }
        if ($is_vimeo) {
            wp_enqueue_script('froogaloop');
        }
        $primary = true;
        array_unshift($default_types, 'src');
    } else {
        foreach ($default_types as $ext) {
            if (!empty($atts[$ext])) {
                $type = wp_check_filetype($atts[$ext], wp_get_mime_types());
                if (strtolower($type['ext']) === $ext) {
                    $primary = true;
                }
            }
        }
    }
    if (!$primary) {
        $videos = get_attached_media('video', $post_id);
        if (empty($videos)) {
            return;
        }
        $video = reset($videos);
        $atts['src'] = wp_get_attachment_url($video->ID);
        if (empty($atts['src'])) {
            return;
        }
        array_unshift($default_types, 'src');
    }
    /**
     * Filter the media library used for the video shortcode.
     *
     * @since 3.6.0
     *
     * @param string $library Media library used for the video shortcode.
     */
    $library = apply_filters('wp_video_shortcode_library', 'mediaelement');
    if ('mediaelement' === $library && did_action('init')) {
        wp_enqueue_style('wp-mediaelement');
        wp_enqueue_script('wp-mediaelement');
    }
    /**
     * Filter the class attribute for the video shortcode output container.
     *
     * @since 3.6.0
     *
     * @param string $class CSS class or list of space-separated classes.
     */
    $html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instance), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload']);
    // These ones should just be omitted altogether if they are blank
    foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) {
        if (empty($html_atts[$a])) {
            unset($html_atts[$a]);
        }
    }
    $attr_strings = array();
    foreach ($html_atts as $k => $v) {
        $attr_strings[] = $k . '="' . esc_attr($v) . '"';
    }
    $html = '';
    if ('mediaelement' === $library && 1 === $instance) {
        $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
    }
    $html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings));
    $fileurl = '';
    $source = '<source type="%s" src="%s" />';
    foreach ($default_types as $fallback) {
        if (!empty($atts[$fallback])) {
            if (empty($fileurl)) {
                $fileurl = $atts[$fallback];
            }
            if ('src' === $fallback && $is_youtube) {
                $type = array('type' => 'video/youtube');
            } elseif ('src' === $fallback && $is_vimeo) {
                $type = array('type' => 'video/vimeo');
            } else {
                $type = wp_check_filetype($atts[$fallback], wp_get_mime_types());
            }
            $url = add_query_arg('_', $instance, $atts[$fallback]);
            $html .= sprintf($source, $type['type'], esc_url($url));
        }
    }
    if (!empty($content)) {
        if (false !== strpos($content, "\n")) {
            $content = str_replace(array("\r\n", "\n", "\t"), '', $content);
        }
        $html .= trim($content);
    }
    if ('mediaelement' === $library) {
        $html .= wp_mediaelement_fallback($fileurl);
    }
    $html .= '</video>';
    $width_rule = '';
    if (!empty($atts['width'])) {
        $width_rule = sprintf('width: %dpx; ', $atts['width']);
    }
    $output = sprintf('<div style="%s" class="wp-video">%s</div>', $width_rule, $html);
    /**
     * Filter the output of the video shortcode.
     *
     * @since 3.6.0
     *
     * @param string $output  Video shortcode HTML output.
     * @param array  $atts    Array of video shortcode attributes.
     * @param string $video   Video file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the video shortcode.
     */
    return apply_filters('wp_video_shortcode', $output, $atts, $video, $post_id, $library);
}
예제 #24
0
파일: widgets.php 프로젝트: ka215/wp-qiita
        public function form($instance)
        {
            // Create setting fields in widget menu
            foreach ($this->fields as $_name => $_label) {
                $_field_id = isset($instance[$_name]) ? $this->get_field_id($_name) : '';
                $_field_name = isset($instance[$_name]) ? $this->get_field_name($_name) : '';
                switch ($_name) {
                    case 'title':
                    case 'display_title':
                        ${$_name} = isset($instance[$_name]) ? esc_attr($instance[$_name]) : '';
                        ?>
<p>
  <label for="<?php 
                        echo $_field_id;
                        ?>
"><?php 
                        echo $_label;
                        ?>
:</label>
  <input class="widefat" id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
" type="text" value="<?php 
                        echo ${$_name};
                        ?>
">
</p>
<?php 
                        break;
                    case 'display_limit':
                        ${$_name} = isset($instance[$_name]) && !empty($instance[$_name]) && intval($instance[$_name]) > 0 ? esc_attr($instance[$_name]) : 5;
                        ?>
<p>
  <label for="<?php 
                        echo $_field_id;
                        ?>
"><?php 
                        echo $_label;
                        ?>
:</label>
  <input id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
" type="number" value="<?php 
                        echo ${$_name};
                        ?>
" style="text-align: center; width: 5em;">
</p>
<?php 
                        break;
                    case 'display_state':
                        ${$_name} = isset($instance[$_name]) && !empty($instance[$_name]) && in_array($instance[$_name], array('publish', 'publish+private')) ? esc_attr($instance[$_name]) : 'publish';
                        ?>
<p>
  <label for="<?php 
                        echo $_field_id;
                        ?>
"><?php 
                        echo $_label;
                        ?>
:</label>
  <select id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
">
    <option value="publish"<?php 
                        if ('publish' === ${$_name}) {
                            ?>
 selected="selected"<?php 
                        }
                        ?>
><?php 
                        _e('Publish Only', WPQT);
                        ?>
</option>
    <option value="publish+private"<?php 
                        if ('publish+private' === ${$_name}) {
                            ?>
 selected="selected"<?php 
                        }
                        ?>
><?php 
                        _e('Publish and Private', WPQT);
                        ?>
</option>
  </select>
</p>
<?php 
                        break;
                    case 'sort_by':
                        $candidates = array('date' => __('Created Date', WPQT), 'modified' => __('Modified Date', WPQT), 'comment_count' => __('Comment Count', WPQT), 'stocks' => __('Stocks', WPQT), 'rand' => __('Random', WPQT));
                        unset($candidates['comment_count']);
                        ${$_name} = isset($instance[$_name]) && !empty($instance[$_name]) && in_array($instance[$_name], array_keys($candidates)) ? esc_attr($instance[$_name]) : 'date';
                        ?>
<p>
  <label for="<?php 
                        echo $_field_id;
                        ?>
"><?php 
                        echo $_label;
                        ?>
:</label>
  <select id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
">
  <?php 
                        foreach ($candidates as $_key => $_label) {
                            ?>
    <option value="<?php 
                            echo $_key;
                            ?>
"<?php 
                            if ($_key === ${$_name}) {
                                ?>
 selected="selected"<?php 
                            }
                            ?>
><?php 
                            echo $_label;
                            ?>
</option>
  <?php 
                        }
                        ?>
  </select>
</p>
<?php 
                        break;
                    case 'sort_order':
                        ${$_name} = isset($instance[$_name]) && !empty($instance[$_name]) && in_array($instance[$_name], array('DESC', 'ASC')) ? esc_attr($instance[$_name]) : 'DESC';
                        ?>
<p>
  <label for="<?php 
                        echo $_field_id;
                        ?>
"><?php 
                        echo $_label;
                        ?>
:</label>
  <select id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
">
    <option value="DESC"<?php 
                        if ('DESC' === ${$_name}) {
                            ?>
 selected="selected"<?php 
                        }
                        ?>
><?php 
                        _e('DESC', WPQT);
                        ?>
</option>
    <option value="ASC"<?php 
                        if ('ASC' === ${$_name}) {
                            ?>
 selected="selected"<?php 
                        }
                        ?>
><?php 
                        _e('ASC', WPQT);
                        ?>
</option>
  </select>
</p>
<?php 
                        break;
                    case 'show_stocks':
                        ${$_name} = isset($instance[$_name]) ? wp_validate_boolean($instance[$_name]) : false;
                        ?>
<p>
  <label>
    <input type="checkbox" id="<?php 
                        echo $_field_id;
                        ?>
" name="<?php 
                        echo $_field_name;
                        ?>
" value="1" <?php 
                        checked(${$_name}, true);
                        ?>
> <?php 
                        echo $_label;
                        ?>
  </label>
</p>
<?php 
                        break;
                    default:
                        break;
                }
            }
        }
/**
 * Retrieve term parents with separator.
 *
 * @since 4.8.0
 *
 * @param int     $term_id  Term ID.
 * @param string  $taxonomy Taxonomy name.
 * @param string|array $args {
 *     Array of optional arguments.
 *
 *     @type string $format    Use term names or slugs for display. Accepts 'name' or 'slug'.
 *                             Default 'name'.
 *     @type string $separator Separator for between the terms. Default '/'.
 *     @type bool   $link      Whether to format as a link. Default true.
 *     @type bool   $inclusive Include the term to get the parents for. Default true.
 * }
 * @return string|WP_Error A list of term parents on success, WP_Error or empty string on failure.
 */
function get_term_parents_list($term_id, $taxonomy, $args = array())
{
    $list = '';
    $term = get_term($term_id, $taxonomy);
    if (is_wp_error($term)) {
        return $term;
    }
    if (!$term) {
        return $list;
    }
    $term_id = $term->term_id;
    $defaults = array('format' => 'name', 'separator' => '/', 'link' => true, 'inclusive' => true);
    $args = wp_parse_args($args, $defaults);
    foreach (array('link', 'inclusive') as $bool) {
        $args[$bool] = wp_validate_boolean($args[$bool]);
    }
    $parents = get_ancestors($term_id, $taxonomy, 'taxonomy');
    if ($args['inclusive']) {
        array_unshift($parents, $term_id);
    }
    foreach (array_reverse($parents) as $term_id) {
        $parent = get_term($term_id, $taxonomy);
        $name = 'slug' === $args['format'] ? $parent->slug : $parent->name;
        if ($args['link']) {
            $list .= '<a href="' . esc_url(get_term_link($parent->term_id, $taxonomy)) . '">' . $name . '</a>' . $args['separator'];
        } else {
            $list .= $name . $args['separator'];
        }
    }
    return $list;
}
예제 #26
0
/**
 * give notice on edited terms
 *
 * @since 1.0
 *
*/
function stt2extat_edit_term_notice($code, $error, $add_setting_error)
{
    if (isset($_GET['term_ID']) && '' == stt2extat_get_post_terms(absint($_GET['post_ID']))) {
        return;
    }
    if (false == $code) {
        $code = 5;
    }
    $code = absint($code);
    $messages['searchterms'] = array(0 => '', 1 => __('Term added.'), 2 => __('Term deleted.'), 3 => __('Term updated.'), 4 => __('Term not added.'), 5 => __('Term not updated.'), 6 => __('Term empty.', 'stt2extat'), 7 => __('Term was exists.', 'stt2extat'), 8 => __('Terms deleted.'), 9 => __('You do not have permission to do that.'), 10 => __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?.'), 11 => __('Term was deleted.'), 12 => __('Term too short ( min 4 characters ).', 'stt2extat'), 13 => __('Term too long ( max 70 characters ).', 'stt2extat'), 14 => __('An unidentified error has occurred.', 'stt2extat'), 15 => __('Terms migrated.', 'stt2extat'));
    if (wp_validate_boolean($add_setting_error)) {
        if (isset($messages['searchterms'][$code])) {
            return $messages['searchterms'][$code];
        }
        return $messages['searchterms'][1];
    }
    $class = 'updated';
    if (wp_validate_boolean($error)) {
        $class = 'error';
    }
    printf('<div id="message" class="%1$s notice is-dismissible"><p>%2$s</p><button type="button" class="notice-dismiss"><span class="screen-reader-text">%3$s.</span></button></div>', sanitize_html_class($class), esc_html($messages['searchterms'][$code]), __('Dismiss this notice', 'stt2extat'));
    if (defined('DOING_AJAX') && DOING_AJAX) {
        wp_die();
    }
}