public function go() { //$feed = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/_add-ons/wordpress/wp_posts.xml'); //$items = simplexml_load_string($feed); $posts_object = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/_add-ons/wordpress/roobottom_old_posts.xml'); $posts = object_to_array($posts_object); $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/01-blog/'; foreach ($posts['table'] as $post) { if ($post['column'][8] == "publish") { $slug = Slug::make($post['column'][5]); $slug = preg_replace('/[^a-z\\d]+/i', '-', $slug); if (substr($slug, -1) == '-') { $slug = substr($slug, 0, -1); } $date = date('Y-m-d-Hi', strtotime($post['column'][3])); $file = $date . "-" . $slug . ".md"; if (!File::exists($yaml_path . $file)) { $yaml = []; $yaml['title'] = $post['column'][5]; $content = $post['column'][4]; $markdown = new HTML_To_Markdown($content, array('header_style' => 'atx')); File::put($yaml_path . $file, YAML::dump($yaml) . '---' . "\n" . $markdown); } echo $slug . "-" . $date; echo "<br/><hr/><br/>"; } } return "ok"; }
public function control_panel__add_routes() { $app = \Slim\Slim::getInstance(); $app->get('/globes', function () use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); Statamic_View::set_templates(array('globes-overview'), __DIR__ . '/templates'); $data = $this->tasks->getThemeSettings(); $app->render(null, array('route' => 'globes', 'app' => $app) + $data); })->name('globes'); // Update global vars $app->post('/globes/update', function () use($app) { authenticateForRole('admin'); doStatamicVersionCheck($app); $data = $this->tasks->getThemeSettings(); $vars = Request::fetch('pageglobals'); foreach ($vars as $name => $var) { foreach ($data['globals'] as $key => $item) { if ($item['name'] === $name) { $data['globals'][$key]['value'] = $var; } } } File::put($this->tasks->getThemeSettingsPath(), YAML::dump($data, 1)); $app->flash('success', Localization::fetch('update_success')); $app->redirect($app->urlFor('globes')); }); }
protected function execute(InputInterface $input, OutputInterface $output) { $method = $input->getOption('method'); switch ($method) { case 'drush': $alias = $input->getOption('alias'); if (empty($alias)) { throw new RuntimeException("You must supply a valid Drush alias using the --alias argument."); } if ($alias[0] != '@') { throw new RuntimeException("Invalid alias \"{$alas}\"."); } $config = array('fetch-method' => $method, 'fetch-alias' => $alias); break; case 'dump-n-config': $config = array('fetch-method' => $method, 'fetch-dumpfile' => $input->getOption('dumpfile'), 'fetch-staging' => $input->getOption('staging')); break; default: throw new RuntimeException("Unknown fetching method \"{$method}\"."); } $fileName = 'tests/proctor/drupal.yml'; $dirName = dirname($fileName); if (!file_exists($dirName) && !mkdir($dirName, 0777, true)) { throw new RuntimeException("Could not create {$dirName}", 1); } $config = YAML::dump($config); if (file_put_contents($fileName, $config) === false) { throw new RuntimeException("Could not write {$fileName}", 1); } $output->writeln("<info>Wrote " . $fileName . "</info>"); }
/** * Function: export * Export posts, pages, etc. */ public function export() { if (!Visitor::current()->group->can("add_post")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to export content.")); } if (empty($_POST)) { return $this->display("export"); } $config = Config::current(); $trigger = Trigger::current(); $route = Route::current(); $exports = array(); if (isset($_POST['posts'])) { list($where, $params) = keywords($_POST['filter_posts'], "post_attributes.value LIKE :query OR url LIKE :query", "post_attributes"); if (!empty($_GET['month'])) { $where["created_at like"] = $_GET['month'] . "-%"; } $visitor = Visitor::current(); if (!$visitor->group->can("view_draft", "edit_draft", "edit_post", "delete_draft", "delete_post")) { $where["user_id"] = $visitor->id; } $results = Post::find(array("placeholders" => true, "drafts" => true, "where" => $where, "params" => $params)); $ids = array(); foreach ($results[0] as $result) { $ids[] = $result["id"]; } if (!empty($ids)) { $posts = Post::find(array("drafts" => true, "where" => array("id" => $ids), "order" => "id ASC"), array("filter" => false)); } else { $posts = new Paginator(array()); } $latest_timestamp = 0; foreach ($posts as $post) { if (strtotime($post->created_at) > $latest_timestamp) { $latest_timestamp = strtotime($post->created_at); } } $id = substr(strstr($config->url, "//"), 2); $id = str_replace("#", "/", $id); $id = preg_replace("/(" . preg_quote(parse_url($config->url, PHP_URL_HOST)) . ")/", "\\1," . date("Y", $latest_timestamp) . ":", $id, 1); $posts_atom = '<?xml version="1.0" encoding="utf-8"?>' . "\r"; $posts_atom .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:chyrp="http://chyrp.net/export/1.0/">' . "\r"; $posts_atom .= ' <title>' . fix($config->name) . ' Posts</title>' . "\r"; $posts_atom .= ' <subtitle>' . fix($config->description) . '</subtitle>' . "\r"; $posts_atom .= ' <id>tag:' . parse_url($config->url, PHP_URL_HOST) . ',' . date("Y", $latest_timestamp) . ':Chyrp</id>' . "\r"; $posts_atom .= ' <updated>' . date("c", $latest_timestamp) . '</updated>' . "\r"; $posts_atom .= ' <link href="' . $config->url . '" rel="self" type="application/atom+xml" />' . "\r"; $posts_atom .= ' <generator uri="http://chyrp.net/" version="' . CHYRP_VERSION . '">Chyrp</generator>' . "\r"; foreach ($posts as $post) { $title = fix($post->title(), false); fallback($title, ucfirst($post->feather) . " Post #" . $post->id); $updated = $post->updated ? $post->updated_at : $post->created_at; $tagged = substr(strstr(url("id/" . $post->id), "//"), 2); $tagged = str_replace("#", "/", $tagged); $tagged = preg_replace("/(" . preg_quote(parse_url($post->url(), PHP_URL_HOST)) . ")/", "\\1," . when("Y-m-d", $updated) . ":", $tagged, 1); $url = $post->url(); $posts_atom .= ' <entry xml:base="' . fix($url) . '">' . "\r"; $posts_atom .= ' <title type="html">' . $title . '</title>' . "\r"; $posts_atom .= ' <id>tag:' . $tagged . '</id>' . "\r"; $posts_atom .= ' <updated>' . when("c", $updated) . '</updated>' . "\r"; $posts_atom .= ' <published>' . when("c", $post->created_at) . '</published>' . "\r"; $posts_atom .= ' <link href="' . fix($trigger->filter($url, "post_export_url", $post)) . '" />' . "\r"; $posts_atom .= ' <author chyrp:user_id="' . $post->user_id . '">' . "\r"; $posts_atom .= ' <name>' . fix(oneof($post->user->full_name, $post->user->login)) . '</name>' . "\r"; if (!empty($post->user->website)) { $posts_atom .= ' <uri>' . fix($post->user->website) . '</uri>' . "\r"; } $posts_atom .= ' <chyrp:login>' . fix($post->user->login) . '</chyrp:login>' . "\r"; $posts_atom .= ' </author>' . "\r"; $posts_atom .= ' <content>' . "\r"; foreach ($post->attributes as $key => $val) { $posts_atom .= ' <' . $key . '>' . fix($val) . '</' . $key . '>' . "\r"; } $posts_atom .= ' </content>' . "\r"; foreach (array("feather", "clean", "url", "pinned", "status") as $attr) { $posts_atom .= ' <chyrp:' . $attr . '>' . fix($post->{$attr}) . '</chyrp:' . $attr . '>' . "\r"; } $trigger->filter($posts_atom, "posts_export", $post); $posts_atom .= ' </entry>' . "\r"; } $posts_atom .= '</feed>' . "\r"; $exports["posts.atom"] = $posts_atom; } if (isset($_POST['pages'])) { list($where, $params) = keywords($_POST['filter_pages'], "title LIKE :query OR body LIKE :query", "pages"); $pages = Page::find(array("where" => $where, "params" => $params, "order" => "id ASC"), array("filter" => false)); $latest_timestamp = 0; foreach ($pages as $page) { if (strtotime($page->created_at) > $latest_timestamp) { $latest_timestamp = strtotime($page->created_at); } } $pages_atom = '<?xml version="1.0" encoding="utf-8"?>' . "\r"; $pages_atom .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:chyrp="http://chyrp.net/export/1.0/">' . "\r"; $pages_atom .= ' <title>' . fix($config->name) . ' Pages</title>' . "\r"; $pages_atom .= ' <subtitle>' . fix($config->description) . '</subtitle>' . "\r"; $pages_atom .= ' <id>tag:' . parse_url($config->url, PHP_URL_HOST) . ',' . date("Y", $latest_timestamp) . ':Chyrp</id>' . "\r"; $pages_atom .= ' <updated>' . date("c", $latest_timestamp) . '</updated>' . "\r"; $pages_atom .= ' <link href="' . $config->url . '" rel="self" type="application/atom+xml" />' . "\r"; $pages_atom .= ' <generator uri="http://chyrp.net/" version="' . CHYRP_VERSION . '">Chyrp</generator>' . "\r"; foreach ($pages as $page) { $updated = $page->updated ? $page->updated_at : $page->created_at; $tagged = substr(strstr($page->url(), "//"), 2); $tagged = str_replace("#", "/", $tagged); $tagged = preg_replace("/(" . preg_quote(parse_url($page->url(), PHP_URL_HOST)) . ")/", "\\1," . when("Y-m-d", $updated) . ":", $tagged, 1); $url = $page->url(); $pages_atom .= ' <entry xml:base="' . fix($url) . '" chyrp:parent_id="' . $page->parent_id . '">' . "\r"; $pages_atom .= ' <title type="html">' . fix($page->title) . '</title>' . "\r"; $pages_atom .= ' <id>tag:' . $tagged . '</id>' . "\r"; $pages_atom .= ' <updated>' . when("c", $updated) . '</updated>' . "\r"; $pages_atom .= ' <published>' . when("c", $page->created_at) . '</published>' . "\r"; $pages_atom .= ' <link href="' . fix($trigger->filter($url, "page_export_url", $page)) . '" />' . "\r"; $pages_atom .= ' <author chyrp:user_id="' . fix($page->user_id) . '">' . "\r"; $pages_atom .= ' <name>' . fix(oneof($page->user->full_name, $page->user->login)) . '</name>' . "\r"; if (!empty($page->user->website)) { $pages_atom .= ' <uri>' . fix($page->user->website) . '</uri>' . "\r"; } $pages_atom .= ' <chyrp:login>' . fix($page->user->login) . '</chyrp:login>' . "\r"; $pages_atom .= ' </author>' . "\r"; $pages_atom .= ' <content type="html">' . fix($page->body) . '</content>' . "\r"; foreach (array("show_in_list", "list_order", "clean", "url") as $attr) { $pages_atom .= ' <chyrp:' . $attr . '>' . fix($page->{$attr}) . '</chyrp:' . $attr . '>' . "\r"; } $trigger->filter($pages_atom, "pages_export", $page); $pages_atom .= ' </entry>' . "\r"; } $pages_atom .= '</feed>' . "\r"; $exports["pages.atom"] = $pages_atom; } if (isset($_POST['groups'])) { list($where, $params) = keywords($_POST['filter_groups'], "name LIKE :query", "groups"); $groups = Group::find(array("where" => $where, "params" => $params, "order" => "id ASC")); $groups_yaml = array("groups" => array(), "permissions" => array()); foreach (SQL::current()->select("permissions", "*", array("group_id" => 0))->fetchAll() as $permission) { $groups_yaml["permissions"][$permission["id"]] = $permission["name"]; } foreach ($groups as $index => $group) { $groups_yaml["groups"][$group->name] = $group->permissions; } $exports["groups.yaml"] = YAML::dump($groups_yaml); } if (isset($_POST['users'])) { list($where, $params) = keywords($_POST['filter_users'], "login LIKE :query OR full_name LIKE :query OR email LIKE :query OR website LIKE :query", "users"); $users = User::find(array("where" => $where, "params" => $params, "order" => "id ASC")); $users_yaml = array(); foreach ($users as $user) { $users_yaml[$user->login] = array(); foreach ($user as $name => $attr) { if (!in_array($name, array("no_results", "group_id", "group", "id", "login", "belongs_to", "has_many", "has_one", "queryString"))) { $users_yaml[$user->login][$name] = $attr; } elseif ($name == "group_id") { $users_yaml[$user->login]["group"] = $user->group->name; } } } $exports["users.yaml"] = YAML::dump($users_yaml); } $trigger->filter($exports, "export"); require INCLUDES_DIR . "/lib/zip.php"; $zip = new ZipFile(); foreach ($exports as $filename => $content) { $zip->addFile($content, $filename); } $zip_contents = $zip->file(); $filename = sanitize(camelize($config->name), false, true) . "_Export_" . date("Y-m-d"); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $filename . ".zip\""); header("Content-length: " . strlen($zip_contents) . "\n\n"); echo $zip_contents; }
/** * Function: remove * Removes a configuration setting. * * Parameters: * $setting - The name of the setting to remove. */ public function remove($setting) { if (isset($this->file) and file_exists($this->file)) { $contents = str_replace("<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n", "", file_get_contents($this->file)); $this->yaml = YAML::load($contents); } # Add the setting unset($this->yaml[$setting]); # Add the PHP protection! $contents = "<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n"; # Generate the new YAML settings $contents .= YAML::dump($this->yaml); file_put_contents(INCLUDES_DIR . "/config.yaml.php", $contents); }
/** * Encode data as YAML and return YAML text * * @param Array/Object $data the data to encode * @return String the encoded data as YAML text */ public static function to_yaml($data) { load_tool('YAML'); return YAML::dump(object_to_array($data)); }
public function ajax_tag_post() { if (empty($_POST['name']) or empty($_POST['post'])) { exit("{}"); } $sql = SQL::current(); $post = new Post($_POST['post']); $tag = $_POST['name']; if (!$post->editable()) { exit("{}"); } $tags = $sql->select("post_attributes", "value", array("name" => "tags", "post_id" => $post->id)); if ($tags and $value = $tags->fetchColumn()) { $tags = YAML::load($value); } else { $tags = array(); } $tags[$tag] = sanitize($tag); $sql->replace("post_attributes", array("post_id", "name"), array("name" => "tags", "value" => YAML::dump($tags), "post_id" => $post->id)); exit("{ url: \"" . url("tag/" . $tags[$tag], MainController::current()) . "\", tag: \"" . $_POST['name'] . "\" }"); }
<?php header('Content-Type: text/plain'); load_tool('YAML'); // Get the data to encode into YAML if (!isset($data)) { $data = array(); } // Now for our elegant YAML encoding echo YAML::dump($data);
public function admin_edit_aggregate($admin) { if (empty($_GET['id'])) { error(__("No ID Specified"), __("An ID is required to delete an aggregate.", "aggregator")); } if (!Visitor::current()->group->can("edit_aggregate")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this aggregate.", "aggregator")); } $admin->context["users"] = User::find(); $config = Config::current(); $aggregate = $config->aggregates[$_GET['id']]; if (empty($_POST)) { return $admin->display("edit_aggregate", array("users" => User::find(), "aggregate" => array("name" => $_GET['id'], "url" => $aggregate["url"], "feather" => $aggregate["feather"], "author" => $aggregate["author"], "data" => preg_replace("/---\n/", "", YAML::dump($aggregate["data"]))))); } if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } $aggregate = array("url" => $_POST['url'], "last_updated" => 0, "feather" => $_POST['feather'], "author" => $_POST['author'], "data" => YAML::load($_POST['data'])); unset($config->aggregates[$_GET['id']]); $config->aggregates[$_POST['name']] = $aggregate; $config->set("aggregates", $config->aggregates); $config->set("last_aggregation", 0); // to force a refresh Flash::notice(__("Aggregate updated.", "aggregator"), "/admin/?action=manage_aggregates"); }
/** * Parses the given $content array and puts a file to this plugin's namespaced storage * * @param string $filename Name of file to put * @param array $content Array to parse and write to file * @return void */ public function putYAML($filename, Array $content) { $this->verifyStorageFolder(); $this->put($filename, YAML::dump($content)); }
/** * Builds a file with YAML front-matter * * @param array $data Front-matter data * @param string $content Content * @return string */ public static function buildContent(array $data, $content) { $file_content = "---\n"; $file_content .= preg_replace('/\\A^---\\s/ism', "", YAML::dump($data)); $file_content .= "---\n"; $file_content .= $content; return $file_content; }
/** * Parses the given $content array and puts a file to this plugin's namespaced cache * * @param string $filename Name of file to put * @param array $content Array to parse and write to file * @return int */ public function putYAML($filename, array $content) { return $this->put($filename, YAML::dump($content)); }
public function createPhotoCollection() { $yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/photos/'; $files = glob($yaml_path . '*.{md,collection}', GLOB_BRACE); $arr_files = []; //put each file into an array foreach ($files as $file) { if (basename($file) != "page.md") { $temp = array('date' => substr(basename($file), 0, 10), 'time' => substr(basename($file), 11, 4), 'hour' => substr(basename($file), 11, 2), 'file' => basename($file)); $arr_files[] = $temp; } } //now split these into more arrays, grouped by date. //this is where we're loosing a file $last_date = $arr_files[0]['date']; $arr_groups = []; $i = 0; foreach ($arr_files as $file) { if ($last_date != $file['date']) { $i++; } $arr_groups[$i][] = $file; $last_date = $file['date']; } reset($arr_groups); //now further split this into similar times (+ or - 2 hours of eachother) $last_time = $arr_groups[0][0]['hour']; foreach ($arr_groups as $group) { if (count($group) > 1) { $last_time = $group[0]['hour']; foreach ($group as $item) { $max = $last_time + 2; $min = $last_time - 2; if ($min < $item['hour'] && $item['hour'] > $max) { $i++; } $time_groups[$i][] = $item; $last_time = $item['hour']; } $i++; } } //now write out these groups into new YAML files. foreach ($time_groups as $times) { $YAML_arr = []; $images_arr = []; $i = 0; if (count($times) > 1) { foreach ($times as $item) { //convert this array into the -images part of the YAML $images_arr[] = YAML::parseFile($yaml_path . $item['file']); $i++; } $YAML_arr['title'] = $images_arr[0]['title']; $YAML_arr['cover'] = $images_arr[0]['image']; $YAML_arr['first_time'] = $times[0]['time']; $YAML_arr['last_time'] = $times[$i - 1]['time']; $YAML_arr['images'] = $images_arr; $slug = Slug::make($images_arr[0]['flickr_id']); $file = $times[0]['date'] . "-" . $times[0]['time'] . "-" . $slug . ".md"; if (!File::exists($yaml_path . "collections/" . $file)) { File::put($yaml_path . "collections/" . $file, YAML::dump($YAML_arr) . '---' . "\n"); foreach ($times as $item) { $arhive_file = $archive_file = preg_replace('"\\.md$"', '.collection', $item['file']); if (File::exists($yaml_path . $item['file'])) { rename($yaml_path . $item['file'], $yaml_path . $archive_file); } } } } } return true; }
/** * Function: update * Updates the version. * * Parameters: * $title - The new title. * $description - The new description. */ public function update($number = null, $description = null, $compatible = null, $tags = null, $filename = null, $image = null, $loves = null, $downloads = null, $extension = null, $created_at = null, $updated_at = null) { if ($this->no_results) { return false; } $sql = SQL::current(); $trigger = Trigger::current(); $old = clone $this; if (is_array($tags)) { $tags = array_map("strip_tags", $tags); $compatible = array_map("strip_tags", $compatible); $tags = array_combine($tags, array_map("sanitize", $tags)); } foreach (array("number", "description", "compatible", "tags", "filename", "image", "loves", "downloads", "extension_id", "created_at", "updated_at") as $attr) { if (substr($attr, -3) == "_id") { $arg = ${substr($attr, 0, -3)}; $this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr}); } elseif ($attr == "updated_at") { if (${$attr} === null) { $this->{$attr} = ${$attr} = datetime(); } elseif (${$attr} === false) { $this->{$attr} = ${$attr} = $this->{$attr}; } else { $this->{$attr} = ${$attr}; } } else { $this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr}; } } $sql->update("versions", array("id" => $this->id), array("number" => $number, "description" => $description, "compatible" => is_array($compatible) ? YAML::dump($compatible) : $compatible, "tags" => is_array($tags) ? YAML::dump($tags) : $tags, "filename" => $filename, "image" => $image, "loves" => $loves, "downloads" => $downloads, "extension_id" => $extension_id, "created_at" => $created_at, "updated_at" => $updated_at)); $trigger->call("update_version", $this, $old); if (module_enabled("cacher")) { Modules::$instances["cacher"]->regenerate(); } }
/** * Builds a file with YAML front-matter * * @param array $data Front-matter data * @param string $content Content * @return string */ public static function buildContent(array $data, $content) { Debug::increment('content', 'files_built'); $file_content = "---\n"; $file_content .= preg_replace('/\\A^---\\s/ism', "", YAML::dump($data)); $file_content .= "---\n"; $file_content .= $content; return $file_content; }
/** * Function: remove * Removes a setting if it exists. * * Parameters: * $setting - The setting to remove. */ static function remove($setting) { if (!self::check($setting)) { return; } unset(Config::$yaml["config"][$setting]); $protection = "<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n"; $dump = $protection . YAML::dump(Config::$yaml["config"]); echo _f("Removing %s setting...", array($setting)) . test(@file_put_contents(INCLUDES_DIR . "/config.yaml.php", $dump)); }
function fix_quotes() { $sql = SQL::current(); if (!($tags = $sql->select("post_attributes", array("post_id", "value"), array("name" => "tags")))) { return; } foreach ($tags->fetchAll() as $attr) { $sql->replace("post_attributes", array("post_id" => $attr["post_id"], "name" => "tags", "value" => YAML::dump(YAML::load($attr["value"])))); } }
/** * Function: update * Updates the revision. * * Parameters: * $title - The new title. * $description - The new description. */ public function update($body = null, $changes = null, $ticket = null, $user = null, $created_at = null, $updated_at = null) { if ($this->no_results) { return false; } $old = clone $this; foreach (array("body", "changes", "ticket_id", "user_id", "created_at", "updated_at") as $attr) { if (substr($attr, -3) == "_id") { $arg = ${substr($attr, 0, -3)}; $this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr}); } elseif ($attr == "updated_at") { $this->{$attr} = ${$attr} = datetime(); } else { $this->{$attr} = ${$attr} = ${$attr} === null ? $this->{$attr} : ${$attr}; } } $sql = SQL::current(); $sql->update("revisions", array("id" => $this->id), array("body" => $body, "changes" => YAML::dump($changes), "ticket_id" => $ticket_id, "user_id" => $user_id, "created_at" => $created_at, "updated_at" => $updated_at)); Trigger::current()->call("update_revision", $this, $old); if (module_enabled("cacher")) { Modules::$instances["cacher"]->regenerate(); } }