本文整理汇总了PHP中String::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP String::prepare方法的具体用法?PHP String::prepare怎么用?PHP String::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::prepare方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateUser
public function updateUser()
{
$user = false;
$updateError = null;
if ($this->passwordOld !== $this->passwordNew) {
$webserviceUrl = String::prepare('%svisualization/wo/user', WEBSERVICE_URL);
$webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->user['UserName'], 'userKey' => $this->user['ApiKey'], 'userPasswordOld' => $this->passwordOld, 'userPasswordNew' => $this->passwordNew, 'userPasswordConfirm' => $this->passwordConfirm, 'format' => 'application/json');
$requestContents = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => http_build_query($webserviceParams)));
if ($requestContents) {
$jsonOutput = json_decode($requestContents, true);
if (isset($jsonOutput['response']['user']) && $jsonOutput['response']['user']) {
$userOutput = $jsonOutput['response']['user'];
if ($userOutput['user'] && !$userOutput['error']) {
$user = $userOutput['user'];
} else {
$updateError = is_array($userOutput['error']) ? implode('<br>', Collection::flatten($userOutput['error'])) : $userOutput['error'];
}
}
}
if ($user) {
$saltSize = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
$salt = base64_encode(mcrypt_create_iv($saltSize, MCRYPT_RAND));
$this->vizDb->update(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationUser', array('Password' => hash('sha256', $salt . $this->passwordNew), 'PasswordSalt' => $salt), 'Name=?', array($this->user['UserName']));
Session::setData(REQUEST_PARAMETER_USER_NAME, $user);
} elseif (empty($updateError)) {
$updateError = __('An unknown error occured while updating');
}
} else {
$updateError = __('The new password can not be equal to the old password');
}
// Return the user update result
return array(REQUEST_RESULT => $user ? true : false, REQUEST_ERROR => $updateError);
}
示例2: validateEndpoint
/**
* Validate a requested endpoint.
*
* @return mixed Endpoint record on success, false otherwise
*/
protected function validateEndpoint()
{
// The method call is invalid if we're missing parameters
if (empty($this->module) || empty($this->action)) {
return false;
}
$physicalControllerPath = String::prepare(DIR_APP_MODULE_CONTROLLER, ucfirst($this->module)) . ucfirst($this->module) . 'Controller.php';
return file_exists($physicalControllerPath);
}
示例3: loadLanguage
/**
* Load the module language file.
*
* @param string $language Language code
* @param string $languagePath Path to the language file (optional)
* @return boolean True on success, false otherwise
*/
protected function loadLanguage($language, $languagePath = null)
{
// In case no language path is given, prepare the module language path
if (empty($languagePath)) {
$languagePath = String::prepare(DIR_APP_MODULE_LANGUAGE, $this->module);
}
// Load the language file and return the result
return parent::loadLanguage($language, $languagePath);
}
示例4: setPropositionLayer
public function setPropositionLayer()
{
$propositionResult = false;
if ($this->visualization[REQUEST_PARAMETER_MYMAP]) {
$vizJSON = $this->getVisualizationJSON();
$propositionsLayer = array();
if (isset($vizJSON['layers'])) {
$layer = end($vizJSON['layers']);
if (isset($layer['type']) && $layer['type'] === 'layergroup') {
foreach ($layer['options']['layer_definition']['layers'] as $groupLayer) {
// substr: remove the date from the end of the layer name (Ymd_His)
if (isset($groupLayer['options']['layer_name']) && String::endsWith(substr($groupLayer['options']['layer_name'], 0, -16), '_propose')) {
$propositionsLayer = $groupLayer;
break;
}
}
}
}
if (!$propositionsLayer) {
$vizResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/viz/%s?api_key=%s', $this->user['UserName'], $this->visualization[REQUEST_PARAMETER_VIZ_ID], $this->user['ApiKey']));
if ($vizResult) {
$visualization = json_decode($vizResult, true);
if (isset($visualization['related_tables'])) {
$table = reset($visualization['related_tables']);
$tableId = $table['id'];
$tableResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables/%s?api_key=%s', $this->user['UserName'], $tableId, $this->user['ApiKey']));
if ($tableResult) {
$originalTable = json_decode($tableResult, true);
// substr: retrieve the base table name and date from the original table name (Ymd_His)
$originalName = substr($originalTable['name'], 0, -16);
$originalDate = substr($originalTable['name'], -15);
// the_geom_type: geometry, multipolygon, point, multilinestring
$createTableResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables?api_key=%s', $this->user['UserName'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('name' => substr($originalName, 0, 22) . '_propose_' . $originalDate, 'description' => __('Update propositions for %s', $originalTable['name']), 'tags' => 'update,propose,propositions')));
if ($createTableResult) {
$newTable = json_decode($createTableResult, true);
$newTableName = $newTable['name'];
Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/tables/%s?api_key=%s', $this->user['UserName'], $newTable['id'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode(array('privacy' => 'PUBLIC'))));
Connectivity::closeCurl();
$columns = array(' ADD COLUMN user_id text NOT NULL', ' ADD COLUMN visualization_id text NOT NULL', ' ADD COLUMN column_data text', ' ADD COLUMN the_geom_old geometry');
$columnQuery = "ALTER TABLE \"{$newTableName}\"" . implode(',', $columns) . ';';
$sqlResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v2/sql', $this->user['UserName']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('q' => $columnQuery, 'api_key' => $this->user['ApiKey'])));
$layerParams = array('kind' => 'carto', 'order' => 2, 'options' => array('table_name' => $newTableName, 'user_name' => $this->user['UserName'], 'interactivity' => 'cartodb_id', 'visible' => false, 'style_version' => '2.1.1', 'tile_style' => "#{$newTableName} {\n // points\n [mapnik-geometry-type=point] {\n marker-fill: #77BBDD;\n marker-opacity: 0.5;\n marker-width: 12;\n marker-line-color: #222222;\n marker-line-width: 3;\n marker-line-opacity: 1;\n marker-placement: point;\n marker-type: ellipse;\n marker-allow-overlap: true;\n }\n\n //lines\n [mapnik-geometry-type=linestring] {\n line-color: #77BBDD;\n line-width: 2;\n line-opacity: 0.5;\n }\n\n //polygons\n [mapnik-geometry-type=polygon] {\n polygon-fill: #77BBDD;\n polygon-opacity: 0.5;\n line-opacity: 1;\n line-color: #222222;\n }\n}"));
$layerCreateResult = Connectivity::runCurl(String::prepare('http://%s.spotzi.me/api/v1/maps/%s/layers?api_key=%s', $this->user['UserName'], $visualization['map_id'], $this->user['ApiKey']), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode($layerParams)));
$propositionResult = (bool) $layerCreateResult;
}
}
}
}
}
}
return array(REQUEST_RESULT => $propositionResult);
}
示例5: update
public function update()
{
$result = false;
if (isset($this->visualization[REQUEST_PARAMETER_VIZ_ID])) {
$mapPrivacy = $this->getParam('mapPrivacy');
$mapPrivacyUsers = $this->getParam('mapPrivacyUsers');
$editPrivacy = $this->getParam('editPrivacy');
$editPrivacyUsers = $this->getParam('editPrivacyUsers');
$editMode = $this->getParam('editMode') === 'on';
$apiUrl = String::prepare('http://%s.spotzi.me/api/v1/viz/%s?api_key=%s', $this->user['UserName'], $this->visualization[REQUEST_PARAMETER_VIZ_ID], $this->user['ApiKey']);
$apiParams = array('map_options' => json_encode(array('map_privacy' => $mapPrivacy, 'map_privacy_users' => $mapPrivacyUsers, 'edit_privacy' => $editPrivacy, 'edit_privacy_users' => $editPrivacyUsers ? $editPrivacyUsers : $mapPrivacyUsers, 'edit_mode' => $editMode)));
Connectivity::runCurl($apiUrl, array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array('Content-Type: application/json'), CURLOPT_POSTFIELDS => json_encode($apiParams)));
$httpCode = Connectivity::getCurlInfo(CURLINFO_HTTP_CODE);
$result = $httpCode === 200;
}
// Return the update result
return array(REQUEST_RESULT => $result);
}
示例6: validate
public function validate()
{
$webserviceUrl = String::prepare('%svisualization/wo/user?user=%s&password=%s&userName=%s&userPassword=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $this->userName, $this->userPassword);
$requestContents = Connectivity::runCurl($webserviceUrl);
$validateResult = false;
$validateError = null;
if ($requestContents) {
$jsonOutput = json_decode($requestContents, true);
if (isset($jsonOutput['response']['user'])) {
$validateResult = true;
Session::setData(REQUEST_PARAMETER_LOGGEDIN, true);
Session::setData('freshLogin', true);
Session::setData(REQUEST_PARAMETER_USER_NAME, $jsonOutput['response']['user']);
}
}
if (!$validateResult && empty($validateError)) {
$validateError = __('Your user name or password is incorrect');
}
// Return the validation result
return array(REQUEST_RESULT => $validateResult, REQUEST_ERROR => $validateError);
}
示例7: prepareVisualization
/**
*
* @return string
*/
protected function prepareVisualization()
{
$loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN);
$sessionViz = Session::getData(REQUEST_PARAMETER_VIZ);
$user = Session::getData(REQUEST_PARAMETER_USER_NAME);
$visualization = array('communityMaps' => array(), 'myMaps' => array());
// Community maps
$webserviceUrl = String::prepare('%svisualization/wo/community?user=%s&password=%s&userName=%s&userKey=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $user['UserName'], $user['ApiKey']);
$requestContents = Connectivity::runCurl($webserviceUrl);
if ($requestContents) {
$jsonOutput = json_decode($requestContents, true);
if (isset($jsonOutput['response']['community'])) {
$visualization['communityMaps'] = $jsonOutput['response']['community'];
}
}
// My maps
if ($loggedIn) {
$webserviceUrl = String::prepare('%svisualization/wo/visualization?user=%s&password=%s&userName=%s&userKey=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $user['UserName'], $user['ApiKey']);
$requestContents = Connectivity::runCurl($webserviceUrl);
if ($requestContents) {
$jsonOutput = json_decode($requestContents, true);
if (isset($jsonOutput['response']['visualization'])) {
$visualization['myMaps'] = $jsonOutput['response']['visualization'];
}
}
}
// Set the default visualization
$vizUrl = isset($sessionViz[REQUEST_PARAMETER_VIZ_URL]) ? $sessionViz[REQUEST_PARAMETER_VIZ_URL] : '';
// Fallback for the default visualization
if (empty($visualization['defaultVisualization'])) {
if (!$vizUrl) {
$vizUrl = $loggedIn && isset($sessionViz[REQUEST_PARAMETER_VIZ_URL]) ? $sessionViz[REQUEST_PARAMETER_VIZ_URL] : null;
}
$visualization['defaultVisualization'] = array('Url' => $vizUrl ? $vizUrl : VISUALIZATION_DEFAULT);
if (!$vizUrl) {
$this->visualizationSet = false;
}
}
$this->visualization = $visualization;
}
示例8: import
public function import()
{
// Set the script execution settings
$importSize = String::formatBytes(VISUALIZATION_IMPORT_SIZE, 'mB');
setExecutionSettings($importSize + 256);
$result = false;
$error = null;
$fileName = File::handleUpload(DIR_TEMP, 'importFile', null, array(), VISUALIZATION_IMPORT_SIZE);
if ($fileName) {
$fileInfo = pathinfo($fileName);
$fileNameNew = str_replace(' ', '_', substr(strtolower($fileInfo['filename']), 0, 22)) . '_' . Date::format('now', 'Ymd_His') . '.' . $fileInfo['extension'];
$destinationDir = '\\\\db-images\\data.spotzi.com\\import\\' . $this->user['UserName'];
if (!is_dir($destinationDir)) {
mkdir($destinationDir);
}
$destination = $destinationDir . '\\' . $fileNameNew;
if (is_dir($destinationDir) && copy(DIR_TEMP . $fileName, $destination)) {
$importName = $this->getParam('importName');
if (!$importName) {
$importName = ucwords(substr(str_replace('_', ' ', $fileName), 0, strrpos($fileName, '.')));
}
$dataUrl = 'http://data.spotzi.com/import/' . $this->user['UserName'] . '/' . $fileNameNew;
$this->vizDb->insert(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationImport', array('Service' => 'geonovum', 'UserName' => $this->user['UserName'], 'Email' => $this->user['Email'], 'Name' => $importName, 'DataUrl' => $dataUrl, 'DebugImport' => debugMode()));
$webserviceUrl = String::prepare('%svisualization/wo/import?user=%s&password=%s&userName=%s&userKey=%s&callback=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $this->user['UserName'], $this->user['ApiKey'], Url::buildPlatformURL(false, 'import', 'import', 'finish'));
Connectivity::runCurlAsync($webserviceUrl);
$result = true;
} else {
$error = __('An error occured while preparing the file');
}
File::delete(DIR_TEMP . $fileName);
} else {
$error = __('An error occured while uploading the file');
}
if ($result === false) {
ErrorHandler::error(E_NOTICE, "The import failed, file name: %s\nerror: %s", $fileName, $error);
}
return array(REQUEST_RESULT => $result, REQUEST_ERROR => $error);
}
示例9: register
public function register()
{
$webserviceUrl = String::prepare('%svisualization/wo/user', WEBSERVICE_URL);
$webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->userName, 'userEmail' => $this->userEmail, 'userPassword' => $this->userPassword, 'format' => 'application/json');
$requestContents = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $webserviceParams));
$user = false;
$registerError = null;
if ($requestContents) {
$jsonOutput = json_decode($requestContents, true);
if (isset($jsonOutput['response']['user']) && $jsonOutput['response']['user']) {
$userOutput = $jsonOutput['response']['user'];
if ($userOutput['user'] && !$userOutput['error']) {
$user = $userOutput['user'];
} else {
if (is_array($userOutput['error'])) {
$userErrors = array();
foreach ($userOutput['error'] as $field => $errors) {
$fieldPresent = !empty($webserviceParams[$field]);
switch ($field) {
case REQUEST_PARAMETER_USER_NAME:
$field = __('User name');
break;
case REQUEST_PARAMETER_USER_EMAIL:
$field = __('Email address');
break;
case REQUEST_PARAMETER_USER_PASSWORD:
$field = __('Password');
break;
}
foreach ($errors as $error) {
if ($error === 'is not present' && $fieldPresent) {
continue;
}
$userErrors[] = '<b>' . $field . '</b> ' . $error;
}
}
$registerError = implode('<br>', $userErrors);
} else {
$registerError = $userOutput['error'];
}
}
}
}
if ($user) {
$saltSize = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
$salt = base64_encode(mcrypt_create_iv($saltSize, MCRYPT_RAND));
$this->vizDb->insert(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationUser', array('Id' => $user['Id'], 'Name' => $user['UserName'], 'Password' => hash('sha256', $salt . $this->userPassword), 'PasswordSalt' => $salt, 'Email' => $user['Email'], 'ApiKey' => $user['ApiKey']));
Session::setData(REQUEST_PARAMETER_LOGGEDIN, true);
Session::setData('freshLogin', true);
Session::setData(REQUEST_PARAMETER_USER_NAME, $user);
// Retrieve the register email template
ob_start();
require_once $this->modulePath . DIR_VIEW . 'mail/register.php';
$message = ob_get_clean();
// Prepare the register mailer
Mail::addMailer(EMAIL_HOST, EMAIL_PORT, EMAIL_FROM, EMAIL_FROM_PASSWORD, BRAND_PRODUCT);
// Send the register email
Mail::send($this->userEmail, EMAIL_FROM, __('%s - your Spotzi Mapbuilder account', BRAND_PRODUCT), $message, true, true);
// Add the user to the newsletter subscription list
$this->registerNewsletterSubscription($this->userEmail);
} elseif (empty($registerError)) {
$registerError = __('An unknown error occured while registering');
}
// Return the register result
return array(REQUEST_RESULT => $user ? true : false, REQUEST_ERROR => $registerError);
}
示例10: addFeature
public function addFeature()
{
$this->featureArray = ['visualizationId' => $this->visualization[REQUEST_PARAMETER_VIZ_ID], 'featureAction' => $this->action];
switch ($this->action) {
case EDITOR_ACTION_NEW_FEATURE:
$this->featureArray['the_geom'] = $this->the_geom;
$this->featureArray['geom_type'] = $this->geom_type;
$this->featureArray['featureStyle'] = $this->featureStyle;
break;
case EDITOR_ACTION_EDIT_DATA:
$this->featureArray['featureId'] = $this->featureId;
$this->featureArray['layerId'] = $this->layerId;
$this->featureArray['geom_type'] = $this->geom_type;
$this->featureArray['featureStyle'] = $this->featureStyle;
break;
case EDITOR_ACTION_EDIT_GEOM:
$this->featureArray['featureId'] = $this->featureId;
$this->featureArray['layerId'] = $this->layerId;
$this->featureArray['the_geom'] = $this->the_geom;
$this->featureArray['geom_type'] = $this->geom_type;
break;
case EDITOR_ACTION_DELETE:
$this->featureArray['featureId'] = $this->featureId;
$this->featureArray['layerId'] = $this->layerId;
break;
}
if (in_array($this->action, [EDITOR_ACTION_NEW_FEATURE, EDITOR_ACTION_EDIT_DATA])) {
$fileName = File::handleUpload(DIR_TEMP, 'imageurl', null, array(), 26214400);
//25 MB
$imageurl = '';
if ($fileName) {
if (exif_imagetype(DIR_TEMP . $fileName)) {
$fileNameNew = Date::format('now', 'YmdHis') . '_' . str_replace(' ', '_', $fileName);
$destinationDir = '\\\\db-images\\images.spotzi.com\\mapbuilder\\users\\' . $this->user['UserName'];
if (!is_dir($destinationDir)) {
mkdir($destinationDir);
}
$destination = $destinationDir . '\\' . $fileNameNew;
if (is_dir($destinationDir) && copy(DIR_TEMP . $fileName, $destination)) {
$importName = substr(str_replace('_', ' ', $fileName), 0, strrpos($fileName, '.'));
$imageurl = 'http://images.spotzi.com/mapbuilder/users/' . $this->user['UserName'] . '/' . $fileNameNew;
}
File::delete(DIR_TEMP . $fileName);
} else {
File::delete(DIR_TEMP . $fileName);
ErrorHandler::error(E_ERROR, String::prepare('%s is not an image', $fileName));
}
} else {
$imageurl = $this->getParam('image');
}
$this->featureArray['name'] = $this->getParam('name') ? $this->getParam('name') : '';
$this->featureArray['description'] = $this->getParam('description') ? $this->getParam('description') : '';
$this->featureArray['imageurl'] = $imageurl ? $imageurl : '';
}
$this->feature = json_encode($this->featureArray);
$webserviceUrl = WEBSERVICE_URL . 'visualization/wo/map_feature';
$webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->user['UserName'], 'userKey' => $this->user['ApiKey'], 'feature' => $this->feature, 'format' => 'application/json');
$result = false;
$webserviceResult = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $webserviceParams));
if ($webserviceResult) {
$webserviceContents = json_decode($webserviceResult, true);
if (isset($webserviceContents['response']['map_feature'])) {
$result = $webserviceContents['response']['map_feature'];
}
}
return array(REQUEST_RESULT => $result);
}
示例11: getRequestController
/**
* Retrieve the requested module controller.
*
* @return ModuleController Module controller
*/
protected function getRequestController()
{
// Create the controller object
$requestController = $this->getController($this->module, String::prepare(DIR_APP_MODULE_CONTROLLER, ucfirst($this->module)));
// Set the core metadata when needed
if ($requestController) {
$requestController->meta['core'] = $this->meta['core'];
}
// Return the controller object
return $requestController;
}