/** * 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'])); } } }
/** * Finds settings matching a specified scope and echoes them out formatted * for a dropdown box in a form * */ public static function echoConnectionsOptions($scope, $selected = false, $return = false) { // get system settings: $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $applicable_settings_array = $page_data_object->getConnectionsByScope($scope); // echo out the proper dropdown bits if ($applicable_settings_array) { $settings_count = 1; $all_connections = ''; foreach ($applicable_settings_array as $setting) { $echo_selected = ''; if ($setting['id'] == $selected) { $echo_selected = ' selected="selected"'; } $all_connections .= '<option value="' . $setting['id'] . '"' . $echo_selected . '>' . $setting['name'] . '</option>'; } if ($return) { return $all_connections; } else { echo $all_connections; } } }
public static function getConnectionsByScope($scope) { // get system settings: $page_data_object = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $applicable_settings_array = $page_data_object->getConnectionsByScope($scope); return $applicable_settings_array; }
} else { $min = $Min; $max = $Max; } $randomfloat = $min + mt_rand() / mt_getrandmax() * ($max - $min); if ($round > 0) { $randomfloat = round($randomfloat, $round); } return $randomfloat; } // include the main CASH file include_once __DIR__ . '/../../framework/cashmusic.php'; // check for existing commerce connections // if not found, add a fake paypal connection for testing $page_data_object = new CASHConnection(1); $connections = $page_data_object->getConnectionsByScope('commerce'); if (is_array($connections)) { $c_id = $connections[0]['id']; } else { $c = new CASHConnection(1); $c_id = $c->setSettings('Fake Paypal connection', 'com.paypal', array('whatever' => 0)); } // add a customer. if this fake dude's already in the system we just get his ID $cust = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'addlogin', 'address' => '*****@*****.**', 'password' => 'whocares', 'first_name' => 'Fake', 'last_name' => 'McTest', 'display_name' => 'Fake McTest')); // do between one and seven orders. mix it up! $loops = rand(1, 7); $i = 1; while ($i <= $loops) { // randomize the price $price = float_rand(3.0, 150.0, 2); $fee = 0.05 + $price * 0.03;
<?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;
/** * 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; } }
$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');