Guest User

Untitled

a guest
Mar 2nd, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 34.85 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Plugin Name: gw2pcl - Guild Wars 2 Player's Character List
  6.  
  7. Description: Users can manage their own Guild Wars 2 characters. A list of all characters assigned to one player can be integrated in any post or page. If no user is given as an attribute to the short code all existing characters are printed out.
  8.  
  9. Usage: [gw2pcl who="<<user_login>>"]
  10.  
  11. Version: 2.0.2
  12.  
  13. Author: max.mueller
  14.  
  15. Based on gw2pcl written by Arne.
  16.  
  17. License: GPL3
  18.  
  19. */
  20.  
  21. global $gw2pcl_database_version;
  22.  
  23.  
  24.  
  25. $gw2pcl_database_version = 1;
  26.  
  27.  
  28.  
  29. add_action ( 'admin_menu', 'gw2pcl_menu' );
  30.  
  31. register_activation_hook(__FILE__,'gw2pcl_create_database');
  32.  
  33. if (get_site_option('gw2pcl_database_version') != gw2pcl_database_version) gw2pcl_create_database();
  34.  
  35. add_shortcode( 'gw2pcl', 'gw2pcl_shortcode' );
  36.  
  37. add_action('wp_head', 'gw2pcl_css');
  38.  
  39. register_uninstall_hook( __FILE__, 'gw2pcl_uninstall' );
  40.  
  41.  
  42.  
  43. // If your wordpress installation is configured to german all texts will be translated. Otherwise it'll stay English.
  44.  
  45. load_plugin_textdomain( 'gw2pcl', false, basename(dirname(__FILE__)) . '/languages/' );
  46.  
  47.  
  48.  
  49.  
  50.  
  51. function gw2pcl_css() {
  52.  
  53.     echo '<link rel="stylesheet" href="' . plugin_dir_url( __FILE__ ) . 'gw2pcl.css" />' . "\n";
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. function gw2pcl_menu() {
  62.  
  63.     add_menu_page( __( 'Manage my Characters', 'gw2pcl' ), __( 'My Chars', 'gw2pcl' ), 'upload_files', 'gw2pclmainmenu', 'gw2pcl_page', plugin_dir_url( __FILE__ ).'pics/gw2.png', '99.000020120924171044' );
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. /**
  74.  
  75.  *  Displaying Guild Member's Character List on the Frontend
  76.  
  77.  */
  78.  
  79.  
  80.  
  81. function gw2pcl_shortcode( $attributes ) {
  82.  
  83.     // Allow following atributes, which are optional and have default values (=> 'default value').
  84.  
  85.     extract( shortcode_atts( array(
  86.  
  87.         'who' => 'nobody',
  88.  
  89.     ), $attributes ) );
  90.  
  91.  
  92.  
  93.     global $wpdb;
  94.  
  95.     $gw2pcl_table_name = $wpdb->prefix . 'gw2pcl';
  96.  
  97.     $output = "";
  98.  
  99.    
  100.  
  101.     // IF no user is given as an attribute print all the characters.
  102.  
  103.     if ( $who == "nobody" ) {
  104.  
  105.         $chars = $wpdb->get_results( "
  106.  
  107.             SELECT id, user_id, name, isCommander, picture_file, race, profession, orderCol, crafting1, crafting2, fractals, dungeons, teaser
  108.  
  109.             FROM $gw2pcl_table_name
  110.  
  111.             ORDER BY user_id ASC, name ASC
  112.  
  113.         " );
  114.  
  115.     } else {
  116.  
  117.         // Predetermine which user_id is assigned to the transmitted user (shortcode attribute "who").
  118.  
  119.         $current_user_id = $wpdb->get_var( "SELECT id FROM $wpdb->users WHERE user_login = '$who'" );
  120.  
  121.        
  122.  
  123.         // Get this specific user's characters.
  124.  
  125.         $chars = $wpdb->get_results( "
  126.  
  127.             SELECT id, user_id, name, isCommander, picture_file, race, profession, orderCol, crafting1, crafting2, fractals, dungeons, teaser
  128.  
  129.             FROM $gw2pcl_table_name
  130.  
  131.             WHERE user_id = $current_user_id
  132.  
  133.             ORDER BY user_id ASC, name ASC
  134.  
  135.         " );
  136.  
  137.     }
  138.  
  139.  
  140.  
  141.     $alternate = 1;
  142.  
  143.     $last_uid = 0;
  144.  
  145.    
  146.  
  147.     foreach ( $chars as $char ) {
  148.  
  149.         if ( $char->user_id != $last_uid) {
  150.  
  151.             $user = get_user_by('id', $char->user_id);
  152.  
  153.             $output .= '<div class="gw2user">' . esc_html( $user->display_name ) . '</div>' . "\n";
  154.  
  155.             $last_uid = $char->user_id;
  156.  
  157.         }
  158.  
  159.         $output .= '<div class="gw2row ' . ( $alternate ? 'gw2odd' : 'gw2even' ) . '">' . "\n";
  160.  
  161.         $output .= '<div class="gw2desc">';
  162.  
  163.        
  164.  
  165.         $output .= '<div class="gw2pic">';
  166.  
  167.         if ( file_exists( $char->picture_file ) ) {
  168.  
  169.    
  170.  
  171.             $upload_path = wp_upload_dir();
  172.  
  173.             $image_sized = image_resize( $char->picture_file, 160, 300, true, null, null, 100 );       
  174.  
  175.             $image_sized = is_wp_error($image_sized) ? $char->picture_file : $image_sized;
  176.  
  177.             $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );  
  178.  
  179.  
  180.  
  181.             $output .= '<img src="' . $image_sized . '" alt="' . esc_html( $char->name ) . '" />';
  182.  
  183.         } else {
  184.  
  185.             $output .= '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $char->name ) . '" />';
  186.  
  187.         }
  188.  
  189.        
  190.  
  191.         $output .= '</div>' . "\n";
  192.  
  193.  
  194.  
  195.         // name and commander badge
  196.  
  197.         $output .= '<strong><span style="font-size:2em;">' . esc_html($char->name);
  198.  
  199.         $output .= ' ' . isCommanderFunction($char->name) . '</span></strong><br />';
  200.  
  201.        
  202.  
  203.         // race
  204.  
  205.         $output .= get_race_pic( $char->race ) . ' ' . get_race( $char->race ) . '<br />';
  206.  
  207.  
  208.  
  209.         //profession
  210.  
  211.         $output .= get_profession_pic( $char->race ) . ' ' . get_profession( $char->race ) . '<br />';
  212.  
  213.  
  214.  
  215.         // order
  216.  
  217.         if ( $char->orderCol != 0 ) {
  218.  
  219.             $output .= get_orderCol_pic( $char->orderCol ) . ' ' . get_orderCol( $char->orderCol ) . '<br />';
  220.  
  221.         }
  222.  
  223.  
  224.  
  225.         // crafting
  226.  
  227.         if ( $char->crafting1 != 0 ) {
  228.  
  229.             $output .= get_crafting_skill_pic( $char->crafting1 ) . ' ' . get_crafting_skill( $char->crafting1 );
  230.  
  231.         }
  232.  
  233.         if ( ( $char->crafting1 != 0 ) and ( $char->crafting2 != 0 ) ) $output .= ' ' . __( 'and', 'gw2pcl' ) . ' ';
  234.  
  235.         if ( $char->crafting2 != 0 ) {
  236.  
  237.             $output .= get_crafting_skill_pic( $char->crafting2 ) . ' ' . get_crafting_skill( $char->crafting2 );
  238.  
  239.         }
  240.  
  241.         $output .= '<br />';
  242.  
  243.          
  244.  
  245.         // fractals      
  246.  
  247.         if ( $char->fractals != 0 ) {
  248.  
  249.                     $output .= '<img src="' . plugin_dir_url( __FILE__ ) . 'pics/fractals.jpg" />';
  250.  
  251.                     $output .= ' ' . __( 'Fractals Level', 'gw2pcl' ) . ': ' . $char->fractals;
  252.  
  253.                 }
  254.  
  255.  
  256.  
  257.         // story mode
  258.  
  259.         // TODO !!! Code reuse as a function as above. !!!
  260.  
  261.         if ( !strstr($char->dungeons, "a:0") ) {
  262.  
  263.                     $output .= '<br />';
  264.  
  265.                     $output .= __( 'Story Mode Completed', 'gw2pcl' ) . ':<br />';
  266.  
  267.                     $dungeons = unserialize( $char->dungeons );
  268.  
  269.                     if ($dungeons['ac'] == 1) $output .= '<img title="' . __( 'Ascalonian Catacombs', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/ac.png" class="gw2pcl_dungeonpic" /> ';
  270.  
  271.                     if ($dungeons['cm'] == 1) $output .= '<img title="' . __( 'Caudecus\'s Manor', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/cm.png" class="gw2pcl_dungeonpic" /> ';
  272.  
  273.                     if ($dungeons['ta'] == 1) $output .= '<img title="' . __( 'Twilight Arbor', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/ta.png" class="gw2pcl_dungeonpic" /> ';
  274.  
  275.                     if ($dungeons['se'] == 1) $output .= '<img title="' . __( 'Sorrow\'s Embrace', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/se.png" class="gw2pcl_dungeonpic" /> ';
  276.  
  277.                     if ($dungeons['cof'] == 1) $output .= '<img title="' . __( 'Citadel of Flame', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/cof.png" class="gw2pcl_dungeonpic" /> ';
  278.  
  279.                     if ($dungeons['hotw'] == 1) $output .= '<img title="' . __( 'Honor of the Waves', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/hotw.png" class="gw2pcl_dungeonpic" /> ';
  280.  
  281.                     if ($dungeons['coe'] == 1) $output .= '<img title="' . __( 'Crucible of Eternity', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/coe.png" class="gw2pcl_dungeonpic" /> ';
  282.  
  283.                     if ($dungeons['arah'] == 1) $output .= '<img title="' . __( 'Arah', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/arah.png" class="gw2pcl_dungeonpic" /> ';
  284.  
  285.                 }
  286.  
  287.  
  288.  
  289.         // teaser
  290.  
  291.         if ( strlen( $char->teaser ) > 2 ) {
  292.  
  293.             $output .= '<br />'."\n".'<em>ยป' . esc_html( $char->teaser ) . 'ยซ</em>';
  294.  
  295.         }
  296.  
  297.  
  298.  
  299.         $output .= '</div>' . "\n";
  300.  
  301.                 $output .= '<div style="clear:both;"></div>';
  302.  
  303.         $output .= '</div>' . "\n";
  304.  
  305.         $alternate = 1 - $alternate;
  306.  
  307.     }
  308.  
  309.    
  310.  
  311.     return $output;
  312.  
  313. }
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321. /**
  322.  
  323.  *  DISPLAYS PAGE IN BACKEND AND DOES THE DB-EDITING
  324.  
  325.  */
  326.  
  327.  
  328.  
  329.  
  330.  
  331. function gw2pcl_page() {
  332.  
  333.     global $wpdb;
  334.  
  335.     $table_name = $wpdb->prefix . 'gw2pcl';
  336.  
  337.     $cur_user = get_userdata( get_current_user_id() );
  338.  
  339.     $user_level = $cur_user->user_level;
  340.  
  341.  
  342.  
  343.     // Ensuring I'm either at least an editor or the owner of this char
  344.  
  345.     $where_two = "";
  346.  
  347.     if ( $user_level < 7 ) {
  348.  
  349.         $where_two = ' AND user_id = '.get_current_user_id();
  350.  
  351.     }
  352.  
  353.    
  354.  
  355.  
  356.  
  357.     /**
  358.  
  359.      *  ADD NEW CHAR TO DATABASE
  360.  
  361.      */
  362.  
  363.  
  364.  
  365.     if ( isset( $_POST['gw2pcl_add'] ) ) {
  366.  
  367.  
  368.  
  369.         if ( ! isset( $_POST['_gw2pcl_nonce'] ) || ! wp_verify_nonce( $_POST['_gw2pcl_nonce'], 'gw2pcl_nonce' ) )   return;
  370.  
  371.        
  372.  
  373.         $name       = stripslashes( $_POST['name'] );
  374.  
  375.         $isCommander= intval      ( $_POST['isCommander'] );
  376.  
  377.         $teaser     = stripslashes( $_POST['teaser'] );
  378.  
  379.         $race       = intval      ( $_POST['race'] );
  380.  
  381.         $profession = intval      ( $_POST['profession'] );
  382.  
  383.         $orderCol   = intval      ( $_POST['orderCol'] );
  384.  
  385.         $crafting1  = intval      ( $_POST['crafting1'] );
  386.  
  387.         $crafting2  = intval      ( $_POST['crafting2'] );
  388.  
  389.         $fractals   = intval      ( $_POST['fractals'] );
  390.  
  391.                 if (($fractals > 999) or ($fractals < 2)) $fractals = 0;
  392.  
  393.                
  394.  
  395.                 $dungeons = array();
  396.  
  397.                 if ( intval( $_POST['ac'] ) == 1)   $dungeons['ac'] = 1;
  398.  
  399.                 if ( intval( $_POST['cm'] ) == 1)   $dungeons['cm'] = 1;
  400.  
  401.                 if ( intval( $_POST['ta'] ) == 1)   $dungeons['ta'] = 1;
  402.  
  403.                 if ( intval( $_POST['se'] ) == 1)   $dungeons['se'] = 1;
  404.  
  405.                 if ( intval( $_POST['cof'] ) == 1)  $dungeons['cof'] = 1;
  406.  
  407.                 if ( intval( $_POST['hotw'] ) == 1) $dungeons['hotw'] = 1;
  408.  
  409.                 if ( intval( $_POST['coe'] ) == 1)  $dungeons['coe'] = 1;
  410.  
  411.                 if ( intval( $_POST['arah'] ) == 1) $dungeons['arah'] = 1;
  412.  
  413.        
  414.  
  415.         if ($name == "") {
  416.  
  417.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Name can\'t be left blank.', 'gw2pcl' ) . '</strong></p></div>';
  418.  
  419.         } else {
  420.  
  421.            
  422.  
  423.             // Only JPG and PNG. Not even annoying GIFs.
  424.  
  425.             if ( ! empty( $_FILES['picture']['name'] ) ) {
  426.  
  427.                 $mimes = array(
  428.  
  429.                     'jpg|jpeg' => 'image/jpeg',
  430.  
  431.                     'png' => 'image/png'
  432.  
  433.                 );
  434.  
  435.                 $charpic = wp_handle_upload( $_FILES['picture'], array( 'mimes' => $mimes, 'test_form' => false ) );
  436.  
  437.                 if ( ! empty ( $charpic['file'] ) ) {
  438.  
  439.                     $picture_file = $charpic['file'];
  440.  
  441.                 }
  442.  
  443.             }
  444.  
  445.        
  446.  
  447.             $wpdb->query(
  448.  
  449.                 $wpdb->prepare("
  450.  
  451.                     INSERT INTO $table_name
  452.  
  453.                     ( name, isCommander, race, profession, orderCol, crafting1, crafting2, picture_file, teaser, fractals, dungeons, user_id )
  454.  
  455.                     VALUES ( %s, %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )
  456.  
  457.                 ", $name, $isCommander, $race, $profession, $orderCol, $crafting1, $crafting2, $picture_file, $teaser, $fractals, serialize($dungeons), get_current_user_id() )
  458.  
  459.             );
  460.  
  461.        
  462.  
  463.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Character added.', 'gw2pcl' ) . '</strong></p></div>';
  464.  
  465.         }
  466.  
  467.     }
  468.  
  469.    
  470.  
  471.    
  472.  
  473.     /**
  474.  
  475.      *  MODIFY ENTRY
  476.  
  477.      */
  478.  
  479.        
  480.  
  481.     if ( isset( $_POST['gw2pcl_change'] ) ) {
  482.  
  483.  
  484.  
  485.         if ( ! isset( $_POST['_gw2pcl_nonce'] ) || ! wp_verify_nonce( $_POST['_gw2pcl_nonce'], 'gw2pcl_nonce' ) )   return;
  486.  
  487.        
  488.  
  489.         $name       = stripslashes( $_POST['name'] );
  490.  
  491.         $isCommander= intval      ( $_POST['isCommander'] );
  492.  
  493.         $teaser     = stripslashes( $_POST['teaser'] );
  494.  
  495.         $id         = intval      ( $_POST['gw2pcl_id'] );
  496.  
  497.         $race       = intval      ( $_POST['race'] );
  498.  
  499.         $profession = intval      ( $_POST['profession'] );
  500.  
  501.         $orderCol   = intval      ( $_POST['orderCol'] );
  502.  
  503.         $crafting1  = intval      ( $_POST['crafting1'] );
  504.  
  505.         $crafting2  = intval      ( $_POST['crafting2'] );
  506.  
  507.         $fractals   = intval      ( $_POST['fractals'] );
  508.  
  509.                 if (($fractals > 999) or ($fractals < 2)) $fractals = 0;
  510.  
  511.         $delete     = intval      ( $_POST['deleteoldpic'] or 0 );
  512.  
  513.  
  514.  
  515.                 $dungeons = array();
  516.  
  517.                 if ( intval( $_POST['ac'] ) == 1)   $dungeons['ac'] = 1;
  518.  
  519.                 if ( intval( $_POST['cm'] ) == 1)   $dungeons['cm'] = 1;
  520.  
  521.                 if ( intval( $_POST['ta'] ) == 1)   $dungeons['ta'] = 1;
  522.  
  523.                 if ( intval( $_POST['se'] ) == 1)   $dungeons['se'] = 1;
  524.  
  525.                 if ( intval( $_POST['cof'] ) == 1)  $dungeons['cof'] = 1;
  526.  
  527.                 if ( intval( $_POST['hotw'] ) == 1) $dungeons['hotw'] = 1;
  528.  
  529.                 if ( intval( $_POST['coe'] ) == 1)  $dungeons['coe'] = 1;
  530.  
  531.                 if ( intval( $_POST['arah'] ) == 1) $dungeons['arah'] = 1;
  532.  
  533.  
  534.  
  535.                 // Am I allowed to do that?
  536.  
  537.  
  538.  
  539.         if ( $id > 0 ) {
  540.  
  541.             $entry = $wpdb->get_row('SELECT * FROM ' . $table_name . ' WHERE id = '.$id . $where_two );
  542.  
  543.             if ($entry != null) {
  544.  
  545.                 $picture_file = $entry->picture_file;
  546.  
  547.             } else {
  548.  
  549.                 wp_die( 'No' );
  550.  
  551.             }
  552.  
  553.         } else {
  554.  
  555.             wp_die( 'No' );
  556.  
  557.         }
  558.  
  559.        
  560.  
  561.         // Then do it
  562.  
  563.         // unnice code reuse
  564.  
  565.  
  566.  
  567.         if ($name == "") {
  568.  
  569.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Name can\'t be left blank.', 'gw2pcl' ) . '</strong></p></div>';
  570.  
  571.         } else {
  572.  
  573.        
  574.  
  575.             // Delete old images if a new one was uploaded
  576.  
  577.             // or the user wanted the old one to be deleted
  578.  
  579.            
  580.  
  581.             if ( ( ! empty( $_FILES['picture']['name'] ) ) or ( $delete ) ) {
  582.  
  583.                     @unlink( $entry->picture_file );
  584.  
  585.                     $otherpath = pathinfo( $entry->picture_file );
  586.  
  587.                     @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
  588.  
  589.                     $picture_file = "";
  590.  
  591.             }
  592.  
  593.        
  594.  
  595.             if ( ! empty( $_FILES['picture']['name'] ) ) {
  596.  
  597.                 $mimes = array(
  598.  
  599.                     'jpg|jpeg' => 'image/jpeg',
  600.  
  601.                     'png' => 'image/png'
  602.  
  603.                 );
  604.  
  605.                 $charpic = wp_handle_upload( $_FILES['picture'], array( 'mimes' => $mimes, 'test_form' => false ) );
  606.  
  607.                 if ( ! empty ( $charpic['file'] ) ) {
  608.  
  609.                     $picture_file = $charpic['file'];
  610.  
  611.                 }
  612.  
  613.             }
  614.  
  615.        
  616.  
  617.             $wpdb->query(
  618.  
  619.                 $wpdb->prepare("
  620.  
  621.                     UPDATE $table_name SET
  622.  
  623.                     name = %s,
  624.  
  625.                     isCommander = %d,
  626.  
  627.                     race = %d,
  628.  
  629.                     profession = %d,
  630.  
  631.                     orderCol = %d,
  632.  
  633.                     crafting1 = %d,
  634.  
  635.                     crafting2 = %d,
  636.  
  637.                     picture_file = %s,
  638.  
  639.                     teaser = %s,
  640.  
  641.                                 fractals = %d,
  642.  
  643.                                 dungeons = %s
  644.  
  645.                     WHERE id = %d
  646.  
  647.                 ", $name, $isCommander, $race, $profession, $orderCol, $crafting1, $crafting2, $picture_file, $teaser, $fractals, serialize($dungeons), $id)
  648.  
  649.             );
  650.  
  651.        
  652.  
  653.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Character edited.', 'gw2pcl' ) . '</strong></p></div>';
  654.  
  655.         }
  656.  
  657.     }
  658.  
  659.    
  660.  
  661.     // Default Values
  662.  
  663.     $name       = "";
  664.  
  665.     $isCommander= 0;
  666.  
  667.     $teaser     = "";
  668.  
  669.     $race       = 3;
  670.  
  671.     $profession = 6;
  672.  
  673.     $orderCol   = 0;
  674.  
  675.     $crafting1  = 0;
  676.  
  677.     $crafting2  = 0;
  678.  
  679.         $fractals   = 0;
  680.  
  681.         $dungeons   = array();
  682.  
  683.    
  684.  
  685.     /**
  686.  
  687.      *  Delete selected
  688.  
  689.      */
  690.  
  691.      
  692.  
  693.     if ( isset( $_POST['gw2pcl_delete'] ) ) {
  694.  
  695.         $delete = $_POST["post"];
  696.  
  697.        
  698.  
  699.         if ( sizeof( $delete ) < 1 ) {
  700.  
  701.        
  702.  
  703.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Nothing to delete.', 'gw2pcl' ) . '</strong></p></div>';
  704.  
  705.        
  706.  
  707.         } else {
  708.  
  709.        
  710.  
  711.             $delete_string = "";
  712.  
  713.             foreach ($delete as $todelete) {
  714.  
  715.                 $delete_string = $delete_string . intval($todelete) . ', ';
  716.  
  717.             }
  718.  
  719.             $delete_string = substr($delete_string, 0, strlen($delete_string) - 2);
  720.  
  721.            
  722.  
  723.             // Deleting Images and resized Images
  724.  
  725.             $file_list = $wpdb->get_results( 'SELECT user_id, picture_file FROM ' . $table_name . ' WHERE id IN ( ' . $delete_string  . ' )' . $where_two );
  726.  
  727.                    
  728.  
  729.             foreach ( $file_list as $image_file ) {
  730.  
  731.                 if ( $image_file->picture_file ) {
  732.  
  733.                     @unlink( $image_file->picture_file );
  734.  
  735.                     $otherpath = pathinfo( $image_file->picture_file );
  736.  
  737.                     @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
  738.  
  739.                 }
  740.  
  741.             }
  742.  
  743.            
  744.  
  745.             $wpdb->query( 'DELETE FROM ' . $table_name . ' WHERE id IN ( ' . $delete_string  . ' )' . $where_two );
  746.  
  747.            
  748.  
  749.             echo '<div id="message" class="updated fade"><p><strong>' . __( 'Deleted selected Characters.', 'gw2pcl' ) . '</strong></p></div>';
  750.  
  751.            
  752.  
  753.         }
  754.  
  755.     }
  756.  
  757.    
  758.  
  759.    
  760.  
  761.     /**
  762.  
  763.      *  DISPLAY LIST OF CHARS IN THE BACKEND
  764.  
  765.      */
  766.  
  767.    
  768.  
  769.     ?>
  770.  
  771.     <h1><?php __( 'Manage my Characters', 'gw2pcl' ); ?></h1>
  772.  
  773.     <p><?php _e( 'On this page you can enter all your characters for the list of all guild members.', 'gw2pcl' ); ?></p>
  774.  
  775. <?php
  776.  
  777.     if ( $user_level >= 7 ) {
  778.  
  779.         echo '<p>' . sprintf( __( 'To insert the list of all characters on a page or an article enter the shortcode %s.', 'gw2pcl' ), '<code>[gw2pcl]</code>' ) . '</p>' . "\n";
  780.  
  781.         echo '<p>' . sprintf( __( 'To insert the list of all characters assigned to a certain user on a page or an article enter the shortcode %s.', 'gw2pcl' ), '<code>[gw2pcl who=\'user_login\']</code>' ) . '</p>' . "\n";
  782.  
  783.         if ( isset( $_POST['gw2pcl_view_all'] ) ) $_SESSION["gw2pcl-viewall"] = true;
  784.  
  785.         if ( isset( $_POST['gw2pcl_view_mine'] ) ) $_SESSION["gw2pcl-viewall"] = false;
  786.  
  787.         if ( $_SESSION["gw2pcl-viewall"] == false) {
  788.  
  789.             echo '<form method="post" action=""><p><input type="submit" name="gw2pcl_view_all" id="gw2pcl_view_all" value="' . __( 'view all', 'gw2pcl' ) . '" /></p></form>'."\n";
  790.  
  791.         } else {
  792.  
  793.             echo '<form method="post" action=""><p><input type="submit" name="gw2pcl_view_mine" id="gw2pcl_view_mine" value="' . __( 'view just mine', 'gw2pcl' ) . '" /></p></form>'."\n";
  794.  
  795.         }
  796.  
  797.     }
  798.  
  799. ?>
  800.  
  801.     <form method="post" action="">
  802.  
  803.     <table class="wp-list-table widefat" cellspacing="0">
  804.  
  805.         <thead>
  806.  
  807.             <tr>
  808.  
  809.                 <th scope='col' id='cb' class='manage-column column-cb check-column'  style=""><input type="checkbox" /></th>
  810.  
  811.                 <th><?php _e( 'Picture', 'gw2pcl' ); ?></th>
  812.  
  813.                 <th><?php _e( 'Details', 'gw2pcl' ); ?></th>
  814.  
  815.             </tr>
  816.  
  817.         </thead>
  818.  
  819.         <tbody id="the-list">
  820.  
  821.     <?php
  822.  
  823.    
  824.  
  825.     $chars = $wpdb->get_results( "
  826.  
  827.         SELECT *
  828.  
  829.         FROM $table_name
  830.  
  831.         " . ((($user_level >= 7) and ($_SESSION["gw2pcl-viewall"])) ? "" : "WHERE user_id = " . get_current_user_id() ) . "
  832.  
  833.         ORDER BY name
  834.  
  835.     " );
  836.  
  837.    
  838.  
  839.     $alternate = 1;
  840.  
  841.    
  842.  
  843.     foreach ( $chars as $char ) {
  844.  
  845.         echo '<tr' . ( $alternate ? ' class="alternate"' : '' ) . '>' . "\n";
  846.  
  847.         echo '<th scope="row" class="check-column"><input type="checkbox" name="post[]" value="' . $char->id . '" /></th>' . "\n";
  848.  
  849.         echo '<td>';
  850.  
  851.        
  852.  
  853.         if ( file_exists( $char->picture_file ) ) {
  854.  
  855.    
  856.  
  857.             $upload_path = wp_upload_dir();
  858.  
  859.             $image_sized = image_resize( $char->picture_file, 150, 200, true, null, null, 100 );       
  860.  
  861.             $image_sized = is_wp_error($image_sized) ? $char->picture_file : $image_sized;
  862.  
  863.             $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );  
  864.  
  865.  
  866.  
  867.             echo '<img src="' . $image_sized . '" alt="' . esc_html( $char->name ) . '" />';
  868.  
  869.         } else {
  870.  
  871.             echo '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $char->name ) . '" />';
  872.  
  873.         }
  874.  
  875.        
  876.  
  877.         echo '</td>' . "\n";
  878.  
  879.         echo '<td>';
  880.  
  881.         echo '<strong><span style="font-size:2em;">' . esc_html($char->name);
  882.  
  883.         echo ' ' . isCommanderFunction($char->name) . '</span></strong><br />';
  884.  
  885.  
  886.  
  887.         $user = (get_user_meta( $char->user_id, 'nickname', true ));
  888.  
  889.         if ( $user == "" ) {
  890.  
  891.             $user = '<strong><span style="color:#f00;">' . __( 'User doesn\'t exist!', 'gw2pcl' ) . '</span></strong>';
  892.  
  893.         } else {
  894.  
  895.             $user = '<em>' . $user . '</em>';
  896.  
  897.         }
  898.  
  899.         echo $user . '<br />';
  900.  
  901.        
  902.  
  903.         echo get_race( $char->race );
  904.  
  905.        
  906.  
  907.         echo '<br />';
  908.  
  909.        
  910.  
  911.         echo get_profession( $char->profession );
  912.  
  913.  
  914.  
  915.         echo '<br />';
  916.  
  917.        
  918.  
  919.         echo get_orderCol( $char->orderCol );
  920.  
  921.  
  922.  
  923.         echo '<br />';
  924.  
  925.        
  926.  
  927.         if ( $char->crafting1 != 0 ) echo get_crafting_skill( $char->crafting1 );
  928.  
  929.         if ( ( $char->crafting1 != 0 ) and ( $char->crafting2 != 0 ) ) echo ' ' . __( 'and', 'gw2pcl' ) . ' ';
  930.  
  931.         if ( $char->crafting2 != 0 ) echo get_crafting_skill( $char->crafting2 );
  932.  
  933.         if ( ( $char->crafting1 == 0 ) and ( $char->crafting2 == 0 ) ) _e( 'no crafting skills', 'gw2pcl' );
  934.  
  935.  
  936.  
  937.         echo '<br />';
  938.  
  939.                
  940.  
  941.                 if ( ( $char->fractals) == 0) {
  942.  
  943.                     _e( 'hasn\'t been doing fractals so far', 'gw2pcl' );
  944.  
  945.                 } else {
  946.  
  947.                     _e( 'Can enter fractals level', 'gw2pcl' );
  948.  
  949.                     echo ': ' . $char->fractals;
  950.  
  951.                 }
  952.  
  953.  
  954.  
  955.         if ( strlen( $char->teaser ) > 2 ) {
  956.  
  957.             echo '<br />'."\n".'<em>ยป' . esc_html( $char->teaser ) . 'ยซ</em>';
  958.  
  959.         }
  960.  
  961.        
  962.  
  963.         echo '<form method="POST" action="#edit"><p><input type="submit" name="gw2pcl_edit" id="gw2pcl_edit" value="' . __( 'edit', 'gw2pcl' ) . '" /><input type="hidden" name="gw2pcl_id" value="' . $char->id . '" /></p></form>' . "\n";
  964.  
  965.         echo '</td>' . "\n";
  966.  
  967.         echo '</tr>' . "\n";
  968.  
  969.         $alternate = 1 - $alternate;
  970.  
  971.     }
  972.  
  973.    
  974.  
  975.     ?>
  976.  
  977.         </tbody>
  978.  
  979.     </table>
  980.  
  981.     <p><input type="submit" name="gw2pcl_delete" id="gw2pcl_delete" value="<?php _e( 'Delete selected', 'gw2pcl' ); ?>" /></p>
  982.  
  983.     </form>
  984.  
  985. <?php
  986.  
  987.  
  988.  
  989.  
  990.  
  991.     /**
  992.  
  993.      *  FORM FOR ADDING AND MODIFYING NEW CHARS
  994.  
  995.      *  Man, that's ugly. I'm not used to do that on my own.
  996.  
  997.      */
  998.  
  999.      
  1000.  
  1001. ?>
  1002.  
  1003.     <h2><?php
  1004.  
  1005.         if ( isset( $_POST['gw2pcl_edit'] ) ) {
  1006.  
  1007.             _e( 'Edit Character', 'gw2pcl' );
  1008.  
  1009.             $id = intval( $_POST['gw2pcl_id'] );
  1010.  
  1011.             if ( $id > 0 ) {
  1012.  
  1013.                 $entry = $wpdb->get_row('SELECT * FROM ' . $table_name . ' WHERE id = '.$id . $where_two );
  1014.  
  1015.                 if ($entry != null) {
  1016.  
  1017.                     $name       = $entry->name;
  1018.  
  1019.                     $isCommander= $entry->isCommander;
  1020.  
  1021.                     $race       = $entry->race;
  1022.  
  1023.                     $teaser     = $entry->teaser;
  1024.  
  1025.                     $profession = $entry->profession;
  1026.  
  1027.                     $orderCol   = $entry->orderCol;
  1028.  
  1029.                     $crafting1  = $entry->crafting1;
  1030.  
  1031.                     $crafting2  = $entry->crafting2;
  1032.  
  1033.                                         $fractals   = $entry->fractals;
  1034.  
  1035.                                         $dungeons   = unserialize( $entry->dungeons );
  1036.  
  1037.                 }
  1038.  
  1039.             }
  1040.  
  1041.         } else {
  1042.  
  1043.             _e( 'Add New Character', 'gw2pcl' );
  1044.  
  1045.         }
  1046.  
  1047.     ?></h2>
  1048.  
  1049.  
  1050.  
  1051.     <form method="post" enctype="multipart/form-data" action="">
  1052.  
  1053. <?php wp_nonce_field( 'gw2pcl_nonce', '_gw2pcl_nonce', false ); ?>
  1054.  
  1055.     <table class="form-table">
  1056.  
  1057.     <tr valign="top">
  1058.  
  1059.     <th scope="row"><label for="name"><?php _e( 'Name', 'gw2pcl' ); ?>:</label></th>
  1060.  
  1061.     <td><input name="name" type="text" id="name" class="regular-text" value="<?php echo $name; ?>" /></td>
  1062.  
  1063.     <td rowspan="0" width="170" valign="top">
  1064.  
  1065.     <?php
  1066.  
  1067.         if ( isset( $_POST['gw2pcl_edit'] ) ) {
  1068.  
  1069.        
  1070.  
  1071.             // When editing a char display the image, too.
  1072.  
  1073.             if ( file_exists( $entry->picture_file ) ) {
  1074.  
  1075.        
  1076.  
  1077.                 $upload_path = wp_upload_dir();
  1078.  
  1079.                 $image_sized = image_resize( $entry->picture_file, 150, 200, true, null, null, 100 );      
  1080.  
  1081.                 $image_sized = is_wp_error($image_sized) ? $entry->picture_file : $image_sized;
  1082.  
  1083.                 $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );  
  1084.  
  1085.  
  1086.  
  1087.                 echo '<img src="' . $image_sized . '" alt="' . esc_html( $entry->name ) . '" />';
  1088.  
  1089.             } else {
  1090.  
  1091.                 echo '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $entry->name ) . '" />';
  1092.  
  1093.             }
  1094.  
  1095.  
  1096.  
  1097.         }
  1098.  
  1099.     ?>
  1100.  
  1101.     </td>
  1102.  
  1103.  
  1104.  
  1105.     <?php
  1106.  
  1107.     //Choose if character is a commander or not.
  1108.  
  1109.     ?>
  1110.  
  1111.     <tr valign="top">
  1112.  
  1113.     <th scope="row"><?php _e( 'Commander', 'gw2pcl' ); ?>:</th>
  1114.  
  1115.         <td>
  1116.  
  1117.         <input name="isCommander" type="checkbox" id="isCommander" class="checkbox" value="1" <?php if ($isCommander == 1) echo 'checked="checked" '; ?>/><label for="isCommander"> <?php _e( 'Char is a commander.', 'gw2pcl' ); ?></label><br />
  1118.  
  1119.         </td>
  1120.  
  1121.     </tr>
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.     <tr valign="top">
  1128.  
  1129.     <th scope="row"><label for="race"><?php _e( 'Race', 'gw2pcl' ); ?>:</label></th>
  1130.  
  1131.     <td><select name="race" id="race">
  1132.  
  1133.     <?php
  1134.  
  1135.         for ( $i=1;$i<=5;$i++ ) {
  1136.  
  1137.             echo '<option' . ( $i == $race ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_race( $i ) . '</option>' . "\n";
  1138.  
  1139.         }
  1140.  
  1141.     ?></select></td>
  1142.  
  1143.     </tr>
  1144.  
  1145.     <tr valign="top">
  1146.  
  1147.     <th scope="row"><label for="profession"><?php _e( 'Profession', 'gw2pcl' ); ?>:</label></th>
  1148.  
  1149.     <td><select name="profession" id="profession">
  1150.  
  1151.     <?php
  1152.  
  1153.         for ( $i=1;$i<=8;$i++ ) {
  1154.  
  1155.             echo '<option' . ( $i == $profession ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_profession( $i ) . '</option>' . "\n";
  1156.  
  1157.         }
  1158.  
  1159.     ?></select></td>
  1160.  
  1161.     </tr>
  1162.  
  1163.     <tr valign="top">
  1164.  
  1165.     <th scope="row"><label for="orderCol"><?php _e( 'Order', 'gw2pcl' ); ?>:</label></th>
  1166.  
  1167.     <td><select name="orderCol" id="orderCol">
  1168.  
  1169.     <?php
  1170.  
  1171.         for ( $i=0;$i<=3;$i++ ) {
  1172.  
  1173.             echo '<option' . ( $i == $orderCol ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_orderCol( $i ) . '</option>' . "\n";
  1174.  
  1175.         }
  1176.  
  1177.     ?></select></td>
  1178.  
  1179.     </tr>
  1180.  
  1181.     <tr valign="top">
  1182.  
  1183.     <th scope="row"><label for="crafting1"><?php _e( 'First Crafting Skill', 'gw2pcl' ); ?>:</label></th>
  1184.  
  1185.     <td><select name="crafting1" id="crafting1">
  1186.  
  1187.     <?php
  1188.  
  1189.         for ( $i=0;$i<=8;$i++ ) {
  1190.  
  1191.             echo '<option' . ( $i == $crafting1 ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_crafting_skill( $i ) . '</option>' . "\n";
  1192.  
  1193.         }
  1194.  
  1195.     ?></select></td>
  1196.  
  1197.     </tr>
  1198.  
  1199.     <tr valign="top">
  1200.  
  1201.     <th scope="row"><label for="crafting2"><?php _e( 'Second Crafting Skill', 'gw2pcl' ); ?>:</label></th>
  1202.  
  1203.     <td><select name="crafting2" id="crafting2">
  1204.  
  1205.     <?php
  1206.  
  1207.         for ( $i=0;$i<=8;$i++ ) {
  1208.  
  1209.             echo '<option' . ( $i == $crafting2 ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_crafting_skill( $i ) . '</option>' . "\n";
  1210.  
  1211.         }
  1212.  
  1213.     ?></select></td>
  1214.  
  1215.     </tr>
  1216.  
  1217.     <tr valign="top">
  1218.  
  1219.     <th scope="row"><label for="fractals"><?php _e( 'Ready to do fractals level', 'gw2pcl' ); ?>:</label></th>
  1220.  
  1221.     <td><input name="fractals" type="text" id="fractals" class="regular-text" value="<?php echo $fractals; ?>" /></td>
  1222.  
  1223.     </tr>
  1224.  
  1225.     <tr valign="top">
  1226.  
  1227.     <th scope="row"><?php _e( 'Story Mode Completed', 'gw2pcl' ); ?>:</th>
  1228.  
  1229.         <td>
  1230.  
  1231.         <input name="ac" type="checkbox" id="ac" class="checkbox" value="1" <?php if ($dungeons['ac'] == 1) echo 'checked="checked" '; ?>/><label for="ac"> <?php _e( 'Ascalonian Catacombs', 'gw2pcl' ); ?></label><br />
  1232.  
  1233.         <input name="cm" type="checkbox" id="cm" class="checkbox" value="1" <?php if ($dungeons['cm'] == 1) echo 'checked="checked" '; ?>/><label for="cm"> <?php _e( 'Caudecus\'s Manor', 'gw2pcl' ); ?></label><br />
  1234.  
  1235.         <input name="ta" type="checkbox" id="ta" class="checkbox" value="1" <?php if ($dungeons['ta'] == 1) echo 'checked="checked" '; ?>/><label for="ta"> <?php _e( 'Twilight Arbor', 'gw2pcl' ); ?></label><br />
  1236.  
  1237.         <input name="se" type="checkbox" id="se" class="checkbox" value="1" <?php if ($dungeons['se'] == 1) echo 'checked="checked" '; ?>/><label for="se"> <?php _e( 'Sorrow\'s Embrace', 'gw2pcl' ); ?></label><br />
  1238.  
  1239.         <input name="cof" type="checkbox" id="cof" class="checkbox" value="1" <?php if ($dungeons['cof'] == 1) echo 'checked="checked" '; ?>/><label for="cof"> <?php _e( 'Citadel of Flame', 'gw2pcl' ); ?></label><br />
  1240.  
  1241.         <input name="hotw" type="checkbox" id="hotw class="checkbox" value="1" <?php if ($dungeons['hotw'] == 1) echo 'checked="checked" '; ?>/><label for="hotw"> <?php _e( 'Honor of the Waves', 'gw2pcl' ); ?></label><br />
  1242.  
  1243.         <input name="coe" type="checkbox" id="coe" class="checkbox" value="1" <?php if ($dungeons['coe'] == 1) echo 'checked="checked" '; ?>/><label for="coe"> <?php _e( 'Crucible of Eternity', 'gw2pcl' ); ?></label><br />
  1244.  
  1245.         <input name="arah" type="checkbox" id="arah" class="checkbox" value="1" <?php if ($dungeons['arah'] == 1) echo 'checked="checked" '; ?>/><label for="arah"> <?php _e( 'Arah', 'gw2pcl' ); ?></label>
  1246.  
  1247.         </td>
  1248.  
  1249.     </tr>
  1250.  
  1251.     <tr valign="top">
  1252.  
  1253.     <th scope="row"><label for="picture"><?php _e( 'Upload Picture', 'gw2pcl' ); ?>:</label></th>
  1254.  
  1255.     <td><input type="file" name="picture" id="picture" /></td>
  1256.  
  1257.     </tr>
  1258.  
  1259. <?php
  1260.  
  1261.     if ( isset( $_POST['gw2pcl_edit'] ) ) {
  1262.  
  1263.         echo '<tr>' . "\n";
  1264.  
  1265.         echo '<td>' . "\n";
  1266.  
  1267.         echo '<input type="checkbox" name="deleteoldpic" id="deleteoldpic" value="1" /><label for="deleteoldpic"> ' . _e( 'delete old picture', 'gw2pcl' ) . '</label>' . "\n";
  1268.  
  1269.         echo '</td>' . "\n";
  1270.  
  1271.         echo '<td>' . "\n";
  1272.  
  1273.         echo '</td>' . "\n";
  1274.  
  1275.         echo '</tr>' . "\n";
  1276.  
  1277.     }
  1278.  
  1279. ?>
  1280.  
  1281.     <tr valign="top">
  1282.  
  1283.     <th scope="row"><label for="teaser"><?php _e( 'Short Phrase', 'gw2pcl' ); ?>:</label></th>
  1284.  
  1285.     <td><input name="teaser" type="text" id="teaser" class="regular-text" value="<?php echo $teaser; ?>" /></td>
  1286.  
  1287.     </tr>
  1288.  
  1289.     </table>
  1290.  
  1291. <?php
  1292.  
  1293.     if ( isset( $_POST['gw2pcl_edit'] ) ) {
  1294.  
  1295.         echo '<input type="hidden" name="gw2pcl_id" value="' . $id . '" />' . "\n";
  1296.  
  1297.         echo '<p><input type="submit" name="gw2pcl_change" value="' . __( 'Change', 'gw2pcl' ) . '" /></p>' . "\n";
  1298.  
  1299.     } else {
  1300.  
  1301.         echo '<p><input type="submit" name="gw2pcl_add" value="' . __( 'Save', 'gw2pcl' ) . '" /></p>' . "\n";
  1302.  
  1303.     }
  1304.  
  1305. ?>
  1306.  
  1307.         <a name="edit"></a>
  1308.  
  1309.     </form>
  1310.  
  1311.  
  1312.  
  1313.     <?php
  1314.  
  1315. }
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321. /**
  1322.  
  1323.  *  Creating our own database table.
  1324.  
  1325.  */
  1326.  
  1327.  
  1328.  
  1329. function gw2pcl_create_database() {
  1330.  
  1331.     global $wpdb;
  1332.  
  1333.     global $gw2pcl_database_version;
  1334.  
  1335.    
  1336.  
  1337.     $table_name = $wpdb->prefix . 'gw2pcl';
  1338.  
  1339.  
  1340.  
  1341.     $sql = "CREATE TABLE $table_name (
  1342.  
  1343.         id mediumint(9) NOT NULL AUTO_INCREMENT,
  1344.  
  1345.         user_id bigint(20) unsigned NOT NULL DEFAULT '0',
  1346.  
  1347.         name VARCHAR(255) DEFAULT '' NOT NULL,
  1348.  
  1349.         teaser VARCHAR(255) DEFAULT '' NOT NULL,
  1350.  
  1351.         picture_file VARCHAR(255) DEFAULT '' NOT NULL,
  1352.  
  1353.         race int(11) NOT NULL DEFAULT '0',
  1354.  
  1355.         profession int(11) NOT NULL DEFAULT '0',
  1356.  
  1357.         orderCol int(11) NOT NULL DEFAULT '0',
  1358.  
  1359.         crafting1 int(11) NOT NULL DEFAULT '0',
  1360.  
  1361.         crafting2 int(11) NOT NULL DEFAULT '0',
  1362.  
  1363.         fractals int(11) NOT NULL DEFAULT '0',
  1364.  
  1365.         dungeons TEXT NOT NULL DEFAULT '',
  1366.  
  1367.         isCommander tinyint(1) NOT NULL DEFAULT '0',
  1368.  
  1369.         UNIQUE KEY id (id)
  1370.  
  1371.     );";
  1372.  
  1373.    
  1374.  
  1375.     require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  1376.  
  1377.     dbDelta($sql);
  1378.  
  1379.    
  1380.  
  1381.     add_option("gw2pcl_database_version", $gw2pcl_database_version);
  1382.  
  1383. }
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389. /**
  1390.  
  1391.  * Uninstall: delete files and database
  1392.  
  1393.  */
  1394.  
  1395.  
  1396.  
  1397. function gw2pcl_uninstall() {
  1398.  
  1399.     global $wpdb;
  1400.  
  1401.     $table_name = $wpdb->prefix . 'gw2pcl';
  1402.  
  1403.    
  1404.  
  1405.     $file_list = $wpdb->get_results( '
  1406.  
  1407.         SELECT id, picture_file
  1408.  
  1409.         FROM $table_name
  1410.  
  1411.         WHERE NOT picture_file = ""
  1412.  
  1413.     ' );
  1414.  
  1415.  
  1416.  
  1417.     foreach ( $file_list as $image_file ) {
  1418.  
  1419.         @unlink( $image_file->picture_file );
  1420.  
  1421.         $otherpath = pathinfo( $image_file->picture_file );
  1422.  
  1423.         @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
  1424.  
  1425.     }
  1426.  
  1427.    
  1428.  
  1429.     $wpdb->query(  'DROP TABLE ' . $table_name );
  1430.  
  1431. }
  1432.  
  1433.  
  1434.  
  1435. /**
  1436.  
  1437.  *  HELPER FUNCTIONS
  1438.  
  1439.  *  HINT: User strtolower after code outsourcing into it's own files.
  1440.  
  1441.  */
  1442.  
  1443.  
  1444.  
  1445. // Define wether the current char is a commander or not and display the commander icon if he is.
  1446.  
  1447. function isCommanderFunction($charName) {
  1448.  
  1449.     global $wpdb;
  1450.  
  1451.     $table_name = $wpdb->prefix . 'gw2pcl';
  1452.  
  1453.     $isCommander = $wpdb->get_var( "SELECT isCommander FROM $table_name WHERE name = '$charName'" );
  1454.  
  1455.    
  1456.  
  1457.     if ( $isCommander == '1' )
  1458.  
  1459.         return (' <img src="' . plugin_dir_url( __FILE__ ) . 'pics/commander.png" alt="commander" />');
  1460.  
  1461. }
  1462.  
  1463.  
  1464.  
  1465. function get_race( $id ) {
  1466.  
  1467.     switch ( $id ) {
  1468.  
  1469.         case 1:
  1470.  
  1471.             return( __( 'Asura', 'gw2pcl' ) );
  1472.  
  1473.             break;
  1474.  
  1475.         case 2:
  1476.  
  1477.             return( __( 'Charr', 'gw2pcl' ) );
  1478.  
  1479.             break;
  1480.  
  1481.         case 3:
  1482.  
  1483.             return( __( 'Human', 'gw2pcl' ) );
  1484.  
  1485.             break;
  1486.  
  1487.         case 4:
  1488.  
  1489.             return( __( 'Norn', 'gw2pcl' ) );
  1490.  
  1491.             break;
  1492.  
  1493.         case 5:
  1494.  
  1495.             return( __( 'Sylvari', 'gw2pcl' ) );
  1496.  
  1497.             break;
  1498.  
  1499.     }
  1500.  
  1501.     return( __( 'unknown race', 'gw2pcl' ) );
  1502.  
  1503. }
  1504.  
  1505.  
  1506.  
  1507. function get_race_pic( $id ) {
  1508.  
  1509.     $pic = "";
  1510.  
  1511.     switch ( $id ) {
  1512.  
  1513.         case 1:
  1514.  
  1515.             $pic .= 'asura';
  1516.  
  1517.             break;
  1518.  
  1519.         case 2:
  1520.  
  1521.             $pic .= 'charr';
  1522.  
  1523.             break;
  1524.  
  1525.         case 3:
  1526.  
  1527.             $pic .= 'human';
  1528.  
  1529.             break;
  1530.  
  1531.         case 4:
  1532.  
  1533.             $pic .= 'norn';
  1534.  
  1535.             break;
  1536.  
  1537.         case 5:
  1538.  
  1539.             $pic .= 'sylvari';
  1540.  
  1541.             break;
  1542.  
  1543.     }
  1544.  
  1545.     return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_race( $id ) . '" />');
  1546.  
  1547. }
  1548.  
  1549.  
  1550.  
  1551. function get_profession( $id ) {
  1552.  
  1553.     switch ( $id ) {
  1554.  
  1555.         case 1:
  1556.  
  1557.             return( __( 'Guardian', 'gw2pcl' ) );
  1558.  
  1559.             break;
  1560.  
  1561.         case 2:
  1562.  
  1563.             return( __( 'Warrior', 'gw2pcl' ) );
  1564.  
  1565.             break;
  1566.  
  1567.         case 3:
  1568.  
  1569.             return( __( 'Engineer', 'gw2pcl' ) );
  1570.  
  1571.             break;
  1572.  
  1573.         case 4:
  1574.  
  1575.             return( __( 'Ranger', 'gw2pcl' ) );
  1576.  
  1577.             break;
  1578.  
  1579.         case 5:
  1580.  
  1581.             return( __( 'Thief', 'gw2pcl' ) );
  1582.  
  1583.             break;
  1584.  
  1585.         case 6:
  1586.  
  1587.             return( __( 'Elementalist', 'gw2pcl' ) );
  1588.  
  1589.             break;
  1590.  
  1591.         case 7:
  1592.  
  1593.             return( __( 'Mesmer', 'gw2pcl' ) );
  1594.  
  1595.             break;
  1596.  
  1597.         case 8:
  1598.  
  1599.             return( __( 'Necromancer', 'gw2pcl' ) );
  1600.  
  1601.             break;
  1602.  
  1603.     }
  1604.  
  1605.     return( __( 'unknown profession', 'gw2pcl' ) );
  1606.  
  1607. }
  1608.  
  1609.  
  1610.  
  1611. function get_profession_pic( $id ) {
  1612.  
  1613.     $pic = "";
  1614.  
  1615.     switch ( $id ) {
  1616.  
  1617.         case 1:
  1618.  
  1619.             $pic .= 'guardian';
  1620.  
  1621.             break;
  1622.  
  1623.         case 2:
  1624.  
  1625.             $pic .= 'warrior';
  1626.  
  1627.             break;
  1628.  
  1629.         case 3:
  1630.  
  1631.             $pic .= 'engineer';
  1632.  
  1633.             break;
  1634.  
  1635.         case 4:
  1636.  
  1637.             $pic .= 'ranger';
  1638.  
  1639.             break;
  1640.  
  1641.         case 5:
  1642.  
  1643.             $pic .= 'thief';
  1644.  
  1645.             break;
  1646.  
  1647.         case 6:
  1648.  
  1649.             $pic .= 'elementalist';
  1650.  
  1651.             break;
  1652.  
  1653.         case 7:
  1654.  
  1655.             $pic .= 'mesmer';
  1656.  
  1657.             break;
  1658.  
  1659.         case 8:
  1660.  
  1661.             $pic .= 'necromancer';
  1662.  
  1663.             break;
  1664.  
  1665.     }
  1666.  
  1667.     return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_profession( $id ) . '" />');
  1668.  
  1669. }
  1670.  
  1671.  
  1672.  
  1673. function get_orderCol( $id ) {
  1674.  
  1675.         switch ( $id ) {
  1676.  
  1677.             case 0:
  1678.  
  1679.                 return( __( 'No order', 'gw2pcl' ) );
  1680.  
  1681.                 break;
  1682.  
  1683.             case 1:
  1684.  
  1685.                 return( __( 'Order of Whisperers', 'gw2pcl' ) );
  1686.  
  1687.                 break;
  1688.  
  1689.             case 2:
  1690.  
  1691.                 return( __( 'Durmand Priory', 'gw2pcl' ) );
  1692.  
  1693.                 break;
  1694.  
  1695.             case 3:
  1696.  
  1697.                 return( __( 'The Vigil', 'gw2pcl' ) );
  1698.  
  1699.                 break;
  1700.  
  1701.         }
  1702.  
  1703.         return( __( 'unknown order', 'gw2pcl' ) );
  1704.  
  1705. }
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711. function get_orderCol_pic( $id ) {
  1712.  
  1713.     $pic = "";
  1714.  
  1715.     switch ( $id ) {
  1716.  
  1717.         case 1:
  1718.  
  1719.             $pic .= 'orderOfWhisperers';
  1720.  
  1721.             break;
  1722.  
  1723.         case 2:
  1724.  
  1725.             $pic .= 'durmandPriory';
  1726.  
  1727.             break;
  1728.  
  1729.         case 3:
  1730.  
  1731.             $pic .= 'theVigil';
  1732.  
  1733.             break;
  1734.  
  1735.     }
  1736.  
  1737.     return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/orders/' . $pic . '.png" alt="' . get_orderCol( $id ) . '" />');
  1738.  
  1739. }
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747. function get_crafting_skill( $id ) {
  1748.  
  1749.     switch ( $id ) {
  1750.  
  1751.         case 0:
  1752.  
  1753.             return ( __( 'I don\'t craft', 'gw2pcl' ) );
  1754.  
  1755.             break;
  1756.  
  1757.         case 1:
  1758.  
  1759.             return ( __( 'Armorsmith', 'gw2pcl' ) );
  1760.  
  1761.             break;
  1762.  
  1763.         case 2:
  1764.  
  1765.             return ( __( 'Artificer', 'gw2pcl' ) );
  1766.  
  1767.             break;
  1768.  
  1769.         case 3:
  1770.  
  1771.             return ( __( 'Chef', 'gw2pcl' ) );
  1772.  
  1773.             break;
  1774.  
  1775.         case 4:
  1776.  
  1777.             return ( __( 'Huntsman', 'gw2pcl' ) );
  1778.  
  1779.             break;
  1780.  
  1781.         case 5:
  1782.  
  1783.             return ( __( 'Jeweler', 'gw2pcl' ) );
  1784.  
  1785.             break;
  1786.  
  1787.         case 6:
  1788.  
  1789.             return ( __( 'Leatherworker', 'gw2pcl' ) );
  1790.  
  1791.             break;
  1792.  
  1793.         case 7:
  1794.  
  1795.             return ( __( 'Tailor', 'gw2pcl' ) );
  1796.  
  1797.             break;
  1798.  
  1799.         case 8:
  1800.  
  1801.             return ( __( 'Weaponsmith', 'gw2pcl' ) );
  1802.  
  1803.             break;
  1804.  
  1805.     }
  1806.  
  1807.     return ( __( 'unknown crafting skill', 'gw2pcl' ) );
  1808.  
  1809. }
  1810.  
  1811.  
  1812.  
  1813.  
  1814.  
  1815. function get_crafting_skill_pic( $id ) {
  1816.  
  1817.     $pic = "";
  1818.  
  1819.     switch ( $id ) {
  1820.  
  1821.         case 1:
  1822.  
  1823.             $pic = 'armorsmith';
  1824.  
  1825.             break;
  1826.  
  1827.         case 2:
  1828.  
  1829.             $pic = 'artificer';
  1830.  
  1831.             break;
  1832.  
  1833.         case 3:
  1834.  
  1835.             $pic = 'chef';
  1836.  
  1837.             break;
  1838.  
  1839.         case 4:
  1840.  
  1841.             $pic = 'huntsman';
  1842.  
  1843.             break;
  1844.  
  1845.         case 5:
  1846.  
  1847.             $pic = 'jeweler';
  1848.  
  1849.             break;
  1850.  
  1851.         case 6:
  1852.  
  1853.             $pic = 'leatherworker';
  1854.  
  1855.             break;
  1856.  
  1857.         case 7:
  1858.  
  1859.             $pic = 'tailor';
  1860.  
  1861.             break;
  1862.  
  1863.         case 8:
  1864.  
  1865.             $pic = 'weaponsmith';
  1866.  
  1867.             break;
  1868.  
  1869.     }
  1870.  
  1871.     return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_crafting_skill( $id ) . '" />');
  1872.  
  1873. }
  1874.  
  1875.  
  1876.  
  1877. ?>
Advertisement
Add Comment
Please, Sign In to add comment