コード例 #1
0
 public static function syslog($var = NULL, $title = '', $trim_url = TRUE)
 {
     if (CrayonGlobalSettings::val(CrayonSettings::ERROR_LOG_SYS)) {
         $title = empty($title) ? 'SYSTEM ERROR' : $title;
         self::log($var, $title, $trim_url);
     }
 }
コード例 #2
0
 public function detect($path, $fallback_id = NULL)
 {
     $this->load();
     extract(pathinfo($path));
     // If fallback id if given
     if ($fallback_id == NULL) {
         // Otherwise use global fallback
         $fallback_id = CrayonGlobalSettings::get(CrayonSettings::FALLBACK_LANG);
     }
     // Attempt to use fallback
     $fallback = $this->get($fallback_id);
     // Use extension before trying fallback
     $extension = isset($extension) ? $extension : '';
     if (!empty($extension) && ($lang = $this->ext($extension)) || ($lang = $this->get($extension))) {
         // If extension is found, attempt to find a language for it.
         // If that fails, attempt to load a language with the same id as the extension.
         return $lang;
     } else {
         if ($fallback != NULL || ($fallback = $this->get_default())) {
             // Resort to fallback if loaded, or fallback to default
             return $fallback;
         } else {
             // No language found
             return NULL;
         }
     }
 }
 public static function init_settings()
 {
     if (!self::$settings) {
         // Add settings
         CrayonSettingsWP::load_settings(TRUE);
         self::$settings = array('url' => plugins_url(CRAYON_TE_CONTENT_PHP, __FILE__), 'home_url' => home_url(), 'css' => 'crayon-te', 'used' => CrayonGlobalSettings::val(CrayonSettings::TINYMCE_USED), 'used_setting' => CrayonSettings::TINYMCE_USED, 'ajax_url' => plugins_url(CRAYON_AJAX_PHP, dirname(dirname(__FILE__))), 'css_selected' => 'crayon-selected', 'code_css' => '#crayon-code', 'url_css' => '#crayon-url', 'url_info_css' => '#crayon-te-url-info', 'lang_css' => '#crayon-lang', 'title_css' => '#crayon-title', 'mark_css' => '#crayon-mark', 'inline_css' => 'crayon-inline', 'inline_hide_css' => 'crayon-hide-inline', 'inline_hide_only_css' => 'crayon-hide-inline-only', 'hl_css' => '#crayon-highlight', 'switch_html' => '#content-html', 'switch_tmce' => '#content-tmce', 'tinymce_button' => '#content_crayon_tinymce', 'submit_css' => 'crayon-te-submit', 'submit_wrapper_css' => '#crayon-te-submit-wrapper', 'data_value' => 'data-value', 'attr_sep' => CrayonGlobalSettings::val_str(CrayonSettings::ATTR_SEP), 'css_sep' => '_', 'fallback_lang' => CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG), 'dialog_title_add' => crayon__('Add Crayon Code'), 'dialog_title_edit' => crayon__('Edit Crayon Code'), 'submit_add' => crayon__('Add'), 'submit_edit' => crayon__('Save'));
     }
 }
コード例 #4
0
function crayon_resources()
{
    global $CRAYON_VERSION;
    $plugin_url = CrayonGlobalSettings::plugin_path();
    // jQuery only needed once! Don't have two jQuerys, so remove if you've already got one in your header :)
    crayon_print_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', $CRAYON_VERSION);
    crayon_print_style('crayon-style', $plugin_url . CRAYON_STYLE, $CRAYON_VERSION);
    crayon_print_script('crayon_util_js', $plugin_url . CRAYON_JS_UTIL, $CRAYON_VERSION);
    crayon_print_script('crayon-js', $plugin_url . CRAYON_JS, $CRAYON_VERSION);
    crayon_print_script('crayon-jquery-popup', $plugin_url . CRAYON_JQUERY_POPUP, $CRAYON_VERSION);
}
コード例 #5
0
 function __construct()
 {
     $this->set_default(self::DEFAULT_FONT, self::DEFAULT_FONT_NAME);
     $this->directory(CRAYON_FONT_PATH);
     $this->relative_directory(CRAYON_FONT_DIR);
     $this->extension('css');
     CrayonLog::debug("Setting font directories");
     $upload = CrayonGlobalSettings::upload_path();
     if ($upload) {
         $this->user_directory($upload . CRAYON_FONT_DIR);
         if (!is_dir($this->user_directory())) {
             CrayonGlobalSettings::mkdir($this->user_directory());
             CrayonLog::debug($this->user_directory(), "THEME DIR");
         }
     } else {
         CrayonLog::syslog("Upload directory is empty: " . $upload);
     }
     CrayonLog::debug($this->directory());
     CrayonLog::debug($this->user_directory());
 }
 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) {
         echo CrayonResources::fonts()->get_css($font_id);
     }
     // Load custom code based on language
     $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG);
     $path = CrayonGlobalSettings::plugin_path() . CRAYON_UTIL_DIR . '/sample/' . $lang . '.txt';
     if (isset($_POST[self::SAMPLE_CODE])) {
         $crayon->code($_POST[self::SAMPLE_CODE]);
     } else {
         if ($lang && @file_exists($path)) {
             $crayon->url($path);
         } else {
             $code = "\n// A sample class\nclass Human {\n\tprivate int age = 0;\n\tpublic void birthday() {\n\t\tage++;\n\t\tprint('Happy Birthday!');\n\t}\n}\n";
             $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;
 }
コード例 #7
0
 function settings($mixed = NULL)
 {
     if ($this->settings == NULL) {
         $this->settings = CrayonGlobalSettings::get_obj();
     }
     if ($mixed === NULL) {
         return $this->settings;
     } else {
         if (is_string($mixed)) {
             return $this->settings->get($mixed);
         } else {
             if (is_array($mixed)) {
                 $this->settings->set($mixed);
                 return TRUE;
             }
         }
     }
     return FALSE;
 }
コード例 #8
0
 public static function plain_code($code, $encoded = TRUE)
 {
     if (is_array($code)) {
         // When used as a preg_replace_callback
         $code = $code[1];
     }
     if (!$encoded) {
         $code = CrayonUtil::htmlentities($code);
     }
     if (CrayonGlobalSettings::val(CrayonSettings::TRIM_WHITESPACE)) {
         $code = trim($code);
     }
     return '<pre class="crayon-plain-tag">' . $code . '</pre>';
 }
コード例 #9
0
 public function dirurl($user = NULL)
 {
     $path = $user ? CrayonGlobalSettings::upload_url() : CrayonGlobalSettings::plugin_path();
     return CrayonUtil::path_slash($path . $this->relative_directory());
 }
コード例 #10
0
 public function get_url($id)
 {
     return CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_FONT_DIR) . $id . '.css';
 }
コード例 #11
0
 public static function delete()
 {
     CrayonSettingsWP::load_settings();
     $id = $_POST['id'];
     $dir = CrayonResources::themes()->dirpath_for_id($id);
     if (is_dir($dir) && CrayonResources::themes()->exists($id)) {
         try {
             CrayonUtil::deleteDir($dir);
             CrayonGlobalSettings::set(CrayonSettings::THEME, CrayonThemes::DEFAULT_THEME);
             CrayonSettingsWP::save_settings();
             echo 1;
         } catch (Exception $e) {
             CrayonLog::syslog($e->getMessage(), "THEME SAVE");
             echo -2;
         }
     } else {
         echo -1;
     }
     exit;
 }
コード例 #12
0
 public static function set_mkdir($mkdir = NULL)
 {
     if ($mkdir === NULL) {
         return self::$mkdir;
     } else {
         self::$mkdir = $mkdir;
     }
 }
コード例 #13
0
 public static function get_crayon_help_file()
 {
     // Load help
     if (($help = @file_get_contents(CRAYON_HELP_FILE)) !== FALSE) {
         $help = str_replace('{PLUGIN}', CrayonGlobalSettings::plugin_path(), $help);
     } else {
         $help = 'Help failed to load... Try <a href="#info">these</a> instead.';
     }
     return $help;
 }
コード例 #14
0
<?php

// Used to send requests to db from jQuery
require_once dirname(dirname(__FILE__)) . '/crayon_wp.class.php';
require_once CrayonSettingsWP::wp_load_path();
CrayonSettingsWP::load_settings(true);
//echo json_encode(CrayonGlobalSettings::get());
$allowed = array(CrayonSettings::HIDE_HELP, CrayonSettings::TINYMCE_USED);
//var_dump($_GET);
foreach ($allowed as $allow) {
    if (array_key_exists($allow, $_GET)) {
        CrayonGlobalSettings::set($allow, $_GET[$allow]);
        CrayonSettingsWP::save_settings();
    }
}
コード例 #15
0
"></textarea></td>
		</tr>
		<tr class="crayon-tr-center">
			<th id="crayon-url-th"><?php 
crayon_e('URL');
?>
</th>
			<td>
				<?php 
CrayonTEContent::textbox('url', array('placeholder' => crayon__('Relative local path or absolute URL')));
?>
				<div id="crayon-te-url-info" class="crayon-te-info">
				<?php 
crayon_e("If the URL fails to load, the code above will be shown instead. If no code exists, an error is shown.");
echo ' ';
printf(crayon__('If a relative local path is given it will be appended to %s - which is defined in %sCrayon &gt; Settings &gt; Files%s.'), '<span class="crayon-te-quote">' . get_home_url() . '/' . CrayonGlobalSettings::val(CrayonSettings::LOCAL_PATH) . '</span>', '<a href="options-general.php?page=crayon_settings" target="_blank">', '</a>');
?>
			</div>
			</td>
		</tr>
		<tr>
			<td id="crayon-te-submit-wrapper" colspan="2" style="text-align: center;">
				<?php 
CrayonTEContent::submit();
?>
			</td>
		</tr>
<!--		<tr>-->
<!--			<td colspan="2"><div id="crayon-te-warning" class="updated crayon-te-info"></div></td>-->
<!--		</tr>-->
		<tr>
コード例 #16
0
 public static function plugin_path($plugin_path = NULL)
 {
     if ($plugin_path === NULL) {
         return self::$plugin_path;
     } else {
         self::$plugin_path = CrayonUtil::path_slash($plugin_path);
     }
 }
コード例 #17
0
 public static function capture_replace_pre($capture, $original, $id, $is_inline, $wp_content, $args = array())
 {
     $code = $capture['code'];
     $oldAtts = $capture['atts'];
     $newAtts = array();
     $encode = isset($args['encode']) ? $args['encode'] : FALSE;
     if (!isset($oldAtts[CrayonSettings::DECODE]) && $encode) {
         // Encode the content, since no decode information exists.
         $code = CrayonUtil::htmlentities($code);
     }
     // We always set decode=1 irrespectively - so at this point the code is assumed to be encoded
     $oldAtts[CrayonSettings::DECODE] = TRUE;
     $newAtts['class'] = CrayonUtil::html_attributes($oldAtts, CrayonGlobalSettings::val_str(CrayonSettings::ATTR_SEP), '');
     return str_replace($original, CrayonUtil::html_element('pre', $code, $newAtts), $wp_content);
 }
コード例 #18
0
    public static function content()
    {
        CrayonSettingsWP::load_settings();
        $langs = CrayonLangs::sort_by_name(CrayonParser::parse_all());
        $curr_lang = CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG);
        $themes = CrayonResources::themes()->get();
        $curr_theme = CrayonGlobalSettings::val(CrayonSettings::THEME);
        $fonts = CrayonResources::fonts()->get();
        $curr_font = CrayonGlobalSettings::val(CrayonSettings::FONT);
        CrayonTagEditorWP::init_settings();
        ?>

    <div id="crayon-te-content" class="crayon-te">
        <div id="crayon-te-bar">
            <div id="crayon-te-bar-content">
                <div id="crayon-te-title">Title</div>
                <div id="crayon-te-controls">
                    <a id="crayon-te-ok" href="#"><?php 
        crayon_e('OK');
        ?>
</a> <span
                        class="crayon-te-seperator">|</span> <a id="crayon-te-cancel"
                                                                href="#"><?php 
        crayon_e('Cancel');
        ?>
</a>
                </div>
            </div>
        </div>

        <table id="crayon-te-table" class="describe">
            <tr class="crayon-tr-center">
                <th><?php 
        crayon_e('Title');
        ?>
                </th>
                <td class="crayon-nowrap"><?php 
        self::textbox('title', array('placeholder' => crayon__('A short description')));
        ?>
                    <span id="crayon-te-sub-section"> <?php 
        self::checkbox('inline');
        ?>
                        <span class="crayon-te-section"><?php 
        crayon_e('Inline');
        ?>
 </span>
			</span> <span id="crayon-te-sub-section"> <?php 
        self::checkbox('highlight');
        ?>
                        <span class="crayon-te-section"><?php 
        crayon_e("Don't Highlight");
        ?>
				</span>
			</span></td>
            </tr>
            <tr class="crayon-tr-center">
                <th><?php 
        crayon_e('Language');
        ?>
                </th>
                <td class="crayon-nowrap"><?php 
        self::select_resource('lang', $langs, $curr_lang);
        ?>
                    <span class="crayon-te-section"><?php 
        crayon_e('Line Range');
        ?>
 </span>
                    <?php 
        self::textbox('range', array('placeholder' => crayon__('(e.g. 3-5 or 3)')));
        ?>
                    <span class="crayon-te-section"><?php 
        crayon_e('Marked Lines');
        ?>
 </span>
                    <?php 
        self::textbox('mark', array('placeholder' => crayon__('(e.g. 1,2,3-5)')));
        ?>
                </td>
            </tr>
            <tr class="crayon-tr-center" style="text-align: center;">
                <th>
                    <div>
                        <?php 
        crayon_e('Code');
        ?>
                    </div>
                    <input type="button" id="crayon-te-clear"
                           class="secondary-primary" value="<?php 
        crayon_e('Clear');
        ?>
"
                           name="clear"/>
                </th>
                <td><textarea id="crayon-code" name="code"
                              placeholder="<?php 
        crayon_e('Paste your code here, or type it in manually.');
        ?>
"></textarea>
                </td>
            </tr>
            <tr class="crayon-tr-center">
                <th id="crayon-url-th"><?php 
        crayon_e('URL');
        ?>
                </th>
                <td><?php 
        self::textbox('url', array('placeholder' => crayon__('Relative local path or absolute URL')));
        ?>
                    <div id="crayon-te-url-info" class="crayon-te-info">
                        <?php 
        crayon_e("If the URL fails to load, the code above will be shown instead. If no code exists, an error is shown.");
        echo ' ';
        printf(crayon__('If a relative local path is given it will be appended to %s - which is defined in %sCrayon &gt; Settings &gt; Files%s.'), '<span class="crayon-te-quote">' . get_home_url() . '/' . CrayonGlobalSettings::val(CrayonSettings::LOCAL_PATH) . '</span>', '<a href="options-general.php?page=crayon_settings" target="_blank">', '</a>');
        ?>
                    </div>
                </td>
            </tr>
            <tr>
                <td id="crayon-te-submit-wrapper" colspan="2"
                    style="text-align: center;"><?php 
        self::submit();
        ?>
</td>
            </tr>
            <!--		<tr>-->
            <!--			<td colspan="2"><div id="crayon-te-warning" class="updated crayon-te-info"></div></td>-->
            <!--		</tr>-->
            <tr>
                <td colspan="2"><?php 
        $admin = isset($_GET['is_admin']) ? intval($_GET['is_admin']) : is_admin();
        if (!$admin && !CrayonGlobalSettings::val(CrayonSettings::TAG_EDITOR_SETTINGS)) {
            exit;
        }
        ?>
                    <hr/>
                    <div>
                        <h2 class="crayon-te-heading">
                            <?php 
        crayon_e('Settings');
        ?>
                        </h2>
                    </div>
                    <div id="crayon-te-settings-info" class="crayon-te-info">
                        <?php 
        crayon_e('Change the following settings to override their global values.');
        echo ' <span class="', CrayonSettings::SETTING_CHANGED, '">';
        crayon_e('Only changes (shown yellow) are applied.');
        echo '</span><br/>';
        echo sprintf(crayon__('Future changes to the global settings under %sCrayon &gt; Settings%s won\'t affect overridden settings.'), '<a href="options-general.php?page=crayon_settings" target="_blank">', '</a>');
        ?>
                    </div>
                </td>
            </tr>
            <?php 
        $sections = array('Theme', 'Font', 'Metrics', 'Toolbar', 'Lines', 'Code');
        foreach ($sections as $section) {
            echo '<tr><th>', crayon__($section), '</th><td>';
            call_user_func('CrayonSettingsWP::' . strtolower($section), TRUE);
            echo '</td></tr>';
        }
        ?>
        </table>
    </div>

    <?php 
        exit;
    }
コード例 #19
0
    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>
						';
    }
コード例 #20
0
 public static function wp_head()
 {
     CrayonLog::debug('head');
     self::$wp_head = TRUE;
     if (!self::$enqueued) {
         CrayonLog::debug('head: missed enqueue');
         // We have missed our chance to check before enqueuing. Use setting to either load always or only in the_post
         CrayonSettingsWP::load_settings(TRUE);
         // Ensure settings are loaded
         if (!CrayonGlobalSettings::val(CrayonSettings::EFFICIENT_ENQUEUE)) {
             CrayonLog::debug('head: force enqueue');
             // Efficient enqueuing disabled, always load despite enqueuing or not in the_post
             self::enqueue_resources();
         }
     }
     // Enqueue Theme CSS
     if (CrayonGlobalSettings::val(CrayonSettings::ENQUEUE_THEMES)) {
         self::crayon_theme_css();
     }
     // Enqueue Font CSS
     if (CrayonGlobalSettings::val(CrayonSettings::ENQUEUE_FONTS)) {
         self::crayon_font_css();
     }
 }