本文整理汇总了PHP中URLify::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP URLify::filter方法的具体用法?PHP URLify::filter怎么用?PHP URLify::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类URLify
的用法示例。
在下文中一共展示了URLify::filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* {@inheritdoc}
*/
public function upload($fp, $dst, $name, $tmpname)
{
$this->setConnectorFromPlugin();
// upload file by elfinder.
$result = parent::upload($fp, $dst, $name, $tmpname);
$name = $result['name'];
$filtered = \URLify::filter($result['name'], 80);
if (strcmp($name, $filtered) != 0) {
/*$arg = array('target' => $file['hash'], 'name' => $filtered);
$elFinder->exec('rename', $arg);*/
$this->rename($result['hash'], $filtered);
}
$realPath = $this->realpath($result['hash']);
if (!empty($realPath)) {
// Getting file info
//$info = $elFinder->exec('file', array('target' => $file['hash']));
/** @var elFinderVolumeLocalFileSystem $volume */
//$volume = $info['volume'];
//$root = $volume->root();
//var/www/chamilogits/data/courses/NEWONE/document
$realPathRoot = $this->getCourseDocumentSysPath();
// Removing course path
$realPath = str_replace($realPathRoot, '/', $realPath);
\FileManager::add_document($this->connector->course, $realPath, 'file', intval($result['size']), $result['name']);
}
return $result;
}
示例2: execute
public function execute(Stdio $stdio, array $params = [])
{
if (strpos($params['source'], 'data/') !== 0) {
throw new \DomainException('The source must be in the data directory.');
}
if (strpos($params['target'], 'data/') !== 0) {
throw new \DomainException('The target must be in the data directory.');
}
$params['source'] = substr($params['source'], strlen('data/'));
$params['target'] = substr($params['target'], strlen('data/'));
$match = preg_match('/^(?:.*?\\/)?([0-9]{4}-[0-9]{2}-[0-9]{2}\\.|[0-9]+\\.|)([^\\/]*)$/', $params['source'], $matches);
$matches[1] = trim($matches[1], '.');
if ($params['--date']) {
$matches[1] = (new \DateTime())->format('Y-m-d');
}
if ($params['--title']) {
$matches[2] = \URLify::filter($params['--title']);
}
$file = trim($params['target'], '/') . '/';
$file .= $params['--date'] ? $matches[1] . '.' : '';
$file .= $matches[2];
$this->hooks->call('before.move');
$this->data->move($params['source'], $file);
if ($params['--title']) {
$data = $this->data->read($file);
$data['title'] = $params['--title'];
$this->data->write($file, $data);
}
$stdio->outln('<<magenta>>' . $params['source'] . ' moved to ' . $file . '<<reset>>');
$this->hooks->call('after.move');
return Status::SUCCESS;
}
示例3: filter
public function filter($value)
{
URLify::$remove_list = array();
$value = URLify::filter($value, 60, 'de');
$value = str_replace('-', '_', $value);
return $value;
}
示例4: setFile
public function setFile($title, $fieldName)
{
$storage = new \Upload\Storage\FileSystem(self::PATH_ORIGINALS);
$this->file = new \Upload\File($fieldName, $storage);
$filename = \URLify::filter($title);
$this->file->setName($filename . '-' . uniqid());
$this->file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/jpg', 'image/jpeg', 'image/gif']), new \Upload\Validation\Size('5M')]);
}
示例5: __construct
/**
* LogFile constructor.
*
* @param string $name
* @param string $clientSlug
* @param array $args
*/
public function __construct($name, $clientSlug, $args)
{
setlocale(LC_ALL, 'en_US.UTF8');
$this->name = $name;
$this->slug = \URLify::filter($name);
$this->collectionSlug = \URLify::filter($clientSlug);
$this->args = $args;
$this->lines = new ArrayCollection();
$this->loggers = new ArrayCollection();
}
示例6: run
/**
* @inheritdoc
*/
public function run()
{
if (Yii::$app->request->isPost) {
if (isset($_POST['filename'])) {
$this->fileName = \URLify::filter(pathinfo($_POST['filename'], PATHINFO_FILENAME), 255, "", true) . '_' . uniqid() . '.' . pathinfo($_POST['filename'], PATHINFO_EXTENSION);
$upload_dir = $this->uploadDir;
$upload_file = $this->fileName;
$uploader = new FileUpload('uploadfile');
$uploader->newFileName = $this->fileName;
$uploader->sizeLimit = $this->fileSizeLimit;
// Handle the upload
$result = $uploader->handleUpload($upload_dir);
unset($_POST['filename']);
if (!$result) {
$upload_result = json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg()));
} else {
if ($this->isImage($upload_dir . $upload_file)) {
//
$image_name = $upload_dir . $upload_file;
// resize with calculate aspect ratio
list($image_width, $image_height, $type, $attr) = getimagesize($image_name);
$ratio = $image_width / $image_height;
if ($ratio > 1) {
$target_width = $this->resize_max_width;
$target_height = $this->resize_max_width / $ratio;
} else {
$target_width = $this->resize_max_height * $ratio;
$target_height = $this->resize_max_height;
}
// resize image if original dimension is bigger from max size
if ($target_width < $this->resize_max_width || $target_height < $this->resize_max_height) {
Image::thumbnail($image_name, $target_width, $target_height, ManipulatorInterface::THUMBNAIL_INSET)->save($image_name);
}
// apply watermark
if ($this->watermark) {
Image::watermark($image_name, $this->watermark)->save($image_name);
}
}
// thumbnails create
if ($this->thumbnail && $this->isImage($image_name) && ($this->thumbnail_width > 0 && $this->thumbnail_height > 0)) {
Image::thumbnail($image_name, $this->thumbnail_width, $this->thumbnail_height)->save($upload_dir . 'thumbs/' . $upload_file);
}
$upload_result = ['success' => true, 'filelink' => $upload_file];
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $upload_result;
}
} else {
throw new BadRequestHttpException(Yii::t('upload', 'ONLY_POST_REQUEST'));
}
}
示例7: publishToPage
public function publishToPage(Page $c, $data, $controls)
{
$slug = array_filter($controls, function ($item) {
if ($item instanceof UrlSlugCorePageProperty) {
return true;
}
return false;
});
$this->addPageTypeComposerControlRequestValue('cName', $data['name']);
if (!count($slug) && $c->isPageDraft()) {
$txt = new \URLify();
$this->addPageTypeComposerControlRequestValue('cHandle', $txt->filter($data['name']));
}
parent::publishToPage($c, $data, $controls);
}
示例8: actionNovo
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionNovo()
{
$model = new Depoimento();
$professor = Professor::model()->findByPk($_POST['Depoimento']['id_professor']);
if (!empty($_POST['Depoimento'])) {
if (empty($_POST['Depoimento']['nome'])) {
unset($_POST['Depoimento']['nome']);
}
$model->attributes = $_POST['Depoimento'];
$model->id_disciplina = empty($_POST['Depoimento']['id_disciplina']) ? null : $_POST['Depoimento']['id_disciplina'];
if ($model->save()) {
Yii::app()->user->setFlash('success', "Seu depoimento foi enviado com sucesso e está aguardando aprovação.");
$this->redirect(Yii::app()->baseUrl . '/professor/' . $model->id_professor . '/' . URLify::filter($professor->nome));
}
}
}
示例9: execute
public function execute(Stdio $stdio, array $params = [])
{
if (strpos($params['target'], 'data/') !== 0) {
throw new \DomainException('The target must be in the data directory.');
}
$params['target'] = substr($params['target'], strlen('data/'));
if (!empty($params['--related'])) {
foreach ($params['--related'] as $key => $related) {
if (strpos($related, 'data/') !== 0) {
throw new \DomainException('Each --related must be in the data directory.');
}
$params['--related'][$key] = substr(dirname($related), strlen('data/')) . '/' . pathinfo($related, PATHINFO_FILENAME);
}
}
$data = [];
foreach (['title', 'summary', '--related'] as $param_key) {
if (!empty($params[$param_key])) {
$data[trim($param_key, '-')] = $params[$param_key];
}
}
$file = '';
if ($params['target']) {
$file = trim($params['target'], '/') . '/';
}
if ($params['--date']) {
$file .= (new \DateTime())->format('Y-m-d') . '.';
}
$file .= \URLify::filter($data['title']);
$file .= $params['--ext'] ? $params['--ext'] : '.md';
$file = trim($file, '/');
$this->hooks->call('before.make');
$this->data->write($file, $data);
$stdio->outln('<<magenta>>' . $file . ' published on ' . (new \DateTime())->format('Y-m-d') . '<<reset>>');
$this->hooks->call('after.make');
return Status::SUCCESS;
}
示例10: test_remove_words
function test_remove_words()
{
$this->assertEquals('foo-bar', URLify::filter('foo bar'));
URLify::remove_words(array('foo', 'bar'));
$this->assertEquals('', URLify::filter('foo bar'));
}
示例11: get
/**
* Returns a config property if it exists and throws an exception if not.
*
* @param string|null $property Dot-separated property (e.g. "date_format" or "logs.collection.log_file")
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function get($property = null)
{
if ($property === null || $property == '') {
return $this->config;
}
$tree = explode('.', $property);
$node = $this->config;
foreach ($tree as $workingNode) {
if (!array_key_exists($workingNode, $node)) {
$actualNode = null;
foreach ($node as $testNodeKey => $testNode) {
if (\URLify::filter($testNodeKey) == $workingNode) {
$actualNode = $testNodeKey;
}
}
if ($actualNode === null) {
throw new \InvalidArgumentException('The property "' . $property . '" was not found. Failed while getting node "' . $workingNode . '"');
}
$workingNode = $actualNode;
}
$node = $node[$workingNode];
}
return $node;
}
示例12: search
/**
* Generate a list of posts for the search app,
* and add them directly via `Search::add()`.
*/
public static function search () {
$posts = self::query ()
->where ('published', 'yes')
->fetch_orig ();
foreach ($posts as $i => $post) {
$url = 'blog/post/' . $post->id . '/' . \URLify::filter ($post->title);
if (! \Search::add (
$url,
array (
'title' => $post->title,
'text' => $post->body,
'url' => '/' . $url
)
)) {
return array (false, $i);
}
}
return array (true, count ($posts));
}
示例13: translit
/**
* Transliteration of cyrillic into URL-string
*/
public static function translit($text, $length = 60)
{
//$result = URLify::filter(iconv("windows-1251", "utf-8", $text), $length);
$result = URLify::filter($text, $length);
return $result;
}
示例14: api_replace_dangerous_char
/**
* Replaces "forbidden" characters in a filename string.
*
* @param string $filename
* @param int $length
* @param bool $file_name
*
* @return string
*/
function api_replace_dangerous_char($filename)
{
return URLify::filter($filename, 250, '', true);
/*
// Safe replacements for some non-letter characters.
static $search = array(',', "\0", ' ', "\t", "\n", "\r", "\x0B", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
static $replace = array('_', '', '_', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
// Encoding detection.
$encoding = api_detect_encoding($filename);
// Converting html-entities into encoded characters.
$filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
// Transliteration to ASCII letters, they are not dangerous for filesystems.
$filename = api_transliterate($filename, 'x', $encoding);
// Trimming leading/trailing whitespace.
$filename = trim($filename);
// Trimming any leading/trailing dots.
$filename = trim($filename, '.');
$filename = trim($filename);
// Replacing remaining dangerous non-letter characters.
$filename = str_replace($search, $replace, $filename);
if ($strict == 'strict') {
//$filename = str_replace('-', '_', $filename); // See task #1848.
//$filename = preg_replace('/[^0-9A-Za-z_.\-]/', '', $filename);
//Removing "_" character see BT#3628
$filename = preg_replace('/[^0-9A-Za-z.\-_]/', '', $filename);
}
// Length is to be limited, so the file name to be acceptable by some operating systems.
$extension = (string)strrchr($filename, '.');
$extension_len = strlen($extension);
if ($extension_len > 0 && $extension_len < 250) {
$filename = substr($filename, 0, -$extension_len);
return substr($filename, 0, 250 - $extension_len).$extension;
}
return substr($filename, 0, 250);*/
}
示例15: save
/**
* Saves an option into the corresponding *_field_options table
* @param array $params Parameters to be considered for the insertion
* @param bool $show_query Whether to show the query (sent to the parent save() method)
* @return bool True on success, false on error
* @assert (array('field_id'=>0), false) === false
* @assert (array('field_id'=>1), false) === true
*/
public function save($params, $show_query = false)
{
$field_id = intval($params['field_id']);
if (empty($field_id)) {
return false;
}
$time = api_get_utc_datetime();
if (!empty($params['field_options']) && in_array($params['field_type'], array(ExtraField::FIELD_TYPE_RADIO, ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_SELECT_MULTIPLE, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
if ($params['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
//$params['field_options'] = France:Paris;Bretagne;Marseilles;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura;
$options_parsed = ExtraField::extra_field_double_select_convert_string_to_array($params['field_options']);
if (!empty($options_parsed)) {
foreach ($options_parsed as $key => $option) {
$sub_options = $option['options'];
$new_params = array('field_id' => $field_id, 'option_value' => 0, 'option_display_text' => $option['label'], 'option_order' => 0, 'tms' => $time);
// Looking if option already exists:
$option_info = self::get_field_option_by_field_id_and_option_display_text($field_id, $option['label']);
if (empty($option_info)) {
$sub_id = parent::save($new_params, $show_query);
} else {
$sub_id = $option_info['id'];
$new_params['id'] = $sub_id;
parent::update($new_params, $show_query);
}
foreach ($sub_options as $sub_option) {
if (!empty($sub_option)) {
$new_params = array('field_id' => $field_id, 'option_value' => $sub_id, 'option_display_text' => $sub_option, 'option_order' => 0, 'tms' => $time);
$option_info = self::get_field_option_by_field_id_and_option_display_text_and_option_value($field_id, $sub_option, $sub_id);
if (empty($option_info)) {
parent::save($new_params, $show_query);
} else {
$new_params['id'] = $option_info['id'];
parent::update($new_params, $show_query);
}
}
}
}
}
$list = array();
} else {
$list = explode(';', $params['field_options']);
}
if (!empty($list)) {
foreach ($list as $option) {
$option_info = self::get_field_option_by_field_and_option($field_id, $option);
// Use URLify only for new items
$optionValue = URLify::filter($option);
$option = trim($option);
if ($option_info == false) {
$order = self::get_max_order($field_id);
$new_params = array('field_id' => $field_id, 'option_value' => trim($optionValue), 'option_display_text' => trim($option), 'option_order' => $order, 'tms' => $time);
parent::save($new_params, $show_query);
}
}
}
}
return true;
}