本文整理汇总了PHP中Sanitize::translate方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitize::translate方法的具体用法?PHP Sanitize::translate怎么用?PHP Sanitize::translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitize
的用法示例。
在下文中一共展示了Sanitize::translate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
function save(&$data)
{
$isNew = Sanitize::getInt($data['FieldOption'], 'optionid') ? false : true;
$field_id = Sanitize::getInt($data['FieldOption'], 'fieldid');
if ($isNew) {
// Remove non alphanumeric characters from option value
$data['FieldOption']['value'] = Sanitize::translate($data['FieldOption']['value']);
$data['FieldOption']['value'] = str_replace($this->blackList, '', $data['FieldOption']['value']);
$data['FieldOption']['value'] = str_replace($this->dashReplacements, '-', $data['FieldOption']['value']);
$data['FieldOption']['value'] = preg_replace(array('/[-]+/'), array('-'), $data['FieldOption']['value']);
$data['FieldOption']['value'] = mb_strtolower($data['FieldOption']['value'], 'UTF-8');
// If is new checks for duplicate value
$query = "SELECT count(fieldid) FROM #__jreviews_fieldoptions WHERE fieldid = '{$field_id}' AND value = " . $this->_db->Quote($data['FieldOption']['value']);
$this->_db->setQuery($query);
if ($this->_db->loadResult()) {
return 'duplicate';
}
// Find last option
$this->_db->setQuery("select max(ordering) FROM #__jreviews_fieldoptions WHERE fieldid = '" . $field_id . "'");
$max = $this->_db->loadResult();
if ($max > 0) {
$data['FieldOption']['ordering'] = $max + 1;
} else {
$data['FieldOption']['ordering'] = 1;
}
}
# store it in the db
if (!$this->store($data)) {
return 'db_error';
}
return 'success';
}
示例2: save
function save(&$data)
{
$isNew = Sanitize::getInt($data['FieldOption'], 'optionid') ? false : true;
$control_value = '';
$field_id = Sanitize::getInt($data['FieldOption'], 'fieldid');
// Before saving storing control field info for the field option,
// first check if this is a Field Option => Field relationship
// If it is, then we drop the control field info.
$query = "SELECT control_field FROM #__jreviews_fields WHERE fieldid = " . $field_id;
$this->_db->setQuery($query);
if (($FieldOptionToField = $this->_db->loadResult()) == '' && isset($data['FieldOption']['control_value']) && !empty($data['FieldOption']['control_value'])) {
$control_value = Sanitize::getVar($data['FieldOption'], 'control_value');
if (is_array($control_value)) {
$control_value = array_filter($control_value);
}
$data['FieldOption']['control_value'] = !empty($control_value) ? '*' . implode('*', $control_value) . '*' : '';
} else {
$data['FieldOption']['control_field'] = '';
$data['FieldOption']['control_value'] = array();
}
$data['FieldOption']['value'] = html_entity_decode(urldecode($data['FieldOption']['value']), ENT_COMPAT, 'utf-8');
if ($isNew) {
$data['FieldOption']['text'] = html_entity_decode(urldecode($data['FieldOption']['text']), ENT_COMPAT, 'utf-8');
// Remove non alphanumeric characters from option value
$data['FieldOption']['value'] = Sanitize::translate(urldecode($data['FieldOption']['value']));
$data['FieldOption']['value'] = trim($data['FieldOption']['value']);
$data['FieldOption']['value'] = str_replace($this->blackList, '', $data['FieldOption']['value']);
$data['FieldOption']['value'] = str_replace($this->dashReplacements, '-', $data['FieldOption']['value']);
$data['FieldOption']['value'] = preg_replace(array('/[-]+/'), array('-'), $data['FieldOption']['value']);
$data['FieldOption']['value'] = mb_strtolower($data['FieldOption']['value'], 'UTF-8');
// If is new checks for duplicate value
$query = "\n SELECT \n optionid, control_field, control_value \n FROM \n #__jreviews_fieldoptions \n WHERE \n fieldid = {$field_id} AND value = " . $this->_db->Quote($data['FieldOption']['value']);
$this->_db->setQuery($query);
$option = $this->_db->loadAssocList();
if (!empty($option) && $control_value == '') {
return 'duplicate';
} elseif (!empty($option) && $control_value != '') {
$option = array_shift($option);
$option['control_value'] = explode('*', rtrim(ltrim($option['control_value'], '*'), '*'));
$value_exists = array_intersect($control_value, $option['control_value']);
if ($data['FieldOption']['control_field'] == $option['control_field'] && !empty($value_exists)) {
return 'duplicate';
}
$data['FieldOption']['control_value'] = '*' . implode('*', array_unique(array_merge($control_value, $option['control_value']))) . '*';
$data['FieldOption']['optionid'] = $option['optionid'];
}
// Find last option
if (!isset($data['FieldOption']['optionid'])) {
$this->_db->setQuery("SELECT max(ordering) FROM #__jreviews_fieldoptions WHERE fieldid = '" . $field_id . "'");
$max = $this->_db->loadResult();
if ($max > 0) {
$data['FieldOption']['ordering'] = $max + 1;
} else {
$data['FieldOption']['ordering'] = 1;
}
}
}
// Make sure there's a control value, otherwise clear the control field as well
if (empty($data['FieldOption']['control_value'])) {
$data['FieldOption']['control_field'] = '';
}
# store it in the db
if (!$this->store($data)) {
return 'db_error';
}
return 'success';
}
示例3: uploadImages
function uploadImages($listing_id, $path)
{
$imgMaxWidth = $this->Config->content_max_imgwidth;
$fileKeys = $this->fileKeys;
$images = array();
// Load thumbnail library
App::import('Vendor', 'phpthumb' . DS . 'ThumbLib.inc');
foreach ($fileKeys as $key) {
$tmp_name = $_FILES['image']['tmp_name'][$key];
$name = basename($_FILES['image']['name'][$key]);
$fileParts = pathinfo($name);
// Remove special chars, lowercase and trim
$filename = trim(strtolower(Sanitize::translate($fileParts['filename'])));
// Remove any duplicate whitespace, and ensure all characters are alphanumeric
$filename = preg_replace(array('/\\s+/', '/\\_+/', '/\\./', '/[^A-Za-z0-9\\-]/', '/\\-+/'), array('-', '-', '-', '', '-'), $filename);
// Append datetime stamp to file name
$filename = $filename . "-" . time();
// Prepend contentid
$filename = $listing_id . "_" . $filename . "." . $fileParts['extension'];
$uploadfile = $path . $filename;
if (move_uploaded_file($tmp_name, $uploadfile)) {
$images[] = "jreviews/" . $filename . "|||0||bottom||";
chmod($uploadfile, 0644);
// Begin image resizing
if ($imgMaxWidth > 0) {
$thumb = PhpThumbFactory::create($uploadfile);
extract($thumb->getCurrentDimensions());
/* $width, $height */
$thumb->resize($imgMaxWidth, $height)->save($uploadfile);
}
}
}
$this->images = $images;
}