コード例 #1
0
ファイル: media.php プロジェクト: nxtclass/NXTClass
/**
 * {@internal Missing Short Description}}
 *
 * @since 2.5.0
 *
 * @param unknown_type $post
 * @param unknown_type $errors
 * @return unknown
 */
function get_attachment_fields_to_edit($post, $errors = null)
{
    if (is_int($post)) {
        $post =& get_post($post);
    }
    if (is_array($post)) {
        $post = (object) $post;
    }
    $image_url = nxt_get_attachment_url($post->ID);
    $edit_post = sanitize_post($post, 'edit');
    $form_fields = array('post_title' => array('label' => __('Title'), 'value' => $edit_post->post_title), 'image_alt' => array(), 'post_excerpt' => array('label' => __('Caption'), 'value' => $edit_post->post_excerpt), 'post_content' => array('label' => __('Description'), 'value' => $edit_post->post_content, 'input' => 'textarea'), 'url' => array('label' => __('Link URL'), 'input' => 'html', 'html' => image_link_input_fields($post, get_option('image_default_link_type')), 'helps' => __('Enter a link URL or click above for presets.')), 'menu_order' => array('label' => __('Order'), 'value' => $edit_post->menu_order), 'image_url' => array('label' => __('File URL'), 'input' => 'html', 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[{$post->ID}][url]' value='" . esc_attr($image_url) . "' /><br />", 'value' => nxt_get_attachment_url($post->ID), 'helps' => __('Location of the uploaded file.')));
    foreach (get_attachment_taxonomies($post) as $taxonomy) {
        $t = (array) get_taxonomy($taxonomy);
        if (!$t['public']) {
            continue;
        }
        if (empty($t['label'])) {
            $t['label'] = $taxonomy;
        }
        if (empty($t['args'])) {
            $t['args'] = array();
        }
        $terms = get_object_term_cache($post->ID, $taxonomy);
        if (empty($terms)) {
            $terms = nxt_get_object_terms($post->ID, $taxonomy, $t['args']);
        }
        $values = array();
        foreach ($terms as $term) {
            $values[] = $term->name;
        }
        $t['value'] = join(', ', $values);
        $form_fields[$taxonomy] = $t;
    }
    // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
    // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
    $form_fields = array_merge_recursive($form_fields, (array) $errors);
    $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
    return $form_fields;
}
コード例 #2
0
ファイル: post.php プロジェクト: nxtclass/NXTClass
/**
 * Retrieve URL for an attachment thumbnail.
 *
 * @since 2.1.0
 *
 * @param int $post_id Attachment ID
 * @return string|bool False on failure. Thumbnail URL on success.
 */
function nxt_get_attachment_thumb_url($post_id = 0)
{
    $post_id = (int) $post_id;
    if (!($post =& get_post($post_id))) {
        return false;
    }
    if (!($url = nxt_get_attachment_url($post->ID))) {
        return false;
    }
    $sized = image_downsize($post_id, 'thumbnail');
    if ($sized) {
        return $sized[0];
    }
    if (!($thumb = nxt_get_attachment_thumb_file($post->ID))) {
        return false;
    }
    $url = str_replace(basename($url), basename($thumb), $url);
    return apply_filters('nxt_get_attachment_thumb_url', $url, $post->ID);
}
コード例 #3
0
ファイル: media.php プロジェクト: nxtclass/NXTClass
/**
 * Retrieve the image's intermediate size (resized) path, width, and height.
 *
 * The $size parameter can be an array with the width and height respectively.
 * If the size matches the 'sizes' metadata array for width and height, then it
 * will be used. If there is no direct match, then the nearest image size larger
 * than the specified size will be used. If nothing is found, then the function
 * will break out and return false.
 *
 * The metadata 'sizes' is used for compatible sizes that can be used for the
 * parameter $size value.
 *
 * The url path will be given, when the $size parameter is a string.
 *
 * If you are passing an array for the $size, you should consider using
 * add_image_size() so that a cropped version is generated. It's much more
 * efficient than having to find the closest-sized image and then having the
 * browser scale down the image.
 *
 * @since 2.5.0
 * @see add_image_size()
 *
 * @param int $post_id Attachment ID for image.
 * @param array|string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @return bool|array False on failure or array of file path, width, and height on success.
 */
function image_get_intermediate_size($post_id, $size = 'thumbnail')
{
    if (!is_array($imagedata = nxt_get_attachment_metadata($post_id))) {
        return false;
    }
    // get the best one for a specified set of dimensions
    if (is_array($size) && !empty($imagedata['sizes'])) {
        foreach ($imagedata['sizes'] as $_size => $data) {
            // already cropped to width or height; so use this size
            if ($data['width'] == $size[0] && $data['height'] <= $size[1] || $data['height'] == $size[1] && $data['width'] <= $size[0]) {
                $file = $data['file'];
                list($width, $height) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                return compact('file', 'width', 'height');
            }
            // add to lookup table: area => size
            $areas[$data['width'] * $data['height']] = $_size;
        }
        if (!$size || !empty($areas)) {
            // find for the smallest image not smaller than the desired size
            ksort($areas);
            foreach ($areas as $_size) {
                $data = $imagedata['sizes'][$_size];
                if ($data['width'] >= $size[0] || $data['height'] >= $size[1]) {
                    // Skip images with unexpectedly divergent aspect ratios (crops)
                    // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
                    $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false);
                    // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
                    if ('thumbnail' != $_size && (!$maybe_cropped || $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] || $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'])) {
                        continue;
                    }
                    // If we're still here, then we're going to use this size
                    $file = $data['file'];
                    list($width, $height) = image_constrain_size_for_editor($data['width'], $data['height'], $size);
                    return compact('file', 'width', 'height');
                }
            }
        }
    }
    if (is_array($size) || empty($size) || empty($imagedata['sizes'][$size])) {
        return false;
    }
    $data = $imagedata['sizes'][$size];
    // include the full filesystem path of the intermediate file
    if (empty($data['path']) && !empty($data['file'])) {
        $file_url = nxt_get_attachment_url($post_id);
        $data['path'] = path_join(dirname($imagedata['file']), $data['file']);
        $data['url'] = path_join(dirname($file_url), $data['file']);
    }
    return $data;
}
コード例 #4
0
ファイル: attachment.php プロジェクト: nxtclass/NXTClass
								<div class="entry-caption"><?php 
        if (!empty($post->post_excerpt)) {
            the_excerpt();
        }
        ?>
</div>
								<?php 
        the_content();
        ?>
							</div>

							<p class="postmetadata">
								<?php 
        if (nxt_attachment_is_image()) {
            $metadata = nxt_get_attachment_metadata();
            printf(__('Full size is %s pixels', 'buddypress'), sprintf('<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>', nxt_get_attachment_url(), esc_attr(__('Link to full size image', 'buddypress')), $metadata['width'], $metadata['height']));
        }
        ?>
								&nbsp;
							</p>
						</div>

					</div>

					<?php 
        do_action('bp_after_blog_post');
        ?>

					<?php 
        comments_template();
        ?>
コード例 #5
0
 /**
  * Retrieve a media item by ID
  *
  * @since 3.1.0
  *
  * @param array $args Method parameters. Contains:
  *  - blog_id
  *  - username
  *  - password
  *  - attachment_id
  * @return array. Associative array containing:
  *  - 'date_created_gmt'
  *  - 'parent'
  *  - 'link'
  *  - 'thumbnail'
  *  - 'title'
  *  - 'caption'
  *  - 'description'
  *  - 'metadata'
  */
 function nxt_getMediaItem($args)
 {
     $this->escape($args);
     $blog_id = (int) $args[0];
     $username = $args[1];
     $password = $args[2];
     $attachment_id = (int) $args[3];
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     if (!current_user_can('upload_files')) {
         return new IXR_Error(403, __('You are not allowed to upload files to this site.'));
     }
     do_action('xmlrpc_call', 'nxt.getMediaItem');
     if (!($attachment = get_post($attachment_id))) {
         return new IXR_Error(404, __('Invalid attachment ID.'));
     }
     // Format page date.
     $attachment_date = mysql2date('Ymd\\TH:i:s', $attachment->post_date, false);
     $attachment_date_gmt = mysql2date('Ymd\\TH:i:s', $attachment->post_date_gmt, false);
     $link = nxt_get_attachment_url($attachment->ID);
     $thumbnail_link = nxt_get_attachment_thumb_url($attachment->ID);
     $attachment_struct = array('date_created_gmt' => new IXR_Date($attachment_date_gmt), 'parent' => $attachment->post_parent, 'link' => $link, 'thumbnail' => $thumbnail_link, 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'metadata' => nxt_get_attachment_metadata($attachment->ID));
     return $attachment_struct;
 }
コード例 #6
0
ファイル: post-template.php プロジェクト: nxtclass/NXTClass
/**
 * Retrieve an attachment page link using an image or icon, if possible.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'nxt_get_attachment_link' filter on HTML content with same parameters as function.
 *
 * @param int $id Optional. Post ID.
 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
 * @param bool $icon Optional, default is false. Whether to include icon.
 * @param string $text Optional, default is false. If string, then will be link text.
 * @return string HTML content.
 */
function nxt_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false)
{
    $id = intval($id);
    $_post =& get_post($id);
    if (empty($_post) || 'attachment' != $_post->post_type || !($url = nxt_get_attachment_url($_post->ID))) {
        return __('Missing Attachment');
    }
    if ($permalink) {
        $url = get_attachment_link($_post->ID);
    }
    $post_title = esc_attr($_post->post_title);
    if ($text) {
        $link_text = esc_attr($text);
    } elseif ($size && 'none' != $size) {
        $link_text = nxt_get_attachment_image($id, $size, $icon);
    } else {
        $link_text = '';
    }
    if (trim($link_text) == '') {
        $link_text = $_post->post_title;
    }
    return apply_filters('nxt_get_attachment_link', "<a href='{$url}' title='{$post_title}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text);
}
コード例 #7
0
ファイル: theme.php プロジェクト: nxtclass/NXTClass
/**
 * Checks an attachment being deleted to see if it's a header or background image.
 *
 * If true it removes the theme modification which would be pointing at the deleted
 * attachment
 *
 * @access private
 * @since 3.0.0
 * @param int $id the attachment id
 */
function _delete_attachment_theme_mod($id)
{
    $attachment_image = nxt_get_attachment_url($id);
    $header_image = get_header_image();
    $background_image = get_background_image();
    if ($header_image && $header_image == $attachment_image) {
        remove_theme_mod('header_image');
    }
    if ($background_image && $background_image == $attachment_image) {
        remove_theme_mod('background_image');
    }
}
コード例 #8
0
ファイル: export.php プロジェクト: nxtclass/NXTClass
/**
 * Generates the WXR export file for download
 *
 * @since 2.1.0
 *
 * @param array $args Filters defining what should be included in the export
 */
function export_nxt($args = array())
{
    global $nxtdb, $post;
    $defaults = array('content' => 'all', 'author' => false, 'category' => false, 'start_date' => false, 'end_date' => false, 'status' => false);
    $args = nxt_parse_args($args, $defaults);
    do_action('export_nxt');
    $sitename = sanitize_key(get_bloginfo('name'));
    if (!empty($sitename)) {
        $sitename .= '.';
    }
    $filename = $sitename . 'nxtclass.' . date('Y-m-d') . '.xml';
    header('Content-Description: File Transfer');
    header('Content-Disposition: attachment; filename=' . $filename);
    header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    if ('all' != $args['content'] && post_type_exists($args['content'])) {
        $ptype = get_post_type_object($args['content']);
        if (!$ptype->can_export) {
            $args['content'] = 'post';
        }
        $where = $nxtdb->prepare("{$nxtdb->posts}.post_type = %s", $args['content']);
    } else {
        $post_types = get_post_types(array('can_export' => true));
        $esses = array_fill(0, count($post_types), '%s');
        $where = $nxtdb->prepare("{$nxtdb->posts}.post_type IN (" . implode(',', $esses) . ')', $post_types);
    }
    if ($args['status'] && ('post' == $args['content'] || 'page' == $args['content'])) {
        $where .= $nxtdb->prepare(" AND {$nxtdb->posts}.post_status = %s", $args['status']);
    } else {
        $where .= " AND {$nxtdb->posts}.post_status != 'auto-draft'";
    }
    $join = '';
    if ($args['category'] && 'post' == $args['content']) {
        if ($term = term_exists($args['category'], 'category')) {
            $join = "INNER JOIN {$nxtdb->term_relationships} ON ({$nxtdb->posts}.ID = {$nxtdb->term_relationships}.object_id)";
            $where .= $nxtdb->prepare(" AND {$nxtdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id']);
        }
    }
    if ('post' == $args['content'] || 'page' == $args['content']) {
        if ($args['author']) {
            $where .= $nxtdb->prepare(" AND {$nxtdb->posts}.post_author = %d", $args['author']);
        }
        if ($args['start_date']) {
            $where .= $nxtdb->prepare(" AND {$nxtdb->posts}.post_date >= %s", date('Y-m-d', strtotime($args['start_date'])));
        }
        if ($args['end_date']) {
            $where .= $nxtdb->prepare(" AND {$nxtdb->posts}.post_date < %s", date('Y-m-d', strtotime('+1 month', strtotime($args['end_date']))));
        }
    }
    // grab a snapshot of post IDs, just in case it changes during the export
    $post_ids = $nxtdb->get_col("SELECT ID FROM {$nxtdb->posts} {$join} WHERE {$where}");
    // get the requested terms ready, empty unless posts filtered by category or all content
    $cats = $tags = $terms = array();
    if (isset($term) && $term) {
        $cat = get_term($term['term_id'], 'category');
        $cats = array($cat->term_id => $cat);
        unset($term, $cat);
    } else {
        if ('all' == $args['content']) {
            $categories = (array) get_categories(array('get' => 'all'));
            $tags = (array) get_tags(array('get' => 'all'));
            $custom_taxonomies = get_taxonomies(array('_builtin' => false));
            $custom_terms = (array) get_terms($custom_taxonomies, array('get' => 'all'));
            // put categories in order with no child going before its parent
            while ($cat = array_shift($categories)) {
                if ($cat->parent == 0 || isset($cats[$cat->parent])) {
                    $cats[$cat->term_id] = $cat;
                } else {
                    $categories[] = $cat;
                }
            }
            // put terms in order with no child going before its parent
            while ($t = array_shift($custom_terms)) {
                if ($t->parent == 0 || isset($terms[$t->parent])) {
                    $terms[$t->term_id] = $t;
                } else {
                    $custom_terms[] = $t;
                }
            }
            unset($categories, $custom_taxonomies, $custom_terms);
        }
    }
    /**
     * Wrap given string in XML CDATA tag.
     *
     * @since 2.1.0
     *
     * @param string $str String to wrap in XML CDATA tag.
     */
    function wxr_cdata($str)
    {
        if (seems_utf8($str) == false) {
            $str = utf8_encode($str);
        }
        // $str = ent2ncr(esc_html($str));
        $str = "<![CDATA[{$str}" . (substr($str, -1) == ']' ? ' ' : '') . ']]>';
        return $str;
    }
    /**
     * Return the URL of the site
     *
     * @since 2.5.0
     *
     * @return string Site URL.
     */
    function wxr_site_url()
    {
        // ms: the base url
        if (is_multisite()) {
            return network_home_url();
        } else {
            return get_bloginfo_rss('url');
        }
    }
    /**
     * Output a cat_name XML tag from a given category object
     *
     * @since 2.1.0
     *
     * @param object $category Category Object
     */
    function wxr_cat_name($category)
    {
        if (empty($category->name)) {
            return;
        }
        echo '<nxt:cat_name>' . wxr_cdata($category->name) . '</nxt:cat_name>';
    }
    /**
     * Output a category_description XML tag from a given category object
     *
     * @since 2.1.0
     *
     * @param object $category Category Object
     */
    function wxr_category_description($category)
    {
        if (empty($category->description)) {
            return;
        }
        echo '<nxt:category_description>' . wxr_cdata($category->description) . '</nxt:category_description>';
    }
    /**
     * Output a tag_name XML tag from a given tag object
     *
     * @since 2.3.0
     *
     * @param object $tag Tag Object
     */
    function wxr_tag_name($tag)
    {
        if (empty($tag->name)) {
            return;
        }
        echo '<nxt:tag_name>' . wxr_cdata($tag->name) . '</nxt:tag_name>';
    }
    /**
     * Output a tag_description XML tag from a given tag object
     *
     * @since 2.3.0
     *
     * @param object $tag Tag Object
     */
    function wxr_tag_description($tag)
    {
        if (empty($tag->description)) {
            return;
        }
        echo '<nxt:tag_description>' . wxr_cdata($tag->description) . '</nxt:tag_description>';
    }
    /**
     * Output a term_name XML tag from a given term object
     *
     * @since 2.9.0
     *
     * @param object $term Term Object
     */
    function wxr_term_name($term)
    {
        if (empty($term->name)) {
            return;
        }
        echo '<nxt:term_name>' . wxr_cdata($term->name) . '</nxt:term_name>';
    }
    /**
     * Output a term_description XML tag from a given term object
     *
     * @since 2.9.0
     *
     * @param object $term Term Object
     */
    function wxr_term_description($term)
    {
        if (empty($term->description)) {
            return;
        }
        echo '<nxt:term_description>' . wxr_cdata($term->description) . '</nxt:term_description>';
    }
    /**
     * Output list of authors with posts
     *
     * @since 3.1.0
     */
    function wxr_authors_list()
    {
        global $nxtdb;
        $authors = array();
        $results = $nxtdb->get_results("SELECT DISTINCT post_author FROM {$nxtdb->posts}");
        foreach ((array) $results as $result) {
            $authors[] = get_userdata($result->post_author);
        }
        $authors = array_filter($authors);
        foreach ($authors as $author) {
            echo "\t<nxt:author>";
            echo '<nxt:author_id>' . $author->ID . '</nxt:author_id>';
            echo '<nxt:author_login>' . $author->user_login . '</nxt:author_login>';
            echo '<nxt:author_email>' . $author->user_email . '</nxt:author_email>';
            echo '<nxt:author_display_name>' . wxr_cdata($author->display_name) . '</nxt:author_display_name>';
            echo '<nxt:author_first_name>' . wxr_cdata($author->user_firstname) . '</nxt:author_first_name>';
            echo '<nxt:author_last_name>' . wxr_cdata($author->user_lastname) . '</nxt:author_last_name>';
            echo "</nxt:author>\n";
        }
    }
    /**
     * Ouput all navigation menu terms
     *
     * @since 3.1.0
     */
    function wxr_nav_menu_terms()
    {
        $nav_menus = nxt_get_nav_menus();
        if (empty($nav_menus) || !is_array($nav_menus)) {
            return;
        }
        foreach ($nav_menus as $menu) {
            echo "\t<nxt:term><nxt:term_id>{$menu->term_id}</nxt:term_id><nxt:term_taxonomy>nav_menu</nxt:term_taxonomy><nxt:term_slug>{$menu->slug}</nxt:term_slug>";
            wxr_term_name($menu);
            echo "</nxt:term>\n";
        }
    }
    /**
     * Output list of taxonomy terms, in XML tag format, associated with a post
     *
     * @since 2.3.0
     */
    function wxr_post_taxonomy()
    {
        global $post;
        $taxonomies = get_object_taxonomies($post->post_type);
        if (empty($taxonomies)) {
            return;
        }
        $terms = nxt_get_object_terms($post->ID, $taxonomies);
        foreach ((array) $terms as $term) {
            echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata($term->name) . "</category>\n";
        }
    }
    function wxr_filter_postmeta($return_me, $meta_key)
    {
        if ('_edit_lock' == $meta_key) {
            $return_me = true;
        }
        return $return_me;
    }
    add_filter('wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2);
    echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
    ?>
<!-- This is a NXTClass eXtended RSS file generated by NXTClass as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->

<!-- To import this information into a NXTClass site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the NXTClass admin panel. -->
<!-- 3. Install the "NXTClass" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!--    on the site. For each author, you may choose to map to an -->
<!--    existing user on the site or to create a new user. -->
<!-- 7. NXTClass will then import each of the posts, pages, comments, categories, etc. -->
<!--    contained in this file into your site. -->

<?php 
    the_generator('export');
    ?>
<rss version="2.0"
	xmlns:excerpt="http://nxtclass.org/export/<?php 
    echo WXR_VERSION;
    ?>
/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:nxt="http://nxtclass.org/export/<?php 
    echo WXR_VERSION;
    ?>
/"
>

<channel>
	<title><?php 
    bloginfo_rss('name');
    ?>
</title>
	<link><?php 
    bloginfo_rss('url');
    ?>
</link>
	<description><?php 
    bloginfo_rss('description');
    ?>
</description>
	<pubDate><?php 
    echo date('D, d M Y H:i:s +0000');
    ?>
</pubDate>
	<language><?php 
    echo get_option('rss_language');
    ?>
</language>
	<nxt:wxr_version><?php 
    echo WXR_VERSION;
    ?>
</nxt:wxr_version>
	<nxt:base_site_url><?php 
    echo wxr_site_url();
    ?>
</nxt:base_site_url>
	<nxt:base_blog_url><?php 
    bloginfo_rss('url');
    ?>
</nxt:base_blog_url>

<?php 
    wxr_authors_list();
    ?>

<?php 
    foreach ($cats as $c) {
        ?>
	<nxt:category><nxt:term_id><?php 
        echo $c->term_id;
        ?>
</nxt:term_id><nxt:category_nicename><?php 
        echo $c->slug;
        ?>
</nxt:category_nicename><nxt:category_parent><?php 
        echo $c->parent ? $cats[$c->parent]->slug : '';
        ?>
</nxt:category_parent><?php 
        wxr_cat_name($c);
        wxr_category_description($c);
        ?>
</nxt:category>
<?php 
    }
    foreach ($tags as $t) {
        ?>
	<nxt:tag><nxt:term_id><?php 
        echo $t->term_id;
        ?>
</nxt:term_id><nxt:tag_slug><?php 
        echo $t->slug;
        ?>
</nxt:tag_slug><?php 
        wxr_tag_name($t);
        wxr_tag_description($t);
        ?>
</nxt:tag>
<?php 
    }
    foreach ($terms as $t) {
        ?>
	<nxt:term><nxt:term_id><?php 
        echo $t->term_id;
        ?>
</nxt:term_id><nxt:term_taxonomy><?php 
        echo $t->taxonomy;
        ?>
</nxt:term_taxonomy><nxt:term_slug><?php 
        echo $t->slug;
        ?>
</nxt:term_slug><nxt:term_parent><?php 
        echo $t->parent ? $terms[$t->parent]->slug : '';
        ?>
</nxt:term_parent><?php 
        wxr_term_name($t);
        wxr_term_description($t);
        ?>
</nxt:term>
<?php 
    }
    if ('all' == $args['content']) {
        wxr_nav_menu_terms();
    }
    ?>

	<?php 
    do_action('rss2_head');
    ?>

<?php 
    if ($post_ids) {
        global $nxt_query;
        $nxt_query->in_the_loop = true;
        // Fake being in the loop.
        // fetch 20 posts at a time rather than loading the entire table into memory
        while ($next_posts = array_splice($post_ids, 0, 20)) {
            $where = 'WHERE ID IN (' . join(',', $next_posts) . ')';
            $posts = $nxtdb->get_results("SELECT * FROM {$nxtdb->posts} {$where}");
            // Begin Loop
            foreach ($posts as $post) {
                setup_postdata($post);
                $is_sticky = is_sticky($post->ID) ? 1 : 0;
                ?>
	<item>
		<title><?php 
                echo apply_filters('the_title_rss', $post->post_title);
                ?>
</title>
		<link><?php 
                the_permalink_rss();
                ?>
</link>
		<pubDate><?php 
                echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false);
                ?>
</pubDate>
		<dc:creator><?php 
                echo get_the_author_meta('login');
                ?>
</dc:creator>
		<guid isPermaLink="false"><?php 
                esc_url(the_guid());
                ?>
</guid>
		<description></description>
		<content:encoded><?php 
                echo wxr_cdata(apply_filters('the_content_export', $post->post_content));
                ?>
</content:encoded>
		<excerpt:encoded><?php 
                echo wxr_cdata(apply_filters('the_excerpt_export', $post->post_excerpt));
                ?>
</excerpt:encoded>
		<nxt:post_id><?php 
                echo $post->ID;
                ?>
</nxt:post_id>
		<nxt:post_date><?php 
                echo $post->post_date;
                ?>
</nxt:post_date>
		<nxt:post_date_gmt><?php 
                echo $post->post_date_gmt;
                ?>
</nxt:post_date_gmt>
		<nxt:comment_status><?php 
                echo $post->comment_status;
                ?>
</nxt:comment_status>
		<nxt:ping_status><?php 
                echo $post->ping_status;
                ?>
</nxt:ping_status>
		<nxt:post_name><?php 
                echo $post->post_name;
                ?>
</nxt:post_name>
		<nxt:status><?php 
                echo $post->post_status;
                ?>
</nxt:status>
		<nxt:post_parent><?php 
                echo $post->post_parent;
                ?>
</nxt:post_parent>
		<nxt:menu_order><?php 
                echo $post->menu_order;
                ?>
</nxt:menu_order>
		<nxt:post_type><?php 
                echo $post->post_type;
                ?>
</nxt:post_type>
		<nxt:post_password><?php 
                echo $post->post_password;
                ?>
</nxt:post_password>
		<nxt:is_sticky><?php 
                echo $is_sticky;
                ?>
</nxt:is_sticky>
<?php 
                if ($post->post_type == 'attachment') {
                    ?>
		<nxt:attachment_url><?php 
                    echo nxt_get_attachment_url($post->ID);
                    ?>
</nxt:attachment_url>
<?php 
                }
                wxr_post_taxonomy();
                $postmeta = $nxtdb->get_results($nxtdb->prepare("SELECT * FROM {$nxtdb->postmeta} WHERE post_id = %d", $post->ID));
                foreach ($postmeta as $meta) {
                    if (apply_filters('wxr_export_skip_postmeta', false, $meta->meta_key, $meta)) {
                        continue;
                    }
                    ?>
		<nxt:postmeta>
			<nxt:meta_key><?php 
                    echo $meta->meta_key;
                    ?>
</nxt:meta_key>
			<nxt:meta_value><?php 
                    echo wxr_cdata($meta->meta_value);
                    ?>
</nxt:meta_value>
		</nxt:postmeta>
<?php 
                }
                $comments = $nxtdb->get_results($nxtdb->prepare("SELECT * FROM {$nxtdb->comments} WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID));
                foreach ($comments as $c) {
                    ?>
		<nxt:comment>
			<nxt:comment_id><?php 
                    echo $c->comment_ID;
                    ?>
</nxt:comment_id>
			<nxt:comment_author><?php 
                    echo wxr_cdata($c->comment_author);
                    ?>
</nxt:comment_author>
			<nxt:comment_author_email><?php 
                    echo $c->comment_author_email;
                    ?>
</nxt:comment_author_email>
			<nxt:comment_author_url><?php 
                    echo esc_url_raw($c->comment_author_url);
                    ?>
</nxt:comment_author_url>
			<nxt:comment_author_IP><?php 
                    echo $c->comment_author_IP;
                    ?>
</nxt:comment_author_IP>
			<nxt:comment_date><?php 
                    echo $c->comment_date;
                    ?>
</nxt:comment_date>
			<nxt:comment_date_gmt><?php 
                    echo $c->comment_date_gmt;
                    ?>
</nxt:comment_date_gmt>
			<nxt:comment_content><?php 
                    echo wxr_cdata($c->comment_content);
                    ?>
</nxt:comment_content>
			<nxt:comment_approved><?php 
                    echo $c->comment_approved;
                    ?>
</nxt:comment_approved>
			<nxt:comment_type><?php 
                    echo $c->comment_type;
                    ?>
</nxt:comment_type>
			<nxt:comment_parent><?php 
                    echo $c->comment_parent;
                    ?>
</nxt:comment_parent>
			<nxt:comment_user_id><?php 
                    echo $c->user_id;
                    ?>
</nxt:comment_user_id>
<?php 
                    $c_meta = $nxtdb->get_results($nxtdb->prepare("SELECT * FROM {$nxtdb->commentmeta} WHERE comment_id = %d", $c->comment_ID));
                    foreach ($c_meta as $meta) {
                        ?>
			<nxt:commentmeta>
				<nxt:meta_key><?php 
                        echo $meta->meta_key;
                        ?>
</nxt:meta_key>
				<nxt:meta_value><?php 
                        echo wxr_cdata($meta->meta_value);
                        ?>
</nxt:meta_value>
			</nxt:commentmeta>
<?php 
                    }
                    ?>
		</nxt:comment>
<?php 
                }
                ?>
	</item>
<?php 
            }
        }
    }
    ?>
</channel>
</rss>
<?php 
}
コード例 #9
0
ファイル: deprecated.php プロジェクト: nxtclass/NXTClass
/**
 * Retrieve icon URL and Path.
 *
 * @since 2.1.0
 * @deprecated 2.5.0
 * @deprecated Use nxt_get_attachment_image_src()
 * @see nxt_get_attachment_image_src()
 *
 * @param int $id Optional. Post ID.
 * @param bool $fullsize Optional, default to false. Whether to have full image.
 * @return array Icon URL and full path to file, respectively.
 */
function get_attachment_icon_src($id = 0, $fullsize = false)
{
    _deprecated_function(__FUNCTION__, '2.5', 'nxt_get_attachment_image_src()');
    $id = (int) $id;
    if (!($post =& get_post($id))) {
        return false;
    }
    $file = get_attached_file($post->ID);
    if (!$fullsize && ($src = nxt_get_attachment_thumb_url($post->ID))) {
        // We have a thumbnail desired, specified and existing
        $src_file = basename($src);
        $class = 'attachmentthumb';
    } elseif (nxt_attachment_is_image($post->ID)) {
        // We have an image without a thumbnail
        $src = nxt_get_attachment_url($post->ID);
        $src_file =& $file;
        $class = 'attachmentimage';
    } elseif ($src = nxt_mime_type_icon($post->ID)) {
        // No thumb, no image. We'll look for a mime-related icon instead.
        $icon_dir = apply_filters('icon_dir', get_template_directory() . '/images');
        $src_file = $icon_dir . '/' . basename($src);
    }
    if (!isset($src) || !$src) {
        return false;
    }
    return array($src, $src_file);
}
コード例 #10
0
ファイル: template.php プロジェクト: nxtclass/NXTClass
/**
 * {@internal Missing Short Description}}
 *
 * @since 2.0.0
 *
 * @param unknown_type $id
 * @return unknown
 */
function the_attachment_links($id = false)
{
    $id = (int) $id;
    $post =& get_post($id);
    if ($post->post_type != 'attachment') {
        return false;
    }
    $icon = nxt_get_attachment_image($post->ID, 'thumbnail', true);
    $attachment_data = nxt_get_attachment_metadata($id);
    $thumb = isset($attachment_data['thumb']);
    ?>
<form id="the-attachment-links">
<table>
	<col />
	<col class="widefat" />
	<tr>
		<th scope="row"><?php 
    _e('URL');
    ?>
</th>
		<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php 
    echo esc_textarea(nxt_get_attachment_url());
    ?>
</textarea></td>
	</tr>
<?php 
    if ($icon) {
        ?>
	<tr>
		<th scope="row"><?php 
        $thumb ? _e('Thumbnail linked to file') : _e('Image linked to file');
        ?>
</th>
		<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php 
        echo nxt_get_attachment_url();
        ?>
"><?php 
        echo $icon;
        ?>
</a></textarea></td>
	</tr>
	<tr>
		<th scope="row"><?php 
        $thumb ? _e('Thumbnail linked to page') : _e('Image linked to page');
        ?>
</th>
		<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php 
        echo get_attachment_link($post->ID);
        ?>
" rel="attachment nxt-att-<?php 
        echo $post->ID;
        ?>
"><?php 
        echo $icon;
        ?>
</a></textarea></td>
	</tr>
<?php 
    } else {
        ?>
	<tr>
		<th scope="row"><?php 
        _e('Link to file');
        ?>
</th>
		<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php 
        echo nxt_get_attachment_url();
        ?>
" class="attachmentlink"><?php 
        echo basename(nxt_get_attachment_url());
        ?>
</a></textarea></td>
	</tr>
	<tr>
		<th scope="row"><?php 
        _e('Link to page');
        ?>
</th>
		<td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php 
        echo get_attachment_link($post->ID);
        ?>
" rel="attachment nxt-att-<?php 
        echo $post->ID;
        ?>
"><?php 
        the_title();
        ?>
</a></textarea></td>
	</tr>
<?php 
    }
    ?>
</table>
</form>
<?php 
}
コード例 #11
0
ファイル: image-edit.php プロジェクト: nxtclass/NXTClass
function nxt_save_image($post_id)
{
    $return = new stdClass();
    $success = $delete = $scaled = $nocrop = false;
    $post = get_post($post_id);
    @ini_set('memory_limit', apply_filters('admin_memory_limit', nxt_MAX_MEMORY_LIMIT));
    $img = load_image_to_edit($post_id, $post->post_mime_type);
    if (!is_resource($img)) {
        $return->error = esc_js(__('Unable to create new image.'));
        return $return;
    }
    $fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;
    $fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;
    $target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';
    $scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do'];
    if ($scale && $fwidth > 0 && $fheight > 0) {
        $sX = imagesx($img);
        $sY = imagesy($img);
        // check if it has roughly the same w / h ratio
        $diff = round($sX / $sY, 2) - round($fwidth / $fheight, 2);
        if (-0.1 < $diff && $diff < 0.1) {
            // scale the full size image
            $dst = nxt_imagecreatetruecolor($fwidth, $fheight);
            if (imagecopyresampled($dst, $img, 0, 0, 0, 0, $fwidth, $fheight, $sX, $sY)) {
                imagedestroy($img);
                $img = $dst;
                $scaled = true;
            }
        }
        if (!$scaled) {
            $return->error = esc_js(__('Error while saving the scaled image. Please reload the page and try again.'));
            return $return;
        }
    } elseif (!empty($_REQUEST['history'])) {
        $changes = json_decode(stripslashes($_REQUEST['history']));
        if ($changes) {
            $img = image_edit_apply_changes($img, $changes);
        }
    } else {
        $return->error = esc_js(__('Nothing to save, the image has not changed.'));
        return $return;
    }
    $meta = nxt_get_attachment_metadata($post_id);
    $backup_sizes = get_post_meta($post->ID, '_nxt_attachment_backup_sizes', true);
    if (!is_array($meta)) {
        $return->error = esc_js(__('Image data does not exist. Please re-upload the image.'));
        return $return;
    }
    if (!is_array($backup_sizes)) {
        $backup_sizes = array();
    }
    // generate new filename
    $path = get_attached_file($post_id);
    $path_parts = pathinfo($path);
    $filename = $path_parts['filename'];
    $suffix = time() . rand(100, 999);
    if (defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename']) {
        if ('thumbnail' == $target) {
            $new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";
        } else {
            $new_path = $path;
        }
    } else {
        while (true) {
            $filename = preg_replace('/-e([0-9]+)$/', '', $filename);
            $filename .= "-e{$suffix}";
            $new_filename = "{$filename}.{$path_parts['extension']}";
            $new_path = "{$path_parts['dirname']}/{$new_filename}";
            if (file_exists($new_path)) {
                $suffix++;
            } else {
                break;
            }
        }
    }
    // save the full-size file, also needed to create sub-sizes
    if (!nxt_save_image_file($new_path, $img, $post->post_mime_type, $post_id)) {
        $return->error = esc_js(__('Unable to save the image.'));
        return $return;
    }
    if ('nothumb' == $target || 'all' == $target || 'full' == $target || $scaled) {
        $tag = false;
        if (isset($backup_sizes['full-orig'])) {
            if ((!defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE) && $backup_sizes['full-orig']['file'] != $path_parts['basename']) {
                $tag = "full-{$suffix}";
            }
        } else {
            $tag = 'full-orig';
        }
        if ($tag) {
            $backup_sizes[$tag] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $path_parts['basename']);
        }
        $success = update_attached_file($post_id, $new_path);
        $meta['file'] = _nxt_relative_upload_path($new_path);
        $meta['width'] = imagesx($img);
        $meta['height'] = imagesy($img);
        list($uwidth, $uheight) = nxt_constrain_dimensions($meta['width'], $meta['height'], 128, 96);
        $meta['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'";
        if ($success && ('nothumb' == $target || 'all' == $target)) {
            $sizes = get_intermediate_image_sizes();
            if ('nothumb' == $target) {
                $sizes = array_diff($sizes, array('thumbnail'));
            }
        }
        $return->fw = $meta['width'];
        $return->fh = $meta['height'];
    } elseif ('thumbnail' == $target) {
        $sizes = array('thumbnail');
        $success = $delete = $nocrop = true;
    }
    if (isset($sizes)) {
        foreach ($sizes as $size) {
            $tag = false;
            if (isset($meta['sizes'][$size])) {
                if (isset($backup_sizes["{$size}-orig"])) {
                    if ((!defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE) && $backup_sizes["{$size}-orig"]['file'] != $meta['sizes'][$size]['file']) {
                        $tag = "{$size}-{$suffix}";
                    }
                } else {
                    $tag = "{$size}-orig";
                }
                if ($tag) {
                    $backup_sizes[$tag] = $meta['sizes'][$size];
                }
            }
            $crop = $nocrop ? false : get_option("{$size}_crop");
            $resized = image_make_intermediate_size($new_path, get_option("{$size}_size_w"), get_option("{$size}_size_h"), $crop);
            if ($resized) {
                $meta['sizes'][$size] = $resized;
            } else {
                unset($meta['sizes'][$size]);
            }
        }
    }
    if ($success) {
        nxt_update_attachment_metadata($post_id, $meta);
        update_post_meta($post_id, '_nxt_attachment_backup_sizes', $backup_sizes);
        if ($target == 'thumbnail' || $target == 'all' || $target == 'full') {
            $file_url = nxt_get_attachment_url($post_id);
            if ($thumb = $meta['sizes']['thumbnail']) {
                $return->thumbnail = path_join(dirname($file_url), $thumb['file']);
            } else {
                $return->thumbnail = "{$file_url}?w=128&h=128";
            }
        }
    } else {
        $delete = true;
    }
    if ($delete) {
        $delpath = apply_filters('nxt_delete_file', $new_path);
        @unlink($delpath);
    }
    imagedestroy($img);
    $return->msg = esc_js(__('Image saved'));
    return $return;
}