Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Importing the files and folders for the Get the Image plugin.

git-svn-id: http://svn.locallylost.com/plugins/get-the-image/trunk@208 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
commit 4c2ae75d6329642ee08241b642f1a3c8bb596306 0 parents
greenshady authored
Showing with 999 additions and 0 deletions.
  1. +304 −0 get-the-image.php
  2. +339 −0 license.txt
  3. +77 −0 readme.css
  4. +191 −0 readme.html
  5. +88 −0 readme.txt
304 get-the-image.php
@@ -0,0 +1,304 @@
+<?php
+/**
+ * Plugin Name: Get The Image
+ * Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
+ * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
+ * Version: 0.4
+ * Author: Justin Tadlock
+ * Author URI: http://justintadlock.com
+ *
+ * Get the Image was created to solve a problem in the WordPress community about how to handle
+ * post-specific images. It was created to be a highly-intuitive image script that loads images that are
+ * related to specific posts in some way. It creates an image-based representation of a WordPress
+ * post (or any post type).
+ *
+ * @copyright 2008 - 2009
+ * @version 0.4
+ * @author Justin Tadlock
+ * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * @package GetTheImage
+ */
+
+/* Adds theme support for post images. */
+add_theme_support( 'post-thumbnails' );
+
+/**
+ * This is a highly intuitive function that gets images. It first calls for custom field keys. If no
+ * custom field key is set, check for the_post_thumbnail(). If no post image, check for images
+ * attached to post. Check for image order if looking for attached images. Scan the post for
+ * images if $image_scan = true. Check for default image if $default_image = true. If an image
+ * is found, call display_the_image() to format it.
+ *
+ * @since 0.1
+ * @global $post The current post's DB object.
+ * @param array $args Parameters for what image to get.
+ * @return string|array The HTML for the image. | Image attributes in an array.
+ */
+function get_the_image( $args = array() ) {
+ global $post;
+
+ /* Set the default arguments. */
+ $defaults = array(
+ 'custom_key' => array( 'Thumbnail', 'thumbnail' ),
+ 'post_id' => $post->ID,
+ 'attachment' => true,
+ 'the_post_thumbnail' => true, // WP 2.9+ image function
+ 'default_size' => 'thumbnail',
+ 'default_image' => false,
+ 'order_of_image' => 1,
+ 'link_to_post' => true,
+ 'image_class' => false,
+ 'image_scan' => false,
+ 'width' => false,
+ 'height' => false,
+ 'format' => 'img',
+ 'echo' => true
+ );
+
+ /* Allow plugins/themes to filter the arguments. */
+ $args = apply_filters( 'get_the_image_args', $args );
+
+ /* Merge the input arguments and the defaults. */
+ $args = wp_parse_args( $args, $defaults );
+
+ /* Extract the array to allow easy use of variables. */
+ extract( $args );
+
+ /* If a custom field key (array) is defined, check for images by custom field. */
+ if ( $custom_key )
+ $image = image_by_custom_field( $args );
+
+ /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */
+ if ( !$image && $the_post_thumbnail )
+ $image = image_by_the_post_thumbnail( $args );
+
+ /* If no image found and $attachment is set to true, check for an image by attachment. */
+ if ( !$image && $attachment )
+ $image = image_by_attachment( $args );
+
+ /* If no image found and $image_scan is set to true, scan the post for images. */
+ if ( !$image && $image_scan )
+ $image = image_by_scan( $args );
+
+ /* If no image found and a $default_image is set, get the default image. */
+ if ( !$image && $default_image )
+ $image = image_by_default( $args );
+
+ /* If an image is returned, run it through the display function. */
+ if ( $image )
+ $image = display_the_image( $args, $image );
+
+ /* Allow plugins/theme to override the final output. */
+ $image = apply_filters( 'get_the_image', $image );
+
+ /* Display the image if $echo is set to true and the $format isn't an array. Else, return the image. */
+ if ( $echo && 'array' !== $format )
+ echo $image;
+ else
+ return $image;
+}
+
+/* Internal Functions */
+
+/**
+ * Calls images by custom field key. Script loops through multiple custom field keys.
+ * If that particular key is found, $image is set and the loop breaks. If an image is
+ * found, it is returned.
+ *
+ * @since 0.3
+ * @param array $args
+ * @return array|bool
+ */
+function image_by_custom_field( $args = array() ) {
+
+ /* If $custom_key is a string, we want to split it by spaces into an array. */
+ if ( !is_array( $args['custom_key'] ) )
+ $args['custom_key'] = preg_split( '#\s+#', $args['custom_key'] );
+
+ /* If $custom_key is set, loop through each custom field key, searching for values. */
+ if ( isset( $args['custom_key'] ) ) {
+ foreach ( $args['custom_key'] as $custom ) {
+ $image = get_metadata( 'post', $args['post_id'], $custom, true );
+ if ( $image )
+ break;
+ }
+ }
+
+ /* If a custom key value has been given for one of the keys, return the image URL. */
+ if ( $image )
+ return array( 'url' => $image );
+
+ return false;
+}
+
+/**
+ * Checks for images using a custom version of the WordPress 2.9+ get_the_post_thumbnail()
+ * function. If an image is found, return it and the $post_thumbnail_id. The WordPress function's
+ * other filters are later added in the display_the_image() function.
+ *
+ * @since 0.4
+ * @param array $args
+ * @return array|bool
+ */
+function image_by_the_post_thumbnail( $args = array() ) {
+
+ /* Check for a post image ID (set by WP as a custom field). */
+ $post_thumbnail_id = get_post_thumbnail_id( $args['post_id'] );
+
+ /* If no post image ID is found, return false. */
+ if ( empty( $post_thumbnail_id ) )
+ return false;
+
+ /* Apply filters on post_thumbnail_size because this is a default WP filter used with its image feature. */
+ $size = apply_filters( 'post_thumbnail_size', $args['default_size'] );
+
+ /* Get the attachment image source. This should return an array. */
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, $size );
+
+ /* Return both the image URL and the post thumbnail ID. */
+ return array( 'url' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id );
+}
+
+/**
+ * Check for attachment images. Uses get_children() to check if the post has images
+ * attached. If image attachments are found, loop through each. The loop only breaks
+ * once $order_of_image is reached.
+ *
+ * @since 0.3
+ * @param array $args
+ * @return array|bool
+ */
+function image_by_attachment( $args = array() ) {
+
+ /* Get attachments for the inputted $post_id. */
+ $attachments = get_children( array( 'post_parent' => $args['post_id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
+
+ /* If no attachments are found, return false. */
+ if ( empty( $attachments ) )
+ return false;
+
+ /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */
+ foreach ( $attachments as $id => $attachment ) {
+ if ( ++$i == $args['order_of_image'] ) {
+ $image = wp_get_attachment_image_src( $id, $args['default_size'] );
+ break;
+ }
+ }
+
+ /* Return the image URL. */
+ return array( 'url' => $image[0] );
+}
+
+/**
+ * Scans the post for images within the content. Not called by default with get_the_image().
+ * Shouldn't use if using large images within posts, better to use the other options.
+ *
+ * @since 0.3
+ * @global $post The current post's DB object.
+ * @param array $args
+ * @return array|bool
+ */
+function image_by_scan( $args = array() ) {
+
+ /* Search the post's content for the <img /> tag and get its URL. */
+ preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', get_post_field( 'post_content', $args['post_id'] ), $matches );
+
+ /* If there is a match for the image, return its URL. */
+ if ( isset( $matches ) && $matches[1][0] )
+ return array( 'url' => $matches[1][0] );
+
+ return false;
+}
+
+/**
+ * Used for setting a default image. The function simply returns the image URL it was
+ * given in an array. Not used with get_the_image() by default.
+ *
+ * @since 0.3
+ * @param array $args
+ * @return array
+ */
+function image_by_default( $args = array() ) {
+ return array( 'url' => $args['default_image'] );
+}
+
+/**
+ * Formats an image with appropriate alt text and class. Adds a link to the post if argument
+ * is set. Should only be called if there is an image to display, but will handle it if not.
+ *
+ * @since 0.1
+ * @param array $args
+ * @param array $image Array of image info ($image, $classes, $alt, $caption).
+ * @return string $image Formatted image (w/link to post if the option is set).
+ */
+function display_the_image( $args = array(), $image = false ) {
+
+ /* If there is no image URL, return false. */
+ if ( empty( $image['url'] ) )
+ return false;
+
+ /* Extract the arguments for easy-to-use variables. */
+ extract( $args );
+
+ /* If there is a width or height, set them as HMTL-ready attributes. */
+ if ( $width )
+ $width = ' width="' . $width . '"';
+ if ( $height )
+ $height = ' height="' . $height . '"';
+
+ /* Loop through the custom field keys and add them as classes. */
+ if ( is_array( $custom_key ) ) {
+ foreach ( $custom_key as $key )
+ $classes[] = str_replace( ' ', '-', strtolower( $key ) );
+ }
+
+ /* Add the $default_size and any user-added $image_class to the class. */
+ $classes[] = $default_size;
+ $classes[] = $image_class;
+
+ /* Join all the classes into a single string. */
+ $class = join( ' ', $classes );
+
+ /* If $format should be an array, return the attributes in array format. */
+ if ( 'array' == $format )
+ return array( 'url' => $image['url'], 'alt' => esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ), 'class' => $class, 'link' => get_permalink( $post_id ) );
+
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
+ if ( $image['post_thumbnail_id'] )
+ do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $default_size );
+
+ /* Add the image attributes to the <img /> element. */
+ $html = '<img src="' . $image['url'] . '" alt="' . esc_attr( strip_tags( get_post_field( 'post_title', $post_id ) ) ) . '" class="' . $class . '"' . $width . $height . ' />';
+
+ /* If $link_to_post is set to true, link the image to its post. */
+ if ( $link_to_post )
+ $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
+
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
+ if ( $image['post_thumbnail_id'] )
+ do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $default_size );
+
+ /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
+ if ( $image['post_thumbnail_id'] )
+ $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $default_size, $attr );
+
+ return $html;
+}
+
+/**
+ * Get the image with a link to the post. Use get_the_image() instead.
+ *
+ * @since 0.1
+ * @deprecated 0.3
+ */
+function get_the_image_link( $deprecated = '', $deprecated_2 = '', $deprecated_3 = '' ) {
+ get_the_image();
+}
+
+?>
339 license.txt
@@ -0,0 +1,339 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
77 readme.css
@@ -0,0 +1,77 @@
+/* Reset values */
+html,body,div,span,object,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,samp,small,strong,sub,sup,tt,var,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;vertical-align:baseline;outline:none;font-size:100%;background:transparent;border:none;text-decoration:none}b,i,hr,u,center,menu,layer,s,strike,font,xmp{margin:0;padding:0;vertical-align:baseline;outline:none;font-size:100%;font-weight:normal;font-style:normal;background:transparent;border:none;text-decoration:none}font{color:#333}center{text-align:left}body{line-height:25px;font-family:Cambria,Georgia,Times,"Times New Roman",serif;color:#333;background:#fff}h1,h2,h3,h4,h5,h6{font-style:normal;font-weight:normal;margin:0 0 25px 0}h1{font-size:1.8em}h2{font-size:1.7em}h3{font-size:1.55em;}h4{font-size:1.4em}h5{font-size:1.25em}h6{font-size:1.1em}p{margin:0 0 25px 0}ol,ul{list-style:none}ul{list-style:disc;margin:0 0 25px 2.5em}ol{list-style-type:decimal;margin:0 0 25px 3em}ol ol{list-style:upper-roman}ol ol ol{list-style:lower-roman}ol ol ol ol{list-style:upper-alpha}ol ol ol ol ol{list-style:lower-alpha}ul ul,ol ol,ul ol,ol ul{margin-bottom:0}dl{margin:0 0 25px 5px}dl dt{font-weight:bold;margin:10px 0 0 0}dl dd{margin:5px 0 0 1.5em}strong{font-weight:bold}strong strong{font-weight:normal}em,cite{font-style:italic}em em,cite cite{font-style:normal}abbr{cursor:help}acronym{text-transform:uppercase;border-bottom:1px dashed #666;cursor:help}big{font-size:120%}small,sup,sub{font-size:80%}sup{vertical-align:baseline;position:relative;bottom:0.3em}sub{vertical-align:baseline;position:relative;top:0.3em}address{font-style:italic;margin:0 0 25px 0}li address,dd address{margin:0}blockquote{margin:0 25px;font-style:normal}blockquote em,blockquote cite{font-style:italic}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}a{cursor:pointer}a img{border:none}pre{overflow:auto;font:.9em Monaco,monospace,Courier,"Courier New";line-height:25px;margin-bottom:25px;padding:10px}code{font:.9em Monaco,monospace,Courier,"Courier New"}pre code{font-size:1em}ins,dfn{font-style:italic;text-decoration:none;border-bottom:1px solid #666}del{text-decoration:line-through}object{margin-bottom:25px}input,textarea{font-size:1em;font-family:Cambria,Georgia,Times,"Times New Roman",serif;padding:3px}:focus{outline:none}form label{cursor:pointer}option{padding:1px 2px}table{border-collapse:collapse;border-spacing:0;margin-bottom:25px}th,td{text-align:left}hr{margin-bottom:25px}img.wp-smiley{max-height:12px;margin:0;padding:0;border:none}.gallery{display:block;text-align:center;margin-bottom:25px !important}.alignleft,.left{float:left;margin-right:20px}.alignright,.right{float:right;margin-left:20px}.aligncenter,.center{display:block;margin:0 auto 25px auto}.alignnone,.block{clear:both;margin:0 0 25px 0}.clear{clear:both}img.alignleft,img.alignright{display:inline}
+
+body {
+ width: 750px;
+ margin: 36px auto 60px auto;
+ font: 15px/21px Arial, 'Helvetica Neue', Helvetica, sans-serif;
+ font: 16px/25px Georgia, Times, 'Times New Roman', serif;
+ }
+/* Links */
+a:link, a:visited {
+ color: #2f6eb9;
+ text-decoration: none;
+ }
+a:hover, a:active {
+ text-decoration: underline;
+ }
+/* Headers */
+h1, h2, h3, h4, h5, h6 {
+ margin: 40px 0 30px 0;
+ color: #000;
+ font-weight: bold;
+ font-family: Arial, sans-serif;
+ }
+h3 {
+ font-weight: normal;
+ font-style: italic;
+ font-family: Georgia, Times, 'Times New Roman', serif;
+ }
+h1 {
+ margin-top: 80px;
+ font-size: 2.2em;
+ }
+code {
+ padding: 0 3px;
+ background: #eee;
+ }
+pre code {
+ padding: 0;
+ }
+pre {
+ padding: 9px;
+ background: #eee;
+ border: 1px solid #ccc;
+ }
+ul {
+ list-style: square;
+ }
+p.first {
+ font-size: 21px;
+ }
+p.second {
+ font-size: 15px;
+ }
+ul.space li {
+ margin-bottom: 10px;
+ }
+.section {
+ overflow: hidden;
+ }
+
+.columns-2 {
+ float: left;
+ width: 350px;
+ margin: 0 0 21px 25px;
+ }
+.columns-3 {
+ float: left;
+ width: 230px;
+ margin: 0 0 21px 20px;
+ }
+/* Warnings/Alerts */
+.warning, .alert {
+ padding: 6px 9px;
+ background: #fffbbc;
+ border: 1px solid #E6DB55;
+ }
191 readme.html
@@ -0,0 +1,191 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<title>A guide to the Get the Image plugin</title>
+
+<link rel="stylesheet" href="readme.css" type="text/css" media="screen" />
+
+</head>
+<body>
+
+<h1>A guide to Get the Image</h1>
+
+<p class="first"><em>Get the Image</em> is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.</p>
+
+<p class="second">To use this plugin, you must be familiar with two very important things in WordPress: the <a href="http://codex.wordpress.org/Template_Hierarchy" title="Template Hierarchy">Template Hierarchy</a> and <a href="http://codex.wordpress.org/The_Loop" title="The Loop">The Loop</a>. If you don't have a working knowledge of those two things, then you should not attempt to use this plugin. More importantly, you should be familiar with how all of this works within your theme because not all themes are the same.</p>
+
+<h2>What this plugin does</h2>
+
+<p>This plugin was made to easily find images and add them on pages where the full post isn't shown. This is the order in which the plugin attempts to grab an image.</p>
+
+<ol>
+ <li>Looks for an image by custom field.</li>
+ <li>If no image is added by custom field, check for a <a href="http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature" title="WordPress 2.9's post image feature">post image</a> (WordPresss 2.9+ feature).</li>
+ <li>If no image is found, it grabs an image attached to your post.</li>
+ <li>If no image is attached, it can extract an image from your post content (off by default).</li>
+ <li>If no image is found at this point, it will default to an image you set (not set by default).</li>
+</ol>
+
+<h2>How to install the plugin</h2>
+
+<ol>
+ <li>Uzip the <code>get-the-image.zip</code> folder.</li>
+ <li>Upload the <code>get-the-image</code> folder to your <code>/wp-content/plugins</code> directory.</li>
+ <li>In your WordPress dashboard, head over to the <em>Plugins</em> section.</li>
+ <li>Activate <em>Get The Image</em>.</li>
+</ol>
+
+<p class="alert">If you are upgrading from a version prior to 0.3 just overwrite your old files. You'll need to change the calls to the plugin in your template files because how the plugin works has changed. Follow the instructions below to see how the image script should be called.</p>
+
+<h2>How to use the plugin</h2>
+
+<p>To call the image script, you'll need to use what's called <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters" title="PHP function-style parameters">function-style parameters</a>.</p>
+
+<p><strong>Example with function-style parameters</strong></p>
+
+<pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'default_size' => 'thumbnail' ) ); ?></code></pre>
+
+<h2>The image script parameters</h2>
+
+<p>By simply making a function call to <code>&lt;?php get_the_image(); ?></code> within a template file, the script will default to this:</p>
+
+<pre><code>$defaults = array(
+ 'custom_key' => array( 'Thumbnail', 'thumbnail' ),
+ 'attachment' => true,
+ 'default_size' => 'thumbnail',
+ 'the_post_thumbnail' => true,
+ 'default_image' => false,
+ 'order_of_image' => 1,
+ 'link_to_post' => true,
+ 'image_class' => false,
+ 'image_scan' => false,
+ 'width' => false,
+ 'height' => false,
+ 'echo' => true
+);</code></pre>
+
+<dl>
+ <dt>custom_key</dt>
+ <dd>This parameter refers to a custom field key (or keys) that you use. Remember, custom field keys are case-sensitive (defaults are <code>Thumbnail</code> and <code>thumbnail</code>).</dd>
+ <dt>attachment</dt>
+ <dd>The script will look for images attached to the post (set to <code>true</code> by default).</dd>
+ <dt>default_size</dt>
+ <dd>This refers to the default size of an attached image. You can choose between <code>thumbnail</code>, <code>medium</code>, <code>large</code> (WP 2.7+), or <code>full</code> (the default is <code>thumbnail</code>).</dd>
+ <dt>the_post_thumbnail</dt>
+ <dd>This refers to the WordPress 2.9's new <code>the_post_thumbnail()</code> feature. By having this set to <code>true</code>, you may select an image from the post image meta box while in the post editor.
+ <dt>default_image</dt>
+ <dd>Will take the input of an image URL and use it if no other images are found (no default set).</dd>
+ <dt>order_of_image</dt>
+ <dd>You can choose for the script to grab something other than the first attached image. This only refers to image attachments.</dd>
+ <dt>link_to_post</dt>
+ <dd>Whether the attachment image should be linked to the post (set to <code>true</code> by default).</dd>
+ <dt>image_class</dt>
+ <dd>You can give an additional class to the image for use in your CSS.</dd>
+ <dt>image_scan</dt>
+ <dd>If set to <code>true</code>, the script will search within your post for an image that's been added.</dd>
+ <dt>width</dt>
+ <dd>Set the width of the image on output.</dd>
+ <dt>height</dt>
+ <dd>Set the height of the image on output.</dd>
+ <dt>echo</dt>
+ <dd>If set to <code>true</code>, the image is shown on the page. If set to <code>false</code>, the image will be returned to use in your own function. (Set to <code>true</code> by default.)</dd>
+</dl>
+
+<h2>Some examples of how to use this plugin</h2>
+
+<p><strong>Example 1:</strong> Let's suppose that you want to add thumbnails to your category archive pages. What you'll need to do is open your <code>category.php</code> file and add this code within the Loop:</p>
+
+<pre><code>&lt;?php get_the_image(); ?></code></pre>
+
+<p>By default, that will look for an image with the custom field <strong>key</strong> <code>Thumbnail</code> and <code>thumnbail</code>. If that image doesn't exist, it will check if a post image has been set. If that image doesn't exist, it will search for any images attached to your post.</p>
+
+<p><strong>Example 2:</strong> Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of <code>Feature</code>. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.</p>
+
+<pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Feature' ), 'default_size' => 'full' ) ); ?></code></pre>
+
+<p>If no feature image exists by custom field, it will look for images attached to your post.</p>
+
+<p><strong>Example 3:</strong> If you want to have a sort of fallback image, then you can set an image for the script to default to if no other images are found.</p>
+
+<pre><code>&lt;?php get_the_image( array( 'default_image' => 'http://mysite.com/wp-content/uploads/example.jpg' ) ); ?></code></pre>
+
+<p><strong>Example 4:</strong> You can even make the script scan for images that have been added to your post with this:</p>
+
+<pre><code>&lt;?php get_the_image( array( 'image_scan' => true ) ); ?></code></pre>
+
+<p><strong>Example 5:</strong> You might want to make the script grab the second attached image to a post. You can do that with this code:</p>
+
+<pre><code>&lt;?php get_the_image( array( 'order_of_image' => 2 ) ); ?></code></pre>
+
+<h2>A real-world example</h2>
+
+<p>This is an example Loop, which may differ slightly from your theme, but the concept is the same. The call to get the image can go anywhere between the opening and closing lines.</p>
+
+<pre><code>&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
+
+ &lt;div id="post-&lt;?php the_ID(); ?>" &lt;?php post_class(); ?>>
+
+ &lt;?php get_the_image( array( 'custom_key' => array( 'feature_img' ), 'default_size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
+
+ &lt;h2>&lt;a href="&lt;?php the_permalink(); ?>" title="&lt;?php the_title_attribute(); ?>" rel="bookmark">&lt;?php the_title(); ?>&lt;/a>&lt;/h2>
+
+ &lt;div class="entry-summary">
+ &lt;?the_excerpt(); ?>
+ &lt;/div>
+
+ &lt;/div>
+
+&lt;?php endwhile; endif; ?></code></pre>
+
+<h2>Protect yourself from errors in the future</h2>
+
+<p>Sometimes, we stop using plugins, but we forget to remove the function calls to the plugin in our theme files. When deactivated, this causes errors. To protect yourself from these errors, you can call the image script like this:</p>
+
+<pre><code>&lt;?php if ( function_exists( 'get_the_image' ) ) { get_the_image(); } ?></code></pre>
+
+<p>Basically, this just checks to see if the plugin is activated and has loaded the appropriate function.</p>
+
+<h2>Styling your images</h2>
+
+<p>The plugin will help you style your images by giving you some CSS classes to work with. It will turn your custom field keys and default size into CSS classes. You can also choose to input your own class.</p>
+
+<p>By default, you can add this to your CSS:</p>
+
+<pre><code>img.thumbnail { }</code></pre>
+
+<p>Let's suppose you've used this code:</p>
+
+<pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Donkey Kong', 'mario' ), 'default_size' => 'full' ) ); ?></code></pre>
+
+<p>This will give you these CSS classes to work with:</p>
+
+<pre><code>img.full { }
+img.donkey-kong { }
+img.mario { }</code></pre>
+
+<p>You can also input a custom CSS class like so:</p>
+
+<pre><code>&lt;?php get_the_image( array( 'image_class' => 'custom-image' ) ); ?></code></pre>
+
+<p>You will still have the <code>default_size</code> and <code>custom_key</code> classes plus your additional class:</p>
+
+<pre><code>img.custom-image { }
+img.thumbnail { }</code></pre>
+
+<h2>Plugin support</h2>
+
+<p>I run a WordPress community called <a href="http://themehybrid.com" title="Theme Hybrid">Theme Hybrid</a>, which is where I fully support all of my WordPress projects, including plugins. You can sign up for an account to get plugin support for a small yearly fee ($25 <acronym title="United States Dollars">USD</acronym> at the time of writing).</p>
+
+<p>I know. I know. You might not want to pay for support, but just consider it a donation to the project. To continue making cool, GPL-licensed plugins and having the time to support them, I must pay the bills.</p>
+
+<h2>Copyright &amp; license</h2>
+
+<p><em>Get the Image</em> is licensed under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="GNU GPL">GNU General Public License</a>, version 2 (<acronym title="GNU General Public License">GPL</acronym>).</p>
+
+<p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
+
+<p>2008&thinsp;&ndash;&thinsp;2009 &copy; Justin Tadlock. All rights reserved.</p>
+
+</body>
+</html>
88 readme.txt
@@ -0,0 +1,88 @@
+=== Get the Image ===
+Contributors: greenshady
+Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
+Tags: image, images, thumbnail
+Requires at least: 2.9
+Tested up to: 2.9
+Stable tag: 0.4
+
+An easy-to-use image script for adding things such as thumbnails and feature images.
+
+== Description ==
+
+*Get the Image* is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
+
+This is a highly intuitive script that can grab an image by custom field input, WP's post image feature, post attachment, or extracting it from the post's content.
+
+== Installation ==
+
+1. Upload `get-the-image` to the `/wp-content/plugins/` directory.
+1. Activate the plugin through the 'Plugins' menu in WordPress.
+1. Add the appropriate code to your template files as outlined in the `readme.html` file.
+
+More detailed instructions are included in the plugin's `readme.html` file. It is important to read through that file to properly understand all of the options and how the plugin works.
+
+== Frequently Asked Questions ==
+
+= Why was this plugin created? =
+
+Many magazine-type themes require a lot of work when inputting images to make them look good. This plugin was developed to make that process much easier for the end user. But, at the same time, it needed to be flexible enough to handle anything.
+
+Other scripts are bloated and offer odd solutions. This plugin uses the built-in methods of WordPress to create things such as feature images, thumbnails, galleries, or whatever.
+
+This plugin was created to be a lightweight solution to handle a very powerful need in the WordPress community.
+
+= How does it pull images? =
+
+1. Looks for an image by custom field (one of your choosing).
+1. If no image is added by custom field, check for an image using `the_post_thumbnail()` (WP 2.9's new image feature).
+1. If no image is found, it grabs an image attached to your post.
+1. If no image is attached, it can extract an image from your post content (off by default).
+1. If no image is found at this point, it will default to an image you set (not set by default).
+
+= How do I add it to my theme? =
+
+There are several methods, but in general, you would use this call:
+
+`
+<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>
+`
+
+To see all methods and options, refer to the `readme.html` file included with the theme download.
+
+== Screenshots ==
+
+You can view this plugin in action on my <a href="http://justintadlock.com" title="Justin Tadlock's blog">personal blog</a> (note the thumbnails).
+
+== Changelog ==
+
+Earlier versions were not documented well.
+
+**Version 0.4**
+
+* Dropped support for older versions of WordPress. Now only compatible with 2.9+.
+* Added support for `the_post_thumbnail()`, which is WordPress 2.9's new image functionality.
+* New function: `image_by_the_post_thumbnail()`.
+* Documented more of the code, so the inline PHP doc is updated.
+* Cleaned up some of the old legacy code that's no longer needed.
+
+**Version 0.3.3**
+
+* General code cleanup
+* Added the `get_the_image` filter hook.
+
+**Version 0.3.2**
+
+* General code cleanup.
+* More efficient and logical code.
+* Beefed up the inline documentation so developers can better understand the code.
+* Added a GPL license.txt file.
+
+**Version 0.3.1**
+
+* Fixed the default image and image scan features.
+
+**Version 0.3**
+
+* Changed methods of calling the image script.
+* Added more parameters.
Please sign in to comment.
Something went wrong with that request. Please try again.