Exemplo n.º 1
0
 public function isMobile($attribute, $params)
 {
     $result = \common\components\Utils::isMobile($this->{$attribute});
     if (!$result) {
         $this->addError($attribute, '手机号码格式错误');
     }
 }
Exemplo n.º 2
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         if (\common\components\Utils::isEmail($this->username)) {
             $this->_user = User::findByEmail($this->username);
         } else {
             $this->_user = User::findByUsername($this->username);
         }
     }
     //var_dump($this->_user);//die;
     return $this->_user;
 }
Exemplo n.º 3
0
 public function upload()
 {
     //parent::beforeSave($insert);
     if ($this->imageFile && $this->validate()) {
         $Name = \common\components\Utils::fileName(5);
         $fileName = 'upload/pics/' . $Name . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs(Yii::getAlias("@wwwdir") . "/" . $fileName);
         $str = "/" . $fileName;
     } else {
         $str = 'pic error';
     }
     $this->thumb = $str;
     $this->imageFile = null;
 }
Exemplo n.º 4
0
 public function init()
 {
     parent::init();
     $this->upload = $this->upload . '/' . date('Ym');
     $this->uploadDir = Yii::getAlias('@wwwdir/' . $this->upload . '/');
     $this->newFileName = \common\components\Utils::fileName(5);
     if (!file_exists($this->uploadDir)) {
         FileHelper::createDirectory($this->uploadDir);
     }
     $this->uploadSrc = Yii::getAlias('/' . $this->upload . '/');
     if (!isset($this->afterUploadHandler)) {
         $this->afterUploadHandler = [$this, 'afterUpload'];
     }
 }
Exemplo n.º 5
0
 public function run()
 {
     $file = UploadedFile::getInstanceByName($this->fileName);
     if ($file->hasError) {
         throw new HttpException(500, 'Upload error');
     }
     $this->upload = $this->upload . '/' . date('Ym');
     $this->uploadDir = Yii::getAlias('@wwwdir/' . $this->upload . '/');
     $newFileName = \common\components\Utils::fileName(5);
     if (!file_exists($this->uploadDir)) {
         FileHelper::createDirectory($this->uploadDir);
     }
     $fileName = $newFileName . "." . $file->extension;
     if (file_exists($this->uploadDir . $fileName)) {
         $fileName = $newFileName . '-' . uniqid() . '.' . $file->extension;
     }
     $result = $file->saveAs($this->uploadDir . $fileName);
     $response['status'] = 0;
     if ($result) {
         //上传成功";写入数据库
         $item = Yii::$app->request->post('item');
         $item_id = Yii::$app->request->post('item_id');
         $image = new Images();
         $image->item = $item;
         $image->item_id = $item_id;
         $image->filename = $fileName;
         $image->image = "/" . $this->upload . "/" . $fileName;
         $image->filename = $fileName;
         $image->sort_order = 50;
         $n = $image->save();
         if ($n) {
             //$image->
             $response['status'] = 1;
             $response['imgID'] = $image->id;
             $response['filePath'] = "/" . $this->upload . "/" . $fileName;
             $response['initialPreview'] = ["<img src='" . $response['filePath'] . "' class='file-preview-image'>"];
             $response['initialPreviewConfig'] = [['caption' => $fileName, 'width' => "120px;", 'url' => Yii::$app->urlManager->createUrl(['services/remove']), 'key' => $image->id, 'description' => "", 'sort_order' => ""]];
         }
     }
     return Json::encode($response);
 }
Exemplo n.º 6
0
foreach ($models as $k => $v) {
    ?>
            <li>
                <div class="zxzx-zt">
                    <div class="zxzx-zt-tit"><a href="<?php 
    echo Yii::$app->urlManager->createUrl(['news/show', 'id' => $v->id]);
    ?>
"><?php 
    echo $v->title;
    ?>
</a></div>
                    <div class="zxzx-zt-fb"><span class="ly"><?php 
    echo $v->author;
    ?>
</span><span class="gs">宇斌造价</span><span class="sj"><?php 
    echo \common\components\Utils::dateFormat($v->created_at, 0);
    ?>
</span><span class="ll"><?php 
    echo $v->views;
    ?>
</span></div>
                    <div class="zxzx-zt-nr">
                        <a href="<?php 
    echo Yii::$app->urlManager->createUrl(['news/show', 'id' => $v->id]);
    ?>
"><?php 
    echo $v->intro;
    ?>
</a>
                    </div>
                </div>
Exemplo n.º 7
0
    public function run()
    {
        $image_posX = 0;
        $image_posY = 0;
        /* $scale=2;
           $image_real_width=$this->place_width*$scale;
           $image_real_height=$this->place_height*$scale;*/
        $img_path = UserUrl::photobookTexts(false, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        $img_url = UserUrl::photobookTexts(true, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        $img_path = UserUrl::photobookTexts(false, $this->photobook_id, $this->user_id) . '/' . UserUrl::imageFile($this->photo_id, $this->image_size, 'png');
        if (!file_exists($img_path) || $this->update_img) {
            $place_width = $this->place_width;
            $place_height = $this->place_height;
            /* $resize_val=UserUrl::$IMAGE_SIZE[$this->image_size]['size'];
                           $w=Utils::pxToMm(Utils::mmToPx($place_width, 300)/$resize_val, 300);
                           $h=Utils::pxToMm(Utils::mmToPx($place_height, 300)/$resize_val, 300);
            
            
                        echo  $w;
                        echo $h;
                        die();*/
            $image_data = Utils::makeTextImage($this->text_label, $place_width, $place_height, $this->text_color, $this->font, $this->margin);
            file_put_contents($img_path, $image_data);
        }
        $size = getimagesize($img_path);
        //$img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);
        $image_real_width = $size[0];
        $image_real_height = $size[1];
        $thumb_width = $this->place_width;
        $thumb_height = $this->place_height;
        $width = $image_real_width;
        $height = $image_real_height;
        $original_aspect = $width / $height;
        $thumb_aspect = $thumb_width / $thumb_height;
        if ($original_aspect >= $thumb_aspect) {
            $new_height = $thumb_height;
            $new_width = $width / ($height / $thumb_height);
        } else {
            // If the thumbnail is wider than the image
            $new_width = $thumb_width;
            $new_height = $height / ($width / $thumb_width);
        }
        $image_posX = 0 - ($new_width - $thumb_width) / 2;
        $image_posY = 0 - ($new_height - $thumb_height) / 2;
        $image_real_width = $new_width;
        $image_real_height = $new_height;
        $uid = rand(1, 99999999999999999);
        $lastModified = filemtime($img_path);
        if ($this->view == 'svg') {
            // <path fill="#999999" fill-opacity="1" clip-path="url(#clip-path-{uid})" d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
            $content = '<g xmlns:xlink="http://www.w3.org/1999/xlink"  class="placeholder text"  transform="translate(-{w2}, -{h2})" width="{width}" height="{height}" clip-path="url(#clip-path-{uid})" >
                        <defs>
                            <clipPath id="clip-path-{uid}">
                                <path d="M 0 0 h {width}  v {height}  h -{width}  v -{height}  z"/>
                            </clipPath>
                        </defs>



                        <g >
                            <g transform="translate({img_pos_x},{img_pos_y}) scale(1,1)" width="{width}" height="{height}" pointer-events="none">
                                <image width="{image_real_width}" height="{image_real_height}" xlink:href="{img_url}"/>
                            </g>
                        </g>

                    </g>';
            $img_url = $img_url . '?v=' . $lastModified;
            if ($this->image_size == UserUrl::IMAGE_THUMB || $this->image_size == UserUrl::IMAGE_SMALL) {
                // $img_path=UserUrl::photobookPhotos(false, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, UserUrl::IMAGE_SMALL);
                $imageData = base64_encode(file_get_contents($img_path));
                $img_url = 'data:image/jpeg' . ';base64,' . $imageData;
            } else {
                if ($this->image_size == UserUrl::IMAGE_ORIGINAL) {
                    $imageData = base64_encode(file_get_contents($img_path));
                    $img_url = 'data:image/jpeg' . ';base64,' . $imageData;
                    //$img_url='http://'.$_SERVER['HTTP_HOST'].UserUrl::photobookPhotos(true, $this->photobook_id, $this->user_id).'/'.UserUrl::imageFile($this->photo_id, $this->image_size);;
                }
            }
            echo Yii::t('app', $content, ['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'img_url' => $img_url, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY]);
        } else {
            if ($this->view == 'json') {
                echo json_encode(['width' => $this->place_width, 'height' => $this->place_height, 'uid' => $uid, 'object_text' => true, 'image_width' => $this->image_width, 'image_height' => $this->image_height, 'image_real_width' => $image_real_width, 'image_real_height' => $image_real_height, 'first_image_real_width' => $image_real_width, 'first_image_real_height' => $image_real_height, 'img_url' => $img_url . '?v=' . $lastModified, 'photo_id' => $this->photo_id, 'w2' => $this->place_width / 2, 'h2' => $this->place_height / 2, 'img_pos_x' => $image_posX, 'img_pos_y' => $image_posY, 'last_modified' => $lastModified]);
            }
        }
    }
Exemplo n.º 8
0
 public function addText($text)
 {
     $group = 'Текст';
     if (empty($this->photos[$group])) {
         $this->photos[$group] = [];
     }
     //нужно сгенерить фотку из текста
     $style = Style::findOne(['id' => $this->style_id]);
     if (empty($style)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль для фотокниги не найден')]];
     }
     $font = Font::findOne(['id' => $style->font_id]);
     if (empty($font)) {
         return ['error' => ['msg' => Yii::t('app', 'Шрифт для фотокниги не найден')]];
     }
     $font_path = UserUrl::font(false) . DIRECTORY_SEPARATOR . UserUrl::fontFile($font->file);
     if (!file_exists($font_path)) {
         return ['error' => ['msg' => Yii::t('app', 'Файл шрифта не найден.')]];
     }
     $place_width = 350;
     $place_height = 350;
     $text_color = '#000000';
     //Ставим черный нужно брать из стиля но пока нет поля
     $image_data = Utils::makeTextImage($text, $place_width, $place_height, $text_color, $font_path, 5);
     $text_photo_id = AlphaId::id(rand(10000000000, 9999999999999));
     $text_photo_path = UserUrl::photobookPhotos(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($text_photo_id, UserUrl::IMAGE_ORIGINAL, 'png');
     file_put_contents($text_photo_path, $image_data);
     foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
         if ($key != UserUrl::IMAGE_ORIGINAL) {
             $image = Yii::$app->image->load($text_photo_path);
             $type = Yii\image\drivers\Image::HEIGHT;
             if ($size['width'] > 0 && $size['height'] > 0) {
                 $type = Yii\image\drivers\Image::AUTO;
             }
             if ($size['width'] > 0 && $size['height'] == 0) {
                 $type = Yii\image\drivers\Image::WIDTH;
             }
             $file_resize_path = UserUrl::photobookPhotos(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($text_photo_id, $key, 'png');
             $image->resize($size['width'], $size['height'], $type);
             $image->save($file_resize_path);
             //$paths[]=$file_resize_path;
         }
     }
     if (empty($this->photos[$group]['photos'])) {
         $this->photos[$group]['photos'] = [];
     }
     if (empty($this->photos[$group]['texts'])) {
         $this->photos[$group]['texts'] = [];
     }
     $this->photos[$group]['photos'][] = $text_photo_id;
     $this->photos[$group]['texts'][$text_photo_id] = ['photo_id' => $text_photo_id, 'place_width' => $place_width, 'place_height' => $place_height, 'text_color' => $text_color, 'font_file' => $font->file, 'font_id' => $font->id, 'text' => $text];
     if ($this->save()) {
         $current_photo = ThumbInGroup::widget(['photobook_id' => $this->id, 'photo_id' => $text_photo_id, 'user_id' => $this->user_id]);
         return ['response' => ['status' => true, 'photos' => $this->photos, 'current_photo' => $current_photo, 'photo_id' => $text_photo_id]];
         //return ['response'=>['status'=>true, 'page'=>$this->data['pages'][$page_index]]];
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу-данных')]];
     }
 }
Exemplo n.º 9
0
echo Yii::$app->urlManager->createUrl(['news/index', 'cid' => 57]);
?>
">更多</a></span>学员通知</div>	
            <ul class="xytz-nr">
                <?php 
$xueyuantongzhi = \common\models\News::getNews(57, 8);
?>
                <?php 
if ($xueyuantongzhi) {
    foreach ($xueyuantongzhi as $k => $v) {
        ?>
                <li><a href="<?php 
        echo Yii::$app->urlManager->createUrl(['news/show', 'id' => $v->id]);
        ?>
"><?php 
        echo \common\components\Utils::cutStr($v->title, 42);
        ?>
</a></li> 
                <?php 
    }
} else {
    ?>
                <li>暂无内容,请从后台添加</li> 
                <?php 
}
?>
            </ul>
        </div>
        
        <div class="third-right f-l">
            <div class="wlst-tit lm-tb"><span><a href="<?php 
 public function bootstrap($app)
 {
     $url = "http://media." . Utils::url_to_domain($_SERVER['SERVER_NAME']);
     Yii::setAlias("media", $url);
 }
Exemplo n.º 11
0
 public function actionDownloadLayouts()
 {
     $this->layout = 'json';
     $ref = Yii::$app->request->get('ref');
     $id = Yii::$app->request->get('id');
     $cmds = [];
     if (!empty($ref) && !empty($id)) {
         $model = new PhotobookForm();
         $user_id = AlphaId::id($ref, true);
         $pb_id = AlphaId::id($id, true);
         // Yii::getLogger()->log('post:'.print_r(Yii::$app->request->post(), true), YII_DEBUG);
         if ($model->loadById($pb_id)) {
             $pages = $model->data['pages'];
             $path_layouts = [];
             foreach ($pages as $key => $page) {
                 if ($page['action'] == 'print') {
                     $svg = $model->getPageSvgWithOriginalPhotos($page);
                     $svg_path = UserUrl::photobookLayouts(false, $pb_id, $user_id) . DIRECTORY_SEPARATOR . 'layout_' . (intval($key) + 1) . '.svg';
                     $jpg_path = UserUrl::photobookLayouts(false, $pb_id, $user_id) . DIRECTORY_SEPARATOR . 'layout_' . (intval($key) + 1) . '.jpg';
                     $svg = str_replace('fill: transparent;', 'fill-opacity:0;', $svg);
                     file_put_contents($svg_path, $svg);
                     unset($svg);
                     /* $image = new \Imagick();
                        $image->readImageBlob($svg);
                        $image->setImageFormat("jpeg");
                        $image->setImageCompressionQuality(100);
                        $image->resizeImage(8571, 4286, \imagick::FILTER_LANCZOS, 1);
                        $image->writeImage(UserUrl::photobookLayouts(false, $pb_id, $user_id).DIRECTORY_SEPARATOR.'layout_'.$key.'.jpg');*/
                     /*
                      * java -jar batik-rasterizer.jar -w 9000 -h 4500 -q 0.99 -dpi 300 layout_0.svg
                      */
                     $batik_path = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'batik' . DIRECTORY_SEPARATOR;
                     $cmds[] = "java -d64 -Xms512m -Xmx4g -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpeg -w 8572 -h 4286 -q 0.99 -dpi 300 -d " . $jpg_path . " " . $svg_path;
                     exec("java -d64 -Xms512m -Xmx4g -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpeg -w 8572 -h 4286 -q 0.99 -dpi 300 -d " . $jpg_path . " " . $svg_path);
                     if (file_exists($svg_path)) {
                         unlink($svg_path);
                     }
                     if (file_exists($jpg_path)) {
                         $path_layouts[] = $jpg_path;
                     }
                 }
             }
             $zip_file_path = UserUrl::photobookLayouts(false, $pb_id, $user_id) . DIRECTORY_SEPARATOR . 'layouts_' . $pb_id . '.zip';
             $zip_file_url = UserUrl::photobookLayouts(true, $pb_id, $user_id) . '/' . 'layouts_' . $pb_id . '.zip';
             if (Utils::create_zip($path_layouts, $zip_file_path, true, '.jpg')) {
                 foreach ($path_layouts as $key => $path_layout) {
                     unlink($path_layout);
                 }
             }
             $batik_path = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'batik' . DIRECTORY_SEPARATOR;
             $result = ['response' => ['status' => true, 'batik_path' => $batik_path, 'url' => $zip_file_url, 'cmds' => $cmds]];
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
         }
     } else {
         $result = ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
     }
     return $this->render('json', ['result' => $result]);
 }
Exemplo n.º 12
0
$this->title = $model->title;
$breadcrumbs = Category::getBreadcrumbs($model->category_id, "news/index", "cid");
$this->params['breadcrumbs'] = $breadcrumbs;
?>
<div class="container ">
	<div class="container-left f-l">
      <?php 
echo $this->render('/layouts/_breadcrumbs');
?>
      <div class="detail-nr m-t-20">
          <div class="xq-bt"><?php 
echo $model->title;
?>
</div>
          <div class="time"><span>时间: <?php 
echo \common\components\Utils::dateFormat($model->created_at, 4);
?>
</span><span>来源:<?php 
echo $model->author ? $model->author : '管理员';
?>
</span><span>阅读数:<?php 
echo $model->views;
?>
人</span></div>
            <div class="nr-hg">
            	<?php 
echo $model->content;
?>

            </div>
            <div class="xian m-t-20"></div>
Exemplo n.º 13
0
            ?>

                                                        <?php 
            echo Utils::timeAgo($order->change_status_at);
            ?>

                                                    <?php 
        } elseif ($order->status == Photobook::STATUS_RECEIVED_FEEDBACK) {
            ?>

                                                        <?php 
            echo Yii::t('app', 'Получен');
            ?>

                                                        <?php 
            echo Utils::timeAgo($order->change_status_at);
            ?>

                                                    <?php 
        } elseif ($order->status == Photobook::STATUS_ARCHIVE) {
            ?>


                                                        <?php 
            echo Yii::t('app', 'Архив');
            ?>

                                                    <?php 
        }
        ?>
Exemplo n.º 14
0
 public static function timeAgo($time)
 {
     $current_time = time();
     $diff = $current_time - $time;
     $sec = $diff;
     $min = intval($diff / 60);
     $hour = intval($diff / 60 / 60);
     $day = intval($diff / 60 / 60 / 24);
     $month = intval($diff / 60 / 60 / 24 / 31);
     $year = intval($diff / 60 / 60 / 24 / 31 / 12);
     if ($sec < 60) {
         return Yii::t('app', '{num} {unit} назад', ['num' => $sec, 'unit' => Utils::getInclinationByNumber($sec, ['сукунда', 'сукунды', 'сукунд'])]);
     } else {
         if ($min < 60) {
             return Yii::t('app', '{num} {unit} назад', ['num' => $min, 'unit' => Utils::getInclinationByNumber($min, ['минута', 'минуты', 'минут'])]);
         } else {
             if ($hour < 24) {
                 return Yii::t('app', '{num} {unit} назад', ['num' => $hour, 'unit' => Utils::getInclinationByNumber($hour, ['час', 'часа', 'часов'])]);
             } else {
                 if ($day < 31) {
                     return Yii::t('app', '{num} {unit} назад', ['num' => $day, 'unit' => Utils::getInclinationByNumber($day, ['день', 'дня', 'дней'])]);
                 } else {
                     if ($month < 12) {
                         return Yii::t('app', '{num} {unit} назад', ['num' => $month, 'unit' => Utils::getInclinationByNumber($month, ['месяц', 'месяца', 'месяцев'])]);
                     } else {
                         return Yii::t('app', '{num} {unit} назад', ['num' => $year, 'unit' => Utils::getInclinationByNumber($year, ['год', 'года', 'лет'])]);
                     }
                 }
             }
         }
     }
 }