/** * Overloads the {@link BedrockNode::get()} method to pipe failures through {@link SilverSmithDefaults} * * @param string The path to the setting * @return BedrockNode */ public function get($setting) { $result = parent::get($setting); if (!$result) { return SilverSmithDefaults::get($setting); } return $result; }
// Turn off timezone warning date_default_timezone_set(@date_default_timezone_get()); // Require dependencies $script_dir = dirname(dirname(__FILE__)); require_once "{$script_dir}/code/lib/bedrock/Bedrock.php"; require_once "{$script_dir}/code/SilverSmithNode.php"; require_once "{$script_dir}/code/BedrockDataRecord.php"; foreach (glob("{$script_dir}/code/*.php") as $class) { require_once $class; } require_once "{$script_dir}/code/lib/thirdparty/TextDiff.php"; // Bootstrap the SilverSmith class SilverSmith::set_cli(true); SilverSmith::set_script_dir($script_dir); SilverSmith::set_git_path(trim(shell_exec("which git"))); SilverSmithDefaults::load(SilverSmith::get_script_dir() . "/code/lib/_defaults.yml"); SilverSmithSpec::load(SilverSmith::get_script_dir() . "/code/lib/_spec.yml"); // Validation for the CLI commands $commands = new BedrockYAML(SilverSmith::get_script_dir() . "/code/lib/_cli.yml"); $allowed_actions = $commands->getAllowedActions(); $PARAMS = SilverSmithUtil::parse_parameters(); if (!isset($PARAMS[1])) { fail("Usage: silversmith <command> [-args]. Type 'silversmith help' for more information."); } $action = $PARAMS[1]; if (!$allowed_actions->get($action)) { say(error("'{$action}' is not an allowed command.")); say("Available commands:\n " . implode("\n", array_keys($allowed_actions->toArray()))); die; } $allowed_options = $allowed_actions->get($action)->getOptions();
/** * Get some lipsum text * * @todo Move this into local storage so it doesn't use HTTP requests * @param integer The length of the lipsum text, in sentences * @param boolean If true, include html links * @return string */ public static function get_lipsum($length = 1, $rich = false) { $tags = $rich ? "link" : ""; $text = @file_get_contents("http://loripsum.net/api/{$length}/short/{$tags}"); if (!$rich) { $text = strip_tags($text); } return $text && !empty($text) ? $text : SilverSmithDefaults::get('DefaultContent'); }
/** * Load the default settings from a path to a YAML file * * @param string the path to the YAML */ public static function load($path) { self::$settings_list = new BedrockYAML($path); }
/** * Gets the code that will instantiate this form field in PHP code * * @return string */ public function getInstantiation() { if (!($yml = $this->getConfig()) || !($content = $yml->getInstantiate())) { $content = SilverSmithDefaults::get('InstantiateField'); } $template = new BedrockTemplate(SilverSmithUtil::tabify(rtrim($content))); $template->bind($this); $inst = $template->render(); $up = $this->getUpdate(); if ($up && !empty($up)) { return $this->getVar() . " = " . $inst; } return $inst; }