本文整理汇总了PHP中Grav\Common\Page\Page::rawMarkdown方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::rawMarkdown方法的具体用法?PHP Page::rawMarkdown怎么用?PHP Page::rawMarkdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Page\Page
的用法示例。
在下文中一共展示了Page::rawMarkdown方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preparePage
/**
* Prepare a page to be stored: update its folder, name, template, header and content
*
* @param \Grav\Common\Page\Page $page
* @param bool $clean_header
*/
protected function preparePage(\Grav\Common\Page\Page $page, $clean_header = false, $language = null)
{
$input = $this->post;
if (isset($input['order'])) {
$order = max(0, (int) isset($input['order']) ? $input['order'] : $page->value('order'));
$ordering = $order ? sprintf('%02d.', $order) : '';
$slug = empty($input['folder']) ? $page->value('folder') : (string) $input['folder'];
$page->folder($ordering . $slug);
}
if (isset($input['name']) && !empty($input['name'])) {
$type = (string) strtolower($input['name']);
$name = preg_replace('|.*/|', '', $type);
if ($language) {
$name .= '.' . $language;
} else {
$language = $this->grav['language'];
if ($language->enabled()) {
$name .= '.' . $language->getLanguage();
}
}
$name .= '.md';
$page->name($name);
$page->template($type);
// unset some header things, template for now as we've just set that
if (isset($input['header']['template'])) {
unset($input['header']['template']);
}
}
// Special case for Expert mode: build the raw, unset content
if (isset($input['frontmatter']) && isset($input['content'])) {
$page->raw("---\n" . (string) $input['frontmatter'] . "\n---\n" . (string) $input['content']);
unset($input['content']);
}
if (isset($input['header'])) {
$header = $input['header'];
foreach ($header as $key => $value) {
if ($key == 'metadata') {
foreach ($header['metadata'] as $key2 => $value2) {
if (isset($input['toggleable_header']['metadata'][$key2]) && !$input['toggleable_header']['metadata'][$key2]) {
$header['metadata'][$key2] = '';
}
}
} elseif ($key == 'taxonomy') {
foreach ($header[$key] as $taxkey => $taxonomy) {
if (is_array($taxonomy) && count($taxonomy) == 1 && trim($taxonomy[0]) == '') {
unset($header[$key][$taxkey]);
}
}
} else {
if (isset($input['toggleable_header'][$key]) && !$input['toggleable_header'][$key]) {
$header[$key] = null;
}
}
}
if ($clean_header) {
$header = Utils::arrayFilterRecursive($header, function ($k, $v) {
return !(is_null($v) || $v === '');
});
}
$page->header((object) $header);
$page->frontmatter(Yaml::dump((array) $page->header()));
}
// Fill content last because it also renders the output.
if (isset($input['content'])) {
$page->rawMarkdown((string) $input['content']);
}
}
示例2: preparePage
/**
* Prepare a page to be stored: update its folder, name, template, header and content
*
* @param \Grav\Common\Page\Page $page
* @param bool $clean_header
*/
protected function preparePage(\Grav\Common\Page\Page $page, $clean_header = false)
{
$input = $this->post;
$order = max(0, (int) isset($input['order']) ? $input['order'] : $page->value('order'));
$ordering = $order ? sprintf('%02d.', $order) : '';
$slug = empty($input['folder']) ? $page->value('folder') : (string) $input['folder'];
$page->folder($ordering . $slug);
if (isset($input['type']) && !empty($input['type'])) {
$type = (string) strtolower($input['type']);
$name = preg_replace('|.*/|', '', $type) . '.md';
$page->name($name);
$page->template($type);
}
// Special case for Expert mode: build the raw, unset content
if (isset($input['frontmatter']) && isset($input['content'])) {
$page->raw("---\n" . (string) $input['frontmatter'] . "\n---\n" . (string) $input['content']);
unset($input['content']);
}
if (isset($input['header'])) {
$header = $input['header'];
if ($clean_header) {
$header = Utils::arrayFilterRecursive($header, function ($k, $v) {
return !(is_null($v) || $v === '');
});
}
$page->header((object) $header);
}
// Fill content last because it also renders the output.
if (isset($input['content'])) {
$page->rawMarkdown((string) $input['content']);
}
}
示例3: taskSaveas
/**
* Save the current page in a different language. Automatically switches to that language.
*
* @return bool True if the action was performed.
*/
protected function taskSaveas()
{
if (!$this->authorizeTask('save', $this->dataPermissions())) {
return false;
}
$data = (array) $this->data;
$language = $data['lang'];
if ($language) {
$this->grav['session']->admin_lang = $language ?: 'en';
}
$uri = $this->grav['uri'];
$obj = $this->admin->page($uri->route());
$this->preparePage($obj, false, $language);
$file = $obj->file();
if ($file) {
$filename = $this->determineFilenameIncludingLanguage($obj->name(), $language);
$path = $obj->path() . DS . $filename;
$aFile = File::instance($path);
$aFile->save();
$aPage = new Page();
$aPage->init(new \SplFileInfo($path), $language . '.md');
$aPage->header($obj->header());
$aPage->rawMarkdown($obj->rawMarkdown());
$aPage->validate();
$aPage->filter();
$aPage->save();
$this->grav->fireEvent('onAdminAfterSave', new Event(['page' => $obj]));
}
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info');
$this->setRedirect('/' . $language . $uri->route());
return true;
}
示例4: savePage
/**
* Get Page informations
* update content
* save page
*
* @param Page Page that has to be saved
* @return void - calls ajaxoutput
*/
public function savePage(\Grav\Common\Page\Page $page)
{
// get local names for some objects
$input = $this->post;
$user = $this->grav['user'];
// Check Permissions for Save
if ($user->authenticated && $user->authorize("site.editor")) {
var_dump($input);
// Fill content last because it also renders the output.
if (isset($input['content'])) {
$page->rawMarkdown((string) $input['content']);
}
} else {
$this->json_response = ['status' => 'unauthorized', 'message' => 'You have insufficient permissions for editing. Make sure you logged in.'];
return;
}
}