Ejemplo n.º 1
0
 public static function scanTags($inputTags)
 {
     if (!is_array($inputTags)) {
         return false;
     }
     $inputTags = array_unique($inputTags);
     $result = [];
     foreach ($inputTags as $v) {
         if (empty($v)) {
             continue;
         }
         $slug = StringHelper::generateCleanStr($v);
         if (!$slug) {
             continue;
         }
         $model = static::find()->andWhere(['name' => $slug])->one();
         if ($model) {
             $result[] = $model->mid;
         } else {
             $tag = new self();
             $tag->name = $tag->slug = $slug;
             if ($tag->insert(false)) {
                 $result[] = $tag->mid;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 private function slugify($alias)
 {
     if ($this->translit) {
         //return yii\helpers\Inflector::slug( TransliteratorHelper::progress( $alias ), '-', true );
         //return yii\helpers\Inflector::slug( yii\helpers\Inflector::transliterate( $alias ), '-', true );
         return strtolower(StringHelper::translit($alias));
         //Inflector::slug($alias);
         //var_dump($v);
         //return Inflector::slug($alias);
     } else {
         return $this->alias($alias, '-', true);
     }
 }
Ejemplo n.º 3
0
 /**
  * 检测生成缩略名
  * @param $attribute
  * @param $params
  */
 public function checkSlugName($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $name = StringHelper::generateCleanStr($this->{$attribute});
         if ($attribute == 'name' && empty($name) || $attribute == 'slug' && !empty($this->slug) && empty($name)) {
             $this->addError($attribute, $this->getAttributeLabel($attribute) . '全部为非法字符,无法转换');
         }
         if ($attribute == 'slug' && empty($this->slug)) {
             $this->{$attribute} = $this->name;
         } else {
             $this->{$attribute} = $name;
         }
     }
 }
Ejemplo n.º 4
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             $this->created = time();
             $this->slug = \common\helpers\StringHelper::generateCleanStr($this->title) . '-' . sha1(microtime(true));
             $this->title = Html::encode($this->title);
             $this->text = json_encode($this->text);
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['title', 'slug'], 'string', 'max' => 200], [['slug'], 'filter', 'filter' => function ($value) {
         return StringHelper::generateCleanStr($value);
     }], [['slug'], 'unique'], [['title'], 'default', 'value' => function ($model, $attribute) {
         return '未命名文档';
     }], [['title'], 'filter', 'filter' => function ($value) {
         return Html::encode($value);
     }], [['order', 'allowComment', 'allowPing', 'allowFeed'], 'filter', 'filter' => function ($value) {
         return intval($value);
     }], [['status'], 'filter', 'filter' => function ($value) {
         return in_array($value, [self::STATUS_PUBLISH, self::STATUS_HIDDEN]) ? $value : self::STATUS_PUBLISH;
     }], [['created'], 'filter', 'filter' => function ($value) {
         if ($value == '') {
             return time();
         } else {
             return strtotime($value);
         }
     }], [['text'], 'safe']];
 }
Ejemplo n.º 6
0
            <span class="article-date">
                <?php 
echo Yii::$app->formatter->asDatetime($model->created_at);
?>
            </span>,
            <span class="article-category">
                <?php 
echo Html::a($model->category->title, ['index', 'ArticleSearch[category_id]' => $model->category_id]);
?>
            </span>
        </div>
        <div class="article-content">
            <?php 
if ($model->thumbnail_path) {
    ?>
                <?php 
    echo Html::img(Yii::$app->glide->createSignedUrl(['glide/index', 'path' => $model->thumbnail_path, 'w' => 100], true), ['class' => 'article-thumb img-rounded pull-left']);
    ?>
            <?php 
}
?>
            <div class="article-text">
                <?php 
//excerpt 5 lines and filter img
echo StringHelper::Excerpt($model->body, 5, '...', 90, Yii::$app->charset);
?>
            </div>
        </div>
    </div>
</div>
Ejemplo n.º 7
0
 public function checkName($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if ($attribute == 'name' || $attribute == 'screenName' && $this->{$attribute} != '') {
             if (!StringHelper::checkCleanStr($this->{$attribute})) {
                 $this->addError($attribute, $this->getAttributeLabel($attribute) . '只能为数字字母下划线横线');
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @covers common\helpers\StringHelper::camelcase_to_dash
  */
 public function test_camelcase_to_dash()
 {
     self::assertEquals('starter/admin_panel', StringHelper::camelcase_to_dash('Starter/AdminPanel'));
 }
Ejemplo n.º 9
0
 /**
  * @param WidgetsCrud $nextModel
  * @return string
  */
 public function generateWidgetActiveField($nextModel)
 {
     $controllerName = explode(' ', BaseInflector::camel2words(str_replace('Controller', '', StringHelper::basename($this->controllerClass))));
     $controller = '';
     $module = $this->moduleID ? "/{$this->moduleID}" : '';
     foreach ($controllerName as $item) {
         $controller .= (strlen($controller) ? '-' : '') . strtolower($item);
     }
     $nextModel->pathName = $nextModel->pathName ?: '_widgets';
     return str_replace(['{controller}', '{module}'], [$controller, $module], $this->render("views/{$nextModel->pathName}/_{$nextModel->widgetType}Input.php"));
 }