filter() public static method

Filters a string, e.g., "Petty theft" to "petty-theft"
public static filter ( string $text, integer $length = 60, string $language = "", boolean $file_name = false, boolean $use_remove_list = true, boolean $lower_case = true, boolean $treat_underscore_as_space = true )
$text string The text to return filtered
$length integer The length (after filtering) of the string to be returned
$language string The transliteration language, passed down to downcode()
$file_name boolean Whether there should be and additional filter considering this is a filename
$use_remove_list boolean Whether you want to remove specific elements previously set in self::$remove_list
$lower_case boolean Whether you want the filter to maintain casing or lowercase everything (default)
$treat_underscore_as_space boolean Treat underscore as space, so it will replaced with "-"
Ejemplo n.º 1
0
 /**
  * {@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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public function filter($value)
 {
     URLify::$remove_list = array();
     $value = URLify::filter($value, 60, 'de');
     $value = str_replace('-', '_', $value);
     return $value;
 }
Ejemplo n.º 4
0
 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')]);
 }
Ejemplo n.º 5
0
 /**
  * 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();
 }
Ejemplo n.º 6
0
 /**
  * @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'));
     }
 }
Ejemplo n.º 7
0
 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);
 }
 /**
  * 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));
         }
     }
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 function test_remove_words()
 {
     $this->assertEquals('foo-bar', URLify::filter('foo bar'));
     URLify::remove_words(array('foo', 'bar'));
     $this->assertEquals('', URLify::filter('foo bar'));
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
Ejemplo n.º 12
0
Archivo: Post.php Proyecto: R-J/elefant
	/**
	 * 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));
	}
Ejemplo n.º 13
0
 /**
  * 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;
 }
Ejemplo n.º 14
0
/**
 * 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);*/
}
 /**
  * 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;
 }
Ejemplo n.º 16
0
 /**
  * @param Request $request
  * @param $entity
  * @return EntityManager
  */
 public function saveLink(Request $request, Link $entity)
 {
     $pubdate = $request->get('ls_pubdate');
     $pubdate = new \DateTime($pubdate);
     $entity->setPubdate($pubdate);
     $entity->setPubyear($pubdate->format("Y"));
     $entity->setGuid($request->get('ls_url'));
     $entity->setDescription($request->get('ls_description'));
     $entity->setTitle($request->get('ls_title'));
     $entity->setUrl($request->get('ls_url'));
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $repo = $em->getRepository('FreifunkLinkSinkBundle:Category');
     $result = $repo->findOneBy(array('slug' => $request->get('ls_category')));
     $entity->setCategory($result);
     $entity->setSlug(\URLify::filter($entity->title, 255, 'de'));
     if ($request->get('ls_enclosureurl')) {
         $repo = $em->getRepository('FreifunkLinkSinkBundle:Enclosure');
         $results = $repo->findBy(array('id' => $request->get('ls_enclosureid')));
         if (count($results) > 0) {
             $enclosure = $results[0];
         } else {
             $enclosure = new Enclosure();
         }
         $info = $this->getUrlHeader($request->get('ls_enclosureurl'));
         $enclosure->setUrl($request->get('ls_enclosureurl'));
         if (!is_null($info['download_content_length'])) {
             $enclosure->setLength($info['download_content_length']);
         } else {
             $enclosure->setLength($request->get('ls_enclosurelength'));
         }
         if (!is_null($info['content_type'])) {
             $enclosure->setType($info['content_type']);
         } else {
             if (!is_null($request->get('ls_enclosuretype'))) {
                 $enclosure->setType($request->get('ls_enclosuretype'));
             } else {
                 $enclosure->setType('application/octet-stream');
             }
         }
         $em->persist($enclosure);
         $em->flush();
         $entity->setEnclosure($enclosure);
     }
     $tags = $request->get('ls_tags');
     if (strlen($tags) > 0) {
         $tags = explode(',', $tags);
         $repo = $em->getRepository('FreifunkLinkSinkBundle:Tag');
         $entity->clearTags();
         foreach ($tags as $tag) {
             $tag = trim($tag);
             $results = $repo->findBy(['name' => $tag]);
             if (count($results) > 0) {
                 $entity->addTag($results[0]);
             } else {
                 $tag_obj = new Tag();
                 $tag_obj->setName($tag);
                 $tag_obj->slug = \URLify::filter($tag_obj->getName(), 255, 'de');
                 $em->persist($tag_obj);
                 $em->flush();
                 $entity->addTag($tag_obj);
             }
         }
         return $em;
     }
     return $em;
 }
Ejemplo n.º 17
0
 /**
  * @return void
  */
 public function setUri($uri)
 {
     $this->uri = \URLify::filter($uri);
 }
Ejemplo n.º 18
0
 private function saveCategory(Request $request, Category $entity)
 {
     $entity->setName($request->get('name'));
     $entity->setSlug(\URLify::filter($entity->getName(), 255, 'de'));
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     return $em;
 }
Ejemplo n.º 19
0
Archivo: post.php Proyecto: R-J/elefant
if ($p->published === 'que') {
	if ($p->ts <= gmdate ('Y-m-d H:i:s')) {
		$p->published = 'yes';
		$p->put ();
		Versions::add ($p);
	} else {
	    return $this->error (404, __ ('Post not found'), '<p>' . __ ('Hmm, we can\'t seem to find the post you wanted at the moment.') . '</p>');
	}
}

$page->title = $p->title;

$post = $p->orig ();
$post->full = true;
$post->url = '/blog/post/' . $post->id . '/';
$post->fullurl = $post->url . URLify::filter ($post->title);
$post->tag_list = (strlen ($post->tags) > 0) ? explode (',', $post->tags) : array ();
if (Appconf::blog ('Blog', 'post_format') === 'html') {
	$post->body = $tpl->run_includes ($post->body);
} else {
	require_once ('apps/blog/lib/markdown.php');
	$post->body = $tpl->run_includes (Markdown ($post->body));
}
$post->social_buttons = Appconf::blog ('Social Buttons');
$post->related = Appconf::blog ('Blog', 'show_related_posts');

$footer = Appconf::blog ('Blog', 'post_footer');
$footer_stripped = strip_tags ($footer);
$post->footer = ($footer && ! empty ($footer_stripped))
	? $tpl->run_includes ($footer)
	: false;
Ejemplo n.º 20
0
 public function rescanPagePaths($newPaths)
 {
     $db = Loader::db();
     $txt = Loader::helper('text');
     // First, get the list of page paths from the DB.
     $ppaths = $this->getPagePaths();
     // Second, reset all of their cPath values to null.
     $paths = array();
     foreach ($ppaths as $ppath) {
         if (!$ppath['ppIsCanonical']) {
             $paths[$ppath['ppID']] = null;
         }
     }
     // Third, fill in the cPath values from the user updated data.
     Loader::library('3rdparty/urlify');
     foreach ($newPaths as $key => $val) {
         if (!empty($val)) {
             // Auto-prepend a slash if one is missing.
             $val = trim($val, '/');
             $pathSegments = explode('/', $val);
             $newVal = '/';
             foreach ($pathSegments as $pathSegment) {
                 $newVal .= URLify::filter($pathSegment) . '/';
             }
             $newVal = substr($newVal, 0, strlen($newVal) - 1);
             $newVal = str_replace('-', PAGE_PATH_SEPARATOR, $newVal);
             $paths[$key] = $newVal;
         }
     }
     // Fourth, delete, update, or insert page paths as necessary.
     foreach ($paths as $key => $val) {
         if (empty($val)) {
             $v = array($this->cID, $key);
             $q = "delete from PagePaths where cID = ? and ppID = ?";
         } else {
             if (is_numeric($key)) {
                 $val = $this->uniquifyPagePath($val);
                 $v = array($val, $this->cID, $key);
                 $q = "update PagePaths set cPath = ?, ppIsCanonical = 0 where cID = ? and ppID = ?";
             } else {
                 $val = $this->uniquifyPagePath($val);
                 $v = array($this->cID, $val);
                 $q = "insert into PagePaths (cID, cPath, ppIsCanonical) values (?, ?, 0)";
             }
         }
         $r = $db->query($q, $v);
     }
 }
Ejemplo n.º 21
0
<?php

//Filter the provided argument or stdin if the argument was not present
require_once dirname(__DIR__) . '/URLify.php';
//Print usage and exit if arguments are invalid
if ($argc < 1 || $argc > 2) {
    die("Usage (argument): php " . basename(__FILE__) . " \"<text to filter>\"\nUsage (pipe): <Arbitrary command> | php " . basename(__FILE__) . "\n");
}
//Process the provided argument
if ($argc === 2) {
    $s = $argv[1];
    //Or read from stdin if the argument wasn't present
} else {
    $piped = true;
    $s = file_get_contents("php://stdin");
}
echo URLify::filter($s) . ($piped ? "\n" : "");
 function sanitize_repeat_tab($tabs, $option)
 {
     $results = array();
     if (is_array($tabs)) {
         for ($i = 0; $i < count($tabs); $i++) {
             if (isset($tabs[$i])) {
                 $tab = $tabs[$i];
                 if (!isset($tab['id']) && isset($tab['label'])) {
                     $tab['id'] = URLify::filter($tab['label']);
                 }
                 if (isset($tab['label'])) {
                     $this->register_dynamic_string_for_translation($this->get_option_id_context($option['id']) . ' ' . $tab['label'], $tab['label']);
                 }
                 $results[] = $tab;
             }
         }
     }
     return $results;
 }
<?php

defined('C5_EXECUTE') or die("Access Denied.");
if (Loader::helper('validation/token')->validate('get_url_slug', $_REQUEST['token'])) {
    Loader::library('3rdparty/urlify');
    print URLify::filter($_REQUEST['name']);
}
Ejemplo n.º 24
0
    echo json_encode($res);
    return;
}
$error = false;
$o = new blog\Post($_GET['id']);
if ($o->error) {
    $error = $o->error;
} else {
    foreach ($_POST as $k => $v) {
        if ($k != $o->key && isset($o->data[$k])) {
            $o->{$k} = $v;
        }
    }
    if (!$o->put()) {
        $error = $o->error;
    } else {
        Versions::add($o);
        require_once 'apps/blog/lib/Filters.php';
        $_POST['page'] = 'blog/post/' . $o->id . '/' . URLify::filter($o->title);
        $this->hook('blog/edit', $_POST);
    }
}
$res = new StdClass();
if ($error) {
    $res->success = false;
    $res->error = $error;
} else {
    $res->success = true;
    $res->data = $_GET['id'];
}
echo json_encode($res);
Ejemplo n.º 25
0
<?php

/**
 * Renders the RSS feed for the blog.
 */
$res = $memcache->get('_blog_rss');
if (!$res) {
    require_once 'apps/blog/lib/Filters.php';
    $p = new blog\Post();
    $page->posts = $p->latest(10, 0);
    $page->title = $appconf['Blog']['title'];
    $page->date = gmdate('Y-m-d\\TH:i:s');
    foreach ($page->posts as $k => $post) {
        $page->posts[$k]->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
    }
    $res = $tpl->render('blog/rss', $page);
    $memcache->set('_blog_rss', $res, 1800);
    // half an hour
}
$page->layout = false;
header('Content-Type: text/xml');
echo $res;
Ejemplo n.º 26
0
	/** 
	 * Takes text and returns it in the "lowercase-and-dashed-with-no-punctuation" format
	 * @param string $handle
	 * @param int $maxlength Max number of characters of the return value
	 * @param string $lang Language code of the language rules that should be priorized
	 * @return string $handle
	 */
	public function urlify($handle, $maxlength = PAGE_PATH_SEGMENT_MAX_LENGTH, $lang = LANGUAGE) {
		Loader::library('3rdparty/urlify');
		$handle = URLify::filter($handle, $maxlength, $lang);
		return $handle;
	}
Ejemplo n.º 27
0
$page->num = count($this->params) > 1 && is_numeric($this->params[1]) ? $this->params[1] - 1 : 0;
$page->offset = $page->num * $page->limit;
$p = new blog\Post();
$posts = $p->by($page->author, $page->limit, $page->offset);
$page->count = $p->query()->where('published', 'yes')->where('author', $page->author)->count();
$page->last = $page->offset + count($posts);
$page->more = $page->count > $page->last ? true : false;
$page->next = $page->num + 2;
$footer = Appconf::blog('Blog', 'post_footer');
$footer_stripped = strip_tags($footer);
$footer = $footer && !empty($footer_stripped) ? $tpl->run_includes($footer) : false;
if (Appconf::blog('Blog', 'post_format') === 'markdown') {
    require_once 'apps/blog/lib/markdown.php';
}
foreach ($posts as $post) {
    $post->url = '/blog/post/' . $post->id . '/' . URLify::filter($post->title);
    $post->tag_list = strlen($post->tags) > 0 ? explode(',', $post->tags) : array();
    $post->social_buttons = $appconf['Social Buttons'];
    if (Appconf::blog('Blog', 'post_format') === 'html') {
        $post->body = $tpl->run_includes($post->body);
    } else {
        $post->body = $tpl->run_includes(Markdown($post->body));
    }
    if ($preview_chars) {
        $post->body = blog_filter_truncate($post->body, $preview_chars) . ' <a href="' . $post->url . '">' . __('Read more') . '</a>';
    } else {
        $post->footer = $footer;
    }
    echo $tpl->render('blog/post', $post);
}
$page->title = __('Posts by %s', $tpl->sanitize($page->author));
Ejemplo n.º 28
0
 public function filter($value)
 {
     URLify::$remove_list = array();
     return URLify::filter($value, 60, 'de');
 }
Ejemplo n.º 29
0
/**
 * Modify a string, so that we can use it for slugs. Like
 * safeString, but using hyphens instead of underscores.
 *
 * @param string $str
 * @param string $type
 * @return string
 */
function makeSlug($str)
{
    return \URLify::filter(strip_tags($str));
}
Ejemplo n.º 30
0
	/** 
	 * Takes text and returns it in the "lowercase-and-dashed-with-no-punctuation" format
	 * @param string $handle
	 * @return string $handle
	 */
	public function urlify($handle) {
		Loader::library('3rdparty/urlify');
		$handle = URLify::filter($handle);
		return $handle;
	}