Changeset 1524886
- Timestamp:
- 10/30/2016 04:48:01 PM (9 years ago)
- Location:
- eve-shipinfo/trunk
- Files:
-
- 8 added
- 11 edited
-
classes/EVEShipInfo.php (modified) (6 diffs)
-
classes/EVEShipInfo/Admin/Page.php (modified) (1 diff)
-
classes/EVEShipInfo/Admin/Page/Main/EFTFittings.php (modified) (1 diff)
-
classes/EVEShipInfo/Admin/UI.php (modified) (1 diff)
-
classes/EVEShipInfo/Admin/UI/Icon.php (modified) (3 diffs)
-
classes/EVEShipInfo/AjaxHandler.php (added)
-
classes/EVEShipInfo/AjaxMethod (added)
-
classes/EVEShipInfo/AjaxMethod.php (added)
-
classes/EVEShipInfo/AjaxMethod/CheckForUpdate.php (added)
-
classes/EVEShipInfo/AjaxMethod/FittingSetVisibility.php (added)
-
classes/EVEShipInfo/EFTManager.php (modified) (1 diff)
-
css/admin.css (modified) (1 diff)
-
errorcodes.txt (modified) (1 diff)
-
images (added)
-
images/spinner.gif (added)
-
js/admin/Admin.js (added)
-
js/admin/Dashboard.js (modified) (1 diff)
-
js/admin/FittingsList.js (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
eve-shipinfo/trunk/classes/EVEShipInfo.php
r1515401 r1524886 42 42 const ERROR_COULD_NOT_CREATE_SQL_STRUCTURE = 1303; 43 43 44 const ERROR_CANNOT_FIND_CLASS_FILE = 1304; 45 44 46 /** 45 47 * The name of the request variable which is used to … … 97 99 98 100 add_action('init', array($this, 'handle_init')); 99 add_action('wp_ajax_eveshipinfo_checkforupdate', array($this, 'ajax_checkForUpdate')); 101 102 $this->handle_initAJAXMethods(); 103 100 104 add_action('admin_init', array($this, 'handle_initPluginSettings')); 101 105 add_action('admin_menu', array($this, 'handle_initAdminMenu')); … … 106 110 107 111 /** 108 * Ajax handler for fetching the database version from the project homepage. 109 */ 110 public function ajax_checkForUpdate() 111 { 112 $url = $this->getHomepageURL().'/api/getDataVersion.php'; 113 114 $result = wp_remote_get($url); 115 116 $state = 'success'; 117 if(is_wp_error($result)) { 118 $state = 'error'; 119 $data = $result->get_error_message(); 120 } else { 121 $code = wp_remote_retrieve_response_code($result); 122 if($code != 200) { 123 $state = 'error'; 124 $data = wp_remote_retrieve_response_message($result); 125 } else { 126 $infoRemote = EVEShipInfo::parseVersion(trim($result['body'])); 127 $infoLocal = EVEShipInfo::parseVersion($this->getDataVersion()); 128 $update = false; 129 if($infoRemote['date'] > $infoLocal['date']) { 130 $update = true; 131 } 132 133 $data = array( 134 'remoteVersion' => $infoRemote['version'], 135 'updateAvailable' => $update, 136 ); 137 } 138 } 139 140 $response = array( 141 'url' => $url, 142 'state' => $state, 143 'data' => $data 144 ); 145 146 echo json_encode($response); 147 wp_die(); 112 * Sets up all AJAX methods available for the plugin, 113 * by checking which are available in the AjaxMethod 114 * classes folder. Adds each as a plugin-specific 115 * AJAX method. 116 */ 117 protected function handle_initAJAXMethods() 118 { 119 $this->loadClass('EVEShipInfo_AjaxHandler'); 120 121 $names = $this->getClassNamesFromFolder($this->getClassesFolder().'/EVEShipInfo/AjaxMethod'); 122 123 foreach($names as $name) { 124 // to avoid having to load the entire ajax class for each method on each request, 125 // we use the lightweight handler, which loads the class on demand. 126 $handler = new EVEShipInfo_AjaxHandler($this, $name); 127 add_action('wp_ajax_eveshipinfo_'.strtolower($name), array($handler, 'execute')); 128 } 148 129 } 149 130 … … 582 563 $this->shortcodeIDs = array(); 583 564 584 $folder = $this->get Dir().'/classes/EVEShipInfo/Shortcode';565 $folder = $this->getClassesFolder().'/EVEShipInfo/Shortcode'; 585 566 if(!file_exists($folder)) { 586 567 return $this->shortcodeIDs; 587 568 } 588 569 570 $this->shortcodeIDs = $this->getClassNamesFromFolder($folder); 571 572 return $this->shortcodeIDs; 573 } 574 575 /** 576 * Retrieves all PHP file names from the specified folder, 577 * without their extensions. 578 * 579 * @param string $folder 580 * @return string[] 581 */ 582 public function getClassNamesFromFolder($folder) 583 { 584 $names = array(); 589 585 $d = new DirectoryIterator($folder); 590 586 foreach($d as $item) { 591 $file = $item->getFilename();592 $ext = pathinfo($file, PATHINFO_EXTENSION);593 if($ext != 'php') {594 continue;595 }596 597 $this->shortcodeIDs[] = str_replace('.php', '', $file);598 } 599 600 return $ this->shortcodeIDs;587 $file = $item->getFilename(); 588 $ext = pathinfo($file, PATHINFO_EXTENSION); 589 if($ext != 'php') { 590 continue; 591 } 592 593 $names[] = str_replace('.php', '', $file); 594 } 595 596 return $names; 601 597 } 602 598 … … 667 663 { 668 664 if(is_admin()) { 669 $this->addScript('admin/FittingsList.js', array('jquery')); 665 $this->addScript('admin/Admin.js', array('jquery')); 666 $this->addScript('admin/FittingsList.js', array('jquery')); 670 667 $this->addScript('admin/Themes.js', array('jquery')); 671 668 $this->addStyle('admin.css'); … … 1015 1012 } 1016 1013 1017 $file = $this->dir.'/classes/'.str_replace('_', '/', $className).'.php'; 1014 $file = $this->getClassesFolder().'/'.str_replace('_', '/', $className).'.php'; 1015 if(!file_exists($file)) { 1016 throw new EVEShipInfo_Exception( 1017 'Class file not found', 1018 sprintf( 1019 'Tried loading the class [%s] from file [%s].', 1020 $className, 1021 $file 1022 ), 1023 self::ERROR_CANNOT_FIND_CLASS_FILE 1024 ); 1025 } 1026 1018 1027 require_once $file; 1028 } 1029 1030 /** 1031 * Retrieves the full path to the plugin's "classes" folder. 1032 * @return string 1033 */ 1034 public function getClassesFolder() 1035 { 1036 return $this->dir.'/classes'; 1019 1037 } 1020 1038 -
eve-shipinfo/trunk/classes/EVEShipInfo/Admin/Page.php
r1296717 r1524886 195 195 $content. 196 196 '</div>'. 197 '</div>'; 198 197 '</div>'. 198 $this->ui->renderJS(); 199 199 200 return $html; 200 201 } -
eve-shipinfo/trunk/classes/EVEShipInfo/Admin/Page/Main/EFTFittings.php
r1512895 r1524886 139 139 '</tr>'; 140 140 } else { 141 foreach($fits as $fit) { 142 $public = $this->ui->icon()->visibilityPrivate()->makeDangerous().' '.__('Private', 'eve-shipinfo'); 143 if($fit->isPublic()) { 144 $public = $this->ui->icon()->visibilityPublic()->makeSuccess().' '.__('Public', 'eve-shipinfo'); 145 } 141 foreach($fits as $fit) 142 { 143 $jsID = EVEShipInfo::nextJSID(); 144 $displayPrivate = 'none'; 145 $displayPublic = 'none'; 146 147 $this->ui->addJSOnload(sprintf( 148 "jQuery('#%s-private, #%s-public').dblclick(function() {FittingsList.ToggleVisibility('%s', '%s');}).addClass('shipinfo-clickable')", 149 $jsID, 150 $jsID, 151 $fit->getID(), 152 $jsID 153 )); 154 155 if($fit->isPublic()) { $displayPublic = 'block'; } 156 if($fit->isPrivate()) { $displayPrivate = 'block'; } 157 158 $public = 159 '<div id="'.$jsID.'-private" class="fit-visibility-toggle" style="display:'.$displayPrivate.'" title="'.__('Double-click to toggle.', 'eve-shipinfo').'">'. 160 $this->ui->icon()->visibilityPrivate() 161 ->makeDangerous(). 162 ' '. 163 __('Private', 'eve-shipinfo'). 164 '</div>'. 165 '<div id="'.$jsID.'-public" class="fit-visibility-toggle" style="display:'.$displayPublic.'" title="'.__('Double-click to toggle.', 'eve-shipinfo').'">'. 166 $this->ui->icon()->visibilityPublic() 167 ->makeSuccess(). 168 ' '. 169 __('Public', 'eve-shipinfo'). 170 '</div>'. 171 '<div id="'.$jsID.'-loading" style="display:none">'. 172 $this->ui->icon()->spinner() 173 ->addClass('spinner-datagrid'). 174 ' '. 175 __('Updating...', 'eve-shipinfo'). 176 '</div>'; 146 177 147 178 $invalid = ''; -
eve-shipinfo/trunk/classes/EVEShipInfo/Admin/UI.php
r1236586 r1524886 97 97 return new EVEShipInfo_Admin_UI_Icon(); 98 98 } 99 100 protected $jsOnload = array(); 101 protected $jsHead = array(); 102 103 /** 104 * Adds a javascript statement intended to be executed on page load. 105 * 106 * @param string $statement 107 * @return EVEShipInfo_Admin_UI 108 */ 109 public function addJSOnload($statement) 110 { 111 $this->jsOnload[] = rtrim(trim($statement), ';'); 112 return $this; 113 } 114 115 /** 116 * Adds a javascript statement intended to to be executed before the page loads. 117 * 118 * @param string $statement 119 * @return EVEShipInfo_Admin_UI 120 */ 121 public function addJSHead($statement) 122 { 123 $this->jsHead[] = rtrim(trim($statement), ';'); 124 return $this; 125 } 126 127 public function renderJS() 128 { 129 if(empty($this->jsOnload) && empty($this->jsHead)) { 130 return ''; 131 } 132 133 $head = $this->jsHead; 134 if(!empty($this->jsOnload)) { 135 $head[] = 'jQuery(document).ready(function() {'.implode(';', $this->jsOnload).';})'; 136 } 137 138 return '<script>'.implode(';', $head).';</script>'; 139 } 99 140 } -
eve-shipinfo/trunk/classes/EVEShipInfo/Admin/UI/Icon.php
r1417468 r1524886 25 25 'LIST_VIEW' => 'list-view', 26 26 'THEME' => 'admin-appearance', 27 'UPDATE' => 'update' 27 'UPDATE' => 'update', 28 'SPINNER' => '_spinner' 28 29 ); 29 30 … … 59 60 public function visibilityPublic() { return $this->setType('VISIBILITY_PUBLIC'); } 60 61 public function visibilityPrivate() { return $this->setType('VISIBILITY_PRIVATE'); } 62 public function spinner() { return $this->setType('SPINNER'); } 61 63 62 64 /** … … 138 140 public function render() 139 141 { 140 $this->setAttribute('class', 'dashicons dashicons-' . self::$types[$this->type] . ' ' . implode(' ', $this->classes)); 142 if($this->type == 'SPINNER') { 143 $this->setAttribute('class', 'shipinfo-spinner'); 144 } else { 145 $this->setAttribute('class', 'dashicons dashicons-' . self::$types[$this->type] . ' ' . implode(' ', $this->classes)); 146 } 141 147 142 148 if(!empty($this->styles)) { -
eve-shipinfo/trunk/classes/EVEShipInfo/EFTManager.php
r1411207 r1524886 276 276 $label = trim($result[2][0]); 277 277 278 $this->load Modules();278 $this->load(); 279 279 280 280 $modules = array(); -
eve-shipinfo/trunk/css/admin.css
r1417468 r1524886 196 196 cursor:zoom-out; 197 197 } 198 199 .shipinfo-spinner{ 200 display:inline-block; 201 background:url(../images/spinner.gif) no-repeat center center; 202 min-width:20px; 203 min-height:20px; 204 line-height:1; 205 vertical-align:top; 206 } 207 208 .shipinfo-clickable{ 209 cursor:pointer; 210 } 211 212 .fit-visibility-toggle.shipinfo-clickable:hover{ 213 color:#0073aa; 214 } -
eve-shipinfo/trunk/errorcodes.txt
r1417468 r1524886 1 1 80011 19001 -
eve-shipinfo/trunk/js/admin/Dashboard.js
r1515401 r1524886 9 9 jQuery('#updatecheck-available').hide(); 10 10 11 jQuery.ajax({ 12 'url':ajaxurl, 13 'data':{ 14 'action':'eveshipinfo_checkforupdate' 15 }, 16 'success':function(data) { 11 EVEShipInfo_Admin.AJAX( 12 'CheckForUpdate', 13 null, 14 function(data) { 17 15 EVEShipInfo_Dashboard.Handle_UpdateCheckSuccess(data); 18 16 }, 19 'error':function(jqXHR, textStatus, errorThrown) { 20 EVEShipInfo_Dashboard.Handle_UpdateCheckFailure(errorThrown); 21 }, 22 'dataType':'json' 23 }); 17 function(errorMessage) { 18 EVEShipInfo_Dashboard.Handle_UpdateCheckFailure(errorMessage); 19 } 20 ); 24 21 }, 25 22 -
eve-shipinfo/trunk/js/admin/FittingsList.js
r1112684 r1524886 15 15 jQuery('.fit-checkbox').prop('checked', true); 16 16 this.allSelected = true; 17 }, 18 19 ToggleVisibility:function(fitID, jsID) 20 { 21 // avoid the text being selected after the doubleclick 22 var sel = window.getSelection(); 23 if(sel) { sel.removeAllRanges(); } 24 25 var elPublic = jQuery('#'+jsID+'-public'); 26 var elPrivate = jQuery('#'+jsID+'-private'); 27 var elLoader = jQuery('#'+jsID+'-loading'); 28 29 var payload = { 30 'fitID':fitID, 31 'changeTo':'private' 32 }; 33 34 if(elPrivate.is(':visible')) { 35 payload.changeTo = 'public'; 36 } 37 38 elPublic.hide(); 39 elPrivate.hide(); 40 elLoader.show(); 41 42 EVEShipInfo_Admin.AJAX( 43 'FittingSetVisibility', 44 payload, 45 function(data) { 46 FittingsList.Handle_ToggleVisibilitySuccess(data, jsID); 47 }, 48 function(errorMessage) { 49 FittingsList.Handle_ToggleVisibilityFailure(errorMessage, payload, jsID); 50 } 51 ); 52 }, 53 54 Handle_ToggleVisibilityFailure:function(errorMessage, payload, jsID) 55 { 56 console.log('ERROR | Could not update visibility | '+errorMessage); 57 58 jQuery('#'+jsID+'-loading').hide(); 59 60 if(payload.changeTo == 'public') { 61 jQuery('#'+jsID+'-private').show(); 62 } else { 63 jQuery('#'+jsID+'-public').show(); 64 } 65 }, 66 67 Handle_ToggleVisibilitySuccess:function(response, jsID) 68 { 69 jQuery('#'+jsID+'-loading').hide(); 70 71 if(response.visibility == 'private') { 72 jQuery('#'+jsID+'-private').show(); 73 } else { 74 jQuery('#'+jsID+'-public').show(); 75 } 17 76 } 18 77 }; -
eve-shipinfo/trunk/readme.txt
r1515807 r1524886 54 54 55 55 = 2.1 = 56 * Added the "mass" filter to the list shortcodes to limit the list by ship mass 56 57 * Added the "ships" filter to the list shortcodes to display specific ships by name or id 57 * Added the "mass" filter to the list shortcodes to limit the list by ship mass 58 * Fixed an error when importing an EFT XML file 59 * Made the EFT fitting visibility toggle-able in the list by double-clicking the icon 60 * Improved the internal handling of Ajax calls for future features 58 61 59 62 = 2.0 =
Note: See TracChangeset
for help on using the changeset viewer.