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]]); }
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); }
/** * */ 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()); } } } }