Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: gw2pcl - Guild Wars 2 Player's Character List
- 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.
- Usage: [gw2pcl who="<<user_login>>"]
- Version: 2.0.2
- Author: max.mueller
- Based on gw2pcl written by Arne.
- License: GPL3
- */
- global $gw2pcl_database_version;
- $gw2pcl_database_version = 1;
- add_action ( 'admin_menu', 'gw2pcl_menu' );
- register_activation_hook(__FILE__,'gw2pcl_create_database');
- if (get_site_option('gw2pcl_database_version') != gw2pcl_database_version) gw2pcl_create_database();
- add_shortcode( 'gw2pcl', 'gw2pcl_shortcode' );
- add_action('wp_head', 'gw2pcl_css');
- register_uninstall_hook( __FILE__, 'gw2pcl_uninstall' );
- // If your wordpress installation is configured to german all texts will be translated. Otherwise it'll stay English.
- load_plugin_textdomain( 'gw2pcl', false, basename(dirname(__FILE__)) . '/languages/' );
- function gw2pcl_css() {
- echo '<link rel="stylesheet" href="' . plugin_dir_url( __FILE__ ) . 'gw2pcl.css" />' . "\n";
- }
- function gw2pcl_menu() {
- add_menu_page( __( 'Manage my Characters', 'gw2pcl' ), __( 'My Chars', 'gw2pcl' ), 'upload_files', 'gw2pclmainmenu', 'gw2pcl_page', plugin_dir_url( __FILE__ ).'pics/gw2.png', '99.000020120924171044' );
- }
- /**
- * Displaying Guild Member's Character List on the Frontend
- */
- function gw2pcl_shortcode( $attributes ) {
- // Allow following atributes, which are optional and have default values (=> 'default value').
- extract( shortcode_atts( array(
- 'who' => 'nobody',
- ), $attributes ) );
- global $wpdb;
- $gw2pcl_table_name = $wpdb->prefix . 'gw2pcl';
- $output = "";
- // IF no user is given as an attribute print all the characters.
- if ( $who == "nobody" ) {
- $chars = $wpdb->get_results( "
- SELECT id, user_id, name, isCommander, picture_file, race, profession, orderCol, crafting1, crafting2, fractals, dungeons, teaser
- FROM $gw2pcl_table_name
- ORDER BY user_id ASC, name ASC
- " );
- } else {
- // Predetermine which user_id is assigned to the transmitted user (shortcode attribute "who").
- $current_user_id = $wpdb->get_var( "SELECT id FROM $wpdb->users WHERE user_login = '$who'" );
- // Get this specific user's characters.
- $chars = $wpdb->get_results( "
- SELECT id, user_id, name, isCommander, picture_file, race, profession, orderCol, crafting1, crafting2, fractals, dungeons, teaser
- FROM $gw2pcl_table_name
- WHERE user_id = $current_user_id
- ORDER BY user_id ASC, name ASC
- " );
- }
- $alternate = 1;
- $last_uid = 0;
- foreach ( $chars as $char ) {
- if ( $char->user_id != $last_uid) {
- $user = get_user_by('id', $char->user_id);
- $output .= '<div class="gw2user">' . esc_html( $user->display_name ) . '</div>' . "\n";
- $last_uid = $char->user_id;
- }
- $output .= '<div class="gw2row ' . ( $alternate ? 'gw2odd' : 'gw2even' ) . '">' . "\n";
- $output .= '<div class="gw2desc">';
- $output .= '<div class="gw2pic">';
- if ( file_exists( $char->picture_file ) ) {
- $upload_path = wp_upload_dir();
- $image_sized = image_resize( $char->picture_file, 160, 300, true, null, null, 100 );
- $image_sized = is_wp_error($image_sized) ? $char->picture_file : $image_sized;
- $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );
- $output .= '<img src="' . $image_sized . '" alt="' . esc_html( $char->name ) . '" />';
- } else {
- $output .= '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $char->name ) . '" />';
- }
- $output .= '</div>' . "\n";
- // name and commander badge
- $output .= '<strong><span style="font-size:2em;">' . esc_html($char->name);
- $output .= ' ' . isCommanderFunction($char->name) . '</span></strong><br />';
- // race
- $output .= get_race_pic( $char->race ) . ' ' . get_race( $char->race ) . '<br />';
- //profession
- $output .= get_profession_pic( $char->race ) . ' ' . get_profession( $char->race ) . '<br />';
- // order
- if ( $char->orderCol != 0 ) {
- $output .= get_orderCol_pic( $char->orderCol ) . ' ' . get_orderCol( $char->orderCol ) . '<br />';
- }
- // crafting
- if ( $char->crafting1 != 0 ) {
- $output .= get_crafting_skill_pic( $char->crafting1 ) . ' ' . get_crafting_skill( $char->crafting1 );
- }
- if ( ( $char->crafting1 != 0 ) and ( $char->crafting2 != 0 ) ) $output .= ' ' . __( 'and', 'gw2pcl' ) . ' ';
- if ( $char->crafting2 != 0 ) {
- $output .= get_crafting_skill_pic( $char->crafting2 ) . ' ' . get_crafting_skill( $char->crafting2 );
- }
- $output .= '<br />';
- // fractals
- if ( $char->fractals != 0 ) {
- $output .= '<img src="' . plugin_dir_url( __FILE__ ) . 'pics/fractals.jpg" />';
- $output .= ' ' . __( 'Fractals Level', 'gw2pcl' ) . ': ' . $char->fractals;
- }
- // story mode
- // TODO !!! Code reuse as a function as above. !!!
- if ( !strstr($char->dungeons, "a:0") ) {
- $output .= '<br />';
- $output .= __( 'Story Mode Completed', 'gw2pcl' ) . ':<br />';
- $dungeons = unserialize( $char->dungeons );
- if ($dungeons['ac'] == 1) $output .= '<img title="' . __( 'Ascalonian Catacombs', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/ac.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['cm'] == 1) $output .= '<img title="' . __( 'Caudecus\'s Manor', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/cm.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['ta'] == 1) $output .= '<img title="' . __( 'Twilight Arbor', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/ta.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['se'] == 1) $output .= '<img title="' . __( 'Sorrow\'s Embrace', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/se.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['cof'] == 1) $output .= '<img title="' . __( 'Citadel of Flame', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/cof.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['hotw'] == 1) $output .= '<img title="' . __( 'Honor of the Waves', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/hotw.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['coe'] == 1) $output .= '<img title="' . __( 'Crucible of Eternity', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/coe.png" class="gw2pcl_dungeonpic" /> ';
- if ($dungeons['arah'] == 1) $output .= '<img title="' . __( 'Arah', 'gw2pcl' ) . '" src="' . plugin_dir_url( __FILE__ ) . 'pics/dungeons/arah.png" class="gw2pcl_dungeonpic" /> ';
- }
- // teaser
- if ( strlen( $char->teaser ) > 2 ) {
- $output .= '<br />'."\n".'<em>ยป' . esc_html( $char->teaser ) . 'ยซ</em>';
- }
- $output .= '</div>' . "\n";
- $output .= '<div style="clear:both;"></div>';
- $output .= '</div>' . "\n";
- $alternate = 1 - $alternate;
- }
- return $output;
- }
- /**
- * DISPLAYS PAGE IN BACKEND AND DOES THE DB-EDITING
- */
- function gw2pcl_page() {
- global $wpdb;
- $table_name = $wpdb->prefix . 'gw2pcl';
- $cur_user = get_userdata( get_current_user_id() );
- $user_level = $cur_user->user_level;
- // Ensuring I'm either at least an editor or the owner of this char
- $where_two = "";
- if ( $user_level < 7 ) {
- $where_two = ' AND user_id = '.get_current_user_id();
- }
- /**
- * ADD NEW CHAR TO DATABASE
- */
- if ( isset( $_POST['gw2pcl_add'] ) ) {
- if ( ! isset( $_POST['_gw2pcl_nonce'] ) || ! wp_verify_nonce( $_POST['_gw2pcl_nonce'], 'gw2pcl_nonce' ) ) return;
- $name = stripslashes( $_POST['name'] );
- $isCommander= intval ( $_POST['isCommander'] );
- $teaser = stripslashes( $_POST['teaser'] );
- $race = intval ( $_POST['race'] );
- $profession = intval ( $_POST['profession'] );
- $orderCol = intval ( $_POST['orderCol'] );
- $crafting1 = intval ( $_POST['crafting1'] );
- $crafting2 = intval ( $_POST['crafting2'] );
- $fractals = intval ( $_POST['fractals'] );
- if (($fractals > 999) or ($fractals < 2)) $fractals = 0;
- $dungeons = array();
- if ( intval( $_POST['ac'] ) == 1) $dungeons['ac'] = 1;
- if ( intval( $_POST['cm'] ) == 1) $dungeons['cm'] = 1;
- if ( intval( $_POST['ta'] ) == 1) $dungeons['ta'] = 1;
- if ( intval( $_POST['se'] ) == 1) $dungeons['se'] = 1;
- if ( intval( $_POST['cof'] ) == 1) $dungeons['cof'] = 1;
- if ( intval( $_POST['hotw'] ) == 1) $dungeons['hotw'] = 1;
- if ( intval( $_POST['coe'] ) == 1) $dungeons['coe'] = 1;
- if ( intval( $_POST['arah'] ) == 1) $dungeons['arah'] = 1;
- if ($name == "") {
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Name can\'t be left blank.', 'gw2pcl' ) . '</strong></p></div>';
- } else {
- // Only JPG and PNG. Not even annoying GIFs.
- if ( ! empty( $_FILES['picture']['name'] ) ) {
- $mimes = array(
- 'jpg|jpeg' => 'image/jpeg',
- 'png' => 'image/png'
- );
- $charpic = wp_handle_upload( $_FILES['picture'], array( 'mimes' => $mimes, 'test_form' => false ) );
- if ( ! empty ( $charpic['file'] ) ) {
- $picture_file = $charpic['file'];
- }
- }
- $wpdb->query(
- $wpdb->prepare("
- INSERT INTO $table_name
- ( name, isCommander, race, profession, orderCol, crafting1, crafting2, picture_file, teaser, fractals, dungeons, user_id )
- VALUES ( %s, %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )
- ", $name, $isCommander, $race, $profession, $orderCol, $crafting1, $crafting2, $picture_file, $teaser, $fractals, serialize($dungeons), get_current_user_id() )
- );
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Character added.', 'gw2pcl' ) . '</strong></p></div>';
- }
- }
- /**
- * MODIFY ENTRY
- */
- if ( isset( $_POST['gw2pcl_change'] ) ) {
- if ( ! isset( $_POST['_gw2pcl_nonce'] ) || ! wp_verify_nonce( $_POST['_gw2pcl_nonce'], 'gw2pcl_nonce' ) ) return;
- $name = stripslashes( $_POST['name'] );
- $isCommander= intval ( $_POST['isCommander'] );
- $teaser = stripslashes( $_POST['teaser'] );
- $id = intval ( $_POST['gw2pcl_id'] );
- $race = intval ( $_POST['race'] );
- $profession = intval ( $_POST['profession'] );
- $orderCol = intval ( $_POST['orderCol'] );
- $crafting1 = intval ( $_POST['crafting1'] );
- $crafting2 = intval ( $_POST['crafting2'] );
- $fractals = intval ( $_POST['fractals'] );
- if (($fractals > 999) or ($fractals < 2)) $fractals = 0;
- $delete = intval ( $_POST['deleteoldpic'] or 0 );
- $dungeons = array();
- if ( intval( $_POST['ac'] ) == 1) $dungeons['ac'] = 1;
- if ( intval( $_POST['cm'] ) == 1) $dungeons['cm'] = 1;
- if ( intval( $_POST['ta'] ) == 1) $dungeons['ta'] = 1;
- if ( intval( $_POST['se'] ) == 1) $dungeons['se'] = 1;
- if ( intval( $_POST['cof'] ) == 1) $dungeons['cof'] = 1;
- if ( intval( $_POST['hotw'] ) == 1) $dungeons['hotw'] = 1;
- if ( intval( $_POST['coe'] ) == 1) $dungeons['coe'] = 1;
- if ( intval( $_POST['arah'] ) == 1) $dungeons['arah'] = 1;
- // Am I allowed to do that?
- if ( $id > 0 ) {
- $entry = $wpdb->get_row('SELECT * FROM ' . $table_name . ' WHERE id = '.$id . $where_two );
- if ($entry != null) {
- $picture_file = $entry->picture_file;
- } else {
- wp_die( 'No' );
- }
- } else {
- wp_die( 'No' );
- }
- // Then do it
- // unnice code reuse
- if ($name == "") {
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Name can\'t be left blank.', 'gw2pcl' ) . '</strong></p></div>';
- } else {
- // Delete old images if a new one was uploaded
- // or the user wanted the old one to be deleted
- if ( ( ! empty( $_FILES['picture']['name'] ) ) or ( $delete ) ) {
- @unlink( $entry->picture_file );
- $otherpath = pathinfo( $entry->picture_file );
- @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
- $picture_file = "";
- }
- if ( ! empty( $_FILES['picture']['name'] ) ) {
- $mimes = array(
- 'jpg|jpeg' => 'image/jpeg',
- 'png' => 'image/png'
- );
- $charpic = wp_handle_upload( $_FILES['picture'], array( 'mimes' => $mimes, 'test_form' => false ) );
- if ( ! empty ( $charpic['file'] ) ) {
- $picture_file = $charpic['file'];
- }
- }
- $wpdb->query(
- $wpdb->prepare("
- UPDATE $table_name SET
- name = %s,
- isCommander = %d,
- race = %d,
- profession = %d,
- orderCol = %d,
- crafting1 = %d,
- crafting2 = %d,
- picture_file = %s,
- teaser = %s,
- fractals = %d,
- dungeons = %s
- WHERE id = %d
- ", $name, $isCommander, $race, $profession, $orderCol, $crafting1, $crafting2, $picture_file, $teaser, $fractals, serialize($dungeons), $id)
- );
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Character edited.', 'gw2pcl' ) . '</strong></p></div>';
- }
- }
- // Default Values
- $name = "";
- $isCommander= 0;
- $teaser = "";
- $race = 3;
- $profession = 6;
- $orderCol = 0;
- $crafting1 = 0;
- $crafting2 = 0;
- $fractals = 0;
- $dungeons = array();
- /**
- * Delete selected
- */
- if ( isset( $_POST['gw2pcl_delete'] ) ) {
- $delete = $_POST["post"];
- if ( sizeof( $delete ) < 1 ) {
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Nothing to delete.', 'gw2pcl' ) . '</strong></p></div>';
- } else {
- $delete_string = "";
- foreach ($delete as $todelete) {
- $delete_string = $delete_string . intval($todelete) . ', ';
- }
- $delete_string = substr($delete_string, 0, strlen($delete_string) - 2);
- // Deleting Images and resized Images
- $file_list = $wpdb->get_results( 'SELECT user_id, picture_file FROM ' . $table_name . ' WHERE id IN ( ' . $delete_string . ' )' . $where_two );
- foreach ( $file_list as $image_file ) {
- if ( $image_file->picture_file ) {
- @unlink( $image_file->picture_file );
- $otherpath = pathinfo( $image_file->picture_file );
- @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
- }
- }
- $wpdb->query( 'DELETE FROM ' . $table_name . ' WHERE id IN ( ' . $delete_string . ' )' . $where_two );
- echo '<div id="message" class="updated fade"><p><strong>' . __( 'Deleted selected Characters.', 'gw2pcl' ) . '</strong></p></div>';
- }
- }
- /**
- * DISPLAY LIST OF CHARS IN THE BACKEND
- */
- ?>
- <h1><?php __( 'Manage my Characters', 'gw2pcl' ); ?></h1>
- <p><?php _e( 'On this page you can enter all your characters for the list of all guild members.', 'gw2pcl' ); ?></p>
- <?php
- if ( $user_level >= 7 ) {
- 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";
- 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";
- if ( isset( $_POST['gw2pcl_view_all'] ) ) $_SESSION["gw2pcl-viewall"] = true;
- if ( isset( $_POST['gw2pcl_view_mine'] ) ) $_SESSION["gw2pcl-viewall"] = false;
- if ( $_SESSION["gw2pcl-viewall"] == false) {
- echo '<form method="post" action=""><p><input type="submit" name="gw2pcl_view_all" id="gw2pcl_view_all" value="' . __( 'view all', 'gw2pcl' ) . '" /></p></form>'."\n";
- } else {
- 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";
- }
- }
- ?>
- <form method="post" action="">
- <table class="wp-list-table widefat" cellspacing="0">
- <thead>
- <tr>
- <th scope='col' id='cb' class='manage-column column-cb check-column' style=""><input type="checkbox" /></th>
- <th><?php _e( 'Picture', 'gw2pcl' ); ?></th>
- <th><?php _e( 'Details', 'gw2pcl' ); ?></th>
- </tr>
- </thead>
- <tbody id="the-list">
- <?php
- $chars = $wpdb->get_results( "
- SELECT *
- FROM $table_name
- " . ((($user_level >= 7) and ($_SESSION["gw2pcl-viewall"])) ? "" : "WHERE user_id = " . get_current_user_id() ) . "
- ORDER BY name
- " );
- $alternate = 1;
- foreach ( $chars as $char ) {
- echo '<tr' . ( $alternate ? ' class="alternate"' : '' ) . '>' . "\n";
- echo '<th scope="row" class="check-column"><input type="checkbox" name="post[]" value="' . $char->id . '" /></th>' . "\n";
- echo '<td>';
- if ( file_exists( $char->picture_file ) ) {
- $upload_path = wp_upload_dir();
- $image_sized = image_resize( $char->picture_file, 150, 200, true, null, null, 100 );
- $image_sized = is_wp_error($image_sized) ? $char->picture_file : $image_sized;
- $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );
- echo '<img src="' . $image_sized . '" alt="' . esc_html( $char->name ) . '" />';
- } else {
- echo '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $char->name ) . '" />';
- }
- echo '</td>' . "\n";
- echo '<td>';
- echo '<strong><span style="font-size:2em;">' . esc_html($char->name);
- echo ' ' . isCommanderFunction($char->name) . '</span></strong><br />';
- $user = (get_user_meta( $char->user_id, 'nickname', true ));
- if ( $user == "" ) {
- $user = '<strong><span style="color:#f00;">' . __( 'User doesn\'t exist!', 'gw2pcl' ) . '</span></strong>';
- } else {
- $user = '<em>' . $user . '</em>';
- }
- echo $user . '<br />';
- echo get_race( $char->race );
- echo '<br />';
- echo get_profession( $char->profession );
- echo '<br />';
- echo get_orderCol( $char->orderCol );
- echo '<br />';
- if ( $char->crafting1 != 0 ) echo get_crafting_skill( $char->crafting1 );
- if ( ( $char->crafting1 != 0 ) and ( $char->crafting2 != 0 ) ) echo ' ' . __( 'and', 'gw2pcl' ) . ' ';
- if ( $char->crafting2 != 0 ) echo get_crafting_skill( $char->crafting2 );
- if ( ( $char->crafting1 == 0 ) and ( $char->crafting2 == 0 ) ) _e( 'no crafting skills', 'gw2pcl' );
- echo '<br />';
- if ( ( $char->fractals) == 0) {
- _e( 'hasn\'t been doing fractals so far', 'gw2pcl' );
- } else {
- _e( 'Can enter fractals level', 'gw2pcl' );
- echo ': ' . $char->fractals;
- }
- if ( strlen( $char->teaser ) > 2 ) {
- echo '<br />'."\n".'<em>ยป' . esc_html( $char->teaser ) . 'ยซ</em>';
- }
- 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";
- echo '</td>' . "\n";
- echo '</tr>' . "\n";
- $alternate = 1 - $alternate;
- }
- ?>
- </tbody>
- </table>
- <p><input type="submit" name="gw2pcl_delete" id="gw2pcl_delete" value="<?php _e( 'Delete selected', 'gw2pcl' ); ?>" /></p>
- </form>
- <?php
- /**
- * FORM FOR ADDING AND MODIFYING NEW CHARS
- * Man, that's ugly. I'm not used to do that on my own.
- */
- ?>
- <h2><?php
- if ( isset( $_POST['gw2pcl_edit'] ) ) {
- _e( 'Edit Character', 'gw2pcl' );
- $id = intval( $_POST['gw2pcl_id'] );
- if ( $id > 0 ) {
- $entry = $wpdb->get_row('SELECT * FROM ' . $table_name . ' WHERE id = '.$id . $where_two );
- if ($entry != null) {
- $name = $entry->name;
- $isCommander= $entry->isCommander;
- $race = $entry->race;
- $teaser = $entry->teaser;
- $profession = $entry->profession;
- $orderCol = $entry->orderCol;
- $crafting1 = $entry->crafting1;
- $crafting2 = $entry->crafting2;
- $fractals = $entry->fractals;
- $dungeons = unserialize( $entry->dungeons );
- }
- }
- } else {
- _e( 'Add New Character', 'gw2pcl' );
- }
- ?></h2>
- <form method="post" enctype="multipart/form-data" action="">
- <?php wp_nonce_field( 'gw2pcl_nonce', '_gw2pcl_nonce', false ); ?>
- <table class="form-table">
- <tr valign="top">
- <th scope="row"><label for="name"><?php _e( 'Name', 'gw2pcl' ); ?>:</label></th>
- <td><input name="name" type="text" id="name" class="regular-text" value="<?php echo $name; ?>" /></td>
- <td rowspan="0" width="170" valign="top">
- <?php
- if ( isset( $_POST['gw2pcl_edit'] ) ) {
- // When editing a char display the image, too.
- if ( file_exists( $entry->picture_file ) ) {
- $upload_path = wp_upload_dir();
- $image_sized = image_resize( $entry->picture_file, 150, 200, true, null, null, 100 );
- $image_sized = is_wp_error($image_sized) ? $entry->picture_file : $image_sized;
- $image_sized = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $image_sized );
- echo '<img src="' . $image_sized . '" alt="' . esc_html( $entry->name ) . '" />';
- } else {
- echo '<img src="' . plugin_dir_url( __FILE__ ).'pics/nopic.png' . '" alt="' . esc_html( $entry->name ) . '" />';
- }
- }
- ?>
- </td>
- <?php
- //Choose if character is a commander or not.
- ?>
- <tr valign="top">
- <th scope="row"><?php _e( 'Commander', 'gw2pcl' ); ?>:</th>
- <td>
- <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 />
- </td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="race"><?php _e( 'Race', 'gw2pcl' ); ?>:</label></th>
- <td><select name="race" id="race">
- <?php
- for ( $i=1;$i<=5;$i++ ) {
- echo '<option' . ( $i == $race ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_race( $i ) . '</option>' . "\n";
- }
- ?></select></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="profession"><?php _e( 'Profession', 'gw2pcl' ); ?>:</label></th>
- <td><select name="profession" id="profession">
- <?php
- for ( $i=1;$i<=8;$i++ ) {
- echo '<option' . ( $i == $profession ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_profession( $i ) . '</option>' . "\n";
- }
- ?></select></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="orderCol"><?php _e( 'Order', 'gw2pcl' ); ?>:</label></th>
- <td><select name="orderCol" id="orderCol">
- <?php
- for ( $i=0;$i<=3;$i++ ) {
- echo '<option' . ( $i == $orderCol ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_orderCol( $i ) . '</option>' . "\n";
- }
- ?></select></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="crafting1"><?php _e( 'First Crafting Skill', 'gw2pcl' ); ?>:</label></th>
- <td><select name="crafting1" id="crafting1">
- <?php
- for ( $i=0;$i<=8;$i++ ) {
- echo '<option' . ( $i == $crafting1 ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_crafting_skill( $i ) . '</option>' . "\n";
- }
- ?></select></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="crafting2"><?php _e( 'Second Crafting Skill', 'gw2pcl' ); ?>:</label></th>
- <td><select name="crafting2" id="crafting2">
- <?php
- for ( $i=0;$i<=8;$i++ ) {
- echo '<option' . ( $i == $crafting2 ? ' selected="selected"' : '' ) . ' value="' . $i . '">' . get_crafting_skill( $i ) . '</option>' . "\n";
- }
- ?></select></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="fractals"><?php _e( 'Ready to do fractals level', 'gw2pcl' ); ?>:</label></th>
- <td><input name="fractals" type="text" id="fractals" class="regular-text" value="<?php echo $fractals; ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row"><?php _e( 'Story Mode Completed', 'gw2pcl' ); ?>:</th>
- <td>
- <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 />
- <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 />
- <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 />
- <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 />
- <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 />
- <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 />
- <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 />
- <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>
- </td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="picture"><?php _e( 'Upload Picture', 'gw2pcl' ); ?>:</label></th>
- <td><input type="file" name="picture" id="picture" /></td>
- </tr>
- <?php
- if ( isset( $_POST['gw2pcl_edit'] ) ) {
- echo '<tr>' . "\n";
- echo '<td>' . "\n";
- echo '<input type="checkbox" name="deleteoldpic" id="deleteoldpic" value="1" /><label for="deleteoldpic"> ' . _e( 'delete old picture', 'gw2pcl' ) . '</label>' . "\n";
- echo '</td>' . "\n";
- echo '<td>' . "\n";
- echo '</td>' . "\n";
- echo '</tr>' . "\n";
- }
- ?>
- <tr valign="top">
- <th scope="row"><label for="teaser"><?php _e( 'Short Phrase', 'gw2pcl' ); ?>:</label></th>
- <td><input name="teaser" type="text" id="teaser" class="regular-text" value="<?php echo $teaser; ?>" /></td>
- </tr>
- </table>
- <?php
- if ( isset( $_POST['gw2pcl_edit'] ) ) {
- echo '<input type="hidden" name="gw2pcl_id" value="' . $id . '" />' . "\n";
- echo '<p><input type="submit" name="gw2pcl_change" value="' . __( 'Change', 'gw2pcl' ) . '" /></p>' . "\n";
- } else {
- echo '<p><input type="submit" name="gw2pcl_add" value="' . __( 'Save', 'gw2pcl' ) . '" /></p>' . "\n";
- }
- ?>
- <a name="edit"></a>
- </form>
- <?php
- }
- /**
- * Creating our own database table.
- */
- function gw2pcl_create_database() {
- global $wpdb;
- global $gw2pcl_database_version;
- $table_name = $wpdb->prefix . 'gw2pcl';
- $sql = "CREATE TABLE $table_name (
- id mediumint(9) NOT NULL AUTO_INCREMENT,
- user_id bigint(20) unsigned NOT NULL DEFAULT '0',
- name VARCHAR(255) DEFAULT '' NOT NULL,
- teaser VARCHAR(255) DEFAULT '' NOT NULL,
- picture_file VARCHAR(255) DEFAULT '' NOT NULL,
- race int(11) NOT NULL DEFAULT '0',
- profession int(11) NOT NULL DEFAULT '0',
- orderCol int(11) NOT NULL DEFAULT '0',
- crafting1 int(11) NOT NULL DEFAULT '0',
- crafting2 int(11) NOT NULL DEFAULT '0',
- fractals int(11) NOT NULL DEFAULT '0',
- dungeons TEXT NOT NULL DEFAULT '',
- isCommander tinyint(1) NOT NULL DEFAULT '0',
- UNIQUE KEY id (id)
- );";
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
- dbDelta($sql);
- add_option("gw2pcl_database_version", $gw2pcl_database_version);
- }
- /**
- * Uninstall: delete files and database
- */
- function gw2pcl_uninstall() {
- global $wpdb;
- $table_name = $wpdb->prefix . 'gw2pcl';
- $file_list = $wpdb->get_results( '
- SELECT id, picture_file
- FROM $table_name
- WHERE NOT picture_file = ""
- ' );
- foreach ( $file_list as $image_file ) {
- @unlink( $image_file->picture_file );
- $otherpath = pathinfo( $image_file->picture_file );
- @unlink( $otherpath['dirname'] . '/' . $otherpath['filename'] . '-150x200.' . $otherpath['extension'] );
- }
- $wpdb->query( 'DROP TABLE ' . $table_name );
- }
- /**
- * HELPER FUNCTIONS
- * HINT: User strtolower after code outsourcing into it's own files.
- */
- // Define wether the current char is a commander or not and display the commander icon if he is.
- function isCommanderFunction($charName) {
- global $wpdb;
- $table_name = $wpdb->prefix . 'gw2pcl';
- $isCommander = $wpdb->get_var( "SELECT isCommander FROM $table_name WHERE name = '$charName'" );
- if ( $isCommander == '1' )
- return (' <img src="' . plugin_dir_url( __FILE__ ) . 'pics/commander.png" alt="commander" />');
- }
- function get_race( $id ) {
- switch ( $id ) {
- case 1:
- return( __( 'Asura', 'gw2pcl' ) );
- break;
- case 2:
- return( __( 'Charr', 'gw2pcl' ) );
- break;
- case 3:
- return( __( 'Human', 'gw2pcl' ) );
- break;
- case 4:
- return( __( 'Norn', 'gw2pcl' ) );
- break;
- case 5:
- return( __( 'Sylvari', 'gw2pcl' ) );
- break;
- }
- return( __( 'unknown race', 'gw2pcl' ) );
- }
- function get_race_pic( $id ) {
- $pic = "";
- switch ( $id ) {
- case 1:
- $pic .= 'asura';
- break;
- case 2:
- $pic .= 'charr';
- break;
- case 3:
- $pic .= 'human';
- break;
- case 4:
- $pic .= 'norn';
- break;
- case 5:
- $pic .= 'sylvari';
- break;
- }
- return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_race( $id ) . '" />');
- }
- function get_profession( $id ) {
- switch ( $id ) {
- case 1:
- return( __( 'Guardian', 'gw2pcl' ) );
- break;
- case 2:
- return( __( 'Warrior', 'gw2pcl' ) );
- break;
- case 3:
- return( __( 'Engineer', 'gw2pcl' ) );
- break;
- case 4:
- return( __( 'Ranger', 'gw2pcl' ) );
- break;
- case 5:
- return( __( 'Thief', 'gw2pcl' ) );
- break;
- case 6:
- return( __( 'Elementalist', 'gw2pcl' ) );
- break;
- case 7:
- return( __( 'Mesmer', 'gw2pcl' ) );
- break;
- case 8:
- return( __( 'Necromancer', 'gw2pcl' ) );
- break;
- }
- return( __( 'unknown profession', 'gw2pcl' ) );
- }
- function get_profession_pic( $id ) {
- $pic = "";
- switch ( $id ) {
- case 1:
- $pic .= 'guardian';
- break;
- case 2:
- $pic .= 'warrior';
- break;
- case 3:
- $pic .= 'engineer';
- break;
- case 4:
- $pic .= 'ranger';
- break;
- case 5:
- $pic .= 'thief';
- break;
- case 6:
- $pic .= 'elementalist';
- break;
- case 7:
- $pic .= 'mesmer';
- break;
- case 8:
- $pic .= 'necromancer';
- break;
- }
- return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_profession( $id ) . '" />');
- }
- function get_orderCol( $id ) {
- switch ( $id ) {
- case 0:
- return( __( 'No order', 'gw2pcl' ) );
- break;
- case 1:
- return( __( 'Order of Whisperers', 'gw2pcl' ) );
- break;
- case 2:
- return( __( 'Durmand Priory', 'gw2pcl' ) );
- break;
- case 3:
- return( __( 'The Vigil', 'gw2pcl' ) );
- break;
- }
- return( __( 'unknown order', 'gw2pcl' ) );
- }
- function get_orderCol_pic( $id ) {
- $pic = "";
- switch ( $id ) {
- case 1:
- $pic .= 'orderOfWhisperers';
- break;
- case 2:
- $pic .= 'durmandPriory';
- break;
- case 3:
- $pic .= 'theVigil';
- break;
- }
- return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/orders/' . $pic . '.png" alt="' . get_orderCol( $id ) . '" />');
- }
- function get_crafting_skill( $id ) {
- switch ( $id ) {
- case 0:
- return ( __( 'I don\'t craft', 'gw2pcl' ) );
- break;
- case 1:
- return ( __( 'Armorsmith', 'gw2pcl' ) );
- break;
- case 2:
- return ( __( 'Artificer', 'gw2pcl' ) );
- break;
- case 3:
- return ( __( 'Chef', 'gw2pcl' ) );
- break;
- case 4:
- return ( __( 'Huntsman', 'gw2pcl' ) );
- break;
- case 5:
- return ( __( 'Jeweler', 'gw2pcl' ) );
- break;
- case 6:
- return ( __( 'Leatherworker', 'gw2pcl' ) );
- break;
- case 7:
- return ( __( 'Tailor', 'gw2pcl' ) );
- break;
- case 8:
- return ( __( 'Weaponsmith', 'gw2pcl' ) );
- break;
- }
- return ( __( 'unknown crafting skill', 'gw2pcl' ) );
- }
- function get_crafting_skill_pic( $id ) {
- $pic = "";
- switch ( $id ) {
- case 1:
- $pic = 'armorsmith';
- break;
- case 2:
- $pic = 'artificer';
- break;
- case 3:
- $pic = 'chef';
- break;
- case 4:
- $pic = 'huntsman';
- break;
- case 5:
- $pic = 'jeweler';
- break;
- case 6:
- $pic = 'leatherworker';
- break;
- case 7:
- $pic = 'tailor';
- break;
- case 8:
- $pic = 'weaponsmith';
- break;
- }
- return ('<img src="' . plugin_dir_url( __FILE__ ) . 'pics/' . $pic . '.png" alt="' . get_crafting_skill( $id ) . '" />');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment