Example #1
0
 function testValidReturn()
 {
     if ($this->cash_test_url) {
         $return = json_decode(CASHSystem::getURLContents(CASH_API_URL . 'verbose/element/getmarkup/100/status_uid/whatever', false, true));
         // test valid JSON:
         $this->assertNotNull($return);
         // make sure all the bits and pieces are in place
         $this->assertTrue(isset($return->status_code));
         $this->assertTrue(isset($return->status_uid));
         $this->assertTrue(isset($return->status_message));
         $this->assertTrue(isset($return->contextual_message));
         $this->assertTrue(isset($return->request_type));
         $this->assertTrue(isset($return->action));
         $this->assertTrue(isset($return->payload));
         $this->assertTrue(isset($return->api_version));
         $this->assertTrue(isset($return->timestamp));
         // test types for the standardized bits, ignore the variable pieces
         $this->assertTrue(is_int($return->status_code));
         $this->assertTrue(is_string($return->status_uid));
         $this->assertTrue(is_string($return->status_message));
         $this->assertTrue(is_string($return->contextual_message));
         $this->assertTrue(is_string($return->request_type));
         $this->assertTrue(is_string($return->action));
         $this->assertTrue(is_int($return->api_version));
         $this->assertTrue(is_int($return->timestamp));
     }
 }
Example #2
0
 public function getData()
 {
     if ($this->options['skip_login']) {
         $show_final_message = true;
     } else {
         $show_final_message = false;
         $this->element_data['browserid_js'] = CASHSystem::getBrowserIdJS($this->element_id);
         if ($this->status_uid == 'people_signintolist_200') {
             $show_final_message = true;
         } elseif ($this->status_uid == 'people_signintolist_400') {
             // sign-in failed, try element-specific password and check that the
             // address is for realy realz on the list
             if (trim($this->original_request['password']) == trim($this->options['alternate_password'])) {
                 $status_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'address' => $this->original_request['address'], 'list_id' => $this->options['email_list_id']));
                 if ($status_request->response['payload']) {
                     $show_final_message = true;
                 }
             }
         }
     }
     if ($show_final_message) {
         if ($this->options['asset_id'] != 0) {
             // first we "unlock" the asset, telling the platform it's okay to generate a link for non-private assets
             $unlock_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'unlock', 'id' => $this->options['asset_id']));
             // next we make the link
             $asset_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getasset', 'id' => $this->options['asset_id']));
             $this->element_data['asset_title'] = $asset_request->response['payload']['title'];
             $this->element_data['asset_description'] = $asset_request->response['payload']['description'];
         }
         $this->setTemplate('success');
     }
     return $this->element_data;
 }
Example #3
0
 public function getMarkup()
 {
     // define $markup to store all screen output
     $markup = '';
     // the default form and basic elements:
     $default_markup = '<form id="cash_' . self::type . '_form_' . $this->element_id . '" class="cash_form ' . self::type . '" method="post" action="">';
     if ($this->options->display_title) {
         $default_markup .= '<h2 class="cash_title">' . $this->options->display_title . '</h2>';
     }
     if ($this->options->display_message) {
         $default_markup .= '<p class="cash_message">' . $this->options->display_message . '</p>';
     }
     $default_markup .= '' . '<div class="cash_address_container"><label for="address">Email</label>' . '<input type="email" name="address"  placeholder="Your Email Address" value="" class="cash_input cash_input_address" /></div>' . '<div class="cash_password_container"><label for="password">Password</label>' . '<input type="password" name="password" value="" class="cash_input cash_input_password" /></div>' . '<div class="cash_hidden"><input type="hidden" name="cash_request_type" value="people" />' . '<input type="hidden" name="cash_action" value="signintolist" />' . '<input type="hidden" name="list_id" value="' . $this->options->email_list_id . '" class="cash_input cash_input_list_id" />' . '<input type="hidden" name="element_id" value="' . $this->element_id . '" class="cash_input cash_input_element_id" />' . '<input type="hidden" id="browseridassertion_' . $this->element_id . '" name="browseridassertion" value="" class="cash_input cash_input_element_id" /></div>' . '<input type="submit" value="log in" class="button" /> <span class="cash_divider_text"> - or - </span> <a href="javascript:void(0)" id="browserid_login_link_' . $this->element_id . '"><img src="' . CASH_PUBLIC_URL . 'assets/images/browserid.png" alt="log in with browser id" class="cash_browserid_button" /></a>' . '</form>';
     $default_markup .= CASHSystem::getBrowserIdJS($this->element_id);
     switch ($this->status_uid) {
         case 'people_signintolist_400':
             // error, likely in the email format. error message + default form
             $markup = '<div class="cash_error ' . self::type . '">' . 'We could not verify your login. Please try again.' . '</div>' . $default_markup;
             break;
         case 'empty':
             $markup = '';
             break;
         default:
             // default form
             $markup = $default_markup;
     }
     return $markup;
 }
Example #4
0
 protected function postToPaypal($method_name, $nvp_parameters)
 {
     // Set the API operation, version, and API signature in the request.
     $request_parameters = array('METHOD' => $method_name, 'VERSION' => $this->api_version, 'PWD' => $this->api_password, 'USER' => $this->api_username, 'SIGNATURE' => $this->api_signature);
     $request_parameters = array_merge($request_parameters, $nvp_parameters);
     // Get response from the server.
     $http_response = CASHSystem::getURLContents($this->api_endpoint, $request_parameters, true);
     if ($http_response) {
         // Extract the response details.
         $http_response = explode("&", $http_response);
         $parsed_response = array();
         foreach ($http_response as $i => $value) {
             $tmpAr = explode("=", $value);
             if (sizeof($tmpAr) > 1) {
                 $parsed_response[$tmpAr[0]] = urldecode($tmpAr[1]);
             }
         }
         if (0 == sizeof($parsed_response) || !array_key_exists('ACK', $parsed_response)) {
             $this->setErrorMessage("Invalid HTTP Response for POST (" . $nvpreq . ") to " . $this->api_endpoint);
             return false;
         }
         if ("SUCCESS" == strtoupper($parsed_response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($parsed_response["ACK"])) {
             return $parsed_response;
         } else {
             $this->setErrorMessage(print_r($parsed_response, true));
             return false;
         }
     } else {
         $this->setErrorMessage('could not reach Paypal servers');
         return false;
     }
 }
Example #5
0
	public function prepMarkup($post) {
		if ($post->type == 'regular') {
			$textbody = '';
			$textbodyarray = explode('.',strip_tags($post->{'regular-body'}));
			if (count($textbodyarray) > 3) {
				$textbodyarray = array_slice($textbodyarray,0,3);
			}
			$textbody = implode('.',$textbodyarray) . '...';

			$innermarkup = "<div class=\"cashmusic_social cashmusic_tumblr\">"
			. '<h2><a href="' . $post->{'url-with-slug'} . '" target="_blank">' . $post->{$post->type . '-title'} . '</a></h2><div>' . $textbody . '</div><div class="cashmusic_social_date"><a href="' . $post->{'url-with-slug'} . '" target="_blank">' . CASHSystem::formatAgo($post->{'unix-timestamp'}) . ' / tumblr</a> </div>'
			. '<div style="clear:both;overflow:hidden;visibility:hidden;height:1px;">.</div></div>';
		} else if ($post->type == 'photo') {
			$innermarkup = "<div class=\"cashmusic_social cashmusic_tumblr\">"
			. '<div><img src="' . $post->{'photo-url-500'} . '" width="100%" alt="" /><br />' . $post->{'photo-caption'} . '</div><div class="cashmusic_social_date"><a href="' . $post->{'url-with-slug'} . '" target="_blank">' . CASHSystem::formatAgo($post->{'unix-timestamp'}) . ' / tumblr</a> </div>'
			. '<div style="clear:both;overflow:hidden;visibility:hidden;height:1px;">.</div></div>';
		} else if ($post->type == 'video') {
			$innermarkup = "<div class=\"cashmusic_social cashmusic_tumblr\">"
			. '<div><div class="cashmusic_social_video_container">' . $post->{'video-player'} . '</div><br />' . $post->{'video-caption'} . '</div><div class="cashmusic_social_date"><a href="' . $post->{'url-with-slug'} . '" target="_blank">' . CASHSystem::formatAgo($post->{'unix-timestamp'}) . ' / tumblr</a> </div>'
			. '<div style="clear:both;overflow:hidden;visibility:hidden;height:1px;">.</div></div>';
		}
		/*
		The CSS to go along with the video container:
		
		Thanks to http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
		
		echo '<style type="text/css">';
		echo '.cashmusic_video_container {position:relative;padding-bottom:56.25%;padding-top:30px;height:0;overflow:hidden;}';
		echo '.cashmusic_video_container iframe, .cashmusic_video_container object, .cashmusic_video_container embed {position:absolute;top:0;left:0;width:100%;height:100%;}';
		echo '</style>';
		*/
	}
Example #6
0
	public function prepMarkup($tweet) {
		$tmp_profile_img = $tweet->user->profile_image_url;
		if ($tmp_profile_img == 'http://static.twitter.com/images/default_profile_normal.png') {
			$tmp_profile_img = 'http://a2.twimg.com/sticky/default_profile_images/default_profile_' . rand(0, 6) . '_normal.png';
		}
		$innermarkup = "<div class=\"cashmusic_social cashmusic_twitter\"><img src=\"$tmp_profile_img\" class=\"cashmusic_twitter_avatar\" alt=\"avatar\" />"
		. "<div class=\"cashmusic_twitter_namespc\"><a href=\"http://twitter.com/" . $tweet->user->screen_name . "\">@" . $tweet->user->screen_name . "</a><br />" . $tweet->user->name . "</div><div class=\"cashmusic_clearall\">.</div>"
		. "<div class=\"tweet\">" . $tweet->text . '<div class="cashmusic_social_date"><a href="http://twitter.com/#!/' . $tweet->user->screen_name . '/status/' . $tweet->id_str . '" target="_blank">' . CASHSystem::formatAgo($tweet->created_at) . ' / twitter</a> </div></div>';
		/*
		The CSS to go along with the twitter markup:
		
		From our stuff up on http://marketairglovamusic.com/
		
		.cashmusic_social {margin:10px 0 20px 0;padding:15px;background-color:#fff;border-top-left-radius:5px 5px;border-top-right-radius:5px 5px;border-bottom-right-radius:5px 5px;border-bottom-left-radius:5px 5px;}
		.cashmusic_social a {color:#cdcdcd;}
		.cashmusic_twitter {font:14.5px/1.75em georgia,'times new roman',times,serif;}
		.cashmusic_twitter_avatar {float:left;margin:1px 8px 8px 0;}
		.cashmusic_twitter_namespc {color:#cdcdcd;font:11px/1.5em helvetica,"helvetica neue",arial,sans-serif;}
		.cashmusic_twitter_namespc a {color:#007e3d;font:bold 15px/1.85em helvetica,"helvetica neue",arial,sans-serif;}
		.cashmusic_twitter a {color:#007e3d;}
		.cashmusic_tumblr h2, .cashmusic_tumblr h2 a, #topmenu * a, h2 {color:#111;font:28px/1em 'IM Fell English',georgia,'times new roman',times,serif;}
		.cashmusic_social_date {margin-top:10px;color:#cdcdcd;font:11px/1.75em helvetica,"helvetica neue",arial,sans-serif;}
		.cashmusic_clearall {clear:both;height:1px;overflow:hidden;visibility:hidden;}
		*/
	}
Example #7
0
 function testURLsAndContent()
 {
     if ($this->s3_key) {
         $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id);
         // check for the timestamp in the public link for the public test file
         $test_content = CASHSystem::getURLContents('http://' . $this->s3_bucket . '.s3.amazonaws.com/' . 'test' . $this->timestamp);
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // and in the private link generated for the private test file
         $test_content = CASHSystem::getURLContents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
         $this->assertPattern('/' . $this->timestamp . '/', $test_content);
         // now test headers -- relies on fopen wrappers
         if (ini_get('allow_url_fopen')) {
             // first defaults, both present:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // no-cache only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, false, true));
             $this->assertFalse(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertTrue(array_search('Cache-Control: no-cache', $http_response_header));
             // attachment only:
             file_get_contents($s3->getExpiryURL('test_private' . $this->timestamp, 20, true, false));
             $this->assertTrue(array_search('Content-Disposition: attachment', $http_response_header));
             $this->assertFalse(array_search('Cache-Control: no-cache', $http_response_header));
         }
     }
 }
Example #8
0
 function cashmusic_shortcode($attributes)
 {
     extract(shortcode_atts(array('element' => false, 'name' => false), $attributes));
     if ($element) {
         CASHSystem::embedElement($element);
     } else {
         echo '<!-- CASH Music error: no such element found -->';
     }
 }
Example #9
0
 public function getData()
 {
     // define $markup to store all screen output
     $item_request = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'getitem', 'id' => $this->options['item_id']));
     $item = $item_request->response['payload'];
     $this->element_data['item_name'] = $item['name'];
     $this->element_data['item_price'] = number_format($item['price'], 2, '.', '');
     $this->element_data['item_flexible_price'] = $item['flexible_price'];
     $this->element_data['item_description'] = $item['description'];
     $this->element_data['item_asset'] = $item['fulfillment_asset'];
     if ($item['available_units'] != 0) {
         $this->element_data['is_available'] = true;
     } else {
         $this->element_data['is_available'] = false;
     }
     $currency_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'use_currency', 'user_id' => $this->element_data['user_id']));
     if ($currency_request->response['payload']) {
         $this->element_data['currency'] = CASHSystem::getCurrencySymbol($currency_request->response['payload']);
     } else {
         $this->element_data['currency'] = CASHSystem::getCurrencySymbol('USD');
     }
     if ($this->status_uid == 'commerce_finalizepayment_200' || $this->status_uid == 'element_redeemcode_200' || $this->status_uid == 'commerce_initiatecheckout_200' && $this->original_response['payload'] == 'force_success') {
         if ($item['fulfillment_asset'] != 0) {
             $fulfillment_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getfulfillmentassets', 'asset_details' => $item['fulfillment_asset']));
             if ($fulfillment_request->response['payload']) {
                 $this->element_data['fulfillment_assets'] = new ArrayIterator($fulfillment_request->response['payload']);
             }
         }
         $this->setTemplate('success');
     } elseif ($this->status_uid == 'commerce_initiatecheckout_400') {
         // could happen on a database glitch, but probably means the user set a pay-minimum price below the
         // minimum price. what a heel.
         $this->element_data['error_message'] = 'Make sure you enter a price of at least ' . $this->element_data['currency'] . $item['price'] . ' and try again.';
     } elseif ($this->status_uid == 'commerce_finalizepayment_400' || $this->status_uid == 'element_redeemcode_400') {
         // payerid is specific to paypal, so this is temporary to tell between canceled and errored:
         if (isset($_GET['PayerID'])) {
             //$this->element_data['error_message'] = $this->options['message_error'];
             $this->element_data['error_message'] = print_r($this->original_response, true);
         }
     } elseif (isset($_POST['singlepurchase1'])) {
         $total_price = $item['price'];
         if (isset($_POST['total_price'])) {
             $total_price = $_POST['total_price'];
         }
         $this->element_data['total_price'] = $total_price;
         if ($this->element_data['region1_cost'] + $this->element_data['region2_cost'] == 0.0) {
             $this->element_data['no_shipping'] = true;
         }
         if ($total_price >= $item['price']) {
             $this->setTemplate('shipping');
         } else {
             $this->element_data['error_message'] = 'Make sure you enter a price of at least ' . $this->element_data['currency'] . $item['price'] . ' and try again.';
         }
     }
     return $this->element_data;
 }
Example #10
0
 public function getData()
 {
     if ($this->unlocked || $this->hide) {
         $this->setTemplate('empty');
     } else {
         if ($this->status_uid == 'people_signintolist_400') {
             $this->element_data['error_message'] = 'Could not verify your login. Please try again.';
         }
         $this->element_data['browserid_js'] = CASHSystem::getBrowserIdJS($this->element_id);
     }
     return $this->element_data;
 }
Example #11
0
 public function getData()
 {
     switch ($this->status_uid) {
         case 'people_signup_200' || 'people_verifyaddress_200':
             // successful submit, return messaging and optionally an asset link
             $show_final_message = true;
             if ($this->status_uid == 'people_signup_200' && !$this->options['do_not_verify']) {
                 // if this is a first submit and we're verifying the email, first check to see if it's been verified already
                 $verification_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'checkverification', 'address' => $this->original_response['payload']['address'], 'list_id' => $this->options['email_list_id']));
                 if (!$verification_request->response['payload']) {
                     // not verified, so do not show the final message, and instead give a "you must verify" jam
                     $show_final_message = false;
                     $this->setTemplate('mustverify');
                 }
             }
             if ($show_final_message) {
                 $all_friends = array($this->original_request['friend1'], $this->original_request['friend2'], $this->original_request['friend3']);
                 if (!empty($this->original_request['main_name'])) {
                     $from_name = $this->original_request['main_name'];
                 } else {
                     $from_name = $this->original_request['address'];
                 }
                 if (!empty($this->options['email_html_message'])) {
                     $html_message = str_replace('</body>', '<br /><br /><br /><small>This e-card was sent from <a href="' . CASHSystem::getCurrentURL() . '">' . CASHSystem::getCurrentURL() . '</a></small></body>', $this->options['email_html_message']);
                 } else {
                     $html_message = false;
                 }
                 foreach ($all_friends as $friend) {
                     if (filter_var($friend, FILTER_VALIDATE_EMAIL)) {
                         CASHSystem::sendEmail(trim($this->options['email_subject']) . ' ' . $from_name, CASHSystem::getDefaultEmail(), $friend, $this->options['email_message'] . "\n\n\nThis e-card was sent from " . CASHSystem::getCurrentURL(), '', $html_message);
                     }
                 }
                 if ($this->options['asset_id'] != 0) {
                     // first we "unlock" the asset, telling the platform it's okay to generate a link for non-private assets
                     $unlock_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'unlock', 'id' => $this->options['asset_id']));
                     // next we make the link
                     $asset_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'getasset', 'id' => $this->options['asset_id']));
                     $this->element_data['asset_title'] = $asset_request->response['payload']['title'];
                     $this->element_data['asset_description'] = $asset_request->response['payload']['description'];
                 }
                 $this->setTemplate('success');
             }
             break;
         case 'people_signup_400':
             // error, likely in the email format. error message + default form
             $this->element_data['error_message'] = $this->options['message_invalid_email'];
             break;
     }
     return $this->element_data;
 }
Example #12
0
 /**
  * Returns the (best guess at) APE URL
  * fix that typo. I refuse. It's too funny.
  *
  * @return array
  */
 public static function getAPIDetails()
 {
     if (!defined('STDIN')) {
         // check for command line
         $api_url = 'http' . (empty($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] != 443 ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . str_replace('/admin', '/api', ADMIN_WWW_BASE_PATH);
         $api_response = json_decode(CASHSystem::getURLContents($api_url));
         if ($api_response->greeting == 'hi.') {
             return array('api_url' => $api_url, 'api_version' => $api_response->api_version);
         } else {
             return false;
         }
         return $api_url;
     } else {
         return false;
     }
 }
Example #13
0
 public function __construct($effective_user_id = false, $primary_request = false)
 {
     $this->platform_type = CASHSystem::getSystemSettings('instancetype');
     if (!$this->platform_type) {
         $this->platform_type = 'single';
     }
     $this->stored_responses = array();
     $this->stored_data = array();
     $this->page_data = array();
     if ($effective_user_id) {
         $this->effective_user_id = $effective_user_id;
     }
     if ($primary_request) {
         $this->primary_request = $primary_request;
     }
 }
Example #14
0
 public function getTumblrFeed($tumblr_domain, $start_at = 0, $tagged = false, $post_types = false)
 {
     if ($tumblr_domain) {
         $default_post_types = array('regular' => true, 'link' => true, 'quote' => false, 'photo' => true, 'conversation' => false, 'video' => true, 'audio' => true, 'answer' => false);
         if (is_array($post_types)) {
             $final_post_types = array_merge($default_post_types, $post_types);
         } else {
             $final_post_types = $default_post_types;
         }
         $tumblr_domain = str_replace(array('http://', '/'), '', $tumblr_domain);
         $tumblr_url = 'http://' . $tumblr_domain . '/api/read/json?start=' . $start_at . '&num=30';
         if ($tagged) {
             $tumblr_url .= '&tagged=' . urlencode($tagged);
         }
         $feed_data = $this->getCachedURL('com.tumblr', 'domain_' . str_replace('.', '', $tumblr_domain) . $start_at, $tumblr_url, 'raw', false);
         if ($feed_data) {
             // tumblr's funny, JSONP only, so we cache its return and strip of some extra
             $feed_data = str_replace('var tumblr_api_read = ', '', $feed_data);
             // strip off the variable declaration
             $feed_data = substr($feed_data, 0, strlen($feed_data) - 2);
             // and the trailing semicolon+newline
             // decode the trimmed content, then return just the posts
             $feed_data = json_decode($feed_data);
             $feed_data = $feed_data->posts;
             // make a dummy array to save final posts
             $final_feed_data = array();
             // loop through all the posts, filter by type
             foreach ($feed_data as $post) {
                 if ($final_post_types[$post->type]) {
                     $post->formatted_date = CASHSystem::formatTimeAgo($post->{'unix-timestamp'});
                     $final_feed_data[] = $post;
                 }
             }
             $feed_data = $final_feed_data;
         }
         return $feed_data;
     } else {
         return false;
     }
 }
Example #15
0
 public static function handleRedirectReturn($data = false)
 {
     if (isset($data['error'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         $connections = CASHSystem::getSystemSettings('system_connections');
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Client.php';
         require_once CASH_PLATFORM_ROOT . '/lib/oauth2/OAuth2Exception.php';
         require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MC_OAuth2Client.php';
         $oauth_options = array('redirect_uri' => $connections['com.mailchimp']['redirect_uri'], 'client_id' => $connections['com.mailchimp']['client_id'], 'client_secret' => $connections['com.mailchimp']['client_secret'], 'code' => $data['code']);
         $client = new MC_OAuth2Client($oauth_options);
         $session = $client->getSession();
         if ($session) {
             require_once CASH_PLATFORM_ROOT . '/lib/mailchimp/MailChimp.class.php';
             $cn = new MC_OAuth2Client($oauth_options);
             $cn->setSession($session, false);
             $odata = $cn->api('metadata', 'GET');
             $access_token = $session['access_token'];
             $api_key = $session['access_token'] . '-' . $odata['dc'];
             $api = new MailChimp($api_key);
             $lists = $api->call('lists/list');
             $return_markup = '<h4>Connect to MailChimp</h4>' . '<p>Now just choose a list and save the connection.</p>' . '<form accept-charset="UTF-8" method="post" action="">' . '<input type="hidden" name="dosettingsadd" value="makeitso" />' . '<input id="connection_name_input" type="hidden" name="settings_name" value="(MailChimp list)" />' . '<input type="hidden" name="settings_type" value="com.mailchimp" />' . '<input type="hidden" name="key" value="' . $api_key . '" />' . '<label for="list">Choose a list to connect to:</label>' . '<select id="list_select" name="list">';
             $selected = ' selected="selected"';
             $list_name = false;
             foreach ($lists['data'] as $list) {
                 if ($selected) {
                     $list_name = $list['name'];
                 }
                 $return_markup .= '<option value="' . $list['id'] . '"' . $selected . '>' . $list['name'] . '</option>';
                 $selected = false;
             }
             $return_markup .= '</select><br /><br />' . '<div><input class="button" type="submit" value="Add The Connection" /></div>' . '</form>' . '<script type="text/javascript">' . '$("#connection_name_input").val("' . $list_name . ' (MailChimp)");' . '$("#list_select").change(function() {' . '	var newvalue = this.options[this.selectedIndex].text + " (MailChimp)";' . '	$("#connection_name_input").val(newvalue);' . '});' . '</script>';
             return $return_markup;
         } else {
             return 'There was an error. (session) Please try again.';
         }
     }
 }
Example #16
0
 function testWhatever()
 {
     $request = new CASHRequest();
     // test script-scope sesstion values:
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz', 'script');
     $value = $request->sessionGet('foobar', 'script');
     $this->assertEqual($value, 'baz');
     $request->sessionClear('foobar', 'script');
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz', 'script');
     $request->sessionClearAll();
     $value = $request->sessionGet('foobar', 'script');
     $this->assertFalse($value);
     // test persistent-scope sesstion values:
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz');
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     // fail without startSession()
     $session = CASHSystem::startSession();
     $this->assertTrue($session);
     echo 'Session started: ' . json_encode($session) . "\n";
     $request->sessionSet('foobar', 'baz');
     $value = $request->sessionGet('foobar');
     $this->assertEqual($value, 'baz');
     $request->sessionClear('foobar');
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
     $request->sessionSet('foobar', 'baz');
     $request->sessionClearAll();
     $value = $request->sessionGet('foobar');
     $this->assertFalse($value);
 }
Example #17
0
 ***************************************************************************************************/
if (strrpos($_SERVER['REQUEST_URI'], 'controller.php') !== false) {
    header('Location: ./');
    exit;
}
/***************************************************************************************************
 *
 * INCLUDES AND STARTUP
 *
 ***************************************************************************************************/
require_once __DIR__ . '/constants.php';
// instead of the previous require_once(CASH_PLATFORM_PATH) call, we manually
// load CASHSystem and set admin_primary_cash_request to the first CASHRequest set
include_once dirname(CASH_PLATFORM_PATH) . '/classes/core/CASHSystem.php';
include_once dirname(CASH_PLATFORM_PATH) . '/lib/mustache/Mustache.php';
$admin_primary_cash_request = CASHSystem::startUp(true);
// admin-specific autoloader
function cash_admin_autoloadCore($classname)
{
    $file = ADMIN_BASE_PATH . '/classes/' . $classname . '.php';
    if (file_exists($file)) {
        require_once $file;
    }
}
spl_autoload_register('cash_admin_autoloadCore');
// make an object to use throughout the pages
$cash_admin = new AdminCore($admin_primary_cash_request->sessionGet('cash_effective_user'), $admin_primary_cash_request);
$cash_admin->mustache_groomer = new Mustache();
$cash_admin->page_data['www_path'] = ADMIN_WWW_BASE_PATH;
$cash_admin->page_data['public_url'] = CASH_PUBLIC_URL;
$cash_admin->page_data['platform_version'] = CASHRequest::$version;
Example #18
0
 function testProcessWebhooks()
 {
     $time = time();
     // only run if key / list have been set properly
     if ($this->api_key && $this->api_list_id) {
         $data_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'getapicredentials', 'user_id' => $this->cash_user_id));
         $api_credentials = $data_request->response['payload'];
         // valid API url, but likely localhost
         $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $this->test_list_id . '/api_key/' . $api_credentials['api_key'];
         // make sure we're rejecting bad keys
         $bad_webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mailchimp/list_id/' . $this->test_list_id . '/api_key/incorrect';
         $response = json_decode(CASHSystem::getURLContents($bad_webhook_api_url, array('sample' => 'data'), true));
         // TODO: this is currently returning 400, we need to get that to 403, but we'll test for not-200
         //       which at least proves we're not accepting bad keys
         $this->assertNotEqual($response->status_code, 200);
         $test_address = 'dev+shouldnotsubscribe' . $time . '@cashmusic.org';
         $add_post_data = array("type" => "subscribe", "fired_at" => "2009-03-26 21:35:57", "data" => array("id" => "8a25ff1d98", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $add_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // make sure that the address has been added to the local list
         $this->assertTrue($list_request->response['payload']);
         $remove_post_data = array("type" => "unsubscribe", "fired_at" => "2009-03-26 21:36:52", "data" => array("id" => "8a25ff1d98", "action" => "unsub", "reason" => "manual", "list_id" => "a6b5da1054", "email" => $test_address, "email_type" => "html", "merges" => null, "ip_opt" => "10.20.10.30", "ip_signup" => "10.20.10.30"));
         CASHSystem::getURLContents($webhook_api_url, $remove_post_data, true);
         $list_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'getaddresslistinfo', 'list_id' => $this->test_list_id, 'address' => $test_address));
         // now make sure that the address has been removed
         $this->assertEqual($list_request->response['payload']['active'], 0);
     }
 }
Example #19
0
// parsing posted data:
if (isset($_POST['docampaignedit'])) {
    // do the actual list add stuffs...
    $edit_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'editcampaign', 'id' => $request_parameters[0], 'title' => $_POST['campaign_title'], 'description' => $_POST['campaign_description']));
    if ($edit_response['status_uid'] == 'element_editcampaign_200') {
        AdminHelper::formSuccess('Success. Edited.', '/');
    } else {
        AdminHelper::formFailure('Error. There was a problem editing your campaign.', '/');
    }
}
$current_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getcampaign', 'id' => $request_parameters[0]));
$cash_admin->page_data['ui_title'] = 'Campaigns: Edit "' . $current_response['payload']['title'] . '"';
$current_campaign = $current_response['payload'];
if (is_array($current_campaign)) {
    $cash_admin->page_data = array_merge($cash_admin->page_data, $current_campaign);
}
$cash_admin->page_data['form_state_action'] = 'docampaignedit';
$cash_admin->page_data['button_text'] = 'Save changes';
$elements_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getelementsforcampaign', 'id' => $request_parameters[0]));
if (is_array($elements_response['payload'])) {
    foreach ($elements_response['payload'] as &$element) {
        if ($element['modification_date'] == 0) {
            $element['formatted_date'] = CASHSystem::formatTimeAgo($element['creation_date']);
        } else {
            $element['formatted_date'] = CASHSystem::formatTimeAgo($element['modification_date']);
        }
    }
    $cash_admin->page_data['elements_for_campaign'] = new ArrayIterator($elements_response['payload']);
}
$cash_admin->setPageContentTemplate('campaign_edit');
Example #20
0
         $embed_location = $requests[3];
         $embed_location = str_replace('!slash!', '/', $embed_location);
         // dumb. supporting old versions.
     }
     if (isset($_GET['location'])) {
         $embed_location = $_GET['location'];
     }
     if (isset($_GET['geo'])) {
         $embed_geo = $_GET['geo'];
     }
     $template_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelementtemplate', 'element_id' => $requests[1], 'return_template' => 1));
     $template = $template_request->response['payload'];
     $embed_data = array();
     $element_markup = false;
     ob_start();
     CASHSystem::embedElement($requests[1], 'embed', $embed_location, $embed_geo);
     $embed_data['element_markup'] = ob_get_contents();
     $embed_data['cdn_url'] = defined('CDN_URL') ? CDN_URL : CASH_ADMIN_URL;
     ob_end_clean();
     header('Content-Type: text/html; charset=utf-8');
     $template = str_replace('</head>', '<script type="text/javascript" src="' . CASH_PUBLIC_URL . '/cashmusic.js"></script></head>', $template);
     $encoded_html = $freddiemercury->render($template, $embed_data);
     echo $encoded_html;
 } else {
     if ($initial_page_request) {
         if (in_array('payload', $requests)) {
             $output = $initial_page_request['response']['payload'];
         } else {
             $output = array('response' => $initial_page_request['response']);
         }
     } else {
Example #21
0
 protected function startJSSession()
 {
     $r = new CASHRequest();
     $session_details = $r->startSession();
     if ($session_details['newsession']) {
         $endpoint = explode('/', CASHSystem::getCurrentURL(), 4);
         unset($endpoint[3]);
         $endpoint = join('/', $endpoint);
         if (!$session_details['expiration']) {
             $session_details['expiration'] = time() + 10800;
         }
         return json_encode(array('endpoint' => $endpoint, 'expiration' => $session_details['expiration'], 'id' => $session_details['id']));
     } else {
         return '';
     }
 }
Example #22
0
                }
            }
            $orders_currency = $order['currency'];
        }
        $total_spend = round($total_spend);
    }
    $cash_admin->page_data['dashboard_lists'] = $session_news['activity']['lists'];
    if ($session_news['activity']['orders']) {
        $cash_admin->page_data['total_orders'] = count($session_news['activity']['orders']);
        if ($cash_admin->page_data['total_orders'] == 1) {
            $cash_admin->page_data['orders_singular'] = true;
        }
    } else {
        $cash_admin->page_data['total_orders'] = false;
    }
    $cash_admin->page_data['total_spend'] = CASHSystem::getCurrencySymbol($orders_currency) . $total_spend;
}
// handle all of the sales options, first the change
if (isset($_POST['currency_id'])) {
    $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'use_currency', 'value' => $_POST['currency_id'], 'user_id' => $cash_admin->effective_user_id));
    $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'payment_defaults', 'value' => array('pp_default' => $_POST['paypal_default_id'], 'pp_micro' => $_POST['paypal_micropayment_id']), 'user_id' => $cash_admin->effective_user_id));
    if ($settings_response['payload']) {
        AdminHelper::formSuccess('Success.', '/commerce/');
    }
}
// now get the current currency setting
$settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'use_currency', 'user_id' => $cash_admin->effective_user_id));
if ($settings_response['payload']) {
    $current_currency = $settings_response['payload'];
} else {
    $current_currency = 'USD';
Example #23
0
 protected function sendOrderReceipt($id = false, $order_details = false, $finalize_url = false)
 {
     if (!$id && !$order_details) {
         return false;
     }
     if (!$order_details) {
         $order_details = $this->getOrder($id, true);
     }
     $order_totals = $this->getOrderTotals($order_details['order_contents']);
     try {
         $personalized_message = '';
         if ($order_details['element_id']) {
             $element_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'getelement', 'id' => $order_details['element_id']));
             if ($element_request->response['payload']) {
                 if (isset($element_request->response['payload']['options']['message_email'])) {
                     if ($element_request->response['payload']['options']['message_email']) {
                         $personalized_message = $element_request->response['payload']['options']['message_email'] . "\n\n";
                     }
                 }
             }
         }
         if ($order_details['digital']) {
             $addcode_request = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addlockcode', 'element_id' => $order_details['element_id']));
             if (!$finalize_url) {
                 $finalize_url = CASHSystem::getCurrentURL();
             }
             return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "**  \n" . $order_totals['description'] . "  \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n" . "\n\n" . '[View your receipt and any downloads](' . $finalize_url . '?cash_request_type=element&cash_action=redeemcode&code=' . $addcode_request->response['payload'] . '&element_id=' . $order_details['element_id'] . '&email=' . urlencode($order_details['customer_details']['email_address']) . '&order_id=' . $order_details['id'] . ')', 'Thank you.');
         } else {
             return CASHSystem::sendEmail('Thank you for your order', $order_details['user_id'], $order_details['customer_details']['email_address'], $personalized_message . "Your order is complete. Here are some details:\n\n**Order #" . $order_details['id'] . "**  \n" . $order_totals['description'] . "  \n Total: " . CASHSystem::getCurrencySymbol($order_details['currency']) . number_format($order_details['gross_price'], 2) . "\n\n", 'Thank you.');
         }
     } catch (Exception $e) {
         // TODO: handle the case where an email can't be sent. maybe display the download
         //       code on-screen? that plus storing it with the order is probably enough
         return false;
     }
 }
Example #24
0
 /**
  * Records the basic access data to the elements analytics table
  *
  * @return boolean
  */
 protected function recordAnalytics($id, $access_method, $access_action = 'getmarkup', $access_data = '')
 {
     $ip_and_proxy = CASHSystem::getRemoteIP();
     $already_recorded = false;
     // first check and see if we've recorded this session and circumstance yet
     // only do this for empty lock_method_table queries so we don't repeat
     // unnecessary rows and overwhelm the table
     if ($access_action == 'getmarkup') {
         $already_recorded = $this->db->getData('elements_analytics', 'id', array("element_id" => array("condition" => "=", "value" => $id), "access_method" => array("condition" => "=", "value" => $access_method), "access_location" => array("condition" => "=", "value" => CASHSystem::getCurrentURL()), "cash_session_id" => array("condition" => "=", "value" => $this->getCASHSessionID()), "client_ip" => array("condition" => "=", "value" => $ip_and_proxy['ip']), "client_proxy" => array("condition" => "=", "value" => $ip_and_proxy['proxy'])));
     }
     if (!$already_recorded) {
         $result = $this->db->setData('elements_analytics', array('element_id' => $id, 'access_method' => $access_method, 'access_location' => CASHSystem::getCurrentURL(), 'access_action' => $access_action, 'access_data' => $access_data, 'access_time' => time(), 'client_ip' => $ip_and_proxy['ip'], 'client_proxy' => $ip_and_proxy['proxy'], 'cash_session_id' => $this->getCASHSessionID()));
         return $result;
     } else {
         return true;
     }
 }
Example #25
0
	/**
	 * Records the basic access data to the assets analytics table
	 *
	 * @return boolean
	 */protected function recordAnalytics($asset_id,$element_id=0) {
		$ip_and_proxy = CASHSystem::getCurrentIP();
		$result = $this->db->setData(
			'assets_analytics',
			array(
				'asset_id' => $asset_id,
				'element_id' => $element_id,
				'access_time' => time(),
				'client_ip' => $ip_and_proxy['ip'],
				'client_proxy' => $ip_and_proxy['proxy'],
				'cash_session_id' => $this->getCASHSessionID()
			)
		);
		return $result;
	}
Example #26
0
$misc_message = false;
if (isset($_POST['domisc'])) {
    CASHSystem::setSystemSetting('timezone', $_POST['timezone']);
    CASHSystem::setSystemSetting('systememail', $_POST['systememail']);
    $cash_admin->page_data['page_message'] = 'Success. All changed.';
}
$migrate_message = false;
if (isset($_POST['domigrate'])) {
    $new_settings = array('hostname' => $_POST['hostname'], 'username' => $_POST['adminuser'], 'password' => $_POST['adminpassword'], 'database' => $_POST['databasename']);
    $migrate_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'migratedb', 'todriver' => $_POST['driver'], 'tosettings' => $new_settings));
    if ($migrate_request->response['payload']) {
        $cash_admin->page_data['page_message'] = 'Success. So that happened.';
    } else {
        $cash_admin->page_data['error_message'] = 'Error. There was a problem migrating your data.';
    }
}
$platform_settings = CASHSystem::getSystemSettings();
$cash_admin->page_data['system_email'] = $platform_settings['systememail'];
$cash_admin->page_data['timezone_options'] = AdminHelper::drawTimeZones($platform_settings['timezone']);
$db_types = array('mysql' => 'MySQL', 'sqlite' => 'SQLite');
$db_type = 'unknown';
if (array_key_exists($platform_settings['driver'], $db_types)) {
    $cash_admin->page_data['db_type'] = $db_types[$platform_settings['driver']];
}
if ($cash_admin->page_data['db_type'] == 'MySQL') {
    $cash_admin->page_data['migrate_from_mysql'] = true;
} elseif ($cash_admin->page_data['db_type'] == 'SQLite') {
    $cash_admin->page_data['migrate_from_sqlite'] = true;
}
$cash_admin->page_data['platform_path'] = realpath(CASH_PLATFORM_PATH);
$cash_admin->setPageContentTemplate('settings');
Example #27
0
<body>

<div id="mainspc">
	<img src="assets/images/funzone.png" width="160" height="77" id="titleimg" />
	<span id="navtitle">&nbsp;MGMT<b>FUNZONE</b></span>
	<div id="navmenu">
		<a href="#">NEWS</a><a href="#">EVENTS</a><a href="#" class="selected">TICKETS</a><a href="#">MERCH</a><a href="#">PHOTOS</a><a href="#">MUSIC+VIDEO</a><a href="#">SHOW ARCHIVE</a>
	</div>
	<?php 
CASHSystem::embedElement(106);
// CASH element (Dandy's e-card test / ecard)
?>
		It's working. Here's a sample element:<br />
		<?php 
CASHSystem::embedElement(107);
// CASH element (Front page news box)
?>
 
	<?php 
CASHSystem::embedElement(106);
// CASH element (Dandy's e-card test / ecard)
?>
</div>

<?php 
include '../../../../framework/php/settings/debug/cashmusic_debug.php';
// Debug
?>
</body>
</html>
Example #28
0
 /**
  * Takes a cache name, data name, and URL — first looks for viable cache data, 
  * then 
  *
  * @return int (remaining time in seconds) or false
  */
 protected function getCachedURL($cache_name, $data_name, $data_url, $format = 'json', $decode = true)
 {
     $url_contents = $this->getCacheData($cache_name, $data_name, false, $decode);
     if (!$url_contents) {
         $url_contents = CASHSystem::getURLContents($data_url);
         if (!$url_contents) {
             $url_contents = $this->getCacheData($cache_name, $data_name, true, $decode);
         } else {
             if ($format == 'json') {
                 $url_contents = json_decode($url_contents);
             }
             $this->setCacheData($cache_name, $data_name, $url_contents);
         }
     }
     return $url_contents;
 }
Example #29
0
     if (isset($cash_admin->page_data['metadata']['private'])) {
         if (count($cash_admin->page_data['metadata']['private'])) {
             $private_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'getfulfillmentassets', 'asset_details' => $asset_response['payload'], 'type' => 'private'));
             if ($private_response['payload']) {
                 $cash_admin->page_data['private_files'] = new ArrayIterator($private_response['payload']);
             }
         }
     }
     $cash_admin->page_data['cover_url'] = ADMIN_WWW_BASE_PATH . '/assets/images/release.jpg';
     if (isset($cash_admin->page_data['metadata']['cover'])) {
         if ($cash_admin->page_data['metadata']['cover']) {
             // effectively non-zero
             $cover_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'getasset', 'id' => $cash_admin->page_data['metadata']['cover']));
             if ($cover_response['payload']) {
                 $cover_asset = $cover_response['payload'];
                 if (strpos(CASHSystem::getMimeTypeFor($cover_asset['location']), 'image') !== false) {
                     $cover_url_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'getasseturl', 'connection_id' => $cover_asset['connection_id'], 'user_id' => AdminHelper::getPersistentData('cash_effective_user'), 'asset_location' => $cover_asset['location'], 'inline' => true));
                     if ($cover_url_response['payload']) {
                         $cash_admin->page_data['cover_url'] = $cover_url_response['payload'];
                         $cash_admin->page_data['cover_asset_id'] = $cash_admin->page_data['metadata']['cover'];
                     }
                 }
             }
         }
     }
     // set the view
     $cash_admin->setPageContentTemplate('assets_details_release');
 } else {
     // default back to the most basic view:
     $cash_admin->page_data['form_state_action'] = 'doassetedit';
     $cash_admin->page_data['asset_button_text'] = 'Edit the asset';
Example #30
-1
 public static function handleRedirectReturn($data = false)
 {
     if (!isset($data['key'])) {
         return 'There was an error. (general) Please try again.';
     } else {
         require_once CASH_PLATFORM_ROOT . '/lib/mandrill/Mandrill.php';
         $m = new Mandrill($data['key']);
         $user_info = $m->getUserInfo();
         $username = $user_info['username'];
         // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth
         // calls would only happen in the admin. If this changes we can f**k around with it later.
         $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user'));
         $result = $new_connection->setSettings($username . ' (Mandrill)', 'com.mandrillapp', array('key' => $data['key']));
         if (!$result) {
             return 'There was an error. (adding the connection) Please try again.';
         }
         // set up webhooks
         $api_credentials = CASHSystem::getAPICredentials();
         $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mandrillapp/api_key/' . $api_credentials['api_key'];
         //$m->webhooksDelete($webhook_api_url); // remove duplicate webhooks
         //$m->webhooksAdd($webhook_api_url,array('send','hard_bounce','soft_bounce','open','click','spam','unsub','reject')); // add it, all events
         $m->call('webhooks/add', array("url" => $webhook_api_url, "events" => array('hard_bounce', 'soft_bounce', 'open', 'click', 'spam', 'unsub', 'reject')));
         if (isset($data['return_result_directly'])) {
             return $result;
         } else {
             if ($result) {
                 AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/');
             } else {
                 AdminHelper::formFailure('Error. Something just didn\'t work right.');
             }
         }
     }
 }