39 lines
845 B
PHP
39 lines
845 B
PHP
<?php
|
|
class Model_Post extends RedBean_SimpleModel
|
|
{
|
|
public static function validateSafety($safety)
|
|
{
|
|
$safety = intval($safety);
|
|
|
|
if (!in_array($safety, PostSafety::getAll()))
|
|
throw new SimpleException('Invalid safety type "' . $safety . '"');
|
|
|
|
return $safety;
|
|
}
|
|
|
|
public static function validateTag($tag)
|
|
{
|
|
$tag = trim($tag);
|
|
|
|
if (!preg_match('/^[a-zA-Z0-9_-]+$/i', $tag))
|
|
throw new SimpleException('Invalid tag "' . $tag . '"');
|
|
|
|
return $tag;
|
|
}
|
|
|
|
public static function validateTags($tags)
|
|
{
|
|
$tags = trim($tags);
|
|
$tags = preg_split('/[,;\s]+/', $tags);
|
|
$tags = array_filter($tags, function($x) { return $x != ''; });
|
|
$tags = array_unique($tags);
|
|
|
|
foreach ($tags as $key => $tag)
|
|
$tags[$key] = self::validateTag($tag);
|
|
|
|
if (empty($tags))
|
|
throw new SimpleException('No tags set');
|
|
|
|
return $tags;
|
|
}
|
|
}
|