Exemplo n.º 1
0
 /**
  * 演讲更改
  * @param  int $id 演讲id
  * @param array $_POST[]  更改数据
  * @return 
  */
 public function actionUpdate($id)
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $model = Speech::findOne($id);
     if ($model !== null) {
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $model->speech_date = strtotime($model->speech_date);
             //封面图片修改
             $maxSize = 1024 * 1024 * 1024;
             $web = Yii::getAlias("@frontend/web/");
             if ($re = Yii::$app->Picture->uploads('photo', $maxSize)) {
                 $oldImg = $web . $model->photo . ".jpg";
                 file_exists($oldImg) && unlink($oldImg);
                 $model->photo = $re;
             }
             //图片修改
             if ($re = Yii::$app->Picture->uploads('photo_url', $maxSize)) {
                 $oldImg = $web . $model->photo_url . ".jpg";
                 file_exists($oldImg) && unlink($oldImg);
                 $model->photo_url = $re;
             }
             $model->update_time = time();
             $model->save();
             $this->redirect(['index']);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * 将演讲集迁移到新的资讯里面
  *
  * @return void
  * @author 
  **/
 public function actionIndex()
 {
     echo "========== start processing ==========\n\n";
     $i = 1;
     $info = Speech::find()->where(['is_del' => 0])->all();
     foreach ($info as $speech) {
         preg_match('/[\\w][\\w-]*\\.(?:com\\.cn|com|cn|co|net|org|gov|cc|biz|info)/isU', $speech->video_url, $match);
         if (isset($match[0]) && $match[0] == 'youku.com' && strlen($speech->video_url) > 5) {
             // if (file_exists($src_file = Yii::getAlias("@frontend/web/{$speech->photo_url}"))) {
             // 复制图片
             $ext = '.jpg';
             if (strlen($speech->photo_url) > 0) {
                 $src_file = Yii::getAlias("@frontend/web/{$speech->photo_url}{$ext}");
                 $new_file = 'speech' . substr($speech->photo_url, strpos($speech->photo_url, '/'));
                 $dist_file = Yii::getAlias("@frontend/web/source/{$new_file}{$ext}");
                 if (!is_dir(dirname($dist_file))) {
                     mkdir(dirname($dist_file), 0777, true);
                 }
                 $copied = @copy($src_file, $dist_file);
             }
             // 写入数据
             $post = Post::findOne(['migrate_id' => md5($speech->id)]);
             if (!$post) {
                 $post_model = new Post();
                 $post_model->news_title = $speech->title;
                 $post_model->news_type = 'news_video';
                 $post_model->news_des = $speech->short_intro;
                 $post_model->news_content = empty($speech->detailed_intro) ? ' ' : $speech->detailed_intro;
                 $post_model->news_author = $speech->author;
                 $post_model->news_cover_url = $new_file;
                 $post_model->news_video_url = $speech->video_url;
                 $post_model->news_active = 0;
                 $post_model->migrate_id = md5($speech->id);
                 $saved = $post_model->save();
                 // Msg
                 $saved_msg = $saved ? '成功' : '失败';
                 $copied_msg = $copied ? '成功' : '失败';
                 echo "Process_{$i}: {$src_file} -> {$dist_file} 复制{$copied_msg} \n";
                 echo "{$src_file} -> {$dist_file} 迁移{$saved_msg} \n";
                 $i++;
             }
         }
     }
     echo "Process Over\n";
 }
Exemplo n.º 3
0
 /**
  * 演讲集管理
  */
 public function actionSpeech()
 {
     //菜单权限检测
     Yii::$app->util->adminAuth() ? '' : $this->redirect('/admin/login');
     $options = Yii::$app->request->get();
     $orderMapping = ['0' => '默认', '1' => '最新更新'];
     $options['page'] = isset($options['page']) ? intval($options['page']) : 1;
     $options['order'] = isset($options['order']) ? intval($options['order']) : 0;
     $options['order'] = in_array($options['order'], array_keys($orderMapping)) ? $options['order'] : 0;
     $options['title'] = isset($options['title']) ? urldecode($options['title']) : '';
     $mSpeech = new Speech();
     $speech = $mSpeech->search($options);
     $pages = new Pagination(['totalCount' => $speech->count(), 'pageSize' => Speech::PAGE_SIZE]);
     //推送演讲集数据
     $mPageCustomBlock = new PageCustomBlock();
     $data = $mPageCustomBlock->block(['customId' => 'main_page_speeches']);
     $speeches = $speech->asArray()->all();
     return $this->render('speech', ['speeches' => $speeches, 'pages' => $pages, 'options' => $options, 'data' => $data]);
 }