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);
 }
 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();
 }
 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);
 }
 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();
 }
Esempio n. 5
0
 function hashids_decode($raw)
 {
     $ids = \Hashids::decode($raw);
     return current($ids);
 }
            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;
});
 /**
  * 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];
 }
Esempio n. 8
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);
     }
 }
Esempio n. 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;
     }
 }
Esempio n. 10
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;
     }
 }
 public function processAddCartItem()
 {
     $encoded_product_id = \Input::get('product_id');
     $product_user_id = \Input::get('product_user_id');
     $vendor_id = \Input::get('vendor_id');
     $quantity = \Input::get('quantity');
     $sub_product = $this->sub_product_repo->subProductMatchingVendorId($vendor_id);
     $decoded_product_id = $encoded_product_id;
     if (!is_null($encoded_product_id)) {
         list($decoded_product_id) = Hashids::decode($encoded_product_id);
     }
     if (!$sub_product || empty($quantity) || empty($decoded_product_id)) {
         throw new \InvalidArgumentException('Invalid parameters for this request');
     }
     $cart = $this->amz_prod_repo->addCartItem($sub_product, $quantity, $this->sales_agent_mgr->getSalesAgent());
     //if cart is not successful, go back with errors
     if (!$cart) {
         return Redirect::back()->withErrors($this->amz_prod_repo->errors());
     }
     //fire event to record this interaction
     \Event::fire('ProductUserInteraction.cartAdded', [$decoded_product_id, $product_user_id]);
     return Redirect::to(route('get_item', ['id' => $encoded_product_id, 'option' => $sub_product['vendor_id']]))->with('success_message', 'Item added to cart');
 }
Esempio n. 12
0
 public function deScrypt($hashStr)
 {
     $hashids = new Hashids(url_hash_key);
     $id = $hashids->decode($hashStr);
     $id = $id[0];
     return $id;
 }
        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)]);
});
Esempio n. 14
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);