Пример #1
0
 public static function PublishPage($pageId, $preview = false, $remove_draft = false)
 {
     $page = Page::GetByPageId($pageId);
     if ($page != null) {
         $site = Site::GetBySiteId($page['SiteId']);
         // test for now
         if ($site['UrlMode'] == 'static') {
             // for sites using static html pages (URL-based routing)
             Publish::PublishDynamicPage($page, $site, $preview, $remove_draft);
             // do not publish a static page for include only pages
             if ($page['IncludeOnly'] == 0) {
                 Publish::PublishStaticPage($page, $site, $preview, $remove_draft);
             }
             // inject controllers
             Publish::InjectControllers($site);
         } else {
             // publishes a dynamic version of the page (for sites using UI-ROUTER (html5, hashbang, etc)
             Publish::PublishDynamicPage($page, $site, $preview, $remove_draft);
             // inject states
             Publish::InjectStates($site);
         }
     }
 }
Пример #2
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         $user = User::GetByUserId($token->UserId);
         $site = Site::GetBySiteId($token->SiteId);
         // creates an access object
         $access = Utilities::SetAccess($user);
         parse_str($this->request->data, $request);
         // parse request
         $pageId = $request['pageId'];
         $page = Page::GetByPageId($pageId);
         // check permissions
         if (Utilities::CanPerformAction($page['PageTypeId'], $access['CanEdit']) == false) {
             return new Tonic\Response(Tonic\Response::BADREQUEST);
         }
         // make sure page is part of the site
         if ($page['SiteId'] == $site['SiteId']) {
             // get file location
             $path = SITES_LOCATION . '/' . $site['FriendlyId'] . '/';
             $static_path = SITES_LOCATION . '/' . $site['FriendlyId'] . '/';
             // default is root
             $pageTypeId = -1;
             // set file
             $file = $page['FriendlyId'] . '.html';
             // set file
             if ($page['PageTypeId'] != -1) {
                 $pageType = PageType::GetByPageTypeId($page['PageTypeId']);
                 if ($pageType != NULL) {
                     $pageTypeId = $pageType['PageTypeId'];
                     $file = $pageType['FriendlyId'] . '.' . $page['FriendlyId'] . '.html';
                     $static_path = $static_file . $pageType['FriendlyId'] . '/';
                 }
             }
             // check permissions
             if (Utilities::CanPerformAction($pageTypeId, $access['CanRemove']) == false) {
                 return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
             }
             // set template
             $template = $path . 'templates/page/' . $file;
             // remove template
             if (file_exists($template)) {
                 unlink($template);
             }
             $static_file = $static_path . $file;
             // remove static file if it exists
             if (file_exists($static_file)) {
                 unlink($static_file);
             }
             // remove page from the DB
             Page::Remove($pageId);
             if ($site['UrlMode'] == 'static') {
                 // update controllers
                 Publish::InjectControllers($site);
             } else {
                 // update states
                 Publish::InjectStates($site);
             }
             return new Tonic\Response(Tonic\Response::OK);
         } else {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }