Beispiel #1
0
 public static function getRecentTorrentDataProvider()
 {
     $query = Torrent::find();
     $query->with('scrapes');
     $query->where(['visible_status' => [0, 3]]);
     $query->addOrderBy(['id' => SORT_DESC]);
     $cmd = $query->createCommand();
     return new RecentTorrentsActiveDataProvider(['query' => $query, 'db' => Yii::$app->db, 'sort' => false, 'pagination' => ['pageSize' => 35]]);
 }
Beispiel #2
0
 public function beforeAction($action)
 {
     $query = Yii::$app->request->getQueryParam('q');
     $queryLength = mb_strlen($query, 'UTF-8');
     if (40 == $queryLength && preg_match('#^[0-9a-f]{40}$#i', $query)) {
         if ($torrent = Torrent::find()->where(['hash' => $query])->one()) {
             $action->controller->redirect($torrent->getUrl());
         }
     }
     return parent::beforeAction($action);
 }
Beispiel #3
0
 /**
  *
  */
 public function actionDownload($id, $name, $hash)
 {
     if ($id && ($model = Torrent::find()->where(['hash' => $hash])->one())) {
         if (urlencode($model->name) == $name) {
             if ($model->torrentFileIsLocal()) {
                 header('Content-Description: File Transfer');
                 header('Content-Type: application/octet-stream');
                 header('Content-Disposition: attachment; filename=' . $model->name . '.torrent');
                 header('Pragma: public');
                 header('Content-Length: ' . filesize($model->getFilePath()));
                 readfile($model->getFilePath());
             } else {
                 $this->redirect($model->getDownloadLink());
             }
         }
     }
 }