Пример #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 POST
  */
 function checkCaptcha()
 {
     // parse request
     parse_str($this->request->data, $request);
     $siteId = $request['siteId'];
     $pageUniqId = $request['pageId'];
     $recaptcha_challenge_field = $request['recaptcha_challenge_field'];
     $recaptcha_response_field = $request['recaptcha_response_field'];
     require_once '../libs/recaptchalib.php';
     $site = Site::GetBySiteId($siteId);
     $resp = recaptcha_check_answer($site['FormPrivateId'], $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/html';
     if ($resp->is_valid) {
         $response->body = 'OK';
     } else {
         $response->body = 'NOK';
     }
     return $response;
 }
Пример #3
0
 public static function Create($user, $canEdit, $canPublish, $canRemove, $canCreate)
 {
     session_start();
     $site = Site::GetBySiteId($user['SiteId']);
     $isSuperAdmin = false;
     if ($user['Email'] == SITE_ADMIN) {
         // set is superman
         $isSuperAdmin = true;
     }
     $isFirstLogin = 0;
     if ($site['LastLogin'] == null || $site['LastLogin'] == '') {
         $isFirstLogin = 1;
     }
     // determine whether user has a photo
     $hasPhotoUrl = true;
     if ($user['PhotoUrl'] == null || $user['PhotoUrl'] == '') {
         $hasPhotoUrl = false;
     }
     Site::SetLastLogin($site['SiteUniqId']);
     $directory = 'sites/' . $site['FriendlyId'] . '/';
     $_SESSION['UserId'] = $user['UserId'];
     $_SESSION['UserUniqId'] = $user['UserUniqId'];
     $_SESSION['Role'] = $user['Role'];
     $_SESSION['Language'] = $user['Language'];
     $_SESSION['IsSuperAdmin'] = $isSuperAdmin;
     $_SESSION['IsFirstLogin'] = $isFirstLogin;
     $_SESSION['Email'] = $user['Email'];
     $_SESSION['Name'] = $user['FirstName'] . ' ' . $user['LastName'];
     $_SESSION['FirstName'] = $user['FirstName'];
     $_SESSION['LastName'] = $user['LastName'];
     $_SESSION['HasPhotoUrl'] = $hasPhotoUrl;
     $_SESSION['PhotoUrl'] = $user['PhotoUrl'];
     $_SESSION['SiteId'] = $user['SiteId'];
     $_SESSION['SiteUniqId'] = $site['SiteUniqId'];
     $_SESSION['SiteFriendlyId'] = $site['FriendlyId'];
     $_SESSION['Domain'] = $site['Domain'];
     $_SESSION['Currency'] = $site['Currency'];
     $_SESSION['WeightUnit'] = $site['WeightUnit'];
     $_SESSION['Directory'] = $directory;
     $_SESSION['LogoUrl'] = $site['LogoUrl'];
     $_SESSION['sid'] = session_id();
     $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
     $_SESSION['SiteName'] = $site['Name'];
     $_SESSION['FileUrl'] = 'sites/' . $site['FriendlyId'] . '/files/';
     $_SESSION['TimeZone'] = $site['TimeZone'];
     $_SESSION['Type'] = $site['Type'];
     $_SESSION['CustomerId'] = $site['CustomerId'];
     // what can be edited and published
     if ($canEdit == 'All' || $canPublish == 'All' || $canRemove == 'All' || $canCreate == 'All') {
         $_SESSION['Access'] = 'All';
     } else {
         $_SESSION['Access'] = $canEdit . ',' . $canPublish . ',' . $canRemove . ',' . $canCreate;
     }
     $_SESSION['CanEdit'] = $canEdit;
     $_SESSION['CanPublish'] = $canPublish;
     $_SESSION['CanRemove'] = $canRemove;
     $_SESSION['CanCreate'] = $canCreate;
     if (strtoupper($site['Type']) == 'SUBSCRIPTION' && $site['CustomerId'] != NULL) {
         AuthUser::UpdateSubscription();
     } else {
         $_SESSION['Status'] = 'N/A';
         $_SESSION['Plan'] = 'N/A';
         $_SESSION['RenewalDate'] = NULL;
     }
 }
Пример #4
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;
 }
Пример #5
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);
         }
     }
 }
Пример #6
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);
     }
 }
Пример #7
0
 /**
  * @method GET
  */
 function get()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $site = Site::GetBySiteId($authUser->SiteId);
         $directory = '../sites/' . $site['FriendlyId'] . '/js/custom/';
         //get all image files with a .less ext
         $files = glob($directory . "*.js");
         $arr = array();
         //print each file name
         foreach ($files as $file) {
             $f_arr = explode("/", $file);
             $count = count($f_arr);
             $filename = $f_arr[$count - 1];
             array_push($arr, $filename);
         }
         // 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);
     }
 }
Пример #8
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
         Publish::PublishTemplate($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);
         }
     }
 }
Пример #9
0
 /**
  * @method GET
  */
 function get($friendlyId)
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $siteId = $authUser->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['TypeS']) . '/';
         }
         // get site url
         $site = Site::GetBySiteId($authUser->SiteId);
         $dir = 'sites/' . $site['FriendlyId'] . '/files/';
         // 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'] != '') {
                 if (strpos($page['Image'], 't-') !== false) {
                     $thumbUrl = $dir . $page['Image'];
                 } else {
                     $thumbUrl = $dir . 't-' . $page['Image'];
                 }
             }
             // set thumb
             $page['Thumb'] = $thumbUrl;
             $url = $page['FriendlyId'];
             if ($page['PageTypeId'] != -1) {
                 $pageType = PageType::GetByPageTypeId($page['PageTypeId']);
                 $url = strtolower($pageType['TypeS']) . '/' . $page['FriendlyId'];
             }
             // set url
             $page['Url'] = $url;
             // permissions are not applicable to this API call
             $page['CanEdit'] = '';
             $page['CanPublish'] = '';
             $page['CanRemove'] = '';
             $pages[$row['PageUniqId']] = $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);
     }
 }
Пример #10
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     $txn_type = $request['txn_type'];
     $status = $request['payer_status'];
     $siteId = $request['custom'];
     $email = $request['payer_email'];
     $payerId = $request['payer_id'];
     $item_name = $request['item_name'];
     // parse domain
     preg_match('#\\((.*?)\\)#', $item_name, $match);
     $domain = $match[1];
     // get reference to site
     $site = Site::GetBySiteId($siteId);
     // response was "VERIFIED"
     if ($status == 'verified' && $txn_type == 'subscr_signup') {
         $provider = 'PayPal';
         $status = 'Active';
         $subscriptionId = $payerId;
         $customerId = $email;
         // subscribe 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 . ': Thank your for subscribing to ' . BRAND;
         $file = APP_LOCATION . '/emails/subscribe-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 . ': New Subscriber';
         $file = APP_LOCATION . '/emails/subscribe-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}}' => $provider, '{{customerid}}' => $customerId);
         // send email from file
         Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
     } else {
         // IPN response was "INVALID"\
     }
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/HTML';
     $response->body = 'Yah!!!';
     return $response;
 }
Пример #11
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     $siteId = $request['custom'];
     // get reference to site
     $site = Site::GetBySiteId($siteId);
     $use_sandbox = false;
     // set whether to use a sandbox
     if ($site['PayPalUseSandbox'] == '1') {
         $use_sandbox = true;
     }
     $listener = new IpnListener();
     $listener->use_curl = false;
     $listener->use_sandbox = $use_sandbox;
     $listener->use_ssl = true;
     try {
         $verified = $listener->processIpn();
     } catch (Exception $e) {
         // fatal error trying to process IPN.
         exit(0);
     }
     // IPN response was "VERIFIED"
     if ($verified) {
         $processor = 'PayPal';
         if ($use_sandbox == true) {
             $processor .= ' (sandbox)';
         }
         $processorTransactionId = $request['txn_id'];
         $processorStatus = $request['payment_status'];
         $email = $request['payer_email'];
         $payerId = $request['payer_id'];
         $name = $request['first_name'] . ' ' . $request['last_name'];
         $shipping = $request['mc_handling'];
         $fee = $request['mc_fee'];
         $tax = $request['tax'];
         $total = $request['mc_gross'];
         $currency = $request['mc_currency'];
         $num_items = 1000;
         if (isset($request['num_cart_items'])) {
             $num_items = $request['num_cart_items'];
         }
         $items = array();
         // line-items (for receipt)
         $line_items = '';
         // set static URL
         $staticUrl = $site['Domain'];
         // get items
         for ($x = 1; $x <= $num_items; $x++) {
             if (isset($request['item_number' . $x])) {
                 $item_number = $request['item_number' . $x];
                 $item_name = $request['item_name' . $x];
                 $item_number = iconv("ISO-8859-1", "UTF-8", $item_number);
                 $item_name = iconv("ISO-8859-1", "UTF-8", $item_name);
                 $item_quantity = $request['quantity' . $x];
                 $item_total = $request['mc_gross_' . $x];
                 $item_price = floatval($item_total) / intval($item_quantity);
                 $item = array('ProductId' => $item_number, 'Name' => $item_name, 'Quantity' => $item_quantity, 'Price' => $item_price, 'Total' => $item_total);
                 // get product
                 $product = Product::GetByProductId($item_number);
                 // get download link
                 $download_link = '';
                 // check if there is a downloaded file for the product
                 if ($product['Download'] != '' && $product['Download'] != NULL) {
                     $download_link = '<br><a href="' . API_URL . '/transaction/download/{{transactionId}}/' . $item_number . '">Download</a>';
                 }
                 // setup currency for line items
                 $item_total = $item_total . ' ' . $currency;
                 $item_price = $item_price . ' ' . $currency;
                 // add $ for total and price
                 if ($currency == 'USD') {
                     $item_total = '$' . $item_total;
                     $item_price = '$' . $item_price;
                 }
                 $line_items .= '<tr style="border-bottom: 1px solid #f0f0f0;"><td>' . $item_name . '<br><small>' . $item_number . '</small>' . $download_link . '</td><td align="right">' . $item_price . '</td><td align="right">' . $item_quantity . '</td><td align="right">' . $item_total . '</td></tr>';
                 array_push($items, $item);
             }
         }
         $items_json = json_encode($items);
         $data_json = json_encode($_POST);
         // create receipt
         $receipt = $line_items;
         // add a transaction
         $transaction = Transaction::Add($site['SiteId'], $processor, $processorTransactionId, $processorStatus, $email, $payerId, $name, $shipping, $fee, $tax, $total, $currency, $items_json, $data_json, $receipt);
         // replace {{transactionId}} in line_items
         $line_items = str_replace('{{transactionId}}', $transaction['TransactionId'], $line_items);
         $site_logo = '';
         if ($site['LogoUrl'] != '' && $site['LogoUrl'] != NULL) {
             $site_logo = '<img src="' . $staticUrl . '/files/' . $site['LogoUrl'] . '" style="max-height:50px">';
         }
         // setup currency for line items
         $shipping = $shipping . ' ' . $currency;
         $tax = $tax . ' ' . $currency;
         $total = $total . ' ' . $currency;
         // add $ for total and price
         if ($currency == 'USD') {
             $shipping = '$' . $shipping;
             $tax = '$' . $tax;
             $total = '$' . $total;
         }
         // send email
         $replace = array('{{site}}' => $site['Name'], '{{site-logo}}' => $site_logo, '{{reply-to}}' => $site['PrimaryEmail'], '{{line-items}}' => $line_items, '{{shipping}}' => $shipping, '{{tax}}' => $tax, '{{total}}' => $total);
         // create subject
         $subject = SITE_RECEIPT_EMAIL_SUBJECT;
         $subject = str_replace('{{site}}', $site['Name'], $subject);
         $subject = str_replace('{{transactionId}}', $transaction['TransactionId'], $subject);
         // send email
         $content = $site['ReceiptEmail'];
         // walk through and replace values in associative array
         foreach ($replace as $key => &$value) {
             $content = str_replace($key, $value, $content);
             $subject = str_replace($key, $value, $subject);
         }
         // send site email
         Utilities::SendSiteEmail($site, $email, $site['PrimaryEmail'], $site['Name'], $subject, $content);
     } else {
         // IPN response was "INVALID"\
     }
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/HTML';
     $response->body = 'Yah!!!';
     return $response;
 }
Пример #12
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
         $pageTypeId = $request['pageTypeId'];
         $pageType = PageType::GetByPageTypeId($pageTypeId);
         $site = Site::GetBySiteId($pageType['SiteId']);
         // remove page type and pages from DB
         PageType::Remove($pageType['PageTypeId'], $token->SiteId);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         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 DELETE
  */
 function delete($pageTypeUniqId)
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $pageType = PageType::GetByPageTypeUniqId($pageTypeUniqId);
         $site = Site::GetBySiteId($pageType['SiteId']);
         // remove pages for that pagetype in that site
         $dir = '../sites/' . $site['FriendlyId'] . '/' . $pageType['FriendlyId'];
         if (file_exists($dir)) {
             Utilities::RemoveDirectory($dir);
         }
         // remove page type and pages from DB
         PageType::Delete($pageType['PageTypeId']);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Пример #16
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);
     }
 }
Пример #17
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);
     }
 }
Пример #18
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);
     }
 }
Пример #19
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;
     }
 }
Пример #20
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     // parse request
     $siteId = $request['siteId'];
     $friendlyId = $request['type'];
     $pageSize = $request['pagesize'];
     $orderBy = $request['orderby'];
     $current = $request['current'];
     // get language
     $language = 'en';
     // set order
     if ($orderBy == 'Created' || $orderBy == 'BeginDate') {
         $orderBy = 'Pages.' . $orderBy . ' DESC';
     } else {
         $orderBy = 'Pages.' . $orderBy . ' ASC';
     }
     if ($pageSize == '') {
         $pageSize = 10;
     }
     $site = Site::GetBySiteId($siteId);
     $pageType = PageType::GetByFriendlyId($friendlyId, $siteId);
     $list = Page::GetPages($site['SiteId'], $pageType['PageTypeId'], $pageSize, $current, $orderBy, true);
     $pages = array();
     foreach ($list as $row) {
         $page = Page::GetByPageId($row['PageId']);
         $name = $row['FirstName'] . ' ' . $row['LastName'];
         // get image url
         $thumbUrl = '';
         $imageUrl = '';
         $hasImage = false;
         if ($page['Image'] != '') {
             $hasImage = true;
             $thumbUrl = 'files/thumbs/' . $page['Image'];
             $imageUrl = 'files/' . substr($page['Image'], 2);
         }
         // check for callout
         $hasCallout = false;
         if ($page['Callout'] != '') {
             $hasCallout = true;
         }
         // build URL
         $url = strtolower($pageType['FriendlyId']) . '/' . $page['FriendlyId'];
         $beginDate = null;
         $beginReadable = '';
         if ($page['BeginDate'] != null) {
             // create a readable begin date
             $begin = DateTime::createFromFormat('Y-m-d H:i:s', $page['BeginDate']);
             $local = new DateTimeZone($site['TimeZone']);
             $begin->setTimezone($local);
             $beginReadable = $begin->format('D, M d y h:i a');
             $beginDate = $begin->format('Y-m-d H:i:s');
         }
         $endDate = null;
         $endReadable = '';
         if ($page['EndDate'] != null) {
             // create a readable end date
             $end = DateTime::createFromFormat('Y-m-d H:i:s', $page['EndDate']);
             $local = new DateTimeZone($site['TimeZone']);
             $end->setTimezone($local);
             $endReadable = $end->format('D, M d y h:i a');
             $endDate = $end->format('Y-m-d H:i:s');
         }
         $item = array('PageId' => $page['PageId'], 'Name' => $page['Name'], 'Description' => $page['Description'], 'Callout' => $page['Callout'], 'Location' => $page['Location'], 'LatLong' => $page['LatLong'], 'HasCallout' => $hasCallout, 'Url' => $url, 'Image' => $imageUrl, 'Thumb' => $thumbUrl, 'HasImage' => $hasImage, 'BeginDate' => $beginDate, 'BeginDateReadable' => $beginReadable, 'EndDate' => $endDate, 'EndDateReadable' => $endReadable, 'LastModified' => $page['LastModifiedDate'], 'Author' => $name, 'FirstName' => $row['FirstName'], 'LastName' => $row['LastName'], 'Photo' => $row['PhotoUrl'], 'Tags' => $page['Tags']);
         array_push($pages, $item);
     }
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'applicaton/json';
     $response->body = json_encode($pages);
     return $response;
     return new Tonic\Response(Tonic\Response::CREATED);
 }
Пример #21
0
 /**
  * @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);
 }
Пример #22
0
 /**
  * @method GET
  */
 function get()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $arr = array();
         $site = Site::GetBySiteId($authUser->SiteId);
         $directory = '../themes/' . $site['Theme'] . '/pages/';
         //get files with a .html ext
         $files = glob($directory . "*.html");
         $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('-', ' ', $filename);
             $name = str_replace('.html', '', $name);
             $name = ucfirst($name);
             $file = array('name' => $name, 'fileName' => $filename, 'location' => 'themes/' . $site['Theme'] . '/pages/' . $filename);
             array_push($arr, $file);
         }
         // 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);
     }
 }
Пример #23
0
 public static function DeploySite($siteId)
 {
     // get a reference to the site
     $site = Site::GetBySiteId($siteId);
     // create AWS client
     $client = Aws\S3\S3Client::factory(array('key' => S3_KEY, 'secret' => S3_SECRET, 'region' => S3_LOCATION));
     $bucket = $site['Bucket'];
     $bucket_www = 'www.' . $site['Bucket'];
     // create a bucket if it doesn't already exist
     S3::CreateBucket($bucket);
     // set local director
     $local_dir = SITES_LOCATION . '/' . $site['FriendlyId'];
     // prefix
     $keyPrefix = '';
     // set permissions
     $options = array('params' => array('ACL' => 'public-read'), 'concurrency' => 20, 'debug' => true);
     // sync folders, #ref: http://blogs.aws.amazon.com/php/post/Tx2W9JAA7RXVOXA/Syncing-Data-with-Amazon-S3
     $client->uploadDirectory($local_dir, $bucket, $keyPrefix, $options);
     // get json for the site
     $json = json_encode(Publish::CreateSiteJSON($site, 'S3'));
     // deploy an updated site.json
     $result = $client->putObject(array('Bucket' => $bucket, 'Key' => 'data/site.json', 'Body' => $json, 'ContentType' => 'application/json', 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY'));
     /*
     // #support for S3 ANAME   
     // #ref: http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_createBucket
     $result = $client->createBucket(array(
         'Bucket' => $bucket_www,
         'ACL'	 => 'public-read'		
     ));
     
     // enable hosting for the bucket
     $result = $client->putBucketWebsite(array(
         // Bucket is required
         'Bucket' => $bucket_www,
         'RedirectAllRequestsTo' => array(
             'HostName' => $bucket
         )));
     */
 }
Пример #24
0
 /**
  * @method POST
  */
 function get()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         parse_str($this->request->data, $request);
         // parse request
         $filename = $request['filename'];
         $site = Site::GetBySiteId($authUser->SiteId);
         $full_path = '../sites/' . $site['FriendlyId'] . '/files/' . $filename;
         $success = unlink($full_path);
         if ($success == true) {
             return new Tonic\Response(Tonic\Response::OK);
         } else {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = 'File could not be removed';
             return $response;
         }
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }