Advertisement
emcniece

WP Bug Library Proposed HTML structure updates

Feb 20th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 76.97 KB | None | 0 0
  1. <?php
  2. /* NOTE: This is a patch intended for discussion at http://wordpress.org/support/topic/developer-necessities */
  3. /*
  4. Plugin Name: Bug Library
  5. Plugin URI: http://wordpress.org/extend/plugins/bug-library/
  6. Description: Display bug manager on pages with a variety of options
  7. Version: 1.2.8
  8. Author: Yannick Lefebvre
  9. Author URI: http://yannickcorner.nayanna.biz/
  10.  
  11. A plugin for the blogging MySQL/PHP-based WordPress.
  12. Copyright 2013 Yannick Lefebvre
  13.  
  14. This program is free software; you can redistribute it and/or
  15. modify it under the terms of the GNU General Public License
  16. as published by the Free Software Foundation; either version 2
  17. of the License, or (at your option) any later version.
  18.  
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. GNU General Public License for more details.
  23.  
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software
  26. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  27.  
  28. You can also view a copy of the HTML version of the GNU General Public
  29. License at http://www.gnu.org/copyleft/gpl.html
  30.  
  31. I, Yannick Lefebvre, can be contacted via e-mail at ylefebvre@gmail.com
  32. */
  33.  
  34. global $wpdb;
  35.  
  36. define('BUG_LIBRARY_ADMIN_PAGE_NAME', 'bug-library');
  37.  
  38. define('BLDIR', dirname(__FILE__) . '/');
  39.  
  40. if ( !defined('WP_ADMIN_URL') )
  41.     define( 'WP_ADMIN_URL', get_option('siteurl') . '/wp-admin');
  42.    
  43. require_once(BLDIR . '/wp-admin-menu-classes.php');
  44.  
  45. $pagehooktop = "";
  46. $pagehookstylesheet = "";
  47. $pagehookinstructions = "";
  48.  
  49. /*********************************** Bug Library Class *****************************************************************************/
  50. class bug_library_plugin {
  51.  
  52.     //constructor of class, PHP4 compatible construction for backward compatibility
  53.     function bug_library_plugin() {
  54.    
  55.         $newoptions = get_option('BugLibraryGeneral', "");
  56.  
  57.         if ($newoptions == "")
  58.         {
  59.             $this->bl_reset_gen_settings();
  60.         }
  61.  
  62.         // Functions to be called when plugin is activated and deactivated
  63.         register_activation_hook(__FILE__, array($this, 'bl_install'));
  64.         register_deactivation_hook(__FILE__, array($this, 'bl_uninstall'));
  65.  
  66.         //add filter for WordPress 2.8 changed backend box system !
  67.         add_filter('screen_layout_columns', array($this, 'on_screen_layout_columns'), 10, 2);
  68.         //register callback for admin menu  setup
  69.         add_action('admin_menu', array($this, 'on_admin_menu'));
  70.                
  71.                 add_action('admin_init', array($this, 'admin_init'));
  72.         //register the callback been used if options of page been submitted and needs to be processed
  73.         add_action('admin_post_save_bug_library_general', array($this, 'on_save_changes_general'));
  74.         add_action('admin_post_save_bug_library_stylesheet', array($this, 'on_save_changes_stylesheet'));
  75.  
  76.         // Add short codes
  77.         add_shortcode('bug-library', array($this, 'bug_library_func'));
  78.  
  79.         // Function to print information in page header when plugin present
  80.         add_action('wp_head', array($this, 'bl_page_header'));
  81.        
  82.         add_action('admin_head', array($this, 'bl_admin_header'));
  83.        
  84.         add_action('init', array($this, 'my_custom_taxonomies'), 0);
  85.         add_action( 'init', array($this, 'create_bug_post_type') );
  86.                
  87.         add_action("manage_posts_custom_column", array($this, "bugs_populate_columns"));
  88.         add_filter("manage_edit-bug-library-bugs_columns", array($this, "bugs_columns_list"));
  89.        
  90.         add_action('restrict_manage_posts', array($this, 'restrict_listings'));
  91.         add_filter('parse_query', array($this, 'convert_ids_to_taxonomy_term_in_query'));
  92.        
  93.         add_action('save_post', array($this, 'add_bug_field'), 10, 2);
  94.         add_action('delete_post', array($this, 'delete_bug_field'));
  95.        
  96.         add_action('admin_menu', array($this, 'my_admin_menu'));
  97.        
  98.         // Function to determine if Bug Library is used on a page before printing headers
  99.         add_filter('the_posts', array($this, 'conditionally_add_scripts_and_styles')); // the_posts gets triggered before wp_head
  100.  
  101.         global $blpluginpath;
  102.         $blpluginpath = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)).'/';
  103.  
  104.         // Load text domain for translation of admin pages and text strings
  105.         load_plugin_textdomain( 'bug-library', $blpluginpath . '/languages', 'bug-library/languages');
  106.     }
  107.  
  108.     /************************** Bug Library Installation Function **************************/
  109.     function bl_install() {
  110.    
  111.         global $wpdb;
  112.        
  113.         $productexist = $wpdb->get_var("select * from " . $wpdb->get_blog_prefix() . "term_taxonomy where taxonomy = 'bug-library-products'");
  114.                
  115.         if ($productterms == "")
  116.         {
  117.             $wpdb->insert( $wpdb->get_blog_prefix() . 'terms', array( 'name' => 'Default Product', 'slug' => 'default-product', 'term_group' => 0 ) );
  118.             $producttermid = $wpdb->get_var("select term_id from " . $wpdb->get_blog_prefix() . "terms where name = 'Default Product'");
  119.             $wpdb->insert( $wpdb->get_blog_prefix() . 'term_taxonomy', array( 'term_id' => $producttermid, 'taxonomy' => 'bug-library-products', 'description' => '', 'parent' => 0, 'count' => 0 ) );
  120.         }
  121.        
  122.         $typeexist = $wpdb->get_var("select * from " . $wpdb->get_blog_prefix() . "term_taxonomy where taxonomy = 'bug-library-types'");
  123.        
  124.         if ($typeexist == "")
  125.         {
  126.             $wpdb->insert( $wpdb->get_blog_prefix() . 'terms', array( 'name' => 'Default Type', 'slug' => 'default-type', 'term_group' => 0 ) );
  127.             $typetermid = $wpdb->get_var("select term_id from " . $wpdb->get_blog_prefix() . "terms where name = 'Default Type'");
  128.             $wpdb->insert( $wpdb->get_blog_prefix() . 'term_taxonomy', array( 'term_id' => $typetermid, 'taxonomy' => 'bug-library-types', 'description' => '', 'parent' => 0, 'count' => 0 ) );       
  129.         }
  130.        
  131.         $statusexist = $wpdb->get_var("select * from " . $wpdb->get_blog_prefix() . "term_taxonomy where taxonomy = 'bug-library-status'");
  132.        
  133.         if ($statusexist == "")
  134.         {
  135.             $wpdb->insert( $wpdb->get_blog_prefix() . 'terms', array( 'name' => 'Default Status', 'slug' => 'default-status', 'term_group' => 0 ) );
  136.             $statustermid = $wpdb->get_var("select term_id from " . $wpdb->get_blog_prefix() . "terms where name = 'Default Status'");
  137.             $wpdb->insert( $wpdb->get_blog_prefix() . 'term_taxonomy', array( 'term_id' => $statustermid, 'taxonomy' => 'bug-library-status', 'description' => '', 'parent' => 0, 'count' => 0 ) );    
  138.         }
  139.        
  140.         $priorityexist = $wpdb->get_var("select * from " . $wpdb->get_blog_prefix() . "term_taxonomy where taxonomy = 'bug-library-priority'");
  141.        
  142.         if ($priorityexist == "")
  143.         {
  144.             $wpdb->insert( $wpdb->get_blog_prefix() . 'terms', array( 'name' => 'Default Priority', 'slug' => 'default-priority', 'term_group' => 0 ) );
  145.             $prioritytermid = $wpdb->get_var("select term_id from " . $wpdb->get_blog_prefix() . "terms where name = 'Default Priority'");
  146.             $wpdb->insert( $wpdb->get_blog_prefix() . 'term_taxonomy', array( 'term_id' => $prioritytermid, 'taxonomy' => 'bug-library-priority', 'description' => '', 'parent' => 0, 'count' => 0 ) );
  147.         }
  148.        
  149.         $bugs = $wpdb->get_results("select * from " . $wpdb->get_blog_prefix() . "posts where post_type = 'bug-library-bugs'");
  150.            
  151.         if ($bugs)
  152.         {
  153.             foreach ($bugs as $bug)
  154.             {
  155.                 $priorityterms = wp_get_post_terms( $bug->ID, 'bug-library-priority');
  156.                 if (!$priorityterms)
  157.                     wp_set_post_terms( $bug->ID, 'Default Priority', 'bug-library-priority');
  158.             }
  159.         }
  160.     }
  161.        
  162.         function admin_init() {
  163.             add_meta_box('buglibrary_edit_bug_meta_box', __('Bug Details', 'bug-library'), array($this, 'bug_library_edit_bug_details'), 'bug-library-bugs', 'normal', 'high');
  164.         }
  165.    
  166.     function my_admin_menu() {
  167.         add_admin_menu_item('Bugs',array(                       // (Another way to get a 'Add Actor' Link to a section.)
  168.             'title' => 'Edit Product List',
  169.             'slug' => 'edit-tags.php?taxonomy=bug-library-products&post_type=bug-library-bugs',
  170.             )
  171.         );
  172.        
  173.         add_admin_menu_item('Bugs',array(                       // (Another way to get a 'Add Actor' Link to a section.)
  174.             'title' => 'Edit Bug Statuses',
  175.             'slug' => 'edit-tags.php?taxonomy=bug-library-status&post_type=bug-library-bugs',
  176.             )
  177.         );
  178.        
  179.         add_admin_menu_item('Bugs',array(                       // (Another way to get a 'Add Actor' Link to a section.)
  180.             'title' => 'Edit Bug Types',
  181.             'slug' => 'edit-tags.php?taxonomy=bug-library-types&post_type=bug-library-bugs',
  182.             )
  183.         );
  184.        
  185.         add_admin_menu_item('Bugs',array(                       // (Another way to get a 'Add Actor' Link to a section.)
  186.             'title' => 'Edit Bug Priorities',
  187.             'slug' => 'edit-tags.php?taxonomy=bug-library-priority&post_type=bug-library-bugs',
  188.             )
  189.         );
  190.  
  191.     }
  192.    
  193.     function my_custom_taxonomies() {
  194.    
  195.         register_taxonomy(
  196.             'bug-library-products',     // internal name = machine-readable taxonomy name
  197.             'bug-library-bugs',     // object type = post, page, link, or custom post-type
  198.             array(
  199.                 'hierarchical' => false,
  200.                 'label' => 'Products',  // the human-readable taxonomy name
  201.                 'query_var' => true,    // enable taxonomy-specific querying
  202.                 'rewrite' => array( 'slug' => 'products' ), // pretty permalinks for your taxonomy?
  203.                 'add_new_item' => 'Add New Product',
  204.                 'new_item_name' => "New Product Name",
  205.                 'show_ui' => false,
  206.                 'show_tagcloud' => false
  207.             )
  208.         );
  209.        
  210.         register_taxonomy(
  211.             'bug-library-status',       // internal name = machine-readable taxonomy name
  212.             'bug-library-bugs',     // object type = post, page, link, or custom post-type
  213.             array(
  214.                 'hierarchical' => false,
  215.                 'label' => 'Bug Status',    // the human-readable taxonomy name
  216.                 'query_var' => true,    // enable taxonomy-specific querying
  217.                 'rewrite' => array( 'slug' => 'status' ),   // pretty permalinks for your taxonomy?
  218.                 'add_new_item' => 'Add New Status',
  219.                 'new_item_name' => "New Status",
  220.                 'show_ui' => false,
  221.                 'show_tagcloud' => false
  222.             )
  223.         );
  224.        
  225.         register_taxonomy(
  226.             'bug-library-types',        // internal name = machine-readable taxonomy name
  227.             'bug-library-bugs',     // object type = post, page, link, or custom post-type
  228.             array(
  229.                 'hierarchical' => false,
  230.                 'label' => 'Types', // the human-readable taxonomy name
  231.                 'query_var' => true,    // enable taxonomy-specific querying
  232.                 'rewrite' => array( 'slug' => 'types' ),    // pretty permalinks for your taxonomy?
  233.                 'add_new_item' => 'Add New Type',
  234.                 'new_item_name' => "New Type",
  235.                 'show_ui' => false,
  236.                 'show_tagcloud' => false
  237.             )
  238.         );
  239.        
  240.         register_taxonomy(
  241.             'bug-library-priority',     // internal name = machine-readable taxonomy name
  242.             'bug-library-bugs',     // object type = post, page, link, or custom post-type
  243.             array(
  244.                 'hierarchical' => false,
  245.                 'label' => 'Priorities',    // the human-readable taxonomy name
  246.                 'query_var' => true,    // enable taxonomy-specific querying
  247.                 'rewrite' => array( 'slug' => 'priority' ), // pretty permalinks for your taxonomy?
  248.                 'add_new_item' => 'Add New Priority',
  249.                 'new_item_name' => "New Priority",
  250.                 'show_ui' => false,
  251.                 'show_tagcloud' => false
  252.             )
  253.         );
  254.     }
  255.    
  256.     function create_bug_post_type() {
  257.         global $blpluginpath;
  258.         $genoptions = get_option('BugLibraryGeneral', "");
  259.         if ($genoptions['permalinkpageid'] != -1)
  260.         {
  261.             $page = get_page( $genoptions['permalinkpageid'] );
  262.             $slug = $page->post_name;
  263.         }
  264.         else
  265.             $slug = 'bugs';
  266.    
  267.         register_post_type( 'bug-library-bugs',
  268.             array(
  269.                 'labels' => array(
  270.                     'name' => __( 'Bugs' ),
  271.                     'singular_name' => __( 'Bug' ),
  272.                     'add_new' => __( 'Add New' ),
  273.                     'add_new_item' => __( 'Add New Bug' ),
  274.                     'edit' => __( 'Edit' ),
  275.                     'edit_item' => __( 'Edit Bug' ),
  276.                     'new_item' => __( 'New Bug' ),
  277.                     'view' => __( 'View Bug' ),
  278.                     'view_item' => __( 'View Bug' ),
  279.                     'search_items' => __( 'Search Bugs' ),
  280.                     'not_found' => __( 'No bugs found' ),
  281.                     'not_found_in_trash' => __( 'No bugs found in Trash' ),
  282.                     'parent' => __( 'Parent Bug' ),
  283.                 ),
  284.             'public' => true,
  285.             'menu_position' => 20,
  286.             'supports' => array( 'title', 'editor', 'comments', 'thumbnail'),
  287.             'taxonomies' => array(''),
  288.             'menu_icon' => $blpluginpath . '/icons/bug-icon.png',
  289.             'rewrite' => array('slug' => $slug)
  290.             )
  291.         );
  292.        
  293.     }
  294.  
  295.     function bugs_columns_list($columns)
  296.     {
  297.         $columns["bug-library-view-ID"] = "ID";
  298.         $columns["bug-library-view-product"] = "Product";
  299.         $columns["bug-library-view-status"] = "Status";
  300.         $columns["bug-library-view-type"] = "Type";
  301.         $columns["bug-library-view-priority"] = "Priority";
  302.         $columns["bug-library-view-assignee"] = "Assignee";
  303.         unset($columns['comments']);
  304.  
  305.         return $columns;
  306.     }
  307.    
  308.     function bugs_populate_columns($column)
  309.     {
  310.         global $post;
  311.    
  312.         $products = wp_get_post_terms( $post->ID, "bug-library-products");
  313.         $status = wp_get_post_terms( $post->ID, "bug-library-status");
  314.         $types = wp_get_post_terms( $post->ID, "bug-library-types");
  315.         $priorities = wp_get_post_terms( $post->ID, "bug-library-priority");
  316.        
  317.         $assigneduserid = get_post_meta($post->ID, "bug-library-assignee", true);
  318.         if ($assigneduserid != -1 && $assigneduserid != '')
  319.         {
  320.             $assigneedata = get_userdata($assigneduserid);
  321.             if ($assigneedata)
  322.             {
  323.                 $firstname = get_user_meta($assigneduserid, 'first_name', true);
  324.                 $lastname = get_user_meta($assigneduserid, 'last_name', true);
  325.                
  326.                 if ($firstname == "" && $lastname == "")
  327.                 {
  328.                     $firstname = $assigneedata->user_login;
  329.                 }
  330.             }
  331.             else
  332.             {
  333.                 $firstname = "Unassigned";
  334.                 $lastname = "";
  335.             }
  336.         }
  337.         else
  338.         {
  339.             $firstname = "Unassigned";
  340.             $lastname = "";
  341.         }
  342.        
  343.         if ("bug-library-view-ID" == $column) echo $post->ID;
  344.         elseif ("bug-library-view-title" == $column) echo $post->post_title;
  345.         elseif ("bug-library-view-product" == $column) echo $products[0]->name;
  346.         elseif ("bug-library-view-status" == $column) echo $status[0]->name;
  347.         elseif ("bug-library-view-type" == $column) echo $types[0]->name;
  348.         elseif ("bug-library-view-priority" == $column) echo $priorities[0]->name;
  349.         elseif ("bug-library-view-assignee" == $column) echo $firstname . " " . $lastname;
  350.     }
  351.    
  352.     function restrict_listings() {
  353.         global $typenow;
  354.         global $wp_query;
  355.         if ($typenow=='bug-library-bugs') {
  356.             $taxonomy = 'bug-library-products';
  357.             $product_taxonomy = get_taxonomy($taxonomy);
  358.             wp_dropdown_categories(array(
  359.                 'show_option_all' =>  __("Show All {$product_taxonomy->label}"),
  360.                 'taxonomy'        =>  $taxonomy,
  361.                 'name'            =>  'bug-library-products',
  362.                 'orderby'         =>  'name',
  363.                 'selected'        =>  $wp_query->query['bug-library-products'],
  364.                 'hierarchical'    =>  true,
  365.                 'depth'           =>  3,
  366.                 'show_count'      =>  false, // Show # listings in parens
  367.                 'hide_empty'      =>  true, // Don't show businesses w/o listings
  368.             ));
  369.            
  370.             $taxonomy = 'bug-library-types';
  371.             $product_taxonomy = get_taxonomy($taxonomy);
  372.             wp_dropdown_categories(array(
  373.                 'show_option_all' =>  __("Show All {$product_taxonomy->label}"),
  374.                 'taxonomy'        =>  $taxonomy,
  375.                 'name'            =>  'bug-library-types',
  376.                 'orderby'         =>  'name',
  377.                 'selected'        =>  $wp_query->query['bug-library-types'],
  378.                 'hierarchical'    =>  true,
  379.                 'depth'           =>  3,
  380.                 'show_count'      =>  false, // Show # listings in parens
  381.                 'hide_empty'      =>  true, // Don't show businesses w/o listings
  382.             ));
  383.            
  384.             $taxonomy = 'bug-library-status';
  385.             $product_taxonomy = get_taxonomy($taxonomy);
  386.             wp_dropdown_categories(array(
  387.                 'show_option_all' =>  __("Show All {$product_taxonomy->label}"),
  388.                 'taxonomy'        =>  $taxonomy,
  389.                 'name'            =>  'bug-library-status',
  390.                 'orderby'         =>  'name',
  391.                 'selected'        =>  $wp_query->query['bug-library-status'],
  392.                 'hierarchical'    =>  true,
  393.                 'depth'           =>  3,
  394.                 'show_count'      =>  false, // Show # listings in parens
  395.                 'hide_empty'      =>  true, // Don't show businesses w/o listings
  396.             ));
  397.            
  398.             $taxonomy = 'bug-library-priority';
  399.             $product_taxonomy = get_taxonomy($taxonomy);
  400.             wp_dropdown_categories(array(
  401.                 'show_option_all' =>  __("Show All {$product_taxonomy->label}"),
  402.                 'taxonomy'        =>  $taxonomy,
  403.                 'name'            =>  'bug-library-priority',
  404.                 'orderby'         =>  'name',
  405.                 'selected'        =>  $wp_query->query['bug-library-priority'],
  406.                 'hierarchical'    =>  true,
  407.                 'depth'           =>  3,
  408.                 'show_count'      =>  false, // Show # listings in parens
  409.                 'hide_empty'      =>  true, // Don't show businesses w/o listings
  410.             ));
  411.         }
  412.     }
  413.    
  414.     function convert_ids_to_taxonomy_term_in_query($query) {
  415.         global $pagenow;
  416.         $qv = &$query->query_vars;
  417.        
  418.         if ($pagenow=='edit.php' &&
  419.                 isset($qv['bug-library-products']) && is_numeric($qv['bug-library-products'])) {
  420.            
  421.             $term = get_term_by('id',$qv['bug-library-products'],'bug-library-products');
  422.             $qv['bug-library-products'] = $term->slug;
  423.         }
  424.        
  425.         if ($pagenow=='edit.php' &&
  426.                 isset($qv['bug-library-types']) && is_numeric($qv['bug-library-types'])) {
  427.            
  428.             $term = get_term_by('id',$qv['bug-library-types'],'bug-library-types');
  429.             $qv['bug-library-types'] = $term->slug;
  430.         }
  431.  
  432.         if ($pagenow=='edit.php' &&
  433.                 isset($qv['bug-library-status']) && is_numeric($qv['bug-library-status'])) {
  434.            
  435.             $term = get_term_by('id',$qv['bug-library-status'],'bug-library-status');
  436.             $qv['bug-library-status'] = $term->slug;
  437.         }
  438.        
  439.         if ($pagenow=='edit.php' &&
  440.                 isset($qv['bug-library-priority']) && is_numeric($qv['bug-library-priority'])) {
  441.            
  442.             $term = get_term_by('id',$qv['bug-library-priority'],'bug-library-priority');
  443.             $qv['bug-library-priority'] = $term->slug;
  444.         }
  445.        
  446.     }
  447.    
  448.     function bug_library_edit_bug_details($bug)
  449.     {
  450.         $genoptions = get_option('BugLibraryGeneral', "");
  451.         global $wpdb;
  452.    
  453.         $products = wp_get_post_terms( $bug->ID, "bug-library-products");
  454.         $statuses = wp_get_post_terms( $bug->ID, "bug-library-status");
  455.         $types = wp_get_post_terms( $bug->ID, "bug-library-types");
  456.         $priorities = wp_get_post_terms( $bug->ID, "bug-library-priority");
  457.         $productversion = get_post_meta($bug->ID, "bug-library-product-version", true);
  458.         $reportername = get_post_meta($bug->ID, "bug-library-reporter-name", true);
  459.         $reporteremail = get_post_meta($bug->ID, "bug-library-reporter-email", true);
  460.         $resolutiondate = get_post_meta($bug->ID, "bug-library-resolution-date", true);
  461.         $resolutionversion = get_post_meta($bug->ID, "bug-library-resolution-version", true);
  462.         $imagepath = get_post_meta($bug->ID, "bug-library-image-path", true);
  463.         $assigneduserid = get_post_meta($bug->ID, "bug-library-assignee", true);
  464.            
  465.         echo "<table>\n";
  466.        
  467.         echo "<tr><td>Assigned user</td><td>\n";
  468.        
  469.         global $wp_roles;
  470.        
  471.         $users = array();
  472.  
  473.         foreach ( $wp_roles->role_names as $role => $name ) :
  474.    
  475.             $userquery = "select * from " . $wpdb->get_blog_prefix() . "users u LEFT JOIN " . $wpdb->get_blog_prefix() . "usermeta um ON u.ID = um.user_id ";
  476.             $userquery .= "where meta_key = 'wp_capabilities'";
  477.  
  478.             $userarray = $wpdb->get_results($userquery);
  479.            
  480.             if ($userarray)
  481.             {
  482.                 foreach ($userarray as $user)
  483.                 {
  484.                     $array = unserialize($user->meta_value);
  485.                     foreach ($array as $key => $value)
  486.                     {
  487.                         if ($key == $role)
  488.                             $users[] = $user;                  
  489.                     }
  490.                 }
  491.             }
  492.                                    
  493.             if ( $name == $genoptions['rolelevel'])
  494.             {
  495.                 break;
  496.             }
  497.  
  498.         endforeach;
  499.  
  500.         asort($users);
  501.        
  502.         if ($users)
  503.         {
  504.             echo "<select name='bug-library-assignee' style='width: 400px'>";
  505.             echo "<option value='-1'>Unassigned</option>";
  506.             foreach ($users as $user)
  507.             {
  508.                 $firstname = get_user_meta($user->ID, 'first_name', true);
  509.                
  510.                 $lastname = get_user_meta($user->ID, 'last_name', true);
  511.                
  512.                 if ($user->ID == $assigneduserid)
  513.                     $selectedterm = "selected='selected'";
  514.                 else
  515.                     $selectedterm = '';
  516.                
  517.                 echo "<option value='" . $user->ID . "' " . $selectedterm . ">";
  518.                
  519.                 if ($firstname != '' || $lastname != '')
  520.                     echo $firstname . " " . $lastname;
  521.                 else
  522.                     echo $user->user_login;
  523.                    
  524.                 echo "</option>";
  525.             }          
  526.             echo "</select>";
  527.         }
  528.        
  529.         echo "</td></tr>\n";
  530.        
  531.         echo "\t<tr>\n";
  532.         echo "\t\t<td style='width: 150px'>Product</td><td>";
  533.        
  534.         $productterms = get_terms('bug-library-products', 'orderby=name&hide_empty=0');
  535.        
  536.         if ($productterms)
  537.         {
  538.             echo "<select name='bug-library-product' style='width: 400px'>";
  539.             foreach ($productterms as $productterm)
  540.             {
  541.                
  542.                 if ($products[0]->term_id == $productterm->term_id)
  543.                     $selectedterm = "selected='selected'";
  544.                 else
  545.                     $selectedterm = '';
  546.                    
  547.                 echo "<option value='" . $productterm->term_id . "' " . $selectedterm . ">" . $productterm->name . "</option>";
  548.             }      
  549.             echo "</select>";
  550.         }
  551.        
  552.         echo "\t\t</td>\t";
  553.         echo "\t</tr>\n";
  554.  
  555.         echo "\t<tr>\n";
  556.         echo "\t\t<td>Status</td><td>\n";
  557.        
  558.         $statusterms = get_terms('bug-library-status', 'orderby=name&hide_empty=0');
  559.        
  560.         if ($statusterms)
  561.         {
  562.             echo "<select name='bug-library-status' style='width: 400px'>\n";
  563.             foreach ($statusterms as $statusterm)
  564.             {
  565.                 $selectedterm = '';
  566.                
  567.                 if ($statuses[0]->term_id != '')
  568.                 {
  569.                     if ($statuses[0]->term_id == $statusterm->term_id)
  570.                         $selectedterm = "selected='selected'";
  571.                 }
  572.                 elseif ($statuses[0]->term_id == '' && $genoptions['defaultuserbugstatus'] != '')
  573.                 {
  574.                     if ($genoptions['defaultuserbugstatus'] == $statusterm->term_id)
  575.                         $selectedterm = "selected='selected'";
  576.                 }
  577.                    
  578.                 echo "<option value='" . $statusterm->term_id . "' " . $selectedterm . ">" . $statusterm->name . "</option>\n";
  579.             }      
  580.             echo "</select>\n";
  581.         }
  582.        
  583.         echo "</td>\n";
  584.         echo "</tr>\n";
  585.        
  586.         echo "\t<tr>\n";
  587.         echo "\t\t<td>Type</td><td>\n";
  588.        
  589.         $typesterms = get_terms('bug-library-types', 'orderby=name&hide_empty=0');
  590.        
  591.         if ($typesterms)
  592.         {
  593.             echo "<select name='bug-library-types' style='width: 400px'>\n";
  594.             foreach ($typesterms as $typesterm)
  595.             {
  596.                
  597.                 if ($types[0]->term_id == $typesterm->term_id)
  598.                     $selectedterm = "selected='selected'";
  599.                 else
  600.                     $selectedterm = '';
  601.                    
  602.                 echo "<option value='" . $typesterm->term_id . "' " . $selectedterm . ">" . $typesterm->name . "</option>\n";
  603.             }      
  604.             echo "</select>\n";
  605.         }
  606.        
  607.         echo "</td>\n";
  608.         echo "</tr>\n";
  609.        
  610.         echo "\t<tr>\n";
  611.         echo "\t\t<td>Priority</td><td>\n";
  612.        
  613.         $prioritiesterms = get_terms('bug-library-priority', 'orderby=name&hide_empty=0');
  614.        
  615.         if ($prioritiesterms)
  616.         {
  617.             echo "<select name='bug-library-priority' style='width: 400px'>\n";
  618.             foreach ($prioritiesterms as $priorityterm)
  619.             {
  620.                             $selectedterm = '';
  621.                             if ($priorities[0]->term_id != '')
  622.                             {              
  623.                 if ($priorities[0]->term_id == $priorityterm->term_id)
  624.                     $selectedterm = "selected='selected'";
  625.                             }
  626.                             elseif ($priorities[0]->term_id == '' && $genoptions['defaultuserbugpriority'] != '')
  627.                             {
  628.                                     if ($genoptions['defaultuserbugpriority'] == $priorityterm->term_id)
  629.                                             $selectedterm = "selected='selected'";
  630.                             }
  631.                                    
  632.                    
  633.                    
  634.                 echo "<option value='" . $priorityterm->term_id . "' " . $selectedterm . ">" . $priorityterm->name . "</option>\n";
  635.             }      
  636.             echo "</select>\n";
  637.         }
  638.        
  639.         echo "</td>\n";
  640.         echo "</tr>\n";
  641.        
  642.         echo "<tr>\n";
  643.         echo "\t<td>Version</td><td><input type='text' name='bug-library-product-version' ";
  644.        
  645.         if ($productversion != '')
  646.             echo "value='" . $productversion . "'";
  647.        
  648.         echo " /></td>\n";
  649.         echo "</tr>\n";
  650.        
  651.         echo "<tr>\n";
  652.         echo "\t<td>Reporter Name</td><td><input type='text' size='80' name='bug-library-reporter-name' ";
  653.        
  654.         if ($reportername != '')
  655.             echo "value='" . $reportername . "'";
  656.        
  657.         echo " /></td>\n";
  658.         echo "</tr>\n";
  659.        
  660.         echo "<tr>\n";
  661.         echo "\t<td>Reporter E-mail</td><td><input type='text' size='80' name='bug-library-reporter-email' ";
  662.        
  663.         if ($reporteremail != '')
  664.             echo "value='" . $reporteremail . "'";
  665.        
  666.         echo " /></td>\n";
  667.         echo "</tr>\n";
  668.        
  669.         echo "<tr>\n";
  670.         echo "\t<td>Resolution Date</td><td><input type='text' id='bug-library-resolution-date' name='bug-library-resolution-date' ";
  671.        
  672.         if ($resolutiondate != '')
  673.             echo "value='" . $resolutiondate . "'";
  674.        
  675.         echo " /></td>\n";
  676.         echo "</tr>\n";
  677.        
  678.         echo "<tr>\n";
  679.         echo "\t<td>Resolution Version</td><td><input type='text' name='bug-library-resolution-version' ";
  680.        
  681.         if ($resolutionversion != '')
  682.             echo "value='" . $resolutionversion . "'";
  683.        
  684.         echo " /></td>\n";
  685.         echo "</tr>\n";
  686.        
  687.         echo "<tr>\n";
  688.         echo "\t<td>Attached File</td><td>";
  689.        
  690.         if ($imagepath != '')
  691.             echo "<a href='" . $imagepath . "'>File Attachment</a>";
  692.         else
  693.             echo "No file attached to this bug";
  694.            
  695.         echo "</td></tr><tr><td></td><td>Attach new file: <input type='file' name='attachimage' id='attachimage' />";
  696.            
  697.         echo "</td>\n";
  698.         echo "</tr>\n";
  699.        
  700.         echo "</table>\t";
  701.        
  702.         global $blpluginpath;
  703.        
  704.         echo "<script type='text/javascript'>\n";
  705.         echo "\tjQuery(document).ready(function() {\n";
  706.         echo "\t\tjQuery('#bug-library-resolution-date').datepicker({minDate: '+0', dateFormat: 'mm-dd-yy', showOn: 'both', constrainInput: true, buttonImage: '" . $blpluginpath . "/icons/calendar.png'}) });\n";
  707.        
  708.         echo "jQuery( 'form#post' )\n";
  709.         echo "\t.attr( 'enctype', 'multipart/form-data' )\n";
  710.         echo "\t.attr( 'encoding', 'multipart/form-data' )\n";
  711.         echo ";\n";
  712.        
  713.         echo "</script>\n";
  714.    
  715.     }
  716.    
  717.     function add_bug_field($ID = false, $post = false) {
  718.                 $post = get_post($ID);
  719.         if ($post->post_type = 'bug-library-bugs')
  720.         {
  721.             if (isset($_POST['bug-library-product']))
  722.             {
  723.                 $productterm = get_term_by( 'id', $_POST['bug-library-product'], "bug-library-products");
  724.                 if ($productterm)
  725.                 {
  726.                     wp_set_post_terms( $post->ID, $productterm->name, "bug-library-products" );
  727.                 }
  728.             }
  729.            
  730.             if (isset($_POST['bug-library-status']))
  731.             {
  732.                 $statusterm = get_term_by( 'id', $_POST['bug-library-status'], "bug-library-status");
  733.                 if ($statusterm)
  734.                 {
  735.                     wp_set_post_terms( $post->ID, $statusterm->name, "bug-library-status" );
  736.                 }
  737.             }
  738.            
  739.             if (isset($_POST['bug-library-types']))
  740.             {
  741.                 $typeterm = get_term_by( 'id', $_POST['bug-library-types'], "bug-library-types");
  742.                 if ($typeterm)
  743.                 {
  744.                     wp_set_post_terms( $post->ID, $typeterm->name, "bug-library-types" );
  745.                 }
  746.             }
  747.            
  748.             if (isset($_POST['bug-library-priority']))
  749.             {
  750.                 $priorityterm = get_term_by( 'id', $_POST['bug-library-priority'], "bug-library-priority");
  751.                 if ($priorityterm)
  752.                 {
  753.                     wp_set_post_terms( $post->ID, $priorityterm->name, "bug-library-priority" );
  754.                 }
  755.             }
  756.            
  757.             if (isset($_POST['bug-library-product-version']) && $_POST['bug-library-product-version'] != '')
  758.             {
  759.                 update_post_meta($post->ID, "bug-library-product-version", $_POST['bug-library-product-version']);
  760.             }
  761.            
  762.             if (isset($_POST['bug-library-reporter-name']) && $_POST['bug-library-reporter-name'] != '')
  763.             {
  764.                 update_post_meta($post->ID, "bug-library-reporter-name", $_POST['bug-library-reporter-name']);
  765.             }
  766.            
  767.             if (isset($_POST['bug-library-reporter-email']) && $_POST['bug-library-reporter-email'] != '')
  768.             {
  769.                 update_post_meta($post->ID, "bug-library-reporter-email", $_POST['bug-library-reporter-email']);
  770.             }
  771.            
  772.             if (isset($_POST['bug-library-resolution-date']) && $_POST['bug-library-resolution-date'] != '')
  773.             {
  774.                 update_post_meta($post->ID, "bug-library-resolution-date", $_POST['bug-library-resolution-date']);
  775.             }
  776.            
  777.             if (isset($_POST['bug-library-resolution-version']) && $_POST['bug-library-resolution-version'] != '')
  778.             {
  779.                 update_post_meta($post->ID, "bug-library-resolution-version", $_POST['bug-library-resolution-version']);
  780.             }
  781.            
  782.             if (isset($_POST['bug-library-assignee']) && $_POST['bug-library-assignee'] != '')
  783.             {
  784.                 update_post_meta($post->ID, "bug-library-assignee", $_POST['bug-library-assignee']);
  785.             }
  786.            
  787.             $uploads = wp_upload_dir();
  788.                
  789.             if(array_key_exists('attachimage', $_FILES))
  790.             {
  791.                 $target_path = $uploads['basedir'] . "/bug-library/bugimage-" . $post->ID. ".jpg";
  792.                 $file_path = $uploads['baseurl'] . "/bug-library/bugimage-" . $post->ID . ".jpg";
  793.                
  794.                 if (move_uploaded_file($_FILES['attachimage']['tmp_name'], $target_path))
  795.                 {
  796.                     update_post_meta($post->ID, "bug-library-image-path", $file_path);
  797.                 }                  
  798.             }          
  799.         }      
  800.     }
  801.    
  802.     function delete_bug_field($bug_id) {
  803.         delete_post_meta($bug_id, "bug-library-product-version");
  804.         delete_post_meta($bug_id, "bug-library-reporter-name");
  805.         delete_post_meta($bug_id, "bug-library-reporter-email");
  806.         delete_post_meta($bug_id, "bug-library-resolution-date");
  807.         delete_post_meta($bug_id, "bug-library-resolution-version");
  808.     }
  809.    
  810.     /************************** Bug Library Uninstall Function **************************/
  811.     function bl_uninstall() {
  812.         $genoptions = get_option('BugLibraryGeneral');
  813.     }
  814.    
  815.     // Function used to set initial settings or reset them on user request
  816.     function bl_reset_gen_settings()
  817.     {
  818.         global $wpdb;
  819.        
  820.         $genoptions['moderatesubmissions'] = true;
  821.         $genoptions['showcaptcha'] = true;
  822.         $genoptions['requirelogin'] = false;
  823.         $genoptions['entriesperpage'] = 10;
  824.         $genoptions['allowattach'] = false;
  825.         $genoptions['defaultuserbugstatus'] = 'Default Status';
  826.                 $genoptions['defaultuserbugstatus'] = 'Default Priority';
  827.         $genoptions['newbugadminnotify'] = true;
  828.         $genoptions['bugnotifytitle'] = __('New bug added to Wordpress Bug Library: %bugtitle%', 'bug-library');
  829.         $genoptions['permalinkpageid'] = -1;
  830.         $genoptions['firstrowheaders'] = false;
  831.         $genoptions['showpriority'] = false;
  832.         $genoptions['showreporter'] = false;
  833.         $genoptions['rolelevel'] = 'administrator';
  834.         $genoptions['showassignee'] = false;
  835.         $genoptions['editlevel'] = 'administrator';
  836.         $genoptions['requirename'] = false;
  837.         $genoptions['requireemail'] = false;
  838.    
  839.         $stylesheetlocation = get_bloginfo('wpurl') . '/wp-content/plugins/bug-library/stylesheet.css';
  840.         $genoptions['fullstylesheet'] = file_get_contents($stylesheetlocation);
  841.  
  842.         update_option('BugLibraryGeneral', $genoptions);
  843.     }
  844.  
  845.     //for WordPress 2.8 we have to tell, that we support 2 columns !
  846.     function on_screen_layout_columns($columns, $screen) {
  847.         return $columns;
  848.     }
  849.    
  850.     function remove_querystring_var($url, $key) {
  851.         $keypos = strpos($url, $key);
  852.         if ($keypos)
  853.         {
  854.             $ampersandpos = strpos($url, '&', $keypos);
  855.             $newurl = substr($url, 0, $keypos - 1);
  856.            
  857.             if ($ampersandpos)
  858.                 $newurl .= substr($url, $ampersandpos);
  859.         }
  860.         else
  861.             $newurl = $url;
  862.        
  863.         return $newurl;
  864.     }
  865.  
  866.     //extend the admin menu
  867.     function on_admin_menu() {
  868.         //add our own option page, you can also add it to different sections or use your own one
  869.         global $wpdb, $blpluginpath, $pagehooktop, $pagehookstylesheet, $pagehookinstructions;
  870.        
  871.         $pagehooktop = add_menu_page(__('Bug Library General Options', 'bug-library'), "Bug Library", 'manage_options', BUG_LIBRARY_ADMIN_PAGE_NAME, array($this, 'on_show_page'), $blpluginpath . '/icons/bug-icon.png');
  872.                
  873.         $pagehookstylesheet = add_submenu_page( BUG_LIBRARY_ADMIN_PAGE_NAME, __('Bug Library - Stylesheet Editor', 'bug-library') , __('Stylesheet', 'bug-library'), 'manage_options', 'bug-library-stylesheet', array($this,'on_show_page'));
  874.        
  875.         $pagehookinstructions = add_submenu_page( BUG_LIBRARY_ADMIN_PAGE_NAME, __('Bug Library - Instructions', 'bug-library') , __('Instructions', 'bug-library'), 'manage_options', 'bug-library-instructions', array($this,'on_show_page'));
  876.        
  877.         //register  callback gets call prior your own page gets rendered
  878.         add_action('load-'.$pagehooktop, array($this, 'on_load_page'));
  879.         add_action('load-'.$pagehookstylesheet, array($this, 'on_load_page'));
  880.         add_action('load-'.$pagehookinstructions, array($this, 'on_load_page'));
  881.     }
  882.  
  883.     //will be executed if wordpress core detects this page has to be rendered
  884.     function on_load_page() {
  885.    
  886.         global $pagehooktop, $pagehookstylesheet, $pagehookinstructions;
  887.        
  888.         wp_enqueue_script('tiptip', get_bloginfo('wpurl').'/wp-content/plugins/bug-library/tiptip/jquery.tipTip.minified.js', "jQuery", "1.0rc3");
  889.         wp_enqueue_style('tiptipstyle', get_bloginfo('wpurl').'/wp-content/plugins/bug-library/tiptip/tipTip.css');
  890.         wp_enqueue_script('postbox');
  891.        
  892.         //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore
  893.         add_meta_box('buglibrary_general_meta_box', __('General Settings', 'bug-library'), array($this, 'general_meta_box'), $pagehooktop, 'normal', 'high');
  894.         add_meta_box('buglibrary_general_newissue_meta_box', __('User Submission Settings', 'bug-library'), array($this, 'general_meta_newissue_box'), $pagehooktop, 'normal', 'high');
  895.         add_meta_box('buglibrary_general_import_meta_box', __('Import / Export', 'bug-library'), array($this, 'general_importexport_meta_box'), $pagehooktop, 'normal', 'high');
  896.         add_meta_box('buglibrary_general_save_meta_box', __('Save', 'bug-library'), array($this, 'general_save_meta_box'), $pagehooktop, 'normal', 'high');    
  897.        
  898.         add_meta_box('buglibrary_stylesheet_meta_box', __('Stylesheet', 'bug-library'), array($this, 'stylesheet_meta_box'), $pagehookstylesheet, 'normal', 'high');
  899.        
  900.         add_meta_box('buglibrary_instructions_meta_box', __('Instructions', 'bug-library'), array($this, 'instructions_meta_box'), $pagehookinstructions, 'normal', 'high');
  901.     }
  902.  
  903.     //executed to show the plugins complete admin page
  904.     function on_show_page() {
  905.         //we need the global screen column value to beable to have a sidebar in WordPress 2.8
  906.         global $screen_layout_columns, $blpluginpath;
  907.  
  908.         // Retrieve general options
  909.         $genoptions = get_option('BugLibraryGeneral');
  910.  
  911.         // If general options don't exist, create them
  912.         if ($genoptions == FALSE)
  913.         {
  914.             $this->bl_reset_gen_settings();
  915.         }
  916.  
  917.         // Check for current page to set some page=specific variables
  918.         if ($_GET['page'] == 'bug-library')
  919.         {
  920.             if ($_GET['message'] == '1')
  921.                 echo "<div id='message' class='updated fade'><p><strong>" . __('General Settings Saved', 'bug-library') . ".</strong></p></div>";
  922.             elseif ($_GET['message'] == '2')
  923.                 echo  "<div id='message' class='updated fade'><p><strong>" . __('Please create a folder called uploads under your Wordpress /wp-content/ directory with write permissions to use this functionality.', 'bug-library') . ".</strong></p></div>";
  924.             elseif ($_GET['message'] == '3')
  925.                 echo  "<div id='message' class='updated fade'><p><strong>" . __('Please make sure that the /wp-content/uploads/ directory has write permissions to use this functionality.', 'bug-library') . ".</strong></p></div>";
  926.             elseif ($_GET['message'] == '4')
  927.                 echo "<div id='message' class='updated fade'><p><strong>" . __('Invalid column count for bug on row', 'bug-library') . "</strong></p></div>";
  928.             elseif ($_GET['message'] == '9')
  929.                 echo "<div id='message' class='updated fade'><p><strong>" . $_GET['importrowscount'] . " " . __('row(s) found', 'bug-library') . ". " . $_GET['successimportcount'] . " " . __('bugs(s) imported successfully', 'bugs-library') . ".</strong></p></div>";      
  930.                
  931.             $formvalue = 'save_bug_library_general';
  932.             $pagetitle = "Bug Library General Settings";
  933.         }
  934.         elseif ($_GET['page'] == 'bug-library-stylesheet')
  935.         {
  936.             $formvalue = 'save_bug_library_stylesheet';
  937.            
  938.             $pagetitle = "Bug Library Stylesheet Editor";
  939.            
  940.             if ($_GET['message'] == '1')
  941.                 echo "<div id='message' class='updated fade'><p><strong>" . __('Stylesheet updated', 'link-library') . ".</strong></p></div>";
  942.             elseif ($_GET['message'] == '2')
  943.                 echo "<div id='message' class='updated fade'><p><strong>" . __('Stylesheet reset to original state', 'link-library') . ".</strong></p></div>"; 
  944.         }
  945.         elseif ($_GET['page'] == 'bug-library-instructions')
  946.         {
  947.             $formvalue = 'save_bug_library_instructions';
  948.            
  949.             $pagetitle = "Bug Library Usage Instructions";
  950.  
  951.         }
  952.  
  953.         $data = array();
  954.         $data['genoptions'] = $genoptions;
  955.         global $pagehooktop, $pagehookstylesheet, $pagehookinstructions;
  956.         ?>
  957.         <div id="bug-library-general" class="wrap">
  958.         <div class='icon32'><img src="<?php echo $blpluginpath . '/icons/bug-icon32.png'; ?>" /></div>
  959.         <h2><?php echo $pagetitle; ?><span style='padding-left: 50px'><a href="http://yannickcorner.nayanna.biz/wordpress-plugins/bug-library/" target="buglibrary"><img src="<?php echo $blpluginpath; ?>/icons/btn_donate_LG.gif" /></a></span></h2>
  960.         <form name='buglibrary' enctype="multipart/form-data" action="admin-post.php" method="post">
  961.             <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  962.  
  963.             <?php wp_nonce_field('bug-library'); ?>
  964.             <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
  965.             <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
  966.             <input type="hidden" name="action" value="<?php echo $formvalue; ?>" />
  967.  
  968.             <div id="poststuff" class="metabox-holder">
  969.                 <div id="post-body" class="has-sidebar">
  970.                     <div id="post-body-content" class="has-sidebar-content">
  971.                         <?php
  972.                             if ($_GET['page'] == 'bug-library')
  973.                                 do_meta_boxes($pagehooktop, 'normal', $data);
  974.                             elseif ($_GET['page'] == 'bug-library-stylesheet')
  975.                                 do_meta_boxes($pagehookstylesheet, 'normal', $data);
  976.                             elseif ($_GET['page'] == 'bug-library-instructions')
  977.                                 do_meta_boxes($pagehookinstructions, 'normal', $data);
  978.                         ?>
  979.                     </div>
  980.                 </div>
  981.                 <br class="clear"/>
  982.             </div>
  983.         </form>
  984.         </div>
  985.     <script type="text/javascript">
  986.         //<![CDATA[
  987.         jQuery(document).ready( function($) {
  988.             // close postboxes that should be closed
  989.             jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  990.             // postboxes setup
  991.             postboxes.add_postbox_toggles('<?php
  992.                 if ($_GET['page'] == 'bug-library')
  993.                     echo $pagehooktop;
  994.                 elseif ($_GET['page'] == 'bug-library-stylesheet')
  995.                     echo $pagehookstylesheet;
  996.                 elseif ($_GET['page'] == 'bug-library-instructions')
  997.                     echo $pagehookinstructions;
  998.                 ?>');
  999.                
  1000.             jQuery('.bltooltip').each(function()
  1001.                         {
  1002.                         $(this).tipTip();
  1003.                         }
  1004.                 );
  1005.  
  1006.         });
  1007.         //]]>
  1008.  
  1009.         </script>
  1010.  
  1011.         <?php
  1012.     }
  1013.  
  1014.         //executed if the post arrives initiated by pressing the submit button of form
  1015.     function on_save_changes_general() {
  1016.         //user permission check
  1017.         if ( !current_user_can('manage_options') )
  1018.             wp_die( __('Not allowed', 'bug-library') );        
  1019.         //cross check the given referer
  1020.         check_admin_referer('bug-library');
  1021.  
  1022.         $genoptions = get_option('BugLibraryGeneral');
  1023.        
  1024.         if (isset($_POST['importbugs']))
  1025.         {
  1026.             global $wpdb;
  1027.  
  1028.             $handle = fopen($_FILES['bugsfile']['tmp_name'], "r");
  1029.  
  1030.             if ($handle)
  1031.             {
  1032.                 $skiprow = 1;
  1033.  
  1034.                 while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
  1035.                     $row += 1;
  1036.                     if ($skiprow == 1 && isset($_POST['firstrowheaders']) && $row >= 2)
  1037.                         $skiprow = 0;
  1038.                     elseif (!isset($_POST['firstrowheaders']))
  1039.                         $skiprow = 0;
  1040.  
  1041.                     if (!$skiprow)
  1042.                     {
  1043.                         if (count($data) == 13)
  1044.                         {
  1045.                             $new_bug_data = array(
  1046.                                 'post_status' => $data[9],
  1047.                                 'post_type' => 'bug-library-bugs',
  1048.                                 'post_author' => '',
  1049.                                 'ping_status' => get_option('default_ping_status'),
  1050.                                 'post_parent' => 0,
  1051.                                 'menu_order' => 0,
  1052.                                 'to_ping' =>  '',
  1053.                                 'pinged' => '',
  1054.                                 'post_password' => '',
  1055.                                 'guid' => '',
  1056.                                 'post_content_filtered' => '',
  1057.                                 'post_excerpt' => '',
  1058.                                 'import_id' => 0,
  1059.                                 'comment_status' => 'open',
  1060.                                 'post_content' => wp_specialchars(stripslashes($data[5])),
  1061.                                 'post_date' => date('Y-m-d H:i:s', strtotime($data[8])),
  1062.                                 'post_excerpt' => '',
  1063.                                 'post_title' => wp_specialchars(stripslashes($data[4])));
  1064.  
  1065.                             $newbugid = wp_insert_post( $new_bug_data );
  1066.                            
  1067.                             if ($newbugid != -1)
  1068.                             {
  1069.                                 $successfulimport += 1;
  1070.                                 $message = '9';
  1071.                                
  1072.                                 if ($data[1] != '')
  1073.                                     wp_set_post_terms( $newbugid, $data[1], "bug-library-products" );
  1074.                                
  1075.                                 if ($data[3] != '')
  1076.                                     wp_set_post_terms( $newbugid, $data[3], "bug-library-status" );
  1077.                                
  1078.                                 if ($data[0] != '')
  1079.                                     wp_set_post_terms( $newbugid, $data[0], "bug-library-types" );
  1080.                                
  1081.                                 if ($data[2] != '')
  1082.                                 {
  1083.                                     update_post_meta($newbugid, "bug-library-product-version", $data[2]);
  1084.                                 }
  1085.                                
  1086.                                 if ($data[6] != '')
  1087.                                 {
  1088.                                     update_post_meta($newbugid, "bug-library-reporter-name", $data[6]);
  1089.                                 }
  1090.                                
  1091.                                 if ($data[7] != '')
  1092.                                 {
  1093.                                     update_post_meta($newbugid, "bug-library-reporter-email", $data[7]);
  1094.                                 }
  1095.                                
  1096.                                 if ($data[10] != '')
  1097.                                     update_post_meta($newbugid, "bug-library-resolution-date", $data[10]);
  1098.                                    
  1099.                                 if ($data[11] != '')
  1100.                                     update_post_meta($newbugid, "bug-library-resolution-version", $data[11]);
  1101.                                    
  1102.                                 if ($data[12] != '')
  1103.                                     wp_set_post_terms( $newbugid, $data[12], "bug-library-priority" );
  1104.                                    
  1105.                             }
  1106.                         }
  1107.                         else
  1108.                         {
  1109.                             $messages[] = '4';
  1110.                         }
  1111.                     }
  1112.                 }
  1113.             }
  1114.  
  1115.             if (isset($_POST['firstrowheaders']))
  1116.                 $row -= 1;
  1117.            
  1118.             $message = '9';
  1119.         }
  1120.         else
  1121.         {
  1122.             $statusterm = get_term_by('id', $_POST['bug-library-status'], 'bug-library-status');
  1123.             $genoptions['defaultuserbugstatus'] = $statusterm->name;
  1124.                        
  1125.                         $priorityterm = get_term_by('id', $_POST['bug-library-priority'], 'bug-library-priority');
  1126.             $genoptions['defaultuserbugpriority'] = $priorityterm->name;
  1127.            
  1128.             if ($genoptions['allowattach'] == false && $_POST['allowattach'] == true)
  1129.             {
  1130.                 $uploads = wp_upload_dir();
  1131.                
  1132.                 if (!file_exists($uploads['basedir']))
  1133.                 {
  1134.                     $message = 2;
  1135.                     $genoptions['allowattach'] = false;            
  1136.                 }
  1137.                 elseif (!is_writable($uploads['basedir']))
  1138.                 {
  1139.                     $message = 3;
  1140.                     $genoptions['allowattach'] = false;
  1141.                 }
  1142.                 else
  1143.                 {
  1144.                     if (!file_exists($uploads['basedir'] . '/bug-library'))
  1145.                         mkdir($uploads['basedir'] . '/bug-library');
  1146.                        
  1147.                     $genoptions['allowattach'] = true;
  1148.                 }          
  1149.             }
  1150.             elseif ($_POST['allowattach'] == false)
  1151.             {
  1152.                 $genoptions['allowattach'] = false;
  1153.             }
  1154.  
  1155.             foreach (array('entriesperpage', 'bugnotifytitle', 'permalinkpageid', 'rolelevel', 'editlevel') as $option_name) {
  1156.                 if (isset($_POST[$option_name])) {
  1157.                     $genoptions[$option_name] = $_POST[$option_name];
  1158.                 }
  1159.             }
  1160.  
  1161.             foreach (array('moderatesubmissions', 'showcaptcha', 'requirelogin', 'newbugadminnotify', 'firstrowheaders', 'showpriority',
  1162.                             'showreporter', 'showassignee', 'requirename', 'requireemail') as $option_name) {
  1163.                 if (isset($_POST[$option_name])) {
  1164.                     $genoptions[$option_name] = true;
  1165.                 } else {
  1166.                     $genoptions[$option_name] = false;
  1167.                 }
  1168.             }
  1169.  
  1170.             update_option('BugLibraryGeneral', $genoptions);
  1171.            
  1172.             if ($message == '') $message = 1;
  1173.         }
  1174.                
  1175.         global $wp_rewrite;
  1176.         $wp_rewrite->flush_rules();
  1177.        
  1178.         //lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
  1179.         wp_redirect($this->remove_querystring_var($_POST['_wp_http_referer'], 'message') . "&message=" . $message . ($row != 0 ? "&importrowscount=" . $row : '') . ($successfulimport != 0 ? "&successimportcount=" . $successfulimport : ""));
  1180.     }
  1181.  
  1182.         //executed if the post arrives initiated by pressing the submit button of form
  1183.     function on_save_changes_stylesheet() {
  1184.         //user permission check
  1185.         if ( !current_user_can('manage_options') )
  1186.             wp_die( __('Not allowed', 'bug-library') );
  1187.         //cross check the given referer
  1188.         check_admin_referer('bug-library');
  1189.        
  1190.         $message = '';
  1191.         global $wpdb;
  1192.        
  1193.         if (isset($_POST['submitstyle']))
  1194.         {
  1195.             $genoptions = get_option('BugLibraryGeneral');
  1196.  
  1197.             $genoptions['fullstylesheet'] = $_POST['fullstylesheet'];
  1198.  
  1199.             update_option('BugLibraryGeneral', $genoptions);
  1200.             $message = 1;
  1201.         }
  1202.         elseif (isset($_POST['resetstyle']))
  1203.         {
  1204.             $genoptions = get_option('BugLibraryGeneral');
  1205.  
  1206.             $stylesheetlocation = BLDIR . '/stylesheet.css';
  1207.             if (file_exists($stylesheetlocation))
  1208.                 $genoptions['fullstylesheet'] = file_get_contents($stylesheetlocation);
  1209.  
  1210.             update_option('BugLibraryGeneral', $genoptions);
  1211.  
  1212.             $message = 2;
  1213.         }
  1214.        
  1215.         //lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
  1216.         $cleanredirecturl = $this->remove_querystring_var($_POST['_wp_http_referer'], 'message');
  1217.  
  1218.         if ($message != '')
  1219.             $cleanredirecturl .= "&message=" . $message;
  1220.  
  1221.         wp_redirect($cleanredirecturl);
  1222.     }
  1223.    
  1224.     //executed if the post arrives initiated by pressing the submit button of form
  1225.     function on_save_changes_instructions() {
  1226.         //user permission check
  1227.         if ( !current_user_can('manage_options') )
  1228.             wp_die( __('Not allowed', 'bug-library') );
  1229.         //cross check the given referer
  1230.         check_admin_referer('bug-library');
  1231.  
  1232.         wp_redirect($this->remove_querystring_var($_POST['_wp_http_referer'], 'message') . "&message=1");
  1233.     }
  1234.  
  1235.     function general_meta_box($data) {
  1236.         $genoptions = $data['genoptions'];
  1237.  
  1238.         ?>
  1239.             <table>
  1240.             <tr>
  1241.             <td style='vertical-align: top; padding-right: 10px;'>
  1242.                 <table>
  1243.                 <tr>
  1244.                     <td style='width: 200px'>Number of entries per page</td>
  1245.                     <td><input style="width:100%" type="text" name="entriesperpage" <?php echo "value='" . $genoptions['entriesperpage'] . "'";?>/></td>
  1246.                     </tr>
  1247.                     <tr>
  1248.                     <td class='bltooltip' title='Must re-apply permalink rules for this option to take effect'>Parent page (for permalink structure)</td>
  1249.                     <td class='bltooltip' title='Must re-apply permalink rules for this option to take effect'>
  1250.                     <?php $pages = get_pages(array('parent' => 0, 'sort_column' => 'post_title'));
  1251.                    
  1252.                     if ($pages): ?>
  1253.                         <select name='permalinkpageid' style='width: 200px'>
  1254.                             <option value='-1'>Default (bugs)</option>
  1255.                         <?php foreach ($pages as $page):                   
  1256.                             if ($page->ID == $genoptions['permalinkpageid'])
  1257.                             {
  1258.                                 $selectedterm = "selected='selected'";
  1259.                             }
  1260.                             else
  1261.                             {
  1262.                                 $selectedterm = '';
  1263.                             } ?>
  1264.                                
  1265.                             <option value='<?php echo $page->ID; ?>' <?php echo $selectedterm; ?>><?php echo $page->post_title; ?></option>
  1266.                         <?php endforeach; ?>
  1267.                         </select>
  1268.                     <?php endif; ?>
  1269.                     </td>
  1270.                     </tr>
  1271.                     <tr>
  1272.                         <td>Show bug priorities</td>
  1273.                         <td><input type="checkbox" id="showpriority" name="showpriority" <?php if ($genoptions['showpriority']) echo ' checked="checked" '; ?>/></td>
  1274.                     </tr>
  1275.                     <tr>
  1276.                         <td>Show reporter name</td>
  1277.                         <td><input type="checkbox" id="showreporter" name="showreporter" <?php if ($genoptions['showreporter']) echo ' checked="checked" '; ?>/></td>
  1278.                     </tr>
  1279.                     <tr>
  1280.                         <td>Show assigned user</td>
  1281.                         <td><input type="checkbox" id="showassignee" name="showassignee" <?php if ($genoptions['showassignee']) echo ' checked="checked" '; ?>/></td>
  1282.                     </tr>
  1283.                     <tr>
  1284.                         <td>Minimum role for bug assignment</td>
  1285.                         <td>
  1286.                             <?php global $wp_roles;
  1287.                                   if ($wp_roles):?>
  1288.                                         <select name='rolelevel' style='width: 200px'>
  1289.                                         <?php $roles = $wp_roles->roles;
  1290.                                              
  1291.                                             foreach ($roles as $role):
  1292.                                             if ($genoptions['rolelevel'] == $role['name'])
  1293.                                             {
  1294.                                                 $selectedterm = "selected='selected'";
  1295.                                             }
  1296.                                             else
  1297.                                             {
  1298.                                                 $selectedterm = '';
  1299.                                             } ?>
  1300.                                             <option value='<?php echo $role['name']; ?>' <?php echo $selectedterm; ?>><?php echo $role['name']; ?></option>
  1301.                                         <?php endforeach; ?>
  1302.                                         </select>
  1303.                                   <?php endif; ?>
  1304.                         </td>
  1305.                     </tr>
  1306.                     <tr>
  1307.                         <td>Minimum role to get bug edit link</td>
  1308.                         <td>
  1309.                             <?php if ($wp_roles):?>
  1310.                                         <select name='editlevel' style='width: 200px'>
  1311.                                         <?php $roles = $wp_roles->roles;
  1312.                                              
  1313.                                             foreach ($roles as $role):
  1314.                                             if ($genoptions['editlevel'] == $role['name'])
  1315.                                             {
  1316.                                                 $selectedterm = "selected='selected'";
  1317.                                             }
  1318.                                             else
  1319.                                             {
  1320.                                                 $selectedterm = '';
  1321.                                             } ?>
  1322.                                             <option value='<?php echo $role['name']; ?>' <?php echo $selectedterm; ?>><?php echo $role['name']; ?></option>
  1323.                                         <?php endforeach; ?>
  1324.                                         </select>
  1325.                                   <?php endif; ?>
  1326.                         </td>
  1327.                     </tr>
  1328.                 </table>
  1329.             </td>
  1330.             <td style='padding: 8px; border: 1px solid #cccccc;'>
  1331.                 <div><h3>ThemeFuse Original WP Themes</h3><br />If you are looking to buy an original WP theme, take a look at <a href="https://www.e-junkie.com/ecom/gb.php?cl=136641&c=ib&aff=153522" target="ejejcsingle">ThemeFuse</a><br />They have a nice 1-click installer, great support and good-looking themes.</div><div style='text-align: center; padding-top: 10px'><a href="https://www.e-junkie.com/ecom/gb.php?cl=136641&c=ib&aff=153522" target="ejejcsingle"><img src='http://themefuse.com/wp-content/themes/themefuse/images/campaigns/themefuse.jpg' /></a></div>
  1332.             </td>
  1333.             </tr>
  1334.             </table>
  1335.         <?php }
  1336.        
  1337.     function general_meta_newissue_box($data) {
  1338.         $genoptions = $data['genoptions'];
  1339.     ?>
  1340.         <table>
  1341.             <tr>
  1342.                 <td style='width: 300px'>Moderate new submissions</td>
  1343.                 <td><input type="checkbox" id="moderatesubmissions" name="moderatesubmissions" <?php if ($genoptions['moderatesubmissions']) echo ' checked="checked" '; ?>/></td>
  1344.                 <td style='width: 40px'></td>
  1345.                 <td style='width: 300px'>Show Captcha in submission form</td>
  1346.                 <td><input type="checkbox" id="showcaptcha" name="showcaptcha" <?php if ($genoptions['showcaptcha']) echo ' checked="checked" '; ?>/></td>
  1347.             </tr>
  1348.             <tr>
  1349.                 <td>Allow file attachments</td>
  1350.                 <td><input type="checkbox" id="allowattach" name="allowattach" <?php if ($genoptions['allowattach']) echo ' checked="checked" '; ?>/></td>
  1351.                 <td></td>
  1352.                 <td>Require login to submit new issues</td>
  1353.                 <td><input type="checkbox" id="requirelogin" name="requirelogin" <?php if ($genoptions['requirelogin']) echo ' checked="checked" '; ?>/></td>
  1354.             </tr>
  1355.             <tr>
  1356.                 <td>Require Reporter Name</td>
  1357.                 <td><input type="checkbox" id="requirename" name="requirename" <?php if ($genoptions['requirename']) echo ' checked="checked" '; ?>/></td>
  1358.                 <td></td>
  1359.                 <td>Require Product Version</td>
  1360.                 <td><input type="checkbox" id="requireemail" name="requireemail" <?php if ($genoptions['requireemail']) echo ' checked="checked" '; ?>/></td>
  1361.             </tr>
  1362.             <tr>
  1363.                 <td>Default user bug status</td>
  1364.                 <td>
  1365.                
  1366.                 <?php $statusterms = get_terms('bug-library-status', 'orderby=name&hide_empty=0');
  1367.        
  1368.                 if ($statusterms): ?>
  1369.                     <select name='bug-library-status' style='width: 200px'>
  1370.                     <?php foreach ($statusterms as $statusterm):                   
  1371.                         if ($statusterm->name == $genoptions['defaultuserbugstatus'])
  1372.                         {
  1373.                             $selectedterm = "selected='selected'";
  1374.                         }
  1375.                         else
  1376.                         {
  1377.                             $selectedterm = '';
  1378.                         } ?>
  1379.                            
  1380.                         <option value='<?php echo $statusterm->term_id; ?>' <?php echo $selectedterm; ?>><?php echo $statusterm->name; ?></option>
  1381.                     <?php endforeach; ?>
  1382.                     </select>
  1383.                 <?php endif; ?>
  1384.                 </td>
  1385.                                 <td></td>
  1386.                 <td>Default user bug priority</td>
  1387.                 <td>
  1388.                
  1389.                 <?php $priorityterms = get_terms('bug-library-priority', 'orderby=name&hide_empty=0');
  1390.        
  1391.                 if ($priorityterms): ?>
  1392.                     <select name='bug-library-priority' style='width: 200px'>
  1393.                     <?php foreach ($priorityterms as $priorityterm):                   
  1394.                         if ($priorityterm->name == $genoptions['defaultuserbugpriority'])
  1395.                         {
  1396.                             $selectedterm = "selected='selected'";
  1397.                         }
  1398.                         else
  1399.                         {
  1400.                             $selectedterm = '';
  1401.                         } ?>
  1402.                            
  1403.                         <option value='<?php echo $priorityterm->term_id; ?>' <?php echo $selectedterm; ?>><?php echo $priorityterm->name; ?></option>
  1404.                     <?php endforeach; ?>
  1405.                     </select>
  1406.                 <?php endif; ?>
  1407.                 </td>
  1408.             </tr>
  1409.             <tr>
  1410.                 <td>Notify admin of new bugs</td>
  1411.                 <td><input type="checkbox" id="newbugadminnotify" name="newbugadminnotify" <?php if ($genoptions['newbugadminnotify']) echo ' checked="checked" '; ?>/></td>
  1412.             </tr>
  1413.             <tr>
  1414.                 <td class='bltooltip' title='Set the title of new bug e-mail notifications. Use variable %bugtitle% to be replaced by the new bug title.'>New bug notification title</td>
  1415.                 <td colspan='4' class='bltooltip' title='Set the title of new bug e-mail notifications. Use variable %bugtitle% to be replaced by the new bug title.'><input style="width:100%" type="text" size='80' name="bugnotifytitle" <?php echo "value='" . $genoptions['bugnotifytitle'] . "'";?>/></td>
  1416.             </tr>
  1417.         </table>
  1418.    
  1419.     <?php }
  1420.    
  1421.     function general_importexport_meta_box($data) {
  1422.         $genoptions = $data['genoptions'];
  1423.     ?>
  1424.         <table>
  1425.             <tr>
  1426.                 <td>First Row Contains Headers</td>
  1427.                 <td><input type="checkbox" id="firstrowheaders" name="firstrowheaders" <?php if ($genoptions['firstrowheaders']) echo ' checked="checked" '; ?>/></td>
  1428.             </tr>
  1429.             <tr>
  1430.                 <td class='bltooltip' title='<?php _e('Allows for bugs to be added in batch to the Wordpress bugs database. CSV file needs to follow template for column layout.', 'bug-library'); ?>' style='width: 330px'><?php _e('CSV file to upload to import bugs', 'bug-library'); ?> (<a href="<?php global $blpluginpath; echo $blpluginpath . 'importtemplate.csv'; ?>"><?php _e('file template', 'bug-library'); ?></a>)</td>
  1431.                 <td><input size="80" name="bugsfile" type="file" /></td>
  1432.                 <td><input type="submit" name="importbugs" value="<?php _e('Import Bugs', 'link-library'); ?>" /></td>
  1433.             </tr>
  1434.         </table>
  1435.     <?php
  1436.     }
  1437.        
  1438.     function general_save_meta_box() {
  1439.     ?>
  1440.         <div class="submitbox">
  1441.         <input type="submit" name="submit" class="button-primary" value="<?php _e('Save','bug-library'); ?>" />
  1442.         </div>
  1443.     <?php
  1444.     }
  1445.  
  1446.     function stylesheet_meta_box($data) {
  1447.         $genoptions = $data['genoptions'];
  1448.     ?>
  1449.         <textarea name='fullstylesheet' id='fullstylesheet' style='font-family:Courier' rows="30" cols="90"><?php echo stripslashes($genoptions['fullstylesheet']);?></textarea>
  1450.         <div><input type="submit" name="submitstyle" value="<?php _e('Submit','bug-library'); ?>" /><input type="submit" name="resetstyle" value="<?php _e('Reset to default','bug-library'); ?>" /></div>
  1451.  
  1452.     <?php
  1453.     }
  1454.    
  1455.     function instructions_meta_box() {
  1456.     ?>
  1457.         <ol>
  1458.             <li>To get a basic Bug Library list showing on one of your Wordpress pages, create a new page and type the following text: [bug-library]</li>
  1459.             <li>Configure the Bug Library General Options section for more control over the plugin functionality.</li>
  1460.             <li>Copy the file single-bug-library-bugs.php from the bug-library plugin directory to your theme directory to display all information related to your bugs. You might have to edit this file a bit and compare it to single.php to get the proper layout to show up on your web site.</li>
  1461.         </ol>
  1462.     <?php
  1463.     }
  1464.  
  1465.    
  1466.    
  1467.     /******************************************** Print style data to header *********************************************/
  1468.  
  1469.     function bl_page_header() {
  1470.         $genoptions = get_option('BugLibraryGeneral');
  1471.  
  1472.         echo "<style id='BugLibraryStyle' type='text/css'>\n";
  1473.             echo stripslashes($genoptions['fullstylesheet']);
  1474.         echo "</style>\n";
  1475.     }
  1476.    
  1477.     function bl_admin_header() {
  1478.         echo "<link rel='stylesheet' id='datePickerstyle-css'  href='/wp-content/plugins/bug-library/css/ui-lightness/jquery-ui-1.8.4.custom.css?ver=3.0.4' type='text/css' media='all' />\n";
  1479.         echo "<script type='text/javascript' src='/wp-content/plugins/bug-library/js/ui.datepicker.js?ver=3.0.4'></script>\n";
  1480.     }
  1481.  
  1482.     function bl_highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
  1483.     {
  1484.         if ($str == '')
  1485.         {
  1486.             return '';
  1487.         }
  1488.  
  1489.         if ($phrase != '')
  1490.         {
  1491.             return preg_replace('/('.preg_quote($phrase, '/').'(?![^<]*>))/i', $tag_open."\\1".$tag_close, $str);
  1492.         }
  1493.  
  1494.         return $str;
  1495.     }
  1496.  
  1497.     function BugLibrary($entriesperpage = 10, $moderatesubmissions = true, $bugcategorylist = '', $requirelogin = false, $permalinkpageid = -1,
  1498.                         $showpriority = false, $showreporter = false, $showassignee = false, $shortcodebugtypeid = '', $shortcodebugstatusid = '', $shortcodebugpriorityid = '') {
  1499.  
  1500.         global $wpdb, $blpluginpath;
  1501.        
  1502.         if (isset($_GET['bugid']))
  1503.         {
  1504.             $bugid = intval($_GET['bugid']);
  1505.             $view = 'single';
  1506.         }
  1507.         else
  1508.         {
  1509.             $bugid = -1;
  1510.             $view = 'list';
  1511.            
  1512.             if (isset($_GET['bugpage']))
  1513.             {
  1514.                 $pagenumber = intval($_GET['bugpage']);
  1515.             }
  1516.             else
  1517.             {
  1518.                 $pagenumber = 1;
  1519.             }
  1520.            
  1521.             if (isset($_GET['bugcatid']))
  1522.             {
  1523.                 $bugcatid = intval($_GET['bugcatid']);         
  1524.             }
  1525.             else
  1526.             {
  1527.                 $bugcatid = -1;
  1528.             }
  1529.            
  1530.             if (isset($_GET['bugtypeid']))
  1531.             {
  1532.                             $bugtypeid = intval($_GET['bugtypeid']);
  1533.             }
  1534.                         elseif ($shortcodebugtypeid != '')
  1535.                         {
  1536.                             $bugtypeid = $shortcodebugtypeid;
  1537.                         }
  1538.             else
  1539.             {
  1540.                             $bugtypeid = -1;
  1541.             }
  1542.            
  1543.             if (isset($_GET['bugstatusid']))
  1544.             {
  1545.                             $bugstatusid = intval($_GET['bugstatusid']);
  1546.             }
  1547.                         elseif ($shortcodebugstatusid != '')
  1548.                         {
  1549.                             $bugstatusid = $shortcodebugstatusid;
  1550.                         }
  1551.             else
  1552.             {
  1553.                             $bugstatusid = -1;
  1554.             }
  1555.            
  1556.             if (isset($_GET['bugpriorityid']))
  1557.             {
  1558.                 $bugpriorityid = intval($_GET['bugpriorityid']);
  1559.             }
  1560.                         elseif ($shortcodebugpriorityid != '')
  1561.                         {
  1562.                             $bugpriorityid = $shortcodepriorityid;
  1563.                         }
  1564.             else
  1565.             {
  1566.                 $bugpriorityid = -1;
  1567.             }          
  1568.         }
  1569.        
  1570.         $bugquery = "SELECT bugs.*, UNIX_TIMESTAMP(bugs.post_date) as bug_date_unix, pt.name as productname, pt.term_id as pid, st.name as statusname, ";
  1571.         $bugquery .= "st.term_id as sid, tt.name as typename, tt.term_id as tid, pt.slug as productslug, st.slug as statusslug, tt.slug as typeslug, tpr.name as priorityname ";
  1572.         $bugquery .= "FROM $wpdb->posts bugs LEFT JOIN " . $wpdb->get_blog_prefix() . "term_relationships trp ";
  1573.         $bugquery .= "ON bugs.ID = trp.object_id LEFT JOIN ";
  1574.         $bugquery .= $wpdb->get_blog_prefix() . "term_taxonomy ttp ON trp.term_taxonomy_id = ttp.term_taxonomy_id LEFT JOIN " . $wpdb->get_blog_prefix();
  1575.         $bugquery .= "terms pt ON ttp.term_id = pt.term_id LEFT JOIN " . $wpdb->get_blog_prefix() . "term_relationships trs ON bugs.ID = trs.object_id ";
  1576.         $bugquery .= "LEFT JOIN " . $wpdb->get_blog_prefix() . "term_taxonomy tts ON trs.term_taxonomy_id = tts.term_taxonomy_id LEFT JOIN " . $wpdb->get_blog_prefix();
  1577.         $bugquery .= "terms st ON tts.term_id = st.term_id LEFT JOIN " . $wpdb->get_blog_prefix() . "term_relationships trt ON bugs.ID = trt.object_id ";
  1578.         $bugquery .= "LEFT JOIN " . $wpdb->get_blog_prefix() . "term_taxonomy ttt ON trt.term_taxonomy_id = ttt.term_taxonomy_id LEFT JOIN " . $wpdb->get_blog_prefix();
  1579.         $bugquery .= "terms tt ON ttt.term_id = tt.term_id LEFT JOIN " . $wpdb->get_blog_prefix() . "term_relationships trpr ON bugs.ID = trpr.object_id ";
  1580.         $bugquery .= "LEFT OUTER JOIN " . $wpdb->get_blog_prefix() . "term_taxonomy ttpr ON trpr.term_taxonomy_id = ttpr.term_taxonomy_id LEFT OUTER JOIN " . $wpdb->get_blog_prefix();
  1581.         $bugquery .= "terms tpr ON ttpr.term_id = tpr.term_id ";
  1582.        
  1583.         $bugquery .= "WHERE bugs.post_type = 'bug-library-bugs' AND ttp.taxonomy = 'bug-library-products' ";
  1584.         $bugquery .= "AND tts.taxonomy = 'bug-library-status' AND ttt.taxonomy = 'bug-library-types' AND ttpr.taxonomy = 'bug-library-priority' ";
  1585.        
  1586.         if ($bugcategorylist != '')
  1587.         {
  1588.             $bugquery .= "AND pt.term_id in ('" . $bugcategorylist . "') ";
  1589.         }
  1590.    
  1591.         if ($view == 'single')
  1592.         {
  1593.             if ($bugid != -1)
  1594.                 $bugquery .= " and ID = " . $bugid;
  1595.         }
  1596.         elseif ($view == 'list')
  1597.         {
  1598.             if ($bugstatusid != -1)
  1599.                 $bugquery .= " and tts.term_id = " . $bugstatusid;
  1600.            
  1601.             if ($bugcatid != -1)
  1602.                 $bugquery .= " and ttp.term_id = " . $bugcatid;
  1603.                
  1604.             if ($bugtypeid != -1)
  1605.                 $bugquery .= " and ttt.term_id = " . $bugtypeid;
  1606.                
  1607.             if ($bugpriorityid != -1)
  1608.                 $bugquery .= " and ttpr.term_id = " . $bugpriorityid;
  1609.         }
  1610.        
  1611.         if ($moderatesubmissions == true)
  1612.             $bugquery .= " and bugs.post_status = 'publish' ";
  1613.        
  1614.         $bugquery .= " order by bugs.post_date DESC";
  1615.        
  1616.         //echo $bugquery;
  1617.        
  1618.         $startingentry = ($pagenumber - 1) * $entriesperpage;
  1619.         $quantity = $entriesperpage + 1;
  1620.        
  1621.         $countbugsquery = str_replace('bugs.*, UNIX_TIMESTAMP(bugs.post_date) as bug_date_unix, pt.name as productname, pt.term_id as pid, st.name as statusname, st.term_id as sid, tt.name as typename, tt.term_id as tid, pt.slug as productslug, st.slug as statusslug, tt.slug as typeslug', 'count(*)', $bugquery);
  1622.        
  1623.         $bugscount = $wpdb->get_var($countbugsquery);
  1624.        
  1625.         if ($view == 'list')
  1626.             $bugquery .= " LIMIT " . $startingentry . ", " . $quantity;
  1627.        
  1628.         $bugs = $wpdb->get_results($bugquery, ARRAY_A);
  1629.        
  1630.         //print_r($bugs);
  1631.        
  1632.         if ($entriesperpage == 0 && $entriesperpage == '')
  1633.             $entriesperpage = 10;
  1634.  
  1635.         if (count($bugs) > $entriesperpage)
  1636.         {
  1637.             array_pop($bugs);
  1638.             $nextpage = true;
  1639.         }
  1640.         else
  1641.             $nextpage = false;
  1642.            
  1643.         $preroundpages = $bugscount / $entriesperpage;
  1644.         $numberofpages = ceil( $preroundpages * 1 ) / 1;
  1645.        
  1646.         $output = "<div id='bug-library-list'>\n";
  1647.        
  1648.         if ($view == 'list')
  1649.         {
  1650.             // Filter List
  1651.            
  1652.             $output .= "<div id='bug-library-currentfilters'>
  1653.                 <div class='bug-library-filteredby'>Filtered by: ";
  1654.            
  1655.             if (($bugcatid == -1) && ($bugtypeid == -1) && ($bugstatusid == -1) && ($bugpriorityid == -1))
  1656.                 $output .= "None";         
  1657.            
  1658.             if ($bugcatid != -1)
  1659.             {
  1660.                 $products = get_term_by( 'id', $bugcatid, "bug-library-products", ARRAY_A);
  1661.                 $output .= "Products (" . $products['name'] . ")";
  1662.             }
  1663.            
  1664.             if ($bugtypeid != -1)
  1665.             {
  1666.                 if ($bugcatid != -1)
  1667.                     $output .= ", ";
  1668.                    
  1669.                 $types = get_term_by( 'id', $bugtypeid, "bug-library-types", ARRAY_A);
  1670.                 $output .= "Type (" . $types['name'] . ")";
  1671.             }
  1672.            
  1673.             if ($bugstatusid != -1)
  1674.             {
  1675.                 if (($bugcatid != -1) || ($bugtypeid != -1))
  1676.                     $output .= ", ";
  1677.                 $statuses = get_term_by( 'id', $bugstatusid, "bug-library-status", ARRAY_A);
  1678.                 $output .= "Status (" . $statuses['name'] . ")";
  1679.             }
  1680.            
  1681.             if ($bugpriorityid != -1)
  1682.             {
  1683.                 if (($bugcatid != -1) || ($bugtypeid != -1) || ($bugstatusid != -1))
  1684.                     $output .= ", ";
  1685.                 $priorities = get_term_by( 'id', $bugpriorityid, "bug-library-priority", ARRAY_A);
  1686.                 $output .= "Priority (" . $priorities['name'] . ")";
  1687.             }
  1688.            
  1689.             $output .= "</div><div class='bug-library-filterchange'><a href='#'>Change Filter</a></div>";
  1690.            
  1691.             $cleanuri = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugid");
  1692.             $cleanuri = $this->remove_querystring_var($cleanuri, "bugcatid");
  1693.             $cleanuri = $this->remove_querystring_var($cleanuri, "bugstatusid");
  1694.             $cleanuri = $this->remove_querystring_var($cleanuri, "bugtypeid");
  1695.             $cleanuri = $this->remove_querystring_var($cleanuri, "bugpriorityid");
  1696.  
  1697.             if ($permalinkpageid != -1)
  1698.             {
  1699.                 $parentpage = get_post($permalinkpageid);
  1700.                 $parentslug = $parentpage->post_name;
  1701.             }
  1702.             else
  1703.             {
  1704.                 $parentslug = 'bugs';
  1705.             }
  1706.  
  1707.             $output .= "<div class='bug-library-remove-all-filters'><a href='/" . $parentslug. "'>Remove all filters</a></div>";
  1708.            
  1709.             $output .= "</div>";
  1710.            
  1711.             if ($view == 'list' && ($requirelogin == false || is_user_logged_in()))
  1712.             {
  1713.                 $output .= "<div id='bug-library-newissuebutton'><button id='submitnewissue'>Report new issue</button></div>";
  1714.             }
  1715.            
  1716.             $output .= "<div id='bug-library-filters'>";
  1717.             $output .= "<div class='bug-library-filter bug-library-filter-product'>";
  1718.             $output .= "<div class='bug-library-filter-producttitle'>Products</div>";
  1719.            
  1720.             $output .= "<div class='bug-library-filter-productitems'>";
  1721.            
  1722.             $products = get_terms('bug-library-products', 'orderby=name&hide_empty=0');
  1723.            
  1724.             if ($products)
  1725.             {
  1726.                 $bugcaturi = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugcatid");
  1727.                
  1728.                 if (strpos($bugcaturi, '?') === false)
  1729.                 {
  1730.                     if (strpos($bugcaturi, '&') === false)
  1731.                         $queryoperator = '?';
  1732.                     elseif (strpos($bugcaturi, '&') !== false)
  1733.                     {
  1734.                         $ampersandpos = strpos($bugcaturi, '&');
  1735.                         $bugcaturi = preg_replace('/&/', '?', $bugcaturi, 1);
  1736.                         $queryoperator = '&';
  1737.                     }
  1738.                 }
  1739.                 else
  1740.                     $queryoperator = '&';
  1741.                
  1742.                 if ($bugcatid == -1 )
  1743.                     $output .= "<span class='bug-library-filter-currentproduct'>All Products</span>";
  1744.                 else
  1745.                     $output .= "<a href='" . $bugcaturi . "'>All Products</a>";
  1746.                
  1747.                 foreach ($products as $product)
  1748.                 {
  1749.                     $bugcategoryarray = explode(",", $bugcategorylist);
  1750.                    
  1751.                     if (($bugcategorylist != '' && in_array($product->term_id, $bugcategoryarray)) || $bugcategorylist == '')
  1752.                     {
  1753.                             if ($product->term_id == $bugcatid)
  1754.                                 $output .= "<span id='bug-library-filter-currentproduct'>" . stripslashes($product->name) . "</span>";
  1755.                             else
  1756.                                 $output .= "<a href='" . $bugcaturi . $queryoperator . "bugcatid=" . $product->term_id .  "'>" . stripslashes($product->name) . "</a>";
  1757.                     }
  1758.                 }
  1759.             }
  1760.            
  1761.             $output .= "</div></div>";
  1762.            
  1763.             $output .= "<div class='bug-library-filter bug-library-filter-types'>";
  1764.             $output .= "<div class='bug-library-filter-typestitle'>Types</div>";
  1765.            
  1766.             $output .= "<div class='bug-library-filter-typesitems'>";
  1767.            
  1768.             $types = get_terms('bug-library-types', 'orderby=name&hide_empty=0');
  1769.            
  1770.             if ($types)
  1771.             {
  1772.                 $bugtypeuri = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugtypeid");
  1773.            
  1774.                 if (strpos($bugtypeuri, '?') === false)
  1775.                 {
  1776.                     if (strpos($bugtypeuri, '&') === false)
  1777.                         $queryoperator = '?';
  1778.                     elseif (strpos($bugtypeuri, '&') !== false)
  1779.                     {
  1780.                         $ampersandpos = strpos($bugtypeuri, '&');
  1781.                         $bugtypeuri = preg_replace('/&/', '?', $bugtypeuri, 1);
  1782.                         $queryoperator = '&';
  1783.                     }
  1784.                 }
  1785.                 else
  1786.                     $queryoperator = '&';
  1787.                
  1788.                 if ($bugtypeid == -1 )
  1789.                     $output .= "<span class='bug-library-filter-currentproduct'>All Types</span>";
  1790.                 else
  1791.                     $output .= "<a href='" . $bugtypeuri . "'>All Types</a>";
  1792.                
  1793.                 foreach ($types as $type)
  1794.                 {
  1795.                     if ($type->term_id == $bugtypeid)
  1796.                         $output .= "<span class='bug-library-filter-currentproduct'>" . stripslashes($type->name) . "</span>";
  1797.                     else
  1798.                         $output .= "<a href='" . $bugtypeuri . $queryoperator . "bugtypeid=" . $type->term_id .  "'>" . stripslashes($type->name) . "</a>";
  1799.                 }
  1800.             }
  1801.            
  1802.             $output .= "</div></div>";
  1803.            
  1804.             $output .= "<div class='bug-library-filter bug-library-filter-status'>";
  1805.             $output .= "<div class='bug-library-filter-statustitle'>Status</div>";
  1806.            
  1807.             $output .= "<div class='bug-library-filter-statusitems'>";
  1808.            
  1809.             $statuses = get_terms('bug-library-status', 'orderby=name&hide_empty=0');
  1810.            
  1811.             if ($statuses)
  1812.             {
  1813.                 $bugstatusuri = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugstatusid");
  1814.                
  1815.                 if (strpos($bugstatusuri, '?') === false)
  1816.                 {
  1817.                     if (strpos($bugstatusuri, '&') === false)
  1818.                         $queryoperator = '?';
  1819.                     elseif (strpos($bugstatusuri, '&') !== false)
  1820.                     {
  1821.                         $ampersandpos = strpos($bugstatusuri, '&');
  1822.                         $bugstatusuri = preg_replace('/&/', '?', $bugstatusuri, 1);
  1823.                         $queryoperator = '&';
  1824.                     }
  1825.                 }
  1826.                 else
  1827.                     $queryoperator = '&';
  1828.                
  1829.                 if ($bugstatusid == -1 )
  1830.                     $output .= "<span class='bug-library-filter-currentstatus'>All Statuses</span>";
  1831.                 else
  1832.                     $output .= "<a href='" . $bugstatusuri . "'>All Statuses</a>";
  1833.                
  1834.                 foreach ($statuses as $status)
  1835.                 {
  1836.                     if ($status->term_id == $bugstatusid)
  1837.                         $output .= "<span class='bug-library-filter-currentproduct'>" . stripslashes($status->name) . "</span>";
  1838.                     else
  1839.                         $output .= "<a href='" . $bugstatusuri . $queryoperator . "bugstatusid=" . $status->term_id .  "'>" . stripslashes($status->name) . "</a>";
  1840.                 }
  1841.             }
  1842.            
  1843.             $output .= "</div></div>";
  1844.            
  1845.             $output .= "<div class='bug-library-filter bug-library-filter-priorities'>";
  1846.             $output .= "<div class='bug-library-filter-prioritiestitle'>Priorities</div>";
  1847.            
  1848.             $output .= "<div class='bug-library-filter-prioritiesitems'>";
  1849.            
  1850.             $priorities = get_terms('bug-library-priority', 'orderby=name&hide_empty=0');
  1851.            
  1852.             if ($priorities)
  1853.             {
  1854.                 $bugpriorityuri = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugpriorityid");
  1855.            
  1856.                 if (strpos($bugpriorityuri, '?') === false)
  1857.                 {
  1858.                     if (strpos($bugpriorityuri, '&') === false)
  1859.                         $queryoperator = '?';
  1860.                     elseif (strpos($bugpriorityuri, '&') !== false)
  1861.                     {
  1862.                         $ampersandpos = strpos($bugpriorityuri, '&');
  1863.                         $bugpriorityuri = preg_replace('/&/', '?', $bugpriorityuri, 1);
  1864.                         $queryoperator = '&';
  1865.                     }
  1866.                 }
  1867.                 else
  1868.                     $queryoperator = '&';
  1869.                
  1870.                 if ($bugpriorityid == -1 )
  1871.                     $output .= "<span class='bug-library-filter-currentpriorities'>All Priorities</span>";
  1872.                 else
  1873.                     $output .= "<a href='" . $bugpriorityuri . "'>All Priorities</a>";
  1874.                
  1875.                 foreach ($priorities as $priority)
  1876.                 {
  1877.                     if ($priority->term_id == $bugpriorityid)
  1878.                         $output .= "<span class='bug-library-filter-currentproduct'>" . stripslashes($priority->name) . "</span>";
  1879.                     else
  1880.                         $output .= "<a href='" . $bugpriorityuri . $queryoperator . "bugpriorityid=" . $priority->term_id .  "'>" . stripslashes($priority->name) . "</a>";
  1881.                 }
  1882.             }
  1883.            
  1884.             $output .= "</div></div>";
  1885.            
  1886.             $output .= "</div>";
  1887.         }
  1888.  
  1889.         if ($bugs)
  1890.         {
  1891.             $output .= "<div class='bug-library-item-table'>";
  1892.            
  1893.             $counter = 1;
  1894.            
  1895.             foreach ($bugs as $bug)
  1896.             {
  1897.                 $productversion = get_post_meta($bug['ID'], "bug-library-product-version", true);
  1898.                 $reportername = get_post_meta($bug['ID'], "bug-library-reporter-name", true);
  1899.                 $reporteremail = get_post_meta($bug['ID'], "bug-library-reporter-email", true);
  1900.                 $resolutiondate = get_post_meta($bug['ID'], "bug-library-resolution-date", true);
  1901.                 $resolutionversion = get_post_meta($bug['ID'], "bug-library-resolution-version", true);
  1902.                 $assigneduserid = get_post_meta($bug['ID'], "bug-library-assignee", true);
  1903.                
  1904.                 $dateformat = get_option("date_format");
  1905.                
  1906.                 $output .= "<table>\n";
  1907.            
  1908.                 $output .= "<tr class='" . ($counter % 2 == 1 ? 'odd' : 'even'). "'><td class='bug-library-type'><div class='bug-library-type-" . $bug['typeslug'];
  1909.                 $output .= "'>" . $bug['typename'] . "</div></td><td class='bug-library-title'><a href='" . get_permalink($bug['ID']) . "'>" . stripslashes($bug['post_title']). "</a></td>";
  1910.                
  1911.                 $output .= "</tr>";
  1912.                 $output .= "<tr class='" . ($counter % 2 == 1 ? 'odd' : 'even'). "'><td class='bug-library-data' colspan='2'>ID: <a href='" . get_permalink( $bug['ID'] ) . "'>";
  1913.                 $output .= $bug['ID']. "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Product: " . $bug['productname'];
  1914.                 $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Version: " . ($productversion != '' ? $productversion : 'N/A');
  1915.                 $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Report Date: " . date($dateformat, $bug['bug_date_unix']) . "</td></tr>";
  1916.                
  1917.                 $output .= "<tr class='" . ($counter % 2 == 1 ? 'odd' : 'even'). "'><td class='bug-library-data2' colspan='2'>Status: " . $bug['statusname'];
  1918.                
  1919.                 if ($showpriority)
  1920.                     $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Priority: " . $bug['priorityname'];
  1921.                    
  1922.                 if ($showreporter)
  1923.                     $output .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reporter: " . $reportername;
  1924.                    
  1925.                 $output .= "</td></tr>";
  1926.                
  1927.                 if ($showassignee && $assigneduserid != -1 && $assigneduserid != '')
  1928.                 {
  1929.                     $output .= "<tr class='" . ($counter % 2 == 1 ? 'odd' : 'even'). "'><td class='bug-library-data' colspan='2'>\n";
  1930.                     $firstname = get_user_meta($bug['ID'], 'first_name', true);
  1931.                     $lastname = get_user_meta($bug['ID'], 'last_name', true);
  1932.                     $assigneedata = get_userdata($assigneduserid);
  1933.  
  1934.                     $output .= "Assigned to: ";
  1935.  
  1936.                     if ($firstname != '' || $lastname != '')
  1937.                         $output .= $firstname . " " . $lastname;
  1938.                     else
  1939.                         $output .= $assigneedata->user_login;
  1940.  
  1941.                     $output .= "</td></tr>\n";
  1942.                 }
  1943.  
  1944.                 $counter++;
  1945.  
  1946.                 $output .= "</table>\n";               
  1947.             }
  1948.  
  1949.             $previouspagenumber = $pagenumber - 1;
  1950.             $nextpagenumber = $pagenumber + 1;
  1951.             $dotbelow = false;
  1952.             $dotabove = false;
  1953.  
  1954.             $currentpageuri = $this->remove_querystring_var($_SERVER['REQUEST_URI'], "bugpage");
  1955.             $currentpageuri = $this->remove_querystring_var($currentpageuri, "page_id");
  1956.  
  1957.             if (strpos($currentpageuri, '?') === false)
  1958.             {
  1959.                 if (strpos($currentpageuri, '&') === false)
  1960.                     $queryoperator = '?';
  1961.                 elseif (strpos($currentpageuri, '&') !== false)
  1962.                 {
  1963.                     $ampersandpos = strpos($currentpageuri, '&');
  1964.                     $currentpageuri = preg_replace('/&/', '?', $currentpageuri, 1);
  1965.                     $currentpageuri = '&';
  1966.                 }
  1967.             }
  1968.             else
  1969.                 $queryoperator = '&';
  1970.  
  1971.             if ($numberofpages > 1 && $view == 'list')
  1972.             {
  1973.                 $output .= "<div class='bug-library-pageselector'>";   
  1974.  
  1975.                 if ($pagenumber != 1)
  1976.                 {
  1977.                     $output .= "<span class='bug-library-previousnextactive'>";
  1978.  
  1979.                     $output .= "<a href='" . $currentpageuri . $queryoperator . "page_id=" . get_the_ID() . "&bugpage=" . $previouspagenumber . "'>" . __('Previous', 'bug-library') . "</a>";
  1980.  
  1981.                     $output .= "</span>";
  1982.                 }
  1983.                 else
  1984.                     $output .= "<span class='bug-library-previousnextinactive'>" . __('Previous', 'bug-library') . "</span>";
  1985.  
  1986.                 for ($counter = 1; $counter <= $numberofpages; $counter++)
  1987.                 {
  1988.                     if ($counter <= 2 || $counter >= $numberofpages - 1 || ($counter <= $pagenumber + 2 && $counter >= $pagenumber - 2))
  1989.                     {
  1990.                         if ($counter != $pagenumber)
  1991.                             $output .= "<span class='bug-library-unselectedpage'>";
  1992.                         else
  1993.                             $output .= "<span class='bug-library-selectedpage'>";
  1994.  
  1995.                         $output .= "<a href='" . $currentpageuri . $queryoperator . "page_id=" . get_the_ID() . "&bugpage=" . $counter . "'>" . $counter . "</a>";
  1996.  
  1997.                         $output .= "</a></span>";
  1998.                     }
  1999.  
  2000.                     if ($counter >= 2 && $counter < $pagenumber - 2 && $dotbelow == false)
  2001.                     {
  2002.                         $output .= "...";
  2003.                         $dotbelow = true;
  2004.                     }
  2005.  
  2006.                     if ($counter > $pagenumber + 2 && $counter < $numberofpages - 1 && $dotabove == false)
  2007.                     {
  2008.                         $output .= "...";
  2009.                         $dotabove = true;
  2010.                     }
  2011.                 }
  2012.  
  2013.                 if ($pagenumber != $numberofpages)
  2014.                 {
  2015.                     $output .= "<span class='bug-library-previousnextactive'>";
  2016.  
  2017.                     $output .= "<a href='" . $currentpageuri . $queryoperator . "page_id=" . get_the_ID() . "&bugpage=" . $nextpagenumber . "'>" . __('Next', 'bug-library') . "</a>";
  2018.  
  2019.                     $output .= "</span>";
  2020.                 }
  2021.                 else
  2022.                     $output .= "<span class='bug-library-previousnextinactive'>" . __('Next', 'bug-library') . "</span>";
  2023.  
  2024.                 $output .= "</div>";
  2025.             }
  2026.            
  2027.             $output .= "</div>";
  2028.         }
  2029.         else
  2030.         {
  2031.             $output .= "<div id='bug-library-item-table'>";
  2032.             $output .= "There are 0 bugs to view based on the currently selected filters.";
  2033.             $output .= "</div>";
  2034.         }
  2035.        
  2036.         $output .= "</div>";
  2037.        
  2038.         $output .= "<SCRIPT LANGUAGE='JavaScript'>";
  2039.         $output .= "/* <![CDATA[ */";
  2040.         $output .= "jQuery(document).ready(function() {";
  2041.         $output .= "\tjQuery('#bug-library-filterchange').click(function() { jQuery('#bug-library-filters').slideToggle('slow'); });";
  2042.        
  2043.         if ($bugcatid != -1)
  2044.             $querystring = "?bugcatid=" . $bugcatid;
  2045.        
  2046.         $output .= "\tjQuery('#submitnewissue').colorbox({href:'" . $blpluginpath . "submitnewissue.php" . $querystring . "', opacity: 0.3, iframe:true, width:'570px', height:'660px'});";
  2047.         $output .= "});";
  2048.         $output .= "/* ]]> */";
  2049.         $output .= "</SCRIPT>";
  2050.        
  2051.         return $output;
  2052.     }
  2053.    
  2054.    
  2055.     /********************************************** Function to Process [bug-library] shortcode *********************************************/
  2056.  
  2057.     function bug_library_func($atts) {
  2058.         extract(shortcode_atts(array(
  2059.             'bugcategorylist' => '',
  2060.                         'bugtypeid' => '',
  2061.                         'bugstatusid' => '',
  2062.                         'bugpriorityid' => ''
  2063.         ), $atts));
  2064.        
  2065.         $genoptions = get_option('BugLibraryGeneral');
  2066.                
  2067.         return $this->BugLibrary($genoptions['entriesperpage'], $genoptions['moderatesubmissions'], $bugcategorylist, $genoptions['requirelogin'],
  2068.                                 $genoptions['permalinkpageid'], $genoptions['showpriority'], $genoptions['showreporter'], $genoptions['showassignee'], $bugtypeid, $bugstatusid, $bugpriorityid);
  2069.     }
  2070.    
  2071.    
  2072.     function conditionally_add_scripts_and_styles($posts){
  2073.         if (empty($posts)) return $posts;
  2074.        
  2075.         $load_jquery = false;
  2076.         $load_fancybox = false;
  2077.         $load_style = false;
  2078.        
  2079.         if (is_admin())
  2080.         {
  2081.             $load_jquery = false;
  2082.             $load_fancybox = false;
  2083.             $load_style = false;
  2084.         }
  2085.         else
  2086.         {
  2087.             foreach ($posts as $post) {    
  2088.                 $buglibrarypos = stripos($post->post_content, 'bug-library');
  2089.                 if ($buglibrarypos !== false)
  2090.                 {
  2091.                     $load_jquery = true;
  2092.                     $load_fancybox = true;
  2093.                     $load_style = true;                    
  2094.                 }
  2095.             }
  2096.         }
  2097.  
  2098.         global $blstylesheet;
  2099.        
  2100.         if ($load_style)
  2101.         {      
  2102.             global $blstylesheet;
  2103.             $blstylesheet = true;
  2104.         }
  2105.         else
  2106.         {
  2107.             global $blstylesheet;
  2108.             $blstylesheet = false;
  2109.         }
  2110.      
  2111.         if ($load_jquery)
  2112.         {
  2113.             wp_enqueue_script('jquery');
  2114.         }
  2115.            
  2116.         if ($load_fancybox)
  2117.         {
  2118.             wp_enqueue_script('colorbox', get_bloginfo('wpurl') . '/wp-content/plugins/bug-library/colorbox/jquery.colorbox-min.js', "", "1.3.9");
  2119.             wp_enqueue_style('colorboxstyle', get_bloginfo('wpurl') . '/wp-content/plugins/bug-library/colorbox/colorbox.css');
  2120.         }
  2121.      
  2122.         return $posts;
  2123.     }
  2124. }
  2125.  
  2126. $my_bug_library_plugin = new bug_library_plugin();
  2127.  
  2128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement