Realising the amount of effort I put into writing templates, uploading huge amounts of files and using crappy FTP connections, I looked for a better way to post stuff.
Jekyll is a static website generator written in Ruby, is very light and didn’t take nearly as much time to install, even though I had to set up DNS records again.
Take a look at the source branch of this website.
Fork the repo and checkout both the source
and master
branches.
Make some changes to the site in the source
branch and push them.
Run publish.sh, which will build the site in the master
branch and push it.
If you’re hosting a Project Page instead of a User Page, you need to push to a gh-pages
branch instead, so edit publish.sh
to your needs. See the GitHub Pages guide.
This has some setbacks – even though I installed the Wordpress importer like so:
sudo gem install jekyll-import --pre
And followed their importing guide, my old posts are more or less broken. But I think cleaning them up will be a more long term solution, and I don’t need a PHP server anymore :)
I plan to port Crayon eventually, but that’s another story.
]]>/** * Sends an email in html and plain encodings with a file attachment. * * @param array $args Arguments associative array * 'to' (string) * 'from' (string) * 'subject' (optional string) * 'message' (HTML string) * 'plain' (optional plain string) * 'file' (optional file path of the attachment) * @see http://webcheatsheet.com/php/send_email_text_html_attachment.php */ function emailFile($args) { $to = set_default($args['to']); $from = set_default($args['from']); $subject = set_default($args['subject'], ''); $message = set_default($args['message'], ''); $plain = set_default($args['plain'], ''); $file = set_default($args['file']); // MIME $random_hash = md5(date('r', time())); $boundaryMixed = 'PHP-mixed-' . $random_hash; $boundaryAlt = 'PHP-alt-' . $random_hash; $charset = 'UTF-8'; $bits = '8bit'; // Headers $headers = "MIME-Version: 1.0"; $headers .= "Reply-To: $to\r\n"; if ($from !== NULL) { $headers .= "From: $from\r\n"; } $headers .= "Content-Type: multipart/mixed; boundary=$boundaryMixed"; if ($file !== NULL) { $info = pathinfo($file); $filename = $info['filename']; $extension = $info['extension']; $contents = @file_get_contents($file); if ($contents === FALSE) { throw new Exception("File contents of '$file' could not be read"); } $chunks = chunk_split(base64_encode($contents)); $attachment = <<<EOT --$boundaryMixed Content-Type: application/$extension; name=$filename.$extension Content-Transfer-Encoding: base64 Content-Disposition: attachment $chunks EOT; } else { $attachment = ''; } $body = <<<EOT --$boundaryMixed Content-Type: multipart/alternative; boundary=$boundaryAlt --$boundaryAlt Content-Type: text/plain; charset="$charset" Content-Transfer-Encoding: $bits $plain --$boundaryAlt Content-Type: text/html; charset="$charset" Content-Transfer-Encoding: $bits $message --$boundaryAlt-- $attachment --$boundaryMixed-- EOT; $result = @mail($to, $subject, $body, $headers); return $result; } function set_default(&$var, $default = NULL) { return isset($var) ? $var : $default; }]]>
/** * @param $path A directory * @param array $args Argument array: * hidden: If true, hidden files beginning with a dot will be included * ignoreRef: If true, . and .. are ignored * recursive: If true, this function is recursive * ignore: An array of paths to ignore * @return array Files in the directory */ public static function getFiles($path, $args = array()) { $hidden = self::set_default($args['hidden'], TRUE); $ignoreRef = self::set_default($args['ignoreRef'], TRUE); $recursive = self::set_default($args['recursive'], FALSE); $ignore = self::set_default($args['ignore'], NULL); $ignore_map = array(); if ($ignore) { foreach ($ignore as $i) { if (is_dir($i)) { $i = CrayonUtil::path_slash($i); } $ignore_map[$i] = TRUE; } } $files = glob($path . '*', GLOB_MARK); if ($hidden) { $files = array_merge($files, glob($path . '.*', GLOB_MARK)); } if ($ignoreRef || $ignore) { $result = array(); for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; if (!isset($ignore_map[$file]) && (!$ignoreRef || (basename($file) != '.' && basename($file) != '..'))) { $result[] = $file; if ($recursive && is_dir($file)) { $result = array_merge($result, self::getFiles($file, $args)); } } } } else { $result = $files; } return $result; }]]>
function array_flip_r($array) { $result = array(); foreach ($array as $k=>$v) { if (is_array($v)) { foreach ($v as $u) { _array_flip_r($result, $k, $u); } } else { _array_flip_r($result, $k, $v); } } return $result; } function _array_flip_r(&$array, $k, $v) { if (is_string($v) || is_int($v)) { $array[$v] = $k; } else { trigger_error("Values must be STRING or INTEGER", E_USER_WARNING); } }]]>
wp-content/plugins/crayon-syntax-highlighter/themes
To allow modifying these themes and preserving changes, Crayon stores User Themes under this path:
wp-content/uploads/crayon-syntax-highlighter/themes
This avoids any changes being overwritten during updates to the plugin. Stock themes can’t be deleted or modified for this reason - unless you enable CRAYON_DEBUG
in globals.php
. Of course, modifying the theme CSS is independent of the Theme Editor, but keep in mind that your changes will be lost when updating the plugin.
(window, document, jQuery)
And it will initialise jQuery.fancybox
. If I want to have my own version running independently, I’d need to provide it with a jQuery instance and a custom attribute name, say “crayonFancybox” so I can use my version without accidentally using the old Fancybox on some users’ Wordpress installs.
window.fancyboxInit = function (window, document, $, fancybox, undefined) { // Original Fancybox script content goes here };Now if you include jQuery and two different Fancybox scripts in the same page, they won’t clash:
<script type='text/javascript' src='http://code.jquery.com/jquery.min.js'></script> <script type='text/javascript' src='http://yandex.st/jquery/fancybox/1.3.4/jquery.fancybox.min.js'></script> <script src="https://raw.github.com/aramkocharyan/fancyBox/master/source/jquery.fancybox.init.pack.js" type="text/javascript"></script> <script type="text/javascript"> var jQueryCrayon = jQuery; fancyboxInit(window, document, jQueryCrayon, 'crayonFancybox'); (function($) { $(document).ready(function() { console.log("old", $.fancybox); // Old version console.log("new", $.crayonFancybox); // My new version }); })(jQueryCrayon); </script> <body> See the JS console! </body>The only downside is that you must use
$(elem).crayonFancybox
instead of $(elem).fancybox
in your scripts.
See a demo, and download the script.
]]>$[crayon lang="php" title="testing"]some code[/crayon]
Then you might like to convert your blog’s old code format into a better standard:
<pre class="lang:php decode:true" title="Testing">some code</pre>
The benefits are backwards compatibility (if Crayon is disabled or you use another highlighter) and the ability to use the Crayon Tag Editor in the visual editor of Wordpress).
Note: decode:true means that the code is encoded, so any < characters in the visual editor are really < in the HTML editor to ensure they are valid HTML entities.
Say I have this in Wordpress, switching to the HTML editor:
From Crayon 1.12 there is a new setting in the admin:
At the moment there are no detected legacy tags in any of my blog posts or comments. Lets add one:
Now in settings, we see the button available:
Clicking it will convert your legacy Crayon tag! Refresh the editor to see the change:
And of course, it should look exactly the same on the front end:
If you keep using the legacy tags and Crayon is disabled, it looks like this:
Since the legacy code is just text in the editor, it looks like text if Crayon isn’t enabled. The <pre> tag however looks much better as preformatted plain text, and it hides all of your settings in the class attribute.
One warning however, is to always backup your database before converting your tags - since this will change your post/comment content it’s safer to have something to rollback to.
The beta version of Crayon (1.12 at the time of writing) can be downloaded from GitHub.
UPDATE: As of the latest version, converting legacy tags now has an “encode” option. If selected, any legacy tag where the “decode” attribute is missing (neither true or false) has its code encoded and decode=”true” specified. This is useful if you have been using < and > instead of < and > in your [php] tags for example - this method is dangerous since disabling Crayon will mean these tags will be recognised as HTML tags. So something like this will actually be executed rather than displayed as code:
[html]<script>alert("bam!")</script>[/html]
The correct approach is to use encoded characters in all your HTML output; including your code snippets.
]]>