YAMLLoadString() public static method

The load method, when supplied with a YAML string, will do its best to convert YAML in a string into a PHP array. Pretty simple. Note: use this function if you don't want files from the file system loaded and processed as YAML. This is of interest to people concerned about security whose input is from a string. Usage: $array = Spyc::YAMLLoadString("---\n0: hello world\n"); print_r($array);
public static YAMLLoadString ( string $input ) : array
$input string String containing YAML
return array
Esempio n. 1
0
 public function read()
 {
     if (file_exists($this->file)) {
         $configuration = file_get_contents($this->file);
         $this->registry = \Spyc::YAMLLoadString($configuration);
     }
 }
 /**
  * Convert YAML to Array using Spyc converter
  *
  * @param   string  $data   Data to convert
  *
  * @return  array
  */
 public final function fromYaml($data)
 {
     if (!is_string($data)) {
         throw new Exception("Invalid data for YAML deserialization");
     }
     return \Spyc::YAMLLoadString($data);
 }
 /**
  * @param string $sYamlString
  * @return array|null
  */
 protected function parseSpyc($sYamlString)
 {
     $aData = null;
     if ($this->loadSpycYamlParser()) {
         $aData = Spyc::YAMLLoadString($sYamlString);
     }
     return $aData;
 }
 public function parse($file)
 {
     $contents = file_get_contents($file);
     preg_match_all('#(?m)/\\*\\s*(^---(\\s*$.*?)^\\.\\.\\.)\\s*#sm', $contents, $comment);
     if (!isset($comment[2]) || !isset($comment[2][0]) || !$comment[2][0]) {
         throw new ForgeJSParserException('Couldn\'t find required YAML header in JS file.');
     }
     $yaml = preg_replace('/$([\\s]+)-/m', '$1 -', trim($comment[2][0]));
     $this->meta = Spyc::YAMLLoadString($yaml);
     return $this->meta;
 }
Esempio n. 5
0
 /**
  * Get template option menu.   
  * 
  * @access public
  * @return void
  */
 public function getTemplateOptions()
 {
     $this->app->loadClass('Spyc', true);
     $folders = glob($this->app->getTplRoot() . '*');
     foreach ($folders as $folder) {
         $templateName = str_replace($this->app->getTplRoot(), '', $folder);
         $config = Spyc::YAMLLoadString(file_get_contents($folder . DS . 'doc' . DS . $this->app->getClientLang() . '.yaml'));
         $templates[$templateName] = $config['name'];
     }
     return $templates;
 }
Esempio n. 6
0
 /**
  * Un-serializes the fields.
  *
  * @param Base\Model $resource Currently processed resource.
  *
  * @static
  * @access public
  *
  * @return void
  */
 public static function unserialize(Base\Model $resource)
 {
     foreach (self::$serializedFields as $field => $type) {
         switch ($type) {
             case 'json':
                 $resource->{$field} = json_decode($resource->{$field}, true);
                 break;
             case 'yaml':
                 $resource->{$field} = \Spyc::YAMLLoadString($resource->{$field});
                 break;
             case 'serialize':
                 $resource->{$field} = unserialize($resource->{$field});
                 break;
         }
     }
 }
Esempio n. 7
0
 function beforeSave()
 {
     parent::beforeSave();
     if ($this->validate()) {
         if ($this->widget) {
             $this->widget = serialize(Spyc::YAMLLoadString($this->widget));
         }
         if ($this->rules) {
             $this->rules = serialize(Spyc::YAMLLoadString($this->rules));
         }
         if ($this->automodel) {
             $this->automodel = serialize(Spyc::YAMLLoadString($this->automodel));
         }
     }
     return true;
 }
Esempio n. 8
0
	public function getStorage()
	{
	    if(empty($this->_storage))
		{
			try 
			{
				KLoader::load('com://admin/learn.library.spyc.spyc');
				$this->_storage = Spyc::YAMLLoadString(parent::getStorage());
			}
			catch(KException $e)
			{
				throw new ComLearnDatabaseTableException($e->getMessage());
			}
		}
		
		return $this->_storage;
	}
Esempio n. 9
0
 public static function load($string, $forgiving = false)
 {
     if (substr($string, 0, 3) != '---') {
         $string = "---\n{$string}";
     }
     try {
         // if syck is available use it
         if (extension_loaded('syck')) {
             return syck_load($string);
         }
         // if not, use the symfony YAML parser
         $yaml = new sfYamlParser();
         return $yaml->parse($string);
     } catch (Exception $e) {
         if ($forgiving) {
             // if YAML document is not correct,
             // but we're forgiving, use the Spyc parser
             return Spyc::YAMLLoadString($string);
         }
         throw new Wikidot_Yaml_Exception("Can't parse the YAML string." . $e->getMessage());
     }
 }
Esempio n. 10
0
 /**
  * Преобразует YAML в массив
  * @param string $yaml
  * @return array
  */
 public static function yamlToArray($yaml)
 {
     cmsCore::loadLib('spyc.class');
     return Spyc::YAMLLoadString($yaml);
 }
 private function processProjects()
 {
     $url = "https://raw.githubusercontent.com/openstack/governance/master/reference/projects.yaml";
     $response = null;
     try {
         $response = $this->client->get($url);
     } catch (Exception $ex) {
         echo $ex->getMessage() . PHP_EOL;
         SS_Log::log($ex->getMessage(), SS_Log::WARN);
     }
     if (is_null($response)) {
         return;
     }
     if ($response->getStatusCode() != 200) {
         return;
     }
     $body = $response->getBody();
     if (is_null($body)) {
         return;
     }
     $content = $body->getContents();
     if (empty($content)) {
         return;
     }
     try {
         $projects = Spyc::YAMLLoadString($content);
         foreach ($projects as $project_name => $info) {
             $component = OpenStackComponent::get()->filter('CodeName', ucfirst($project_name))->first();
             if (is_null($component)) {
                 $component = OpenStackComponent::get()->filter('Name', ucfirst($project_name))->first();
             }
             echo sprintf('processing component %s', $project_name) . PHP_EOL;
             if (is_null($component)) {
                 echo sprintf('component %s not found!', $project_name) . PHP_EOL;
                 continue;
             }
             $ptl = isset($info['ptl']) ? $info['ptl'] : null;
             $wiki = isset($info['url']) ? $info['url'] : null;
             $tags = isset($info['tags']) ? $info['tags'] : [];
             $ptl_member = null;
             if (!empty($ptl)) {
                 if (is_array($ptl) && isset($ptl['name'])) {
                     $ptl_names = preg_split("/\\s/", $ptl['name']);
                     $fname = $ptl_names[0];
                     $lname = $ptl_names[1];
                 } else {
                     $ptl_names = preg_split("/\\s/", $ptl);
                     $fname = $ptl_names[0];
                     $lname = $ptl_names[1];
                 }
                 $email = isset($ptl['email']) ? trim($ptl['email']) : null;
                 echo sprintf('PTL %s %s (%s)', $fname, $lname, $email) . PHP_EOL;
                 if (!empty($email)) {
                     $ptl_member = Member::get()->filter(array('Email' => $email))->first();
                 }
                 if (is_null($ptl_member)) {
                     $ptl_member = Member::get()->filter(array('FirstName' => $fname, 'Surname' => $lname))->first();
                 }
             }
             $team_diverse_affiliation = false;
             $is_service = false;
             $has_stable_branches = false;
             $tc_approved_release = false;
             $release_milestones = false;
             $release_intermediary = false;
             $release_independent = false;
             $starter_kit = false;
             $vulnerability_managed = false;
             $follows_standard_deprecation = false;
             $supports_upgrade = false;
             $supports_rolling_upgrade = false;
             foreach ($tags as $tag) {
                 if ($tag === "team:diverse-affiliation") {
                     $team_diverse_affiliation = true;
                 }
             }
             $deliverables = isset($info['deliverables']) ? $info['deliverables'] : array();
             $service_info = isset($deliverables[$project_name]) ? $deliverables[$project_name] : array();
             $service_tags = isset($service_info['tags']) ? $service_info['tags'] : array();
             foreach ($service_tags as $tag) {
                 if ($tag === "type:service") {
                     $is_service = true;
                 }
                 if ($tag === "stable:follows-policy") {
                     $has_stable_branches = true;
                 }
                 if ($tag === "release:cycle-with-milestones") {
                     $release_milestones = true;
                 }
                 if ($tag === "release:cycle-with-intermediary") {
                     $release_intermediary = true;
                 }
                 if ($tag === "release:independent") {
                     $release_independent = true;
                 }
                 if ($tag === "tc-approved-release") {
                     $tc_approved_release = true;
                 }
                 if ($tag === "starter-kit:compute") {
                     $starter_kit = true;
                 }
                 if ($tag === "vulnerability:managed") {
                     $vulnerability_managed = true;
                 }
                 if ($tag === "assert:follows-standard-deprecation") {
                     $follows_standard_deprecation = true;
                 }
                 if ($tag === "assert:supports-upgrade") {
                     $supports_upgrade = true;
                 }
                 if ($tag === "assert:supports-rolling-upgrade") {
                     $supports_rolling_upgrade = true;
                 }
             }
             $component->HasStableBranches = $has_stable_branches;
             $component->WikiUrl = $wiki;
             $component->TCApprovedRelease = $tc_approved_release;
             $component->ReleaseMileStones = $release_milestones;
             $component->ReleaseCycleWithIntermediary = $release_intermediary;
             $component->ReleaseIndependent = $release_independent;
             $component->HasTeamDiversity = $team_diverse_affiliation;
             $component->IncludedComputeStarterKit = $starter_kit;
             $component->VulnerabilityManaged = $vulnerability_managed;
             $component->FollowsStandardDeprecation = $follows_standard_deprecation;
             $component->SupportsUpgrade = $supports_upgrade;
             $component->SupportsRollingUpgrade = $supports_rolling_upgrade;
             if (!is_null($ptl_member)) {
                 echo sprintf('setting PTL %s %s (%s) to Component %s', $ptl_member->FirstName, $ptl_member->Surname, $ptl_member->Email, $component->Name) . PHP_EOL;
                 $component->LatestReleasePTLID = $ptl_member->ID;
             }
             $component->write();
         }
     } catch (Exception $ex) {
         echo $ex->getMessage() . PHP_EOL;
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return;
     }
 }
	<button type="button" class="btn btn-default btn-sm" style="width:100%; margin-bottom:5px">Flow Form</button><br/>
	<button type="button" class="btn btn-default btn-sm" style="width:100%; margin-bottom:5px">Form Filters</button><br/>
	<button type="button" class="btn btn-default btn-sm" style="width:100%; margin-bottom:5px">Data Grid</button><br/>
-->
<div style="float:left;">
<h2>Slot List</h2> 
</div>
<div style="float:right; margin-top:16px">
<span style="font-size:20px" class="debuger-all-options glyphicon glyphicon-align-justify"></span>
</div>
<br style="clear:both">
<?php 
require_once "../../../../../wp-load.php";
require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/defines-const.php';
require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/Spyc.php';
$all_properties = Spyc::YAMLLoadString($_POST['yaml']);
$listYaml = $all_properties[key($all_properties)]['ui_slot_list_name'];
if ($listYaml == '') {
    $listYaml = 'slot-list';
}
$slotList = Spyc::YAMLLoad(GLOBALDATA_PATH . 'template-hierarchy/schemas/' . $listYaml . '.yaml');
global $DTDC;
require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/display-controller.class.php';
@($DTDC = new ThemeDisplayController($post->ID));
$DTDC->args = $slotList;
require_once TEMPLATEPATH . '/theme-template-parts/flow/basic-test-flow.php';
@(require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/send-post-data_eachwalker.class.php');
global $SPD;
$SPD = new SendPostData($data_arg);
$DTDC->postFormObject = $SPD;
foreach ($slotList as $key => $value) {
 /**
  * Decodes the YAML into a PHP associative array.
  * @return array
  */
 public function getYamlData()
 {
     return Spyc::YAMLLoadString($this->getNativeData(), true);
 }
Esempio n. 14
0
<?php

/* Get the yaml file and parse it. */
if (count($argv) != 2) {
    die("please set the yaml file.\n");
}
$filename = $argv[1];
if (!is_file($filename)) {
    die("the yaml file doesn't exit\n");
}
include '../../lib/spyc/spyc.class.php';
$extension = Spyc::YAMLLoadString(file_get_contents($filename));
/* Basic info checking. */
if (empty($extension['name'])) {
    die("name field must be set\n");
}
if (empty($extension['code'])) {
    die("code field must be set\n");
}
if (!preg_match('/^[a-zA-Z0-9_]{1}[a-zA-Z0-9_]{1,}[a-zA-Z0-9_]{1}$/', $extension['code'])) {
    die("code shoulde be letter, nubmer and _\n");
}
if (!preg_match('/^(extension|patch|theme)$/', $extension['type'])) {
    die("type shoulde be extension, patch or theme\n");
}
if (empty($extension['abstract'])) {
    die("abstract field must be set\n");
}
/* desc and install fields checking. */
if (is_array($extension['desc'])) {
    die("desc should be a string, please check your yaml synatax\n");
Esempio n. 15
0
 public static function decode($input)
 {
     return Spyc::YAMLLoadString($input);
 }
Esempio n. 16
0
 /**
  * Преобразует YAML в массив
  * @param string $yaml
  * @return array
  */
 public static function yamlToArray($yaml)
 {
     return Spyc::YAMLLoadString($yaml);
 }
Esempio n. 17
0
File: yaml.php Progetto: ageo80/test
 /**
  * Loads in and parses the given Yaml string
  * 
  * @param   string  $string  the yaml to parse
  * @return  array   the parsed yaml array
  */
 public function parse_string($string)
 {
     return Spyc::YAMLLoadString($string);
 }
Esempio n. 18
0
 /**
  * Parses the given YML string and caches the resulting definitions
  *
  * @param string $yml
  * @return array
  */
 public function loadYmlData($yml)
 {
     $searchEngines = \Spyc::YAMLLoadString($yml);
     $this->definitionList = $this->transformData($searchEngines);
     return $this->definitionList;
 }
Esempio n. 19
0
<?php

require_once realpath('./../../../../../') . '/wp-content/plugins/UiGEN-Core/class/Spyc.php';
$data = Spyc::YAMLLoadString($_POST['yaml']);
$element_settings['data'] = $data[$_POST['slotname']];
$json = json_encode($element_settings);
//$json = stripslashes($json);
//$json =  str_replace("\\" , "" , $json);
$json = str_replace("/", "", $json);
$json = str_replace("\\\"", "", $json);
$json = str_replace("\\", "", $json);
$json = str_replace("'", "", $json);
//$a = str_replace('/','',json_encode($element_settings));
//$a = str_replace("\\" , "" , $a);
//$a = str_replace('\'','',$a);
//$a = stripslashes($a);
print $json;
die;
function RunImport()
{
    $taglist = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
    $objectnames = $_POST['objectname'];
    global $dbxlink;
    $log = emptyLog();
    foreach ($objectnames as $objectname) {
        // FIXME: This reads the entire directory for each object. Not very efficient.
        if ($handle = opendir('./yamls/')) {
            while (false !== ($file = readdir($handle))) {
                # puppet names the files $FQDN.yaml, not PSMN
                if ($file == $objectname . ".yaml") {
                    # SPYC is not happy with the puppet header. Hence read it as string, strip the header and feed it to SPYC
                    $file_contents = file_get_contents("./yamls/{$file}");
                    $file_contents = substr($file_contents, strpos($file_contents, "\n") + 1);
                    $yaml_file_array = Spyc::YAMLLoadString($file_contents);
                    // FIXME: Is this the correct way to narrow in on an array?
                    // At this point, $yaml_file_array contains all the data from the YAML files in a indexed array.
                    $yaml_name = $yaml_file_array['name'];
                    // switch to the 2nd part of the array
                    $yaml_file_array = $yaml_file_array['parameters'];
                    // getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn = '', $exactness = 0|1|2)
                    $object = getSearchResultByField('RackObject', array('id'), 'name', $yaml_name, '', 2);
                    if ($object) {
                        # Object exists. Do NOT modify.
                        $id = $object[0]['id'];
                        $log = mergeLogs($log, oneLiner(202, array("{$objectname} exists. No modifications!")));
                    } else {
                        // Object does not exist. Create new.
                        // Syntax: commitAddObject ($new_name, $new_label, $new_type_id, $new_asset_no, $taglist = array())
                        // Type is 4, server, by default.
                        $new_yamlobject = commitAddObject($yaml_name, '', 4, $yaml_file_array['serialnumber'], $taglist);
                        // Hardware type (i.e. ProLiant DL380 G6a), Dict Chapter ID is '11';
                        $hw_dict_key = getdict($hw = $yaml_file_array['productname'], $chapter = 11);
                        commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '2', $value = $hw_dict_key);
                        // Operating system string, Dict Chapter ID is '13'.
                        $osrelease = $yaml_file_array['operatingsystem'] . " " . $yaml_file_array['operatingsystemrelease'];
                        $os_dict_key = getdict($hw = $osrelease, $chapter = 13);
                        commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '4', $value = $os_dict_key);
                        /*
                                    // FIXME: The IDs should be looked up, and not preset.
                                    // Architecture. Attribute ID is '10000'.
                                    commitUpdateAttrValue ($object_id = $new_yamlobject, $attr_id = '10000', $value = $yaml_file_array['hardwareisa']);
                                    // Memory. Attribute ID is 17.
                                    commitUpdateAttrValue ($object_id = $new_yamlobject, $attr_id = '17', $value = (int)$yaml_file_array['memorysize']);
                                    // CPU. Attribute ID is 100001
                                    $cpu = $yaml_file_array['processorcount'] . " x " . $yaml_file_array['processor0'];
                                    commitUpdateAttrValue ($object_id = $new_yamlobject, $attr_id = '10001', $value = $cpu);
                        */
                        // OEM S/N 1. Attribute ID is '1'.
                        commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '1', $value = $yaml_file_array['serialnumber']);
                        // FQDN. Attribute ID is '3'.
                        commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '3', $value = $yaml_file_array['fqdn']);
                        // UUID. Attribute ID is '25'.
                        commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '25', $value = $yaml_file_array['uuid']);
                        // Hypervisor. Attribute ID is '26', Dict Chapter ID is '29'.
                        // Hypervisor key does not exist in standard Puppet yaml file, added by PSMN
                        if (isset($yaml_file_array['hypervisor'])) {
                            $hv_dict_key = getdict($hw = $yaml_file_array['hypervisor'], $chapter = 29);
                            commitUpdateAttrValue($object_id = $new_yamlobject, $attr_id = '26', $value = $hv_dict_key);
                        }
                        // NICS
                        // Warning! This part only work if default Configuration is modified
                        // Go to "MainPage -> Configuration -> User Interface"
                        // Modify "AutoPorts configuration": Change "4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm" to "15 = 1*446*kvm"
                        // Ref: http://www.freelists.org/post/racktables-users/Automatic-insertions-of-servers-in-the-db,7
                        $nics = explode(',', $yaml_file_array['interfaces'], 9);
                        $count = count($nics);
                        for ($i = 0; $i < $count; $i++) {
                            switch ($nics[$i]) {
                                case "sit0":
                                    break 1;
                                case "ib0":
                                    // infiniband
                                    if (isset($yaml_file_array['ipaddress_' . $nics[$i]])) {
                                        $ip = $yaml_file_array['ipaddress_' . $nics[$i]];
                                    }
                                    // do NOT import infiniband MAC for now
                                    //                if (isset($yaml_file_array['macaddress_' . $nics[$i]]))
                                    //                {
                                    //                  $mac = $yaml_file_array['macaddress_' . $nics[$i]];
                                    //                }
                                    // Add port to object. Type 40 is 10GBase-CX4, MAC can be NULL
                                    commitAddPort($object_id = $new_yamlobject, $nics[$i], 40, 'infiniband', $mac);
                                    // Add IP to object.
                                    if (isset($ip)) {
                                        bindIpToObject($ip, $new_yamlobject, $nics[$i], 'regular');
                                    }
                                    break 1;
                                default:
                                    if (preg_match("eth", $nics[$i]) === 0) {
                                        break 1;
                                    }
                                    # this one might be bad for non-linux OSes ?
                                    if (isset($yaml_file_array['ipaddress_' . $nics[$i]])) {
                                        $ip = $yaml_file_array['ipaddress_' . $nics[$i]];
                                    }
                                    if (isset($yaml_file_array['macaddress_' . $nics[$i]])) {
                                        $mac = $yaml_file_array['macaddress_' . $nics[$i]];
                                    }
                                    // Add port to object. Type 24 is 1000Base-T
                                    commitAddPort($object_id = $new_yamlobject, $nics[$i], 24, 'Ethernet port', "{$mac}");
                                    // Add IP to object.
                                    if (isset($ip)) {
                                        bindIpToObject($ip, $new_yamlobject, $nics[$i], 'regular');
                                    }
                                    break 1;
                            }
                            unset($ip);
                            unset($mac);
                        }
                        // Create a URL for the log message.
                        $url = makeHref(array('page' => 'object', 'tab' => 'default', 'object_id' => $new_yamlobject));
                        $loginstance = "<a href=\"{$url}\">" . $objectname . "</a>";
                        $log = mergeLogs($log, oneLiner(80, array("{$loginstance}")));
                    }
                }
            }
        }
    }
    return showSuccess($log);
}
Esempio n. 21
0
 if ($item->type == 'file') {
     $id = pathinfo($item->name, PATHINFO_FILENAME);
     if (!array_key_exists($id, $content)) {
         $content[$id] = array('path' => $item->path, 'name' => $item->name, 'html_name' => $id . '.html', 'id' => $id, 'raw_url' => $config['github_url_raw'] . $item->path, 'sha' => '', 'date' => '', 'author' => '', 'title' => '', 'tags' => '');
     }
     $content_item = $content[$id];
     // debug('content_item', $content_item);
     if ($item->sha != $content_item['sha']) {
         $changed++;
         // debug('item', $item);
         $file = get_content_from_github($content_item['raw_url']);
         // debug('file', $file);
         $yaml_end = 0;
         if (substr($file, 0, 3) == '---' && ($yaml_end = strpos($file, '---', 4))) {
             // debug('yaml_end', $yaml_end);
             $metadata = Spyc::YAMLLoadString(substr($file, 4, $yaml_end));
             // debug('metadata', $metadata);
             if (array_key_exists('date', $metadata)) {
                 $content_item['date'] = $metadata['date'];
             }
             $content_item['author'] = array_key_exists('author', $metadata) ? $metadata['author'] : $config['author'];
             if (array_key_exists('title', $metadata)) {
                 $content_item['title'] = $metadata['title'];
             }
             $yaml_end += 4;
             // remove the closing ---
         }
         if ($yaml_end > 0) {
             $file = substr($file, $yaml_end);
         }
         // debug('file', $file);
Esempio n. 22
0
 /**
  * Parse a text string of YAML data into a data array
  *
  * @param String $yaml the string of YAML data to parse
  * @return Array a data array containing the YAML data
  */
 public static function parse($yaml)
 {
     return Spyc::YAMLLoadString($yaml);
 }
Esempio n. 23
0
 protected function _from_yaml($string)
 {
     if (!function_exists('spyc_load')) {
         import('spyc/spyc', 'vendor');
     }
     return \Spyc::YAMLLoadString($string);
 }
Esempio n. 24
0
 }
 put_cache_json(MANUAL_CACHE_GITHUB_FILE, $cache, $manual_id);
 // debug('cache', $cache);
 // debug('cache_update', $cache_update);
 if (MANUAL_LOCAL_FILES_REQUEST) {
     $book = file_get_contents(MANUAL_LOCAL_PATH . MANUAL_SOURCE_BOOK_FILE);
     $book = Spyc::YAMLLoadString($book);
     // put_cache_json(MANUAL_CACHE_TOC_FILE, $book, $manual_id);
 } elseif (array_key_exists(MANUAL_SOURCE_BOOK_FILE, $cache_update)) {
     if (!MANUAL_DEBUG_NO_HTTP_REQUEST) {
         // debug('book url', GITHUB_RAW_URL.MANUAL_SOURCE_BOOK_FILE);
         $book = get_content_from_github(GITHUB_RAW_URL . MANUAL_SOURCE_BOOK_FILE);
     } else {
         $book = file_get_contents('book_github.yaml');
     }
     $book = Spyc::YAMLLoadString($book);
     put_cache_json(MANUAL_CACHE_TOC_FILE, $book, $manual_id);
 } else {
     $book = get_cache_json(MANUAL_CACHE_TOC_FILE, $manual_id);
 }
 // debug('book', $book);
 // TODO: first read the book_toc from the cache
 $book_toc = get_toc($book['toc']);
 // debug('book_toc', $book_toc);
 $book_files = get_book_files($book_toc, $cache);
 // debug('book_files', $book_files);
 put_cache_json(MANUAL_CACHE_SECTION_FILE, $book_files, $manual_id);
 $book_language = get_language($book_toc, $cache);
 // debug('book_language', $book_language);
 put_cache_json(MANUAL_CACHE_LANGUAGE_FILE, $book_language, $manual_id);
 downlad_files($book_files, $manual_id, $cache);
Esempio n. 25
0
 /**
  * Get Front Matter
  */
 public function get_front_matter($template)
 {
     # Open file
     $raw_template = file_get_contents($this->dir . '/' . $template);
     # Split it down
     $data = explode('--#}', $raw_template);
     # Check if meta is there
     if (strpos($data[0], '{#--') !== false) {
         # Save Useful data
         $matter = $data[0];
         # Remove opener
         $matter = str_replace('{#--', '', $matter);
         # Trim First Line
         $matter = ltrim($matter, PHP_EOL);
         # Parse through Spyc
         $page = \Spyc::YAMLLoadString($matter);
         # Return Data
         $this->variables['page'] = array_merge($this->variables['page'], $page);
     } else {
         return;
     }
 }
require dirname(__FILE__) . '/vendor/spyc/spyc.php';
$output_dir = dirname(__FILE__) . '/javascript/';
$mootools_dir = dirname(__FILE__) . '/vendor/mootools-';
$types = array('core', 'more');
$provided_by = array();
$files = array();
foreach ($types as $type) {
    $package = file_get_contents($mootools_dir . $type . '/package.yml');
    $package = Spyc::YAMLLoadString($package);
    $files[$type] = array();
    foreach ($package['sources'] as $file) {
        echo "Examining {$file}\n";
        $contents = file_get_contents($mootools_dir . $type . '/' . $file);
        // Extract and parse the YAML header
        preg_match('/^---$(.*)^\\.\\.\\.$/ms', $contents, $matches);
        $info = Spyc::YAMLLoadString($matches[1]);
        if (!empty($info['provides'])) {
            foreach ((array) $info['provides'] as $provides) {
                $provided_by[$provides] = $info['name'];
            }
        }
        $files[$type][$file] = $info;
    }
}
foreach ($types as $type) {
    foreach ($files[$type] as $file => $info) {
        echo "Creating {$info['name']}\n";
        $headers = array();
        if (!empty($info['requires'])) {
            foreach ((array) $info['requires'] as $req) {
                $req = pathinfo($req, PATHINFO_BASENAME);
<?php

require_once "../../../../../wp-load.php";
require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/Spyc.php';
require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/defines-const.php';
if (current_user_can('manage_options')) {
    /* WARNING - Stripshlashes post data - but only to admin or high level users */
    $prop_data = str_replace("'", "", $_POST['prop_yaml']);
    $prop_data = Spyc::YAMLLoadString(stripslashes($prop_data));
    $prop_data['grid'] = $_POST['ui_grid_name'];
    $prop_data['ui_page_name'] = $_POST['ui_page_name'];
    $prop_data['ui_slot_list_name'] = $_POST['ui_slot_list'];
    $prop_path = GLOBALDATA_PATH;
    file_put_contents($prop_path . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-properties.yaml', Spyc::YAMLDump($prop_data));
    $hierarchy_data = Spyc::YAMLLoadString($_POST['hierarchy_yaml']);
    echo '<h2>hierarchy_data</h2>';
    echo '<pre>';
    var_dump($hierarchy_data);
    echo '</pre>';
    file_put_contents($prop_path . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-hierarchy.yaml', Spyc::YAMLDump($hierarchy_data));
    echo $prop_path . 'template-hierarchy/arguments/' . $_POST['ui_page_name'] . '-slots-hierarchy.yaml';
    ?>
	<div class="modal-content">
	  <div class="modal-header modal-success">
	    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	    <h2 class="modal-title" id="debugModalLabel"><span class="glyphicon glyphicon-thumbs-up"></span> SUCCESS</h2>
	  </div>
	  <div class="modal-body">
			<h1>Your hierarchy was saved !!!</h1>
		 </div>
	  <div class="modal-footer">
Esempio n. 28
0
function update_content($path, $pagePath)
{
    global $globalphase;
    if ($globalphase > 0) {
        check_cross_links($path, $pagePath);
        return;
    }
    $ext = substr($path, strrpos($path, '.') + 1);
    $filename = substr($path, strrpos($path, '/') + 1);
    $filedata = trim(file_get_contents($path));
    $config = array();
    if (preg_match('/^^---(.+?)---/is', $filedata, $match)) {
        $config = Spyc::YAMLLoadString($match[1]);
        $filedata = trim(preg_replace('/^^---(.+?)---/is', '', $filedata));
    }
    if (preg_match_all('/`([a-zA-Z0-9]*Three20[a-zA-Z0-9]+)\\/([a-zA-Z0-9]+)\\.(h|m)`/', $filedata, $matches)) {
        for ($index = 0; $index < count($matches[0]); ++$index) {
            $library = $matches[1][$index];
            $classname = $matches[2][$index];
            $filetype = $matches[3][$index];
            if ($filetype == 'h') {
                $subdir = 'Headers';
            } else {
                if ($filetype == 'm') {
                    $subdir = 'Sources';
                }
            }
            $url = 'http://github.com/facebook/three20/blob/master/src/' . $library . '/' . $subdir . '/' . $classname . '.' . $filetype;
            $filedata = preg_replace('/`' . $library . '\\/' . $classname . '\\.' . $filetype . '`/', '<a href="' . $url . '">' . $classname . '</a>', $filedata);
        }
    }
    $config['ext'] = $ext;
    if (preg_match('/^mdown|markdown$/i', $ext)) {
        $compiledData = Markdown($filedata);
    } else {
        if (preg_match('/^textile$/i', $ext)) {
            $textile = new Textile();
            $compiledData = $textile->TextileThis($filedata);
        } else {
            if (preg_match('/^html|htm$/i', $ext)) {
                $compiledData = $filedata;
            } else {
                $compiledData = null;
                unset($config['ext']);
            }
        }
    }
    if ($compiledData) {
        $compiledFilename = substr($filename, 0, strrpos($filename, '.')) . '.php';
        $configFilename = substr($filename, 0, strrpos($filename, '.')) . '.config';
        $articlePath = join_paths($pagePath, $compiledFilename);
        $configPath = join_paths($pagePath, $configFilename);
        if (!$config) {
            @unlink($configPath);
        } else {
            file_put_contents($configPath, json_encode($config));
        }
        file_put_contents($articlePath, $compiledData);
    }
}
Esempio n. 29
0
 /**
  * Parses YAML to array.
  * @param string $string YAML string.
  * @return array
  */
 function spyc_load($string)
 {
     return Spyc::YAMLLoadString($string);
 }
 public function actionEditPermissionsConfig($id)
 {
     Yii::app()->user->can($id, 'edit configs', true);
     $model = $this->loadModel($id);
     $error = '';
     $world = $model->world ? $model->world : 'world';
     if (@$_POST['save'] === 'true') {
         require_once dirname(__FILE__) . '/../extensions/spyc/spyc.php';
         $groups['groups'] = array();
         $def = User::getLevelRole($model->default_level);
         $prev = false;
         foreach (User::$roles as $role) {
             if ($role == 'none') {
                 continue;
             }
             $lbl = $role;
             //User::getRoleLabel($role);
             $groups['groups'][$lbl] = $this->getRolePerms($role, $role == $def, $_POST['prefix_' . $role], $_POST['suffix_' . $role], $_POST['build_' . $role] == 0, $_POST['perms_' . $role]);
             if ($prev) {
                 $groups['groups'][$lbl]['inheritance'] = array($prev);
             }
             $prev = $lbl;
         }
         $plrs = Player::model()->findAllByAttributes(array('server_id' => $model->id));
         $users['users'] = array();
         foreach ($plrs as $plr) {
             $users['users'][$plr->name] = array('groups' => array(User::getLevelRole($plr->level)));
         }
         $groups = Spyc::YAMLDump($groups, 4, 0);
         $users = Spyc::YAMLDump($users, 4, 0);
         $groupsData = $groups ? str_replace(array('\\', ' ;'), array('\\\\', ' \\;'), $groups) : '';
         $groupsData = preg_replace('/\\n\\r?/', ' ;', $groupsData);
         $usersData = $users ? str_replace(array('\\', ' ;'), array('\\\\', ' \\;'), $users) : '';
         $usersData = preg_replace('/\\n\\r?/', ' ;', $usersData);
         $d = null;
         if (!McBridge::get()->serverCmd($id, 'cfgfile setlist:groups.yml:plugins/Permissions/' . $world . ':' . $groupsData, $d)) {
             $error = McBridge::get()->lastError();
         } else {
             if (@$d[0]['accepted'] != 'True') {
                 $error = isset($d[0]['message']) ? $d[0]['message'] : Yii::t('mc', 'Error updating config file!');
             } else {
                 if (!McBridge::get()->serverCmd($id, 'cfgfile setlist:users.yml:plugins/Permissions/' . $world . ':' . $usersData, $d)) {
                     $error = McBridge::get()->lastError();
                 } else {
                     if (@$d[0]['accepted'] != 'True') {
                         $error = isset($d[0]['message']) ? $d[0]['message'] : Yii::t('mc', 'Error updating config file!');
                     } else {
                         Yii::app()->user->setFlash('server', Yii::t('mc', 'Config File saved.'));
                         $this->redirect(array('configs', 'id' => $id));
                     }
                 }
             }
         }
     } else {
         require_once dirname(__FILE__) . '/../extensions/spyc/spyc.php';
         $groupsData = array();
         $usersData = array();
         if (!McBridge::get()->serverCmd($id, 'cfgfile getlist:groups.yml:plugins/Permissions/' . $world . ':', $groupsData)) {
             $error = McBridge::get()->lastError();
         }
         if (!McBridge::get()->serverCmd($id, 'cfgfile getlist:users.yml:plugins/Permissions/' . $world . ':', $usersData)) {
             $error = McBridge::get()->lastError();
         }
         $users = '';
         $groups = '';
         if (count($groupsData)) {
             foreach ($groupsData as $line) {
                 if (isset($line['line'])) {
                     $groups .= $line['line'] . "\n";
                 }
             }
         }
         if (count($usersData)) {
             foreach ($usersData as $line) {
                 if (isset($line['line'])) {
                     $users .= $line['line'] . "\n";
                 }
             }
         }
         $groups = Spyc::YAMLLoadString($groups);
         foreach (User::$roles as $role) {
             if ($role == 'none') {
                 continue;
             }
             $lbl = $role;
             //User::getRoleLabel($role);
             $_POST['prefix_' . $role] = @$groups['groups'][$lbl]['info']['prefix'];
             $_POST['suffix_' . $role] = @$groups['groups'][$lbl]['info']['suffix'];
             $_POST['build_' . $role] = isset($groups['groups'][$lbl]['info']['build']) && !$groups['groups'][$lbl]['info']['build'] ? 1 : 0;
             if (isset($groups['groups'][$lbl]['permissions'][0]) && $groups['groups'][$lbl]['permissions'][0]) {
                 $_POST['perms_' . $role] = implode(', ', array_map(array($this, 'toYmlStr'), $groups['groups'][$lbl]['permissions']));
             }
         }
     }
     $this->render('editPermissionsConfig', array('model' => $model, 'error' => $error));
 }