Example #1
0
 /**
  * @method POST
  */
 function form()
 {
     // parse request
     parse_str($this->request->data, $request);
     $siteUniqId = SITE_UNIQ_ID;
     $pageUniqId = $request['pageUniqId'];
     $body = $request['body'];
     $site = Site::GetBySiteUniqId($siteUniqId);
     $page = Page::GetByPageUniqId($pageUniqId);
     if ($site != null && $page != null) {
         $subject = 'RespondCMS: Form Submission [' . $site['Name'] . ': ' . $page['Name'] . ']';
         $content = '<h3>Site Information</h3>' . '<table>' . '<tr>' . '<td style="padding: 5px 25px 5px 0;">Site:</td>' . '<td style="padding: 5px 0">' . $site['Name'] . '</td>' . '</tr>' . '<tr>' . '<td style="padding: 5px 25px 5px 0;">Page:</td>' . '<td style="padding: 5px 0">' . $page['Name'] . '</td>' . '</tr>' . '</table>' . '<h3>Form Details</h3>' . $body;
         // send an email
         $headers = 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
         $headers .= 'From: ' . $site['PrimaryEmail'] . "\r\n" . 'Reply-To: ' . $site['PrimaryEmail'] . "\r\n";
         // sends the email
         $to = $site['PrimaryEmail'];
         $from = $site['PrimaryEmail'];
         $fromName = $site['Name'];
         Utilities::SendEmail($to, $from, $fromName, $subject, $content);
         // return a successful response (200)
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Example #2
0
 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;
     }
 }
Example #3
0
 /**
  * @method POST
  */
 function unpublish($pageUniqId)
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         // get page
         $page = Page::GetByPageUniqId($pageUniqId);
         // make sure the user is part of the site (or is a superadmin)
         if ($authUser->IsSuperAdmin == false && $authUser->SiteId != $page['SiteId']) {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
         // delete page
         $site = Site::GetBySiteId($page['SiteId']);
         $filename = '../sites/' . $site['FriendlyId'] . '/';
         // default is root
         $pageTypeUniqId = -1;
         // get $pageTypeUniqId
         if ($page['PageTypeId'] != -1) {
             $pageType = PageType::GetByPageTypeId($page['PageTypeId']);
             $filename .= strtolower($pageType['FriendlyId']) . '/';
             $pageTypeUniqId = $pageType['PageTypeUniqId'];
         }
         // check permissions
         if (Utilities::CanPerformAction($pageTypeUniqId, $authUser->CanPublish) == false) {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
         // set active
         Page::SetIsActive($pageUniqId, 0);
         // remove file
         $filename = $filename . $page['FriendlyId'] . '.php';
         if (file_exists($filename)) {
             unlink($filename);
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }