public function photosCart(Photos $photos, PhotoCategory $photoCategory, Request $request, $slug) { $photoCat = $photoCategory->getId($slug); // категорії $photoCatId = $photoCat->id; $this->data['photos'] = $photoCategory->getId($slug); $this->data['photosCart'] = $photos->getActive($photoCatId); // всі фото if ($request->ajax()) { return response()->json(view('photos.ajaxPaginate.PhotosCart', $this->data)->render()); } return view('photos.photosCart', $this->data); }
/** * get all items of a user or all uploaded latest */ public function getItems($id = null) { $total = []; $query = Photos::find()->where('FIND_IN_SET(:id,shared_with)', [':id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC]); if ($id != null) { $models = Photos::find()->where(['user_id' => $id])->orderBy(['id' => SORT_DESC])->all(); } else { if (Yii::$app->controller->action->id == 'index') { $models = $query->orWhere(['user_id' => Yii::$app->user->id])->all(); } elseif (Yii::$app->controller->action->id == 'dashboard') { $models = Photos::find()->where('FIND_IN_SET(:id,shared_with)', [':id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->all(); } } foreach ($models as $k => $model) { if (Yii::$app->find->isShared(Yii::$app->user->id, $model->shared_with) == false && Yii::$app->user->id != $model->user_id) { continue; } //var_dump(Yii::$app->controller->action->id); die(); if (Yii::$app->controller->action->id != 'view') { if ($k > 30) { break; } } //var_dump($model->shared_with); $items = ['url' => $model->src, 'src' => '@web/uploads/albums/thumbs/' . $model->filename, 'options' => array('title' => 'By ' . $model->user->fullname)]; array_push($total, $items); } return $total; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photos::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'event_id' => $this->event_id]); $query->andFilterWhere(['like', 'photo_path', $this->photo_path]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Photos::find()->where(['user_id' => Yii::$app->user->id]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'filename', $this->filename])->andFilterWhere(['like', 'shared_with', $this->shared_with]); return $dataProvider; }
<?php if ($model->photos) { ?> <div id="carousel-example-generic<?php echo $model->id; ?> " class="carousel slide" data-ride="carousel"> <div class='carousel-inner setted-height'> <?php $count = 0; if ($model->photos) { $i = $j = 0; foreach (array_reverse($model->photos) as $photo) { ?> <?php if (\app\models\Photos::isShared(Yii::$app->user->id, $photo->shared_with) == false && Yii::$app->user->id != $photo->user_id) { $count++; continue; } if ($j++ > 6) { break; } $i++; ?> <div class="item <?php echo $i == 1 ? 'active' : ''; ?> "> <img src="<?php echo Url::to($photo->src); ?>
public function actionView($id) { $photos = Photos::findAll(['album_id' => $id]); return $this->render('view', compact('photos')); }
/** * @inheritdoc * @return Result parsing group. */ public static function parseAllSources() { $query = Sources::find(); $sources = $query->active()->all(); $i = 0; foreach ($sources as $source) { if ($source->ownerId) { $param['ownerId'] = $source->ownerId; } else { $param['ownerId'] = NULL; } $results = Yii::$app->vkApi->createRequest()->setUrl('wall.get')->setData(['owner_id' => $param['ownerId'], 'domain' => $source->domain, 'offset' => $source->postOffset, 'count' => $source->postCount, 'filter' => 'owner'])->send(); if ($results->isOk) { $responses = $results->data['response']; foreach ($responses as $response) { if (is_array($response)) { $post = new Posts(); $post->recordId = $response['id']; $post->sources_id = $source->id; $prepare_content = preg_replace("/([^&]#[a-zA-zа-яА-я0-9]*)/", "", stripcslashes($response['text'])); $prepare_content = preg_replace("/\\[(.+?)\\]/", "", $prepare_content); $post->content = $prepare_content; $title = mb_substr($post->content, 0, mb_stripos($post->content, "<br")); if (!$title) { $title = $post->content; } $post->title = $title ? $title : NULL; $post->slug = Inflector::slug($post->title); if ($response['post_type'] != 'post') { break; } try { if ($post->save()) { foreach ($response['attachments'] as $attachment) { if ($attachment['type'] == 'photo') { $photo = new Photos(); $photo->id_posts = $post->id; $photo->text = $attachment['photo']['text']; if (isset($attachment['photo']['src'])) { $photo->link = $attachment['photo']['src']; } if (isset($attachment['photo']['src_small'])) { $photo->link = $attachment['photo']['src_small']; } if (isset($attachment['photo']['src_big'])) { $photo->link = $attachment['photo']['src_big']; } if (isset($attachment['photo']['src_xbig'])) { $photo->link = $attachment['photo']['src_xbig']; } if (isset($attachment['photo']['src_xxbig'])) { $photo->link = $attachment['photo']['src_xxbig']; } if (isset($attachment['photo']['src_xxxbig'])) { $photo->link = $attachment['photo']['src_xxxbig']; } $photo->save(); } else { $post->delete(); $i--; } } $i++; } $post->slug = $post->id . "-" . $post->slug; $post->save(); } catch (yii\db\IntegrityException $e) { //nothing } } } } sleep(5); } if ($i < 0) { $i = 0; } return Yii::t("app", '{n, plural, =0{Not added new records} =1{# record added} few{# records added} other{# added records}}', ['n' => $i]); }
/** * Display user dashboard */ public function actionDashboard() { //$model = Yii::$app->user->identity; $journals = new ActiveDataProvider(['query' => Journal::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]); $events = new ActiveDataProvider(['query' => \app\models\Event::find()->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]); $photos = \app\models\Photos::find()->orderBy(['id' => SORT_DESC])->limit(5)->all(); $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['status' => 0])->orderBy('id')->limit(5), 'pagination' => false]); $DataProvider = new ActiveDataProvider(['query' => User::find()->where('level !=0 AND parent_id=0')->orderBy('id')]); $RegisteredMembers = count(User::find()->where('level > :level', [':level' => 3])->orWhere('level > :level', [':level' => 2])->orWhere('level > :level', [':level' => 1])->all()); $famillies = User::find()->where(['level' => '1'])->count(); $orders = count(\app\models\Payment::find()->all()); $payments = Payment::getPaymentsCount(); $months = Payment::getMonths(); $epercent = Payment::earningPercentage(); $earning = Payment::getMonthlyEarning(); $revenue = Payment::totalRevenue(); $rpercent = payment::revenuePercentage(); $mearning = Payment::getPaymentsMonth(); return $this->render('dashboard', ['dataProvider' => $DataProvider, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists, 'RegisteredMembers' => $RegisteredMembers, 'orders' => $orders, 'payments' => $payments, 'months' => $months, 'epercent' => $epercent, 'earning' => $earning, 'revenue' => $revenue, 'rpercent' => $rpercent, 'mearning' => $mearning, 'famillies' => $famillies]); }
/** * @return \yii\db\ActiveQuery */ public function getPhotos() { return $this->hasMany(Photos::className(), ['id' => 'photos_id'])->viaTable('photos_has_messages', ['messages_id' => 'id']); }
public function run() { $array = ArrayHelper::toArray(Photos::findAll(['event_id' => $this->eventId])); return $this->render('photo', ['photo' => $array, 'event' => $this->eventId]); }
private function _createAlbumPhoto(array $albums, array $albumThumbs) { $photoData = []; $data = []; foreach ($albums as $key => $album) { sleep(1); $data = $this->_vkObject->api('photos.get', 'GET', ['owner_id' => '-' . self::VK_GROUP_ID, 'album_id' => $album['album_id'], 'rev' => 0, 'extended' => 0]); if (isset($data, $data['response'], $data['response'][0])) { $photoData = []; $this->_setLog(['mess' => 'find (' . count($data['response']) . ') photo in album: ' . $album['title'] . '_' . $album['description']]); foreach ($data['response'] as $response) { $pname = $album['title'] . '_' . $album['description'] . '_' . $response['text']; $pname = 'krasotka_me_' . self::_get_in_translate_to_en($pname) . '_' . $response['pid']; $pname = preg_replace('/(\\.|\\/|<.*>| )/', '_', $pname); $mainPhoto = 0; if ($albumThumbs[$key] == $response['pid']) { $mainPhoto = 1; } $photoData[] = ['album_id' => $response['aid'], 'photo_id' => $response['pid'], 'vk_photo' => isset($response['src_xbig']) ? $response['src_xbig'] : $response['src_big'], 'photo_name' => $pname . '.jpg', 'text' => $response['text'], 'vk_created' => (int) $response['created'], 'main_photo' => $mainPhoto, 'created_at' => time(), 'updated_at' => time()]; } if ($photoData && $photoData[0]) { $isInsert = Yii::$app->db->createCommand()->batchInsert(Photos::tableName(), array_keys($photoData[0]), $photoData)->execute(); if ($isInsert) { foreach ($photoData as $p_data) { $path = Yii::getAlias('@fullMediaDir/' . $p_data['album_id'] . '/' . $p_data['photo_name']); if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } $image = file_get_contents($p_data['vk_photo']); file_put_contents($path, $image); } $this->_setLog(['mess' => 'save in path: ' . $path]); } } $this->_setLog(['mess' => 'Left (' . (count($albums) - ($key + 1)) . ')']); } } }
/** * Show the form for creating a new resource. * * @return Response */ public function create(Photos $photosModel) { $num = $photosModel->getById(); return view('photo.index', ['post' => $num]); }
public function beforeDelete() { $photos = Photos::find()->where(['catalog_id' => $this->id])->all(); //print_r($photos); die(); foreach ($photos as $photo) { if (file_exists("../web" . $photo->url_thumbnail)) { unlink("../web" . $photo->url_thumbnail); } $config = ArrayHelper::map(Config::find()->all(), 'name', 'value'); $s3 = new S3Client(['version' => 'latest', 'region' => 'us-west-2', 'credentials' => ['key' => $config['amazon_key'], 'secret' => $config['amazon_secret']]]); if ($this->storage == 2) { try { $res = $s3->deleteObject(['Bucket' => $config['amazon_bucket'], 'Key' => 'photo/' . urldecode(mb_substr($photo->url, mb_strrpos($photo->url, '/') + 1))]); } catch (S3Exception $e) { echo $e->getMessage(); Yii::$app->session->setFlash('error', $e->getMessage()); } } else { if ($this->storage == 1) { if (file_exists("../web" . $photo->url)) { unlink("../web" . $photo->url); } } else { $arr = explode('/', $photo->url); $f = array_pop($arr); // print_r($f); //die(); $this->ftp_delete($f); } } } return parent::beforeDelete(); // TODO: Change the autogenerated stub }
/** * Finds the Photos model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Posts the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelPhoto($id) { if (($model = Photos::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @inheritdoc */ public function getActivePhotos() { return $this->hasMany(Photos::className(), ['id_posts' => 'id'])->andWhere(['active' => 1]); }
/** * Run the database seeds. * * @return void */ public function run() { Photos::create(['text' => 'test1']); Photos::create(['text' => 'test2']); Photos::create(['text' => 'test3s']); }
public function actionPhoto($id) { $photos = new Photos(); $dataProvider = $photos->findAll(['event_id' => $id]); return $this->render('photos', ['model' => $this->findModel($id), 'photo' => $photos, 'dataProvider' => $dataProvider]); }
<div class="g w1140 main"> <article class="c-c"> <!-- intro text --> <div class="c text-center inflated-top"> <p><?php echo $model->description; ?> </p> </div> <!-- intro text --> <?php // $ads = "test"; $ads = \app\components\widgets\AdsWidget::widget(['url' => 'photo-slider']); $photos = \app\models\Photos::find()->where("catalog_id = :catalog_id", [':catalog_id' => $model->id])->orderBy('sort')->all(); ?> <div class="c-c gallery"> <?php foreach ($photos as $k => $photo) { ?> <div class="c x1d4--d x1d3--t x1d2--m gallery-element"> <div class="photo-element"> <div class="preview-photo" > <a title="" href="<?php echo $photo->url; ?> " class="thumbnail"> <img src="<?php echo $photo->url_thumbnail; ?>
/** * @return newsfeed generations array- DTR */ public function getNews() { $user = Yii::$app->user->id; $notification = Notification::find()->where(['shared_id' => $user])->orderBy(['date' => SORT_DESC])->all(); foreach ($notification as $news) { if ($news->type == 'event') { return Event::find()->where(['id' => $news->type_id]); } elseif ($news->type == 'activity') { return Activity::find()->where(['id' => $news->type_id]); } elseif ($news->type == 'journal') { return Journal::find()->where(['id' => $news->type_id]); } elseif ($news->type == 'wishlist') { return Wishlist::find()->where(['id' => $news->type_id]); } else { return Photos::find()->where(['id' => $news->type_id]); } } }
/** * @return \yii\db\ActiveQuery */ public function getPhotos() { return $this->hasMany(Photos::className(), ['car_id' => 'id']); }
/** * Display user dashboard * @param integer $id User ID */ public function actionDashboard($id = null) { //Check user level & existence of $id $id = Yii::$app->user->identity->level == 0 && $id != null ? $id : Yii::$app->user->id; $model = User::findOne($id); $photos = \app\models\Photos::getItems(); $journals = new ActiveDataProvider(['query' => Journal::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]); if ($model->level == 3) { //if the user is child $moods = new ActiveDataProvider(['query' => Mood::find()->select('mood')->where(['user_id' => $id])->orderBy(['date' => SORT_DESC, 'time' => SORT_DESC])->limit(1), 'pagination' => false]); $DataProvider = new ActiveDataProvider(['query' => $model->findParents(), 'pagination' => ['pageSize' => 20]]); return $this->render('childdashboard', ['dataProvider' => $DataProvider, 'journalProvider' => $journals, 'moodsProvider' => $moods, 'moods' => new Mood(), 'model' => $model, 'photos' => $photos]); } else { //if the user is parent $events = new ActiveDataProvider(['query' => \app\models\Event::find()->where('FIND_IN_SET(' . $id . ', shared_with)')->orWhere(['user_id' => $id])->orderBy(['date' => SORT_DESC])->limit(5), 'pagination' => false]); $wishlists = new ActiveDataProvider(['query' => \app\models\Wishlist::find()->where(['assigned_to' => $id, 'status' => 0])->orderBy('id')->limit(5), 'pagination' => false]); $DataProvider = new ActiveDataProvider(['query' => $model->findFamily()]); $activity = new ActiveDataProvider(['query' => \app\models\Activity::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['id' => SORT_DESC])->limit(4), 'pagination' => false]); return $this->render('dashboard', ['dataProvider' => $DataProvider, 'activity' => $activity, 'events' => $events, 'journals' => $journals, 'photos' => $photos, 'wishlists' => $wishlists]); } }
<!-- gallery --> <div class="c-c gallery"> <?php foreach ($result as $photo) { ?> <?php if (!empty($photo->photo_preview) && file_exists('../web/uploads/previewphoto/' . $photo->photo_preview)) { $src = '/uploads/previewphoto/' . $photo->photo_preview; } else { $src = isset($photo->photos[0]) ? $photo->photos[0] : "#"; } $photos = \app\models\Photos::find()->where("catalog_id = :catalog_id", [":catalog_id" => $photo['id']])->select("url_thumbnail")->asArray()->column(); $photosCount = \app\models\Photos::find()->where("catalog_id = :catalog_id", [":catalog_id" => $photo['id']])->count("*"); ?> <div class="c x1d4--d x1d3--t x1d2--m gallery-element"> <div class="photo-element new"> <a href="/photo/<?php echo $photo['url']; ?> "> <div class="preview"> <img src="<?php echo $src; ?> " class="r" alt="<?php echo $photo['title']; ?> ">
/** * @return \yii\db\ActiveQuery */ public function getPhotos() { return $this->hasOne(Photos::className(), ['id' => 'photos_id']); }
public function actionDeletePhoto($id) { $photo = Photos::findOne($id); $photo->delete(); return $this->redirect(Yii::$app->request->referrer); }
/** * @return \yii\db\ActiveQuery */ public function getPhotos() { return $this->hasMany(Photos::className(), ['id' => 'photos_id'])->viaTable('network_has_photos', ['network_id' => 'id']); }
public function upload() { // Make sure file is not cached (as it happens for example on iOS devices) header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // Support CORS // header("Access-Control-Allow-Origin: *"); // other CORS headers if any... if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { exit; // finish preflight CORS requests here } //是否是debug模式 if (!empty($_REQUEST['debug'])) { $random = rand(0, intval($_REQUEST['debug'])); if ($random === 0) { header("HTTP/1.0 500 Internal Server Error"); exit; } } // header("HTTP/1.0 500 Internal Server Error"); // exit; // 5 minutes execution time @set_time_limit(5 * 60); // Uncomment this one to fake upload time // usleep(5000); // Settings // $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; $targetDir = 'upload/upload_tmp/'; $uploadDir = 'upload/upload/'; $cleanupTargetDir = true; // Remove old files $maxFileAge = 5 * 3600; // Temp file age in seconds // Create target dir if (!file_exists($targetDir)) { @mkdir($targetDir, 777, true); } // Create target dir if (!file_exists($uploadDir)) { @mkdir($uploadDir, 777, true); } // Get a file name if (isset($_REQUEST["name"])) { $fileName = $_REQUEST["name"]; } elseif (!empty($_FILES)) { $fileName = $_FILES["file"]["name"]; } else { $fileName = uniqid("file_"); } $filePath = $targetDir . $fileName; $uploadPath = $uploadDir . $fileName; // Chunking might be enabled $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 1; // Remove old temp files if ($cleanupTargetDir) { if (!is_dir($targetDir) || !($dir = opendir($targetDir))) { die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); } while (($file = readdir($dir)) !== false) { $tmpfilePath = $targetDir . $file; // If temp file is current file proceed to the next if ($tmpfilePath == "{$filePath}_{$chunk}.part" || $tmpfilePath == "{$filePath}_{$chunk}.parttmp") { continue; } // Remove temp file if it is older than the max age and is not the current file if (preg_match('/\\.(part|parttmp)$/', $file) && @filemtime($tmpfilePath) < time() - $maxFileAge) { @unlink($tmpfilePath); } } closedir($dir); } // Open temp file if (!($out = @fopen("{$filePath}_{$chunk}.parttmp", "wb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); } // Read binary input stream and append it to temp file if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } else { if (!($in = @fopen("php://input", "rb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); } } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); rename("{$filePath}_{$chunk}.parttmp", "{$filePath}_{$chunk}.part"); $index = 0; $done = true; for ($index = 0; $index < $chunks; $index++) { if (!file_exists("{$filePath}_{$index}.part")) { $done = false; break; } } if ($done) { if (!($out = @fopen($uploadPath, "wb"))) { die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); } if (flock($out, LOCK_EX)) { for ($index = 0; $index < $chunks; $index++) { if (!($in = @fopen("{$filePath}_{$index}.part", "rb"))) { break; } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($in); @unlink("{$filePath}_{$index}.part"); } flock($out, LOCK_UN); } @fclose($out); } // Return Success JSON-RPC response //die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); $imagePath = $uploadPath; $image = getimagesize($imagePath); $imageWidth = $image[0]; $imageHeight = $image[1]; var_dump($_FILES); $insertResult = Photos::create(['path' => "/" . $uploadPath, 'name' => $_FILES['file']['name'], 'height' => $imageHeight, 'width' => $imageWidth]); if (!$insertResult) { return json_encode(array('status' => 101, 'msg' => '上传失败')); } return json_encode(array('status' => 0, 'msg' => '上传成功')); }