本文整理汇总了PHP中Utilities::SaveContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Utilities::SaveContent方法的具体用法?PHP Utilities::SaveContent怎么用?PHP Utilities::SaveContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities
的用法示例。
在下文中一共展示了Utilities::SaveContent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PublishPage
public static function PublishPage($pageUniqId, $preview = false, $remove_draft = false, $root = '../')
{
$page = Page::GetByPageUniqId($pageUniqId);
if ($page != null) {
$site = Site::GetBySiteId($page['SiteId']);
// test for now
$dest = $root . 'sites/' . $site['FriendlyId'] . '/';
$imageurl = $dest . 'files/';
$siteurl = 'http://' . $site['Domain'] . '/';
$friendlyId = $page['FriendlyId'];
$url = '';
$file = '';
if ($preview == true) {
$previewId = uniqid();
$file = $page['FriendlyId'] . '-' . $previewId . '-preview.php';
} else {
$file = $page['FriendlyId'] . '.php';
}
// create a nice path to store the file
if ($page['PageTypeId'] == -1) {
$url = $page['FriendlyId'] . '.php';
$path = '';
} else {
$pageType = PageType::GetByPageTypeId($page['PageTypeId']);
$path = 'uncategorized/';
if ($pageType != null) {
$path = strtolower($pageType['FriendlyId']) . '/';
}
}
// generate default
$html = Utilities::GeneratePage($site, $page, $siteurl, $imageurl, $preview, $root);
// remove any drafts associated with the page
if ($remove_draft == true) {
$draft = $root . 'sites/' . $site['FriendlyId'] . '/fragments/draft/' . $page['PageUniqId'] . '.html';
if (file_exists($draft)) {
unlink($draft);
}
}
if ($preview == true) {
$s_dest = $dest . 'preview/';
} else {
$s_dest = $dest . $path;
}
// save the content to the published file
Utilities::SaveContent($s_dest, $file, $html);
// publish a rendered fragment
Publish::PublishRender($site, $page, $root);
// build the search index for the page
Publish::BuildSearchIndex($site, $page, $root);
return $s_dest . $file;
}
}
示例2: generate
/**
* @method POST
*/
function generate()
{
// get an authuser
$authUser = new AuthUser();
if (isset($authUser->UserUniqId)) {
// check if authorized
parse_str($this->request->data, $request);
// parse request
$name = $request['name'];
$content = $request['content'];
$site = Site::GetBySiteId($authUser->SiteId);
$dir = '../sites/' . $site['FriendlyId'] . '/';
Utilities::SaveContent($dir, $name, $content);
return new Tonic\Response(Tonic\Response::OK);
} else {
// unauthorized access
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
return new Tonic\Response(Tonic\Response::NOTIMPLEMENTED);
}
示例3: PublishStaticPage
public static function PublishStaticPage($page, $site, $preview = false, $remove_draft = false)
{
$dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/';
$imageurl = $dest . 'files/';
$siteurl = $site['Domain'] . '/';
$friendlyId = $page['FriendlyId'];
$url = '';
$file = '';
// created ctrl
$ctrl = ucfirst($page['FriendlyId']);
$ctrl = str_replace('-', '', $ctrl);
// set base
$base = '';
// create a static location for the page
if ($page['PageTypeId'] == -1) {
$url = $page['FriendlyId'] . '.html';
$dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/';
} else {
$pageType = PageType::GetByPageTypeId($page['PageTypeId']);
$dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/uncategorized/';
if ($pageType != null) {
$dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $pageType['FriendlyId'] . '/';
// created ctrl
$ctrl = ucfirst($pageType['FriendlyId']) . $ctrl;
$ctrl = str_replace('-', '', $ctrl);
}
// explode friendlyid by '/'
$parts = explode('/', $pageType['FriendlyId']);
// set base based on the depth
foreach ($parts as $part) {
$base .= '../';
}
}
// create directory if it does not exist
if (!file_exists($dest)) {
mkdir($dest, 0755, true);
}
// generate default
$html = '';
$content = '';
// get index and layout (file_get_contents)
$index = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/layouts/index.html';
$layout = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/layouts/' . $page['Layout'] . '.html';
// get index html
if (file_exists($index)) {
$html = file_get_contents($index);
}
// get layout html
if (file_exists($layout)) {
$layout_html = file_get_contents($layout);
// set class
$cssClass = $page['Stylesheet'];
// set show-cart, show-settings, show-languages, show-login
if ($site['ShowCart'] == 1) {
$cssClass .= ' show-cart';
}
if ($site['ShowSettings'] == 1) {
$cssClass .= ' show-settings';
}
if ($site['ShowLanguages'] == 1) {
$cssClass .= ' show-languages';
}
if ($site['ShowLogin'] == 1) {
$cssClass .= ' show-login';
}
$html = str_replace('<body ui-view></body>', '<body page="' . $page['PageId'] . '" class="' . $cssClass . '">' . $layout_html . '</body>', $html);
$html = str_replace('<body></body>', '<body page="' . $page['PageId'] . '" class="' . $cssClass . '">' . $layout_html . '</body>', $html);
}
// get draft/content
if ($preview == true) {
$file = $page['FriendlyId'] . '.preview.html';
$content = $page['Draft'];
} else {
$file = $page['FriendlyId'] . '.html';
$content = $page['Content'];
}
// replace respond-content for layout with content
$html = str_replace('<respond-content id="main-content" url="{{page.Url}}"></respond-content>', $content, $html);
// remove any drafts associated with the page
if ($remove_draft == true) {
// remove a draft from the page
Page::RemoveDraft($page['PageId']);
}
if ($html !== NULL) {
// parse the html for menus
$html = str_get_html($html, true, true, DEFAULT_TARGET_CHARSET, false, DEFAULT_BR_TEXT);
// generate the [render=publish] components
$html = Publish::GenerateRenderAtPublish($html, $site, $page);
// applies the style attributes to the $html
$html = Publish::ApplyStyleAttributes($html);
// applies the mustache syntax
$html = Publish::ApplyMustacheSyntax($html, $site, $page);
} else {
$html = '';
}
// update base
$html = str_replace('<base href="/">', '<base href="' . $base . '">', $html);
// save the content to the published file
Utilities::SaveContent($dest, $file, $html);
return $dest . $file;
//.........这里部分代码省略.........
示例4: post
/**
* @method POST
*/
function post()
{
// get token
$token = Utilities::ValidateJWTToken();
// check if token is not null
if ($token != NULL) {
// get a reference to the site, user
$site = Site::GetBySiteId($token->SiteId);
parse_str($this->request->data, $request);
// parse request
// get content
$content = $request['content'];
// set locale as default language
$locale = $site['Language'];
// override if in request
if (isset($request['locale'])) {
$locale = $request['locale'];
}
// decode JSON
$json = json_decode($content);
// encode it to make it look pretty
if (defined('JSON_PRETTY_PRINT')) {
$content = json_encode($json, JSON_PRETTY_PRINT);
} else {
$content = json_encode($json);
}
// make the locales directory if it does not exist
$locales_dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales';
// create locales directory if it does not exist
if (!file_exists($locales_dir)) {
mkdir($locales_dir, 0755, true);
}
// set directory an filename
$locale_dir = $locales_dir . '/' . $locale . '/';
// make the locale dir if it does not exist
if (!file_exists($locale_dir)) {
mkdir($locale_dir, 0755, true);
}
// set filename
$filename = 'translation.json';
// save content
Utilities::SaveContent($locale_dir, $filename, $content);
// return a json response
return new Tonic\Response(Tonic\Response::OK);
} else {
// return an unauthorized exception (401)
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}
示例5: PublishStaticPage
//.........这里部分代码省略.........
$file = $page['FriendlyId'] . '.preview.html';
$content = $page['Draft'];
} else {
$file = $page['FriendlyId'] . '.html';
$content = $page['Content'];
}
// replace respond-content for layout with content
$html = str_replace('<respond-content id="main-content" url="{{page.Url}}"></respond-content>', $content, $html);
// remove any drafts associated with the page
if ($remove_draft == true) {
// remove a draft from the page
Page::RemoveDraft($page['PageId']);
}
// replace common Angular calls for SEO, e.g. {{page.Name}} {{page.Description}} {{site.Name}}
$html = str_replace('{{page.Name}}', $page['Name'], $html);
$html = str_replace('{{page.Description}}', $page['Description'], $html);
$html = str_replace('{{page.Keywords}}', $page['Keywords'], $html);
$html = str_replace('{{page.Callout}}', $page['Callout'], $html);
$html = str_replace('{{site.Name}}', $site['Name'], $html);
$html = str_replace('{{site.Language}}', $site['Language'], $html);
$html = str_replace('{{site.Direction}}', $site['Direction'], $html);
$html = str_replace('{{page.FullStylesheetUrl}}', 'css/' . $page['Stylesheet'] . '.css', $html);
// update base
$html = str_replace('<base href="/">', '<base href="' . $base . '">', $html);
// add menu links for SEO (<respond-menu type="primary"></respond-menu>)
$delimiter = '#';
$startTag = '<respond-menu type="';
$endTag = '"></respond-menu>';
$regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's';
// match against html
preg_match_all($regex, $html, $matches);
// crawl matches
foreach ($matches[1] as &$value) {
// init menu
$menu = '';
// get items for type
$menuItems = MenuItem::GetMenuItemsForType($site['SiteId'], $value);
$i = 0;
$parent_flag = false;
$new_parent = true;
// walk through items
foreach ($menuItems as $menuItem) {
$url = $menuItem['Url'];
$name = $menuItem['Name'];
$css = '';
$cssClass = '';
$active = '';
if ($page['PageId'] == $menuItem['PageId']) {
$css = 'active';
}
$css .= ' ' . $menuItem['CssClass'];
if (trim($css) != '') {
$cssClass = ' class="' . $css . '"';
}
// check for new parent
if (isset($menuItems[$i + 1])) {
if ($menuItems[$i + 1]['IsNested'] == 1 && $new_parent == true) {
$parent_flag = true;
}
}
$menu_root = '/';
// check for external links
if (strpos($url, 'http') !== false) {
$menu_root = '';
}
if ($new_parent == true && $parent_flag == true) {
$menu .= '<li>';
$menu .= '<a href="' . $menu_root . $url . '">' . $menuItem['Name'] . '</a>';
$menu .= '<ul class="dropdown-menu">';
$new_parent = false;
} else {
$menu .= '<li' . $cssClass . '>';
$menu .= '<a href="' . $menu_root . $url . '">' . $menuItem['Name'] . '</a>';
$menu .= '</li>';
}
// end parent
if (isset($menuItems[$i + 1])) {
if ($menuItems[$i + 1]['IsNested'] == 0 && $parent_flag == true) {
$menu .= '</ul></li>';
// end parent if next item is not nested
$parent_flag = false;
$new_parent = true;
}
} else {
if ($parent_flag == true) {
$menu .= '</ul></li>';
// end parent if next menu item is null
$parent_flag = false;
$new_parent = true;
}
}
}
$i = $i + 1;
// fill menu with string
$html = str_replace('<respond-menu type="' . $value . '"></respond-menu>', '<respond-menu type="' . $value . '">' . $menu . '</respond-menu>', $html);
}
// save the content to the published file
Utilities::SaveContent($dest, $file, $html);
return $dest . $file;
}
示例6: post
//.........这里部分代码省略.........
return new Tonic\Response(Tonic\Response::BADREQUEST);
}
} else {
// get an authuser
$authUser = new AuthUser();
if ($authUser->UserId && $authUser->IsSuperAdmin == true) {
// check if authorized
$userId = $authUser->UserId;
} else {
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}
// defaults
$domain = SITE_URL;
$domain = str_replace('{{friendlyId}}', $friendlyId, $domain);
$logoUrl = 'sample-logo.png';
$altLogoUrl = '';
if ($s_passcode == PASSCODE) {
$isFriendlyIdUnique = Site::IsFriendlyIdUnique($friendlyId);
// check for reserved names
if ($friendlyId == 'app' || $friendlyId == 'sites' || $friendlyId == 'api' || $friendlyId == 'triangulate' || $friendlyId == 'developer') {
$isFriendlyIdUnique = false;
}
if ($isFriendlyIdUnique == false) {
return new Tonic\Response(Tonic\Response::CONFLICT);
}
// default is blank
$welcomeEmail = '';
$receiptEmail = '';
// files for emails
$welcome_file = APP_LOCATION . '/site/emails/welcome.html';
$receipt_file = APP_LOCATION . '/site/emails/receipt.html';
// make sure the welcome email exists
if (file_exists($welcome_file)) {
// get default email file
$welcomeEmail = file_get_contents($welcome_file);
}
// make sure the receipt email exists
if (file_exists($receipt_file)) {
// get default email file
$receiptEmail = file_get_contents($receipt_file);
}
// add the site
$site = Site::Add($domain, $name, $friendlyId, $logoUrl, $altLogoUrl, $theme, $email, $timeZone, $language, $direction, $welcomeEmail, $receiptEmail);
// add the admin
if ($email != '') {
$isActive = 1;
// admins by default are active
$user = User::Add($email, $password, $firstName, $lastName, 'Admin', $userLanguage, $isActive, $site['SiteId']);
$userId = $user['UserId'];
}
// set $siteId
$siteId = $site['SiteId'];
// publishes a theme for a site
Publish::PublishTheme($site, $theme);
// publish default content for the theme
Publish::PublishDefaultContent($site, $theme, $user['UserId']);
// publish the site
Publish::PublishSite($site['SiteId']);
// create a locale directory
$locales_dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales';
// create locales directory if it does not exist
if (!file_exists($locales_dir)) {
mkdir($locales_dir, 0755, true);
}
// set directory for locale
$locale_dir = $locales_dir . '/' . $site['Language'] . '/';
// make the locale dir if it does not exist
if (!file_exists($locale_dir)) {
mkdir($locale_dir, 0755, true);
}
// set filename
$filename = 'translation.json';
if (!file_exists($locale_dir . $filename)) {
// create a blank translation file
Utilities::SaveContent($locale_dir, $filename, '{}');
}
// send welcome email
if (SEND_WELCOME_EMAIL == true && $email != '') {
$to = $email;
$from = EMAILS_FROM;
$fromName = EMAILS_FROM_NAME;
$subject = WELCOME_EMAIL_SUBJECT;
$file = WELCOME_EMAIL_FILE;
// create strings to replace
$loginUrl = APP_URL . '/login/' . $site['FriendlyId'];
$newSiteUrl = $domain;
$replace = array('{{brand-logo}}' => '<img src="' . BRAND_LOGO . '" style="max-height:50px">', '{{brand}}' => BRAND, '{{reply-to}}' => EMAILS_FROM, '{{new-site-url}}' => $newSiteUrl, '{{login-url}}' => $loginUrl);
// send email from file
Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
}
// send new site hook
Webhooks::NewSite($site);
// send new user hook
Webhooks::NewUser($user);
return new Tonic\Response(Tonic\Response::OK);
} else {
return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
}
}
示例7: PublishStaticPage
//.........这里部分代码省略.........
}
} else {
if ($backgroundstyle == 'parallax') {
$el->{'data-parallax'} = 'scroll';
$el->{'data-image-src'} = $backgroundimage;
} else {
if ($backgroundstyle == 'repeat') {
$el->style = $style . 'background-image: url(' . $backgroundimage . '); background-repeat: repeat;';
} else {
$el->style = $style . 'background-image: url(' . $backgroundimage . '); background-size: cover; background-position: center center;';
}
}
}
}
/* foreach */
// replace textcolor
foreach ($html->find('[textcolor]') as $el) {
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' color: ' . $el->textcolor . ';';
} else {
$el->style = 'color: ' . $el->textcolor . ';';
}
}
/* foreach */
// replace paddingtop
foreach ($html->find('[paddingtop]') as $el) {
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' padding-top: ' . $el->paddingtop . 'px;';
} else {
$el->style = 'padding-top: ' . $el->paddingtop . 'px;';
}
}
/* foreach */
// replace paddingright
foreach ($html->find('[paddingright]') as $el) {
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' padding-right: ' . $el->paddingright . 'px;';
} else {
$el->style = 'padding-right: ' . $el->paddingright . 'px;';
}
}
/* foreach */
// replace paddingbottom
foreach ($html->find('[paddingbottom]') as $el) {
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' padding-bottom: ' . $el->paddingbottom . 'px;';
} else {
$el->style = 'padding-bottom: ' . $el->paddingbottom . 'px;';
}
}
/* foreach */
// replace paddingleft
foreach ($html->find('[paddingleft]') as $el) {
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' padding-left: ' . $el->paddingleft . 'px;';
} else {
$el->style = 'padding-left: ' . $el->paddingleft . 'px;';
}
}
/* foreach */
// replace textshadowcolor
foreach ($html->find('[textshadowcolor]') as $el) {
$color = $el->textshadowcolor;
$horizontal = '1px';
$vertical = '1px';
$blur = '1px';
if (isset($el->textshadowhorizontal)) {
$horizontal = $el->textshadowhorizontal;
}
if (isset($el->textshadowvertical)) {
$vertical = $el->textshadowblur;
}
if (isset($el->textshadowvertical)) {
$blur = $el->textshadowblur;
}
// build shadow
$textshadow = $horizontal . ' ' . $vertical . ' ' . $blur . ' ' . $color . ';';
// if it is nested, break
if (isset($el->style)) {
$el->style = $el->style . ' text-shadow: ' . $textshadow;
} else {
$el->style = 'text-shadow: ' . $textshadow;
}
}
/* foreach */
// replace textsize
foreach ($html->find('[textsize]') as $el) {
$textsize = $el->textsize;
$el->innertext = '<span style="font-size:' . $textsize . '">' . $el->innertext . '</span>';
}
/* foreach */
// save the content to the published file
Utilities::SaveContent($dest, $file, $html);
return $dest . $file;
}