/** * Default initialization routine for the plugin. * - Registers the default textdomain. * - Loads a rewrite endpoint for processing file downloads. */ function wp_pubarch_init() { load_plugin_textdomain('wp_pubarch_translate', false, dirname(dirname(plugin_basename(__FILE__))) . '/lang/'); WP_Publication_Archive::register_author(); WP_Publication_Archive::register_publication(); add_rewrite_endpoint('wppa_download', EP_ALL); add_rewrite_endpoint('wppa_open', EP_ALL); }
/** * Get the markup for the publication download links. * * @see mimetype * * @uses WP_Publication_Archive::get_image() * @uses WP_Publication_Archive::get_open_link() * @uses WP_Publication_Archive::get_download_link() * * @return string */ public function get_the_uri() { $mime = new mimetype(); $uri = $this->get_the_link(); if ('' == trim($uri)) { return ''; } $output = '<div class="publication_download">'; // $output .= '<span class="title">' . __( 'Download:', 'wp_pubarch_translate' ) . ' </span>'; $output .= '<span class="description">'; $output .= '<img height="16" width="16" alt="download" src="' . WP_Publication_Archive::get_image($mime->getType($this->uri)) . '" /> '; $output .= '<a '; if (apply_filters('wp_pubarch_open_in_blank', false)) { $output .= 'target="_blank" '; } $output .= 'href="' . WP_Publication_Archive::get_open_link($this->ID) . '">'; $output .= __('Open', 'wp_pubarch_translate') . '</a> | '; $output .= '<a href="' . WP_Publication_Archive::get_download_link($this->ID) . '">'; $output .= __('Download', 'wp_pubarch_translate') . '</a>'; $output .= '</span>'; $output .= '</div>'; return $output; }
/** * Echo the content of the widget to the front-end user interface. * * Dynamically loads a template for the widget display. Default template is stored in * includes/template.wppa_widget.php. If a similarly-named file exists in the current theme, the theme's * version will be used instead. * * @param array $argsDisplay arguments including before_title, after_title, before_widget, and after_widget * @param array $instance Settings for this particular instance. * @uses apply_filters() Calls 'widget_title' for the widget title. * @uses apply_filters() Calls 'wppa_widget_template' to get the name of the widget template file. * * @todo Support 'publication_cat' and 'publication_id' in the $query_args array. */ public function widget($args, $instance) { /** * @var string $before_widget * @var string $after_widget * @var string $before_title * @var string $after_title */ extract($args); $title = apply_filters('widget_title', $instance['title']); // Get publications to display $query_args = array(); if (isset($instance['number'])) { $query_args['posts_per_page'] = $instance['number']; } if (isset($instance['order_by'])) { $query_args['order_by'] = $instance['order_by']; } // Globalize our publications wrapper so the template can use it. global $wppa_publications; $wppa_publications = WP_Publication_Archive::query_publications($query_args); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Include widget template. Can be overridden by a theme. $template_name = apply_filters('wppa_widget_template', 'template.wppa_widget.php'); $path = locate_template($template_name); if (empty($path)) { $path = WP_PUB_ARCH_DIR . 'includes/' . $template_name; } include $path; echo $after_widget; // Clean up our globals unset($wppa_publications); }
/** * Generate a link for a particular file download. * * @param int $publication_id Optional ID of the publication for which to retrieve a download link. * * @return string Download link. * @since 2.5 */ public static function get_download_link($publication_id = 0) { return WP_Publication_Archive::get_link($publication_id, 'wppa_download'); }