Beispiel #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);
     }
 }
Beispiel #2
0
 /**
  * @method POST
  */
 function get()
 {
     parse_str($this->request->data, $request);
     // parse request
     $term = $request['term'];
     $language = $request['language'];
     $siteUniqId = SITE_UNIQ_ID;
     $site = Site::GetBySiteUniqId($siteUniqId);
     $showSecure = false;
     if (isset($_SESSION[$site['FriendlyId'] . '.UserId'])) {
         $showSecure = true;
     }
     $results = SearchIndex::Search($siteUniqId, $language, $term, $showSecure);
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'application/json';
     $response->body = json_encode($results);
     return $response;
 }
Beispiel #3
0
 /**
  * @method POST
  */
 function checkCaptcha()
 {
     // parse request
     parse_str($this->request->data, $request);
     $siteUniqId = $request['siteUniqId'];
     $pageUniqId = $request['pageUniqId'];
     $recaptcha_challenge_field = $request['recaptcha_challenge_field'];
     $recaptcha_response_field = $request['recaptcha_response_field'];
     require_once '../libs/recaptchalib.php';
     $site = Site::GetBySiteUniqId($siteUniqId);
     $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;
 }
Beispiel #4
0
 /**
  * @method POST
  */
 function post()
 {
     // parse request
     parse_str($this->request->data, $request);
     $plan = $request['plan'];
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         try {
             $site = Site::GetBySiteUniqId($authUser->SiteUniqId);
             Stripe::setApiKey(STRIPE_API_KEY);
             $customer = Stripe_Customer::retrieve($site['CustomerId']);
             // retrieve default subscription
             if (isset($customer->subscriptions->data[0])) {
                 $subscription = $customer->subscriptions->data[0];
                 // updates the subscription
                 if ($subscription != NULL) {
                     $subscription->plan = $plan;
                     $subscription->save();
                 }
                 // update the session
                 AuthUser::UpdateSubscription();
             }
             // return a json response
             return new Tonic\Response(Tonic\Response::OK);
         } catch (Exception $e) {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = $e->getMessage();
             return $response;
         }
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Beispiel #5
0
 /**
  * @method GET
  */
 function get($siteUniqId)
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $site = Site::GetBySiteUniqId($siteUniqId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($site);
         return $response;
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Beispiel #6
0
 public static function PublishAllCSS($siteUniqId, $root = '../')
 {
     $site = Site::GetBySiteUniqId($siteUniqId);
     // test for now
     $lessDir = $root . 'sites/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/styles/';
     //get all image files with a .less ext
     $files = glob($lessDir . "*.less");
     //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);
         Publish::PublishCSS($site, $name, $root);
     }
 }
Beispiel #7
0
 /**
  * @method POST
  */
 function post($theme)
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $site = Site::GetBySiteUniqId($authUser->SiteUniqId);
         // publishes a theme for a site
         Publish::PublishTheme($site, $theme);
         // republish site with the new theme
         Publish::PublishSite($site['SiteUniqId']);
         // 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);
     }
 }
Beispiel #8
0
 /**
  * @method POST
  */
 function get()
 {
     parse_str($this->request->data, $request);
     // parse request
     $siteUniqId = SITE_UNIQ_ID;
     $pageTypeUniqId = $request['pageTypeUniqId'];
     $site = Site::GetBySiteUniqId($siteUniqId);
     $pageType = PageType::GetByPageTypeUniqId($pageTypeUniqId);
     // Get all pages
     $total = Page::GetPagesCount($site['SiteId'], $pageType['PageTypeId'], true);
     $json = '{"total":"' . $total . '"}';
     header('Content-type: application/json');
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'applicaton/json';
     $response->body = $json;
     return $response;
 }
Beispiel #9
0
 /**
  * @method POST
  */
 function add()
 {
     // parse request
     parse_str($this->request->data, $request);
     // parse request
     $email = $request['email'];
     $password = $request['password'];
     $firstName = $request['firstName'];
     $lastName = $request['lastName'];
     $role = 'Member';
     $isActive = 0;
     $language = $request['language'];
     $site = Site::GetBySiteUniqId(SITE_UNIQ_ID);
     $user = User::Add($email, $password, $firstName, $lastName, $role, $language, $isActive, $site['SiteId']);
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'applicaton/json';
     $response->body = json_encode($user);
     return $response;
 }
Beispiel #10
0
 /**
  * @method POST
  */
 function post()
 {
     // parse request
     parse_str($this->request->data, $request);
     $token = $request['token'];
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         try {
             $site = Site::GetBySiteUniqId($authUser->SiteUniqId);
             Stripe::setApiKey(STRIPE_API_KEY);
             $customer = Stripe_Customer::retrieve($site['CustomerId']);
             //$customer->cards->create(array("card" => $token));
             $customer->card = $token;
             $customer->save();
             // return a 200
             return new Tonic\Response(Tonic\Response::OK);
         } catch (Exception $e) {
             $response = new Tonic\Response(Tonic\Response::BADREQUEST);
             $response->body = $e->getMessage();
             return $response;
         }
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Beispiel #11
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     $siteUniqId = $request['custom'];
     // get reference to site
     $site = Site::GetBySiteUniqId($siteUniqId);
     $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 = '';
         // get items
         for ($x = 1; $x <= $num_items; $x++) {
             if (isset($request['item_number' . $x])) {
                 $arr_temp = explode('-', $request['item_number' . $x]);
                 // shipping type is the last item of the array
                 $item_shipping_type = $arr_temp[count($arr_temp) - 1];
                 // the sku is the last item less the type
                 $item_sku = str_replace('-' . $item_shipping_type, '', $request['item_number' . $x]);
                 $item_name = $request['item_name' . $x];
                 $item_sku = iconv("ISO-8859-1", "UTF-8", $item_name);
                 $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('SKU' => $item_sku, 'Name' => $item_name, 'ShippingType' => $item_shipping_type, 'Quantity' => $item_quantity, 'Price' => $item_price, 'Total' => $item_total);
                 $download_link = '';
                 if ($item_shipping_type == 'DOWNLOAD') {
                     $download_link = '<br><a href="http://' . $site['Domain'] . '/api/transaction/download/{{transactionUniqId}}/' . $item_sku . '">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_sku . '</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);
         // add a transaction
         $transaction = Transaction::Add($site['SiteId'], $processor, $processorTransactionId, $processorStatus, $email, $payerId, $name, $shipping, $fee, $tax, $total, $currency, $items_json, $data_json);
         // replace {{transactionUniqId}} in line_items
         $line_items = str_replace('{{transactionUniqId}}', $transaction['TransactionUniqId'], $line_items);
         $site_logo = '';
         if ($site['LogoUrl'] != '' && $site['LogoUrl'] != NULL) {
             $site_logo = '<img src="http://' . $site['Domain'] . '/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);
         $subject = '[' . $site['Name'] . '] Receipt for your purchase from ' . $site['Name'] . ' (ID: ' . strtoupper($transaction['TransactionUniqId']) . ')';
         //$file = 'sites/'.$site['FriendlyId'].'/emails/receipt.html';
         $file = '/emails/receipt.html';
         // send email from file
         Utilities::SendEmailFromFile($email, $site['PrimaryEmail'], $site['Name'], $subject, $replace, $file);
     } else {
         // IPN response was "INVALID"\
     }
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'text/HTML';
     $response->body = 'Yah!!!';
     return $response;
 }