WordPressを読む 91 /blog/wp-content/plugins/crayon-syntax-highlighter/crayon_settings_wp.class.php
/blog/wp-content/plugins/crayon-syntax-highlighter/crayon_settings_wp.class.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | <?php require_once('global.php'); require_once(CRAYON_LANGS_PHP); require_once(CRAYON_THEMES_PHP); require_once(CRAYON_FONTS_PHP); require_once(CRAYON_SETTINGS_PHP); /* Manages global settings within WP and integrates them with CrayonSettings. CrayonHighlighter and any non-WP classes will only use CrayonSettings to separate the implementation of global settings and ensure any system can use them. */ class CrayonSettingsWP { // Properties and Constants =============================================== // A copy of the current options in db private static $options = NULL; // Posts containing crayons in db private static $crayon_posts = NULL; // Posts containing legacy tags in db private static $crayon_legacy_posts = NULL; // An array of cache names for use with Transients API private static $cache = NULL; // Array of settings to pass to js private static $js_settings = NULL; private static $js_strings = NULL; private static $admin_js_settings = NULL; private static $admin_js_strings = NULL; private static $admin_page = ''; private static $is_fully_loaded = FALSE; const SETTINGS = 'crayon_fields'; const FIELDS = 'crayon_settings'; const OPTIONS = 'crayon_options'; const POSTS = 'crayon_posts'; const LEGACY_POSTS = 'crayon_legacy_posts'; const CACHE = 'crayon_cache'; const GENERAL = 'crayon_general'; const DEBUG = 'crayon_debug'; const ABOUT = 'crayon_about'; // Used on submit const LOG_CLEAR = 'log_clear'; const LOG_EMAIL_ADMIN = 'log_email_admin'; const LOG_EMAIL_DEV = 'log_email_dev'; const SAMPLE_CODE = 'sample-code'; const CACHE_CLEAR = 'crayon-cache-clear'; private function __construct() { } // Methods ================================================================ public static function admin_load() { self::$admin_page = $admin_page = add_options_page('Crayon Syntax Highlighter ' . crayon__('Settings'), 'Crayon', 'manage_options', 'crayon_settings', 'CrayonSettingsWP::settings'); add_action("admin_print_scripts-$admin_page", 'CrayonSettingsWP::admin_scripts'); add_action("admin_print_styles-$admin_page", 'CrayonSettingsWP::admin_styles'); add_action("admin_print_scripts-$admin_page", 'CrayonThemeEditorWP::admin_resources'); // Register settings, second argument is option name stored in db register_setting(self::FIELDS, self::OPTIONS, 'CrayonSettingsWP::settings_validate'); add_action("admin_head-$admin_page", 'CrayonSettingsWP::admin_init'); // Register settings for post page add_action("admin_print_styles-post-new.php", 'CrayonSettingsWP::admin_scripts'); add_action("admin_print_styles-post.php", 'CrayonSettingsWP::admin_scripts'); add_action("admin_print_styles-post-new.php", 'CrayonSettingsWP::admin_styles'); add_action("admin_print_styles-post.php", 'CrayonSettingsWP::admin_styles'); // TODO depreciated since WP 3.3, remove eventually global $wp_version; if ($wp_version >= '3.3') { add_action("load-$admin_page", 'CrayonSettingsWP::help_screen'); } else { add_filter('contextual_help', 'CrayonSettingsWP::cont_help', 10, 3); } } public static function admin_styles() { global $CRAYON_VERSION; if (CRAYON_MINIFY) { wp_enqueue_style('crayon', plugins_url(CRAYON_STYLE_MIN, __FILE__), array('editor-buttons'), $CRAYON_VERSION); } else { wp_enqueue_style('crayon', plugins_url(CRAYON_STYLE, __FILE__), array(), $CRAYON_VERSION); wp_enqueue_style('crayon_global', plugins_url(CRAYON_STYLE_GLOBAL, __FILE__), array(), $CRAYON_VERSION); wp_enqueue_style('crayon_admin', plugins_url(CRAYON_STYLE_ADMIN, __FILE__), array('editor-buttons'), $CRAYON_VERSION); } } public static function admin_scripts() { global $CRAYON_VERSION; if (CRAYON_MINIFY) { CrayonWP::enqueue_resources(); } else { wp_enqueue_script('crayon_util_js', plugins_url(CRAYON_JS_UTIL, __FILE__), array('jquery'), $CRAYON_VERSION); self::other_scripts(); } self::init_js_settings(); if (is_admin()) { wp_enqueue_script('crayon_admin_js', plugins_url(CRAYON_JS_ADMIN, __FILE__), array('jquery', 'crayon_js', 'wpdialogs'), $CRAYON_VERSION); self::init_admin_js_settings(); } } public static function other_scripts() { global $CRAYON_VERSION; self::load_settings(TRUE); $deps = array('jquery', 'crayon_util_js'); if (CrayonGlobalSettings::val(CrayonSettings::POPUP) || is_admin()) { // TODO include anyway and minify wp_enqueue_script('crayon_jquery_popup', plugins_url(CRAYON_JQUERY_POPUP, __FILE__), array('jquery'), $CRAYON_VERSION); $deps[] = 'crayon_jquery_popup'; } wp_enqueue_script('crayon_js', plugins_url(CRAYON_JS, __FILE__), $deps, $CRAYON_VERSION); } public static function init_js_settings() { // This stores JS variables used in AJAX calls and in the JS files global $CRAYON_VERSION; self::load_settings(TRUE); if (!self::$js_settings) { self::$js_settings = array( 'version' => $CRAYON_VERSION, 'is_admin' => intval(is_admin()), 'ajaxurl' => admin_url('admin-ajax.php'), 'prefix' => CrayonSettings::PREFIX, 'setting' => CrayonSettings::SETTING, 'selected' => CrayonSettings::SETTING_SELECTED, 'changed' => CrayonSettings::SETTING_CHANGED, 'special' => CrayonSettings::SETTING_SPECIAL, 'orig_value' => CrayonSettings::SETTING_ORIG_VALUE, 'debug' => CRAYON_DEBUG ); } if (!self::$js_strings) { self::$js_strings = array( 'copy' => crayon__('Press %s to Copy, %s to Paste'), 'minimize' => crayon__('Click To Expand Code') ); } if (CRAYON_MINIFY) { wp_localize_script('crayon_js', 'CrayonSyntaxSettings', self::$js_settings); wp_localize_script('crayon_js', 'CrayonSyntaxStrings', self::$js_strings); } else { wp_localize_script('crayon_util_js', 'CrayonSyntaxSettings', self::$js_settings); wp_localize_script('crayon_util_js', 'CrayonSyntaxStrings', self::$js_strings); } } public static function init_admin_js_settings() { if (!self::$admin_js_settings) { // We need to load themes at this stage CrayonSettingsWP::load_settings(); $themes_ = CrayonResources::themes()->get(); $stockThemes = array(); $userThemes = array(); foreach ($themes_ as $theme) { $id = $theme->id(); $name = $theme->name(); if ($theme->user()) { $userThemes[$id] = $name; } else { $stockThemes[$id] = $name; } } self::$admin_js_settings = array( 'themes' => array_merge($stockThemes, $userThemes), 'stockThemes' => $stockThemes, 'userThemes' => $userThemes, 'defaultTheme' => CrayonThemes::DEFAULT_THEME, 'themesURL' => CrayonResources::themes()->dirurl(false), 'userThemesURL' => CrayonResources::themes()->dirurl(true), 'sampleCode' => self::SAMPLE_CODE, 'dialogFunction' => 'wpdialog' ); wp_localize_script('crayon_admin_js', 'CrayonAdminSettings', self::$admin_js_settings); } if (!self::$admin_js_strings) { self::$admin_js_strings = array( 'prompt' => crayon__("Prompt"), 'value' => crayon__("Value"), 'alert' => crayon__("Alert"), 'no' => crayon__("No"), 'yes' => crayon__("Yes"), 'confirm' => crayon__("Confirm"), 'changeCode' => crayon__("Change Code") ); wp_localize_script('crayon_admin_js', 'CrayonAdminStrings', self::$admin_js_strings); } } public static function settings() { if (!current_user_can('manage_options')) { wp_die(crayon__('You do not have sufficient permissions to access this page.')); } ?> <script type="text/javascript"> jQuery(document).ready(function () { CrayonSyntaxAdmin.init(); }); </script> <div id="crayon-main-wrap" class="wrap"> <div id="icon-options-general" class="icon32"> <br> </div> <h2> Crayon Syntax Highlighter <?php crayon_e('Settings'); ?> </h2> <?php self::help(); ?> <form id="crayon-settings-form" action="options.php" method="post"> <?php settings_fields(self::FIELDS); ?> <?php do_settings_sections(self::SETTINGS); ?> <p class="submit"> <input type="submit" name="submit" id="submit" class="button-primary" value="<?php crayon_e('Save Changes'); ?>"/><span style="width:10px; height: 5px; float:left;"></span> <input type="submit" name="<?php echo self::OPTIONS; ?>[reset]" id="reset" class="button-primary" value="<?php crayon_e('Reset Settings'); ?>"/> </p> </form> </div> <div id="crayon-theme-editor-wrap" class="wrap"></div> <?php } // Load the global settings and update them from the db public static function load_settings($just_load_settings = FALSE) { if (self::$options === NULL) { // Load settings from db if (!(self::$options = get_option(self::OPTIONS))) { self::$options = CrayonSettings::get_defaults_array(); update_option(self::OPTIONS, self::$options); } // Initialise default global settings and update them from db CrayonGlobalSettings::set(self::$options); } if (!self::$is_fully_loaded && !$just_load_settings) { // Load everything else as well // For local file loading // This is used to decouple WP functions from internal Crayon classes CrayonGlobalSettings::site_url(home_url()); CrayonGlobalSettings::site_path(ABSPATH); CrayonGlobalSettings::plugin_path(plugins_url('', __FILE__)); $upload = wp_upload_dir(); CrayonLog::debug($upload, "WP UPLOAD FUNCTION"); CrayonGlobalSettings::upload_path(CrayonUtil::path_slash($upload['basedir']) . CRAYON_DIR); CrayonGlobalSettings::upload_url($upload['baseurl'] . '/' . CRAYON_DIR); CrayonLog::debug(CrayonGlobalSettings::upload_path(), "UPLOAD PATH"); CrayonGlobalSettings::set_mkdir('wp_mkdir_p'); // Load all available languages and themes CrayonResources::langs()->load(); CrayonResources::themes()->load(); // Ensure all missing settings in db are replaced by default values $changed = FALSE; foreach (CrayonSettings::get_defaults_array() as $name => $value) { // Add missing settings if (!array_key_exists($name, self::$options)) { self::$options[$name] = $value; $changed = TRUE; } } // A setting was missing, update options if ($changed) { update_option(self::OPTIONS, self::$options); } self::$is_fully_loaded = TRUE; } } public static function get_settings() { return get_option(self::OPTIONS); } // Saves settings from CrayonGlobalSettings, or provided array, to the db public static function save_settings($settings = NULL) { if ($settings === NULL) { $settings = CrayonGlobalSettings::get_array(); } update_option(self::OPTIONS, $settings); } // Crayon posts /** * This loads the posts marked as containing Crayons */ public static function load_posts() { if (self::$crayon_posts === NULL) { // Load from db if (!(self::$crayon_posts = get_option(self::POSTS))) { // Posts don't exist! Scan for them. This will fill self::$crayon_posts self::$crayon_posts = CrayonWP::scan_posts(); update_option(self::POSTS, self::$crayon_posts); } } return self::$crayon_posts; } /** * This looks through all posts and marks those which contain Crayons */ // public static function scan_and_save_posts() { // self::save_posts(CrayonWP::scan_posts(TRUE, TRUE)); // } /** * Saves the marked posts to the db */ public static function save_posts($posts = NULL) { if ($posts === NULL) { $posts = self::$crayon_posts; } update_option(self::POSTS, $posts); self::load_posts(); } /** * Adds a post as containing a Crayon */ public static function add_post($id, $save = TRUE) { self::load_posts(); if (!in_array($id, self::$crayon_posts)) { self::$crayon_posts[] = $id; } if ($save) { self::save_posts(); } } /** * Removes a post as not containing a Crayon */ public static function remove_post($id, $save = TRUE) { self::load_posts(); $key = array_search($id, self::$crayon_posts); if ($key === false) { return; } unset(self::$crayon_posts[$key]); if ($save) { self::save_posts(); } } public static function remove_posts() { self::$crayon_posts = array(); self::save_posts(); } // Crayon legacy posts /** * This loads the posts marked as containing Crayons */ public static function load_legacy_posts($force = FALSE) { if (self::$crayon_legacy_posts === NULL || $force) { // Load from db if (!(self::$crayon_legacy_posts = get_option(self::LEGACY_POSTS))) { // Posts don't exist! Scan for them. This will fill self::$crayon_legacy_posts self::$crayon_legacy_posts = CrayonWP::scan_legacy_posts(); update_option(self::LEGACY_POSTS, self::$crayon_legacy_posts); } } return self::$crayon_legacy_posts; } /** * This looks through all posts and marks those which contain Crayons */ // public static function scan_and_save_posts() { // self::save_posts(CrayonWP::scan_posts(TRUE, TRUE)); // } /** * Saves the marked posts to the db */ public static function save_legacy_posts($posts = NULL) { if ($posts === NULL) { $posts = self::$crayon_legacy_posts; } update_option(self::LEGACY_POSTS, $posts); self::load_legacy_posts(); } /** * Adds a post as containing a Crayon */ public static function add_legacy_post($id, $save = TRUE) { self::load_legacy_posts(); if (!in_array($id, self::$crayon_legacy_posts)) { self::$crayon_legacy_posts[] = $id; } if ($save) { self::save_legacy_posts(); } } /** * Removes a post as not containing a Crayon */ public static function remove_legacy_post($id, $save = TRUE) { self::load_legacy_posts(); $key = array_search($id, self::$crayon_legacy_posts); if ($key === false) { return; } unset(self::$crayon_legacy_posts[$key]); if ($save) { self::save_legacy_posts(); } } public static function remove_legacy_posts() { self::$crayon_legacy_posts = array(); self::save_legacy_posts(); } // Cache public static function add_cache($name) { self::load_cache(); if (!in_array($name, self::$cache)) { self::$cache[] = $name; } self::save_cache(); } public static function remove_cache($name) { self::load_cache(); $key = array_search($name, self::$cache); if ($key === false) { return; } unset(self::$cache[$key]); self::save_cache(); } public static function clear_cache() { self::load_cache(); foreach (self::$cache as $name) { delete_transient($name); } self::$cache = array(); self::save_cache(); } public static function load_cache() { // Load cache from db if (!(self::$cache = get_option(self::CACHE))) { self::$cache = array(); update_option(self::CACHE, self::$cache); } } public static function save_cache() { update_option(self::CACHE, self::$cache); self::load_cache(); } // Paths public static function admin_init() { // Load default settings if they don't exist self::load_settings(); // General // Some of these will the $editor arguments, if TRUE it will alter for use in the Tag Editor self::add_section(self::GENERAL, crayon__('General')); self::add_field(self::GENERAL, crayon__('Theme'), 'theme'); self::add_field(self::GENERAL, crayon__('Font'), 'font'); self::add_field(self::GENERAL, crayon__('Metrics'), 'metrics'); self::add_field(self::GENERAL, crayon__('Toolbar'), 'toolbar'); self::add_field(self::GENERAL, crayon__('Lines'), 'lines'); self::add_field(self::GENERAL, crayon__('Code'), 'code'); self::add_field(self::GENERAL, crayon__('Tags'), 'tags'); self::add_field(self::GENERAL, crayon__('Languages'), 'langs'); self::add_field(self::GENERAL, crayon__('Files'), 'files'); self::add_field(self::GENERAL, crayon__('Posts'), 'posts'); self::add_field(self::GENERAL, crayon__('Tag Editor'), 'tag_editor'); self::add_field(self::GENERAL, crayon__('Misc'), 'misc'); // Debug self::add_section(self::DEBUG, crayon__('Debug')); self::add_field(self::DEBUG, crayon__('Errors'), 'errors'); self::add_field(self::DEBUG, crayon__('Log'), 'log'); // ABOUT self::add_section(self::ABOUT, crayon__('About')); $image = '<div id="crayon-logo"> <img src="' . plugins_url(CRAYON_LOGO, __FILE__) . '" /><br/></div>'; self::add_field(self::ABOUT, $image, 'info'); } // Wrapper functions private static function add_section($name, $title, $callback = NULL) { $callback = (empty($callback) ? 'blank' : $callback); add_settings_section($name, $title, 'CrayonSettingsWP::' . $callback, self::SETTINGS); } private static function add_field($section, $title, $callback, $args = array()) { $unique = preg_replace('#\\s#', '_', strtolower($title)); add_settings_field($unique, $title, 'CrayonSettingsWP::' . $callback, self::SETTINGS, $section, $args); } // Validates all the settings passed from the form in $inputs public static function settings_validate($inputs) { // Load current settings from db self::load_settings(TRUE); global $CRAYON_EMAIL; // When reset button is pressed, remove settings so default loads next time if (array_key_exists('reset', $inputs)) { self::clear_cache(); return array(); } // Convert old tags if (array_key_exists('convert', $inputs)) { $encode = array_key_exists('convert_encode', $inputs); CrayonWP::convert_tags($encode); } // Refresh internal tag management if (array_key_exists('refresh_tags', $inputs)) { CrayonWP::refresh_posts(); } // Clear the log if needed if (array_key_exists(self::LOG_CLEAR, $_POST)) { CrayonLog::clear(); } // Send to admin if (array_key_exists(self::LOG_EMAIL_ADMIN, $_POST)) { CrayonLog::email(get_bloginfo('admin_email')); } // Send to developer if (array_key_exists(self::LOG_EMAIL_DEV, $_POST)) { CrayonLog::email($CRAYON_EMAIL, get_bloginfo('admin_email')); } // Clear the cache if (array_key_exists(self::CACHE_CLEAR, $_POST)) { self::clear_cache(); } // If settings don't exist in input, set them to default $global_settings = CrayonSettings::get_defaults(); $ignored = array(CrayonSettings::HIDE_HELP); foreach ($global_settings as $setting) { // XXX Ignore some settings if (in_array($setting->name(), $ignored)) { $inputs[$setting->name()] = CrayonGlobalSettings::val($setting->name()); continue; } // If boolean setting is not in input, then it is set to FALSE in the form if (!array_key_exists($setting->name(), $inputs)) { // For booleans, set to FALSE (unchecked boxes are not sent as POST) if (is_bool($setting->def())) { $inputs[$setting->name()] = FALSE; } else { /* For array settings, set the input as the value, which by default is the default index */ if (is_array($setting->def())) { $inputs[$setting->name()] = $setting->value(); } else { $inputs[$setting->name()] = $setting->def(); } } } } $refresh = array( // These should trigger a refresh of which posts contain crayons, since they affect capturing CrayonSettings::INLINE_TAG => TRUE, CrayonSettings::INLINE_TAG_CAPTURE => TRUE, CrayonSettings::CODE_TAG_CAPTURE => TRUE, CrayonSettings::BACKQUOTE => TRUE, CrayonSettings::CAPTURE_PRE => TRUE, CrayonSettings::CAPTURE_MINI_TAG => TRUE, CrayonSettings::PLAIN_TAG => TRUE ); // Validate inputs foreach ($inputs as $input => $value) { // Convert all array setting values to ints $inputs[$input] = $value = CrayonSettings::validate($input, $value); // Clear cache when changed if (CrayonGlobalSettings::has_changed($input, CrayonSettings::CACHE, $value)) { self::clear_cache(); } if (isset($refresh[$input])) { if (CrayonGlobalSettings::has_changed($input, $input, $value)) { // Needs to take place, in case it refresh depends on changed value CrayonGlobalSettings::set($input, $value); CrayonWP::refresh_posts(); } } } return $inputs; } // Section callback functions public static function blank() { } // Used for required callbacks with blank content // Input Drawing ========================================================== private static function textbox($args) { $id = ''; $size = 40; $margin = FALSE; $preview = 1; $break = FALSE; extract($args); echo '<input id="', CrayonSettings::PREFIX, $id, '" name="', self::OPTIONS, '[', $id, ']" class="' . CrayonSettings::SETTING . '" size="', $size, '" type="text" value="', self::$options[$id], '" style="margin-left: ', ($margin ? '20px' : '0px'), ';" crayon-preview="', ($preview ? 1 : 0), '" />', ($break ? CRAYON_BR : ''); } private static function checkbox($args, $line_break = TRUE, $preview = TRUE) { if (empty($args) || !is_array($args) || count($args) != 2) { return; } $id = $args[0]; $text = $args[1]; $checked = (!array_key_exists($id, self::$options)) ? FALSE : self::$options[$id] == TRUE; $checked_str = $checked ? ' checked="checked"' : ''; echo '<input id="', CrayonSettings::PREFIX, $id, '" name="', self::OPTIONS, '[', $id, ']" type="checkbox" class="' . CrayonSettings::SETTING . '" value="1"', $checked_str, ' crayon-preview="', ($preview ? 1 : 0), '" /> ', '<label for="', CrayonSettings::PREFIX, $id, '">', $text, '</label>', ($line_break ? CRAYON_BR : ''); } // Draws a dropdown by loading the default value (an array) from a setting private static function dropdown($id, $line_break = TRUE, $preview = TRUE, $echo = TRUE, $resources = NULL, $selected = NULL) { if (!array_key_exists($id, self::$options)) { return; } $resources = $resources != NULL ? $resources : CrayonGlobalSettings::get($id)->def(); $return = '<select id="' . CrayonSettings::PREFIX . $id . '" name="' . self::OPTIONS . '[' . $id . ']" class="' . CrayonSettings::SETTING . '" crayon-preview="' . ($preview ? 1 : 0) . '">'; foreach ($resources as $k => $v) { if (is_array($v) && count($v)) { $data = $v[0]; $text = $v[1]; } else { $text = $v; } $is_selected = $selected !== NULL && $selected == $k ? 'selected' : selected(self::$options[$id], $k, FALSE); $return .= '<option ' . (isset($data) ? 'data-value="' . $data . '"' : '') . ' value="' . $k . '" ' . $is_selected . '>' . $text . '</option>'; } $return .= '</select>' . ($line_break ? CRAYON_BR : ''); if ($echo) { echo $return; } else { return $return; } } private static function button($args = array()) { extract($args); CrayonUtil::set_var($id, ''); CrayonUtil::set_var($class, ''); CrayonUtil::set_var($onclick, ''); CrayonUtil::set_var($title, ''); return '<a id="' . $id . '" class="button-primary ' . $class . '" onclick="' . $onclick . '">' . $title . '</a>'; } private static function info_span($name, $text) { echo '<span id="', $name, '-info">', $text, '</span>'; } private static function span($text) { echo '<span>', $text, '</span>'; } // General Fields ========================================================= public static function help() { global $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_PLUGIN_WP, $CRAYON_DONATE; if (CrayonGlobalSettings::val(CrayonSettings::HIDE_HELP)) { return; } echo '<div id="crayon-help" class="updated settings-error crayon-help"> <p><strong>Howdy, coder!</strong> Thanks for using Crayon. <strong>Useful Links:</strong> <a href="' . $CRAYON_WEBSITE . '" target="_blank">Documentation</a>, <a href="' . $CRAYON_GIT . '" target="_blank">GitHub</a>, <a href="' . $CRAYON_PLUGIN_WP . '" target="_blank">Plugin Page</a>, <a href="' . $CRAYON_TWITTER . '" target="_blank">Twitter</a>. Crayon has always been free. If you value my work please consider a <a href="' . $CRAYON_DONATE . '">small donation</a> to show your appreciation. Thanks! <a class="crayon-help-close">X</a></p></div> '; } public static function help_screen() { $screen = get_current_screen(); if ($screen->id != self::$admin_page) { return; } } public static function metrics() { echo '<div id="crayon-section-metrics" class="crayon-hide-inline">'; self::checkbox(array(CrayonSettings::HEIGHT_SET, '<span class="crayon-span-50">' . crayon__('Height') . ' </span>'), FALSE); self::dropdown(CrayonSettings::HEIGHT_MODE, FALSE); echo ' '; self::textbox(array('id' => CrayonSettings::HEIGHT, 'size' => 8)); echo ' '; self::dropdown(CrayonSettings::HEIGHT_UNIT); self::checkbox(array(CrayonSettings::WIDTH_SET, '<span class="crayon-span-50">' . crayon__('Width') . ' </span>'), FALSE); self::dropdown(CrayonSettings::WIDTH_MODE, FALSE); echo ' '; self::textbox(array('id' => CrayonSettings::WIDTH, 'size' => 8)); echo ' '; self::dropdown(CrayonSettings::WIDTH_UNIT); $text = array(crayon__('Top Margin') => array(CrayonSettings::TOP_SET, CrayonSettings::TOP_MARGIN), crayon__('Bottom Margin') => array(CrayonSettings::BOTTOM_SET, CrayonSettings::BOTTOM_MARGIN), crayon__('Left Margin') => array(CrayonSettings::LEFT_SET, CrayonSettings::LEFT_MARGIN), crayon__('Right Margin') => array(CrayonSettings::RIGHT_SET, CrayonSettings::RIGHT_MARGIN)); foreach ($text as $p => $s) { $set = $s[0]; $margin = $s[1]; $preview = ($p == crayon__('Left Margin') || $p == crayon__('Right Margin')); self::checkbox(array($set, '<span class="crayon-span-110">' . $p . '</span>'), FALSE, $preview); echo ' '; self::textbox(array('id' => $margin, 'size' => 8, 'preview' => FALSE)); echo '<span class="crayon-span-margin">', crayon__('Pixels'), '</span>', CRAYON_BR; } echo '<span class="crayon-span" style="min-width: 135px;">' . crayon__('Horizontal Alignment') . ' </span>'; self::dropdown(CrayonSettings::H_ALIGN); echo '<div id="crayon-subsection-float">'; self::checkbox(array(CrayonSettings::FLOAT_ENABLE, crayon__('Allow floating elements to surround Crayon')), FALSE, FALSE); echo '</div>'; echo '<span class="crayon-span-100">' . crayon__('Inline Margin') . ' </span>'; self::textbox(array('id' => CrayonSettings::INLINE_MARGIN, 'size' => 2)); echo '<span class="crayon-span-margin">', crayon__('Pixels'), '</span>'; echo '</div>'; } public static function toolbar() { echo '<div id="crayon-section-toolbar" class="crayon-hide-inline">'; self::span(crayon__('Display the Toolbar') . ' '); self::dropdown(CrayonSettings::TOOLBAR); echo '<div id="crayon-subsection-toolbar">'; self::checkbox(array(CrayonSettings::TOOLBAR_OVERLAY, crayon__('Overlay the toolbar on code rather than push it down when possible'))); self::checkbox(array(CrayonSettings::TOOLBAR_HIDE, crayon__('Toggle the toolbar on single click when it is overlayed'))); self::checkbox(array(CrayonSettings::TOOLBAR_DELAY, crayon__('Delay hiding the toolbar on MouseOut'))); echo '</div>'; self::checkbox(array(CrayonSettings::SHOW_TITLE, crayon__('Display the title when provided'))); self::span(crayon__('Display the language') . ' '); self::dropdown(CrayonSettings::SHOW_LANG); echo '</div>'; } public static function lines() { echo '<div id="crayon-section-lines" class="crayon-hide-inline">'; self::checkbox(array(CrayonSettings::STRIPED, crayon__('Display striped code lines'))); self::checkbox(array(CrayonSettings::MARKING, crayon__('Enable line marking for important lines'))); self::checkbox(array(CrayonSettings::RANGES, crayon__('Enable line ranges for showing only parts of code'))); self::checkbox(array(CrayonSettings::NUMS, crayon__('Display line numbers by default'))); self::checkbox(array(CrayonSettings::NUMS_TOGGLE, crayon__('Enable line number toggling'))); self::checkbox(array(CrayonSettings::WRAP, crayon__('Wrap lines by default'))); self::checkbox(array(CrayonSettings::WRAP_TOGGLE, crayon__('Enable line wrap toggling'))); self::span(crayon__('Start line numbers from') . ' '); self::textbox(array('id' => CrayonSettings::START_LINE, 'size' => 2, 'break' => TRUE)); echo '</div>'; } public static function langs() { echo '<a name="langs"></a>'; // Specialised dropdown for languages if (array_key_exists(CrayonSettings::FALLBACK_LANG, self::$options)) { if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); self::span(crayon__('When no language is provided, use the fallback') . ': '); self::dropdown(CrayonSettings::FALLBACK_LANG, FALSE, TRUE, TRUE, $langs); // Information about parsing $parsed = CrayonResources::langs()->is_parsed(); $count = count($langs); echo '</select>', CRAYON_BR, ($parsed ? '' : '<span class="crayon-error">'), sprintf(crayon_n('%d language has been detected.', '%d languages have been detected.', $count), $count), ' ', $parsed ? crayon__('Parsing was successful') : crayon__('Parsing was unsuccessful'), ($parsed ? '. ' : '</span>'); // Check if fallback from db is loaded $db_fallback = self::$options[Crayon-6817748933853392493823Settings::FALLBACK_LANG]; // Fallback name from db if (!CrayonResources::langs()->is_loaded($db_fallback) || !CrayonResources::langs()->exists($db_fallback)) { echo '<br/><span class="crayon-error">', sprintf(crayon__('The selected language with id %s could not be loaded'), '<strong>' . $db_fallback . '</strong>'), '. </span>'; } // Language parsing info echo CRAYON_BR, '<div id="crayon-subsection-langs-info"><div>' . self::button(array('id' => 'show-langs', 'title' => crayon__('Show Languages'))) . '</div></div>'; } else { echo crayon__('No languages could be parsed.'); } } } public static function show_langs() { CrayonSettingsWP::load_settings(); require_once(CRAYON_PARSER_PHP); if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>',crayon__('ID'),'</td><td>',crayon__('Name'),'</td><td>',crayon__('Version'),'</td><td>',crayon__('File Extensions'),'</td><td>',crayon__('Aliases'),'</td><td>',crayon__('State'),'</td></tr>'; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = ($i == count($langs) - 1) ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $lang->id(), '</td>', '<td>', $lang->name(), '</td>', '<td>', $lang->version(), '</td>', '<td>', implode(', ', $lang->ext()), '</td>', '<td>', implode(', ', $lang->alias()), '</td>', '<td class="', strtolower(CrayonUtil::space_to_hyphen($lang->state_info())), '">', $lang->state_info(), '</td>', '</tr>'; } echo '</table><br/>' . crayon__("Languages that have the same extension as their name don't need to explicitly map extensions."); } else { echo crayon__('No languages could be found.'); } exit(); } public static function posts() { echo '<a name="posts"></a>'; echo self::button(array('id' => 'show-posts', 'title' => crayon__('Show Crayon Posts'))); echo ' <input type="submit" name="', self::OPTIONS, '[refresh_tags]" id="refresh_tags" class="button-primary" value="', crayon__('Refresh'), '" />'; echo self::help_button('http://aramk.com/blog/2012/09/26/internal-post-management-crayon/'); echo '<div id="crayon-subsection-posts-info"></div>'; } public static function post_cmp($a, $b) { $a = $a->post_modified; $b = $b->post_modified; if ($a == $b) { return 0; } else { return $a < $b ? 1 : -1; } } public static function show_posts() { CrayonSettingsWP::load_settings(); $postIDs = self::load_posts(); $legacy_posts = self::load_legacy_posts(); // Avoids O(n^2) by using a hash map, tradeoff in using strval $legacy_map = array(); foreach ($legacy_posts as $legacyID) { $legacy_map[strval($legacyID)] = TRUE; } echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>', crayon__('ID'), '</td><td>', crayon__('Title'), '</td><td>', crayon__('Posted'), '</td><td>', crayon__('Modifed'), '</td><td>', crayon__('Contains Legacy Tags?'), '</td></tr>'; $posts = array(); for ($i = 0; $i < count($postIDs); $i++) { $posts[$i] = get_post($postIDs[$i]); } usort($posts, 'CrayonSettingsWP::post_cmp'); for ($i = 0; $i < count($posts); $i++) { $post = $posts[$i]; $postID = $post->ID; $title = $post->post_title; $title = !empty($title) ? $title : 'N/A'; $tr = ($i == count($posts) - 1) ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $postID, '</td>', '<td><a href="', $post->guid, '" target="_blank">', $title, '</a></td>', '<td>', $post->post_date, '</td>', '<td>', $post->post_modified, '</td>', '<td>', isset($legacy_map[strval($postID)]) ? '<span style="color: red;">' . crayon__('Yes') . '</a>' : crayon__('No'), '</td>', '</tr>'; } echo '</table>'; exit(); } public static function show_preview() { echo '<div id="content">'; self::load_settings(); // Run first to ensure global settings loaded $crayon = CrayonWP::instance(); // Settings to prevent from validating $preview_settings = array(self::SAMPLE_CODE); // Load settings from GET and validate foreach ($_POST as $key => $value) { // echo $key, ' ', $value , '<br/>'; $value = stripslashes($value); if (!in_array($key, $preview_settings)) { $_POST[$key] = CrayonSettings::validate($key, $value); } else { $_POST[$key] = $value; } } $crayon->settings($_POST); if (!isset($crayon_preview_dont_override_get) || !$crayon_preview_dont_override_get) { $settings = array(CrayonSettings::TOP_SET => TRUE, CrayonSettings::TOP_MARGIN => 10, CrayonSettings::BOTTOM_SET => FALSE, CrayonSettings::BOTTOM_MARGIN => 0); $crayon->settings($settings); } // Print the theme CSS $theme_id = $crayon->setting_val(CrayonSettings::THEME); if ($theme_id != NULL) { echo CrayonResources::themes()->get_css($theme_id, date('U')); } $font_id = $crayon->setting_val(CrayonSettings::FONT); if ($font_id != NULL /*&& $font_id != CrayonFonts::DEFAULT_FONT*/) { echo CrayonResources::fonts()->get_css($font_id); } // Load custom code based on language $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG); $path = crayon_pf(CRAYON_UTIL_PATH . '/sample/' . $lang . '.txt', FALSE); if (isset($_POST[self::SAMPLE_CODE])) { $crayon->code($_POST[self::SAMPLE_CODE]); } else if ($lang && @file_exists($path)) { $crayon->url($path); } else { $code = " // A sample class class Human { private int age = 0; public void birthday() { age++; print('Happy Birthday!'); } } "; $crayon->code($code); } $crayon->title('Sample Code'); $crayon->marked('5-7'); $crayon->output($highlight = true, $nums = true, $print = true); echo '</div>'; crayon_load_plugin_textdomain(); exit(); } public static function theme($editor = FALSE) { $db_theme = self::$options[Crayon-681774893386b387832221Settings::THEME]; // Theme name from db if (!array_key_exists(CrayonSettings::THEME, self::$options)) { $db_theme = ''; } $themes_array = CrayonResources::themes()->get_array(); // Mark user themes foreach ($themes_array as $id => $name) { $mark = CrayonResources::themes()->get($id)->user() ? ' *' : ''; $themes_array[$id] = array($name, $name . $mark); } $missing_theme = !CrayonResources::themes()->is_loaded($db_theme) || !CrayonResources::themes()->exists($db_theme); self::dropdown(CrayonSettings::THEME, FALSE, FALSE, TRUE, $themes_array, $missing_theme ? CrayonThemes::DEFAULT_THEME : NULL); if ($editor) { return; } // Theme editor if (CRAYON_THEME_EDITOR) { // echo '<a id="crayon-theme-editor-button" class="button-primary crayon-admin-button" loading="'. crayon__('Loading...') .'" loaded="'. crayon__('Theme Editor') .'" >'. crayon__('Theme Editor') .'</a></br>'; echo '<div id="crayon-theme-editor-admin-buttons">'; $buttons = array('edit' => crayon__('Edit'), 'duplicate' => crayon__('Duplicate'), 'submit' => crayon__('Submit'), 'delete' => crayon__('Delete')); foreach ($buttons as $k => $v) { echo '<a id="crayon-theme-editor-', $k, '-button" class="button-secondary crayon-admin-button" loading="', crayon__('Loading...'), '" loaded="', $v, '" >', $v, '</a>'; } echo '<span class="crayon-span-5"></span>', self::help_button('http://aramk.com/blog/2012/12/27/crayon-theme-editor/'), '<span class="crayon-span-5"></span>', crayon__("Duplicate a Stock Theme into a User Theme to allow editing."); echo '</br></div>'; } // Preview Box ?> <div id="crayon-theme-panel"> <div id="crayon-theme-info"></div> <div id="crayon-live-preview-wrapper"> <div id="crayon-live-preview-inner"> <div id="crayon-live-preview"></div> <div id="crayon-preview-info"> <?php printf(crayon__('Change the %1$sfallback language%2$s to change the sample code or %3$schange it manually%4$s. Lines 5-7 are marked.'), '<a href="#langs">', '</a>', '<a id="crayon-change-code" href="#">', '</a>'); ?> </div> </div> </div> </div> <?php // Preview checkbox self::checkbox(array(CrayonSettings::PREVIEW, crayon__('Enable Live Preview')), FALSE, FALSE); echo '</select><span class="crayon-span-10"></span>'; self::checkbox(array(CrayonSettings::ENQUEUE_THEMES, crayon__('Enqueue themes in the header (more efficient).') . self::help_button('http://aramk.com/blog/2012/01/07/enqueuing-themes-and-fonts-in-crayon/'))); // Check if theme from db is loaded if ($missing_theme) { echo '<span class="crayon-error">', sprintf(crayon__('The selected theme with id %s could not be loaded'), '<strong>' . $db_theme . '</strong>'), '. </span>'; } } public static function font($editor = FALSE) { $db_font = self::$options[Crayon-681774893387e319856064Settings::FONT]; // Theme name from db if (!array_key_exists(CrayonSettings::FONT, self::$options)) { $db_font = ''; } $fonts_array = CrayonResources::fonts()->get_array(); self::dropdown(CrayonSettings::FONT, FALSE, TRUE, TRUE, $fonts_array); echo '<span class="crayon-span-5"></span>'; // TODO(aramk) Add this blog article back. // echo '<a href="http://bit.ly/Yr2Xv6" target="_blank">', crayon__('Add More'), '</a>'; echo '<span class="crayon-span-10"></span>'; self::checkbox(array(CrayonSettings::FONT_SIZE_ENABLE, crayon__('Custom Font Size') . ' '), FALSE); self::textbox(array('id' => CrayonSettings::FONT_SIZE, 'size' => 2)); echo '<span class="crayon-span-margin">', crayon__('Pixels'), ', ', crayon__('Line Height'), ' </span>'; self::textbox(array('id' => CrayonSettings::LINE_HEIGHT, 'size' => 2)); echo '<span class="crayon-span-margin">', crayon__('Pixels'), '</span></br>'; if ((!CrayonResources::fonts()->is_loaded($db_font) || !CrayonResources::fonts()->exists($db_font))) { // Default font doesn't actually exist as a file, it means do not override default theme font echo '<span class="crayon-error">', sprintf(crayon__('The selected font with id %s could not be loaded'), '<strong>' . $db_font . '</strong>'), '. </span><br/>'; } if ($editor) { return; } echo '<div style="height:10px;"></div>'; self::checkbox(array(CrayonSettings::ENQUEUE_FONTS, crayon__('Enqueue fonts in the header (more efficient).') . self::help_button('http://aramk.com/blog/2012/01/07/enqueuing-themes-and-fonts-in-crayon/'))); } public static function code($editor = FALSE) { echo '<div id="crayon-section-code-interaction" class="crayon-hide-inline-only">'; self::checkbox(array(CrayonSettings::PLAIN, crayon__('Enable plain code view and display') . ' '), FALSE); self::dropdown(CrayonSettings::SHOW_PLAIN); echo '<span id="crayon-subsection-copy-check">'; self::checkbox(array(CrayonSettings::PLAIN_TOGGLE, crayon__('Enable plain code toggling'))); self::checkbox(array(CrayonSettings::SHOW_PLAIN_DEFAULT, crayon__('Show the plain code by default'))); self::checkbox(array(CrayonSettings::COPY, crayon__('Enable code copy/paste'))); echo '</span>'; self::checkbox(array(CrayonSettings::POPUP, crayon__('Enable opening code in a window'))); self::checkbox(array(CrayonSettings::SCROLL, crayon__('Always display scrollbars'))); self::checkbox(array(CrayonSettings::MINIMIZE, crayon__('Minimize code') . self::help_button('http://aramk.com/blog/2013/01/15/minimizing-code-in-crayon/'))); self::checkbox(array(CrayonSettings::EXPAND, crayon__('Expand code beyond page borders on mouseover'))); self::checkbox(array(CrayonSettings::EXPAND_TOGGLE, crayon__('Enable code expanding toggling when possible'))); echo '</div>'; if (!$editor) { self::checkbox(array(CrayonSettings::DECODE, crayon__('Decode HTML entities in code'))); } self::checkbox(array(CrayonSettings::DECODE_ATTRIBUTES, crayon__('Decode HTML entities in attributes'))); echo '<div class="crayon-hide-inline-only">'; self::checkbox(array(CrayonSettings::TRIM_WHITESPACE, crayon__('Remove whitespace surrounding the shortcode content'))); echo '</div>'; self::checkbox(array(CrayonSettings::TRIM_CODE_TAG, crayon__('Remove <code> tags surrounding the shortcode content'))); self::checkbox(array(CrayonSettings::MIXED, crayon__('Allow Mixed Language Highlighting with delimiters and tags.') . self::help_button('http://aramk.com/blog/2011/12/25/mixed-language-highlighting-in-crayon/'))); echo '<div class="crayon-hide-inline-only">'; self::checkbox(array(CrayonSettings::SHOW_MIXED, crayon__('Show Mixed Language Icon (+)'))); echo '</div>'; self::checkbox(array(CrayonSettings::TAB_CONVERT, crayon__('Convert tabs to spaces'))); self::span(crayon__('Tab size in spaces') . ': '); self::textbox(array('id' => CrayonSettings::TAB_SIZE, 'size' => 2, 'break' => TRUE)); self::span(crayon__('Blank lines before code:') . ' '); self::textbox(array('id' => CrayonSettings::WHITESPACE_BEFORE, 'size' => 2, 'break' => TRUE)); self::span(crayon__('Blank lines after code:') . ' '); self::textbox(array('id' => CrayonSettings::WHITESPACE_AFTER, 'size' => 2, 'break' => TRUE)); } public static function tags() { self::checkbox(array(CrayonSettings::INLINE_TAG, crayon__('Capture Inline Tags') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::INLINE_WRAP, crayon__('Wrap Inline Tags') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::CODE_TAG_CAPTURE, crayon__('Capture <code> as')), FALSE); echo ' '; self::dropdown(CrayonSettings::CODE_TAG_CAPTURE_TYPE, FALSE); echo self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/') . '<br/>'; self::checkbox(array(CrayonSettings::BACKQUOTE, crayon__('Capture `backquotes` as <code>') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::CAPTURE_PRE, crayon__('Capture <pre> tags as Crayons') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); echo '<div class="note" style="width: 350px;">', sprintf(crayon__("Using this markup for Mini Tags and Inline tags is now %sdepreciated%s! Use the %sTag Editor%s instead and convert legacy tags."), '<a href="http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/" target="_blank">', '</a>', '<a href="http://aramk.com/blog/2012/03/25/crayon-tag-editor/" target="_blank">', '</a>'), '</div>'; self::checkbox(array(CrayonSettings::CAPTURE_MINI_TAG, crayon__('Capture Mini Tags like [php][/php] as Crayons.') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); self::checkbox(array(CrayonSettings::INLINE_TAG_CAPTURE, crayon__('Capture Inline Tags like {php}{/php} inside sentences.') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::PLAIN_TAG, crayon__('Enable [plain][/plain] tag.') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); } public static function files() { echo '<a name="files"></a>'; echo crayon__('When loading local files and a relative path is given for the URL, use the absolute path'), ': ', '<div style="margin-left: 20px">', home_url(), '/'; self::textbox(array('id' => CrayonSettings::LOCAL_PATH)); echo '</div>', crayon__('Followed by your relative URL.'); } public static function tag_editor() { $can_convert = self::load_legacy_posts(); if ($can_convert) { $disabled = ''; $convert_text = crayon__('Convert Legacy Tags'); } else { $disabled = 'disabled="disabled"'; $convert_text = crayon__('No Legacy Tags Found'); } echo '<input type="submit" name="', self::OPTIONS, '[convert]" id="convert" class="button-primary" value="', $convert_text, '"', $disabled, ' /> '; self::checkbox(array('convert_encode', crayon__("Encode")), FALSE); echo self::help_button('http://aramk.com/blog/2012/09/26/converting-legacy-tags-to-pre/'), CRAYON_BR, CRAYON_BR; $sep = sprintf(crayon__('Use %s to separate setting names from values in the <pre> class attribute'), self::dropdown(CrayonSettings::ATTR_SEP, FALSE, FALSE, FALSE)); echo '<span>', $sep, self::help_button('http://aramk.com/blog/2012/03/25/crayon-tag-editor/'), '</span><br/>'; self::checkbox(array(CrayonSettings::TAG_EDITOR_FRONT, crayon__("Display the Tag Editor in any TinyMCE instances on the frontend (e.g. bbPress)") . self::help_button('http://aramk.com/blog/2012/09/08/crayon-with-bbpress/'))); self::checkbox(array(CrayonSettings::TAG_EDITOR_SETTINGS, crayon__("Display Tag Editor settings on the frontend"))); } public static function misc() { echo crayon__('Clear the cache used to store remote code requests'), ': '; self::dropdown(CrayonSettings::CACHE, false); echo '<input type="submit" id="', self::CACHE_CLEAR, '" name="', self::CACHE_CLEAR, '" class="button-secondary" value="', crayon__('Clear Now'), '" /><br/>'; self::checkbox(array(CrayonSettings::EFFICIENT_ENQUEUE, crayon__('Attempt to load Crayon\'s CSS and JavaScript only when needed') . self::help_button('http://aramk.com/blog/2012/01/23/failing-to-load-crayons-on-pages/'))); self::checkbox(array(CrayonSettings::SAFE_ENQUEUE, crayon__('Disable enqueuing for page templates that may contain The Loop.') . self::help_button('http://aramk.com/blog/2012/01/23/failing-to-load-crayons-on-pages/'))); self::checkbox(array(CrayonSettings::COMMENTS, crayon__('Allow Crayons inside comments'))); self::checkbox(array(CrayonSettings::EXCERPT_STRIP, crayon__('Remove Crayons from excerpts'))); self::checkbox(array(CrayonSettings::MAIN_QUERY, crayon__('Load Crayons only from the main Wordpress query'))); self::checkbox(array(CrayonSettings::TOUCHSCREEN, crayon__('Disable mouse gestures for touchscreen devices (eg. MouseOver)'))); self::checkbox(array(CrayonSettings::DISABLE_ANIM, crayon__('Disable animations'))); self::checkbox(array(CrayonSettings::DISABLE_RUNTIME, crayon__('Disable runtime stats'))); } // Debug Fields =========================================================== public static function errors() { self::checkbox(array(CrayonSettings::ERROR_LOG, crayon__('Log errors for individual Crayons'))); self::checkbox(array(CrayonSettings::ERROR_LOG_SYS, crayon__('Log system-wide errors'))); self::checkbox(array(CrayonSettings::ERROR_MSG_SHOW, crayon__('Display custom message for errors'))); self::textbox(array('id' => CrayonSettings::ERROR_MSG, 'size' => 60, 'margin' => TRUE)); } public static function log() { $log = CrayonLog::log(); touch(CRAYON_LOG_FILE); $exists = file_exists(CRAYON_LOG_FILE); $writable = is_writable(CRAYON_LOG_FILE); if (!empty($log)) { echo '<div id="crayon-log-wrapper">', '<div id="crayon-log"><div id="crayon-log-text">', $log, '</div></div>', '<div id="crayon-log-controls">', '<input type="button" id="crayon-log-toggle" show_txt="', crayon__('Show Log'), '" hide_txt="', crayon__('Hide Log'), '" class="button-secondary" value="', crayon__('Show Log'), '"> ', '<input type="submit" id="crayon-log-clear" name="', self::LOG_CLEAR, '" class="button-secondary" value="', crayon__('Clear Log'), '"> ', '<input type="submit" id="crayon-log-email" name="', self::LOG_EMAIL_ADMIN . '" class="button-secondary" value="', crayon__('Email Admin'), '"> ', '<input type="submit" id="crayon-log-email" name="', self::LOG_EMAIL_DEV, '" class="button-secondary" value="', crayon__('Email Developer'), '"> ', '</div>', '</div>'; } echo '<span', (!empty($log)) ? ' class="crayon-span"' : '', '>', (empty($log)) ? crayon__('The log is currently empty.') . ' ' : ''; if ($exists) { $writable ? crayon_e('The log file exists and is writable.') : crayon_e('The log file exists and is not writable.'); } else { crayon_e('The log file does not exist and is not writable.'); } echo '</span>'; } // About Fields =========================================================== public static function info() { global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_PLUGIN_WP, $CRAYON_AUTHOR_SITE, $CRAYON_EMAIL, $CRAYON_DONATE; echo '<a name="info"></a>'; $version = '<strong>' . crayon__('Version') . ':</strong> ' . $CRAYON_VERSION; $date = $CRAYON_DATE; $developer = '<strong>' . crayon__('Developer') . ':</strong> ' . '<a href="' . $CRAYON_AUTHOR_SITE . '" target="_blank">' . $CRAYON_AUTHOR . '</a>'; $translators = '<strong>' . crayon__('Translators') . ':</strong> ' . ' Arabic (<a href="http://djennadhamza.eb2a.com/" target="_blank">Djennad Hamza</a>), Chinese Simplified (<a href="http://smerpup.com/" target="_blank">Dezhi Liu</a>, <a href="http://neverno.me/" target="_blank">Jash Yin</a>), Chinese Traditional (<a href="http://www.arefly.com/" target="_blank">Arefly</a>), Dutch (<a href="https://twitter.com/RobinRoelofsen" target="_blank">Robin Roelofsen</a>, <a href="https://twitter.com/#!/chilionsnoek" target="_blank">Chilion Snoek</a>), French (<a href="http://tech.dupeu.pl" target="_blank">Victor Felder</a>), Finnish (<a href="https://github.com/vahalan" target="_blank">vahalan</a>), German (<a href="http://www.technologyblog.de/" target="_blank">Stephan Knauß</a>), Italian (<a href="http://www.federicobellucci.net/" target="_blank">Federico Bellucci</a>), Japanese (<a href="https://twitter.com/#!/west_323" target="_blank">@west_323</a>), Korean (<a href="https://github.com/dokenzy" target="_blank">dokenzy</a>), Lithuanian (Vincent G), Persian (MahdiY), Polish (<a href="https://github.com/toszcze" target="_blank">Bartosz Romanowski</a>), Portuguese (<a href="http://www.adonai.eti.br" target="_blank">Adonai S. Canez</a>), Russian (<a href="http://simplelib.com/" target="_blank">Minimus</a>, Di_Skyer), Slovak (<a href="https://twitter.com/#!/webhostgeeks" target="_blank">webhostgeeks</a>), Slovenian (<a href="http://jodlajodla.si/" target="_blank">Jan Sušnik</a>), Spanish (<a href="http://www.hbravo.com/" target="_blank">Hermann Bravo</a>), Turkish (<a href="http://hakanertr.wordpress.com" target="_blank">Hakan</a>), Ukrainian (<a href="http://getvoip.com/blog" target="_blank">Michael Yunat</a>)'; $links = ' <a id="docs-icon" class="small-icon" title="Documentation" href="' . $CRAYON_WEBSITE . '" target="_blank"></a> <a id="git-icon" class="small-icon" title="GitHub" href="' . $CRAYON_GIT . '" target="_blank"></a> <a id="wp-icon" class="small-icon" title="Plugin Page" href="' . $CRAYON_PLUGIN_WP . '" target="_blank"></a> <a id="twitter-icon" class="small-icon" title="Twitter" href="' . $CRAYON_TWITTER . '" target="_blank"></a> <a id="gmail-icon" class="small-icon" title="Email" href="mailto:' . $CRAYON_EMAIL . '" target="_blank"></a> <div id="crayon-donate"><a href="' . $CRAYON_DONATE . '" title="Donate" target="_blank"> <img src="' . plugins_url(CRAYON_DONATE_BUTTON, __FILE__) . '"></a> </div>'; echo ' <table id="crayon-info" border="0"> <tr> <td>' . $version . ' - ' . $date . '</td> </tr> <tr> <td>' . $developer . '</td> </tr> <tr> <td>' . $translators . '</td> </tr> <tr> <td colspan="2">' . $links . '</td> </tr> </table>'; } public static function help_button($link) { return ' <a href="' . $link . '" target="_blank" class="crayon-question">' . crayon__('?') . '</a>'; } public static function plugin_row_meta($meta, $file) { global $CRAYON_DONATE; if ($file == CrayonWP::basename()) { $meta[] = '<a href="options-general.php?page=crayon_settings">' . crayon__('Settings') . '</a>'; $meta[] = '<a href="options-general.php?page=crayon_settings&theme-editor=1">' . crayon__('Theme Editor') . '</a>'; $meta[] = '<a href="' . $CRAYON_DONATE . '" target="_blank">' . crayon__('Donate') . '</a>'; } return $meta; } } // Add the settings menus if (defined('ABSPATH') && is_admin()) { // For the admin section add_action('admin_menu', 'CrayonSettingsWP::admin_load'); add_filter('plugin_row_meta', 'CrayonSettingsWP::plugin_row_meta', 10, 2); } ?> |