├── .gitignore ├── images ├── cabinet.png └── icons │ ├── doc.png │ ├── pdf.png │ ├── zip.png │ ├── audio.png │ ├── broken.png │ ├── data.png │ ├── image.png │ ├── video.png │ └── unknown.png ├── lang ├── wp_pubarch_translate.mo ├── wp_pubarch_translate-de_DE.mo ├── wp_pubarch_translate-de_DE.po └── wp_pubarch_translate.po ├── includes ├── front-end.css ├── template.wppa_widget.php ├── single-publication.php ├── archive-publication.php ├── template.wppa_publication_dropdown.php └── template.wppa_publication_list.php ├── lib ├── class.wp-publication-archive-category-widget.php ├── class.wp-publication-archive-cat-count-widget.php ├── class.publication-widget.php ├── class.mimetype.php ├── class.publication-markup.php ├── class.wp-publication-archive-utilities.php └── class.wp-publication-archive.php ├── wp-publication-archive.php └── readme.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | Thumbs.db -------------------------------------------------------------------------------- /images/cabinet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/cabinet.png -------------------------------------------------------------------------------- /images/icons/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/doc.png -------------------------------------------------------------------------------- /images/icons/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/pdf.png -------------------------------------------------------------------------------- /images/icons/zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/zip.png -------------------------------------------------------------------------------- /images/icons/audio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/audio.png -------------------------------------------------------------------------------- /images/icons/broken.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/broken.png -------------------------------------------------------------------------------- /images/icons/data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/data.png -------------------------------------------------------------------------------- /images/icons/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/image.png -------------------------------------------------------------------------------- /images/icons/video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/video.png -------------------------------------------------------------------------------- /images/icons/unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/images/icons/unknown.png -------------------------------------------------------------------------------- /lang/wp_pubarch_translate.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/lang/wp_pubarch_translate.mo -------------------------------------------------------------------------------- /lang/wp_pubarch_translate-de_DE.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ericmann/WP-Publication-Archive/HEAD/lang/wp_pubarch_translate-de_DE.mo -------------------------------------------------------------------------------- /includes/front-end.css: -------------------------------------------------------------------------------- 1 | .publication-archive { 2 | font-family: arial,sans-serif; 3 | font-size: 11px; 4 | line-height:1.4; 5 | } 6 | 7 | .publication_title { 8 | font-weight: bold; 9 | padding-bottom: 3px; 10 | color:#F46B4F; 11 | } 12 | 13 | .publication_authors { 14 | padding-bottom: 1px; 15 | } 16 | 17 | .publication_authors .date { 18 | padding-left: 5px; 19 | color: #666666; 20 | } 21 | 22 | .publication_download { 23 | color:#990000; 24 | } 25 | .publication_summary { 26 | padding-left: 20px; 27 | padding-top: 3px; 28 | padding-bottom: 3px; 29 | } 30 | 31 | .publication_summary .title, .publication_keywords .title, .publication_categories .title{ 32 | font-weight: bold; 33 | padding-right: 5px; 34 | color: #666666; 35 | } 36 | 37 | .publication_keywords { 38 | padding-left: 20px; 39 | padding-bottom: 3px; 40 | } 41 | 42 | .publication_categories { 43 | padding-left: 20px; 44 | padding-bottom: 3px; 45 | } 46 | 47 | .single-publication { 48 | margin-bottom:20px; 49 | } -------------------------------------------------------------------------------- /includes/template.wppa_widget.php: -------------------------------------------------------------------------------- 1 | have_posts() ) { 15 | 16 | // begin html 17 | echo ""; 30 | } 31 | wp_reset_postdata(); 32 | ?> -------------------------------------------------------------------------------- /includes/single-publication.php: -------------------------------------------------------------------------------- 1 | 10 | 11 |
12 |
13 | 14 | 16 | 17 |
> 18 |
19 |

20 |
21 | 22 |
23 | the_thumbnail(); ?> 24 | 25 |
26 | the_uri(); ?> 27 | list_downloads(); ?> 28 |
29 |
30 | 31 |
32 | the_keywords(); ?> 33 | the_categories(); ?> 34 | ', '' ); ?> 35 |
36 |
37 | 38 | 39 | 40 |
41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /includes/archive-publication.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 |
15 | 16 | 17 |
18 |

19 | 20 |

21 |
22 | 23 | 25 | 26 |
> 27 |
28 |

29 | 30 |

31 |
32 | 33 |
34 | the_thumbnail(); ?> 35 | 36 |
37 | 38 |
39 | ', '' ); ?> 40 |
41 |
42 | 43 | 44 | 45 | 46 | 47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /includes/template.wppa_publication_dropdown.php: -------------------------------------------------------------------------------- 1 | 26 |
27 |

28 |
29 | 35 |
36 |
-------------------------------------------------------------------------------- /includes/template.wppa_publication_list.php: -------------------------------------------------------------------------------- 1 | 24 |
25 | 26 | 27 |
28 | the_thumbnail(); ?> 29 | the_title(); ?> 30 | the_authors(); ?> 31 | the_uri(); ?> 32 | the_summary(); ?> 33 | the_keywords(); ?> 34 | the_categories(); ?> 35 |
36 | 37 |
38 | $limit ) { ?> 39 | 61 | -------------------------------------------------------------------------------- /lib/class.wp-publication-archive-category-widget.php: -------------------------------------------------------------------------------- 1 | 'widget_pub_related', 25 | 'description' => __( 'A list of related publications (based on category).', 'wp_pubarch_translate' ) 26 | ); 27 | parent::__construct( false, __( 'Related Publications', 'wp_pubarch_translate' ), $widget_ops ); 28 | 29 | $this->utilities = WP_Publication_Archive_Utilities::get_instance(); 30 | } 31 | 32 | /** 33 | * Output the settings update form. 34 | * 35 | * @param array $instance 36 | * 37 | * @return void 38 | */ 39 | public function form( $instance ) { 40 | //Defaults 41 | $instance = wp_parse_args( 42 | (array) $instance, 43 | array( 44 | 'title' => __( 'Related Publications' ), 45 | 'count' => 5 46 | ) 47 | ); 48 | $title = esc_attr( $instance['title'] ); 49 | $count = esc_attr( $instance['count'] ); 50 | 51 | ?> 52 |

53 | 55 | 57 |

58 | 59 |

60 | 62 | 64 |

65 | id_base ); 92 | $count = (int) $instance['count']; 93 | 94 | echo $args['before_widget']; 95 | if ( $title ) { 96 | echo $args['before_title'] . $title . $args['after_title']; 97 | } 98 | 99 | $query_args = array( 100 | 'numberposts' => $count, 101 | 'post_type' => 'publication', 102 | 'orderby' => 'post_date', 103 | 'order' => 'DESC' 104 | ); 105 | 106 | // Grab the current cagtegory 107 | $queried = get_queried_object(); 108 | if ( null !== $queried ) { 109 | // Use the current post's categories 110 | $cats = wp_get_post_categories( $queried->ID ); 111 | 112 | $query_args['category__in'] = $cats; 113 | } 114 | 115 | echo ''; 132 | 133 | echo $args['after_widget']; 134 | } 135 | 136 | public function limit_summary_length( $length ) { 137 | return apply_filters( 'wpa-widget-summary-length', 20 ); 138 | } 139 | } -------------------------------------------------------------------------------- /lib/class.wp-publication-archive-cat-count-widget.php: -------------------------------------------------------------------------------- 1 | 'widget_pub_categories', 27 | 'description' => __( 'A list or dropdown of publication categories.', 'wp_pubarch_translate' ) 28 | ); 29 | parent::__construct( false, __( 'Publication Categories', 'wp_pubarch_translate' ), $widget_ops ); 30 | 31 | $this->utilities = WP_Publication_Archive_Utilities::get_instance(); 32 | } 33 | 34 | /** 35 | * Output the settings update form. 36 | * 37 | * @param array $instance 38 | * 39 | * @return void 40 | */ 41 | public function form( $instance ) { 42 | //Defaults 43 | $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); 44 | $title = esc_attr( $instance['title'] ); 45 | $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false; 46 | $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false; 47 | 48 | ?> 49 |

50 | 52 | 54 |

55 | 56 |

57 | /> 59 |
61 | 62 | /> 64 |
66 |

67 | id_base ); 95 | $count = ! empty( $instance['count'] ) ? '1' : '0'; 96 | $dropdown = ! empty( $instance['dropdown'] ) ? '1' : '0'; 97 | 98 | echo $args['before_widget']; 99 | if ( $title ) 100 | echo $args['before_title'] . $title . $args['after_title']; 101 | 102 | $cat_args = array( 'orderby' => 'name', 'show_count' => $count ); 103 | 104 | if ( $dropdown ) { 105 | $cat_args['show_option_none'] = __( 'Select Category', 'wp_pubarch_translate' ); 106 | 107 | $this->utilities->dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) ); 108 | ?> 109 | 110 | 121 | 122 | 125 | 132 |

'; 98 | _e( 'Please set allow_url_fopen to "On" in your PHP.ini file, otherwise WP Publication Archive downloads WILL NOT WORK!', 'wp_pubarch_translate' ); 99 | echo '
' . __( 'More information ...', 'wp_pubarch_translate' ) . ''; 100 | echo '

'; 101 | } 102 | if ( ! (bool) ini_get( 'allow_url_fopen' ) ) { 103 | add_action( 'admin_notices', 'wp_pubarch_fopen_disabled' ); 104 | } 105 | 106 | // Wireup actions 107 | add_action( 'init', 'wp_pubarch_init' ); 108 | add_action( 'init', array( 'WP_Publication_Archive', 'enqueue_scripts_and_styles' ) ); 109 | add_action( 'save_post', array( 'WP_Publication_Archive', 'save_meta' ) ); 110 | add_action( 'template_redirect', array( 'WP_Publication_Archive', 'open_file' ) ); 111 | add_action( 'template_redirect', array( 'WP_Publication_Archive', 'download_file' ) ); 112 | 113 | // Wireup filters 114 | add_filter( 'query_vars', array( 'WP_Publication_Archive', 'query_vars' ) ); 115 | add_filter( 'posts_where_request', array( 'WP_Publication_Archive', 'search' ) ); 116 | add_filter( 'excerpt_length', array( 'WP_Publication_Archive', 'custom_excerpt_length' ) ); 117 | 118 | // Wireup shortcodes 119 | add_shortcode( 'wp-publication-archive', array( 'WP_Publication_Archive', 'shortcode_handler' ) ); -------------------------------------------------------------------------------- /lib/class.publication-widget.php: -------------------------------------------------------------------------------- 1 | 'publication_archive', 19 | 'description' => __( 'Display a list of publications.', 'wp_pubarch_translate' ) 20 | ) 21 | ); 22 | } 23 | 24 | /** 25 | * Output the settings update form. 26 | * 27 | * @param array $instance Current settings 28 | * 29 | * @return void 30 | */ 31 | public function form( $instance ) { 32 | if ( $instance && isset( $instance['title'] ) ) { 33 | $title = esc_attr( $instance['title'] ); 34 | } else { 35 | $title = esc_attr__( 'Publication Archive', 'wp_pubarch_translate' ); 36 | } 37 | 38 | if ( $instance && isset( $instance['number'] ) ) { 39 | $number = esc_attr( $instance['number'] ); 40 | } else { 41 | $number = 5; 42 | } 43 | 44 | if ( $instance && isset( $instance['orderby'] ) ) { 45 | $orderby = esc_attr( $instance['orderby'] ); 46 | } else { 47 | $orderby = 'menu_order'; 48 | } 49 | 50 | $output = "

" . __( 'Title', 'wp_pubarch_translate' ) . ":

"; 51 | 52 | $output .= "

" . __( 'Number of publications to display', 'wp_pubarch_translate' ) . ": " . __( 'Leave blank for no limit.', 'wp_pubarch_translate' ) . "

"; 53 | 54 | $output .= "

" . __( 'Order by', 'wp_pubarch_translate' ) . ":

"; 58 | 59 | echo $output; 60 | } 61 | 62 | /** 63 | * Update a particular widget instance. 64 | * 65 | * This function builds out an instance array based on data passed through the $new_instance variable. 66 | * Data passed in is never saved directly. 67 | * 68 | * @param array $new_instance New settings for the instance as input by the user. 69 | * @param array $old_instance Old settings for the instance. 70 | * @return array Settings to save or Falst to cancel. 71 | */ 72 | public function update( $new_instance, $old_instance ) { 73 | $instance = $old_instance; 74 | $instance['title'] = strip_tags( $new_instance['title'] ); 75 | $instance['number'] = strip_tags( $new_instance['number'] ); 76 | $instance['orderby'] = strip_tags( $new_instance['orderby'] ); 77 | 78 | return $instance; 79 | } 80 | 81 | /** 82 | * Echo the content of the widget to the front-end user interface. 83 | * 84 | * Dynamically loads a template for the widget display. Default template is stored in 85 | * includes/template.wppa_widget.php. If a similarly-named file exists in the current theme, the theme's 86 | * version will be used instead. 87 | * 88 | * @param array $argsDisplay arguments including before_title, after_title, before_widget, and after_widget 89 | * @param array $instance Settings for this particular instance. 90 | * @uses apply_filters() Calls 'widget_title' for the widget title. 91 | * @uses apply_filters() Calls 'wppa_widget_template' to get the name of the widget template file. 92 | * 93 | * @todo Support 'publication_cat' and 'publication_id' in the $query_args array. 94 | */ 95 | public function widget( $args, $instance ) { 96 | /** 97 | * @var string $before_widget 98 | * @var string $after_widget 99 | * @var string $before_title 100 | * @var string $after_title 101 | */ 102 | extract( $args ); 103 | $title = apply_filters( 'widget_title', $instance['title'] ); 104 | 105 | // Get publications to display 106 | $query_args = array(); 107 | 108 | if ( isset( $instance['number'] ) ) { 109 | $query_args['posts_per_page'] = $instance['number']; 110 | } 111 | if ( isset( $instance['order_by'] ) ) { 112 | $query_args['order_by'] = $instance['order_by']; 113 | } 114 | 115 | // Globalize our publications wrapper so the template can use it. 116 | global $wppa_publications; 117 | 118 | $wppa_publications = WP_Publication_Archive::query_publications( $query_args ); 119 | 120 | echo $before_widget; 121 | 122 | if ( $title ) { 123 | echo $before_title . $title . $after_title; 124 | } 125 | 126 | // Include widget template. Can be overridden by a theme. 127 | $template_name = apply_filters( 'wppa_widget_template', 'template.wppa_widget.php' ); 128 | $path = locate_template( $template_name ); 129 | if ( empty( $path ) ) { 130 | $path = WP_PUB_ARCH_DIR . 'includes/' . $template_name; 131 | } 132 | 133 | include( $path ); 134 | 135 | echo $after_widget; 136 | 137 | // Clean up our globals 138 | unset( $wppa_publications ); 139 | } 140 | } -------------------------------------------------------------------------------- /lang/wp_pubarch_translate-de_DE.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: WP Publication Archive\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2013-01-14 08:03-0800\n" 6 | "PO-Revision-Date: 2013-04-29 00:18+0100\n" 7 | "Last-Translator: Ferdinand Malcher \n" 8 | "Language-Team: Jumping Duck Media \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n" 13 | "X-Poedit-Basepath: C:\\xampp\\htdocs\\wp-test\\wp-content\\plugins\\wp-" 14 | "publication-archive\n" 15 | "Language: en\n" 16 | "X-Generator: Poedit 1.5.5\n" 17 | "X-Poedit-SearchPath-0: .\n" 18 | 19 | #: includes/template.wppa_publication_dropdown.php:27 20 | msgid "Download Publication" 21 | msgstr "Publikation herunterladen" 22 | 23 | #: includes/template.wppa_publication_dropdown.php:30 24 | msgid "Select file" 25 | msgstr "Datei auswählen" 26 | 27 | #: includes/template.wppa_publication_list.php:47 28 | msgid "Previous" 29 | msgstr "Zurück" 30 | 31 | #: includes/template.wppa_publication_list.php:55 32 | msgid "Next" 33 | msgstr "Weiter" 34 | 35 | #: lib/class.publication-markup.php:196 36 | msgid "Download:" 37 | msgstr "Download:" 38 | 39 | #: lib/class.publication-markup.php:204 40 | msgid "Open" 41 | msgstr "Öffnen" 42 | 43 | #: lib/class.publication-markup.php:206 44 | msgid "Download" 45 | msgstr "Download" 46 | 47 | #: lib/class.publication-widget.php:16 48 | msgid "Publication Archive Widget" 49 | msgstr "Publikations-Archiv-Widget" 50 | 51 | #: lib/class.publication-widget.php:19 52 | msgid "Display a list of publications." 53 | msgstr "Liste der Publikationen anzeigen." 54 | 55 | #: lib/class.publication-widget.php:50 56 | msgid "Title" 57 | msgstr "Titel" 58 | 59 | #: lib/class.publication-widget.php:52 60 | msgid "Number of publications to display" 61 | msgstr "Anzahl anzuzeigender Publikationen" 62 | 63 | #: lib/class.publication-widget.php:52 64 | msgid "Leave blank for no limit." 65 | msgstr "leer lassen für unbegrenzt" 66 | 67 | #: lib/class.publication-widget.php:54 68 | msgid "Order by" 69 | msgstr "Sortierung" 70 | 71 | #: lib/class.publication-widget.php:55 72 | msgid "Manual (drag and drop)" 73 | msgstr "manuell (Drag & Drop)" 74 | 75 | #: lib/class.publication-widget.php:56 76 | msgid "Latest (publish date)" 77 | msgstr "nach Veröffentlichungsdatum" 78 | 79 | #: lib/class.wp-publication-archive.php:272 80 | msgid "Publications" 81 | msgstr "Publikationen" 82 | 83 | #: lib/class.wp-publication-archive.php:273 84 | #: lib/class.wp-publication-archive.php:343 85 | msgid "Publication" 86 | msgstr "Publikation" 87 | 88 | #: lib/class.wp-publication-archive.php:274 89 | msgid "Add New Publication" 90 | msgstr "Publikation hinzufügen" 91 | 92 | #: lib/class.wp-publication-archive.php:275 93 | msgid "Edit Publication" 94 | msgstr "Publikation bearbeiten" 95 | 96 | #: lib/class.wp-publication-archive.php:276 97 | msgid "New Publication" 98 | msgstr "Neue Publikation" 99 | 100 | #: lib/class.wp-publication-archive.php:277 101 | msgid "View Publication" 102 | msgstr "Publikation anzeigen" 103 | 104 | #: lib/class.wp-publication-archive.php:278 105 | msgid "Search Publications" 106 | msgstr "Publikationen durchsuchen" 107 | 108 | #: lib/class.wp-publication-archive.php:279 109 | msgid "No publications found" 110 | msgstr "Keine Publikationen gefunden" 111 | 112 | #: lib/class.wp-publication-archive.php:280 113 | msgid "No publications found in trash" 114 | msgstr "Keine Publikationen gefunden in Gelöschte" 115 | 116 | #: lib/class.wp-publication-archive.php:313 117 | #: lib/class.wp-publication-archive.php:322 118 | #: lib/class.wp-publication-archive.php:331 119 | msgid "Authors" 120 | msgstr "Autoren" 121 | 122 | #: lib/class.wp-publication-archive.php:314 123 | msgid "Author" 124 | msgstr "Autor" 125 | 126 | #: lib/class.wp-publication-archive.php:315 127 | msgid "Search Authors" 128 | msgstr "Autoren durchsuchen" 129 | 130 | #: lib/class.wp-publication-archive.php:316 131 | msgid "Popular Authors" 132 | msgstr "Beliebte Autoren" 133 | 134 | #: lib/class.wp-publication-archive.php:317 135 | msgid "All Authors" 136 | msgstr "Alle Autoren" 137 | 138 | #: lib/class.wp-publication-archive.php:318 139 | msgid "Edit Author" 140 | msgstr "Autor bearbeiten" 141 | 142 | #: lib/class.wp-publication-archive.php:319 143 | msgid "Update Author" 144 | msgstr "Autor aktualisieren" 145 | 146 | #: lib/class.wp-publication-archive.php:320 147 | msgid "Add New Author" 148 | msgstr "Autor hinzufügen" 149 | 150 | #: lib/class.wp-publication-archive.php:321 151 | msgid "New Author Name" 152 | msgstr "Autorenname" 153 | 154 | #: lib/class.wp-publication-archive.php:342 155 | msgid "Summary" 156 | msgstr "Zusammenfassung" 157 | 158 | #: lib/class.wp-publication-archive.php:344 159 | msgid "Thumbnail" 160 | msgstr "Thumbnail" 161 | 162 | #: lib/class.wp-publication-archive.php:356 163 | msgid "Provide a short description of the publication:" 164 | msgstr "Geben Sie eine kurze Beschreibung der Publikation ein:" 165 | 166 | #: lib/class.wp-publication-archive.php:367 167 | msgid "" 168 | "Please provide the absolute url of the file (including the http://):" 170 | msgstr "Geben Sie die absolute URL zur Datei an (mit http://):" 171 | 172 | #: lib/class.wp-publication-archive.php:369 173 | #: lib/class.wp-publication-archive.php:385 174 | msgid "Upload Publication" 175 | msgstr "Publikation hochladen" 176 | 177 | #: lib/class.wp-publication-archive.php:401 178 | msgid "Enter an URL or upload an image for the thumb." 179 | msgstr "Geben Sie die URL zum Thumbnail an oder laden Sie ein Bild hoch." 180 | 181 | #: lib/class.wp-publication-archive.php:406 182 | msgid "Upload Thumb" 183 | msgstr "Thumbnail hochladen" 184 | 185 | #: lib/class.wp-publication-archive.php:422 186 | msgid "Upload Thumbnail Image" 187 | msgstr "Thumbnail hochladen" 188 | 189 | #: lib/class.wp-publication-archive.php:520 190 | msgid "" 191 | " Sorry, but the categories you passed to the wp-publication-archive " 192 | "shortcode do not match any publication categories." 193 | msgstr "Die im Shortcode angegebenen Kategorien existieren leider nicht." 194 | 195 | #: lib/class.wp-publication-archive.php:520 196 | msgid "You passed: " 197 | msgstr "Sie haben angegeben:" 198 | 199 | #: lib/class.wp-publication-archive.php:541 200 | msgid "There are no publications to display" 201 | msgstr "Keine anzuzeigenden Publikationen" 202 | 203 | #: lib/class.wp-publication-archive.php:543 204 | msgid " by " 205 | msgstr " von " 206 | 207 | #: lib/class.wp-publication-archive.php:546 208 | msgid " categorized " 209 | msgstr " eingeordnet " 210 | 211 | #: lib/class.wp-publication-archive.php:681 212 | #, php-format 213 | msgid "%s (Publication)" 214 | msgstr "%s (Publikation)" 215 | -------------------------------------------------------------------------------- /lang/wp_pubarch_translate.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: WP Publication Archive\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2013-07-19 21:17-0800\n" 6 | "PO-Revision-Date: 2013-07-19 21:17-0800\n" 7 | "Last-Translator: Eric Mann \n" 8 | "Language-Team: Jumping Duck Media \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n" 13 | "X-Poedit-Basepath: C:\\xampp\\htdocs\\wp-test\\wp-content\\plugins\\wp-publication-archive\n" 14 | "X-Poedit-Language: English\n" 15 | "X-Poedit-Country: USA\n" 16 | "X-Poedit-SearchPath-0: .\n" 17 | 18 | #: wp-publication-archive.php:98 19 | msgid "Please set allow_url_fopen to \"On\" in your PHP.ini file, otherwise WP Publication Archive downloads WILL NOT WORK!" 20 | msgstr "" 21 | 22 | #: wp-publication-archive.php:99 23 | msgid "More information ..." 24 | msgstr "" 25 | 26 | #: includes/archive-publication.php:19 27 | msgid "Publication Archives" 28 | msgstr "" 29 | 30 | #: includes/archive-publication.php:29 31 | #, php-format 32 | msgid "Permalink to %s" 33 | msgstr "" 34 | 35 | #: includes/archive-publication.php:39 36 | #: includes/single-publication.php:34 37 | #: lib/class.wp-publication-archive.php:410 38 | msgid "Edit Publication" 39 | msgstr "" 40 | 41 | #: includes/template.wppa_publication_dropdown.php:27 42 | msgid "Download Publication" 43 | msgstr "" 44 | 45 | #: includes/template.wppa_publication_dropdown.php:30 46 | msgid "Select file" 47 | msgstr "" 48 | 49 | #: includes/template.wppa_publication_list.php:47 50 | msgid "Previous" 51 | msgstr "" 52 | 53 | #: includes/template.wppa_publication_list.php:55 54 | msgid "Next" 55 | msgstr "" 56 | 57 | #: lib/class.publication-markup.php:291 58 | #: lib/class.publication-markup.php:412 59 | msgid "View" 60 | msgstr "" 61 | 62 | #: lib/class.publication-markup.php:293 63 | #: lib/class.publication-markup.php:413 64 | msgid "Download" 65 | msgstr "" 66 | 67 | #: lib/class.publication-markup.php:407 68 | msgid "Other Files:" 69 | msgstr "" 70 | 71 | #: lib/class.publication-widget.php:16 72 | msgid "Publication Archive Widget" 73 | msgstr "" 74 | 75 | #: lib/class.publication-widget.php:19 76 | msgid "Display a list of publications." 77 | msgstr "" 78 | 79 | #: lib/class.publication-widget.php:50 80 | msgid "Title" 81 | msgstr "" 82 | 83 | #: lib/class.publication-widget.php:52 84 | msgid "Number of publications to display" 85 | msgstr "" 86 | 87 | #: lib/class.publication-widget.php:52 88 | msgid "Leave blank for no limit." 89 | msgstr "" 90 | 91 | #: lib/class.publication-widget.php:54 92 | msgid "Order by" 93 | msgstr "" 94 | 95 | #: lib/class.publication-widget.php:55 96 | msgid "Manual (drag and drop)" 97 | msgstr "" 98 | 99 | #: lib/class.publication-widget.php:56 100 | msgid "Latest (publish date)" 101 | msgstr "" 102 | 103 | #: lib/class.wp-publication-archive-cat-count-widget.php:27 104 | msgid "A list or dropdown of publication categories." 105 | msgstr "" 106 | 107 | #: lib/class.wp-publication-archive-cat-count-widget.php:29 108 | #: lib/class.wp-publication-archive-cat-count-widget.php:94 109 | msgid "Publication Categories" 110 | msgstr "" 111 | 112 | #: lib/class.wp-publication-archive-cat-count-widget.php:51 113 | #: lib/class.wp-publication-archive-category-widget.php:54 114 | msgid "Title:" 115 | msgstr "" 116 | 117 | #: lib/class.wp-publication-archive-cat-count-widget.php:60 118 | msgid "Display as dropdown" 119 | msgstr "" 120 | 121 | #: lib/class.wp-publication-archive-cat-count-widget.php:65 122 | #: lib/class.wp-publication-archive-category-widget.php:61 123 | msgid "Show publication counts" 124 | msgstr "" 125 | 126 | #: lib/class.wp-publication-archive-cat-count-widget.php:105 127 | msgid "Select Category" 128 | msgstr "" 129 | 130 | #: lib/class.wp-publication-archive-category-widget.php:25 131 | msgid "A list of related publications (based on category)." 132 | msgstr "" 133 | 134 | #: lib/class.wp-publication-archive-category-widget.php:27 135 | #: lib/class.wp-publication-archive-category-widget.php:44 136 | #: lib/class.wp-publication-archive-category-widget.php:91 137 | msgid "Related Publications" 138 | msgstr "" 139 | 140 | #: lib/class.wp-publication-archive-utilities.php:49 141 | msgid "Utilities object already initialized" 142 | msgstr "" 143 | 144 | #: lib/class.wp-publication-archive-utilities.php:186 145 | msgid "No categories" 146 | msgstr "" 147 | 148 | #: lib/class.wp-publication-archive-utilities.php:201 149 | msgid "Categories" 150 | msgstr "" 151 | 152 | #: lib/class.wp-publication-archive.php:407 153 | msgid "Publications" 154 | msgstr "" 155 | 156 | #: lib/class.wp-publication-archive.php:408 157 | #: lib/class.wp-publication-archive.php:478 158 | msgid "Publication" 159 | msgstr "" 160 | 161 | #: lib/class.wp-publication-archive.php:409 162 | msgid "Add New Publication" 163 | msgstr "" 164 | 165 | #: lib/class.wp-publication-archive.php:411 166 | msgid "New Publication" 167 | msgstr "" 168 | 169 | #: lib/class.wp-publication-archive.php:412 170 | msgid "View Publication" 171 | msgstr "" 172 | 173 | #: lib/class.wp-publication-archive.php:413 174 | msgid "Search Publications" 175 | msgstr "" 176 | 177 | #: lib/class.wp-publication-archive.php:414 178 | msgid "No publications found" 179 | msgstr "" 180 | 181 | #: lib/class.wp-publication-archive.php:415 182 | msgid "No publications found in trash" 183 | msgstr "" 184 | 185 | #: lib/class.wp-publication-archive.php:449 186 | #: lib/class.wp-publication-archive.php:458 187 | #: lib/class.wp-publication-archive.php:467 188 | msgid "Authors" 189 | msgstr "" 190 | 191 | #: lib/class.wp-publication-archive.php:450 192 | msgid "Author" 193 | msgstr "" 194 | 195 | #: lib/class.wp-publication-archive.php:451 196 | msgid "Search Authors" 197 | msgstr "" 198 | 199 | #: lib/class.wp-publication-archive.php:452 200 | msgid "Popular Authors" 201 | msgstr "" 202 | 203 | #: lib/class.wp-publication-archive.php:453 204 | msgid "All Authors" 205 | msgstr "" 206 | 207 | #: lib/class.wp-publication-archive.php:454 208 | msgid "Edit Author" 209 | msgstr "" 210 | 211 | #: lib/class.wp-publication-archive.php:455 212 | msgid "Update Author" 213 | msgstr "" 214 | 215 | #: lib/class.wp-publication-archive.php:456 216 | msgid "Add New Author" 217 | msgstr "" 218 | 219 | #: lib/class.wp-publication-archive.php:457 220 | msgid "New Author Name" 221 | msgstr "" 222 | 223 | #: lib/class.wp-publication-archive.php:479 224 | msgid "Alternate Files" 225 | msgstr "" 226 | 227 | #: lib/class.wp-publication-archive.php:480 228 | msgid "Thumbnail" 229 | msgstr "" 230 | 231 | #: lib/class.wp-publication-archive.php:492 232 | msgid "Please provide the absolute url of the file (including the http://):" 233 | msgstr "" 234 | 235 | #: lib/class.wp-publication-archive.php:494 236 | #: lib/class.wp-publication-archive.php:511 237 | msgid "Upload Publication" 238 | msgstr "" 239 | 240 | #: lib/class.wp-publication-archive.php:529 241 | msgid "Please provide the absolute url for a thumbnail image (including the http://):" 242 | msgstr "" 243 | 244 | #: lib/class.wp-publication-archive.php:531 245 | #: lib/class.wp-publication-archive.php:548 246 | msgid "Upload Thumbnail" 247 | msgstr "" 248 | 249 | #: lib/class.wp-publication-archive.php:566 250 | msgid "These files are considered alternates to the publication listed above (i.e. foreign language translations of the same document)." 251 | msgstr "" 252 | 253 | #: lib/class.wp-publication-archive.php:574 254 | #: lib/class.wp-publication-archive.php:581 255 | #: lib/class.wp-publication-archive.php:622 256 | msgid "upload" 257 | msgstr "" 258 | 259 | #: lib/class.wp-publication-archive.php:574 260 | #: lib/class.wp-publication-archive.php:581 261 | #: lib/class.wp-publication-archive.php:630 262 | msgid "delete" 263 | msgstr "" 264 | 265 | #: lib/class.wp-publication-archive.php:586 266 | msgid "Add Row" 267 | msgstr "" 268 | 269 | #: lib/class.wp-publication-archive.php:662 270 | msgid "Upload Alternate" 271 | msgstr "" 272 | 273 | #: lib/class.wp-publication-archive.php:777 274 | msgid " Sorry, but the categories you passed to the wp-publication-archive shortcode do not match any publication categories." 275 | msgstr "" 276 | 277 | #: lib/class.wp-publication-archive.php:777 278 | msgid "You passed: " 279 | msgstr "" 280 | 281 | #: lib/class.wp-publication-archive.php:801 282 | msgid "There are no publications to display" 283 | msgstr "" 284 | 285 | #: lib/class.wp-publication-archive.php:803 286 | msgid " by " 287 | msgstr "" 288 | 289 | #: lib/class.wp-publication-archive.php:806 290 | msgid " categorized " 291 | msgstr "" 292 | 293 | #: lib/class.wp-publication-archive.php:962 294 | #, php-format 295 | msgid "%s (Publication)" 296 | msgstr "" 297 | 298 | -------------------------------------------------------------------------------- /lib/class.mimetype.php: -------------------------------------------------------------------------------- 1 | . 4 | * Updated 2012 Eric Mann . 5 | * 6 | * All rights reserved. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * 3. Neither the name of the project nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 | * SUCH DAMAGE. 35 | */ 36 | 37 | /** 38 | * Name: PHP MimeType Class 39 | * 40 | * Version: 2.0 41 | * 1.0 Released: 10/20/02 42 | * 2.0 Updated: 10/02/12 43 | * 44 | * Description: This class allows a PHP script to determine the mime type 45 | * a file based on the file extension. This class is handy for PHP versions 46 | * without the benefit of other tools to determine the mime type. The class 47 | * defaults to octet-stream so if the file type is not recognized the user 48 | * is presented with a file download prompt. 49 | * 50 | * NOTES: The mime types for this version are based on Apache 1.3.27 51 | * mime types may change or need to be added in the future, the mime types 52 | * are stored in an array so that an awk or other script can automatically 53 | * generate the code to make the array. 54 | * 55 | * Usage: 56 | * 57 | * First an instance of the mimetype class must be created, then the 58 | * getType method should be called with the filename. It will return 59 | * the mime type, an example follows. 60 | * 61 | * Example: 62 | * 63 | * $mimetype = new mimetype(); 64 | * print $mimetype->getType('acrobat.pdf'); 65 | * 66 | * Author: Jason Sheets 67 | * Update Author: Eric Mann 68 | * 69 | * License: This script is distributed under the BSD License, you are free 70 | * to use, or modify it however you like. If you find this script useful please 71 | * e-mail me. 72 | */ 73 | 74 | class mimetype { 75 | /** 76 | * @var array MIME Type pairings. 77 | */ 78 | private $types = array(); 79 | 80 | /** 81 | * Default constructor. Populates MIME type array. 82 | */ 83 | public function __construct() { 84 | $this->types = array( 85 | "ez" => "application/andrew-inset", 86 | "hqx" => "application/mac-binhex40", 87 | "cpt" => "application/mac-compactpro", 88 | "doc" => "application/msword", 89 | "bin" => "application/octet-stream", 90 | "dms" => "application/octet-stream", 91 | "lha" => "application/octet-stream", 92 | "lzh" => "application/octet-stream", 93 | "exe" => "application/octet-stream", 94 | "class" => "application/octet-stream", 95 | "so" => "application/octet-stream", 96 | "dll" => "application/octet-stream", 97 | "oda" => "application/oda", 98 | "pdf" => "application/pdf", 99 | "ai" => "application/postscript", 100 | "eps" => "application/postscript", 101 | "ps" => "application/postscript", 102 | "smi" => "application/smil", 103 | "smil" => "application/smil", 104 | "wbxml" => "application/vnd.wap.wbxml", 105 | "wmlc" => "application/vnd.wap.wmlc", 106 | "wmlsc" => "application/vnd.wap.wmlscriptc", 107 | "bcpio" => "application/x-bcpio", 108 | "vcd" => "application/x-cdlink", 109 | "pgn" => "application/x-chess-pgn", 110 | "cpio" => "application/x-cpio", 111 | "csh" => "application/x-csh", 112 | "dcr" => "application/x-director", 113 | "dir" => "application/x-director", 114 | "dxr" => "application/x-director", 115 | "dvi" => "application/x-dvi", 116 | "spl" => "application/x-futuresplash", 117 | "gtar" => "application/x-gtar", 118 | "hdf" => "application/x-hdf", 119 | "js" => "application/x-javascript", 120 | "skp" => "application/x-koan", 121 | "skd" => "application/x-koan", 122 | "skt" => "application/x-koan", 123 | "skm" => "application/x-koan", 124 | "latex" => "application/x-latex", 125 | "nc" => "application/x-netcdf", 126 | "cdf" => "application/x-netcdf", 127 | "sh" => "application/x-sh", 128 | "shar" => "application/x-shar", 129 | "swf" => "application/x-shockwave-flash", 130 | "sit" => "application/x-stuffit", 131 | "sv4cpio" => "application/x-sv4cpio", 132 | "sv4crc" => "application/x-sv4crc", 133 | "tar" => "application/x-tar", 134 | "tcl" => "application/x-tcl", 135 | "tex" => "application/x-tex", 136 | "texinfo" => "application/x-texinfo", 137 | "texi" => "application/x-texinfo", 138 | "t" => "application/x-troff", 139 | "tr" => "application/x-troff", 140 | "roff" => "application/x-troff", 141 | "man" => "application/x-troff-man", 142 | "me" => "application/x-troff-me", 143 | "ms" => "application/x-troff-ms", 144 | "ustar" => "application/x-ustar", 145 | "src" => "application/x-wais-source", 146 | "xhtml" => "application/xhtml+xml", 147 | "xht" => "application/xhtml+xml", 148 | "zip" => "application/octet-stream", 149 | "au" => "audio/basic", 150 | "snd" => "audio/basic", 151 | "mid" => "audio/midi", 152 | "midi" => "audio/midi", 153 | "kar" => "audio/midi", 154 | "mpga" => "audio/mpeg", 155 | "mp2" => "audio/mpeg", 156 | "mp3" => "audio/mpeg", 157 | "aif" => "audio/x-aiff", 158 | "aiff" => "audio/x-aiff", 159 | "aifc" => "audio/x-aiff", 160 | "m3u" => "audio/x-mpegurl", 161 | "ram" => "audio/x-pn-realaudio", 162 | "rm" => "audio/x-pn-realaudio", 163 | "rpm" => "audio/x-pn-realaudio-plugin", 164 | "ra" => "audio/x-realaudio", 165 | "wav" => "audio/x-wav", 166 | "pdb" => "chemical/x-pdb", 167 | "xyz" => "chemical/x-xyz", 168 | "bmp" => "image/bmp", 169 | "gif" => "image/gif", 170 | "ief" => "image/ief", 171 | "jpeg" => "image/jpeg", 172 | "jpg" => "image/jpeg", 173 | "jpe" => "image/jpeg", 174 | "png" => "image/png", 175 | "tiff" => "image/tiff", 176 | "tif" => "image/tif", 177 | "djvu" => "image/vnd.djvu", 178 | "djv" => "image/vnd.djvu", 179 | "wbmp" => "image/vnd.wap.wbmp", 180 | "ras" => "image/x-cmu-raster", 181 | "pnm" => "image/x-portable-anymap", 182 | "pbm" => "image/x-portable-bitmap", 183 | "pgm" => "image/x-portable-graymap", 184 | "ppm" => "image/x-portable-pixmap", 185 | "rgb" => "image/x-rgb", 186 | "xbm" => "image/x-xbitmap", 187 | "xpm" => "image/x-xpixmap", 188 | "xwd" => "image/x-windowdump", 189 | "igs" => "model/iges", 190 | "iges" => "model/iges", 191 | "msh" => "model/mesh", 192 | "mesh" => "model/mesh", 193 | "silo" => "model/mesh", 194 | "wrl" => "model/vrml", 195 | "vrml" => "model/vrml", 196 | "css" => "text/css", 197 | "html" => "text/html", 198 | "htm" => "text/html", 199 | "asc" => "text/plain", 200 | "txt" => "text/plain", 201 | "rtx" => "text/richtext", 202 | "rtf" => "text/rtf", 203 | "sgml" => "text/sgml", 204 | "sgm" => "text/sgml", 205 | "tsv" => "text/tab-seperated-values", 206 | "wml" => "text/vnd.wap.wml", 207 | "wmls" => "text/vnd.wap.wmlscript", 208 | "etx" => "text/x-setext", 209 | "xml" => "text/xml", 210 | "xsl" => "text/xml", 211 | "mpeg" => "video/mpeg", 212 | "mpg" => "video/mpeg", 213 | "mpe" => "video/mpeg", 214 | "qt" => "video/quicktime", 215 | "mov" => "video/quicktime", 216 | "mxu" => "video/vnd.mpegurl", 217 | "avi" => "video/x-msvideo", 218 | "movie" => "video/x-sgi-movie", 219 | "ice" => "x-conference-xcooltalk", 220 | "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 221 | "pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", 222 | "xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 223 | ); 224 | } 225 | 226 | /** 227 | * Add a new MIME type to the internal array. 228 | * 229 | * @param string $extension Extension to add. 230 | * @param string $type MIME type of extension. Defaults to 'application/octet-stream'. 231 | */ 232 | public function add_type( $extension, $type = 'application/octet-stream' ) { 233 | $this->types[$extension] = $type; 234 | } 235 | 236 | /** 237 | * Remove a MIME tyoe from the internal array. 238 | * 239 | * @param string $extension Extension to remove. 240 | */ 241 | public function remove_type( $extension ) { 242 | unset( $this->types[$extension] ); 243 | } 244 | 245 | /** 246 | * Get a MIME type from a given file name based on the file extension. 247 | * 248 | * @param string $filename Filename to check. 249 | * 250 | * @return string Assumed extension. 251 | */ 252 | function getType( $filename ) { 253 | // get base name of the filename provided by user 254 | $filename = basename( $filename ); 255 | 256 | // break file into parts seperated by . 257 | $parts = explode( '.', $filename ); 258 | 259 | // take the last part of the file to get the file extension 260 | $extension = $parts[count( $parts ) - 1]; 261 | 262 | // find mime type 263 | if ( isset( $this->types[$extension] ) ) { 264 | return $this->types[$extension]; 265 | } else { 266 | return 'application/octet-stream'; 267 | } 268 | } 269 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === WP Publication Archive === 2 | Contributors: ericmann 3 | Donate link: http://jumping-duck.com/wordpress/plugins 4 | Tags: document management, pdf, doc, archive 5 | Requires at least: 3.5 6 | Tested up to: 3.6 7 | Stable tag: 3.0.1 8 | License: GPLv2 9 | 10 | Allows users to upload, manage, search, and download publications, documents, and similar content (PDF, Power-Point, etc.). 11 | 12 | == Description == 13 | 14 | WP Publication Archive adds a custom content type for storing, tagging, and categorizing downloadable content external to standard WordPress posts and pages. You can add downloadable PDF files, Word documents, and PowerPoint presentations. These files will be stored in the standard WordPress uploads directory but will be managed separately through a custom post type interface in the WordPress admin area. 15 | 16 | == Installation == 17 | 18 | 1. Upload the entire `wp-publication-archive` folder to the `/wp-content/plugins/` directory 19 | 1. Activate the plugin through the 'Plugins' menu in WordPress 20 | 1. Use the "Add Publications" menu to begin adding publications. 21 | 1. Use the built-in menu system to manage your publications. 22 | 23 | == Frequently Asked Questions == 24 | 25 | = How do I upload a new file? = 26 | 27 | **Option 1:** Use the built-in media uploader on the "Add Publication" screen. 28 | 29 | **Option 2:** Upload a file to your server via FTP (or to a remote host like AWS) and place the *full* URL (including the `http://`) in the Publication field on the Edit Publication page. 30 | 31 | = How do I list my publications? = 32 | 33 | You can display a list of publications either by includeing the [wp-publication-archive] shortcode on a post/page or by placing in your theme template files. WordPress will render your publication list automatically. 34 | 35 | = Can I show publications in a dropdown rather than as a list? = 36 | 37 | Yes! Simply add `showas="dropdown"` as a parameter within the regular shortcode, and the plugin will use a dropdown template rather than a list template. For example: 38 | 39 | [wp-publication-archive showas="dropdown" /] 40 | 41 | = Can I filter the list by category = 42 | 43 | Yes! Just include `categories="cat1,cat2"` in your shortcode where "cat1" and "cat2" are the *names* of the categories you want to display. 44 | 45 | = Can I filter the list by author? = 46 | 47 | Yes! Just include `author="author-name"` in your shortcode where "author-name" is the *slug* of the author you want to display. 48 | 49 | = What File Types are Available = 50 | 51 | By default, the plug-in contains icons for several common file types. The icons include: 52 | 53 | - Standard document files 54 | - Spreadsheet formats (i.e. Excel, Open Office Calc) 55 | - Video 56 | - Image 57 | - Audio 58 | - Adobe PDF 59 | - Zip 60 | 61 | All other file types will feature a generic "file" icon. 62 | 63 | = Some of my files aren't downloading. What's wrong? = 64 | 65 | There could be any of a hundred causes for this. Most likely, your files are just too large to be handled by your server. 66 | 67 | By default, both file opens and downloads are streamed to your server. This means the plugin will attempt to open the file (whether it's remote or locally-hosted) and will stream the contents of the file to the browser. This has the advantage of never exposing the raw download URL to the user.* 68 | 69 | Unfortunately, it means your server has to download the file first before it can pass it along to the user. For smaller files, this isn't an issue. But for much larger files, connections can time out. 70 | 71 | If you are serving large files, you can force the **file open** URL to forward connections rather than stream them. This means requests to your file open URL (i.e. `http://site.com/publication/title/wppa_open`) will receive a 303 "See Other" redirect pointing them to the original resource. It's less work for your server, but the end user *will* see the original URL. 72 | 73 | Just add `add_filter( 'wppa_mask_url', '__return_false' );` to your `functions.php` file to turn off URL masking and use the redirect method instead. 74 | 75 | When you add this filter, the **file download** URL will behave the exact same way - redirecting requests to the original resource rather than streaming the file to the browser. Unfortunately, this leaves the exact behavior of the link up to the browser - some will attempt to download the file, some will open it instead. 76 | 77 | * A future version of the plugin will allow you to have password-protected downloads. Hiding the raw URL of a file is important for this feature to work. 78 | 79 | = How do I use the thumbnail feature? = 80 | 81 | Thumbnail support is extended through the plugin, but not actually implemented in any templates. You can upload a custom thumbnail for each Publication, and the URL will be stored in the Publication's meta field in the database under the `wpa-upload_image` key. 82 | 83 | You can get the raw thumbnail URL by requesting it directly with `get_post_meta()`. Alternatively, the `WP_Publication_Archive_Item` class contains some useful helper methods for printing the thumbnail URL wrapped in proper HTML tags. You can use code similar to the following: 84 | 85 | ID, $pub->post_title, $pub->post_date ); 88 | 89 | // Return the Publication thumbnail for use elsewhere 90 | $thumb = $pub->get_the_thumbnail(); 91 | 92 | // Echo/print the thumbnail to the browser 93 | $pub->the_thumbnail(); 94 | 95 | These helper methods will generate HTML tags similar to: 96 | 97 |
98 | 99 |
100 | 101 | Also, the actual thumbnail URL printed will be passed through a filter. You can intercept this and do whatever you need to with the URL (add query arguments, switch http/https protocols, etc). 102 | 103 | add_filter( 'wpa-upload_image', 'your_custom_function', 10, 2 ); 104 | 105 | The filter passes two arguments, the raw URL for the thumbnail and the ID of the publication. 106 | 107 | = Why are some files downloaded even though I clicked "open?" = 108 | 109 | The open behavior is 100% dependent on your browser. In some cases (i.e. PDFs) the file will open in the browser using a built-in viewer. In other cases (i.e. Zips) there is no in-browser viewer for that file type, so the browser will download the file instead. 110 | 111 | The plugin makes every attempt possible to return the correct MIME type for each file so that the browser know what to do with it. But in some cases (i.e. Zips or unknown file types), the plugin will return a type of `application/octet-stream` which the browser sees as a generic file and just downloads to a generic, often extensonless, filename. 112 | 113 | If you're coming up against a situation like this, I recommend you use the Download link instead. 114 | 115 | == Screenshots == 116 | 117 | No screenshots are available at this time. 118 | 119 | == Changelog == 120 | 121 | = 3.0.1 122 | * Revert the dropdown template's file opening functionality to auto-open the file 123 | 124 | = 3.0 = 125 | * Add publication landing pages (with template) 126 | * Add publication archive pages (with template) 127 | * Update streaming methods to use `readfile()` 128 | * Allow category archives for publications 129 | * Add category count widget for publications 130 | * Add related publication sidebar widget 131 | * Update content field to store summary in post content 132 | 133 | = 2.5.7.2 = 134 | * Fix a short PHP open tag. 135 | 136 | = 2.5.7.1 = 137 | * Hotfix to correct a search term issue. 138 | 139 | = 2.5.7 = 140 | * Normalize PHP file endings to remove extra whitespace. 141 | 142 | = 2.5.6 = 143 | * Fix a data sanitation but that was mistakenly removing links from publication summaries. 144 | 145 | = 2.5.5 = 146 | * Fix a broken include path for the Widget. 147 | * Allow targetting a blank tab/window with the `wp_pubarch_open_in_blank` filter. 148 | 149 | = 2.5.4 = 150 | * Convert `wppa_` function and translation prefix to `wp_pubarch_` to avoid a conflict with WP Photo Album +. 151 | * Update strings 152 | 153 | = 2.5.3 = 154 | * Re-add a deprecated tag that I thought no one was actually using. 155 | 156 | = 2.5.2 = 157 | * Fix an issue caused by unnecessary whitespace. 158 | 159 | = 2.5.1 = 160 | * Add some checking to prevent All-in-One Event Calendar from triggering a warning with an improper filter call. 161 | 162 | = 2.5 = 163 | * Removed antiquated openfile.php (allow direct file downloads). 164 | * Made the publication list template-ready. 165 | * Change the "download" link to a pair of "download" or "open" links. 166 | * Included publication description in WordPress search. 167 | * Enable URL masking for file downloads. 168 | 169 | = 2.3.4 = 170 | * Add thumbnail support 171 | 172 | = 2.3.3 = 173 | * Immediate fix to a typo 174 | 175 | = 2.3.2.1 = 176 | * Add "author" filter to shortcode 177 | 178 | = 2.3.2 = 179 | * Fixes pagination bug 180 | * Fixes issue where some installations could not load files starting with "http://" 181 | 182 | = 2.3.1 = 183 | * URGENT SECURITY UPDATE 184 | * Fix some outstanding bugs 185 | 186 | = 2.3 = 187 | * Add publications to standard WordPress search results 188 | 189 | = 2.2 = 190 | * Add pagination for more than 10 publications 191 | * Add category filter to shortcode 192 | 193 | = 2.1.1 = 194 | * Remove an extra space that was throwing a PHP parsing error 195 | 196 | = 2.1.0 = 197 | * Remove erroneous CSS declaration from post/page edit screens 198 | * Silence a $_POST[] error 199 | * Fix a typo on displaying the list of archived files 200 | * Adds simple pagination 201 | 202 | = 2.0.1 = 203 | * Fix PHP error in bootstrap function 204 | 205 | = 2.0 = 206 | * Rewrite plug-in to use custom post types rather than extra database tables 207 | * Add new UI for adding publications 208 | * Hard-code file type icons 209 | 210 | = 1.1.1 = 211 | * Minor repairs to abanoned script to make it compatible with WP>2.5 212 | 213 | = 1.1 = 214 | * Original release of WP Publications Archive by Luis Lino 215 | 216 | == Upgrade Notice == 217 | 218 | = 3.0 = 219 | Please flush your permalinks by visiting the Settings >> Permalinks page in WordPress, otherwise your download links WILL NOT WORK. 220 | 221 | = 2.5 = 222 | Major changes have been made to the way publications are linked and downloaded. If you had previously changed any code for `openfile.php` or the linking/downloading mechanism, be prepared to manually update your Publications should any of them break. 223 | 224 | = 2.3.1 = 225 | URGENT SECURITY UPDATE!!! 226 | 227 | = 2.2 = 228 | This version will *only* work with PHP 5 or above! 229 | 230 | = 2.0 = 231 | Upgrading from 1.1 or 1.1.1 to 2.0 will *not* automatically transfer your publications to the new system. 232 | 233 | == Licenses == 234 | 235 | WP Publication Archive is licensed under the GNU General Public License, version 2. 236 | 237 | This system was based on the original wp-publications-archive plug-in published by Luis Lino and Siemens Networks, S.A. at http://code.google.com/p/wp-publications-archive/. 238 | 239 | The filing cabinet menu icon was created by Glyphish (http://glyphish.com) and is distributed under a Creative Commons Attribution license. 240 | 241 | Filetype icons come from the Crystal Project (http://www.everaldo.com/crystal/) released under the LGPL (http://www.everaldo.com/crystal/?action=license). -------------------------------------------------------------------------------- /lib/class.publication-markup.php: -------------------------------------------------------------------------------- 1 | post = $post; 116 | 117 | $this->ID = $post->ID; 118 | $this->title = $post->post_title; 119 | $this->date = $post->post_date; 120 | $this->content = get_the_content(); 121 | $this->summary = get_the_excerpt(); 122 | 123 | $this->upload_image = get_post_meta( $this->ID, 'wpa-upload_image', true ); 124 | $this->uri = get_post_meta( $this->ID, 'wpa_upload_doc', true ); 125 | $this->filename = basename( $this->uri ); 126 | 127 | // Filter legacy URLs to strip out bad pipes 128 | $this->uri = str_replace( 'http|', 'http://', $this->uri ); 129 | $this->uri = str_replace( 'https|', 'https://', $this->uri ); 130 | 131 | // Build the keywords string 132 | $tags = wp_get_post_tags( $this->ID ); 133 | if ( count( $tags ) > 0 ) { 134 | $this->keyword_array = wp_list_pluck( $tags, 'name' ); 135 | $this->keywords = implode( ', ', $this->keyword_array ); 136 | } else { 137 | $this->keywords = false; 138 | } 139 | 140 | // Build out the category string 141 | $cats = get_the_category( $this->ID ); 142 | if ( count( $cats ) > 0 ) { 143 | $this->category_array = wp_list_pluck( $cats, 'name' ); 144 | $this->categories = implode( ', ', $this->category_array ); 145 | } else { 146 | $this->categories = false; 147 | } 148 | 149 | // Build out the author string 150 | $auths = wp_get_post_terms( $this->ID, 'publication-author' ); 151 | if ( count( $auths ) > 0 ) { 152 | $this->author_array = wp_list_pluck( $auths, 'name' ); 153 | $this->authors = implode( ', ', $this->author_array ); 154 | } else { 155 | $this->authors = false; 156 | } 157 | 158 | // Build out alternates array 159 | $this->alternates = get_post_meta( $this->ID, 'wpa-upload_alternates' ); 160 | 161 | wp_reset_postdata(); 162 | } 163 | 164 | /** 165 | * Get markup for the publication title. 166 | * 167 | * @uses apply_filters() Calls 'wpa-title' to modify the publication title. 168 | * 169 | * @param string $before 170 | * @param string $after 171 | * 172 | * @return string 173 | */ 174 | public function get_the_title( $before = '
', $after = '
' ) { 175 | $title = ''; 176 | $title .= apply_filters( 'wpa-title', $this->title, $this->ID ); 177 | $title .= ''; 178 | 179 | return $before . $title . $after; 180 | } 181 | 182 | /** 183 | * Echo the markup for the publication title. 184 | * 185 | * @see WP_Publication_Archive_Item::get_the_title() 186 | */ 187 | public function the_title() { 188 | echo $this->get_the_title(); 189 | } 190 | 191 | /** 192 | * Get markup for the publication thumbnail image. 193 | * 194 | * @uses apply_filters() Calls 'wpa-upload_image' to modify the thumbnail URL. 195 | * 196 | * @param string $before 197 | * @param string $after 198 | * 199 | * @return string 200 | */ 201 | public function get_the_thumbnail( $before = '
', $after = '
' ) { 202 | $thumb = apply_filters( 'wpa-upload_image', $this->upload_image, $this->ID ); 203 | 204 | if ( '' == trim( $thumb ) ) { 205 | return ''; 206 | } 207 | 208 | return $before . '' . $after; 209 | } 210 | 211 | /** 212 | * Echo the markup for the publication thumbnail. 213 | * 214 | * @see WP_Publication_Archive_Item::get_the_thumbnail() 215 | */ 216 | public function the_thumbnail() { 217 | echo $this->get_the_thumbnail(); 218 | } 219 | 220 | /** 221 | * Get a list of authors for the publication. Also gets the date bound to the publication object. 222 | * 223 | * @uses apply_filters() Calls 'wpa-authors' to modify the author's list. 224 | * 225 | * @param string $before 226 | * @param string $after 227 | * 228 | * @return string 229 | */ 230 | public function get_the_authors( $before = '
', $after = '
' ) { 231 | $authors = apply_filters( 'wpa-authors', $this->authors, $this->ID ); 232 | 233 | $list = ''; 234 | 235 | if ( $authors ) { 236 | $list = '' . $authors . ''; 237 | } 238 | 239 | $date = '(' . date( 'F j, Y', strtotime( $this->date ) ) . ')'; 240 | 241 | return $before . $list . $date . $after; 242 | } 243 | 244 | /** 245 | * Echos the markup for the authors of the publication. 246 | * 247 | * @see WP_Publication_Archive_Item::get_the_authors() 248 | */ 249 | public function the_authors() { 250 | echo $this->get_the_authors(); 251 | } 252 | 253 | /** 254 | * Get the file open link for the current publication. 255 | * 256 | * @return string Download link. 257 | * 258 | * @see WP_Publication_Archive::get_open_link() 259 | */ 260 | public function get_the_link() { 261 | return WP_Publication_Archive::get_open_link( $this->ID ); 262 | } 263 | 264 | /** 265 | * Get the markup for the publication download links. 266 | * 267 | * @see mimetype 268 | * 269 | * @uses WP_Publication_Archive::get_image() 270 | * @uses WP_Publication_Archive::get_open_link() 271 | * @uses WP_Publication_Archive::get_download_link() 272 | * 273 | * @return string 274 | */ 275 | public function get_the_uri() { 276 | $mime = new mimetype(); 277 | 278 | $uri = $this->get_the_link(); 279 | if ( '' == trim( $uri ) ) 280 | return ''; 281 | 282 | $output = '
'; 283 | $output .= '' . $this->filename . ' '; 284 | $output .= ''; 285 | $output .= 'download '; 286 | $output .= 'ID ) . '">'; 291 | $output .= __( 'View', 'wp_pubarch_translate' ) . ' | '; 292 | $output .= ''; 293 | $output .= __( 'Download', 'wp_pubarch_translate' ) . ''; 294 | $output .= ''; 295 | $output .= '
'; 296 | 297 | return $output; 298 | } 299 | 300 | /** 301 | * Echos the markup for publication download links. 302 | * 303 | * @see WP_Publication_Archive_Item::get_the_uri() 304 | */ 305 | public function the_uri() { 306 | echo $this->get_the_uri(); 307 | } 308 | 309 | /** 310 | * Gets the markup for the publication summary. 311 | * 312 | * @uses apply_filters() Calls 'wpa-summary' to modify the publication summary. 313 | * 314 | * @return string 315 | */ 316 | public function get_the_summary() { 317 | $before = '
'; 318 | $before .= 'Summary: '; 319 | $before .= ''; 320 | 321 | $after = '
'; 322 | 323 | $summary = apply_filters( 'wpa-summary', $this->summary, $this->ID ); 324 | 325 | if ( $summary != '' ) { 326 | return $before . $summary . $after; 327 | } 328 | } 329 | 330 | /** 331 | * Echo the markup for the publication summary. 332 | * 333 | * @see WP_Publication_Archive_Item::get_the_summary() 334 | */ 335 | public function the_summary() { 336 | echo $this->get_the_summary(); 337 | } 338 | 339 | /** 340 | * Get the markup for the publication keyword list. 341 | * 342 | * @uses apply_filters() Calls 'wpa-keywords' to modify the publication keyword list. 343 | * 344 | * @return string 345 | */ 346 | public function get_the_keywords() { 347 | $before = '
'; 348 | $before .= 'Keywords: '; 349 | $before .= ''; 350 | 351 | $after = '
'; 352 | 353 | $keywords = apply_filters( 'wpa-keywords', $this->keywords, $this->ID ); 354 | 355 | if ( $keywords != '' ) { 356 | return $before . $keywords . $after; 357 | } 358 | } 359 | 360 | /** 361 | * Echo the publication keyword list. 362 | * 363 | * @see WP_Publication_Archive_Item::get_the_keywords() 364 | */ 365 | public function the_keywords() { 366 | echo $this->get_the_keywords(); 367 | } 368 | 369 | /** 370 | * Get the markup for the publication category list. 371 | * 372 | * @uses apply_filters() Calls 'wpa-categories' to modify the publication category list. 373 | * 374 | * @return string 375 | */ 376 | public function get_the_categories() { 377 | $before = '
'; 378 | $before .= 'Categories: '; 379 | $before .= ''; 380 | 381 | $after = '
'; 382 | 383 | $categories = apply_filters( 'wpa-categories', $this->categories, $this->ID ); 384 | 385 | if ( $categories != '' ) { 386 | return $before . $categories . $after; 387 | } 388 | } 389 | 390 | /** 391 | * Echo the publication category list. 392 | * 393 | * @see WP_Publication_Archive_Item::get_the_categories() 394 | */ 395 | public function the_categories() { 396 | echo $this->get_the_categories(); 397 | } 398 | 399 | /** 400 | * List out the downloads associated with this publication 401 | */ 402 | public function list_downloads() { 403 | if ( count( $this->alternates ) == 0 ) { 404 | return; 405 | } 406 | 407 | echo '' . __( 'Other Files:', 'wp_pubarch_translate' ) . ' '; 408 | echo ''; 417 | } 418 | } -------------------------------------------------------------------------------- /lib/class.wp-publication-archive-utilities.php: -------------------------------------------------------------------------------- 1 | '', 103 | 'show_option_none' => '', 104 | 'orderby' => 'id', 105 | 'order' => 'ASC', 106 | 'show_count' => 0, 107 | 'hide_empty' => 1, 108 | 'child_of' => 0, 109 | 'exclude' => '', 110 | 'echo' => 1, 111 | 'selected' => 0, 112 | 'name' => 'wp_pubarch_cat', 113 | 'id' => '', 114 | 'class' => 'postform', 115 | 'depth' => 0, 116 | 'tab_index' => 0, 117 | 'taxonomy' => 'category', 118 | 'hide_if_empty' => false, 119 | 'post_types' => array( 'publication' ) 120 | ); 121 | 122 | $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; 123 | 124 | $args = wp_parse_args( $args, $defaults ); 125 | 126 | if ( ! isset( $args['pad_counts'] ) && $args['show_count'] ) { 127 | $args['pad_counts'] = true; 128 | } 129 | 130 | $tab_index_attribute = ''; 131 | if ( (int) $args['tab_index'] > 0 ) { 132 | $tab_index_attribute = ' tabindex="' . $args['tab_index'] . '"'; 133 | } 134 | 135 | $categories = $this->get_terms( $args['taxonomy'], $args ); 136 | 137 | $name = esc_attr( $args['name'] ); 138 | $class = esc_attr( $args['class'] ); 139 | $id = $args['id'] ? esc_attr( $args['id'] ) : $name; 140 | 141 | if ( ! $args['hide_if_empty'] || ! empty( $categories ) ) { 142 | $output = "\n"; 173 | 174 | $output = apply_filters( 'wp_dropdown_cats', $output ); 175 | 176 | if ( $args['echo'] ) { 177 | echo $output; 178 | } 179 | 180 | return $output; 181 | } 182 | 183 | public function list_categories( $args = '' ) { 184 | $defaults = array( 185 | 'show_option_all' => '', 186 | 'show_option_none' => __( 'No categories' ), 187 | 'orderby' => 'name', 188 | 'order' => 'ASC', 189 | 'style' => 'list', 190 | 'show_count' => 0, 191 | 'hide_empty' => 1, 192 | 'use_desc_for_title' => 1, 193 | 'child_of' => 0, 194 | 'feed' => '', 195 | 'feed_type' => '', 196 | 'feed_image' => '', 197 | 'exclude' => '', 198 | 'exclude_tree' => '', 199 | 'current_category' => 0, 200 | 'hierarchical' => true, 201 | 'title_li' => __( 'Categories' ), 202 | 'echo' => 1, 203 | 'depth' => 0, 204 | 'taxonomy' => 'category', 205 | 'post_types' => array( 'publication' ) 206 | ); 207 | 208 | $args = wp_parse_args( $args, $defaults ); 209 | 210 | if ( !isset( $args['pad_counts'] ) && $args['show_count'] && $args['hierarchical'] ) { 211 | $args['pad_counts'] = true; 212 | } 213 | 214 | if ( !isset( $args['class'] ) ) { 215 | $args['class'] = ( 'category' === $args['taxonomy'] ) ? 'categories' : $args['taxonomy']; 216 | } 217 | 218 | if ( !taxonomy_exists($args['taxonomy']) ) { 219 | return false; 220 | } 221 | 222 | $categories = $this->get_terms( 'category', $args ); 223 | 224 | $output = ''; 225 | if ( $args['title_li'] && 'list' === $args['style'] ) { 226 | $output = '
  • ' . $args['title_li'] . '
      '; 227 | } 228 | 229 | if ( empty( $categories ) ) { 230 | if ( ! empty( $args['show_option_none'] ) ) { 231 | if ( 'list' == $args['style'] ) { 232 | $output .= '
    • ' . $args['show_option_none'] . '
    • '; 233 | } else { 234 | $output .= $args['show_option_none']; 235 | } 236 | } 237 | } else { 238 | if ( ! empty( $args['show_option_all'] ) ) { 239 | $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); 240 | $posts_page = esc_url( $posts_page ); 241 | if ( 'list' === $args['style'] ) { 242 | $output .= "
    • " . $args['show_option_all'] . "
    • "; 243 | } else { 244 | $output .= "" . $args['show_option_all'] . ""; 245 | } 246 | } 247 | 248 | if ( empty( $args['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { 249 | $current_term_object = get_queried_object(); 250 | if ( $args['taxonomy'] == $current_term_object->taxonomy ) { 251 | $args['current_category'] = get_queried_object_id(); 252 | } 253 | } 254 | 255 | $depth = -1; // Flat. 256 | 257 | add_filter( 'term_link', array( $this, 'filter_category_link' ), 10, 3 ); 258 | $output .= walk_category_tree( $categories, $depth, $args ); 259 | remove_filter( 'term_link', array( $this, 'filter_category_link' ) ); 260 | } 261 | 262 | if ( $args['title_li'] && 'list' === $args['style'] ) { 263 | $output .= '
  • '; 264 | } 265 | 266 | $output = apply_filters( 'wp_list_categories', $output, $args ); 267 | 268 | if ( $args['echo'] ) { 269 | echo $output; 270 | } else { 271 | return $output; 272 | } 273 | } 274 | 275 | /** 276 | * Wrapper for standard get_terms() to allow filtering by custom post type. 277 | * 278 | * @see http://core.trac.wordpress.org/ticket/18106 279 | * 280 | * @param string|array $taxonomies 281 | * @param array $args 282 | * 283 | * @return array|WP_Error 284 | */ 285 | public function get_terms( $taxonomies, $args = array() ) { 286 | if ( ! empty( $args['post_types'] ) ) { 287 | $args['post_types'] = (array) $args['post_types']; 288 | add_filter( 'terms_clauses', array( $this, 'filter_terms_by_cpt' ), 10, 3 ); 289 | } 290 | $terms = get_terms( $taxonomies, $args ); 291 | remove_filter( 'terms_clauses', array( $this, 'filter_terms_by_cpt' ), 10 ); 292 | 293 | return $terms; 294 | } 295 | 296 | /** 297 | * Filter the terms query by custom post type 298 | * 299 | * @see http://core.trac.wordpress.org/ticket/18106 300 | * 301 | * @param array $pieces 302 | * @param string|array $tax 303 | * @param array $args 304 | * 305 | * @return array 306 | */ 307 | public function filter_terms_by_cpt( $pieces, $tax, $args ) { 308 | global $wpdb; 309 | 310 | //Don't use db count 311 | $pieces['fields'] .= ", COUNT(*) "; 312 | 313 | //Join extra tables to restrict by post type. 314 | $pieces['join'] .= " INNER JOIN $wpdb->term_relationships AS r ON r.term_taxonomy_id = tt.term_taxonomy_id 315 | INNER JOIN $wpdb->posts AS p ON p.ID = r.object_id "; 316 | 317 | //Restrict by post type and Group by term_id for COUNTing. 318 | $post_types_str = implode( ',', $args['post_types'] ); 319 | $pieces['where'] .= $wpdb->prepare( " AND p.post_type IN(%s) GROUP BY t.term_id", $post_types_str ); 320 | 321 | return $pieces; 322 | } 323 | 324 | /** 325 | * Filter the category permalink such that we are returning a proper link to a 326 | * custom post type archive. 327 | * 328 | * @param string $termlink 329 | * @param $term 330 | * @param $taxonomy 331 | * 332 | * @return string 333 | */ 334 | public function filter_category_link( $termlink, $term, $taxonomy ) { 335 | $newlink = preg_replace( '/\/category\//', '/publication/category/', $termlink ); 336 | 337 | return $newlink; 338 | } 339 | 340 | /***********************************************************/ 341 | /* Templates and Redirects */ 342 | /***********************************************************/ 343 | 344 | /** 345 | * Override the template hierarchy to include our plugin's version if necessary. 346 | * 347 | * @param string $template 348 | * 349 | * @return string 350 | */ 351 | public function single_publication( $template ) { 352 | if ( is_singular( 'publication' ) ) { 353 | $template_name = apply_filters( 'wppa_single_template', 'single-publication.php' ); 354 | 355 | $path = $this->find_template( $template_name ); 356 | if ( false !== $path ) { 357 | $template = $path; 358 | } 359 | } 360 | 361 | return $template; 362 | } 363 | 364 | /** 365 | * Override the template hierarchy to include our plugin's version if necessary. 366 | * 367 | * @param string $template 368 | * 369 | * @return string 370 | */ 371 | public function publication_archives( $template ) { 372 | global $wp_query; 373 | 374 | if ( is_archive() && 'publication' === $wp_query->query_vars['post_type'] ) { 375 | $template_name = apply_filters( 'wppa_archive_template', 'archive-publication.php' ); 376 | 377 | $path = $this->find_template( $template_name ); 378 | if ( false !== $path ) { 379 | $template = $path; 380 | } 381 | } 382 | 383 | return $template; 384 | } 385 | 386 | /** 387 | * Locate a template in the theme or plugin and return it. 388 | * 389 | * @param string $template_name 390 | * 391 | * @return string|bool Returns false if no template is found 392 | */ 393 | protected function find_template( $template_name ) { 394 | $paths = array( 395 | get_stylesheet_directory() . '/' . $template_name, 396 | get_template_directory() . '/' . $template_name, 397 | WP_PUB_ARCH_DIR . 'includes/' . $template_name 398 | ); 399 | 400 | foreach ( $paths as $path ) { 401 | if ( file_exists( $path ) ) { 402 | return $path; 403 | } 404 | } 405 | 406 | return false; 407 | } 408 | } 409 | 410 | // Initialize the singleton 411 | WP_Publication_Archive_Utilities::create_instance(); -------------------------------------------------------------------------------- /lib/class.wp-publication-archive.php: -------------------------------------------------------------------------------- 1 | - 1, 30 | 'post_type' => 'publication' 31 | ) 32 | ); 33 | 34 | foreach ( $publications as $publication ) { 35 | $content = get_post_meta( $publication->ID, 'wpa_doc_desc', true ); 36 | 37 | // Upgrade content storage 38 | if ( ! empty( $content ) && empty( $publication->post_content ) ) { 39 | $publication->post_content = apply_filters( 'content_save_pre', $content ); 40 | 41 | wp_update_post( $publication ); 42 | } 43 | } 44 | break; 45 | } 46 | } 47 | 48 | /** 49 | * Generate a link with a given endpoint. 50 | * 51 | * If no permalink is provided, it will be pulled back from WordPress. In this case, the filter that auto-converts permalinks into open links will be removed and re-added. 52 | * 53 | * @param int $publication_id Optional ID of the publication for which to generate a link. 54 | * @param string $endpoint Optional endpoint name. 55 | * @param bool|string $permalink Optional existing permalink 56 | * @param bool|string $key Optional alternate download key 57 | * 58 | * @return string Download/Open link. 59 | * @since 2.5 60 | */ 61 | protected static function get_link( $publication_id = 0, $endpoint = 'view', $permalink = false, $key = false ) { 62 | if ( ! $permalink ) { 63 | remove_filter( 'post_type_link', array( 'WP_Publication_Archive', 'publication_link' ) ); 64 | $permalink = get_permalink( $publication_id ); 65 | add_filter( 'post_type_link', array( 'WP_Publication_Archive', 'publication_link' ), 10, 2 ); 66 | } 67 | 68 | $structure = get_option( 'permalink_structure' ); 69 | 70 | if ( empty( $structure ) ) { 71 | $new = add_query_arg( $endpoint, 'yes', $permalink ); 72 | 73 | if ( false !== $key ) { 74 | $new = add_query_arg( 'alt', $key, $new ); 75 | } 76 | } else { 77 | $new = site_url() . '/publication/' . $endpoint . '/' . basename( $permalink ); 78 | 79 | if ( false !== $key ) { 80 | $new .= '/' . $key; 81 | } 82 | } 83 | 84 | return $new; 85 | } 86 | 87 | /** 88 | * Generate a link for a particular file download. 89 | * 90 | * @param int $publication_id Optional ID of the publication for which to retrieve a download link. 91 | * 92 | * @return string Open link. 93 | * @since 2.5 94 | */ 95 | public static function get_open_link( $publication_id = 0 ) { 96 | return WP_Publication_Archive::get_link( $publication_id, 'view' ); 97 | } 98 | 99 | /** 100 | * Generate a link for a particular file download. 101 | * 102 | * @param int $publication_id Optional ID of the publication for which to retrieve a download link. 103 | * 104 | * @return string Download link. 105 | * @since 2.5 106 | */ 107 | public static function get_download_link( $publication_id = 0 ) { 108 | return WP_Publication_Archive::get_link( $publication_id, 'download' ); 109 | } 110 | 111 | /** 112 | * Generate a link for a particular alternate file download. 113 | * 114 | * @param int $publication_id Optional ID of the publication for which to retrieve a download link. 115 | * @param string|bool $key Optional key of the file to download 116 | * 117 | * @return string Download link. 118 | * @since 3.0 119 | */ 120 | public static function get_alternate_open_link( $publication_id = 0, $key = false ) { 121 | return WP_Publication_Archive::get_link( $publication_id, 'altview', false, $key ); 122 | } 123 | 124 | /** 125 | * Generate a link for a particular alternate file download. 126 | * 127 | * @param int $publication_id Optional ID of the publication for which to retrieve a download link. 128 | * @param string|bool $key Optional key of the file to download 129 | * 130 | * @return string Download link. 131 | * @since 3.0 132 | */ 133 | public static function get_alternate_download_link( $publication_id = 0, $key = false ) { 134 | return WP_Publication_Archive::get_link( $publication_id, 'altdown', false, $key ); 135 | } 136 | 137 | /** 138 | * Filter WordPress' request so that we can send a redirect to the file if it's requested. 139 | * 140 | * @uses apply_filters() Calls 'wppa_open_url' to get the download URL. 141 | * @uses apply_filters() Calls 'wppa_mask_url' to check whether the file source URL should be masked. 142 | * 143 | * @since 2.5 144 | */ 145 | public static function open_file() { 146 | global $wp_query; 147 | 148 | // If this isn't the right kind of request, bail. 149 | if ( ! isset( $wp_query->query_vars['wppa_open'] ) ) { 150 | return; 151 | } 152 | 153 | $publication = new WP_Publication_Archive_Item( $wp_query->post ); 154 | 155 | // Set an empty URI so we don't get an error later. 156 | $uri = ''; 157 | 158 | if ( isset( $wp_query->query_vars['wppa_alt'] ) ) { 159 | foreach( $publication->alternates as $alt ) { 160 | if ( urldecode( $wp_query->query_vars['wppa_alt'] ) === $alt['description'] ) { 161 | $uri = $alt['url']; 162 | break; 163 | } 164 | } 165 | } else { 166 | // Strip the old http| and https| if they're there 167 | $uri = str_replace( 'http|', 'http://', $publication->uri ); 168 | $uri = str_replace( 'https|', 'https://', $uri ); 169 | } 170 | 171 | $uri = apply_filters( 'wppa_open_url', $uri ); 172 | 173 | if ( empty( $uri ) ) { 174 | return; 175 | } 176 | 177 | if ( apply_filters( 'wppa_mask_url', true ) ) { 178 | $content_length = false; 179 | $last_modified = false; 180 | 181 | // Attempt to grab the content length and last modified date for caching. 182 | $request = wp_remote_head( $uri, array( 'sslverify' => false ) ); 183 | if ( ! is_wp_error( $request ) ) { 184 | $headers = wp_remote_retrieve_headers( $request ); 185 | 186 | if ( isset( $headers['content-length'] ) ) { 187 | $content_length = $headers['content-length']; 188 | } 189 | 190 | if ( isset( $headers['last-modified'] ) ) { 191 | $last_modified = $headers['last-modified']; 192 | } 193 | } 194 | 195 | $mime = new mimetype(); 196 | 197 | $content_type = $mime->getType( basename( $uri ) ); 198 | 199 | header( 'HTTP/1.1 200 OK' ); 200 | header( 'Expires: Wed, 9 Nov 1983 05:00:00 GMT' ); 201 | header( 'Content-type: ' . $content_type ); 202 | header( 'Content-Transfer-Encoding: binary' ); 203 | 204 | if ( false !== $content_length ) { 205 | header( 'Content-Length: ' . $content_length ); 206 | } 207 | 208 | if ( false !== $last_modified ) { 209 | header( 'Last-Modified: ' . $last_modified ); 210 | } 211 | 212 | // Return the remote file 213 | ob_clean(); 214 | flush(); 215 | readfile( $uri ); 216 | } else { 217 | header( 'HTTP/1.1 303 See Other' ); 218 | header( 'Location: ' . $uri ); 219 | } 220 | 221 | exit(); 222 | } 223 | 224 | /** 225 | * Filter WordPress' request so that we can send a redirect to the file if it's requested. 226 | * 227 | * @uses apply_filters() Calls 'wppa_download_url' to get the download URL. 228 | * @since 2.5 229 | */ 230 | public static function download_file() { 231 | global $wp_query; 232 | 233 | // If this isn't the right kind of request, bail. 234 | if ( ! isset( $wp_query->query_vars['wppa_download'] ) ) { 235 | return; 236 | } 237 | 238 | $publication = new WP_Publication_Archive_Item( $wp_query->post ); 239 | 240 | // Set an empty URI so we don't get an error later. 241 | $uri = ''; 242 | 243 | if ( isset( $wp_query->query_vars['wppa_alt'] ) ) { 244 | foreach( $publication->alternates as $alt ) { 245 | if ( urldecode( $wp_query->query_vars['wppa_alt'] ) === $alt['description'] ) { 246 | $uri = $alt['url']; 247 | break; 248 | } 249 | } 250 | } else { 251 | // Strip the old http| and https| if they're there 252 | $uri = str_replace( 'http|', 'http://', $publication->uri ); 253 | $uri = str_replace( 'https|', 'https://', $uri ); 254 | } 255 | 256 | $uri = apply_filters( 'wppa_download_url', $uri ); 257 | 258 | if ( empty( $uri ) ) { 259 | return; 260 | } 261 | 262 | if ( apply_filters( 'wppa_mask_url', true ) ) { 263 | $content_length = false; 264 | $last_modified = false; 265 | 266 | // Fetch the file from the remote server. 267 | $request = wp_remote_head( $uri, array( 'sslverify' => false ) ); 268 | 269 | if ( ! is_wp_error( $request ) ) { 270 | $headers = wp_remote_retrieve_headers( $request ); 271 | 272 | if ( isset( $headers['content-length'] ) ) { 273 | $content_length = $headers['content-length']; 274 | } 275 | 276 | if ( isset( $headers['last-modified'] ) ) { 277 | $last_modified = $headers['last-modified']; 278 | } 279 | } 280 | 281 | $mime = new mimetype(); 282 | 283 | $content_type = $mime->getType( basename( $uri ) ); 284 | 285 | header( 'HTTP/1.1 200 OK' ); 286 | header( 'Expires: Wed, 9 Nov 1983 05:00:00 GMT' ); 287 | header( 'Content-Disposition: attachment; filename=' . basename( $uri ) ); 288 | header( 'Content-type: ' . $content_type ); 289 | header( 'Content-Transfer-Encoding: binary' ); 290 | 291 | if ( false !== $content_length ) { 292 | header( 'Content-Length: ' . $content_length ); 293 | } 294 | 295 | if ( false !== $last_modified ) { 296 | header( 'Last-Modified: ' . $last_modified ); 297 | } 298 | 299 | // Return the remote file 300 | ob_clean(); 301 | flush(); 302 | readfile( $uri ); 303 | } else { 304 | header( 'HTTP/1.1 303 See Other' ); 305 | header( 'Location: ' . $uri ); 306 | } 307 | 308 | exit(); 309 | } 310 | 311 | /** 312 | * Get an image for the publication based on its MIME type. 313 | * 314 | * @uses apply_filters Calls 'wppa_publication_icon' to allow adding icons for unregistered MIME types. 315 | * 316 | * @param string $doctype MIME type of the file. 317 | * 318 | * @return string 319 | */ 320 | public static function get_image( $doctype ) { 321 | switch ( $doctype ) { 322 | case 'application/pdf': 323 | case 'application/postscript': 324 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/pdf.png'; 325 | break; 326 | case 'application/zip': 327 | case 'application/x-stuffit': 328 | case 'application/x-rar-compressed': 329 | case 'application/x-tar': 330 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/zip.png'; 331 | break; 332 | case 'audio/basic': 333 | case 'audio/mp4': 334 | case 'audio/mpeg': 335 | case 'audio/ogg': 336 | case 'audio/vorbis': 337 | case 'audio/x-ms-wma': 338 | case 'audio/x-ms-wax': 339 | case 'audio/vnd.rn-realaudio': 340 | case 'audio/vnd.wave': 341 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/audio.png'; 342 | break; 343 | case 'image/gif': 344 | case 'image/jpeg': 345 | case 'image/png': 346 | case 'image/svg+xml': 347 | case 'image/tiff': 348 | case 'image/vnd.microsoft.icon': 349 | case 'application/vnd.oasis.opendocument.graphics': 350 | case 'application/vnd.ms-excel': 351 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/image.png'; 352 | break; 353 | case 'text/cmd': 354 | case 'text/css': 355 | case 'text/plain': 356 | case 'application/vnd.oasis.opendocument.text': 357 | case 'application/vnd.oasis.opendocument.presentation': 358 | case 'application/vnd.ms-powerpoint': 359 | case 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 360 | case 'application/msword': 361 | case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 362 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/doc.png'; 363 | break; 364 | case 'text/csv': 365 | case 'application/vnd.oasis.opendocument.spreadsheet': 366 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 367 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/data.png'; 368 | break; 369 | case 'video/mpeg': 370 | case 'video/mp4': 371 | case 'video/ogg': 372 | case 'video/quicktime': 373 | case 'video/webm': 374 | case 'video/x-ms-wmv': 375 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/video.png'; 376 | break; 377 | default: 378 | $image_url = WP_PUB_ARCH_URL . 'images' . '/icons/unknown.png'; 379 | } 380 | 381 | return apply_filters( 'wppa_publication_icon', $image_url, $doctype ); 382 | } 383 | 384 | /** 385 | * Queue up scripts and styles, based on whether the user is on the admin or the front-end. 386 | * 387 | * @uses wp_enqueue_script() 388 | * @uses wp_enqueue_style() 389 | */ 390 | public static function enqueue_scripts_and_styles() { 391 | if ( is_admin() ) { 392 | wp_enqueue_script( 'media-upload' ); 393 | wp_enqueue_script( 'thickbox' ); 394 | wp_enqueue_style( 'thickbox' ); 395 | } else { 396 | wp_enqueue_style( 'wp-publication-archive-frontend', WP_PUB_ARCH_URL . 'includes/front-end.css', array(), WP_PUB_ARCH_VERSION, 'all' ); 397 | } 398 | } 399 | 400 | /** 401 | * Register the Publication custom post type. 402 | * 403 | * @uses register_post_type() 404 | */ 405 | public static function register_publication() { 406 | $labels = array( 407 | 'name' => __( 'Publications', 'wp_pubarch_translate' ), 408 | 'singular_name' => __( 'Publication', 'wp_pubarch_translate' ), 409 | 'add_new_item' => __( 'Add New Publication', 'wp_pubarch_translate' ), 410 | 'edit_item' => __( 'Edit Publication', 'wp_pubarch_translate' ), 411 | 'new_item' => __( 'New Publication', 'wp_pubarch_translate' ), 412 | 'view_item' => __( 'View Publication', 'wp_pubarch_translate' ), 413 | 'search_items' => __( 'Search Publications', 'wp_pubarch_translate' ), 414 | 'not_found' => __( 'No publications found', 'wp_pubarch_translate' ), 415 | 'not_found_in_trash' => __( 'No publications found in trash', 'wp_pubarch_translate' ) 416 | ); 417 | 418 | register_post_type( 'publication', 419 | array( 420 | 'labels' => $labels, 421 | 'capability_type' => 'post', 422 | 'public' => true, 423 | 'publicly_queryable' => true, 424 | 'has_archive' => true, 425 | 'menu_position' => 20, 426 | 'supports' => array( 427 | 'title', 428 | 'editor' 429 | ), 430 | 'taxonomies' => array( 431 | 'category', 432 | 'post_tag' 433 | ), 434 | 'register_meta_box_cb' => array( 'WP_Publication_Archive', 'pub_meta_boxes' ), 435 | 'can_export' => true, 436 | 'menu_icon' => WP_PUB_ARCH_URL . 'images/cabinet.png' 437 | ) 438 | ); 439 | } 440 | 441 | /** 442 | * Register the publication author taxonomy. 443 | * 444 | * @uses register_taxonomy 445 | * @todo Create a custom meta box to allow listing previously used authors rather than the freeform Tag box. 446 | */ 447 | public static function register_author() { 448 | $labels = array( 449 | 'name' => __( 'Authors', 'wp_pubarch_translate' ), 450 | 'singular_name' => __( 'Author', 'wp_pubarch_translate' ), 451 | 'search_items' => __( 'Search Authors', 'wp_pubarch_translate' ), 452 | 'popular_items' => __( 'Popular Authors', 'wp_pubarch_translate' ), 453 | 'all_items' => __( 'All Authors', 'wp_pubarch_translate' ), 454 | 'edit_item' => __( 'Edit Author', 'wp_pubarch_translate' ), 455 | 'update_item' => __( 'Update Author', 'wp_pubarch_translate' ), 456 | 'add_new_item' => __( 'Add New Author', 'wp_pubarch_translate' ), 457 | 'new_item_name' => __( 'New Author Name', 'wp_pubarch_translate' ), 458 | 'menu_name' => __( 'Authors', 'wp_pubarch_translate' ), 459 | ); 460 | 461 | register_taxonomy( 462 | 'publication-author', 463 | array( 'publication' ), 464 | array( 465 | 'hierarchical' => false, 466 | 'labels' => $labels, 467 | 'label' => __( 'Authors', 'wp_pubarch_translate' ), 468 | 'query_var' => false, 469 | 'rewrite' => false 470 | ) 471 | ); 472 | } 473 | 474 | /** 475 | * Register custom meta boxes for the Publication oage. 476 | */ 477 | public static function pub_meta_boxes() { 478 | add_meta_box( 'publication_uri', __( 'Publication', 'wp_pubarch_translate' ), array( 'WP_Publication_Archive', 'doc_uri_box' ), 'publication', 'normal', 'high', '' ); 479 | add_meta_box( 'publication_alternates', __( 'Alternate Files', 'wp_pubarch_translate' ), array( 'WP_Publication_Archive', 'doc_alternates_box' ), 'publication', 'normal', 'high', '' ); 480 | add_meta_box( 'publication_thumb', __( 'Thumbnail', 'wp_pubarch_translate' ), array( 'WP_Publication_Archive', 'doc_thumb_box'), 'publication', 'normal', 'high', '' ); 481 | } 482 | 483 | /** 484 | * Build the Publication link box 485 | * 486 | * @param WP_Post $post 487 | */ 488 | public static function doc_uri_box( $post ) { 489 | wp_nonce_field( plugin_basename( __FILE__ ), 'wpa_nonce' ); 490 | 491 | $uri = get_post_meta( $post->ID, 'wpa_upload_doc', true ); 492 | echo '

    ' . __( 'Please provide the absolute url of the file (including the http://):', 'wp_pubarch_translate' ) . '

    '; 493 | echo ''; 494 | echo ''; 495 | ?> 496 | 518 | ID, 'wpa-upload_image', true ); 528 | 529 | echo '

    ' . __( 'Please provide the absolute url for a thumbnail image (including the http://):', 'wp_pubarch_translate' ) . '

    '; 530 | echo ''; 531 | echo ''; 532 | ?> 533 | 555 | ID, 'wpa-upload_alternates' ); 565 | 566 | echo '

    ' . __( 'These files are considered alternates to the publication listed above (i.e. foreign language translations of the same document).', 'wp_pubarch_translate' ) . '

    '; 567 | echo ''; 568 | echo ''; 569 | echo ''; 570 | foreach( $alternates as $alternate ) { 571 | echo ''; 572 | echo ''; 573 | echo ''; 574 | echo ''; 575 | echo ''; 576 | } 577 | 578 | echo ''; 579 | echo ''; 580 | echo ''; 581 | echo ''; 582 | echo ''; 583 | echo ''; 584 | echo '
    DescriptionAbsolute Url
    ' . __( 'upload', 'wp_pubarch_translate' ) . ' | ' . __( 'delete', 'wp_pubarch_translate' ) . '
    ' . __( 'upload', 'wp_pubarch_translate' ) . ' | ' . __( 'delete', 'wp_pubarch_translate' ) . '
    '; 585 | 586 | echo ''; 587 | ?> 588 | 671 | post_type != 'publication' ) { 684 | return $post_id; 685 | } 686 | 687 | if ( ! isset( $_POST['wpa_nonce'] ) || ! wp_verify_nonce( $_POST['wpa_nonce'], plugin_basename( __FILE__ ) ) ) { 688 | return $post_id; 689 | } 690 | 691 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 692 | return $post_id; 693 | } 694 | 695 | $uri = isset( $_POST['wpa_upload_doc'] ) && '' != trim( $_POST['wpa_upload_doc'] ) ? esc_url_raw( $_POST['wpa_upload_doc'] ) : ''; 696 | $thumbnail = isset( $_POST['wpa-upload_image'] ) && '' != trim( $_POST['wpa-upload_image'] ) ? esc_url_raw( $_POST['wpa-upload_image'] ) : ''; 697 | 698 | update_post_meta( $post_id, 'wpa_upload_doc', $uri ); 699 | update_post_meta( $post_id, 'wpa-upload_image', $thumbnail ); 700 | 701 | // Handle alternate uploads 702 | delete_post_meta( $post_id, 'wpa-upload_alternates' ); 703 | if ( isset( $_POST['wpa-alternates'] ) ) { 704 | for ( $i = 0; $i <= count( $_POST['wpa-alternates']['url'] ); $i++ ) { 705 | $description = $_POST['wpa-alternates']['description'][ $i ]; 706 | $url = $_POST['wpa-alternates']['url'][ $i ]; 707 | 708 | if ( '' === trim( $url ) ) { 709 | continue; 710 | } 711 | 712 | add_post_meta( $post_id, 'wpa-upload_alternates', array( 'description' => $description, 'url' => $url ) ); 713 | } 714 | } 715 | 716 | return $post_id; 717 | } 718 | 719 | /** 720 | * Handle the 'wp-publication-archive' shortcode and provided filters. 721 | * 722 | * @param array $atts Shortcode arguments. 723 | * 724 | * @return string Shortcode output. 725 | * @uses apply_filters() Calls 'wwpa_list_limit' to get the number of publications listed on each page. 726 | * @uses apply_filters() Calls 'wppa_list_template' to get the shortcode template file. 727 | * @uses apply_filters() Calls 'wppa_dropdown_template' to get the shortcode template file. 728 | */ 729 | public static function shortcode_handler( $atts ) { 730 | global $post; 731 | 732 | /** 733 | * @var string $categories List of category slugs to filter. 734 | * @var string $author Author slug to filter. 735 | * @var number $limit Number of publications per page. 736 | * @var string $showas Format to use when displaying publications. 737 | */ 738 | extract( shortcode_atts( array( 739 | 'categories' => '', 740 | 'author' => '', 741 | 'limit' => 10, 742 | 'showas' => 'list' 743 | ), $atts ) ); 744 | 745 | $limit = apply_filters( 'wpa-pubs_per_page', $limit ); // Ugly, deprecated filter. 746 | $limit = apply_filters( 'wppa_list_limit', $limit ); 747 | 748 | if ( isset( $_GET['wpa-paged'] ) ) { 749 | $paged = (int) $_GET['wpa-paged']; 750 | $offset = $limit * ( $paged - 1 ); 751 | } else { 752 | $paged = 1; 753 | $offset = 0; 754 | } 755 | 756 | // Get publications 757 | $args = array( 758 | 'offset' => $offset, 759 | 'numberposts' => $limit, 760 | 'post_type' => 'publication', 761 | 'orderby' => 'post_date', 762 | 'order' => 'DESC', 763 | 'post_status' => 'publish' 764 | ); 765 | 766 | if ( '' != $categories ) { 767 | // Create an array of category IDs based on the categories fed in. 768 | $catFilter = array(); 769 | $catList = explode( ',', $categories ); 770 | foreach ( $catList as $catName ) { 771 | $id = get_cat_id( trim( $catName ) ); 772 | if ( 0 !== $id ) 773 | $catFilter[] = $id; 774 | } 775 | // if no categories matched categories in the database, report failure 776 | if ( empty( $catFilter ) ) { 777 | $error_msg = "

    " . __( ' Sorry, but the categories you passed to the wp-publication-archive shortcode do not match any publication categories.', 'wp_pubarch_translate' ) . "

    " . __( 'You passed: ', 'wp_pubarch_translate' ) . "$categories

    "; 778 | 779 | return $error_msg; 780 | } 781 | $args['category'] = implode( ',', $catFilter ); 782 | } 783 | 784 | if ( '' != $author ) { 785 | $args['tax_query'] = array( 786 | array( 787 | 'taxonomy' => 'publication-author', 788 | 'field' => 'slug', 789 | 'terms' => $author 790 | ) 791 | ); 792 | } 793 | 794 | $publications = get_posts( $args ); 795 | 796 | $args['numberposts'] = - 1; 797 | $total_pubs = count( get_posts( $args ) ); 798 | 799 | // Report if there are no publications matching filters 800 | if ( 0 == $total_pubs ) { 801 | $error_msg = "

    " . __( 'There are no publications to display', 'wp_pubarch_translate' ); 802 | if ( '' != $author ) 803 | $error_msg .= __( ' by ', 'wp_pubarch_translate' ) . $author; 804 | if ( '' != $categories ) { 805 | // There is probably a better way to do this 806 | $error_msg .= __( ' categorized ', 'wp_pubarch_translate' ); 807 | $catList = explode( ',', $categories ); 808 | $catNum = count( $catList ); 809 | $x = 3; // number of terms necessary for grammar to require commas after each term 810 | if ( $catNum > 2 ) $x = 1; 811 | for ( $i = 0; $i < $catNum; $i ++ ) { 812 | if ( $catNum > 1 && $i == ( $catNum - 1 ) ) $error_msg .= 'or '; 813 | $error_msg .= $catList[$i]; 814 | if ( $i < ( $catNum - $x ) ) { 815 | $error_msg .= ', '; 816 | } else if ( $i < ( $catNum - 1 ) ) { 817 | $error_msg .= ' '; 818 | } 819 | } 820 | } 821 | $error_msg .= ".

    "; 822 | 823 | return $error_msg; 824 | } 825 | 826 | switch ( $showas ) { 827 | case 'dropdown': 828 | // Get the publication list template 829 | $template_name = apply_filters( 'wppa_dropdown_template', 'template.wppa_publication_dropdown.php' ); 830 | break; 831 | case 'list': 832 | default: 833 | // Get the publication list template 834 | $template_name = apply_filters( 'wppa_list_template', 'template.wppa_publication_list.php' ); 835 | } 836 | 837 | $path = locate_template( $template_name ); 838 | if ( empty( $path ) ) { 839 | $path = WP_PUB_ARCH_DIR . 'includes/' . $template_name; 840 | } 841 | 842 | // Get a global container variable and populate it with our data 843 | global $wppa_container; 844 | $wppa_container = array( 845 | 'publications' => $publications, 846 | 'total_pubs' => $total_pubs, 847 | 'limit' => $limit, 848 | 'offset' => $offset, 849 | 'paged' => $paged, 850 | 'post' => $post 851 | ); 852 | $wppa_container = apply_filters( 'wppa_publication_list_container', $wppa_container ); 853 | 854 | // Start a buffer to capture the HTML output of the shortcode. 855 | ob_start(); 856 | 857 | include( $path ); 858 | 859 | $output = ob_get_contents(); 860 | 861 | ob_end_clean(); 862 | 863 | // Because globals are evil, clean up afterwards. 864 | unset( $wppa_container ); 865 | 866 | return $output; 867 | } 868 | 869 | /** 870 | * Register new query variables. 871 | * 872 | * @param array $public_vars Query variables. 873 | * 874 | * @return array Query variables. 875 | */ 876 | public static function query_vars( $public_vars ) { 877 | $public_vars[] = 'wpa-paged'; 878 | 879 | return $public_vars; 880 | } 881 | 882 | /** 883 | * Register our custom rewrite slugs and URLs. 884 | */ 885 | public static function custom_rewrites() { 886 | add_rewrite_tag( '%wppa_download%', '(.+)' ); 887 | add_rewrite_tag( '%wppa_open%', '(.+)' ); 888 | add_rewrite_tag( '%wppa_alt%', '(.+)' ); 889 | add_rewrite_rule( '^publication/download/([^/]+)(/[0-9]+)?/?$', 'index.php?publication=$matches[1]&wppa_download=yes', 'top' ); 890 | add_rewrite_rule( '^publication/view/([^/]+)(/[0-9]+)?/?$', 'index.php?publication=$matches[1]&wppa_open=yes', 'top' ); 891 | add_rewrite_rule( '^publication/altdown/([^/]+)/([^/]+)/?$', 'index.php?publication=$matches[1]&wppa_download=yes&wppa_alt=$matches[2]', 'top' ); 892 | add_rewrite_rule( '^publication/altview/([^/]+)/([^/]+)/?$', 'index.php?publication=$matches[1]&wppa_open=yes&wppa_alt=$matches[2]', 'top' ); 893 | 894 | add_rewrite_rule( '^publication/category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=publication&category_name=$matches[1]&feed=$matches[2]', 'top' ); 895 | add_rewrite_rule( '^publication/category/(.+?)/(feed|rdf|rss|rss2|atom)/?$', 'index.php?post_type=publication&category_name=$matches[1]&feed=$matches[2]', 'top' ); 896 | add_rewrite_rule( '^publication/category/(.+?)/page/?([0-9]{1,})/?$', 'index.php?post_type=publication&category_name=$matches[1]&paged=$matches[2]', 'top' ); 897 | add_rewrite_rule( '^publication/category/(.+?)/?$', 'index.php?post_type=publication&category_name=$matches[1]', 'top' ); 898 | } 899 | 900 | /** 901 | * The post link for Publications is actually link to *open* the file, rather than to open the post page. Filter 902 | * out requests so we generate the correct link. 903 | * 904 | * @param string $permalink 905 | * @param object $post 906 | * 907 | * @return string 908 | */ 909 | public static function publication_link( $permalink, $post ) { 910 | if ( 'publication' != $post->post_type ) 911 | return $permalink; 912 | 913 | $pub = new WP_Publication_Archive_Item( $post ); 914 | 915 | return self::get_link( $pub->ID, 'wppa_open', $permalink ); 916 | } 917 | 918 | /** 919 | * Filter the content of a Publication. 920 | * 921 | * Since Publications aren't using the regular post editor for their description, we need to hook in to calls 922 | * to `the_content()` to filter out what's stored in the database and replace it with what's stored in the description 923 | * meta field. 924 | * 925 | * We won't use the actual post content for Publications because, eventually, this will contain full-text references 926 | * from the Publication itself to aid in full-text searching within WordPress. 927 | * 928 | * @param string $content Regular post content from the `wp_posts` table. 929 | * 930 | * @return string Actual summary description of the Publication, or unfiltered text if this isn't a Publication. 931 | */ 932 | public static function the_content( $content ) { 933 | global $post; 934 | if ( 'publication' != $post->post_type ) { 935 | return $content; 936 | } 937 | 938 | $pub = new WP_Publication_Archive_Item( $post ); 939 | 940 | return $pub->summary; 941 | } 942 | 943 | /** 944 | * Filter the title to append "(Download Publication)" where necessary. 945 | * 946 | * @param string $title Original title 947 | * @param int $id Post ID 948 | * 949 | * @return string 950 | */ 951 | public static function the_title( $title, $id = 0 ) { 952 | // If the filter is called without passing in an ID, it's being called incorrectly. Rather than spewing a PHP warning, 953 | // we will just exit out. This code was added specifically to handle bad plugins like All-in-One Event Calendar. 954 | if ( 0 == $id ) { 955 | return $title; 956 | } 957 | 958 | $post = get_post( $id ); 959 | if ( 'publication' != $post->post_type || is_admin() ) 960 | return $title; 961 | 962 | return sprintf( __( '%s (Publication)', 'wp_pubarch_translate' ), $title ); 963 | } 964 | 965 | /** 966 | * Also check if the search term is contained in the publication's description. 967 | * 968 | * @param string $where Existing search query string. 969 | * 970 | * @uses add_filter() 971 | * 972 | * @return string 973 | * 974 | * @since 2.5 975 | */ 976 | public static function search( $where ) { 977 | if ( ! is_search() ) { 978 | return $where; 979 | } 980 | 981 | global $wpdb, $wp; 982 | 983 | $where = preg_replace( 984 | "/($wpdb->posts.post_title (LIKE '%{$wp->query_vars['s']}%'))/i", 985 | "$0 OR ($wpdb->postmeta.meta_key = 'wpa_doc_desc' AND $wpdb->postmeta.meta_value $1)", 986 | $where 987 | ); 988 | 989 | $where = preg_replace( 990 | "/$wpdb->postmeta.meta_value $wpdb->posts.post_title LIKE/", 991 | "$wpdb->postmeta.meta_value LIKE", 992 | $where 993 | ); 994 | 995 | add_filter( 'posts_join_request', array( 'WP_Publication_Archive', 'search_join' ) ); 996 | add_filter( 'posts_distinct_request', array( 'WP_Publication_Archive', 'search_distinct' ) ); 997 | 998 | return $where; 999 | } 1000 | 1001 | /** 1002 | * Add post meta to the search Query. 1003 | * 1004 | * @param string $join Existing search query string. 1005 | * 1006 | * @return string 1007 | * 1008 | * @since 2.5 1009 | */ 1010 | public static function search_join( $join ) { 1011 | global $wpdb; 1012 | 1013 | return $join .= " LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) "; 1014 | } 1015 | 1016 | /** 1017 | * Force the search to only return distinct values. 1018 | * 1019 | * @param string $distinct 1020 | * 1021 | * @return string 1022 | */ 1023 | public static function search_distinct( $distinct ) { 1024 | return 'DISTINCT'; 1025 | } 1026 | 1027 | /** 1028 | * Utility function to return a WP_Query object with Publication posts 1029 | * 1030 | * @author Matthew Eppelsheimer 1031 | * @since 2.5 1032 | */ 1033 | public static function query_publications( $args ) { 1034 | $defaults = array( 1035 | 'posts_per_page' => - 1, 1036 | 'order' => 'ASC', 1037 | 'orderby' => 'menu_order' 1038 | ); 1039 | 1040 | $query_args = wp_parse_args( $args, $defaults ); 1041 | $query_args['post_type'] = 'publication'; 1042 | 1043 | $results = new WP_Query( $query_args ); 1044 | 1045 | return $results; 1046 | } 1047 | 1048 | /** 1049 | * Allow users to filter the length of only publication summaries. 1050 | * 1051 | * @param int $length 1052 | * 1053 | * @return int 1054 | */ 1055 | public static function custom_excerpt_length( $length ) { 1056 | global $post; 1057 | 1058 | if ( 'publication' !== $post->post_type ) { 1059 | return $length; 1060 | } 1061 | 1062 | return apply_filters( 'wpa-summary-length', $length ); 1063 | } 1064 | } 1065 | --------------------------------------------------------------------------------