Changeset 741
- Timestamp:
- 11/08/2012 01:00:53 AM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/wp/transposh_admin.php
r730 r741 28 28 private $localeright = 'right'; 29 29 private $localeleft = 'left'; 30 private $pages = array(); 31 private $contains_settings = false; 30 32 31 33 // constructor of class, PHP4 compatible construction for backward compatibility … … 33 35 $this->transposh = &$transposh; 34 36 // add filter for WordPress 2.8 changed backend box system ! 35 add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2);37 //add_filter('screen_layout_columns', array(&$this, 'on_screen_layout_columns'), 10, 2); 36 38 // add some help 37 add_filter('contextual_help_list', array(&$this, 'on_contextual_help'), 100, 2); 38 // register callback for admin menu setup 39 add_action('admin_menu', array(&$this, 'on_admin_menu')); 39 //add_filter('contextual_help_list', array(&$this, 'on_contextual_help'), 100, 2); 40 // register callback for admin menu setup 41 //add_action('admin_menu', array(&$this, 'on_admin_menu')); 42 add_action('admin_menu', array(&$this, 'admin_menu')); 40 43 // register the callback been used if options of page been submitted and needs to be processed 41 44 add_action('admin_post_save_transposh', array(&$this, 'on_save_changes')); … … 51 54 add_action('wp_ajax_tp_post_phrases', array(&$this, 'on_ajax_tp_post_phrases')); 52 55 add_action('wp_ajax_tp_comment_lang', array(&$this, 'on_ajax_tp_comment_lang')); 56 57 $this->pages = array( 58 'tp_main' => array(__('Dashboard', TRANSPOSH_TEXT_DOMAIN)), 59 'tp_langs' => array(__('Languages', TRANSPOSH_TEXT_DOMAIN)), 60 'tp_settings' => array(__('Settings', TRANSPOSH_TEXT_DOMAIN), '<acronym title="Content Delivery Network">CDN</acronym>'), 61 'tp_engines' => array(__('Translation Engines', TRANSPOSH_TEXT_DOMAIN)), 62 'tp_widget' => array(__('Widgets settings', TRANSPOSH_TEXT_DOMAIN)), 63 'tp_advanced' => array(__('Advanced', TRANSPOSH_TEXT_DOMAIN)), 64 'tp_utils' => array(__('Utilities', TRANSPOSH_TEXT_DOMAIN)), 65 'tp_about' => array(__('About', TRANSPOSH_TEXT_DOMAIN)), 66 'tp_support' => array(__('Support', TRANSPOSH_TEXT_DOMAIN)), 67 ); 53 68 } 54 69 … … 73 88 logger('Enter', 1); 74 89 logger($_POST); 75 $viewable_langs = array(); 76 $editable_langs = array(); 77 78 //update roles and capabilities 79 foreach ($GLOBALS['wp_roles']->get_names() as $role_name => $something) { 80 $role = $GLOBALS['wp_roles']->get_role($role_name); 81 if ($_POST[$role_name] == "1") $role->add_cap(TRANSLATOR); 82 else $role->remove_cap(TRANSLATOR); 83 } 84 85 // anonymous needs to be handled differently as it does not have a role 86 $this->transposh->options->set_anonymous_translation($_POST['anonymous']); 87 88 // first set the default language 89 list ($langcode, $viewable, $translateable) = explode(",", $_POST['languages'][0]); 90 $this->transposh->options->set_default_language($langcode); 91 unset($_POST['languages'][0]); 92 93 // update the list of supported/editable/sortable languages 94 logger($_POST['languages']); 95 foreach ($_POST['languages'] as $code => $lang) { 96 list ($langcode, $viewable, $translateable) = explode(",", $lang); 97 $sorted_langs[$langcode] = $langcode; 98 if ($viewable) { 99 $viewable_langs[$langcode] = $langcode; 100 // force that every viewable lang is editable 101 $editable_langs[$langcode] = $langcode; 90 91 switch ($_POST['page']) { 92 case 'tp_langs': 93 $viewable_langs = array(); 94 $editable_langs = array(); 95 96 //update roles and capabilities 97 foreach ($GLOBALS['wp_roles']->get_names() as $role_name => $something) { 98 $role = $GLOBALS['wp_roles']->get_role($role_name); 99 if ($_POST[$role_name] == "1") $role->add_cap(TRANSLATOR); 100 else $role->remove_cap(TRANSLATOR); 101 } 102 103 // anonymous needs to be handled differently as it does not have a role 104 $this->transposh->options->set_anonymous_translation($_POST['anonymous']); 105 106 // first set the default language 107 list ($langcode, $viewable, $translateable) = explode(",", $_POST['languages'][0]); 108 $this->transposh->options->set_default_language($langcode); 109 unset($_POST['languages'][0]); 110 111 // update the list of supported/editable/sortable languages 112 logger($_POST['languages']); 113 foreach ($_POST['languages'] as $code => $lang) { 114 list ($langcode, $viewable, $translateable) = explode(",", $lang); 115 $sorted_langs[$langcode] = $langcode; 116 if ($viewable) { 117 $viewable_langs[$langcode] = $langcode; 118 // force that every viewable lang is editable 119 $editable_langs[$langcode] = $langcode; 120 } 121 122 if ($translateable) { 123 $editable_langs[$langcode] = $langcode; 124 } 125 } 126 127 $this->transposh->options->set_viewable_langs(implode(',', $viewable_langs)); 128 $this->transposh->options->set_editable_langs(implode(',', $editable_langs)); 129 $this->transposh->options->set_sorted_langs(implode(',', $sorted_langs)); 130 break; 131 case "tp_settings": 132 if ($this->transposh->options->get_enable_permalinks() != $_POST[ENABLE_PERMALINKS]) { 133 $this->transposh->options->set_enable_permalinks($_POST[ENABLE_PERMALINKS]); 134 // rewrite rules - refresh. - because we want them set or unset upon this change 135 // TODO - need to check if its even needed 136 add_filter('rewrite_rules_array', array(&$this->transposh, 'update_rewrite_rules')); 137 $GLOBALS['wp_rewrite']->flush_rules(); 138 } 139 140 $this->transposh->options->set_enable_footer_scripts($_POST[ENABLE_FOOTER_SCRIPTS]); 141 $this->transposh->options->set_enable_detect_language($_POST[ENABLE_DETECT_LANG_AND_REDIRECT]); 142 $this->transposh->options->set_transposh_collect_stats($_POST[TRANSPOSH_COLLECT_STATS]); 143 $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]); 144 $this->transposh->options->set_enable_search_translate($_POST[ENABLE_SEARCH_TRANSLATE]); 145 $this->transposh->options->set_transposh_gettext_integration($_POST[TRANSPOSH_GETTEXT_INTEGRATION]); 146 $this->transposh->options->set_transposh_default_locale_override($_POST[TRANSPOSH_DEFAULT_LOCALE_OVERRIDE]); 147 $this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]); 148 // frontend stuff 149 // handle change of schedule for backup to daily 150 //if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] != $this->transposh->options->get_transposh_backup_schedule()) { 151 wp_clear_scheduled_hook('transposh_backup_event'); 152 if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] == 1 || $_POST[TRANSPOSH_BACKUP_SCHEDULE] == 2) 153 wp_schedule_event(time(), 'daily', 'transposh_backup_event'); 154 //} 155 $this->transposh->options->set_transposh_backup_schedule($_POST[TRANSPOSH_BACKUP_SCHEDULE]); 156 break; 157 case "tp_engines": 158 $this->transposh->options->set_enable_auto_translate($_POST[ENABLE_AUTO_TRANSLATE]); 159 $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]); 160 $this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]); 161 $this->transposh->options->set_google_key($_POST[GOOGLE_TRANSLATE_KEY]); 162 $this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]); 163 $this->transposh->options->set_oht_id($_POST[OHT_TRANSLATE_ID]); 164 $this->transposh->options->set_oht_key($_POST[OHT_TRANSLATE_KEY]); 165 break; 166 case "tp_widget": 167 $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 168 $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 169 $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 170 $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 171 break; 172 case "tp_advanced": 173 $this->transposh->options->set_enable_url_translate($_POST[ENABLE_URL_TRANSLATE]); 174 break; 175 } 176 177 /* 178 */ 179 $this->transposh->options->update_options(); 180 } 181 182 /* // for WordPress 2.8 we have to tell, that we support 2 columns ! 183 function on_screen_layout_columns($columns, $screen) { 184 if ($screen == $this->pagehook) { 185 $columns[$this->pagehook] = 2; 186 } 187 return $columns; 188 } 189 190 //add some help 191 function on_contextual_help($filterVal, $screen) { 192 logger($screen); 193 //if ($screen == 'settings_page_transposh') { 194 $filterVal['settings_page_transposh'] = '<p>' . __('Transposh makes your blog translatable', TRANSPOSH_TEXT_DOMAIN) . '</p>' . 195 '<a href="http://transposh.org/">' . __('Plugin homepage', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>' . 196 '<a href="http://transposh.org/faq/">' . __('Frequently asked questions', TRANSPOSH_TEXT_DOMAIN) . '</a>'; 197 //} 198 return $filterVal; 199 } 200 */ 201 202 function admin_menu() { 203 // First param is page title, second is menu title 204 add_menu_page('Transposh', 'Transposh', 'manage_options', 'tp_main', '', $this->transposh->transposh_plugin_url . "/img/tplogo.png"); 205 206 $submenu_pages = array(); 207 foreach ($this->pages as $slug => $titles) { 208 if (!isset($titles[1])) { 209 array_push($titles, $titles[0]); 102 210 } 103 104 if ($translateable) { 105 $editable_langs[$langcode] = $langcode; 211 $submenu_pages[] = add_submenu_page('tp_main', $titles[0] . ' | Transposh', $titles[1], 'manage_options', $slug, array(&$this, 'options')); 212 } 213 214 if (current_user_can('manage_options')) { 215 /** 216 * Only admin can modify settings 217 */ 218 foreach ($submenu_pages as $submenu_page) { 219 add_action('load-' . $submenu_page, array(&$this, 'load')); 220 add_action('admin_print_styles-' . $submenu_page, array(&$this, 'admin_print_styles')); 221 add_action('admin_print_scripts-' . $submenu_page, array(&$this, 'admin_print_scripts')); 222 // echo $submenu_page; 106 223 } 107 } 108 109 $this->transposh->options->set_viewable_langs(implode(',', $viewable_langs)); 110 $this->transposh->options->set_editable_langs(implode(',', $editable_langs)); 111 $this->transposh->options->set_sorted_langs(implode(',', $sorted_langs)); 112 113 if ($this->transposh->options->get_enable_permalinks() != $_POST[ENABLE_PERMALINKS]) { 114 $this->transposh->options->set_enable_permalinks($_POST[ENABLE_PERMALINKS]); 115 // rewrite rules - refresh. - because we want them set or unset upon this change 116 // TODO - need to check if its even needed 117 add_filter('rewrite_rules_array', array(&$this->transposh, 'update_rewrite_rules')); 118 $GLOBALS['wp_rewrite']->flush_rules(); 119 } 120 121 $this->transposh->options->set_enable_footer_scripts($_POST[ENABLE_FOOTER_SCRIPTS]); 122 $this->transposh->options->set_enable_detect_language($_POST[ENABLE_DETECT_LANG_AND_REDIRECT]); 123 $this->transposh->options->set_transposh_collect_stats($_POST[TRANSPOSH_COLLECT_STATS]); 124 $this->transposh->options->set_enable_auto_translate($_POST[ENABLE_AUTO_TRANSLATE]); 125 $this->transposh->options->set_enable_auto_post_translate($_POST[ENABLE_AUTO_POST_TRANSLATE]); 126 $this->transposh->options->set_enable_default_translate($_POST[ENABLE_DEFAULT_TRANSLATE]); 127 $this->transposh->options->set_enable_search_translate($_POST[ENABLE_SEARCH_TRANSLATE]); 128 $this->transposh->options->set_enable_url_translate($_POST[ENABLE_URL_TRANSLATE]); 129 $this->transposh->options->set_transposh_gettext_integration($_POST[TRANSPOSH_GETTEXT_INTEGRATION]); 130 $this->transposh->options->set_transposh_default_locale_override($_POST[TRANSPOSH_DEFAULT_LOCALE_OVERRIDE]); 131 $this->transposh->options->set_preferred_translator($_POST[PREFERRED_TRANSLATOR]); 132 $this->transposh->options->set_msn_key($_POST[MSN_TRANSLATE_KEY]); 133 $this->transposh->options->set_google_key($_POST[GOOGLE_TRANSLATE_KEY]); 134 $this->transposh->options->set_oht_id($_POST[OHT_TRANSLATE_ID]); 135 $this->transposh->options->set_oht_key($_POST[OHT_TRANSLATE_KEY]); 136 $this->transposh->options->set_transposh_key($_POST[TRANSPOSH_KEY]); 137 // frontend stuff 138 $this->transposh->options->set_widget_progressbar($_POST[WIDGET_PROGRESSBAR]); 139 $this->transposh->options->set_widget_allow_set_default_language($_POST[WIDGET_ALLOW_SET_DEFLANG]); 140 $this->transposh->options->set_widget_remove_logo($_POST[WIDGET_REMOVE_LOGO_FOR_AD]); 141 $this->transposh->options->set_widget_theme($_POST[WIDGET_THEME]); 142 143 // handle change of schedule for backup to daily 144 //if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] != $this->transposh->options->get_transposh_backup_schedule()) { 145 wp_clear_scheduled_hook('transposh_backup_event'); 146 if ($_POST[TRANSPOSH_BACKUP_SCHEDULE] == 1 || $_POST[TRANSPOSH_BACKUP_SCHEDULE] == 2) 147 wp_schedule_event(time(), 'daily', 'transposh_backup_event'); 148 //} 149 $this->transposh->options->set_transposh_backup_schedule($_POST[TRANSPOSH_BACKUP_SCHEDULE]); 150 151 $this->transposh->options->update_options(); 152 } 153 154 // for WordPress 2.8 we have to tell, that we support 2 columns ! 155 function on_screen_layout_columns($columns, $screen) { 156 if ($screen == $this->pagehook) { 157 $columns[$this->pagehook] = 2; 158 } 159 return $columns; 160 } 161 162 //add some help 163 function on_contextual_help($filterVal, $screen) { 164 if ($screen == 'settings_page_transposh') { 165 $filterVal['settings_page_transposh'] = '<p>' . __('Transposh makes your blog translatable', TRANSPOSH_TEXT_DOMAIN) . '</p>' . 166 '<a href="http://transposh.org/">' . __('Plugin homepage', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>' . 167 '<a href="http://transposh.org/faq/">' . __('Frequently asked questions', TRANSPOSH_TEXT_DOMAIN) . '</a>'; 168 } 169 return $filterVal; 170 } 171 172 // extend the admin menu 173 function on_admin_menu() { 174 //add our own option page, you can also add it to different sections or use your own one 175 $this->pagehook = add_options_page(__('Transposh control center', TRANSPOSH_TEXT_DOMAIN), __('Transposh', TRANSPOSH_TEXT_DOMAIN), 'manage_options', TRANSPOSH_ADMIN_PAGE_NAME, array(&$this, 'on_show_page')); 176 // register callback gets call prior your own page gets rendered 177 add_action('load-' . $this->pagehook, array(&$this, 'on_load_page')); 224 225 /** 226 */ 227 /* add_action('admin_notices', array( 228 &$this, 229 'admin_notices' 230 )); */ 231 } 232 // DOC 178 233 add_action('load-edit-comments.php', array(&$this, 'on_load_comments_page')); 179 234 } 180 235 181 function on_load_comments_page() { 182 wp_enqueue_script('transposhcomments', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcommentslang.js', array('jquery'), TRANSPOSH_PLUGIN_VER); 183 } 184 185 // will be executed if wordpress core detects this page has to be rendered 186 function on_load_page() { 187 //ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes 188 wp_enqueue_script('common'); 189 wp_enqueue_script('wp-lists'); 190 wp_enqueue_script('postbox'); 191 192 //TODO - make up my mind on using .css flags here (currently no) 193 //if ($this->transposh->options->get_widget_css_flags()) 194 // wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER); 195 wp_enqueue_script('jquery-ui-droppable'); 196 wp_enqueue_script('transposh_settings', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhsettings.js', array('transposh'), TRANSPOSH_PLUGIN_VER, true); 197 // MAKESURE 3.3+ css 198 // wp_enqueue_script('jquery-ui-progressbar'); 199 200 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 201 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 202 wp_enqueue_script('transposh_backend', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array('transposh'), TRANSPOSH_PLUGIN_VER, true); 203 $script_params = array( 204 'l10n_print_after' => 205 't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 206 't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 207 't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 208 ); 209 wp_localize_script("transposh_backend", "t_be", $script_params); 210 211 //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 212 add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), $this->pagehook, 'side', 'core'); 213 add_meta_box('transposh-sidebox-news', __('Plugin news', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_news_content'), $this->pagehook, 'side', 'core'); 214 add_meta_box('transposh-sidebox-stats', __('Plugin stats', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_stats_content'), $this->pagehook, 'side', 'core'); 215 add_meta_box('transposh-sidebox-translate', __('Translate all', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_translate_content'), $this->pagehook, 'side', 'core'); 216 add_meta_box('transposh-contentbox-languages', __('Supported languages', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_languages_content'), $this->pagehook, 'normal', 'core'); 217 add_meta_box('transposh-contentbox-translation', __('Translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core'); 218 add_meta_box('transposh-contentbox-autotranslation', __('Automatic translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core'); 219 add_meta_box('transposh-contentbox-protranslation', __('Professional translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_professional_translation_content'), $this->pagehook, 'normal', 'core'); 220 add_meta_box('transposh-contentbox-frontend', __('Frontend settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_frontend_content'), $this->pagehook, 'normal', 'core'); 221 add_meta_box('transposh-contentbox-general', __('Generic settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core'); 222 add_meta_box('transposh-contentbox-database', __('Database maintenance', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core'); 223 } 224 225 //executed to show the plugins complete admin page 226 function on_show_page() { 236 /** 237 * Print styles 238 * 239 * @return void 240 */ 241 function admin_print_styles() { 242 243 } 244 245 /** 246 * Print scripts 247 * 248 * @return void 249 */ 250 function admin_print_scripts() { 251 switch ($_GET['page']) { 252 case 'tp_main': 253 wp_enqueue_script('common'); 254 wp_enqueue_script('wp-lists'); 255 wp_enqueue_script('postbox'); 256 break; 257 case 'tp_langs': 258 wp_enqueue_script('jquery-ui-droppable'); 259 wp_enqueue_script('transposh_settings', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhsettings.js', array('transposh'), TRANSPOSH_PLUGIN_VER, true); 260 // MAKESURE 3.3+ css 261 // wp_enqueue_script('jquery-ui-progressbar'); 262 263 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 264 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 265 break; 266 } 267 } 268 269 function load() { 270 // figure out page and other stuff... 271 //echo 'loaded!?'; 227 272 global $wp_locale; 228 273 if ($wp_locale->text_direction == 'rtl') { … … 231 276 } 232 277 278 $screen = get_current_screen(); 279 $screen->add_help_tab(array( 280 'id' => 'additional-help-page-one', // This should be unique for the screen. 281 'title' => 'Your Tab Title', 282 // retrieve the function output and set it as tab content 283 'content' => 'wptuts_options_page_contextual_help()')); 284 // $screen->add_option( 'layout_columns', array('max' => 2 ) ); 285 add_screen_option('layout_columns', array('max' => 4, 'default' => 2)); 286 if ($_GET['page'] == 'tp_main') { 287 add_meta_box('transposh-sidebox-about', __('About this plugin', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_about_content'), '', 'side', 'core'); 288 add_meta_box('transposh-sidebox-news', __('Plugin news', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_news_content'), '', 'normal', 'core'); 289 add_meta_box('transposh-sidebox-stats', __('Plugin stats', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_stats_content'), '', 'column3', 'core'); 290 // add_meta_box('transposh-contentbox-community', __('Transposh community features', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_community_content'), '', 'normal', 'core'); 291 } 292 } 293 294 function options() { 295 echo '<div class="wrap">'; 296 echo '<form action="admin-post.php" method="post">'; 297 echo '<input type="hidden" name="action" value="save_transposh"/>'; 298 echo '<input type="hidden" name="page" value="' . $_GET['page'] . '"/>'; 299 echo wp_nonce_field(TR_NONCE); 300 screen_icon('options-general'); 301 //screen_icon(); 302 echo '<h2 class="nav-tab-wrapper">'; 303 foreach ($this->pages as $slug => $titles) { 304 $active = ($slug === $_GET['page']) ? ' nav-tab-active' : ''; 305 echo '<a href="admin.php?page=' . $slug . '" class="nav-tab' . $active . '">'; 306 echo esc_html($titles[0]); 307 echo '</a>'; 308 } 309 echo '</h2>'; 310 311 312 //switch ($_GET['page']) { 313 /* case 'tp_langs': 314 $this->tp_langs(); 315 break; 316 case 'tp_auto': 317 $this->tp_auto(); 318 break; 319 case 'tp_pro': 320 $this->tp_pro(); 321 break; */ 322 // } 323 call_user_func(array(&$this, $_GET['page'])); 324 /* echo 'loaded!?'; 325 add_meta_box('transposh-contentbox-languages', __('Supported languages', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_languages_content'), 'toplevel_page_tp_main', 'normal', 'core'); 326 do_meta_boxes('toplevel_page_tp_main', 'normal', ''); */ 327 328 if ($this->contains_settings) { 329 echo '<p>'; 330 echo'<input type="submit" value="' . esc_attr('Save Changes') . '" class="button-primary" name="Submit"/>'; 331 echo'</p>'; 332 } 333 334 echo '</div>'; 335 } 336 337 // extend the admin menu 338 // function on_admin_menu() { 339 //add our own option page, you can also add it to different sections or use your own one 340 // $this->pagehook = add_options_page(__('Transposh control center', TRANSPOSH_TEXT_DOMAIN), __('Transposh', TRANSPOSH_TEXT_DOMAIN), 'manage_options', TRANSPOSH_ADMIN_PAGE_NAME, array(&$this, 'on_show_page')); 341 // register callback gets call prior your own page gets rendered 342 // add_action('load-' . $this->pagehook, array(&$this, 'on_load_page')); 343 // } 344 345 function on_load_comments_page() { 346 wp_enqueue_script('transposhcomments', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhcommentslang.js', array('jquery'), TRANSPOSH_PLUGIN_VER); 347 } 348 349 // will be executed if wordpress core detects this page has to be rendered 350 /* function on_load_page() { 351 logger('here'); 352 //ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes 353 //TODO - make up my mind on using .css flags here (currently no) 354 //if ($this->transposh->options->get_widget_css_flags()) 355 // wp_enqueue_style("transposh_flags",$this->transposh->transposh_plugin_url."/widgets/flags/tpw_flags.css",array(),TRANSPOSH_PLUGIN_VER); 356 wp_enqueue_script('transposh_settings', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhsettings.js', array('transposh'), TRANSPOSH_PLUGIN_VER, true); 357 // MAKESURE 3.3+ css 358 // wp_enqueue_script('jquery-ui-progressbar'); 359 360 wp_enqueue_style('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/themes/ui-lightness/jquery-ui.css', array(), JQUERYUI_VER); 361 wp_enqueue_script('jqueryui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/' . JQUERYUI_VER . '/jquery-ui.min.js', array('jquery'), JQUERYUI_VER, true); 362 wp_enqueue_script('transposh_backend', $this->transposh->transposh_plugin_url . '/' . TRANSPOSH_DIR_JS . '/transposhbackend.js', array('transposh'), TRANSPOSH_PLUGIN_VER, true); 363 $script_params = array( 364 'l10n_print_after' => 365 't_be.g_langs = ' . json_encode(transposh_consts::$google_languages) . ';' . 366 't_be.m_langs = ' . json_encode(transposh_consts::$bing_languages) . ';' . 367 't_be.a_langs = ' . json_encode(transposh_consts::$apertium_languages) . ';' 368 ); 369 wp_localize_script("transposh_backend", "t_be", $script_params); 370 371 //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore 372 add_meta_box('transposh-sidebox-translate', __('Translate all', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_sidebox_translate_content'), $this->pagehook, 'side', 'core'); 373 add_meta_box('transposh-contentbox-languages', __('Supported languages', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_languages_content'), $this->pagehook, 'normal', 'core'); 374 add_meta_box('transposh-contentbox-translation', __('Translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_translation_content'), $this->pagehook, 'normal', 'core'); 375 add_meta_box('transposh-contentbox-autotranslation', __('Automatic translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_auto_translation_content'), $this->pagehook, 'normal', 'core'); 376 add_meta_box('transposh-contentbox-protranslation', __('Professional translation settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_professional_translation_content'), $this->pagehook, 'normal', 'core'); 377 add_meta_box('transposh-contentbox-frontend', __('Frontend settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_frontend_content'), $this->pagehook, 'normal', 'core'); 378 add_meta_box('transposh-contentbox-general', __('Generic settings', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_generic_content'), $this->pagehook, 'normal', 'core'); 379 add_meta_box('transposh-contentbox-database', __('Database maintenance', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_database_content'), $this->pagehook, 'normal', 'core'); 380 } 381 */ 382 //executed to show the plugins complete admin page 383 function tp_main() { 384 385 233 386 //we need the global screen column value to beable to have a sidebar in WordPress 2.8 234 387 //global $screen_layout_columns; 235 388 //add a 3rd content box now for demonstration purpose, boxes added at start of page rendering can't be switched on/off, 236 389 //may be needed to ensure that a special box is always available 237 add_meta_box('transposh-contentbox-community', __('Transposh community features', TRANSPOSH_TEXT_DOMAIN), array(&$this, 'on_contentbox_community_content'), $this->pagehook, 'normal', 'core');238 390 //define some data can be given to each metabox during rendering - not used now 239 391 //$data = array('My Data 1', 'My Data 2', 'Available Data 1'); 240 241 echo '<div id="transposh-general" class="wrap">'; 242 screen_icon('options-general'); 243 echo '<h2>' . __('Transposh', TRANSPOSH_TEXT_DOMAIN) . '</h2>' . 244 '<form action="admin-post.php" method="post">'; 245 392 //echo '<div id="transposh-general" class="wrap">'; 393 //screen_icon('options-general'); 394 //echo '<h2>' . __('Transposh', TRANSPOSH_TEXT_DOMAIN) . '</h2>' . 246 395 // add some user warnings that leads to some FAQs 247 396 if ((int) ini_get('memory_limit') < 64) { … … 253 402 } 254 403 255 wp_nonce_field(TR_NONCE); 256 wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); 257 wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); 258 259 echo '<input type="hidden" name="action" value="save_transposh" />' . 260 '<div id="poststuff" class="metabox-holder' . ((2 == $GLOBALS['screen_layout_columns']) ? ' has-right-sidebar' : '') . '">' . 261 '<div id="side-info-column" class="inner-sidebar">'; 262 do_meta_boxes($this->pagehook, 'side', ''); 263 264 echo '</div>' . 265 '<div id="post-body" class="has-sidebar">' . 266 '<div id="post-body-content" class="has-sidebar-content"> '; 267 268 do_meta_boxes($this->pagehook, 'normal', ''); 269 /* Maybe add static content here later */ 270 //do_meta_boxes($this->pagehook, 'additional', $data); 271 272 echo '<p>' . 273 '<input type="submit" value="' . __('Save Changes') . '" class="button-primary" name="Submit"/>' . 274 '</p>' . 275 '</div>' . 276 '</div>' . 277 '<br class="clear"/>' . 278 '</div>' . 279 '</form>' . 280 '</div>' . 281 '<script type="text/javascript">' . "\n" . 282 '//<![CDATA[' . "\n" . 283 'jQuery(document).ready( function($) {'; 284 // close postboxes that should be closed 285 echo "$('.if-js-closed').removeClass('if-js-closed').addClass('closed');"; 286 // postboxes setup 287 echo "postboxes.add_postbox_toggles('" . $this->pagehook . "');" . 288 '}); ' . "\n" . 289 '//]]>' . "\n" . 290 '</script>'; 291 } 292 293 // executed if the post arrives initiated by pressing the submit button of form 294 function on_save_changes() { 295 //user permission check 296 if (!current_user_can('manage_options')) 297 wp_die(__('Problems?', TRANSPOSH_TEXT_DOMAIN)); 298 // cross check the given referer 299 check_admin_referer(TR_NONCE); 300 301 // process here your on $_POST validation and / or option saving 302 $this->update_admin_options(); 303 304 // lets redirect the post request into get request (you may add additional params at the url, if you need to show save results 305 $this->transposh->tp_redirect($_POST['_wp_http_referer']); 306 } 307 308 // below you will find for each registered metabox the callback method, that produces the content inside the boxes 309 // i did not describe each callback dedicated, what they do can be easily inspected and compare with the admin page displayed 310 311 function on_sidebox_about_content($data) { 312 echo '<ul style="list-style-type:disc;margin-' . $this->localeleft . ':20px;">'; 313 echo '<li><a href="http://transposh.org/">' . __('Plugin Homepage', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 314 echo '<li><a href="http://transposh.org/redir/newfeature">' . __('Suggest a Feature', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 315 // support Forum 316 echo '<li><a href="http://transposh.org/redir/newticket">' . __('Report a Bug', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 317 // donate with PayPal 318 echo '</ul>'; 319 } 320 321 function on_sidebox_news_content($data) { 322 echo '<div style="margin:6px">'; 323 wp_widget_rss_output('http://feeds2.feedburner.com/transposh', array('items' => 5)); 324 echo '</div>'; 325 } 326 327 function on_sidebox_stats_content($data) { 328 $this->transposh->database->db_stats(); 329 } 330 331 function on_sidebox_translate_content($data) { 332 echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>'; 333 echo '<div id="tr_loading" style="margin: 0 0 10px 0">' . __('Translate by clicking the button below', TRANSPOSH_TEXT_DOMAIN) . '</div>'; 334 echo '<div id="tr_allmsg" style="margin: 0 0 10px 0"></div>'; 335 echo '<a id="transposh-translate" href="#" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 336 //get_posts 404 echo '<div id="dashboard-widgets-wrap">'; 405 406 /** Load WordPress dashboard API */ 407 require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); 408 409 wp_enqueue_script('dashboard'); 410 //wp_enqueue_script( 'plugin-install' ); 411 //wp_enqueue_script( 'media-upload' ); 412 wp_admin_css('dashboard'); 413 //wp_admin_css( 'plugin-install' ); 414 add_thickbox(); 415 416 add_screen_option('layout_columns', array('max' => 4, 'default' => 2)); 417 418 wp_dashboard(); 419 420 echo '<div class="clear"></div>'; 421 422 // wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); 423 // wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); 424 // 425 // '<div id="poststuff" class="metabox-holder' . ((2 == $GLOBALS['screen_layout_columns']) ? ' has-right-sidebar' : '') . '">' . 426 // '<div id="side-info-column" class="inner-sidebar">'; 427 //// do_meta_boxes($this->pagehook, 'side', ''); 428 // 429 // echo '</div>' . 430 //// do_meta_boxes($this->pagehook, 'side', ''); 431 // '<div id="post-body" class="has-sidebar">' . 432 // '<div id="post-body-content" class="has-sidebar-content"> '; 433 // 434 //// do_meta_boxes($this->pagehook, 'normal', ''); 435 // /* Maybe add static content here later */ 436 // //do_meta_boxes($this->pagehook, 'additional', $data); 437 // 438 // echo '<p>' . 439 // '<input type="submit" value="' . __('Save Changes') . '" class="button-primary" name="Submit"/>' . 440 // '</p>' . 441 // '</div>' . 442 // '</div>' . 443 // '<br class="clear"/>' . 444 // '</div>' . 445 // '</form>' . 446 // '</div>' . 447 // '<script type="text/javascript">' . "\n" . 448 // '//<![CDATA[' . "\n" . 449 // 'jQuery(document).ready( function($) {'; 450 // // close postboxes that should be closed 451 // echo "$('.if-js-closed').removeClass('if-js-closed').addClass('closed');"; 452 // // postboxes setup 453 // echo "postboxes.add_postbox_toggles('" . $this->pagehook . "');" . 454 // '}); ' . "\n" . 455 // '//]]>' . "\n" . 456 // '</script>'; 337 457 } 338 458 … … 341 461 * @param string $data 342 462 */ 343 function on_contentbox_languages_content($data) { 463 function tp_langs() { 464 $this->contains_settings = true; 344 465 // we need some styles 345 466 echo '<style type="text/css"> … … 388 509 // this is the default language location 389 510 list ($langname, $langorigname, $flag) = explode(",", transposh_consts::$languages[$this->transposh->options->get_default_language()]); 390 echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;">' . __('Default Language (drag another language here to make it default)', TRANSPOSH_TEXT_DOMAIN); 391 echo '<ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">' 511 echo '<div id="default_lang" style="overflow:auto;padding-bottom:10px;"><h3>'; 512 echo __('Default Language (drag another language here to make it default)', TRANSPOSH_TEXT_DOMAIN); 513 echo '</h3><ul id="default_list"><li id="' . $this->transposh->options->get_default_language() . '" class="languages">' 392 514 . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, $langorigname, false/* $this->transposh->options->get_widget_css_flags() */) 393 515 . '<input type="hidden" name="languages[]" value="' . $this->transposh->options->get_default_language() . '" />' … … 395 517 echo '</ul></div>'; 396 518 // list of languages 397 echo '<div style="overflow:auto; clear: both;">' . __('Available Languages (Click to toggle language state - Drag to sort in the widget)', TRANSPOSH_TEXT_DOMAIN); 398 echo '<ul id="sortable">'; 519 echo '<div style="overflow:auto; clear: both;"><h3>'; 520 echo __('Available Languages (Click to toggle language state - Drag to sort in the widget)', TRANSPOSH_TEXT_DOMAIN); 521 echo '</h3><ul id="sortable">'; 399 522 foreach ($this->transposh->options->get_sorted_langs() as $langcode => $langrecord) { 400 523 list ($langname, $langorigname, $flag) = explode(",", $langrecord); … … 402 525 . (!$this->transposh->options->is_viewable_language($langcode) && $this->transposh->options->is_editable_language($langcode) ? "translateable" : "") . '"><div style="float:' . $this->localeleft . '">' 403 526 . transposh_utils::display_flag("{$this->transposh->transposh_plugin_url}/img/flags", $flag, false /* $langorigname,$this->transposh->options->get_widget_css_flags() */) 404 . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_viewable_language($langcode) ? ",t" : ",") . '" />' 527 // DOC THIS BUGBUG fix! 528 . '<input type="hidden" name="languages[]" value="' . $langcode . ($this->transposh->options->is_viewable_language($langcode) ? ",v" : ",") . ($this->transposh->options->is_editable_language($langcode) ? ",t" : ",") . '" />' 405 529 . ' <span class="langname">' . $langorigname . '</span><span class="langname hidden">' . $langname . '</span></div>'; 406 530 if (in_array($langcode, transposh_consts::$google_languages)) … … 427 551 } 428 552 429 /** 430 * uses a boolean expression to make checkboxes check 431 * @param boolean $eval 432 * @return string used for checkboxes 433 */ 434 private function checked($eval) { 435 return $eval ? 'checked="checked"' : ''; 436 } 437 438 private function checkbox($id, $value, $head, $text) { 439 echo '<h4>' . $head . '</h4>'; 440 echo '<input type="checkbox" value="1" name="' . $id . '" ' . $this->checked($value) . '/> ' . $text; 441 } 442 443 function on_contentbox_translation_content($data) { 553 // Show normal settings 554 function tp_settings() { 555 $this->contains_settings = true; 556 557 echo '<h2>' . __('Translation related settings', TRANSPOSH_TEXT_DOMAIN) . '</h2>'; 558 echo '<div class="col-wrap">'; 444 559 /* 445 560 * Insert permissions section in the admin page 446 561 */ 447 echo '<h 4>' . __('Who can translate ?', TRANSPOSH_TEXT_DOMAIN) . '</h4>';562 echo '<h3>' . __('Who can translate ?', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 448 563 //display known roles and their permission to translate 449 564 foreach ($GLOBALS['wp_roles']->get_names() as $role_name => $something) { … … 467 582 $this->checkbox(ENABLE_SEARCH_TRANSLATE, $this->transposh->options->get_enable_search_translate(), __('Enable search in translated languages', TRANSPOSH_TEXT_DOMAIN), __('Allow search of translated languages (and the original language)', TRANSPOSH_TEXT_DOMAIN)); 468 583 469 /**470 * Insert the option to enable translation of urls471 * Disbaled by default.472 * @since 0.5.3473 */474 $this->checkbox(ENABLE_URL_TRANSLATE, $this->transposh->options->get_enable_url_translate(), __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN));475 584 476 585 /** … … 479 588 * @since 0.6.4 480 589 */ 481 $this->checkbox(TRANSPOSH_GETTEXT_INTEGRATION, $this->transposh->options->get_transposh_gettext_integration(), __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN), __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN));590 $this->checkbox(TRANSPOSH_GETTEXT_INTEGRATION, $this->transposh->options->get_transposh_gettext_integration(), __('Enable gettext integration', TRANSPOSH_TEXT_DOMAIN), __('Enable integration of Transposh with existing gettext interface (.po/.mo files)', TRANSPOSH_TEXT_DOMAIN)); 482 591 483 592 /** … … 487 596 */ 488 597 $this->checkbox(TRANSPOSH_DEFAULT_LOCALE_OVERRIDE, $this->transposh->options->get_transposh_default_locale_override(), __('Enable override for default locale', TRANSPOSH_TEXT_DOMAIN), __('Enable overriding the default locale that is set in WP_LANG on default languages pages (such as untranslated pages and admin pages)', TRANSPOSH_TEXT_DOMAIN)); 489 } 490 491 function on_contentbox_auto_translation_content($data) { 492 598 echo '</div>'; 599 echo '<h2>' . __('General settings', TRANSPOSH_TEXT_DOMAIN) . '</h2>'; 600 echo '<div class="col-wrap">'; 601 /* 602 * Insert the option to enable/disable rewrite of perlmalinks. 603 * When disabled only parameters will be used to identify the current language. 604 */ 605 $this->checkbox(ENABLE_PERMALINKS, $this->transposh->options->get_enable_permalinks(), __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN), __('Rewrite URLs to be search engine friendly, ' . 606 'e.g. (http://transposh.org/<strong>en</strong>). ' . 607 'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN)); 608 609 /* 610 * Insert the option to enable/disable pushing of scripts to footer. 611 * Works on wordpress 2.8 and up (but we no longer care...) 612 */ 613 $this->checkbox(ENABLE_FOOTER_SCRIPTS, $this->transposh->options->get_enable_footer_scripts(), __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN), __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 614 'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN)); 615 616 /** 617 * Insert the option to enable/disable language auto-detection 618 * @since 0.3.8 */ 619 $this->checkbox(ENABLE_DETECT_LANG_AND_REDIRECT, $this->transposh->options->get_enable_detect_language(), __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN), __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 620 'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN)); 621 622 /** 623 * Insert the option to enable/disable statics collection 624 * @since 0.7.6 */ 625 $this->checkbox(TRANSPOSH_COLLECT_STATS, $this->transposh->options->get_transposh_collect_stats(), __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN), __('This option enables collection of statistics by transposh that will be used to improve the product.', TRANSPOSH_TEXT_DOMAIN)); 626 627 /* WIP2 628 echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>'; */ 629 echo '</div>'; 630 echo '<h2>' . __('Backup service settings', TRANSPOSH_TEXT_DOMAIN) . '</h2>'; 631 echo '<div class="col-wrap">'; 632 echo '<input type="radio" value="1" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>' . __('Enable daily backup', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 633 echo '<input type="radio" value="2" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 2) . '/>' . __('Enable live backup', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 634 echo '<input type="radio" value="0" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 0) . '/>' . __('Disable backup (Can be run manually by clicking the button below)', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 635 echo __('Service Key:', TRANSPOSH_TEXT_DOMAIN) . ' <input type="text" size="32" class="regular-text" value="' . $this->transposh->options->get_transposh_key() . '" id="' . TRANSPOSH_KEY . '" name="' . TRANSPOSH_KEY . '"/> <a target="_blank" href="http://transposh.org/faq/#restore">' . __('How to restore?', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 636 echo '</div>'; 637 } 638 639 function tp_engines() { 640 $this->contains_settings = true; 641 642 echo '<h2>Automatic Translation Settings</h2>'; 643 echo '<div class="col-wrap">'; 493 644 /* 494 645 * Insert the option to enable/disable automatic translation. … … 506 657 * Allow users to insert their own API keys 507 658 */ 508 echo '<h 4>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/bingicon.png\"> " . __('MSN API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>';659 echo '<h3>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/bingicon.png\"> " . __('MSN API key', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 509 660 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_msn_key() . '" id="' . MSN_TRANSLATE_KEY . '" name="' . MSN_TRANSLATE_KEY . '"/>'; 510 661 … … 512 663 * Allow users to insert their own API keys 513 664 */ 514 echo '<h 4>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/googleicon.png\"> " . __('Google API key', TRANSPOSH_TEXT_DOMAIN) . '</h4>';665 echo '<h3>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/googleicon.png\"> " . __('Google API key', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 515 666 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_google_key() . '" id="' . GOOGLE_TRANSLATE_KEY . '" name="' . GOOGLE_TRANSLATE_KEY . '"/>'; 516 667 … … 518 669 * Choose default translator... TODO (explain better in wiki) 519 670 */ 520 echo '<h 4>' . __('Select preferred auto translation engine', TRANSPOSH_TEXT_DOMAIN) . '</h4>';671 echo '<h3>' . __('Select preferred auto translation engine', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 521 672 echo '<label for="' . PREFERRED_TRANSLATOR . '">' . __('Translation engine:', TRANSPOSH_TEXT_DOMAIN) . 522 673 '<select name="' . PREFERRED_TRANSLATOR . '">' . … … 525 676 '</select>' . 526 677 '</label>'; 527 } 528 529 function on_contentbox_professional_translation_content($data) { 678 echo '</div>'; 679 680 echo '<h2>Professional Translation Settings</h2>'; 681 echo '<div class="col-wrap">'; 682 530 683 echo __('<a href="http://transposh.org/redir/oht">One Hour Translation</a>, is the largest professional translation service online, with thousands of business customers, including 57% of the Fortune 500 companies, and over 15000 translators worldwide.', TRANSPOSH_TEXT_DOMAIN); 531 684 echo '<br/>'; 532 685 echo __('One Hour Translation provides high-quality, fast professional translation to/from any language, and has specific domain expertise in SW localization, technical, business, and legal translations.', TRANSPOSH_TEXT_DOMAIN); 533 echo '<h 4>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/ohticon.png\"> " . __('One Hour Translation account ID', TRANSPOSH_TEXT_DOMAIN) . '</h4>';686 echo '<h3>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/ohticon.png\"> " . __('One Hour Translation account ID', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 534 687 echo __('Account ID', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_oht_id() . '" id="' . OHT_TRANSLATE_ID . '" name="' . OHT_TRANSLATE_ID . '"/>'; 535 688 … … 537 690 * Allow users to insert their own API keys 538 691 */ 539 echo '<h 4>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/ohticon.png\"> " . __('One Hour Translation secret key', TRANSPOSH_TEXT_DOMAIN) . '</h4>';692 echo '<h3>' . "<img src=\"{$this->transposh->transposh_plugin_url}/img/ohticon.png\"> " . __('One Hour Translation secret key', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 540 693 echo __('API Key', TRANSPOSH_TEXT_DOMAIN) . ': <input type="text" size="35" class="regular-text" value="' . $this->transposh->options->get_oht_key() . '" id="' . OHT_TRANSLATE_KEY . '" name="' . OHT_TRANSLATE_KEY . '"/>'; 541 694 … … 544 697 $timeforevent = floor((max(array(wp_next_scheduled('transposh_oht_event') - time(), 0))) / 60); 545 698 if ((max(array(wp_next_scheduled('transposh_oht_event') - time(), 0)))) { 546 printf('<h 4>' . __('%d Phrases currently queued for next job in ~%d minutes', TRANSPOSH_TEXT_DOMAIN) . '</h4>', sizeof($oht), $timeforevent);699 printf('<h3>' . __('%d Phrases currently queued for next job in ~%d minutes', TRANSPOSH_TEXT_DOMAIN) . '</h3>', sizeof($oht), $timeforevent); 547 700 } 548 701 } 549 702 $ohtp = get_option(TRANSPOSH_OPTIONS_OHT_PROJECTS, array()); 550 703 if (!empty($ohtp)) { 551 printf('<h4>' . __('%d projects have been submitted and waiting for completion', TRANSPOSH_TEXT_DOMAIN) . '</h4>', sizeof($ohtp)); 552 } 553 } 554 555 function on_contentbox_frontend_content($data) { 704 printf('<h3>' . __('%d projects have been submitted and waiting for completion', TRANSPOSH_TEXT_DOMAIN) . '</h3>', sizeof($ohtp)); 705 } 706 echo '</div>'; 707 } 708 709 function tp_widget() { 710 $this->contains_settings = true; 711 556 712 $this->checkbox(WIDGET_PROGRESSBAR, $this->transposh->options->get_widget_progressbar(), __('Show progress bar', TRANSPOSH_TEXT_DOMAIN), __('Show progress bar when a client triggers automatic translation', TRANSPOSH_TEXT_DOMAIN)); 557 713 … … 560 716 $this->checkbox(WIDGET_REMOVE_LOGO_FOR_AD, $this->transposh->options->get_widget_remove_logo(), __('Remove transposh logo (see <a href="http://transposh.org/logoterms">terms</a>)', TRANSPOSH_TEXT_DOMAIN), __('Transposh logo will not appear on widget', TRANSPOSH_TEXT_DOMAIN)); 561 717 562 echo '<h 4>' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '</h4>';718 echo '<h3>' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . '</h3>'; 563 719 echo '<label for="' . WIDGET_THEME . '">' . __('Edit interface (and progress bar) theme:', TRANSPOSH_TEXT_DOMAIN) . 564 720 '<select id="transposh-style" name="' . WIDGET_THEME . '">'; … … 571 727 } 572 728 573 function on_contentbox_generic_content($data) { 574 /* 575 * Insert the option to enable/disable rewrite of perlmalinks. 576 * When disabled only parameters will be used to identify the current language. 577 */ 578 $this->checkbox(ENABLE_PERMALINKS, $this->transposh->options->get_enable_permalinks(), __('Rewrite URLs', TRANSPOSH_TEXT_DOMAIN), __('Rewrite URLs to be search engine friendly, ' . 579 'e.g. (http://transposh.org/<strong>en</strong>). ' . 580 'Requires that permalinks will be enabled.', TRANSPOSH_TEXT_DOMAIN)); 581 582 /* 583 * Insert the option to enable/disable pushing of scripts to footer. 584 * Works on wordpress 2.8 and up (but we no longer care...) 585 */ 586 $this->checkbox(ENABLE_FOOTER_SCRIPTS, $this->transposh->options->get_enable_footer_scripts(), __('Add scripts to footer', TRANSPOSH_TEXT_DOMAIN), __('Push transposh scripts to footer of page instead of header, makes pages load faster. ' . 587 'Requires that your theme should have proper footer support.', TRANSPOSH_TEXT_DOMAIN)); 588 729 function tp_advanced() { 730 $this->contains_settings = true; 589 731 /** 590 * Insert the option to enable/disable language auto-detection 591 * @since 0.3.8 */ 592 $this->checkbox(ENABLE_DETECT_LANG_AND_REDIRECT, $this->transposh->options->get_enable_detect_language(), __('Auto detect language for users', TRANSPOSH_TEXT_DOMAIN), __('This enables auto detection of language used by the user as defined in the ACCEPT_LANGUAGES they send. ' . 593 'This will redirect the first page accessed in the session to the same page with the detected language.', TRANSPOSH_TEXT_DOMAIN)); 594 595 /** 596 * Insert the option to enable/disable statics collection 597 * @since 0.7.6 */ 598 $this->checkbox(TRANSPOSH_COLLECT_STATS, $this->transposh->options->get_transposh_collect_stats(), __('Allow collecting usage statistics', TRANSPOSH_TEXT_DOMAIN), __('This option enables collection of statistics by transposh that will be used to improve the product.', TRANSPOSH_TEXT_DOMAIN)); 599 600 /* WIP2 601 echo '<a href="http://transposh.org/services/index.php?flags='.$flags.'">Gen sprites</a>'; */ 602 } 603 604 function on_contentbox_database_content($data) { 732 * Insert the option to enable translation of urls 733 * Disbaled by default. 734 * @since 0.5.3 735 */ 736 $this->checkbox(ENABLE_URL_TRANSLATE, $this->transposh->options->get_enable_url_translate(), __('Enable url translation', TRANSPOSH_TEXT_DOMAIN) . ' (' . __('experimental', TRANSPOSH_TEXT_DOMAIN) . ')', __('Allow translation of permalinks and urls', TRANSPOSH_TEXT_DOMAIN)); 737 } 738 739 // 740 function tp_utils() { 741 echo '<div id="backup_result"></div>'; 742 echo '<div style="margin:10px 0"><a id="transposh-backup" href="#" class="button">' . __('Do Backup Now', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 743 605 744 /* 606 745 * Insert buttons allowing removal of automated translations from database and maintenence … … 609 748 echo '<div style="margin:10px 0"><a id="transposh-clean-auto14" href="#" nonce="' . wp_create_nonce('transposh-clean') . '" class="button">' . __('Delete automated translations older than 14 days', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 610 749 echo '<div style="margin:10px 0"><a id="transposh-maint" href="#" nonce="' . wp_create_nonce('transposh-clean') . '" class="button">' . __('Attempt to fix errors caused by previous versions - please backup first', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 611 } 612 613 function on_contentbox_community_content($data) { 614 echo '<h4>' . __('Backup service for human translation', TRANSPOSH_TEXT_DOMAIN) . '</h4>'; 615 echo '<input type="radio" value="1" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 1) . '/>' . __('Enable daily backup', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 616 echo '<input type="radio" value="2" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 2) . '/>' . __('Enable live backup', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 617 echo '<input type="radio" value="0" name="' . TRANSPOSH_BACKUP_SCHEDULE . '" ' . $this->checked($this->transposh->options->get_transposh_backup_schedule() == 0) . '/>' . __('Disable backup (Can be run manually by clicking the button below)', TRANSPOSH_TEXT_DOMAIN) . '<br/>'; 618 echo __('Service Key:', TRANSPOSH_TEXT_DOMAIN) . ' <input type="text" size="32" class="regular-text" value="' . $this->transposh->options->get_transposh_key() . '" id="' . TRANSPOSH_KEY . '" name="' . TRANSPOSH_KEY . '"/> <a target="_blank" href="http://transposh.org/faq/#restore">' . __('How to restore?', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 619 echo '<div id="backup_result"></div>'; 620 echo '<div style="margin:10px 0"><a id="transposh-backup" href="#" class="button">' . __('Do Backup Now', TRANSPOSH_TEXT_DOMAIN) . '</a></div>'; 750 751 echo '<div id="progress_bar_all"></div><div id="tr_translate_title"></div>'; 752 echo '<div id="tr_loading" style="margin: 0 0 10px 0">' . __('Translate by clicking the button below', TRANSPOSH_TEXT_DOMAIN) . '</div>'; 753 echo '<div id="tr_allmsg" style="margin: 0 0 10px 0"></div>'; 754 echo '<a id="transposh-translate" href="#" onclick="return false;" class="button">' . __('Translate All Now', TRANSPOSH_TEXT_DOMAIN) . '</a><br/>'; 755 //get_posts 756 } 757 758 function tp_about() { 759 /* wp_enqueue_style( 'wp-pointer' ); 760 wp_enqueue_script( 'wp-pointer' ); 761 762 $content = '<h3>' . __( 'New Feature: Toolbar' ) . '</h3>'; 763 $content .= '<p>' . __( 'We’ve combined the admin bar and the old Dashboard header into one persistent toolbar. Hover over the toolbar items to see what’s new.' ) . '</p>'; 764 765 if ( is_multisite() && is_super_admin() ) 766 $content .= '<p>' . __( 'Network Admin is now located in the My Sites menu.' ) . '</p>'; 767 768 $this->print_js( 'tp_toolbar', '#icon-options-general', array( 769 'content' => $content, 770 'position' => array( 'edge' => 'top', 'align' => 'center' ), 771 ) ); */ 772 } 773 774 function tp_support() { 775 776 } 777 778 // executed if the post arrives initiated by pressing the submit button of form 779 function on_save_changes() { 780 //user permission check 781 if (!current_user_can('manage_options')) 782 wp_die(__('Problems?', TRANSPOSH_TEXT_DOMAIN)); 783 // cross check the given referer 784 check_admin_referer(TR_NONCE); 785 786 // process here your on $_POST validation and / or option saving 787 $this->update_admin_options(); 788 789 // lets redirect the post request into get request (you may add additional params at the url, if you need to show save results 790 $this->transposh->tp_redirect($_POST['_wp_http_referer']); 791 } 792 793 // below you will find for each registered metabox the callback method, that produces the content inside the boxes 794 // i did not describe each callback dedicated, what they do can be easily inspected and compare with the admin page displayed 795 796 function on_sidebox_about_content() { 797 echo '<ul style="list-style-type:disc;margin-' . $this->localeleft . ':20px;">'; 798 echo '<li><a href="http://transposh.org/">' . __('Plugin Homepage', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 799 echo '<li><a href="http://transposh.org/redir/newfeature">' . __('Suggest a Feature', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 800 // support Forum 801 echo '<li><a href="http://transposh.org/redir/newticket">' . __('Report a Bug', TRANSPOSH_TEXT_DOMAIN) . '</a></li>'; 802 // donate with PayPal 803 echo '</ul>'; 804 } 805 806 /* private static function print_js($pointer_id, $selector, $args) { 807 if (empty($pointer_id) || empty($selector) || empty($args) || empty($args['content'])) 808 return; 809 ?> 810 <script type="text/javascript"> 811 //<![CDATA[ 812 (function($){ 813 var options = <?php echo json_encode($args); ?>, setup; 814 815 if ( ! options ) 816 return; 817 818 options = $.extend( options, { 819 close: function() { 820 $.post( ajaxurl, { 821 pointer: '<?php echo $pointer_id; ?>', 822 action: 'dismiss-wp-pointer' 823 }); 824 } 825 }); 826 827 setup = function() { 828 $('<?php echo $selector; ?>').pointer( options ).pointer('open'); 829 }; 830 831 if ( options.position && options.position.defer_loading ) 832 $(window).bind( 'load.wp-pointers', setup ); 833 else 834 $(document).ready( setup ); 835 836 })( jQuery ); 837 //]]> 838 </script> 839 <?php 840 } */ 841 842 function on_sidebox_news_content() { 843 echo '<div style="margin:6px">'; 844 wp_widget_rss_output('http://feeds2.feedburner.com/transposh', array('items' => 5)); 845 echo '</div>'; 846 } 847 848 function on_sidebox_stats_content() { 849 $this->transposh->database->db_stats(); 850 } 851 852 /** 853 * uses a boolean expression to make checkboxes check 854 * @param boolean $eval 855 * @return string used for checkboxes 856 */ 857 858 /** UTILITY FUNCTIONS * */ 859 private function checked($eval) { 860 return $eval ? 'checked="checked"' : ''; 861 } 862 863 private function checkbox($id, $value, $head, $text) { 864 echo '<h3>' . $head . '</h3>'; 865 echo '<input type="checkbox" value="1" name="' . $id . '" ' . $this->checked($value) . '/> ' . $text; 621 866 } 622 867
Note: See TracChangeset
for help on using the changeset viewer.
