Пример #1
0
 /**
  *	Correct any null hash values
  */
 function rehashNullValues()
 {
     $table = 'project_1_images';
     $i = 0;
     $rows = $this->db->query('select * from ' . $table . ' where hash is null');
     foreach ($rows->result() as $row) {
         // Update the hash values
         $hashids = new Hashids('abracadabra', 5);
         $hash = $hashids->encode($row->image_id);
         $dataUpdate = array('hash' => $hash);
         $this->db->where('image_id', $row->image_id);
         $this->db->update($table, $dataUpdate);
         $i++;
     }
     return $i;
 }
 public function init()
 {
     $this->autostart = 'false';
     $assets = dirname(__FILE__) . '/assets';
     $this->assetsPath = Yii::app()->assetManager->publish($assets, false, 1, YII_DEBUG);
     if (empty($this->imageAds)) {
         $this->imageAds = '/web/images/bg_default.png';
     }
     if (empty($this->data)) {
         $data[] = array('file' => $this->assetsPath . '/default.mp3', 'label' => '128K');
         $data[] = array('file' => $this->assetsPath . '/default.mp3', 'label' => '320K VIP');
     }
     //echo json_encode($data);exit;
     $source = json_encode($data);
     $songsListObject = $this->songsListObject;
     $listIndex = $this->songListIndex;
     $indexPl = json_decode($songsListObject);
     $cs = Yii::app()->clientScript;
     $cs->registerCssFile($this->assetsPath . '/css/stylejwp.css');
     $cs->registerScriptFile($this->assetsPath . '/jwplayer.js', CClientScript::POS_END);
     $cs->registerScript('play_song_list' . $this->id, "\n            jwplayer('" . $this->id . "').setup({\n                width: '100%',\n                height: 35,\n                playlist: " . $songsListObject . ",\n                skin: '" . $this->assetsPath . "/vega-skin-album-min-2.xml',\n                autostart: '" . $this->autostart . "',\n                primary: '" . $this->primary . "'\n                /*plugins: {\n                    '" . $this->assetsPath . "/vast.js': {\n                      client:'vast',\n                      schedule:{\n                        overlay: { offset: " . $this->offset . ", tag: '" . Yii::app()->createUrl('/player/banner') . "', type:'nonlinear' }\n                      }\n                    }\n                }*/\n            });\n        ", CClientScript::POS_END);
     $cs->registerScript('play_song_list_this' . $this->id, "\n            function playThis(index) {\n\t\t\t\t\tjwplayer().playlistItem(index);\n            }\n\n            jwplayer().onPlay(function(){\n                var state = jwplayer().getState();\n                if(state=='PLAYING'){\n                    \$('#play').hide();\n                    \$('#pause').show();\n                }else{\n                    \$('#play').show();\n                    \$('#pause').hide();\n                    }\n                    });\n\n                    \$('#play').click(function(){\n                        jwplayer().play();\n                        \$('#play').hide();\n                        \$('#pause').show();\n                    });\n\n                    \$('#pause').click(function(){\n                        jwplayer().pause();\n                        \$('#play').show();\n                        \$('#pause').hide();\n                    });\n\n                    \$('#next').click(function(){\n                        var state = jwplayer().getState();\n                        var curentIndex = jwplayer().getPlaylistIndex();\n                        var totalItem = jwplayer().getPlaylist().length;\n                        if(curentIndex<totalItem){\n                            nextItem = curentIndex+1;\n                        }else{\n                            nextItem = 0;\n                        }\n                        jwplayer().playlistItem(nextItem);\n                        return false;\n                    })\n\n                \$('#prev').click(function(){\n                    var state = jwplayer().getState();\n                    var curentIndex = jwplayer().getPlaylistIndex();\n                    var totalItem = jwplayer().getPlaylist().length;\n                    if(curentIndex <= 0){\n                        nextItem = totalItem-1;\n                    }else{\n                        nextItem = curentIndex-1;\n                    }\n                    jwplayer().playlistItem(nextItem);\n                    return false;\n                })\n\n                \$('#repeat').click(function(){\n                    \$('#repeat').hide();\n                    \$('#playone').show();\n                    jwplayer().setRepeat();\n                    return false;\n                })\n                \$('#playone').click(function(){\n                    \$('#repeat').show();\n                    \$('#playone').hide();\n                    jwplayer().setRepeat();\n                    return false;\n                })\n\n                \$('#sequence').click(function(){\n                    \$('#sequence').hide();\n                    \$('#shuffle').show();\n                    jwplayer().setShuffle();\n                    return false;\n                })\n                \$('#shuffle').click(function(){\n                    \$('#sequence').show();\n                    \$('#shuffle').hide();\n                    jwplayer().setShuffle();\n                    return false;\n                })\n            ;\n        ", CClientScript::POS_END);
     $detect = new Mobile_Detect();
     $deviceType = $detect->isMobile() ? $detect->isTablet() ? 'tablet' : 'mobile' : 'desktop';
     $cs->registerScript('play_song_list_current' . $this->id, "\n                var device_type = '" . $deviceType . "';\n                var listPlayed =Array();\n                var logSongFlag = true;\n                jwplayer().onBeforePlay(function() {\n                    var currentItem = jwplayer().getPlaylistItem();\n                    itemId = currentItem.mediaid;\n                    \$('.nhacvnplayer ul li.item').removeClass('onpause');\n                    \$('.nhacvnplayer ul li.item').removeClass('playing');\n                    \$('.nhacvnplayer #song_'+itemId).addClass('playing');\n                });\n                jwplayer().onPause(function(){\n                    var currentItem = jwplayer().getPlaylistItem();\n                    itemId = currentItem.mediaid;\n                    \$('.nhacvnplayer ul li.item').removeClass('playing');\n                    \$('.nhacvnplayer #song_'+itemId).addClass('onpause');\n                });\n                jwplayer().onPlaylistItem(function() {\n                    logSongFlag = true;\n                    var currentItem = jwplayer().getPlaylistItem();\n                    itemId = currentItem.mediaid;\n                    //\$('.nhacvnplayer ul li.item').removeClass('playing');\n                    //\$('.nhacvnplayer #song_'+itemId).addClass('playing');\n                    hashdis = new Hashids(has_key);\n                    id = hashdis.encode(parseInt(itemId));\n                    songId = 'so'+id;\n                    history.replaceState({}, '', '?st='+songId);\n                })\n                jwplayer().onTime(function(event) {\n                    if(Math.round(event.position) >=5){\n                        if(logSongFlag){\n                            logSongFlag = false;\n                            var currentItem = jwplayer().getPlaylistItem();\n                            itemId = currentItem.mediaid;\n                            itemTitle = currentItem.media_title;\n                            itemDesc = currentItem.media_desc;\n                            var action = 'Play Song';\n                            test = in_array(listPlayed,'song_'+itemId);\n\t\t\t\t\t\t\tif(in_array(listPlayed,'song_'+itemId)){\n\t\t\t\t\t\t\t\tvar action = 'Replay Song';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvar item = {id:'song_'+itemId};\n                            if(!in_array(listPlayed,item.id)){\n                                listPlayed.push(item);\n                            }\n                            //console.log(device_type+'-'+action+'|'+itemId+'|'+itemTitle+'|'+itemDesc);\n\t\t\t\t\t\t\tga('send', 'event', device_type, action, itemTitle+'-'+itemDesc+'-'+itemId);\n\t\t\t\t\t\t\tajax_load('/player/logSong',{'id':itemId});\n                        }\n                    }\n\n\t\t\t    })\n        ", CClientScript::POS_END);
     if (isset($_GET['st']) && !empty($_GET['st'])) {
         $st = $_GET['st'];
         if (!is_numeric($st)) {
             $hashStrId = substr($st, 2);
             $hashids = new Hashids(Yii::app()->params["hash_url"]);
             $parse = $hashids->decode($hashStrId);
             $songId = $parse[0];
             $index = isset($listIndex[$songId]) ? $listIndex[$songId] : 0;
         } else {
             $index = (int) ($st - 1);
         }
         if ($index >= 0) {
             $cs->registerScript('play_song_list_st' . $this->id, "\n\t\t\t\t\tjwplayer().playlistItem(" . $index . ");\n\t\t\t\t\tvar isFirst = true;\n\t\t\t\t\tjwplayer().onQualityLevels(function(event){\n                        if(isFirst){\n                            isFirst=false;\n                            \$('.nhacvnplayer ul li.item').removeClass('playing');\n                            \$('.nhacvnplayer #playlist li.song-item-" . $index . "').addClass('onpause');\n                        }\n                    });\n\t\t\t\t\t", CClientScript::POS_END);
         }
     }
     if (count($this->songs) > 8) {
         $this->classScroll = 'album_song_list';
     }
     parent::init();
 }
Пример #3
0
 public function sendMessage(Request $request)
 {
     $ids = \Hashids::decode($request->input('id'));
     $id = current($ids);
     $conversation = Conversation::withUser(Auth::id())->where('id', $id)->firstOrFail();
     $target = $conversation->target();
     if ($target->isBlockingUser(Auth::user())) {
         return redirect()->route('conversation', $conversation->getKey())->withInput()->with('danger_msg', 'Zostałeś zablokowany przez wybranego użytkownika.');
     }
     $this->validate($request, ['text' => 'required|max:10000']);
     $conversation->notifications()->where('user_id', $target->getKey())->delete();
     $conversation->messages()->create(['user_id' => Auth::id(), 'text' => $request->input('text')]);
     return redirect()->route('conversation', $conversation);
 }
Пример #4
0
 public function init()
 {
     $assets = dirname(__FILE__) . '/assets';
     $this->assetsPath = Yii::app()->assetManager->publish($assets, false, 1, YII_DEBUG);
     $cs = Yii::app()->clientScript;
     $cs->registerCssFile($this->assetsPath . '/css/stylejwp.css');
     $cs->registerScriptFile($this->assetsPath . '/jwplayer.js');
     $album = AlbumModel::model()->findByPk($this->albumId);
     $this->albumObject = $album;
     $this->data = AlbumModel::model()->builDataPlayerAlbum($this->albumId, $this->cached);
     if (!empty($this->data)) {
         $playlistIndex = AlbumModel::model()->getDataIndexAlbum();
         $indexPl = json_decode($this->data);
         $cs->registerScript('play_album_touch' . $this->id, "\n            jwplayer('" . $this->id . "').setup({\n                width: '100%',\n                height: 35,\n                playlist: " . $this->data . ",\n                skin: '" . $this->assetsPath . "/vega-skin-album-min-2.xml',\n                autostart: '" . $this->autostart . "',\n                primary: '" . $this->primary . "'\n            });", CClientScript::POS_END);
         $cs->registerScript('play_album_touch_option' . $this->id, "\n            jwplayer().onReady(function() {\n                var state = jwplayer().getState();\n                if(state=='IDLE'){\n                    \$('#play').show();\n                    \$('#pause').hide();\n                }\n                jwplayer().setVolume(100);\n            });\n            var isShuffle = false;\n            var currentId = 0;\n            jwplayer().onPlaylistItem(function() {\n                //logSongFlag = true;\n                var currentItem = jwplayer().getPlaylistItem();\n                currentId = currentItem['mediaid'];\n                //\$('#vg-player li').removeClass('active');\n                //\$('#vg-player-item-'+currentItem['mediaid']).addClass('active');\n                \$('#item-title').html(currentItem['title']);\n            });\n\n            jwplayer().onPlay(function(){\n                var state = jwplayer().getState();\n                if(state=='PLAYING'){\n                    \$('#play').hide();\n                    \$('#pause').show();\n                }else{\n                    \$('#play').show();\n                    \$('#pause').hide();\n\n                }\n            });\n\n                \$('#play').click(function(){\n                    jwplayer().play();\n                    \$('#play').hide();\n                    \$('#pause').show();\n                });\n\n                \$('#pause').click(function(){\n                    jwplayer().pause();\n                    \$('#play').show();\n                    \$('#pause').hide();\n                });\n\n                \$('#next').click(function(){\n                    var state = jwplayer().getState();\n                    var curentIndex = jwplayer().getPlaylistIndex();\n                    var totalItem = jwplayer().getPlaylist().length;\n                    if(curentIndex<totalItem){\n                        nextItem = curentIndex+1;\n                    }else{\n                        nextItem = 0;\n                    }\n                    if(isShuffle){\n                        nextItem = randomItem();\n                    }\n                    jwplayer().playlistItem(nextItem);\n\n                    return false;\n                })\n\n                \$('#prev').click(function(){\n                    var state = jwplayer().getState();\n                    var curentIndex = jwplayer().getPlaylistIndex();\n                    var totalItem = jwplayer().getPlaylist().length;\n                    if(curentIndex <= 0){\n                        nextItem = totalItem-1;\n                    }else{\n                        nextItem = curentIndex-1;\n                    }\n                    jwplayer().playlistItem(nextItem);\n                    return false;\n                })\n\n                \$('#repeat').click(function(){\n                    \$('#repeat').hide();\n                    \$('#playone').show();\n                    jwplayer().setRepeat();\n                    return false;\n                })\n                \$('#playone').click(function(){\n                    \$('#repeat').show();\n                    \$('#playone').hide();\n                    jwplayer().setRepeat();\n                    return false;\n                })\n\n                \$('#sequence').click(function(){\n                    isShuffle = true;\n                    \$('#sequence').hide();\n                    \$('#shuffle').show();\n                    jwplayer().setShuffle();\n                    return false;\n                })\n                \$('#shuffle').click(function(){\n                    isShuffle = false;\n                    \$('#sequence').show();\n                    \$('#shuffle').hide();\n                    jwplayer().setShuffle();\n                    return false;\n                })\n                function randomItem(){\n                    var playlist = jwplayer().getPlaylist();\n                    var playlistsize = playlist.length;\n                    var randomnumber=Math.floor(Math.random()*playlistsize)\n                    return randomnumber;\n                };\n                ", CClientScript::POS_END);
         $cs->registerScript('play_album_this' . $this->id, "\n            function playThis(index) {\n\t\t\t\t\tjwplayer().playlistItem(index);\n            };", CClientScript::POS_END);
         $cs->registerScript('play_album_getlyrics' . $this->id, "\n            function getLyrics() {\n\t\t\t\t\tvar currentItem = jwplayer().getPlaylistItem();\n                    itemId = currentItem.mediaid;\n                    Popup.title_popup='Lời bài hát';\n                    var lyrics = \$('#lyrics-'+itemId).html();\n                    lyrics = (lyrics=='') ? 'Lời bài hát đang được cập nhật!' : lyrics;\n                    Popup.alert(lyrics);\n            };", CClientScript::POS_END);
         $deviceType = 'mobile';
         $cs->registerScript('play_album_current' . $this->id, "\n                var device_type = '" . $deviceType . "';\n                var listPlayed =Array();\n                var logPlayAlbumFlag = true;\n                var logSongFlag = true;\n                    jwplayer().onBeforePlay(function() {\n                        var currentItem = jwplayer().getPlaylistItem();\n                        itemId = currentItem.mediaid;\n                        \$('.nhacvnplayer ul li.item').removeClass('onpause');\n                        \$('.nhacvnplayer ul li.item').removeClass('playing');\n                        \$('.nhacvnplayer #song_'+itemId).addClass('playing');\n                    });\n                    jwplayer().onPause(function(){\n                        var currentItem = jwplayer().getPlaylistItem();\n                        itemId = currentItem.mediaid;\n                        \$('.nhacvnplayer ul li.item').removeClass('playing');\n                        \$('.nhacvnplayer #song_'+itemId).addClass('onpause');\n                    });\n\t\t\t\t\tjwplayer().onPlaylistItem(function() {\n\t\t\t\t\t    logSongFlag = true;\n                        var currentItem = jwplayer().getPlaylistItem();\n                        itemId = currentItem.mediaid;\n                        //\$('.nhacvnplayer ul li.item').removeClass('playing');\n                        //\$('.nhacvnplayer #song_'+itemId).addClass('playing');\n                        hashdis = new Hashids(has_key);\n                        id = hashdis.encode(parseInt(itemId));\n                        songId = 'so'+id;\n\t                    history.replaceState({}, '', '?st='+songId);\n                    })\n                    //log and track\n                    jwplayer().onTime(function(event) {\n                    if(Math.round(event.position) >=5){\n                        if(logPlayAlbumFlag) {\n                            logPlayAlbumFlag = false;\n                            var action = 'Play Album';\n                            if(in_array_item(listPlayed,'album_'+" . $album->id . ")){\n                                var action = 'Replay Album';\n                            }\n                            var item = 'album_" . $album->id . "';\n                            if(!in_array_item(listPlayed,item)){\n                                listPlayed.push(item);\n                            }\n                            //console.log(device_type+'-'+action);\n                            ga('send', 'event', device_type, action,'" . CHtml::encode($album->name . "-" . $album->artist_name . "-" . $album->id) . "');\n                            ajax_load('/player/logAlbum',{'id':" . $album->id . "});\n                        }\n                        if(logSongFlag){\n                            logSongFlag = false;\n                            var currentItem = jwplayer().getPlaylistItem();\n                            itemId = currentItem.mediaid;\n                            itemTitle = currentItem.media_title;\n                            itemDesc = currentItem.media_desc;\n                            var action = 'Play Song';\n\t\t\t\t\t\t\tif(in_array_item(listPlayed,'song_'+itemId)){\n\t\t\t\t\t\t\t\tvar action = 'Replay Song';\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvar item = 'song_'+itemId;\n                            if(!in_array_item(listPlayed,item)){\n                                listPlayed.push(item);\n                            }\n                            //console.log(device_type+'-'+action+'|'+itemId+'|'+itemTitle+'|'+itemDesc);\n\t\t\t\t\t\t\tga('send', 'event', device_type, action, itemTitle+'-'+itemDesc+'-'+itemId);\n\t\t\t\t\t\t\tajax_load('/player/logSong',{'id':itemId});\n                        }\n                    }\n\n\t\t\t    })", CClientScript::POS_END);
         if (isset($_GET['st']) && !empty($_GET['st'])) {
             $st = $_GET['st'];
             if (!is_numeric($st)) {
                 $hashStrId = substr($st, 2);
                 $hashids = new Hashids(Yii::app()->params["hash_url"]);
                 $parse = $hashids->decode($hashStrId);
                 $songId = $parse[0];
                 $index = isset($playlistIndex[$songId]) ? $playlistIndex[$songId] : 0;
             } else {
                 $index = (int) ($st - 1);
             }
             if ($index >= 0) {
                 $cs->registerScript('play_album_st' . $this->id, "\n                        var isFirst = true;\n                        jwplayer().playlistItem(" . $index . ");\n                        jwplayer().onQualityLevels(function(event){\n                            if(isFirst){\n                                isFirst=false;\n                                \$('.nhacvnplayer ul li.item').removeClass('playing');\n                                \$('.nhacvnplayer #playlist li.song-item-" . $index . "').addClass('onpause');\n                            }\n                        });\n                        ", CClientScript::POS_END);
             }
         }
     }
     parent::init();
 }
Пример #5
0
 public function createOrder(CreateOrderRequest $request)
 {
     $order = \DB::transaction(function () use($request) {
         $order = Order::create($request->all());
         $order->reference = \Hashids::encode($order->id);
         $order->save();
         foreach (\Cart::content() as $item) {
             $order->addItem($item);
         }
         return $order;
     });
     if ($order) {
         return response()->json(['success' => true, 'reference' => $order->reference], 200);
     }
     return response()->json(['success' => false]);
 }
 public function postSenha()
 {
     $associate = ORGAssociates::where('email', '=', Input::get('login'))->take(1)->get();
     if (isset($associate[0])) {
         $new_password = Hashids::encode(date('YmdHis'));
         $associate = $associate[0];
         $associate->senha = md5($new_password);
         $associate->save();
         $user = null;
         if ($associate->associate != null) {
             $user = $associate->associate->getuser;
             $user->password = Hash::make($new_password);
             $user->save();
         } else {
             $user = new User();
             $user->type = 'associate';
             $user->email = $associate->email;
             $user->password = Hash::make($new_password);
             $user->name = $associate->nombre_completo;
             $user->status = 'publish';
             $user->save();
             $assoc = new Associates();
             $assoc->associate = $associate->id_asociado;
             $assoc->user = $user->id;
             $assoc->name = $associate->nombre_completo;
             $assoc->email = $associate->email;
             $assoc->password = $associate->senha;
             $assoc->cpf = $associate->cpf;
             $assoc->type = 'associate';
             $assoc->status = 'publish';
             $assoc->save();
         }
         $data = array('associate' => $associate, 'password' => $new_password);
         Mail::send(array('html' => 'emails.password'), $data, function ($message) use($associate) {
             $message->from('*****@*****.**', 'ABGE');
             $message->to($associate->email, $associate->nombre_completo)->subject('Esqueci minha senha!');
             /*$message->to('*****@*****.**', $associate->nombre_completo)->subject('Esqueci minha senha!');*/
             $message->to('*****@*****.**', $associate->nombre_completo)->subject('Esqueci minha senha!');
         });
         return View::make('auth.minhasenha')->with('route', self::$route);
     } else {
         dd('email no encontrado');
     }
     return Redirect::to(self::$route);
 }
 public function getIndex($id)
 {
     $user_id = \Hashids::decode($id);
     if (!count($user_id)) {
         return abort('404');
     }
     try {
         $email = \App\User::findOrFail($user_id[0])->email;
     } catch (\App\Exceptions\Exception $e) {
         return abort(404);
     }
     $path = storage_path() . '\\profiles\\' . $email . '\\avatar\\avatar.jpg';
     $img = new Filesystem();
     try {
         $imgReal = $img->get($path);
         $headers = array('Content-Type' => $img->mimeType($path));
     } catch (\Illuminate\Contracts\Filesystem\FileNotFoundException $exception) {
         $imgReal = $img->get(storage_path() . '/profiles/default.jpg');
         $headers = array('Content-Type' => $img->mimeType(storage_path() . '/profiles/default.jpg'));
     }
     return Response::make($imgReal, 200, $headers);
 }
                {{--</a>--}}
              {{--</li>--}}
            {{--@endfor--}}
          {{--</ul>--}}
        {{--</div>--}}
      {{--</div>--}}

    </div>

    {{-- Goc Mang Non --}}

    <div class="actnews-list-content clearfix">
      <h2 class="box-title"><span>Góc măng non</span></h2>
      @forelse ($gmn as $key => $p)
        <?php 
$postUri = $p->term_slug . '/' . $p->post_name . '--' . Hashids::encode($p->id);
?>
        @if ($key == 0)  {{-- First post --}}

        <article class="actnews actnews-first" style="float: left;">
          <header class="entry-header">
            <h3 class="entry-title">
              <a href="{{ route('article.index', $postUri) }}">
                <img src="{{ empty($p->post_avatar) ? 'assets/img/transparent.gif' : route('_image.index') . '/' . $p->post_avatar }}" alt="" />
                {{ $p->post_title }}
              </a>
            </h3>
          </header>
          <div class="entry-summary">
            {{ $p->post_excerpt }}
          </div>
Пример #9
0
 /**
  * A helper function for decoding Hashids
  *
  * @param $hash
  * @return null
  */
 protected function decodeHash($hash)
 {
     $decoded = \Hashids::decode($hash);
     if (is_array($decoded)) {
         return $decoded[0];
     } else {
         return null;
     }
 }
Пример #10
0
 public function deScrypt($hashStr)
 {
     $hashids = new Hashids(url_hash_key);
     $id = $hashids->decode($hashStr);
     $id = $id[0];
     return $id;
 }
Пример #11
0
 public function uploadImage($image)
 {
     //dd(storage_path('uploads/'));
     $info_image = getimagesize($image);
     $ratio = $info_image[0] / $info_image[1];
     $newheight = array();
     $width = array("100", $info_image[0]);
     #$filename = "prueba.".$image->getClientOriginalExtension();
     $filename = Hashids::encode(idate('U')) . "." . $image->getClientOriginalExtension();
     $nombres = ["thumb_" . $filename, $filename];
     for ($i = 0; $i < count($width); $i++) {
         $path = public_path('uploads/classificados/' . $nombres[$i]);
         Image::make($image->getRealPath())->resize($width[$i], null, function ($constraint) {
             $constraint->aspectRatio();
         })->save($path);
     }
     return $filename;
 }
 /**
  * Parse URI to array.
  *
  * @param $uri
  *
  * @return array
  */
 private function _parseUri($uri)
 {
     $termSlugs = explode('/', $uri);
     // split URI into an array, delimited by /.
     $postId = 0;
     if (end($termSlugs)) {
         // set array pointer to last element.
         // split article name & hashid into an array, delimited by --.
         $split = preg_split('/^(.*)-{2}/', current($termSlugs), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
         if (count($split) == 2) {
             // has hashid
             array_pop($termSlugs);
             $id = \Hashids::decode($split[1]);
             if (count($id) == 1 and is_numeric($id[0])) {
                 $postId = $id[0];
             }
         }
     }
     $termSlug = implode('/', $termSlugs);
     return ['origin' => $uri, 'term_slugs' => $termSlugs, 'term_slug' => $termSlug, 'post_id' => $postId];
 }
Пример #13
0
 /**
  * @param  string  $id
  * @param  string  $type
  * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model
  */
 private function getObject($id, $type)
 {
     $id = \Hashids::decode($id);
     $id = current($id);
     switch ($type) {
         case 'content':
             return Content::findOrFail($id);
         case 'related':
             return ContentRelated::findOrFail($id);
         case 'entry':
             return Entry::findOrFail($id);
         case 'entry_reply':
             return EntryReply::findOrFail($id);
         case 'comment':
             return Comment::findOrFail($id);
         case 'comment_reply':
             return CommentReply::findOrFail($id);
     }
 }
Пример #14
0
        return Redirect::to('/');
    }
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
    if (Session::token() !== Input::get('_token')) {
        throw new Illuminate\Session\TokenMismatchException();
    }
});
/*
|--------------------------------------------------------------------------
| Decode Filters
|--------------------------------------------------------------------------
*/
//Route::when('*', 'csrf', array('post', 'put', 'delete'));
Route::filter('input_product_id_decode', function ($route) {
    $product_id = Input::get('product_id');
    if (is_null($product_id)) {
        return;
    }
    Input::merge(['product_id' => Hashids::decode($product_id)]);
});
  {{-- PAGE HEADER --}}

  <h1 class="page-header">
    <span class="glyphicon glyphicon-globe" aria-hidden="true"></span>
    {{ $termCategory->term_name }}
  </h1>

  {{-- COLUMNS & CONTENT --}}

  <div class="row">

    <div class="col-md-6 col-md-push-3">
      @forelse ($articles as $key => $p)
      <?php 
$author = $p->author()->select('id', 'name')->first();
$postId = Hashids::encode($p->id);
?>
      @if ($key == 0) {{-- First post --}}

      <div class="post post-first">
        <h2 class="post-title">
          <a href="{{ route('article.index', $termCategory->term_slug . '/' . $p->post_name . '--' . $postId) }}">{{ $p->post_title }}</a>
        </h2>
        <p class="post-info">
          <span class="post-date">{{ ivy_echo_date($p->post_date) }}</span>
          <span class="post-author">bởi {{ $author ? $author->name : 'Hệ thống' }}</span>
        </p>
        @unless (empty($p->post_avatar))
        <div class="post-avatar">
          <a href="{{ route('article.index', $termCategory->term_slug . '/' . $p->post_name . '--' . $postId) }}">
            <img src="{{ route('_image.index') }}/{{ $p->post_avatar }}" alt="" />
Пример #16
0
 public function getHashAttribute()
 {
     return \Hashids::encode($this->attributes['id']);
 }
 public function processLoadProducts()
 {
     DB::beginTransaction();
     try {
         //get args
         $op_id = Session::get('HomeController.op_id');
         $op_type = Session::get('HomeController.op_type');
         $products = Session::get('HomeController.products');
         $admin_add_form = Input::get('query.add_attributes');
         $string_of_keywords = Input::get('query.keywords_profile');
         //prep admin add form, ex: clear sub interests if interest is not selected
         $admin_add_form = $this->add_form_prepper->prep($admin_add_form);
         //make sure we have needed args
         if ($op_type == 'ProductRequest' && count($products) > 1) {
             throw new \RuntimeException('More than one product provided for single product input');
         }
         if ($op_type != 'Idea' && $op_type != 'ProductRequest') {
             throw new \RuntimeException('Invalid op type');
         }
         //make sure categorization data is provided
         if (empty($admin_add_form)) {
             DB::rollback();
             return Redirect::route('get_add-categorize')->withErrors('Category information must be provided.');
         }
         //make sure there is only one id per category since this form is limited to radio selections
         foreach ($admin_add_form as $key => $value) {
             if (is_array($value)) {
                 throw new \InvalidArgumentException('Should not have more than one id per category type for this form.');
             }
         }
         //determine add type
         $add_type = 6;
         //load each product
         $loaded_products_exist = false;
         $approved_products_exist = false;
         foreach ($products as $product_key => $product_suite) {
             //ensure the product is not blacklisted
             if (!$this->blacklisted_product_repo->isProductSuiteBlackListed($product_suite)) {
                 //make keyword profile
                 $product_suite['keyword_profile']['profile'] = $this->keyword_profile_generator->make($string_of_keywords);
                 //make category keywords
                 $product_suite['category_keywords'] = $this->category_keywords_generator->make($this->multi_adds_service->getFormattedAdd($admin_add_form));
                 //load product suite
                 $product = $this->product_suite_repo->finderCreate($product_suite, $op_type, $op_id, \AuthMgr::getLoggedUserId(), false);
                 if (!$product && $op_type == 'Idea') {
                     //since we dont want to roll back, if the product exists let's just delete it
                     $existing_failed_prod_ids = $this->product_suite_repo->errors()->get('sub_products_failure_product_id');
                     $this->product_suite_repo->delete(end($existing_failed_prod_ids));
                     \Log::notice('Could not complete finderCreate for product suite: ' . json_encode($product_suite) . ' REPO ERRORS: ' . json_encode($this->product_suite_repo->errors()));
                     continue;
                 } elseif (!$product) {
                     DB::rollback();
                     return Redirect::route('get_add-categorize')->withErrors("Hmm, I guess we're having an issue, we aren't able to complete this submission.");
                 }
                 //load add for product suite
                 $add = $this->multi_adds_service->save($product->id, $add_type, $admin_add_form);
                 $loaded_products_exist = true;
             }
             $approved_products_exist = true;
         }
         //if there are no approved products, redirect back with errors
         if (!$approved_products_exist && $loaded_products_exist) {
             DB::rollback();
             return Redirect::route('get_add-categorize')->withErrors('At least one product must be approved');
         }
         //if all products where blacklisted
         if (!$loaded_products_exist) {
             DB::rollback();
             return Redirect::route('get_add-categorize')->withErrors('This product is either blacklisted or not eligible to be listed, sorry.');
         }
         //update op model to mark it as fulfilled
         if ($op_type == 'Idea') {
             if (!$this->idea_repo->update($op_id, ['is_fulfilled' => 1])) {
                 throw new \RuntimeException($this->idea_repo->errors());
             }
         } else {
             if ($op_type == 'ProductRequest') {
                 if (!$this->request_repo->update($op_id, ['product_id' => $product->id])) {
                     throw new \RuntimeException($this->idea_repo->errors());
                 }
             }
         }
         //flush product suite indexing  (do this last to ensure everything else is successful before comitting to index)
         $this->product_suite_repo->flushIndexing();
     } catch (\Exception $e) {
         DB::rollback();
         throw $e;
     }
     \DB::commit();
     return Redirect::route('get_add')->with('success_message', 'Your Gift Recommendation Has Been Set Up! <a href="' . route('get_item') . '/' . \Hashids::encode($product->id) . '" class="alert-link">Check It Out!</a>');
 }
Пример #18
0
 public static function makeUrlGenre($object)
 {
     Yii::import("application.vendors.Hashids.*");
     $hashids = new Hashids(Yii::app()->params["hash_url"]);
     $type = $object['type'];
     $name = $object['name'];
     $id = $object['id'];
     $gt = isset($object['gt']) ? $object['gt'] : '';
     $suffix = 'gr';
     $code = $hashids->encode($id);
     $code = $suffix . $code;
     $prefix = 'nhac-';
     $urlKey = $prefix . Common::makeFriendlyUrl($name);
     if ($type == 'song') {
         $type = 'bai-hat';
     }
     $params = array("action" => $type, "url_key" => $urlKey, "code" => $code);
     if (!empty($gt)) {
         if ($gt == 'new') {
             $gt = 'moi';
         }
         $params['gt'] = $gt;
     }
     if (isset($object['other'])) {
         foreach ($object['other'] as $key => $ac) {
             $params[$key] = $ac;
         }
     }
     $link = Yii::app()->createAbsoluteUrl("site/url2", $params);
     return $link;
 }
Пример #19
0
 public function save(Model $model)
 {
     $model->save();
     $model->hash = \Hashids::encrypt($model->id);
     $model->save();
 }
Пример #20
0
 public function getTokenAttribute()
 {
     return Hashids::encrypt($this->id);
 }
Пример #21
0
 public static function makeQlink($name)
 {
     usleep(1100000);
     return Hashids::encode((int) microtime(true));
 }
 public function processProductCategorizationUpdate()
 {
     $product_id = \Input::get('product_id');
     $admin_add_form = \Input::get('query.add_attributes');
     $keyword_profile_string = \Input::get('query.keywords_profile');
     //prep admin add form, ex: clear sub interests if interest is not selected
     $admin_add_form = $this->add_form_prepper->prep($admin_add_form);
     if (empty($admin_add_form)) {
         return \Redirect::back()->withErrors('Categorization data must be provided');
     }
     if (empty($product_id)) {
         throw new \InvalidArgumentException();
     }
     \DB::beginTransaction();
     try {
         //update add for product suite
         $this->save_adds->updateAdminAdd($product_id, $admin_add_form);
         //update keyword profile for product suite
         $keyword_profile = $this->keyword_profile_generator->make($keyword_profile_string);
         if (!$this->keyword_profile_repo->updateForProduct($product_id, ['profile' => $keyword_profile])) {
             \DB::rollback();
             return \Redirect::back()->withErrors($this->keyword_profile_repo->errors());
         }
     } catch (\Exception $e) {
         \DB::rollback();
         throw $e;
     }
     \DB::commit();
     return \Redirect::route('get_item', [Hashids::encode($product_id)])->with('success_message', 'Product updated');
 }
Пример #23
0
 public function actionUrl3()
 {
     Yii::import("application.vendors.Hashids.*");
     $hashStr = Yii::app()->request->getParam('code');
     $hashStrId = substr($hashStr, 2);
     $prefix = substr($hashStr, 0, 2);
     $url_key = Yii::app()->request->getParam('url_key');
     $hashids = new Hashids(Yii::app()->params["hash_url"]);
     $parse = $hashids->decode($hashStrId);
     $id = $parse[0];
     $_GET["id"] = $id;
     $action = Yii::app()->request->getParam('action');
     switch ($prefix) {
         case "tt":
             $_GET["type"] = Yii::app()->request->getParam('action_sub');
             $this->forward("topContent/tag", true);
             break;
         case "at":
             $ac = Yii::app()->request->getParam('action_sub');
             $controller = '';
             if ($ac == 'bai-hat') {
                 $tab = 'song';
                 $controller = 'song';
             } elseif ($ac == 'video') {
                 $tab = 'mv';
                 $controller = 'video';
             } elseif ($ac == 'album') {
                 $controller = 'album';
                 $tab = 'album';
             } elseif ($ac == 'tieu-su') {
                 $tab = 'info';
             } else {
                 $tab = $ac;
             }
             $_GET["tab"] = $tab;
             if ($tab != '') {
                 $_GET["artist_id"] = $_GET["id"];
                 echo $controller;
                 $this->forward("/" . $controller . "/artistList", true);
             } else {
                 $this->forward("artist/view", true);
             }
             break;
         case "ti":
             $ac = Yii::app()->request->getParam('action_sub');
             if ($ac == 'bai-hat') {
                 $type = 'song';
             } else {
                 $type = $ac;
             }
             $_GET["type"] = $type;
             $_GET["name"] = $url_key;
             $this->forward("tag/index", true);
             break;
         default:
             $this->forward("site/error", true);
             break;
     }
 }
Пример #24
0
 /**
  * POST action untuk me-regenerate kode_kelas
  * @param  Request $request [description]
  * @return [type]           [description]
  */
 public function regenerate_kode_kelas(Request $request)
 {
     $k = $this->kelas->findOrFail($request->id);
     $k->kode_kelas = \Hashids::encode($request->id . '' . date('YmdHis'));
     $k->save();
     return $k;
 }
Пример #25
0
            Route::get('category-analytics', ['as' => 'get_category-analytics', 'before' => ['has_perm:admin,_view-analytics'], 'uses' => 'AdminAnalyticsController@showCategoryAnalytics']);
            Route::get('admin-analytics', ['as' => 'get_admin-analytics', 'before' => ['has_perm:admin,_view-analytics'], 'uses' => 'AdminAnalyticsController@showAdminAnalytics']);
            Route::get('my-category-analytics', ['as' => 'get_my-category-analytics', 'before' => ['has_perm:admin,_view-analytics,_view-own-analytics'], 'uses' => 'AdminAnalyticsController@showMyCategoryAnalytics']);
            Route::get('my-products/{page?}', ['as' => 'get_my-products', 'before' => ['has_perm:admin,_load-product-via-id,_load-product-via-idea'], 'uses' => 'AdminProductController@showAdminProducts']);
        });
    }
});
/*
|--------------------------------------------------------------------------
| Route Bindings
|--------------------------------------------------------------------------
*/
Route::bind('product_id', function ($value, $route) {
    $decoded = Hashids::decode($value);
    //if the product id wasn't decodable, abort
    if (!isset($decoded[0])) {
        \App::abort(404);
    }
    return $decoded[0];
});
Route::bind('product_id_sales_agent_user_id', function ($value, $route) {
    $decoded = Hashids::decode($value);
    //if the product id wasn't decodable, abort
    if (!isset($decoded[0])) {
        \App::abort(404);
    }
    if (!isset($decoded[1])) {
        $decoded[1] = null;
    }
    return $decoded;
});
Пример #26
0
 public function authUserInfo()
 {
     $data[] = ['name' => Auth::user()->name, 'profile_picture' => '/avatar/' . \Hashids::encode(Auth::user()->id, rand(0, 100)), 'email' => Auth::user()->email];
     return $data;
 }
Пример #27
0
 function hashids_decode($raw)
 {
     $ids = \Hashids::decode($raw);
     return current($ids);
 }
Пример #28
0
    private function _unhash($input, $alphabet)
    {
        $number = 0;
        if (strlen($input) && $alphabet) {
            $alphabet_length = strlen($alphabet);
            $input_chars = str_split($input);
            foreach ($input_chars as $i => $char) {
                $pos = strpos($alphabet, $char);
                if ($this->_math_functions) {
                    $number = $this->_math_functions['str']($this->_math_functions['add']($number, $pos * pow($alphabet_length, strlen($input) - $i - 1)));
                } else {
                    $number += $pos * pow($alphabet_length, strlen($input) - $i - 1);
                }
            }
        }
        return $number;
    }
}
$key = 'test';
$min_hash_length = 12;
$hashids = new Hashids($key, $min_hash_length);
//$ids = array(1,2,3);
$ids = array(134);
// 加密
$str = $hashids->encode($ids);
echo $str . "<br>";
//exit;
// 解密
$ids = $hashids->decode($str);
echo "<pre>";
var_dump($ids);