コード例 #1
0
ファイル: ArticlesController.php プロジェクト: roman1970/lis
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $uploadFile = new UploadForm();
     $uploadImg = new UploadForm();
     if (Yii::$app->request->isPost) {
         $uploadFile->file = UploadedFile::getInstance($uploadFile, 'file');
         $uploadImg->img = UploadedFile::getInstance($uploadImg, 'img');
         if ($uploadFile->file && $uploadFile->validate()) {
             $uploadFile->file->saveAs('uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension);
         } elseif ($uploadImg->img && $uploadImg->validate()) {
             $uploadImg->img->saveAs('uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension);
         } else {
             print_r($uploadFile->getErrors());
         }
     }
     //var_dump($uploadImg); exit;
     if ($model->load(Yii::$app->request->post())) {
         $model->text = Yii::$app->request->post('Articles')['text'];
         $model->title = Yii::$app->request->post('Articles')['title'];
         $model->alias = TranslateHelper::translit(Yii::$app->request->post('Articles')['title']);
         $model->site_id = Yii::$app->request->post('Articles')['site_id'];
         $model->cat_id = Yii::$app->request->post('Articles')['cat_id'];
         if (Yii::$app->request->post('Articles')['redactor']) {
             $model->redactor = 1;
         } else {
             $model->redactor = 0;
         }
         if (isset(Yii::$app->request->post('Articles')['source_id'])) {
             $model->source_id = Yii::$app->request->post('Articles')['source_id'];
         } else {
             $model->source_id = 2;
         }
         if (isset($uploadFile->file)) {
             $model->audio = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadFile->file->baseName) . '.' . $uploadFile->file->extension;
         }
         if (isset($uploadImg->img)) {
             $model->img = Url::base() . 'uploads/' . Yii::$app->translater->translit($uploadImg->img->baseName) . '.' . $uploadImg->img->extension;
         }
         $model->save(false);
         return $this->redirect(Url::toRoute('articles/index'));
     } else {
         return $this->render('_form', ['model' => $model, 'uploadFile' => $uploadFile, 'uploadImg' => $uploadImg]);
     }
 }
コード例 #2
0
ファイル: ParsersController.php プロジェクト: roman1970/lis
 /**
  * Генерирует страницу с музыкой
  */
 public function actionMusicDirGenerator()
 {
     $music = fopen("/home/romanych/www/vrs/music.html", "w");
     fwrite($music, self::$header);
     $authors = Author::find()->where(['status' => 1])->all();
     foreach ($authors as $author) {
         //var_dump($author->name);
         $alboms = Source::find()->where(['author_id' => $author->id])->all();
         $author_file = fopen("/home/romanych/www/vrs/music/" . TranslateHelper::translit($author->name) . ".html", "w");
         fwrite($author_file, '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                         <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
                         <style>.item_head{font-weight: bold;} body{padding-left: 20px; padding-top: 20px;} </style>');
         foreach ($alboms as $albom) {
             $songs = Items::find()->where(['source_id' => $albom->id])->all();
             $songs_list = fopen("/home/romanych/www/vrs/music/" . TranslateHelper::translit($albom->title) . ".html", "w");
             fwrite($songs_list, '<html><head>
                         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                         <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
                         <link href="/css/audio.css" rel="stylesheet" type="text/css" />
                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
                         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
                         <script type="text/javascript" src="/js/js-jquery-ui-1.8.21.custom.min.js"></script>
                         <script>
                         var songs = [');
             foreach ($songs as $song) {
                 fwrite($songs_list, "{url:'{$song->audio_link}', name: '{$author->name} - {$albom->title} - {$song->title}'},");
             }
             fwrite($songs_list, '];
                         </script>
                         <script type="text/javascript" src="/js/audio.js"></script>
                         </head>
                         <body>
                         <div>
                         <style>.item_head{font-weight: bold;} body{padding-left: 20px; padding-top: 20px;} </style>
                         <div id="audioPlayer" style="cursor: pointer">
                             <a onclick="playSound()">
                                 <p>Воспроизвести весь альбом</p>
                             </a>
                         </div>
                         <div id="currSong">
                         </div>
                      ');
             $r = 1;
             foreach ($songs as $song) {
                 fwrite($songs_list, "<p class='item_head'>{$r} {$song->title} ({$author->name} - {$albom->title})</p>\n                    <audio controls>\n                        <source src='" . $song->audio_link . "'>\n                    </audio>\n                    " . nl2br("<p>{$song->text}</p>") . "\n\n                    ");
                 $r++;
             }
             fwrite($songs_list, self::$footer);
             fclose($songs_list);
             fwrite($author_file, "<a href='" . TranslateHelper::translit($albom->title) . ".html'><button type='button' class='btn btn-default btn-lg'> {$albom->title} </button></a>");
         }
         fwrite($author_file, self::$footer);
         fclose($author_file);
         fwrite($music, "<a href='music/" . TranslateHelper::translit($author->name) . ".html'><button type='button' class='btn btn-default btn-lg'> {$author->name} </button></a>");
     }
     fwrite($music, self::$footer);
     fclose($music);
 }