static function fetch($file) { if (!file_exists($file)) { return array(); } $content = f::read($file); $content = str_replace("", '', $content); $sections = preg_split('![\\r\\n]+[-]{4,}!i', $content); $data = array(); foreach ($sections as $s) { $parts = explode(':', $s); if (count($parts) == 1 && count($sections) == 1) { return $content; } $key = str::urlify($parts[0]); if (empty($key)) { continue; } $value = trim(implode(':', array_slice($parts, 1))); $data[$key] = $value; } return $data; }
/** * Sanitize a filename to strip unwanted special characters * * @param string $string The file name * @return string */ static function safe_name($string) { return str::urlify($string); }
static function write($file, $values) { if (file_exists($file) && !is_writable($file)) { return array('status' => 'error', 'msg' => l::get('writer.errors.permissions')); } $break = false; $result = ""; $keys = array(); foreach ($values as $k => $v) { $k = str::urlify($k); $k = str::ucfirst(str_replace('-', '_', $k)); if (in_array($k, $keys) || empty($k)) { continue; } $keys[] = $k; $result .= $break . $k . ': ' . trim($v); $break = "\n\n----\n\n"; } @chmod(basename($file), 0666); $write = f::write($file, $result); if (!$write || !file_exists($file)) { return array('status' => 'error', 'msg' => l::get('writer.errors.write')); } return array('status' => 'success', 'msg' => l::get('writer.success')); }
</h1> <nav> <?php $company = $page->company(); if ($company == 'Isle of Wight') { ?> <a rel="up" href="/regions/england/isle-of-wight">Isle of Wight</a> <?php } elseif ($company == 'London') { ?> <a rel="up" href="/regions/england/london">London</a> <?php } else { ?> <a rel="up" href="/companies/<?php echo preg_replace('/-railway$/', '', str::urlify($page->company())); ?> "><?php echo smartypants($page->company()); ?> </a> <?php } ?> </nav> </header> <?php if ($page->text != "") { ?> <div class="e-content prose">