상속: extends yii\db\ActiveRecord
예제 #1
0
 public static function checkOrShorten($long_url)
 {
     $link = new Link();
     $link->user_id = NULL;
     $link->long_url = $long_url;
     //logged in handle
     if (Auth::check()) {
         $user_id = Auth::user()->id;
         $link->user_id = Auth::user()->id;
         $query = DB::select("\r\n            \tSELECT \r\n            \t\tshort_url\r\n            \tFROM \r\n            \t\tlinks \r\n            \tWHERE \r\n            \t\tlong_url = '{$long_url}' \r\n            \tAND \r\n            \t\tuser_id = '{$user_id}'\r\n            ");
         if ($query) {
             $link->short_url = $query;
         }
     }
     //While the short url is null, keep going until a new shortened url is found.
     while (is_null($link->short_url)) {
         $link->short_url = str_random(4);
         $query = DB::select("SELECT short_url FROM links WHERE short_url = '" . $link->short_url . "'");
         if (!$query) {
             $context = stream_context_create(array('http' => array('follow_location' => false)));
             $html = file_get_contents($long_url, true, $context);
             if (strlen($html) > 0) {
                 preg_match("/\\<title\\>(.*)\\<\\/title\\>/", $html, $title);
                 $link->page_title = $title[1];
             }
         } else {
             $link->short_url = NULL;
         }
         //Saves the built object to the database.
         $link->save();
         DB::table('users_links')->insert(array('link_id' => $link->id, 'user_id' => $link->user_id, 'privacy' => 0));
     }
     return $link;
 }
예제 #2
0
파일: IndexForm.php 프로젝트: andrey3/yii
 public function generateLink()
 {
     $link = new Link();
     $link->email = $this->email;
     $link->generateToken();
     return $link->save(false) && empty($this->getErrors()) ? $link : null;
 }
예제 #3
0
 public function store($inputs)
 {
     $link = new Link();
     $link->url = urldecode($inputs['url']);
     $link->photo_url = $this->cleanPhotoUrl($inputs['photo_url']);
     $link->title = $inputs['title'];
     $link->save();
     return $link;
 }
예제 #4
0
파일: LinkTest.php 프로젝트: andrey3/yii
 public function testSaveLink()
 {
     $link = new Link();
     $link->email = "*****@*****.**";
     $link->generateToken();
     $token = $link->token;
     $this->assertTrue($link->save());
     $this->tester->seeInDatabase('links', ['email' => '*****@*****.**', 'token' => $token]);
 }
예제 #5
0
 /**
  * Update friend link, new when don't exists.
  *
  * @param $inputs
  */
 public function updateFriend($inputs)
 {
     if (isset($inputs['id'])) {
         $friend = Link::find($inputs['id']);
     } else {
         $friend = new Link();
     }
     $friend->name = $inputs['name'];
     $friend->link = $inputs['link'];
     $friend->save();
 }
예제 #6
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function __construct()
 {
     $setting = Models\Setting::first();
     $this->data['menu'] = Models\Menu::with('child')->where('level', 0)->get();
     $this->data['berita'] = Models\Berita::orderBy('id_berita', 'desc')->limit(6)->get();
     $this->data['pengumuman'] = Models\Pengumuman::orderBy('tanggal', 'desc')->limit(10)->get();
     $this->data['agenda'] = Models\Agenda::orderBy('tgl_posting', 'desc')->limit(5)->get();
     $this->data['polling'] = Models\Polling::with('jawaban')->where('status', 'Y')->limit(1)->first();
     $this->data['title'] = $setting->title_web;
     $this->data['desc'] = $setting->desc_web;
     $this->data['key'] = $setting->key_web;
     $this->data['logo'] = $setting->logo;
     $this->data['header_img'] = $setting->bg_header;
     $this->data['icon'] = $setting->favicon;
     $this->data['facebook'] = $setting->facebook;
     $this->data['peta_latitude'] = $setting->peta_latitude;
     $this->data['peta_longitude'] = $setting->peta_longitude;
     $this->data['twitter'] = $setting->twitter;
     $this->data['gplus'] = $setting->gplus;
     $this->data['slider_home'] = Models\Berita::orderBy('tanggal', 'desc')->limit(5)->get();
     $this->data['galeri_home'] = Models\Foto::OrderBy('id_foto', 'desc')->paginate(9);
     $this->data['opini_home'] = Models\Berita::where('kategori_berita', 5)->orderBy('id_berita', 'desc')->limit(6)->get();
     $this->data['banner'] = Models\Banner::where('id', 1)->first();
     $this->data['link'] = Models\Link::orderBy('id', 'desc')->limit(5)->get();
     $this->data['publikasi'] = Models\Publikasi::orderBy('id', 'desc')->limit(3)->get();
     $this->data['setting'] = $setting;
 }
예제 #7
0
 public function performRedirect(Request $request, $short_url, $secret_key = false)
 {
     $link = Link::where('short_url', $short_url)->first();
     if ($link == null) {
         return abort(404);
     }
     $link_secret_key = $link->secret_key;
     if ($link->is_disabled == 1) {
         return view('error', ['message' => 'Sorry, but this link has been disabled by an administrator.']);
     }
     if ($link_secret_key) {
         if (!$secret_key) {
             // if we do not receieve a secret key
             // when we are expecting one, return a 404
             return abort(404);
         } else {
             if ($link_secret_key != $secret_key) {
                 // a secret key is provided, but it is incorrect
                 return abort(404);
             }
         }
     }
     $long_url = $link->long_url;
     $clicks = intval($link->clicks);
     if (is_int($clicks)) {
         $clicks += 1;
     }
     $link->clicks = $clicks;
     $link->save();
     LinkHelper::processPostClick($link);
     return redirect()->to($long_url);
 }
예제 #8
0
 /**
  * Finds the Link model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Link the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Link::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'PAGE_NOT_FOUND'));
     }
 }
예제 #9
0
 /**
  * Find model by short code
  *
  * @param $shortCode
  * @return null|Link
  * @throws NotFoundHttpException
  */
 protected function findModelByShortCode($shortCode)
 {
     $model = Link::findOne(['short_code' => $shortCode]);
     if (!$model) {
         throw new NotFoundHttpException('The requested link doesn\'t exist');
     }
     return $model;
 }
예제 #10
0
 protected function findModel($id)
 {
     if (($model = Link::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('未找到id为[' . $id . ']的链接');
     }
 }
예제 #11
0
 /**
  * Finds the Link model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Link the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Link::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #12
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     //        dd($this->input('id'));
     $link = Link::find($this->input('id'));
     $lesson = Lesson::find($link->lesson_id);
     $product = $lesson->product;
     $users = $product->owner()->lists('id');
     return in_array(Auth::id(), $users);
 }
예제 #13
0
 public function actionIndex()
 {
     $curUser = \Yii::$app->user->id;
     UserSettingsBlock::sync($curUser);
     //todo return data model
     $block = Block::find()->with('links')->where(['hidden' => Block::STATUS_SHOW, 'type' => Block::TYPE_TAB])->orderBy('order')->all();
     $model = UserSettingsBlock::find()->with('block')->orderBy('column, order')->where(['{{%user_settings_block}}.user_id' => $curUser])->all();
     $msg = Message::find()->where(['status' => Message::STATUS_SHOW])->all();
     return $this->render('index', ['model' => $model, 'blocks' => $block, 'messages' => $msg, 'link' => Link::getLinksBlocks()]);
 }
예제 #14
0
 public function actionEditUserBlock($id)
 {
     $userModel = $this->findUserBlock($id);
     $model = Block::find()->with('links')->where(['id' => $userModel->block_id])->one();
     $states = State::find()->all();
     $test = Link::find()->where(['id' => 2])->one();
     if ($userModel->load(Yii::$app->request->post()) && $userModel->save()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', '{model} SUCCESS_UPDATED', ['model' => $model->title]));
     }
     return $this->render('userSettings', ['userModel' => $userModel, 'model' => $model, 'states' => $states, 'test' => $test]);
 }
예제 #15
0
 public function init()
 {
     parent::init();
     $links = Link::find()->where('visible=1')->orderBy(['position' => SORT_DESC])->limit($this->max)->all();
     echo '<h4>友情链接</h4><ul class="list-unstyled">';
     foreach ($links as $key => $value) {
         $link = Html::a(Html::encode($value->name), $value->url);
         echo Html::tag('li', $link);
     }
     echo "</ul>";
 }
예제 #16
0
 function actionAjaxdelete($id = null)
 {
     $link = Link::findOne($id);
     if ($link != null and $link['admin_id'] == Yii::$app->user->id) {
         if ($link->delete()) {
             echo '...';
         }
     } else {
         echo 'нет данных...';
     }
 }
예제 #17
0
 public function actionLogin($token)
 {
     if (Yii::$app->user->isGuest && ($link = Link::findByToken($token))) {
         $email = $link->email;
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             Link::deleteLinksByToken($token);
             return $this->redirect('/account/index');
         }
         return $this->render('login', ['model' => $model, 'email' => $email]);
     }
     return $this->redirect('/site/index');
 }
예제 #18
0
 public function actionGo($id)
 {
     User::loginGuest();
     if (($link = Link::findOne($id)) !== null) {
         if (LinkStats::create($id) === true) {
             $this->redirect($link->href);
         } else {
             throw new NotFoundHttpException('Запрошеная страница не найдена.');
         }
     } else {
         throw new NotFoundHttpException('Запрошеная страница не найдена.');
     }
 }
예제 #19
0
 public function search($params)
 {
     $query = Link::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'name', true);
     $this->addCondition($query, 'url', true);
     $this->addCondition($query, 'logo', true);
     $this->addCondition($query, 'target');
     $this->addCondition($query, 'type');
     $this->addCondition($query, 'position');
     $this->addCondition($query, 'visible');
     return $dataProvider;
 }
예제 #20
0
 /**
  * Show the admin panel, and process admin AJAX requests.
  *
  * @return Response
  */
 public function displayAdminPage(Request $request)
 {
     if (!$this->isLoggedIn()) {
         return abort(404);
     }
     $username = session('username');
     $role = session('role');
     $admin_users = null;
     $admin_links = null;
     if ($this->currIsAdmin()) {
         $admin_users = User::paginate(15);
         $admin_links = Link::paginate(15);
     }
     $user = UserHelper::getUserByUsername($username);
     if (!$user) {
         return redirect(route('index'))->with('error', 'Invalid or disabled account.');
     }
     $user_links = Link::where('creator', $username)->paginate(15);
     return view('admin', ['role' => $role, 'admin_users' => $admin_users, 'admin_links' => $admin_links, 'user_links' => $user_links, 'api_key' => $user->api_key, 'api_active' => $user->api_active, 'api_quota' => $user->api_quota]);
 }
예제 #21
0
파일: Main.php 프로젝트: nospor/shorten
 private function getLatest()
 {
     $sids = isset($_COOKIE['shids']) ? explode(',', $_COOKIE['shids']) : array();
     $oldSids = array_reverse($sids);
     $latest = [];
     if ($oldSids) {
         $modelLink = new Link();
         $_ids = [];
         foreach ($oldSids as $_id) {
             $_id = (int) $_id;
             $_ids[$_id] = $_id;
         }
         $links = $modelLink->findLinks($_ids);
         foreach ($_ids as $_id) {
             if (isset($links[$_id])) {
                 $links[$_id]['short_link'] = $this->router->url($links[$_id]['short']);
                 $latest[] = $links[$_id];
             }
         }
     }
     return $latest;
 }
예제 #22
0
 /**
  * Execute the console command.
  *
  * @param ImageHandlerInterface $imageHandler
  * @param CacheHandlerInterface $cacheHandler
  * @param SearchHandlerInterface $searchHandler
  * @return mixed
  */
 public function handle(ImageHandlerInterface $imageHandler, CacheHandlerInterface $cacheHandler, SearchHandlerInterface $searchHandler)
 {
     // Find all links with photos URLs that need thumbnails
     $links = Link::with('item', 'item.user')->whereNull('photo')->take(100)->get();
     /* @var $link \App\Models\Link */
     foreach ($links as $link) {
         // Try to generate a thumbnail for the desired photo
         try {
             $generatedFilename = $imageHandler->generateThumbnail($link->photo_url);
             if ($generatedFilename) {
                 $link->photo = $generatedFilename;
                 $link->save();
                 // Update Search
                 $searchHandler->update($link);
                 // Update cache for user
                 $cacheHandler->del(CacheHandlerInterface::MAINPAGE, $link->item->user->id);
             }
         } catch (\Exception $e) {
             error_log($e);
         }
     }
 }
예제 #23
0
파일: LinkHelper.php 프로젝트: rkubik/polr
 public static function findSuitableEnding()
 {
     /**
      * Provided an in-use link ending (string),
      * find the next available base-32/62 ending.
      * @return string
      */
     $base = env('POLR_BASE');
     $link = Link::where('is_custom', 0)->orderBy('created_at', 'desc')->first();
     if ($link == null) {
         $base10_val = 0;
         $base_x_val = 0;
     } else {
         $latest_link_ending = $link->short_url;
         $base10_val = BaseHelper::toBase10($latest_link_ending, $base);
         $base10_val++;
     }
     $base_x_val = null;
     while (LinkHelper::linkExists($base_x_val) || $base_x_val == null) {
         $base_x_val = BaseHelper::toBase($base10_val, $base);
         $base10_val++;
     }
     return $base_x_val;
 }
예제 #24
0
파일: _header.php 프로젝트: Nechhist/to.ru
<?php

use app\models\User;
use app\models\T;
use app\models\Link;
use yii\helpers\Html;
//////////////////// USER //////////////////////
$count_links = 0;
if (!Yii::$app->user->isGuest) {
    $my_t = T::find()->where(['admin_id' => Yii::$app->user->id])->count();
    $my_link = Link::find()->where(['admin_id' => Yii::$app->user->id])->count();
    $count_links = $my_link + $my_t;
}
?>

<style>
    .header-table-small td{
        border: 2px solid <?php 
echo Yii::$app->params['color']['table_bg_dark'];
?>
;
        margin: 0;
        padding: 3px 15px;
        background-color: <?php 
echo Yii::$app->params['color']['table_bg_dark'];
?>
;
        color: #ffffff;
        font-weight: bold;
        font-size: 16px;
    }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $page = $this->page->getWhereSlug('links');
     $links = Link::all();
     return view('main.links')->with('page', $page)->with('links', $links);
 }
예제 #26
0
 public function getInfoLink()
 {
     return Link::find()->where(['block_id' => $this->id])->orderBy('order')->all();
 }
예제 #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(ModifyLinkRequest $request)
 {
     /** @var Link $link */
     $link = Link::find($request->input('id'));
     if (empty($link)) {
         Flash::error('Link not found');
         return redirect(route('admin.links.index'));
     }
     $link->delete();
     Flash::message('Link deleted successfully.');
     return redirect(route('lessons.edit', [$link->lesson_id]))->with('active_tab', 'links');
 }
예제 #28
0
 /**
  * Delete a link from the course.
  *
  * @param Link $link
  * @return mixed
  */
 public function deleteLink(Link $link)
 {
     $result = \DB::transaction(function () use($link) {
         $link->delete();
     });
     return $result;
 }
예제 #29
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     $link = Link::find($id);
     if ($link->delete()) {
         return response()->json(array('success' => TRUE));
     }
 }
예제 #30
0
 public function links($id)
 {
     $links = Link::where('lesson_id', '=', $id)->get();
     return $links;
 }