public static function handleRedirectReturn($data = false) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.amazon'])) { $s3_default_email = $connections['com.amazon']['email']; } else { $s3_default_email = false; } $success = S3Seed::connectAndAuthorize($data['key'], $data['secret'], $data['bucket'], $s3_default_email); if ($success) { // 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')); $connection_name = $data['bucket'] . ' (Amazon S3)'; if (substr($connection_name, 0, 10) == 'cashmusic.') { $connection_name = 'Amazon S3 (created ' . date("M j, Y") . ')'; } $result = $new_connection->setSettings($connection_name, 'com.amazon', array('bucket' => $data['bucket'])); 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.'); } } else { //$return_markup = '<h4>Error</h4>' // . '<p>We couldn\'t connect with your S3 account. Please check the key and secret.</p>'; AdminHelper::formFailure('We couldn\'t connect your S3 account. Please check the key and secret.'); } return $return_markup; }
/** * Performs basic tasks each time a user logs in * */ public function runAtLogin() { // sync all assets $c = new CASHConnection($this->effective_user_id); $applicable_connections = $c->getConnectionsByScope('assets'); if (is_array($applicable_connections)) { foreach ($applicable_connections as $connection) { $sync_request = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'syncconnectionassets', 'connection_id' => $connection['id'])); } } }
function __construct() { // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; // add a new connection $this->api_key = getTestEnv("MAILCHIMP_API_KEY"); $c = new CASHConnection($this->cash_user_id); // the '1' sets a user id=1 $this->mailchimp_connection_id = $c->setSettings('MailChimp', 'com.mailchimp', array("key" => $this->api_key, "list" => $this->test_id)); // add a new list $list_add_request = new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'addlist', 'name' => 'Test List', 'description' => 'Test Description', 'user_id' => $this->cash_user_id, 'connection_id' => $this->mailchimp_connection_id)); // should work fine with no description or connection_id $this->test_list_id = $list_add_request->response['payload']; }
function __construct() { echo "Testing Paypal Seed\n"; // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; // add a new connection $this->paypal_username = getTestEnv("PAYPAL_USERNAME"); if (!$this->paypal_username) { echo "Paypal credentials not found, skipping tests\n"; } $c = new CASHConnection($this->cash_user_id); // the '1' sets a user id=1 $this->paypal_connection_id = $c->setSettings('Paypal', 'com.paypal', array("username" => $this->paypal_username, "password" => getTestEnv("PAYPAL_PASSWORD"), "signature" => getTestEnv("PAYPAL_SIGNATURE"), "sandboxed" => true)); }
function __construct() { echo "Testing S3 Seed\n"; // add a new admin user for this $user_add_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'thiswillneverbeused', 'is_admin' => 1)); $this->cash_user_id = $user_add_request->response['payload']; $this->timestamp = time(); $this->s3_key = getTestEnv("S3_KEY"); $this->s3_bucket = getTestEnv("S3_BUCKET"); if (!$this->s3_key) { echo "S3 credentials not found, skipping tests\n"; } // add a new connection $c = new CASHConnection($this->cash_user_id); $this->s3_connection_id = $c->setSettings('S3', 'com.amazon', array("key" => $this->s3_key, "secret" => getTestEnv("S3_SECRET"), "bucket" => $this->s3_bucket)); }
<?php $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $applicable_connections = $page_data_object->getConnectionsByScope('assets'); $connection_id = 0; $browse_path = false; $browse_depth = 0; // check $request_parameters for connection and path if (is_array($request_parameters)) { if (array_shift($request_parameters) == 'connection') { $connection_id = array_shift($request_parameters); $browse_path = implode('/', $request_parameters); // no path found, set it to '.' for root if ($browse_path == '') { $browse_path = '.'; } else { // path found. compute depth from root by counting slashes $browse_depth = count(explode('/', $browse_path)); } } } // look for local-only assets $local_assets_reponse = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'getassetsforconnection', 'connection_id' => 0), 'localassets'); $local_assets = false; if (is_array($local_assets_reponse['payload'])) { $filecount = count($local_assets_reponse['payload']); if ($filecount) { $local_assets = true; } } $list_connections = false;
/** * Returns the name given to a specific Connection * */ public static function getConnectionName($connection_id) { $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $connection_name = false; $connection_details = $page_data_object->getConnectionDetails($connection_id); if ($connection_details) { $connection_name = $connection_details['name']; } return $connection_name; }
foreach ($people_array as $person) { new CASHRequest(array('cash_request_type' => 'people', 'cash_action' => 'addaddresstolist', 'address' => $person[0], 'list_id' => $list_id, 'first_name' => $person[1], 'last_name' => $person[2], 'initial_comment' => $person[3], 'do_not_verify' => true)); } $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample release', 'description' => 'This is a sample release. I\'m sorry I thought that was sort of obvious.', 'parent_id' => 0, 'user_id' => 1, 'type' => 'release')); // $cr->response['payload'] will be the release id $release_id = $cr->response['payload']; $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample release cover', 'description' => 'This is the cover for the sample release. See?', 'parent_id' => $release_id, 'location' => 'http://*****:*****@testmedia.com', 'onesheet' => 'Test bio'); // add the cover to the release new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'editasset', 'id' => $release_id, 'metadata' => $release_metadata)); $cr = new CASHRequest(array('cash_request_type' => 'asset', 'cash_action' => 'addasset', 'title' => 'Sample file (dog badges)', 'description' => 'Dogs are awesome.', 'parent_id' => 0, 'location' => 'http://*****:*****@buyer.com","PAYERID":"KW2MPO2RWV4SW","PAYERSTATUS":"verified","FIRSTNAME":"Fake","LASTNAME":"McTest","COUNTRYCODE":"US","CURRENCYCODE":"USD","AMT":"5.99","ITEMAMT":"5.99","SHIPPINGAMT":"0.00","HANDLINGAMT":"0.00","TAXAMT":"0.00","DESC":"Sample item","INSURANCEAMT":"0.00","SHIPDISCAMT":"0.00","L_NAME0":"Sample item","L_NUMBER0":"order-6","L_QTY0":"1","L_TAXAMT0":"0.00","L_AMT0":"5.99","L_ITEMWEIGHTVALUE0":" 0.00000","L_ITEMLENGTHVALUE0":" 0.00000","L_ITEMWIDTHVALUE0":" 0.00000","L_ITEMHEIGHTVALUE0":" 0.00000","PAYMENTREQUEST_0_CURRENCYCODE":"USD","PAYMENTREQUEST_0_AMT":"5.99","PAYMENTREQUEST_0_ITEMAMT":"5.99","PAYMENTREQUEST_0_SHIPPINGAMT":"0.00","PAYMENTREQUEST_0_HANDLINGAMT":"0.00","PAYMENTREQUEST_0_TAXAMT":"0.00","PAYMENTREQUEST_0_DESC":"Sample item","PAYMENTREQUEST_0_INSURANCEAMT":"0.00","PAYMENTREQUEST_0_SHIPDISCAMT":"0.00","PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED":"false","L_PAYMENTREQUEST_0_NAME0":"Sample item","L_PAYMENTREQUEST_0_NUMBER0":"order-6","L_PAYMENTREQUEST_0_QTY0":"1","L_PAYMENTREQUEST_0_TAXAMT0":"0.00","L_PAYMENTREQUEST_0_AMT0":"23.00","L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0":" 0.00000","L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0":" 0.00000"}', 'data_returned' => '{"TOKEN":"EC-3CC324611K842411K","SUCCESSPAGEREDIRECTREQUESTED":"false","TIMESTAMP":"2014-10-02T19:16:26Z","CORRELATIONID":"11a6663cxo30d","ACK":"Success","VERSION":"63.0","BUILD":"3719653","INSURANCEOPTIONSELECTED":"false","SHIPPINGOPTIONISDEFAULT":"false","PAYMENTINFO_0_TRANSACTIONID":"4WN12370L1021013D","PAYMENTINFO_0_TRANSACTIONTYPE":"expresscheckout","PAYMENTINFO_0_PAYMENTTYPE":"instant","PAYMENTINFO_0_ORDERTIME":"2014-10-02T19:16:23Z","PAYMENTINFO_0_AMT":"5.99","PAYMENTINFO_0_FEEAMT":"0.35","PAYMENTINFO_0_TAXAMT":"0.00","PAYMENTINFO_0_CURRENCYCODE":"USD","PAYMENTINFO_0_PAYMENTSTATUS":"Completed","PAYMENTINFO_0_PENDINGREASON":"None","PAYMENTINFO_0_REASONCODE":"None","PAYMENTINFO_0_PROTECTIONELIGIBILITY":"Ineligible","PAYMENTINFO_0_ERRORCODE":"0","PAYMENTINFO_0_ACK":"Success"}', 'successful' => 1, 'gross_price' => 5.99, 'service_fee' => 0.35, 'currency' => 'USD', 'status' => 'complete')); // id in $cr->response['payload'] $cust = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'whocares', 'first_name' => 'Fake', 'last_name' => 'McTest', 'display_name' => 'Fake McTest')); $ord = new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'addorder', 'user_id' => 1, 'customer_user_id' => $cust->response['payload'], 'transaction_id' => $cr->response['payload'], 'order_contents' => array(array('id' => 1, 'user_id' => 1, 'name' => 'Sample item', 'description' => 'This is a description for the test item.', 'sku' => '#abc123', 'price' => '5.99', 'flexible_price' => 0, 'digital_fulfillment' => 1, 'physical_fulfillment' => 0, 'physical_weight' => 0, 'physical_width' => 0, 'physical_height' => 0, 'physical_depth' => 0, 'available_units' => -1, 'variable_pricing' => 0, 'fulfillment_asset' => 1, 'descriptive_asset' => 0, 'creation_date' => time())), 'fulfilled' => 0, 'canceled' => 0, 'physical' => 0, 'digital' => 1, 'notes' => '', 'country_code' => 'US', 'currency' => 'USD', 'element_id' => 1)); // this is silly, but we need to edit the order to get a positive "modification_date" // in the table — easiest way to test for abandoned/non-abandoned. will probably be // changing that behavior later. new CASHRequest(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $ord->response['payload'], 'fulfilled' => 1)); $cr = new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addvenue', 'name' => 'Tiga', 'city' => 'Portland', 'region' => 'OR')); $venue_id = $cr->response['payload']; new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addevent', 'date' => 1388534400, 'user_id' => 1, 'venue_id' => $venue_id, 'published' => 1, 'comment' => 'past event')); new CASHRequest(array('cash_request_type' => 'calendar', 'cash_action' => 'addevent', 'date' => time() + 5184000, 'user_id' => 1, 'venue_id' => $venue_id, 'published' => 1, 'comment' => 'coming event')); $cr = new CASHRequest(array('cash_request_type' => 'element', 'cash_action' => 'addelement', 'name' => 'Test element', 'type' => 'emailcollection', 'options_data' => array('message_invalid_email' => 'Sorry, that email address wasn\'t valid. Please try again.', 'message_privacy' => 'We won\'t share, sell, or be jerks with your email address.', 'message_success' => 'Thanks! You\'re all signed up.', 'email_list_id' => $list_id, 'asset_id' => $file_id, 'comment_or_radio' => 0, 'do_not_verify' => 1), 'user_id' => 1)); ?>
<?php $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes(); $settings_for_user = $page_data_object->getAllConnectionsforUser(); $all_services = array(); $typecount = 1; foreach ($settings_types_data as $key => $data) { if ($typecount % 2 == 0) { $alternating_type = true; } else { $alternating_type = false; } if (file_exists(ADMIN_BASE_PATH . '/assets/images/settings/' . $key . '.png')) { $service_has_image = true; } else { $service_has_image = false; } if (in_array($cash_admin->platform_type, $data['compatibility'])) { $all_services[] = array('key' => $key, 'name' => $data['name'], 'alternating_type' => $alternating_type, 'service_has_image' => $service_has_image); $typecount++; } } $cash_admin->page_data['all_services'] = new ArrayIterator($all_services); $settings_action = false; if ($request_parameters) { $settings_action = $request_parameters[0]; } $cash_admin->page_data['action_message'] = false; if ($settings_action) { switch ($settings_action) {
public static function handleRedirectReturn($data = false) { if (!isset($data['state'])) { return "Please start the Dropbox authentication flow from the beginning."; } $connections = CASHSystem::getSystemSettings('system_connections'); if (!isset($connections['com.dropbox'])) { return 'Please add default Dropbox credentials.'; } $auth_client = DropboxSeed::getWebAuthClient($connections['com.dropbox']['redirect_uri']); try { list($token, $user_id) = $auth_client->finish($data); } catch (Exception $e) { $token = false; } if (!$token) { return "The Dropbox authentication flow failed - please try again."; } $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($user_id . ' (Dropbox)', 'com.dropbox', array('access_token' => $token, 'user_id' => $user_id)); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $user_id . ' (Dropbox)') { $result = $connection_data['id']; break; } } } } 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.', '/settings/connections/'); } } }
$html_content = str_replace('{{subject}}', strip_tags($_POST['mail_subject']), $html_content); } else { if ($_POST['template_id'] == 'none') { $html_content = $_POST['html_content']; } else { $html_content = Markdown($_POST['html_content']); } } // make sure we include an unsubscribe link if (!stripos($html_content, '{{{unsubscribe_link}}}')) { if (stripos($html_content, '</body>')) { $html_content = str_ireplace('</body>', '<br /><br />{{{unsubscribe_link}}}</body>', $html_content); } else { $html_content = $html_content . '<br /><br />{{{unsubscribe_link}}}'; } } $mailing_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'addmailing', 'user_id' => $cash_admin->effective_user_id, 'list_id' => $_POST['email_list_id'], 'connection_id' => $_POST['connection_id'], 'subject' => $_POST['mail_subject'], 'from_name' => $_POST['mail_from'], 'html_content' => $html_content)); $mailing_result = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'sendmailing', 'mailing_id' => $mailing_response['payload'])); if ($mailing_result) { AdminHelper::formSuccess('Success. The mail is sent, just kick back and watch.', '/people/mailings/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/people/mailings/'); } } $settings_test_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_test_array = $settings_test_object->getConnectionsByScope('mass_email'); if ($settings_test_array) { $cash_admin->page_data['options_people_lists'] = AdminHelper::echoFormOptions('people_lists', 0, false, true); $cash_admin->page_data['connection_options'] = AdminHelper::echoConnectionsOptions('mass_email', 0, true); } $cash_admin->setPageContentTemplate('people_mailings');
} if (file_exists(ADMIN_BASE_PATH . '/assets/images/settings/' . $key . '.png')) { $service_has_image = true; } else { $service_has_image = false; } if (in_array($cash_admin->platform_type, $data['compatibility'])) { $all_services[] = array('key' => $key, 'name' => $data['name'], 'description' => $data['description'], 'link' => $data['link'], 'alternating_type' => $alternating_type, 'service_has_image' => $service_has_image); $typecount++; } } $cash_admin->page_data['all_services'] = new ArrayIterator($all_services); //people mass email connection present? $cash_admin->page_data['mass_connection'] = AdminHelper::getConnectionsByScope('mass_email'); // Return Mass Email Connections $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_mass_types_data = $page_data_object->getConnectionTypes('mass_email'); $all_mass_services = array(); $typecount = 1; if (is_array($settings_mass_types_data)) { foreach ($settings_mass_types_data as $key => $data) { if ($typecount % 2 == 0) { $alternating_type = true; } else { $alternating_type = false; } if (file_exists(ADMIN_BASE_PATH . '/assets/images/settings/' . $key . '.png')) { $service_has_image = true; } else { $service_has_image = false; }
function testAuth() { if ($this->s3_key) { $s3 = new S3Seed($this->cash_user_id, $this->s3_connection_id); $starting_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertTrue(is_array($starting_acp)); $second_email = getTestEnv("S3_2_EMAIL"); $second_key = getTestEnv("S3_2_KEY"); $second_secret = getTestEnv("S3_2_SECRET"); if ($second_email && $second_key && $second_secret) { $auth_success = $s3->authorizeEmailForBucket($this->s3_bucket, $second_email); $this->assertTrue($auth_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertNotEqual($starting_acp, $changed_acp); // add a new connection for the second user $c = new CASHConnection($this->cash_user_id); $new_connection_id = $c->setSettings('S32', 'com.amazon', array("key" => $second_key, "secret" => $second_secret, "bucket" => $this->s3_bucket)); if ($new_connection_id) { $s32 = new S3Seed($this->cash_user_id, $new_connection_id); // now test that we do in fact have upload permission // go through the range of tests — upload, delete, verify $test_filename = dirname(__FILE__) . '/test' . $this->timestamp; $tmp_file = file_put_contents($test_filename, $this->timestamp); $result = $s32->uploadFile($test_filename, false, false); $this->assertTrue($result); $result = $s32->deleteFile('test' . $this->timestamp); $this->assertTrue($result); $full_list = $s32->listAllFiles(); $this->assertFalse(array_key_exists('test' . $this->timestamp, $full_list)); unlink(dirname(__FILE__) . '/test' . $this->timestamp); unset($s32); $acp_success = $s3->setAccessControlPolicy($this->s3_bucket, '', $starting_acp); $this->assertTrue($acp_success); $changed_acp = $s3->getAccessControlPolicy($this->s3_bucket); $this->assertEqual($starting_acp, $changed_acp); } else { echo 'problem adding second S3Seed'; } } } }
if ($cash_admin->page_data['no_filter']) { $order_request['unfulfilled_only'] = 1; } if ($filter == 'week') { $order_request['since_date'] = time() - 604800; } if ($filter == 'byitem') { $order_request['cash_action'] = 'getordersbyitem'; $order_request['item_id'] = $request_parameters[$filter_key + 2]; $cash_admin->page_data['filter_item_id'] = $order_request['item_id']; } $orders_response = $cash_admin->requestAndStore($order_request); //Commerce connection or Items present? $cash_admin->page_data['connection'] = AdminHelper::getConnectionsByScope('commerce') || $items_response['payload']; // Return Connection $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes('commerce'); $all_services = array(); $typecount = 1; foreach ($settings_types_data as $key => $data) { if ($typecount % 2 == 0) { $alternating_type = true; } else { $alternating_type = false; } if (file_exists(ADMIN_BASE_PATH . '/assets/images/settings/' . $key . '.png')) { $service_has_image = true; } else { $service_has_image = false; } if (in_array($cash_admin->platform_type, $data['compatibility'])) {
public static function handleRedirectReturn($data = false) { if (isset($data['code'])) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.google.drive'])) { $credentials = GoogleDriveSeed::exchangeCode($data['code'], $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret'], $connections['com.google.drive']['redirect_uri']); $user_info = GoogleDriveSeed::getUserInfo($credentials, $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret']); if ($user_info) { $email_address = $user_info['email']; $user_id = $user_info['id']; } else { $email_address = false; $user_id = false; } $credentials_array = json_decode($credentials, true); if (isset($credentials_array['refresh_token'])) { // 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($email_address . ' (Google Drive)', 'com.google.drive', array('user_id' => $user_id, 'email_address' => $email_address, 'access_token' => $credentials, 'access_expires' => $credentials_array['created'] + $credentials_array['expires_in'], 'refresh_token' => $credentials_array['refresh_token'])); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $email_address . ' (Google Drive)') { $result = $connection_data['id']; break; } } } } 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.', '/settings/connections/'); } } } else { return 'Could not find a refresh token from google'; } } else { return 'Please add default google drive app credentials.'; } } else { return 'There was an error. (session) Please try again.'; } }
/** * Finds settings matching a specified scope and echoes them out formatted * for a dropdown box in a form * */ public static function echoSettingsOptions($scope, $selected = false) { // get system settings: $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes($scope); $applicable_settings_array = false; foreach ($settings_types_data as $type_data) { $result = $page_data_object->getSettingsByType($type_data->type); if ($result) { if (!$applicable_settings_array) { $applicable_settings_array = array(); } $applicable_settings_array = $applicable_settings_array + $result; } } // echo out the proper dropdown bits if ($applicable_settings_array) { $settings_count = 1; foreach ($applicable_settings_array as $setting) { $echo_selected = ''; if ($setting['id'] == $selected) { $echo_selected = ' selected="selected"'; } echo '<option value="' . $setting['id'] . '"' . $echo_selected . '>' . $setting['name'] . '</option>'; } } }
/** * Feed in a user id and element type (string) and this function returns either * true, meaning the user has defined all the required bits needed to set up an * element of the type; or an array containing codes for what's missing. * * A boolean return of false means there was an error reading the JSON * * @param {int} $user_id - the user * @param {string} $element_type - element type name * @return true|false|array */ protected function checkUserRequirements($user_id, $element_type) { $json_location = CASH_PLATFORM_ROOT . '/elements/' . $element_type . '/app.json'; $app_json = false; if (file_exists($json_location)) { $app_json = json_decode(file_get_contents($json_location), true); } if ($app_json) { $failures = array(); foreach ($app_json['options'] as $section_name => $details) { foreach ($details['data'] as $data => $values) { if ($values['type'] == 'select') { if (is_string($values['values'])) { if (substr($values['values'], 0, 7) == 'connect') { $scope = explode('/', $values['values']); // get system settings: $data_object = new CASHConnection($user_id); if (!$data_object->getConnectionsByScope($scope[1])) { $failures[] = $values['values']; } } else { $action_name = false; switch ($values['values']) { case 'assets': $plant_name = 'asset'; $action_name = 'getassetsforuser'; break; case 'people/lists': $plant_name = 'people'; $action_name = 'getlistsforuser'; break; case 'items': case 'commerce/items': $plant_name = 'commerce'; $action_name = 'getitemsforuser'; break; } if ($action_name) { $requirements_request = new CASHRequest(array('cash_request_type' => $plant_name, 'cash_action' => $action_name, 'user_id' => $user_id, 'parent_id' => 0)); if (!$requirements_request->response['payload']) { $failures[] = $values['values']; } } } } } } } if (count($failures) == 0) { return true; } else { return $failures; } } else { return false; } }
<?php $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes(); $settings_for_user = $page_data_object->getAllConnectionsforUser(); if ($request_parameters) { $settings_action = $request_parameters[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/twitter/OAuth.php'; require_once CASH_PLATFORM_ROOT . '/lib/twitter/twitteroauth.php'; $temporary_credentials = AdminHelper::getPersistentData('twitter_temporary_credentials'); $twitter = new TwitterOAuth($connections['com.twitter']['client_id'], $connections['com.teitter']['client_secret'], $temporary_credentials['oauth_token'], $temporary_credentials['oauth_token_secret']); $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']); if ($twitter->http_code == 200) { // 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('@' . $access_token['screen_name'] . ' (Twitter)', 'com.twitter', array('token' => $access_token)); if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Could not save connection.', '/settings/connections/'); } } else { AdminHelper::formFailure('Error. Problem communicating with Twitter', '/settings/connections/'); } } }
array( 'cash_request_type' => 'asset', 'cash_action' => 'getassetsforuser', 'type' => 'playlist', 'parent_id' => 0, 'user_id' => $user_id ) ); */ $files_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'getassetsforuser', 'type' => 'file', 'parent_id' => 0, 'user_id' => $user_id)); // we need to get all items for the user to determine if an asset is monetized $items_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'getitemsforuser', 'user_id' => $cash_admin->effective_user_id)); //Commerce connection, release or files present? $cash_admin->page_data['connection'] = AdminHelper::getConnectionsByScope('assets') || $releases_response['payload'] || $files_response['payload']; // Return Connection $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $settings_types_data = $page_data_object->getConnectionTypes('assets'); $all_services = array(); $typecount = 1; foreach ($settings_types_data as $key => $data) { if ($typecount % 2 == 0) { $alternating_type = true; } else { $alternating_type = false; } if (file_exists(ADMIN_BASE_PATH . '/assets/images/settings/' . $key . '.png')) { $service_has_image = true; } else { $service_has_image = false; } if (in_array($cash_admin->platform_type, $data['compatibility'])) {
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.'); } } } }