Пример #1
0
 /**
  * @method POST
  */
 function pay()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         // parse request
         parse_str($this->request->data, $request);
         $site = Site::GetBySiteId($token->SiteId);
         $siteId = $site['SiteId'];
         $email = $site['PrimaryEmail'];
         $status = 'Active';
         $stripe_token = $request['token'];
         $plan = $request['plan'];
         // set API key
         Stripe::setApiKey(STRIPE_SECRET_KEY);
         // create a new customer and subscribe them to the plan
         $customer = Stripe_Customer::create(array("card" => $stripe_token, "plan" => $plan, "email" => $email));
         // get back the id and the end period for the plan
         $id = $customer->id;
         // get subscription information
         $subscription = $customer->subscriptions->data[0];
         $subscriptionId = $subscription->id;
         $stripe_status = $subscription->status;
         $stripe_plan = $subscription->plan->id;
         $stripe_planname = $subscription->plan->name;
         // subscribe to a plan
         Site::Subscribe($siteId, $status, $plan, 'stripe', $subscriptionId, $customerId);
         // return a json response
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #2
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         $list = MenuType::GetMenuTypes($token->SiteId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($list);
         return $response;
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #3
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         // parse request
         parse_str($this->request->data, $request);
         $pageId = $request['pageId'];
         Product::RemoveForPage($pageId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #4
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         // parse request
         parse_str($this->request->data, $request);
         $pageId = $request['pageId'];
         $list = Version::GetVersions($pageId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($list);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #5
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         $site = Site::GetBySiteId($token->SiteId);
         $directory = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/styles/';
         //get all image files with a .less ext
         $files = glob($directory . "*.less");
         $arr = array();
         //print each file name
         foreach ($files as $file) {
             $f_arr = explode("/", $file);
             $count = count($f_arr);
             $filename = $f_arr[$count - 1];
             $name = str_replace('.less', '', $filename);
             array_push($arr, $name);
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($arr);
         return $response;
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #6
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         parse_str($this->request->data, $request);
         // parse request
         $configurations = $request['configurations'];
         $site = Site::GetBySiteId($token->SiteId);
         // get configuration
         $configure_file = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/configure.json';
         // put contents
         file_put_contents($configure_file, $configurations);
         // republish css
         Publish::PublishAllCSS($site);
         // get index
         $page = Page::GetByFriendlyId('index', '-1', $token->SiteId);
         // republish home page
         Publish::PublishPage($page['PageId']);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         return $response;
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #7
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         try {
             parse_str($this->request->data, $request);
             // parse request
             $roleId = $request['roleId'];
             // remove role
             Role::Remove($roleId, $token->SiteId);
             // return a response
             $response = new Tonic\Response(Tonic\Response::OK);
             $response->contentType = 'text/html';
             $response->body = 'success';
             return $response;
         } catch (Exception $e) {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = $e->getMessage();
             return $response;
         }
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #8
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     $siteId = -1;
     parse_str($this->request->data, $request);
     // parse request
     // check if token is not null
     if ($token != NULL) {
         $siteId = $token->SiteId;
     } else {
         if (isset($request['siteId'])) {
             $siteId = $request['siteId'];
         } else {
             // return an unauthorized exception (401)
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
     }
     // get a reference to the site
     $site = Site::GetBySiteId($siteId);
     // set directory an filename
     $dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales/';
     // array to store directories
     $list = array();
     if ($handle = opendir($dir)) {
         $blacklist = array('.', '..');
         while (false !== ($file = readdir($handle))) {
             if (!in_array($file, $blacklist)) {
                 array_push($list, $file);
             }
         }
         closedir($handle);
     }
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'application/json';
     $response->body = json_encode($list);
     return $response;
 }
Пример #9
0
 /**
  * @method POST
  */
 function post()
 {
     // get an authuser
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         parse_str($this->request->data, $request);
         // parse request
         Publish::PublishMenuJSON($token->SiteId);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #10
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         // parse request
         parse_str($this->request->data, $request);
         $site = Site::GetBySiteId($token->SiteId);
         $siteId = $site['siteId'];
         $status = $site['status'];
         $plan = $request['plan'];
         $provider = $request['provider'];
         $subscriptionId = $request['subscriptionId'];
         $customerId = $request['customerId'];
         $userLimit = $request['userLimit'];
         $fileLimit = $request['fileLimit'];
         // subscribe to a plan
         Site::EditSubscription($siteId, $status, $plan, $provider, $subscriptionId, $customerId, $userLimit, $fileLimit);
         // return a json response
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #11
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         parse_str($this->request->data, $request);
         // parse request
         // get transactions
         $list = Transaction::GetTransactions($token->SiteId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($list);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #12
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         $siteId = $token->SiteId;
         // get user
         $user = User::GetByUserId($token->UserId);
         // creates an access object
         $access = Utilities::SetAccess($user);
         // get pagetype
         $list = PageType::GetPageTypes($siteId);
         // allowed
         $allowed = array();
         // create a root element in the array
         $root = array('FriendlyId' => '', 'IsSecure' => 0, 'LastModifiedBy' => NULL, 'LastModifiedDate' => NULL, 'Layout' => 'content', 'PageTypeId' => -1, 'PageTypeId' => -1, 'SiteId' => -1, 'Stylesheet' => 'content');
         // return the entire list for all access
         if ($access['CanAccess'] == 'All') {
             $allowed = $list;
             array_unshift($allowed, $root);
         } else {
             foreach ($list as $row) {
                 $pageTypeId = $row['PageTypeId'];
                 if (Utilities::CanPerformAction('root', $access['CanAccess']) != false) {
                     array_push($allowed, $root);
                 }
                 //print('$pageTypeId='.$pageTypeId.' access='.$access['CanAccess']);
                 // check permissions
                 if (Utilities::CanPerformAction($pageTypeId, $access['CanAccess']) != false) {
                     array_push($allowed, $row);
                 }
             }
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($allowed);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #13
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         // parse request
         parse_str($this->request->data, $request);
         $site = Site::GetBySiteId($token->SiteId);
         $siteId = $site['SiteId'];
         $email = $site['PrimaryEmail'];
         $status = 'Unsubscribed';
         $plan = '';
         $provider = '';
         $subscriptionId = '';
         $customerId = $site['CustomerId'];
         // set API key
         Stripe::setApiKey(STRIPE_SECRET_KEY);
         // retrieve customer
         $customer = Stripe_Customer::retrieve($site['CustomerId']);
         // unsubscribe
         $cu->subscriptions->retrieve($site['SubscriptionId'])->cancel();
         // unsubscribe to a plan
         Site::Subscribe($siteId, $status, $plan, $provider, $subscriptionId, $customerId);
         // send success email to user
         $to = $site['PrimaryEmail'];
         $from = REPLY_TO;
         $fromName = REPLY_TO_NAME;
         $subject = BRAND . ': You have successfully unsubscribed to ' . BRAND;
         $file = APP_LOCATION . '/emails/unsubscribe-success.html';
         $replace = array('{{brand-logo}}' => '<img src="' . BRAND_LOGO . '" style="max-height:50px">', '{{brand}}' => BRAND, '{{reply-to}}' => REPLY_TO);
         // send
         Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
         // send details email to admin
         $to = REPLY_TO;
         $from = REPLY_TO;
         $fromName = REPLY_TO_NAME;
         $subject = BRAND . ': Unsubscribed';
         $file = APP_LOCATION . '/emails/unsubscribe-details.html';
         $replace = array('{{brand-logo}}' => '<img src="' . BRAND_LOGO . '" style="max-height:50px">', '{{brand}}' => BRAND, '{{reply-to}}' => REPLY_TO, '{{domain}}' => $domain, '{{siteid}}' => $site['SiteId'], '{{friendlyid}}' => $site['FriendlyId'], '{{provider}}' => $site['Provider'], '{{customerid}}' => $site['CustomerId']);
         // send email from file
         Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
         // return a json response
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #14
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         // get users
         $list = User::GetUsersForSite($token->SiteId, true);
         $site = Site::GetBySiteId($token->SiteId);
         $updated_list = array();
         //print each file name
         foreach ($list as $user) {
             $hasPhoto = false;
             $fullPhotoUrl = '';
             if ($user['PhotoUrl'] != '' && $user['PhotoUrl'] != '') {
                 $hasPhoto = true;
                 // set images URL
                 if (FILES_ON_S3 == true) {
                     $bucket = $site['Bucket'];
                     $imagesURL = str_replace('{{bucket}}', $bucket, S3_URL);
                     $imagesURL = str_replace('{{site}}', $site['FriendlyId'], $imagesURL);
                 } else {
                     $imagesURL = $site['Domain'];
                 }
                 $fullPhotoUrl = $imagesURL . '/files/thumbs/' . $user['PhotoUrl'];
             }
             $user['HasPhoto'] = $hasPhoto;
             $user['FullPhotoUrl'] = $fullPhotoUrl;
             array_push($updated_list, $user);
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($updated_list);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #15
0
 /**
  * @method POST
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // 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
         $filename = $request['filename'];
         $folder = 'files';
         if (isset($_REQUEST['folder'])) {
             $folder = $_REQUEST['folder'];
         }
         if (FILES_ON_S3 == true) {
             // remove file on S3
             S3::RemoveFile($site, $filename, $folder);
         } else {
             // remove local file
             // remove file
             $path = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $folder . '/' . $filename;
             if (file_exists($path)) {
                 $path = unlink($path);
             }
             // remove thumb
             $path = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $folder . '/thumbs/' . $filename;
             if (file_exists($path)) {
                 $path = unlink($path);
             }
         }
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #16
0
 /**
  * @method GET
  */
 function get($friendlyId)
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         // get a reference to the site
         $site = Site::GetBySiteId($token->SiteId);
         $siteId = $token->SiteId;
         $pageSize = 100;
         $orderBy = 'Created DESC';
         $page = 0;
         $pageTypeId = -1;
         $dir = '/';
         if ($friendlyId != 'root') {
             // get pagetype
             $pageType = PageType::GetByFriendlyId($friendlyId, $siteId);
             $pageTypeId = $pageType['PageTypeId'];
             $dir = strtolower($pageType['FriendlyId']) . '/';
         }
         // get pages
         $list = Page::GetPages($siteId, $pageTypeId, $pageSize, $page, $orderBy);
         $pages = array();
         foreach ($list as $row) {
             $page = Page::GetByPageId($row['PageId']);
             $fullName = $row['FirstName'] . ' ' . $row['LastName'];
             $page['LastModifiedFullName'] = $fullName;
             $thumbUrl = '';
             if ($page['Image'] != '') {
                 $thumbUrl = '/files/thumbs/' . $page['Image'];
             }
             // set thumb
             $page['Thumb'] = $thumbUrl;
             $url = $page['FriendlyId'];
             if ($page['PageTypeId'] != -1) {
                 $pageType = PageType::GetByPageTypeId($page['PageTypeId']);
                 $url = strtolower($pageType['FriendlyId']) . '/' . $page['FriendlyId'];
             }
             // set url
             $page['Url'] = $url;
             // permissions are not applicable to this API call
             $page['CanEdit'] = '';
             $page['CanPublish'] = '';
             $page['CanRemove'] = '';
             $pages[$row['PageId']] = $page;
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($pages);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #17
0
 /**
  * @method POST
  */
 function post()
 {
     // get an authuser
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         parse_str($this->request->data, $request);
         // parse request
         // re-publish the content of the site
         Publish::PublishContent($token->SiteId);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }