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);
     }
 }
 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'));
     }
 }
    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>
						';
    }
 /**
  * Converts Crayon tags found in WP to <pre> form.
  * XXX: This will alter blog content, so backup before calling.
  * XXX: Do NOT call this while updating posts or comments, it may cause an infinite loop or fail.
  * @param $encode Whether to detect missing "decode" attribute and encode html entities in the code.
  */
 public static function convert_tags($encode = FALSE)
 {
     $crayon_posts = CrayonSettingsWP::load_legacy_posts();
     if ($crayon_posts === NULL) {
         return;
     }
     self::init_legacy_tag_bits();
     $args = array('callback' => 'CrayonWP::capture_replace_pre', 'callback_extra_args' => array('encode' => $encode), 'ignore' => FALSE, 'preserve_atts' => TRUE, 'flags' => self::$legacy_flags, 'skip_setting_check' => TRUE);
     foreach ($crayon_posts as $postID) {
         $post = get_post($postID);
         $post_content = $post->post_content;
         $post_captures = self::capture_crayons($postID, $post_content, array(), $args);
         if ($post_captures['has_captured'] === TRUE) {
             $post_obj = array();
             $post_obj['ID'] = $postID;
             $post_obj['post_content'] = addslashes($post_captures['content']);
             wp_update_post($post_obj);
             CrayonLog::syslog("Converted Crayons in post ID {$postID} to pre tags", 'CONVERT');
         }
         if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) {
             $comments = get_comments(array('post_id' => $postID));
             foreach ($comments as $comment) {
                 $commentID = $comment->comment_ID;
                 $comment_captures = self::capture_crayons($commentID, $comment->comment_content, array(CrayonSettings::DECODE => TRUE), $args);
                 if ($comment_captures['has_captured'] === TRUE) {
                     $comment_obj = array();
                     $comment_obj['comment_ID'] = $commentID;
                     $comment_obj['comment_content'] = $comment_captures['content'];
                     wp_update_comment($comment_obj);
                     CrayonLog::syslog("Converted Crayons in post ID {$postID}, comment ID {$commentID} to pre tags", 'CONVERT');
                 }
             }
         }
     }
     self::refresh_posts();
 }
"></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>
 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>';
 }
    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;
    }
 public static function has_changed($input, $setting, $value)
 {
     return $input == $setting && $value != CrayonGlobalSettings::val($setting);
 }
    public static function help()
    {
        global $CRAYON_WEBSITE;
        if (CrayonGlobalSettings::val(CrayonSettings::HIDE_HELP)) {
            return;
        }
        $url = plugins_url(CRAYON_AJAX_PHP, __FILE__) . '?' . CrayonSettings::HIDE_HELP . '=1';
        $web = $CRAYON_WEBSITE;
        echo '
<div id="crayon-help" class="updated settings-error crayon-help">
	<p><strong>Howdy, coder!</strong> Thanks for using Crayon. Use <strong>help</strong> on the top of this page to learn how to use the shortcode and basic features, or check out my <a href="#info">Twitter & Email</a>. For online help and info, visit <a target="_blank" href="' . $web, '">here</a>. <a class="crayon-help-close" url="' . $url . '">X</a></p>
</div>
';
    }
 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();
     }
 }