function substring_between($haystack, $left_needle, $right_needle, $from_end = false) { return substring_before(substring_after($haystack, $left_needle), $right_needle, $from_end); }
<a href="javascript:<?= rawurlencode(str_replace('EXTRA', '', $bookmarklet_code)) ?>">Draft Article</a> </p> <p> Draft link code:<br/> <textarea>javascript:<?= h(rawurlencode(str_replace('EXTRA', 'is-link=1', $bookmarklet_code))) ?></textarea> </p> <p> Draft article code:<br/> <textarea>javascript:<?= h(rawurlencode(str_replace('EXTRA', '', $bookmarklet_code))) ?></textarea> </p> <? exit; } $url = substring_before(normalize_space($_GET['u']), ' '); $title = normalize_space($_GET['t']); $selection = trim($_GET['s']); $is_link = isset($_GET['is-link']) && intval($_GET['is-link']); $slug = trim(preg_replace('/[^a-z0-9-]+/ms', '-', strtolower(summarize($title, 60))), '-'); if (! $slug) $slug = 'draft'; if ($selection) { $body = "> " . str_replace("\n", "\n> ", trim($selection)) . "\n\n"; if (! $is_link) $body = "[$title]($url):\n\n" . $body; } else { $body = ''; } $draft_contents = $title . "\n" .
public static function update_pages() { foreach (self::changed_files_in_directory(self::$source_path . '/pages') as $filename => $info) { self::$changes_were_written = true; if (!file_exists($filename)) { if (ends_with($filename, self::$post_extension)) { error_log("Deleted page {$filename}"); $dest_filename = self::$dest_path . '/' . substring_before(basename($filename), '.', true); if (file_exists($dest_filename)) { safe_unlink($dest_filename); } } continue; } if (substr($filename, -strlen(self::$post_extension)) == self::$post_extension) { $post = new Post($filename, true); $post->slug = basename($filename, self::$post_extension); error_log("Writing page [{$post->slug}]"); $post->write_page(true); } } }
public static function write_index($dest_path, $title, $type, array $posts, $template = 'main.html', $archive_array = false, $seq_count = 0) { $posts_data = array(); foreach ($posts as $p) { $posts_data[] = $p->array_for_template(); } $t = new Template($template); $t->content = array('page-title' => html_entity_decode(SmartyPants($title), ENT_QUOTES, 'UTF-8'), 'blog-title' => html_entity_decode(SmartyPants(self::$blog_title), ENT_QUOTES, 'UTF-8'), 'blog-url' => self::$blog_url, 'blog-description' => html_entity_decode(SmartyPants(self::$blog_description), ENT_QUOTES, 'UTF-8'), 'page-type' => $type, 'posts' => $posts_data, 'previous_page_url' => false, 'next_page_url' => $seq_count > 1 ? substring_after(substring_before($dest_path, '.', true), Updater::$dest_path) . '-2' : false, 'archives' => $archive_array ? $archive_array : array()); $output_html = $t->outputHTML(); $output_path = dirname($dest_path); if (!file_exists($output_path)) { mkdir_as_parent_owner($output_path, 0755, true); } file_put_contents_as_dir_owner($dest_path, $output_html); }
public static function update_pages() { $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(self::$source_path . '/pages'), RecursiveIteratorIterator::SELF_FIRST); foreach ($dir as $d) { if (is_dir($d)) { $n = str_replace(self::$source_path . '/pages', '', $d); if (!file_exists(self::$dest_path . '/' . $n)) { mkdir_as_parent_owner(self::$dest_path . '/' . $n, 0755, true); } } } foreach (self::changed_files_in_directory(self::$source_path . '/pages') as $filename => $info) { self::$changes_were_written = true; $child_dir = str_replace(self::$source_path . '/pages', '', dirname($filename)); if (!file_exists($filename)) { if (ends_with($filename, self::$post_extension)) { error_log("Deleted page {$filename}"); $dest_filename = self::$dest_path . $child_dir . '/' . (substring_before(basename($filename), '.', true) . '.html'); if (file_exists($dest_filename)) { safe_unlink($dest_filename); } } continue; } if (substr($filename, -strlen(self::$post_extension)) == self::$post_extension) { $post = new Post($filename, true); $post->slug = basename($filename, self::$post_extension); error_log("Writing page [{$post->slug}]"); $post->write_page($child_dir, true); } } }