/** * @param $text string * @return array * @throws MWException */ public static function loadString($text) { global $wgTranslateYamlLibrary; switch ($wgTranslateYamlLibrary) { case 'phpyaml': $ret = yaml_parse($text); if ($ret === false) { // Convert failures to exceptions throw new InvalidArgumentException("Invalid Yaml string"); } return $ret; case 'spyc': // Load the bundled version if not otherwise available if (!class_exists('Spyc')) { require_once __DIR__ . '/../libs/spyc/spyc.php'; } $yaml = spyc_load($text); return self::fixSpycSpaces($yaml); case 'syck': $yaml = self::syckLoad($text); return self::fixSyckBooleans($yaml); default: throw new MWException("Unknown Yaml library"); } }
public function testDump() { $yaml = spyc_load(file_get_contents('../spyc.yaml')); $dump = Spyc::YAMLDump($yaml); $yaml_after_dump = Spyc::YAMLLoad($dump); $this->assertEquals($yaml, $yaml_after_dump); }
public static function init(&$report) { $environments = PhpReports::$config['environments']; if (!isset($environments[$report->options['Environment']][$report->options['Database']])) { throw new Exception("No " . $report->options['Database'] . " database defined for environment '" . $report->options['Environment'] . "'"); } //make sure the syntax highlighting is using the proper class SqlFormatter::$pre_attributes = "class='prettyprint linenums lang-sql'"; $object = spyc_load($report->raw_query); $report->raw_query = array(); //if there are any included reports, add the report sql to the top if (isset($report->options['Includes'])) { $included_sql = ''; foreach ($report->options['Includes'] as &$included_report) { $included_sql .= trim($included_report->raw_query) . "\n"; } if (strlen($included_sql) > 0) { $report->raw_query[] = $included_sql; } } $report->raw_query[] = $object; //set a formatted query here for debugging. It will be overwritten below after macros are substituted. //We can not set the query here - it's not a query just yet... //$report->options['Query_Formatted'] = SqlFormatter::format($report->raw_query); }
public function generateModel($yaml_file, $dir) { $schema = spyc_load(file_get_contents($yaml_file)); $this->dir = $dir; foreach ($schema as $entity_name => $entity_definition) { $this->generateClass($dir . '/' . $entity_name . '.class.php', $entity_name, $entity_definition); } }
public function testDump() { foreach ($this->files_to_test as $file) { $yaml = spyc_load(file_get_contents($file)); $dump = Spyc::YAMLDump($yaml); $yaml_after_dump = Spyc::YAMLLoad($dump); $this->assertEquals($yaml, $yaml_after_dump); } }
/** * Parse YAML data, and return an array. * * @param string $yaml The YAML data * * @return array */ public static function parse($yaml) { $options = null; if (function_exists('yaml_parse')) { $options = yaml_parse($yaml); } else { $options = spyc_load($yaml); } if ($options === null) { throw new YamlParseException('There was an error parsing your YAML front matter'); } return $options; }
function yaml_load($input = null) { if (is_null($input)) { return array(); } $input = yaml_include_contents($input); if (is_array($input)) { return $input; } if (function_exists('syck_load')) { $datas = syck_load($input); return is_array($datas) ? $datas : array(); } else { return spyc_load($input); } }
/** * @param $text string * @return array * @throws MWException */ public static function loadString( $text ) { global $wgTranslateYamlLibrary; switch ( $wgTranslateYamlLibrary ) { case 'spyc': require_once( dirname( __FILE__ ) . '/../spyc/spyc.php' ); $yaml = spyc_load( $text ); return self::fixSpycSpaces( $yaml ); case 'syck': $yaml = self::syckLoad( $text ); return self::fixSyckBooleans( $yaml ); case 'syck-pecl': $text = preg_replace( '~^(\s*)no(\s*:\s*[a-zA-Z-_]+\s*)$~m', '\1"no"\2', $text ); return syck_load( $text ); default: throw new MWException( "Unknown Yaml library" ); } }
public function parseYml($file, $env, $dir = NULL) { static $ymldatas; $dir = ($dir === NULL ? dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'config' : $dir) . DIRECTORY_SEPARATOR; $file_path = realpath($dir . $file); if (!isset($ymldatas[$file_path])) { ob_start(); include $dir . $file; $buff = ob_get_contents(); ob_end_clean(); $buff = spyc_load($buff); $ymldatas[$file_path] = $buff; } else { $buff = $ymldatas[$file_path]; } $res = isset($buff[$env]) ? $this->mergeConfiguration($buff['all'], $buff[$env]) : $buff['all']; return $res; }
function yaml($string) { return spyc_load(trim($string)); }
function editextension($id = 0, $data_type = null, $relation_id = null) { if ($id != 0) { $this->data['data'] = $this->general_model->get_extension_detail($id); if ($this->data['data'] == null) { redirect("cpanel/extension"); } if (isset($this->data['data']['extension_more'])) { $this->data['data']['extension_more'] = spyc_load($this->data['data']['extension_more']); } if (isset($this->data['data']["data_type"]) && $this->data['data']["data_type"] != "") { $data_type = $this->data['data_type'] = $this->data['data']["data_type"]; } if (isset($this->data['data']["relation_id"]) && $this->data['data']["relation_id"] != 0) { $relation_id = $this->data['relation_id'] = $this->data['data']["relation_id"]; } } elseif ($data_type == null || $relation_id == null) { $this->session->set_flashdata('error', _l('Your request is not valid.', $this)); redirect("/cpanel/extensions/"); } else { if ($data_type != null) { $this->data['data_type'] = $data_type; } if ($relation_id != null) { $this->data['relation_id'] = $relation_id; } } $this->load->library('spyc'); if ($data_type == "page" && $relation_id != null) { $page = $this->general_model->get_page_detail($relation_id); $options = spyc_load_file(getcwd() . "/page_type.yml"); if (isset($options[$page["page_type"]])) { $this->data['page_type'] = $options[$page["page_type"]]; } } else { $this->data['fields'] = array("icon", "image", "description", "full_description"); } $icons = spyc_load_file(getcwd() . "/icons.yml"); $this->data['faicons'] = $icons["fa"]; $this->data['languages'] = $this->general_model->get_all_language(); $this->data['title'] = _l("extension", $this); $this->data['page'] = "extension"; $this->data['content'] = $this->load->view('flatlab/extension_edit', $this->data, true); $this->load->view('flatlab', $this->data); }
/** * Load a given Yaml state file * * @param string $file * @return object */ private function load_state_file($file) { if (!file_exists($file)) { WP_CLI::error(sprintf("File doesn't exist: %s", $file)); } $yaml = spyc_load(file_get_contents($file)); if (empty($yaml)) { WP_CLI::error(sprintf("Doesn't appear to be a Yaml file: %s", $file)); } return $yaml; }
* * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't * have to do anything special to choose one license or the other and you don't * have to notify anyone which license you are using. You are free to use * UniversalLanguageSelector in commercial projects as long as the copyright * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details. * * @file * @ingroup Extensions * @licence GNU General Public Licence 2.0 or later * @licence MIT License */ include __DIR__ . '/spyc.php'; print "Reading langdb.yaml...\n"; $yamlLangdb = file_get_contents('langdb.yaml'); $parsedLangdb = spyc_load($yamlLangdb); $supplementalDataFilename = 'supplementalData.xml'; $supplementalDataUrl = "http://unicode.org/repos/cldr/trunk/common/supplemental/{$supplementalDataFilename}"; $curl = curl_init($supplementalDataUrl); $supplementalDataFile = fopen($supplementalDataFilename, 'w'); curl_setopt($curl, CURLOPT_FILE, $supplementalDataFile); curl_setopt($curl, CURLOPT_HEADER, 0); print "Trying to download {$supplementalDataUrl}...\n"; $curlSuccess = curl_exec($curl); curl_close($curl); fclose($supplementalDataFile); if (!$curlSuccess) { die("Failed to download CLDR data from {$supplementalDataUrl}.\n"); } print "Downloaded {$supplementalDataFilename}, trying to parse...\n"; $supplementalData = simplexml_load_file($supplementalDataFilename);
/** * @param string $sFileName * @param array $aResultLang * * @return void */ public static function ReadAndAddLang($sFileName, &$aResultLang) { if (\file_exists($sFileName)) { $isYml = '.yml' === substr($sFileName, -4); if ($isYml) { $aLang = \spyc_load(\str_replace(array(': >-', ': |-'), array(': >', ': |'), \file_get_contents($sFileName))); if (\is_array($aLang)) { \reset($aLang); $sLangKey = key($aLang); if (isset($aLang[$sLangKey]) && is_array($aLang[$sLangKey])) { $aLang = $aLang[$sLangKey]; } else { $aLang = null; } } } else { $aLang = \RainLoop\Utils::CustomParseIniFile($sFileName, true); } if (\is_array($aLang)) { foreach ($aLang as $sKey => $mValue) { if (\is_array($mValue)) { foreach ($mValue as $sSecKey => $mSecValue) { $aResultLang[$sKey . '/' . $sSecKey] = $mSecValue; } } else { $aResultLang[$sKey] = $mValue; } } } } }
/** * Read problem description file and testdata from zip archive * and update problem with it, or insert new problem when probid=NULL. * Returns probid on success, or generates error on failure. */ function importZippedProblem($zip, $probid = NULL, $cid = -1) { global $DB, $teamid, $cdatas, $matchstrings; $prop_file = 'domjudge-problem.ini'; $yaml_file = 'problem.yaml'; $ini_keys_problem = array('name', 'timelimit', 'special_run', 'special_compare'); $ini_keys_contest_problem = array('probid', 'allow_submit', 'allow_judge', 'points', 'color'); $def_timelimit = 10; // Read problem properties $ini_array = parse_ini_string($zip->getFromName($prop_file)); if (empty($ini_array)) { if ($probid === NULL) { error("Need '" . $prop_file . "' file when adding a new problem."); } } else { // Only preserve valid keys: $ini_array_problem = array_intersect_key($ini_array, array_flip($ini_keys_problem)); $ini_array_contest_problem = array_intersect_key($ini_array, array_flip($ini_keys_contest_problem)); // Set default of 1 point for a problem if not specified if (!isset($ini_array_contest_problem['points'])) { $ini_array_contest_problem['points'] = 1; } if ($probid === NULL) { if (!isset($ini_array_contest_problem['probid'])) { error("Need 'probid' in '" . $prop_file . "' when adding a new problem."); } // Set sensible defaults for name and timelimit if not specified: if (!isset($ini_array_problem['name'])) { $ini_array_problem['name'] = $ini_array_contest_problem['probid']; } if (!isset($ini_array_problem['timelimit'])) { $ini_array_problem['timelimit'] = $def_timelimit; } // rename probid to shortname $shortname = $ini_array_contest_problem['probid']; unset($ini_array_contest_problem['probid']); $ini_array_contest_problem['shortname'] = $shortname; $probid = $DB->q('RETURNID INSERT INTO problem (' . implode(', ', array_keys($ini_array_problem)) . ') VALUES (%As)', $ini_array_problem); if ($cid != -1) { $ini_array_contest_problem['cid'] = $cid; $ini_array_contest_problem['probid'] = $probid; $DB->q('INSERT INTO contestproblem (' . implode(', ', array_keys($ini_array_contest_problem)) . ') VALUES (%As)', $ini_array_contest_problem); } } else { if (count($ini_array_problem) > 0) { $DB->q('UPDATE problem SET %S WHERE probid = %i', $ini_array_problem, $probid); } if ($cid != -1) { if ($DB->q("MAYBEVALUE SELECT probid FROM contestproblem\n\t\t\t\t WHERE probid = %i AND cid = %i", $probid, $cid)) { // Remove keys that cannot be modified: unset($ini_array_contest_problem['probid']); if (count($ini_array_contest_problem) != 0) { $DB->q('UPDATE contestproblem SET %S WHERE probid = %i AND cid = %i', $ini_array_contest_problem, $probid, $cid); } } else { $shortname = $ini_array_contest_problem['probid']; unset($ini_array_contest_problem['probid']); $ini_array_contest_problem['shortname'] = $shortname; $ini_array_contest_problem['cid'] = $cid; $ini_array_contest_problem['probid'] = $probid; $DB->q('INSERT INTO contestproblem (' . implode(', ', array_keys($ini_array_contest_problem)) . ') VALUES (%As)', $ini_array_contest_problem); } } } } // parse problem.yaml $problem_yaml = $zip->getFromName($yaml_file); if ($problem_yaml !== FALSE) { $problem_yaml_data = spyc_load($problem_yaml); if (!empty($problem_yaml_data)) { if (isset($problem_yaml_data['uuid']) && $cid != -1) { $DB->q('UPDATE contestproblem SET shortname=%s WHERE cid=%i AND probid=%i', $problem_yaml_data['uuid'], $cid, $probid); } $yaml_array_problem = array(); if (isset($problem_yaml_data['name'])) { if (is_array($problem_yaml_data['name'])) { foreach ($problem_yaml_data['name'] as $lang => $name) { // TODO: select a specific instead of the first language $yaml_array_problem['name'] = $name; break; } } else { $yaml_array_problem['name'] = $problem_yaml_data['name']; } } if (isset($problem_yaml_data['validator_flags'])) { $yaml_array_problem['special_compare_args'] = $problem_yaml_data['validator_flags']; } if (isset($problem_yaml_data['validation']) && $problem_yaml_data['validation'] == 'custom') { // search for validator $validator_files = array(); for ($j = 0; $j < $zip->numFiles; $j++) { $filename = $zip->getNameIndex($j); if (starts_with($filename, "output_validators/") && !ends_with($filename, "/")) { $validator_files[] = $filename; } } if (sizeof($validator_files) == 0) { echo "<p>Custom validator specified but not found.</p>\n"; } else { // file(s) have to share common directory $validator_dir = mb_substr($validator_files[0], 0, mb_strrpos($validator_files[0], "/")) . "/"; $same_dir = TRUE; foreach ($validator_files as $validator_file) { if (!starts_with($validator_file, $validator_dir)) { $same_dir = FALSE; echo "<p>{$validator_file} does not start with {$validator_dir}</p>\n"; break; } } if (!$same_dir) { echo "<p>Found multiple custom output validators.</p>\n"; } else { $tmpzipfiledir = exec("mktemp -d --tmpdir=" . TMPDIR, $dontcare, $retval); if ($retval != 0) { error("failed to create temporary directory"); } chmod($tmpzipfiledir, 0700); foreach ($validator_files as $validator_file) { $content = $zip->getFromName($validator_file); $filebase = basename($validator_file); $newfilename = $tmpzipfiledir . "/" . $filebase; file_put_contents($newfilename, $content); if ($filebase === 'build' || $filebase === 'run') { // mark special files as executable chmod($newfilename, 0755); } } exec("zip -r -j '{$tmpzipfiledir}/outputvalidator.zip' '{$tmpzipfiledir}'", $dontcare, $retval); if ($retval != 0) { error("failed to create zip file for output validator."); } $ovzip = file_get_contents("{$tmpzipfiledir}/outputvalidator.zip"); $probname = $DB->q("VALUE SELECT name FROM problem\n\t\t\t\t\t\t WHERE probid=%i", $probid); $ovname = preg_replace('/[^a-zA-Z0-9]/', '_', $probname) . "_cmp"; if ($DB->q("MAYBEVALUE SELECT execid FROM executable\n\t\t\t\t\t\t WHERE execid=%s", $ovname)) { // avoid name clash $clashcnt = 2; while ($DB->q("MAYBEVALUE SELECT execid FROM executable\n\t\t\t\t\t\t\t WHERE execid=%s", $ovname . "_" . $clashcnt)) { $clashcnt++; } $ovname = $ovname . "_" . $clashcnt; } $DB->q("INSERT INTO executable (execid, md5sum, zipfile,\n\t\t\t\t\t\t description, type) VALUES (%s, %s, %s, %s, %s)", $ovname, md5($ovzip), $ovzip, 'output validator for ' . $probname, 'compare'); $DB->q("UPDATE problem SET special_compare=%s\n\t\t\t\t\t\t WHERE probid=%i", $ovname, $probid); echo "<p>Added output validator '{$ovname}'.</p>\n"; } } } if (isset($problem_yaml_data['limits'])) { if (isset($problem_yaml_data['limits']['memory'])) { $yaml_array_problem['memlimit'] = 1024 * $problem_yaml_data['limits']['memory']; } if (isset($problem_yaml_data['limits']['output'])) { $yaml_array_problem['outputlimit'] = 1024 * $problem_yaml_data['limits']['output']; } } if (sizeof($yaml_array_problem) > 0) { $DB->q('UPDATE problem SET %S WHERE probid = %i', $yaml_array_problem, $probid); } } } // Add problem statement foreach (array('pdf', 'html', 'txt') as $type) { $text = $zip->getFromName('problem.' . $type); if ($text !== FALSE) { $DB->q('UPDATE problem SET problemtext = %s, problemtext_type = %s WHERE probid = %i', $text, $type, $probid); echo "<p>Added problem statement from: <tt>problem.{$type}</tt></p>\n"; break; } } // Insert/update testcases $maxrank = 1 + $DB->q('VALUE SELECT max(rank) FROM testcase WHERE probid = %i', $probid); // first insert sample, then secret data in alphabetical order foreach (array('sample', 'secret') as $type) { $ncases = 0; $datafiles = array(); for ($j = 0; $j < $zip->numFiles; $j++) { $filename = $zip->getNameIndex($j); if (starts_with($filename, "data/{$type}/") && ends_with($filename, ".in")) { $basename = basename($filename, ".in"); $fileout = "data/{$type}/" . $basename . ".ans"; if ($zip->locateName($fileout) !== FALSE) { $datafiles[] = $basename; } } } asort($datafiles); echo "<ul>\n"; foreach ($datafiles as $datafile) { $testin = $zip->getFromName("data/{$type}/{$datafile}.in"); $testout = $zip->getFromName("data/{$type}/{$datafile}.ans"); $description = $datafile; if (($descfile = $zip->getFromName("data/{$type}/{$datafile}.desc")) !== FALSE) { $description .= ": \n" . $descfile; } $image_file = $image_type = $image_thumb = FALSE; foreach (array('png', 'jpg', 'jpeg', 'gif') as $img_ext) { if (($image_file = $zip->getFromName("data/{$type}/{$datafile}" . "." . $img_ext)) !== FALSE) { list($image_thumb, $image_type) = get_image_thumb_type($image_file); break; } } $md5in = md5($testin); $md5out = md5($testout); // Skip testcases that already exist identically $id = $DB->q('MAYBEVALUE SELECT testcaseid FROM testcase WHERE md5sum_input = %s AND md5sum_output = %s AND description = %s AND sample = %i AND probid = %i', $md5in, $md5out, $description, $type == 'sample' ? 1 : 0, $probid); if (isset($id)) { echo "<li>Skipped {$type} testcase <tt>{$datafile}</tt>: already exists</li>\n"; continue; } $DB->q('INSERT INTO testcase (probid, rank, sample, md5sum_input, md5sum_output, input, output, description' . ($image_file !== FALSE ? ', image, image_thumb, image_type' : '') . ')' . 'VALUES (%i, %i, %i, %s, %s, %s, %s, %s' . ($image_file !== FALSE ? ', %s, %s, %s' : '%_ %_ %_') . ')', $probid, $maxrank, $type == 'sample' ? 1 : 0, $md5in, $md5out, $testin, $testout, $description, $image_file, $image_thumb, $image_type); $maxrank++; $ncases++; echo "<li>Added {$type} testcase from: <tt>{$datafile}.{in,ans}</tt></li>\n"; } echo "</ul>\n<p>Added {$ncases} {$type} testcase(s).</p>\n"; } // submit reference solutions if ($cid == -1) { echo "<p>No jury solutions added: problem is not linked to a contest (yet).</p>\n"; } else { if (empty($teamid)) { echo "<p>No jury solutions added: must associate team with your user first.</p>\n"; } else { if ($DB->q('VALUE SELECT allow_submit FROM problem INNER JOIN contestproblem using (probid) WHERE probid = %i AND cid = %i', $probid, $cid)) { // First find all submittable languages: $langs = $DB->q('KEYVALUETABLE SELECT langid, extensions FROM language WHERE allow_submit = 1'); $njurysols = 0; echo "<ul>\n"; for ($j = 0; $j < $zip->numFiles; $j++) { $filename = $zip->getNameIndex($j); $filename_parts = explode(".", $filename); $extension = end($filename_parts); if (!starts_with($filename, 'submissions/') || ends_with($filename, '/')) { // skipping non-submission files and directories silently continue; } unset($langid); foreach ($langs as $key => $exts) { if (in_array($extension, json_decode($exts))) { $langid = $key; break; } } if (empty($langid)) { echo "<li>Could not add jury solution <tt>{$filename}</tt>: unknown language.</li>\n"; } else { if (!($tmpfname = tempnam(TMPDIR, "ref_solution-"))) { error("Could not create temporary file in directory " . TMPDIR); } $offset = mb_strlen('submissions/'); $expectedResult = normalizeExpectedResult(mb_substr($filename, $offset, mb_strpos($filename, '/', $offset) - $offset)); $source = $zip->getFromIndex($j); $results = getExpectedResults($source); if ($results === NULL) { // annotate source code with expected result $source = "// added by import: " . $matchstrings[0] . $expectedResult . "\n" . $source; } else { if (!in_array($expectedResult, $results)) { warning("annotated result '" . implode(', ', $results) . "' does not match directory for {$filename}"); } } file_put_contents($tmpfname, $source); if (filesize($tmpfname) <= dbconfig_get('sourcesize_limit') * 1024) { submit_solution($teamid, $probid, $cid, $langid, array($tmpfname), array(basename($filename))); echo "<li>Added jury solution from: <tt>{$filename}</tt></li>\n"; $njurysols++; } else { echo "<li>Could not add jury solution <tt>{$filename}</tt>: too large.</li>\n"; } unlink($tmpfname); } } echo "</ul>\n<p>Added {$njurysols} jury solution(s).</p>\n"; } else { echo "<p>No jury solutions added: problem not submittable</p>\n"; } } } if (!in_array($cid, array_keys($cdatas))) { echo "<p>The corresponding contest is not activated yet." . "To view the submissions in the submissions list, you have to activate the contest first.</p>\n"; } return $probid; }
/** * Parse extension's config file. * * @param string $extension * @access public * @return object */ public function parseExtensionCFG($extension) { $info = new stdclass(); /* First, try ini file. before 2.5 version. */ $infoFile = "ext/{$extension}/doc/copyright.txt"; if (file_exists($infoFile)) { return (object) parse_ini_file($infoFile); } /** * Then try parse yaml file. since 2.5 version. */ /* Try the yaml of current lang, then try en. */ $lang = $this->app->getClientLang(); $infoFile = "ext/{$extension}/doc/{$lang}.yaml"; if (!file_exists($infoFile)) { $infoFile = "ext/{$extension}/doc/en.yaml"; } if (!file_exists($infoFile)) { return $info; } /* Load the yaml file and parse it into object. */ $this->app->loadClass('spyc', true); $info = (object) spyc_load(file_get_contents($infoFile)); if (isset($info->releases)) { krsort($info->releases); $info->version = key($info->releases); foreach ($info->releases[$info->version] as $key => $value) { $info->{$key} = $value; } } return $info; }
function index($ln = null) { $this->preset($ln); $this->load->library('spyc'); $page_type = spyc_load_file(getcwd() . "/page_type.yml"); $pages_render = array(); $pages = $this->general_model->get_preview_pages(); foreach ($pages as $item) { $extension_data["page_data"] = $item; $extension_data["lang"] = $ln; $extension_data["settings"] = $this->data["settings"]; $extension_data["preview_limit"] = $limit = get_extension_limit_preview($item["page_type"], $page_type); if (check_extension_order_preview($item["page_type"], $page_type)) { $extension_data["data"] = $this->general_model->get_extensions_by_page_id($item["page_id"], "extension_order", "ASC", $limit != 0 ? $limit : null); } else { $extension_data["data"] = $this->general_model->get_extensions_by_page_id($item["page_id"], "created_date", "DESC", $limit != 0 ? $limit : null); } foreach ($extension_data["data"] as &$val) { if (isset($val['extension_more'])) { $val['extension_more'] = spyc_load($val['extension_more']); } } if (check_is_gallery($item["page_type"], $page_type)) { $extension_data["gallery"] = $this->general_model->get_gallery_by_page_id($item["page_id"]); $extension_data["gallery_image"] = $this->general_model->get_gallery_image_by_page_id($item["page_id"], "created_date", "DESC", $limit != 0 ? $limit : null); } $page_header = $item['title_caption']; $page_body = $this->load->view($page_type[$item["page_type"]]["theme_preview"], $extension_data, true); array_push($pages_render, array("title" => $page_header, "body" => $page_body)); } $this->data['pages'] = $pages_render; $this->data['title'] = isset($this->data['settings']["options"]["site_title"]) ? $this->data['settings']["options"]["site_title"] : ""; $this->data['content'] = 'home'; $this->data['keyword'] = isset($this->data['settings']["options"]["site_keyword"]) ? $this->data['settings']["options"]["site_keyword"] : ""; $this->data['description'] = isset($this->data['settings']["options"]["site_description"]) ? $this->data['settings']["options"]["site_description"] : ""; $this->load->view('flatlab', $this->data, ''); }
function yaml_decode($opts, $pipe = null) { $opts = get_opts_or_pipe($opts, $pipe); return spyc_load($opts); }
function test_export_options() { global $jekyll_export; $jekyll_export->convert_options(); $config = $jekyll_export->dir . "/_config.yml"; // write the file to the temp dir $this->assertTrue(file_exists($config)); // writes the file content $contents = file_get_contents($config); $this->assertContains("description: Just another WordPress site", $contents); // writes valid YAML $yaml = spyc_load($contents); $this->assertEquals("Just another WordPress site", $yaml["description"]); $this->assertEquals("http://example.org", $yaml["url"]); $this->assertEquals("Test Blog", $yaml["name"]); }
/** * Pull the post from GitHub */ function pull() { global $wpghs; $data = $this->remote_contents(); $content = base64_decode($data->content); // Break out meta, if present preg_match("/(^---(.*)---\$)?(.*)/ms", $content, $matches); $body = array_pop($matches); if (count($matches) == 3) { $meta = spyc_load($matches[2]); } else { $meta = array(); } wp_update_post(array_merge($meta, array("ID" => $this->id, "post_content" => $body))); }
public function create_post($data, $payment) { $maps = array("MerchantID" => $payment["merchantid"], "MerchantKey" => $payment["merchantkey"], "OrderId" => $data["POrderId"], "amount" => $data["amount"], "AutoReceive" => $this->get_AutoReceive($data["apiName"]), "Receive" => $this->get_Receive($data["apiName"]), "bank" => $data["bank"], "remark1" => $data["remark1"], "remark2" => $data["remark2"], "sendmd5info" => ""); $configs = spyc_load($payment["configs"]); if (!is_array($configs)) { $this->front("接口配置出错,请联系客服", $post); } $fields = array(); foreach ($maps as $key => $val) { if (isset($configs["orm"]['send'][$key])) { $fields[$configs["orm"]['send'][$key]] = $val; } } foreach ($configs["static"] as $skey => $sval) { $fields[$skey] = $sval; } $patterns = array("/#([a-zA-Z0-9_]+)#/e", "/%([a-zA-Z0-9_]+)%/e"); $replaces = array('date("\\1")', '$fields["\\1"]'); foreach ($configs["rules"]['send'] as $rkey => $rval) { $tmp_val = preg_replace($patterns, $replaces, $rval[0]); for ($i = 1; $i < count($rval); $i++) { $funcs = explode("=", $rval[$i]); if (count($funcs) == 1) { $tmp_val = $funcs[0]($tmp_val); continue; } else { $params_str = substr($vals[$i], strlen($funcs[0]) + 1); $params = array(0 => $tmp_val); preg_replace("/\\'([^\\']*)\\'/e", '$params[]=\\1;', $params_str); foreach ($params as $p => $v) { if ($v == "###") { $params[$p] = $tmp_val; unset($params[0]); break; } } $tmp_val = call_user_func_array($funcs[0], $params); } } $fields[$rkey] = $tmp_val; } $post = array(); foreach ($configs["required"] as $required) { if (empty($fields[$required])) { $this->front("{$required} 为必填字段!", $_POST); break; } $post[$required] = $fields[$required]; } foreach ($configs["optional"] as $optional) { $post[$optional] = $fields[$optional]; } return $post; }
require_once 'config.php'; // Dangling Function function formatResponse($text) { return str_replace(array(" ", "\n"), array(" ", "<br />"), htmlspecialchars($text, ENT_QUOTES)); } // Handle Caching and Build $RAML = false; if ($cacheTimeLimit && function_exists('apc_fetch')) { $RAML = apc_fetch('RAML' . md5($RAMLsource)); } elseif (!$cacheTimeLimit && function_exists('apc_fetch')) { // Remove existing cache files apc_delete('RAML' . md5($RAMLsource)); } if (!$RAML) { $RAMLarray = spyc_load(file_get_contents($RAMLsource)); $RAML = new RAML2HTML\RAML($RAMLactionVerbs); $RAML->setIncludePath(dirname($RAMLsource) . '/'); $RAML->buildFromArray($RAMLarray); if ($cacheTimeLimit && function_exists('apc_store')) { apc_store('RAML' . md5($RAMLsource), $RAML, $cacheTimeLimit); } } // Set Current Path if (isset($_GET['path'])) { $RAML->setCurrentPath($_GET['path']); unset($_GET['path']); } // Set Current Action if (isset($_GET['action']) && $RAML->isActionValid($_GET['action'])) { $RAML->setCurrentAction($_GET['action']);
/** * Получение yaml-конфигурации из файла и сохранение её в глобальные переменные */ function mso_get_yaml($fn) { global $VAR, $TITLE, $META, $META_LINK; $key = 'yaml-' . $fn; $conf = mso_get_cache($key, 0, false, filemtime($fn)); if (!$conf) { $data = file_get_contents($fn); // проверяем вхождение /* === конфигурация === */ if (preg_match('!\\/\\* \\=\\=\\=(.*?)\\=\\=\\= \\*\\/!is', $data, $conf)) { $yaml = trim($conf[1]); // разрешено использовать php-шаблонизатор ob_start(); eval(mso_tmpl_prepare($yaml)); $yaml = ob_get_clean(); require_once ENGINE_DIR . 'yaml/Spyc.php'; $conf = spyc_load($yaml); mso_add_cache($key, $conf); } } if ($conf) { if (isset($conf['TITLE'])) { $TITLE = $conf['TITLE']; } if (isset($conf['VAR']) and is_array($conf['VAR'])) { $VAR = array_merge($VAR, $conf['VAR']); } if (isset($conf['META']) and is_array($conf['META'])) { $META = array_merge($META, $conf['META']); } if (isset($conf['META_LINK']) and is_array($conf['META_LINK'])) { $META_LINK = array_merge($META_LINK, $conf['META_LINK']); } } }
preg_replace('/[^\\d\\.]/', '', $version); } // Parse the list of modules from the docs folder require_once "../Spyc.php"; $md = file_get_contents('../multiqc/docs/README.md'); $md_parts = explode('---', $md, 3); $modules = []; if (count($md_parts) == 3) { $pages = spyc_load($md_parts[1]); if (isset($pages['MultiQC Modules'])) { foreach ($pages['MultiQC Modules'] as $sect_name => $sect) { foreach ($sect as $fn) { $mod_md = file_get_contents('../multiqc/docs/' . trim($fn)); $mod_md_parts = explode('---', $mod_md, 3); if (count($mod_md_parts) == 3) { $yaml = spyc_load($mod_md_parts[1]); $yaml['docs_url'] = 'docs/#' . strtolower(str_replace(' ', '-', $yaml['Name'])); $yaml['section'] = $sect_name; $modules[] = $yaml; } } } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1">
public function data($edit = NULL, $sec = NULL) { /******************************************** * checking if the page has a ID get paramter * for edit purposes ********************************************/ $this->load->helper('directory'); theme_add('dijit.Dialog'); // getting the content $con = new Content($edit); if (!$con->exists()) { $edit = FALSE; } else { $info = json_decode($con->info); } // creating menu if editing a content if ($edit) { $this->show_toolbar = TRUE; $this->pages = array(); $parent = $con->parent_content; $p = new Content($con->parent_content); $this->pages['up/' . $con->id] = lang('system_move_up'); $this->pages['down/' . $con->id] = lang('system_move_down'); $this->pages['chooser/' . $sec . '/' . $parent . '/' . $con->cell . '/' . $con->sort] = lang('system_add_before'); $this->pages['chooser/' . $sec . '/' . $parent . '/' . $con->cell . '/' . ($con->sort + 1)] = lang('system_add_after'); $this->pages['delete/' . $con->id] = lang('system_delete'); $this->pages['delete_children/' . $con->id] = lang('system_delete_children'); $this->pages['info/' . $con->id] = lang('system_information'); } // creating hidden properties $hidden = array(); if ($edit === FALSE) { $hidden['parent_section'] = $this->input->post("parent_section"); $hidden['parent_content'] = $this->input->post("parent_content"); $hidden['cell'] = $this->input->post("cell"); $hidden['sort'] = $this->input->post("sort"); $hidden['path'] = $this->input->post("path"); $hidden['info'] = ""; } else { $hidden['id'] = $con->id; $hidden['parent_section'] = $con->parent_section; $hidden['parent_content'] = $con->parent_content; $hidden['cell'] = $con->cell; $hidden['sort'] = $con->sort; $hidden['path'] = $con->path; $hidden['info'] = $con->info; } // action of the form button $form_ajax_url = site_url('editor/addaction'); if ($edit === FALSE) { $submit_script = "dijit.byId('basic_form').submit();"; } else { $saved_title = lang('system_save_success'); $error_occured = lang('system_error_occured'); $submit_script = <<<EOT \tdojo.xhrPost({ url: "{$form_ajax_url}", handleAs: "text", preventCache: true, content: dojo.formToObject("basic_form"), load: function(response, args) { \t\t\t Dlg = new dijit.Dialog({ \t\t\t title: "{$saved_title}", \t\t\t style: "width: 300px", \t\t\t content : response \t\t\t }); \t\t\t Dlg.show(); \t\t\t \t\t\t }, error: function(response, args) { \t\t\t\t\tDlg = new dijit.Dialog({ \t\t\t title: "{$error_occured}", \t\t\t style: "width: 300px", \t\t\t content : response \t\t\t }); \t\t\t Dlg.show(); \t\t\t } }); EOT; } $script = <<<EOT <script type="dojo/method" event="onClick" args="evt"> if( dijit.byId('info_form')!=undefined ){ \tdojo.query("[name='info']")[0].value = dojo.toJson(dijit.byId('info_form').getValues()); } \t\t{$submit_script} </script> EOT; if ($edit === FALSE) { $p_cont = new Content($hidden['parent_content']); $Basic_Form = $this->gui->form(site_url('editor/addaction'), array(lang('system_title') => $this->gui->textbox('title'), lang('system_show_in_subsection') => $this->gui->checkbox('subsection'), lang('system_view_perm') => $this->gui->permission('view', $p_cont->view), lang('system_filters') => $this->gui->file_list(site_url('editor/filter_query'), 'filter'), "" => $this->gui->button('', lang('system_save') . $script)), array('id' => 'basic_form'), $hidden); } else { $Basic_Form = $this->gui->form(site_url('editor/addaction'), array(lang('system_title') => $this->gui->textbox('title', $con->title), lang('system_show_in_subsection') => $this->gui->checkbox('subsection', 'subsection', $con->subsection), lang('system_view_perm') => $this->gui->permission('view', $con->view), lang('system_filters') => $this->gui->file_list(site_url('editor/filter_query'), 'filter', $con->filter), "" => $this->gui->button('', lang('system_save') . $script)), array('id' => 'basic_form'), $hidden); } //=============================================== /*OUR YAML OBJECT LIKE THAT variableName1: type: varType default: varDefaultValue label: varHumanizedName variableName2: type: varType default: varDefaultValue label: varHumanizedName */ $this->load->helper('spyc'); $Plugin_Data = $this->load->view('content/' . $hidden['path'], array("mode" => "config"), TRUE); $Plugin_Data = spyc_load($Plugin_Data); $Plugin_Form_Data = array(); // starting to make the form if it is exists if (!empty($Plugin_Data)) { // building each field foreach ($Plugin_Data as $key => $value) { // build the field depending on the type if (is_array($value)) { // this line gets the default value if in insertion mode and the // stored value if in the edit mode $cVal = ''; $cVal = $edit === FALSE ? @$value['default'] : @$info->{$key}; $current_field = $this->gui->textbox($key, @$value['default']); switch ($value['type']) { case "textbox": $current_field = $this->gui->textbox($key, $cVal); break; case "textarea": $current_field = $this->gui->textarea($key, $cVal); break; case "date": $current_field = $this->gui->date($key, $cVal); break; case "editor": $current_field = $this->gui->editor($key, $cVal); break; case "file": $current_field = $this->gui->file_chooser(site_url('editor/file_query'), $key, $cVal); break; case "file list": $current_field = $this->gui->file_list(site_url('editor/file_query'), $key, $cVal); break; case "folder": $current_field = $this->gui->folder_chooser(site_url('editor/folder_query'), $key, $cVal); break; case "model": $current_field = $this->gui->file_chooser(site_url('editor/model_query'), $key, $cVal); break; case "number": $current_field = $this->gui->number($key, $cVal); break; case "password": $current_field = $this->gui->password($key, $cVal); break; case "time": $current_field = $this->gui->time($key, $cVal); break; case "checkbox": $current_field = $this->gui->checkbox($key, $key, $cVal); break; case "dropdown": $current_field = $this->gui->dropdown($key, $cVal, @$value['options']); break; case "section": $current_field = $this->gui->section($key, $cVal); break; case "permission": $current_field = $this->gui->permission($key, $cVal); break; case "smalleditor": $current_field = $this->gui->smalleditor($key, $cVal); break; } } else { if (is_string($value) == TRUE) { $current_field = $this->gui->info($value); } } // checking the existance of label if (is_array($value) and array_key_exists('label', $value) == TRUE) { $Plugin_Form_Data[$value['label']] = $current_field; } else { $Plugin_Form_Data[$key] = $current_field; } } } if (count($Plugin_Form_Data) > 0) { $Plugin_Form = $this->gui->form('#', $Plugin_Form_Data, array("id" => "info_form")); $this->print_text($this->gui->accordion(array(lang('system_basic_data') => $Basic_Form, lang('system_plugin_data') => '<p>' . $Plugin_Form . '</p>'))); } else { $this->print_text($this->gui->accordion(array(lang('system_basic_data') => $Basic_Form))); } }
/** * Compare two strings containing YAML to ensure that @a $actualYaml contains at * least what the YAML string @a $expectedYaml contains. * * @return whether or not @a $actualYaml contains @a $expectedJson * @retval true @a $actualYaml contains @a $expectedJson * @retval false @a $actualYaml does not contain @a $expectedJson * * @param[in] $actualYaml the YAML string to be tested * @param[in] $expectedYaml the expected YAML string */ function checkThatYamlStringContainsYamlString($actualYaml, $expectedYaml) { $actualValue = spyc_load($actualYaml); $expectedValue = spyc_load($expectedYaml); if (!$actualValue) { return false; } return compareContents($expectedValue, $actualValue); }
public static function decode($input) { return spyc_load($input); }
static function load($username) { // check for an existing user account file $file = c::get('root.site') . '/' . c::get('panel.folder') . '/accounts/' . $username . '.php'; if (!file_exists($file)) { return false; } // load the account credentials content::start(); require $file; $account = content::end(true); $account = spyc_load($account); if (!is_array($account)) { return false; } // check for required fields $missing = a::missing($account, array('username', 'password')); if (!empty($missing)) { return false; } return $account; }
/** * Get the schema object for a state * * @param string $name Name of the state * @return object|false */ public static function get_state_schema_obj($name) { if (self::called_statically()) { return Dictator::get_instance()->get_state_schema($name); } if (!isset(self::$instance->states[$name])) { return false; } $state = self::$instance->states[$name]; $schema_file = $state['schema']; if (!file_exists($schema_file)) { $schema_file = dirname(dirname(__FILE__)) . '/schemas/' . $schema_file; } $schema_yaml = spyc_load(file_get_contents($schema_file)); return new MetaYaml($schema_yaml); }