web.php 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498
  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. use Illuminate\Support\Facades\Auth;
  4. use Illuminate\Support\Facades\URL;
  5. use Illuminate\Support\Facades\App;
  6. use Illuminate\Support\Str;
  7. use Illuminate\Support\Facades\Redirect;
  8. use Illuminate\Http\Request;
  9. use App\News;
  10. use App\BreakingNews;
  11. use App\Section;
  12. use App\Home;
  13. use App\Page;
  14. use App\PageAdv;
  15. use App\SectionAdv;
  16. use App\Event;
  17. use App\Season;
  18. use App\Video;
  19. use App\Calendar;
  20. use App\Category;
  21. use App\Group;
  22. use App\CalendarGame;
  23. use App\Notifications\FacebookPost;
  24. use App\Notifications\TwitterPost;
  25. /*
  26. |--------------------------------------------------------------------------
  27. | Web Routes
  28. |--------------------------------------------------------------------------
  29. |
  30. | Here is where you can register web routes for your application. These
  31. | routes are loaded by the RouteServiceProvider within a group which
  32. | contains the "web" middleware group. Now create something great!
  33. |
  34. */
  35. ini_set("auto_detect_line_endings", true);
  36. date_default_timezone_set('Europe/Rome');
  37. Route::get('/test_fb', function(){
  38. print env('FACEBOOK_ACCESS_TOKEN', '');
  39. $n = News::findOrFail(41436);
  40. $n->notify(new FacebookPost());
  41. });
  42. Route::get('/update/sections', function () {
  43. $aPositions = array('big', 'small1', 'small2', 'small3', 'small4', 'small5', 'small6');
  44. $sections = Section::all();
  45. foreach($sections as $section)
  46. {
  47. print $section->name . "<br>";
  48. $section_id = $section->id;
  49. // Carico il layout
  50. $layout = $section->layout;
  51. /*$aExist = array();
  52. foreach($aPositions as $p)
  53. {
  54. if ($section[$p] != null)
  55. $aExist[] = $section[$p];
  56. }*/
  57. // Controllo se ci sono news che devono essere pubblicate appartenenti a questa sezione
  58. $checks = News::where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($section_id) {
  59. $q->where('region_1_id', '=', $section_id)->orWhere('region_2_id', '=', $section_id)->orWhere('section_id', '=', $section_id);
  60. })->where(function ($q) {
  61. $q->where('region_1_position', '<>', '')->orWhere('region_2_position', '<>', '')->orWhere('section_position', '<>', '');
  62. })->get();
  63. foreach($checks as $n)
  64. {
  65. // Controllo se questa news era già in qualche altra posizione
  66. $old_position = Section::where('big', '=', $n->id)
  67. ->orWhere('small1', '=', $n->id)
  68. ->orWhere('small2', '=', $n->id)
  69. ->orWhere('small3', '=', $n->id)
  70. ->orWhere('small4', '=', $n->id)
  71. ->orWhere('small5', '=', $n->id)
  72. ->orWhere('small6', '=', $n->id)->get();
  73. if ($old_position->count() > 0)
  74. {
  75. foreach($old_position as $old_p)
  76. {
  77. foreach($aPositions as $p)
  78. {
  79. if ($old_p[$p] == $n->id)
  80. {
  81. $old_p[$p] = '';
  82. $old_p->save();
  83. }
  84. }
  85. }
  86. }
  87. // Metto la news nella posizione dove deve essere messa
  88. foreach($aPositions as $p)
  89. {
  90. if ($n->section_id == $section_id && $n->section_position == $p)
  91. {
  92. print "Metto la news " . $n->title . " nella posizione " . $p . " della sezione/regione " . $section->name . "<br>";
  93. $section[$p] = $n->id;
  94. $section->save();
  95. $n->section_position = '';
  96. if (!$n->published)
  97. {
  98. //$n->notify(new FacebookPost());
  99. //$n->notify(new TwitterPost());
  100. $n->published = true;
  101. }
  102. $n->save();
  103. }
  104. if ($n->region_1_id == $section_id && $n->region_1_position == $p)
  105. {
  106. print "Metto la news " . $n->title . " nella posizione " . $p . " della sezione/regione " . $section->name . "<br>";
  107. $section[$p] = $n->id;
  108. $section->save();
  109. $n->region_1_position = '';
  110. if (!$n->published)
  111. {
  112. // $n->notify(new FacebookPost());
  113. $n->notify(new TwitterPost());
  114. $n->published = true;
  115. }
  116. $n->save();
  117. }
  118. if ($n->region_2_id == $section_id && $n->region_2_position == $p)
  119. {
  120. print "Metto la news " . $n->title . " nella posizione " . $p . " della sezione/regione " . $section->name . "<br>";
  121. $section[$p] = $n->id;
  122. $section->save();
  123. $n->region_2_position = '';
  124. if (!$n->published)
  125. {
  126. // $n->notify(new FacebookPost());
  127. $n->notify(new TwitterPost());
  128. $n->published = true;
  129. }
  130. $n->save();
  131. }
  132. }
  133. }
  134. }
  135. $sections = Section::all();
  136. foreach($sections as $section)
  137. {
  138. $aExist = array();
  139. foreach($aPositions as $p)
  140. {
  141. if ($section[$p] != null)
  142. $aExist[] = $section[$p];
  143. }
  144. // Riempio i vuoti
  145. $news = News::whereNotIn('id', $aExist)->where(function ($q) use ($section_id) {
  146. $q->where('section_id', '=', $section_id)->orWhere('region_1_id', '=', $section_id)->orWhere('region_2_id', '=', $section_id);
  147. })->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  148. $idx = 0;
  149. if ($section->big == '')
  150. {
  151. $section->big = @$news[$idx]->id;
  152. $idx++;
  153. }
  154. if ($section->small1 == '')
  155. {
  156. $section->small1 = @$news[$idx]->id;
  157. $idx++;
  158. }
  159. if ($section->small2 == '')
  160. {
  161. $section->small2 = @$news[$idx]->id;
  162. $idx++;
  163. }
  164. if ($section->small3 == '')
  165. {
  166. $section->small3 = @$news[$idx]->id;
  167. $idx++;
  168. }
  169. if ($layout == 'layout_3' || $layout == 'layout_4' || $layout == 'layout_5')
  170. {
  171. if ($section->small4 == '')
  172. {
  173. $section->small4 = @$news[$idx]->id;
  174. $idx++;
  175. }
  176. if ($layout == 'layout_4')
  177. {
  178. if ($section->small5 == '')
  179. {
  180. $section->small5 = @$news[$idx]->id;
  181. $idx++;
  182. }
  183. if ($section->small6 == '')
  184. {
  185. $section->small6 = @$news[$idx]->id;
  186. $idx++;
  187. }
  188. }
  189. else
  190. {
  191. $section->small5 = '';
  192. $section->small6 = '';
  193. }
  194. }
  195. else
  196. {
  197. $section->small4 = '';
  198. $section->small5 = '';
  199. $section->small6 = '';
  200. }
  201. $section->save();
  202. }
  203. });
  204. Route::get('sitemap.xml', function() {
  205. // create new sitemap object
  206. $sitemap = App::make('sitemap');
  207. // set cache key (string), duration in minutes (Carbon|Datetime|int), turn on/off (boolean)
  208. // by default cache is disabled
  209. $sitemap->setCache('laravel.sitemap', 60);
  210. // check if there is cached sitemap and build new only if is not
  211. if (!$sitemap->isCached())
  212. {
  213. // add item to the sitemap (url, date, priority, freq)
  214. $sitemap->add(URL::to('/'), date("Y-m-d H:i:s"), '1.0', 'daily');
  215. $sections = Section::orderBy('position')->get();
  216. foreach($sections as $section)
  217. $sitemap->add(URL::to('/' . $section->slug), date("Y-m-d H:i:s", strtotime($section->updated_at)), '0.9', 'daily');
  218. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  219. foreach($pages as $page)
  220. $sitemap->add(URL::to('/' . $page->slug), date("Y-m-d H:i:s", strtotime($page->updated_at)), '0.9', 'daily');
  221. $events = Event::where('online', '=', true)->orderBy('title')->get();
  222. foreach($events as $event)
  223. $sitemap->add(URL::to('/' . $event->slug), date("Y-m-d H:i:s", strtotime($event->updated_at)), '0.9', 'daily');
  224. $season_id = @Season::where('default', '=', true)->first()->id;
  225. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  226. $calendars = array();
  227. foreach($cals as $c)
  228. {
  229. if ($c->category->grp != '')
  230. {
  231. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  232. if ($c->group_id > 0)
  233. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  234. else
  235. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  236. }
  237. }
  238. foreach($calendars as $type => $categories)
  239. {
  240. foreach($categories as $category => $groups)
  241. {
  242. if(is_array($groups))
  243. {
  244. foreach($groups as $group => $cal)
  245. {
  246. $sitemap->add(URL::to('/calendario/' . Str::slug($category) . "-" . Str::slug($group) . "/" . $cal), date("Y-m-d H:i:s"), '0.9', 'daily');
  247. }
  248. }
  249. else
  250. $sitemap->add(URL::to('/calendario/' . Str::slug($category) . "-" . Str::slug($groups)), date("Y-m-d H:i:s"), '0.9', 'daily');
  251. }
  252. }
  253. //$news = News::where('online', '=', true)->where('breaking_news', '=', false)->orderBy('date', 'DESC')->get();
  254. //foreach($news as $n)
  255. // $sitemap->add(URL::to('/' . $n->slug), date("Y-m-d H:i:s", strtotime($n->updated_at)), '0.9', 'hourly');
  256. //$cals = Calendar::orderBy('position')->get();
  257. //foreach($cals as $c)
  258. // $sitemap->add(URL::to('/' . $c->slug), date("Y-m-d H:i:s", strtotime($c->updated_at)), '0.9', 'daily');
  259. /*
  260. //$sitemap->add(URL::to('page'), '2012-08-26T12:30:00+02:00', '0.9', 'monthly');
  261. /*
  262. // add item with translations (url, date, priority, freq, images, title, translations)
  263. $translations = [
  264. ['language' => 'fr', 'url' => URL::to('pageFr')],
  265. ['language' => 'de', 'url' => URL::to('pageDe')],
  266. ['language' => 'bg', 'url' => URL::to('pageBg')],
  267. ];
  268. $sitemap->add(URL::to('pageEn'), '2015-06-24T14:30:00+02:00', '0.9', 'monthly', [], null, $translations);
  269. // add item with images
  270. $images = [
  271. ['url' => URL::to('images/pic1.jpg'), 'title' => 'Image title', 'caption' => 'Image caption', 'geo_location' => 'Plovdiv, Bulgaria'],
  272. ['url' => URL::to('images/pic2.jpg'), 'title' => 'Image title2', 'caption' => 'Image caption2'],
  273. ['url' => URL::to('images/pic3.jpg'), 'title' => 'Image title3'],
  274. ];
  275. $sitemap->add(URL::to('post-with-images'), '2015-06-24T14:30:00+02:00', '0.9', 'monthly', $images);
  276. // get all posts from db
  277. $posts = DB::table('posts')->orderBy('created_at', 'desc')->get();
  278. // add every post to the sitemap
  279. foreach ($posts as $post) {
  280. $sitemap->add($post->slug, $post->modified, $post->priority, $post->freq);
  281. }*/
  282. }
  283. // show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
  284. return $sitemap->render('xml');
  285. });
  286. Route::get('/', function () {
  287. $home = Home::first();
  288. if ($home != null)
  289. $home->loadData();
  290. $aHome = array();
  291. if ($home->image != '')
  292. {
  293. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  294. }
  295. if ($home->image_2 != '')
  296. {
  297. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  298. }
  299. if ($home->image_3 != '')
  300. {
  301. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  302. }
  303. if ($home->image_4 != '')
  304. {
  305. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  306. }
  307. if ($home->image_5 != '')
  308. {
  309. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  310. }
  311. if (sizeof($aHome) > 0)
  312. {
  313. $rnd = 0;//rand (0, sizeof($aHome) - 1);
  314. $home->image = $aHome[$rnd]["image"];
  315. $home->url = $aHome[$rnd]["url"];
  316. }
  317. $show_top = true;
  318. if ($home->banner_right_big != '' || $home->banner_right_big_2 != '' || $home->banner_right_big_3 != '' || $home->banner_right_big_google != '')
  319. $show_top = false;
  320. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  321. $events = Event::where('online', '=', true)->orderBy('title')->get();
  322. // $sections = Section::where('type', '=', 'section')->orderBy('position')->get();
  323. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  324. $sections = Section::where('layout', '!=', '')->orderBy('position')->get();
  325. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  326. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  327. //if($breaking_news->count() == 0)
  328. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  329. $videos = Video::where('online', '=', true)->limit(10)->orderBy('position')->get();
  330. foreach($videos as $i => $v)
  331. {
  332. $x = $v->url;
  333. $x = str_replace("https", "", $x);
  334. $x = str_replace("http", "", $x);
  335. $v->url = $x;
  336. }
  337. $season_id = @Season::where('default', '=', true)->first()->id;
  338. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  339. $calendars = array();
  340. foreach($cals as $c)
  341. {
  342. if ($c->category->grp != '')
  343. {
  344. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  345. if ($c->group_id > 0)
  346. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  347. else
  348. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  349. }
  350. }
  351. // $sections_after = Section::where('type', '=', 'section')->where('after', '=', true)->where('layout', '!=', '')->orderBy('position')->get();
  352. return view('index', compact('home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome', 'show_top'));
  353. });
  354. Route::get('/videos', function(){
  355. $videos = Video::where('online', '=', true)->orderBy('date', 'DESC')->get();
  356. $home = Home::first();
  357. if ($home != null)
  358. $home->loadData();
  359. $aHome = array();
  360. if ($home->image != '')
  361. {
  362. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  363. }
  364. if ($home->image_2 != '')
  365. {
  366. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  367. }
  368. if ($home->image_3 != '')
  369. {
  370. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  371. }
  372. if ($home->image_4 != '')
  373. {
  374. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  375. }
  376. if ($home->image_5 != '')
  377. {
  378. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  379. }
  380. if (sizeof($aHome) > 0)
  381. {
  382. $rnd = rand (0, sizeof($aHome) - 1);
  383. $home->image = $aHome[$rnd]["image"];
  384. $home->url = $aHome[$rnd]["url"];
  385. }
  386. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  387. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  388. $events = Event::where('online', '=', true)->orderBy('title')->get();
  389. $sections = Section::orderBy('position')->get();
  390. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  391. //if($breaking_news->count() == 0)
  392. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  393. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  394. $season_id = @Season::where('default', '=', true)->first()->id;
  395. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  396. /*$calendars = array();
  397. foreach($cals as $c)
  398. {
  399. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  400. if ($c->group_id > 0)
  401. $calendars[$type][$c->category->name][$c->group->name] = $c->id;
  402. else
  403. $calendars[$type][$c->category->name] = $c->id;
  404. }*/
  405. $calendars = array();
  406. foreach($cals as $c)
  407. {
  408. if ($c->category->grp != '')
  409. {
  410. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  411. if ($c->group_id > 0)
  412. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  413. else
  414. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  415. }
  416. }
  417. return view('video', compact('videos', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome'));
  418. });
  419. Route::get('/ricerca', function(){
  420. $news = News::where('id', -1)->get();
  421. $home = Home::first();
  422. if ($home != null)
  423. $home->loadData();
  424. $aHome = array();
  425. if ($home->image != '')
  426. {
  427. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  428. }
  429. if ($home->image_2 != '')
  430. {
  431. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  432. }
  433. if ($home->image_3 != '')
  434. {
  435. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  436. }
  437. if ($home->image_4 != '')
  438. {
  439. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  440. }
  441. if ($home->image_5 != '')
  442. {
  443. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  444. }
  445. if (sizeof($aHome) > 0)
  446. {
  447. $rnd = rand (0, sizeof($aHome) - 1);
  448. $home->image = $aHome[$rnd]["image"];
  449. $home->url = $aHome[$rnd]["url"];
  450. }
  451. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  452. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  453. $events = Event::where('online', '=', true)->orderBy('title')->get();
  454. $sections = Section::orderBy('position')->get();
  455. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  456. //if($breaking_news->count() == 0)
  457. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  458. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  459. $season_id = @Season::where('default', '=', true)->first()->id;
  460. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  461. $calendars = array();
  462. foreach($cals as $c)
  463. {
  464. if ($c->category->grp != '')
  465. {
  466. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  467. if ($c->group_id > 0)
  468. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  469. else
  470. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  471. }
  472. }
  473. $search = '';
  474. $videos = array();
  475. return view('search', compact('news', 'search', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome'));
  476. });
  477. Route::post('/ricerca', function(){
  478. $search = $_POST["search"];
  479. if ($search != '')
  480. {
  481. $news = News::where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->where(function ($q) use ($search) {
  482. $q->where('title', 'like', '%' . $search . '%')
  483. ->orWhere('title_region_1', 'like', '%' . $search . '%')
  484. ->orWhere('title_region_2', 'like', '%' . $search . '%')
  485. ->orWhere('text_short', 'like', '%' . $search . '%')
  486. ->orWhere('text', 'like', '%' . $search . '%');
  487. })->orderBy('date', 'DESC')->get();
  488. }
  489. else
  490. $news = News::where('id', -1)->get();
  491. $home = Home::first();
  492. if ($home != null)
  493. $home->loadData();
  494. $aHome = array();
  495. if ($home->image != '')
  496. {
  497. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  498. }
  499. if ($home->image_2 != '')
  500. {
  501. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  502. }
  503. if ($home->image_3 != '')
  504. {
  505. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  506. }
  507. if ($home->image_4 != '')
  508. {
  509. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  510. }
  511. if ($home->image_5 != '')
  512. {
  513. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  514. }
  515. if (sizeof($aHome) > 0)
  516. {
  517. $rnd = rand (0, sizeof($aHome) - 1);
  518. $home->image = $aHome[$rnd]["image"];
  519. $home->url = $aHome[$rnd]["url"];
  520. }
  521. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  522. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  523. $events = Event::where('online', '=', true)->orderBy('title')->get();
  524. $sections = Section::orderBy('position')->get();
  525. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  526. //if($breaking_news->count() == 0)
  527. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  528. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  529. $season_id = @Season::where('default', '=', true)->first()->id;
  530. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  531. $calendars = array();
  532. foreach($cals as $c)
  533. {
  534. if ($c->category->grp != '')
  535. {
  536. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  537. if ($c->group_id > 0)
  538. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  539. else
  540. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  541. }
  542. }
  543. $videos = array();
  544. return view('search', compact('news', 'search', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome'));
  545. });
  546. Route::get('/eventi', function(){
  547. $news = News::where('id', -1)->get();
  548. $home = Home::first();
  549. if ($home != null)
  550. $home->loadData();
  551. $aHome = array();
  552. if ($home->image != '')
  553. {
  554. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  555. }
  556. if ($home->image_2 != '')
  557. {
  558. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  559. }
  560. if ($home->image_3 != '')
  561. {
  562. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  563. }
  564. if ($home->image_4 != '')
  565. {
  566. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  567. }
  568. if ($home->image_5 != '')
  569. {
  570. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  571. }
  572. if (sizeof($aHome) > 0)
  573. {
  574. $rnd = rand (0, sizeof($aHome) - 1);
  575. $home->image = $aHome[$rnd]["image"];
  576. $home->url = $aHome[$rnd]["url"];
  577. }
  578. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  579. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  580. $events = Event::where('online', '=', true)->orderBy('title')->get();
  581. $sections = Section::orderBy('position')->get();
  582. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  583. //if($breaking_news->count() == 0)
  584. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  585. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  586. $season_id = @Season::where('default', '=', true)->first()->id;
  587. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  588. $calendars = array();
  589. foreach($cals as $c)
  590. {
  591. if ($c->category->grp != '')
  592. {
  593. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  594. if ($c->group_id > 0)
  595. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  596. else
  597. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  598. }
  599. }
  600. $videos = array();
  601. return view('events', compact('news', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome'));
  602. });
  603. Route::get('/archivio', function() {
  604. $news = News::where('id', -1)->get();
  605. $home = Home::first();
  606. if ($home != null) {
  607. $home->loadData();
  608. }
  609. $aHome = array();
  610. if ($home->image != '')
  611. {
  612. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  613. }
  614. if ($home->image_2 != '')
  615. {
  616. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  617. }
  618. if ($home->image_3 != '')
  619. {
  620. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  621. }
  622. if ($home->image_4 != '')
  623. {
  624. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  625. }
  626. if ($home->image_5 != '')
  627. {
  628. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  629. }
  630. if (sizeof($aHome) > 0)
  631. {
  632. $rnd = rand (0, sizeof($aHome) - 1);
  633. $home->image = $aHome[$rnd]["image"];
  634. $home->url = $aHome[$rnd]["url"];
  635. }
  636. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  637. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  638. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  639. $season_id = @Season::where('default', '=', true)->first()->id;
  640. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  641. $archivedCalendars = Calendar::where('archived', true)
  642. ->with(['category', 'group']) // Eager load relationships
  643. ->get();
  644. $calendars = array();
  645. foreach($cals as $c)
  646. {
  647. if ($c->category->grp != '')
  648. {
  649. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  650. if ($c->group_id > 0)
  651. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  652. else
  653. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  654. }
  655. }
  656. $seasons = Season::where('default', false)->orderBy('name', 'desc')->get();
  657. $sections = Section::where('type', '=', 'section')
  658. ->orderBy('position')
  659. ->get();
  660. $regions = Section::where('type', '=', 'region')
  661. ->orderBy('name')
  662. ->get();
  663. $categories = Category::orderBy('name')->get();
  664. $groups = Group::orderBy('name')->get();
  665. $seasonsForJs = $seasons->map(function($season) {
  666. return [
  667. 'id' => $season->id,
  668. 'name' => $season->name
  669. ];
  670. });
  671. return view('calendar_archive', compact(
  672. 'news',
  673. 'home',
  674. 'sections',
  675. 'sections_menu',
  676. 'regions',
  677. 'pages',
  678. 'breaking_news',
  679. 'seasons',
  680. 'seasonsForJs',
  681. 'categories',
  682. 'groups',
  683. 'archivedCalendars',
  684. 'aHome',
  685. 'calendars'
  686. ));
  687. });
  688. Route::get('/api/archive/calendars/search', function(Request $request) {
  689. $query = Calendar::with(['season', 'category', 'group']) // Eager load relationships
  690. ->where('archived', true);
  691. if ($request->season_id) {
  692. $query->where('season_id', $request->season_id);
  693. }
  694. if ($request->type) {
  695. $query->whereHas('category', function($q) use ($request) {
  696. $q->where('type', $request->type);
  697. });
  698. }
  699. if ($request->category_id) {
  700. $query->where('category_id', $request->category_id);
  701. }
  702. if ($request->group_id) {
  703. $query->where('group_id', $request->group_id);
  704. }
  705. $calendars = $query->orderBy('position')->get()
  706. ->map(function($calendar) {
  707. return [
  708. 'id' => $calendar->id,
  709. 'name' => $calendar->name,
  710. 'season' => $calendar->season ? $calendar->season->name : '',
  711. 'category' => $calendar->category ? $calendar->category->name : '',
  712. 'group' => $calendar->group ? $calendar->group->name : '',
  713. 'type' => $calendar->category ? $calendar->category->type : '',
  714. 'position' => $calendar->position
  715. ];
  716. });
  717. return response()->json([
  718. 'success' => true,
  719. 'data' => $calendars
  720. ]);
  721. });
  722. Route::get('/video/{id}', function ($id) {
  723. $video = Video::findOrFail($id);
  724. if ($video->file != '')
  725. {
  726. $html = '<video width="640" height="480" controls>
  727. <source src="/files/videos/' . $video->file . '" type="video/mp4">
  728. Your browser does not support the video tag.
  729. </video>';
  730. print $html;
  731. }
  732. else
  733. print $video->embed;
  734. });
  735. Route::get('/section/{id}', function ($id) {
  736. $home = Home::first();
  737. if ($home != null)
  738. $home->loadData();
  739. $aHome = array();
  740. if ($home->image != '')
  741. {
  742. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  743. }
  744. if ($home->image_2 != '')
  745. {
  746. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  747. }
  748. if ($home->image_3 != '')
  749. {
  750. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  751. }
  752. if (sizeof($aHome) > 0)
  753. {
  754. $rnd = rand (0, sizeof($aHome) - 1);
  755. $home->image = $aHome[$rnd]["image"];
  756. $home->url = $aHome[$rnd]["url"];
  757. }
  758. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  759. $events = Event::where('online', '=', true)->orderBy('title')->get();
  760. //$sections = Section::orderBy('position')->get();
  761. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  762. $sections = Section::where('layout', '!=', '')->orderBy('position')->get();
  763. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  764. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  765. //if($breaking_news->count() == 0)
  766. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  767. $news = News::where('section_id', '=', $id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  768. $season_id = @Season::where('default', '=', true)->first()->id;
  769. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  770. $calendars = array();
  771. foreach($cals as $c)
  772. {
  773. if ($c->category->grp != '')
  774. {
  775. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  776. if ($c->group_id > 0)
  777. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  778. else
  779. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  780. }
  781. }
  782. return view('section', compact('home', 'news', 'sections', 'sections_menu', 'pages', 'regions', 'events', 'breaking_news', 'calendars', 'aHome'));
  783. });
  784. Route::get('/admin', function () {
  785. if (Auth::check())
  786. return Redirect::to('/admin/dashboard');
  787. else
  788. return view('admin');
  789. });
  790. Route::get('/logout', function () {
  791. Auth::logout();
  792. return Redirect::to('/admin');
  793. });
  794. Route::post('/login', function(){
  795. if ($user = Auth::attempt(['email' => $_POST["email"], 'password' => $_POST["password"]]))
  796. return Redirect::to('/admin/dashboard');
  797. else
  798. return view('admin')->with('message', 'Errore login');
  799. });
  800. Route::group(['middleware' => 'auth'], function () {
  801. Route::prefix('admin')->group(function () {
  802. Route::get('/dashboard', function ()
  803. {
  804. $sections = Section::where('type', '=', 'section')->orderBy('position')->get();
  805. $regions = Section::where('type', '=', 'region')->orderBy('position')->get();
  806. return view('admin.dashboard', compact('sections', 'regions'));
  807. });
  808. Route::get('/home', function () {
  809. $home = Home::first();
  810. if ($home == null)
  811. {
  812. $home = new Home();
  813. $home->save();
  814. }
  815. $home->loadData();
  816. $aAssigned = array();
  817. if ($home->slide1 != '')
  818. $aAssigned[] = $home->slide1->id;
  819. if ($home->left1 != '')
  820. $aAssigned[] = $home->left1->id;
  821. if ($home->left2 != '')
  822. $aAssigned[] = $home->left2->id;
  823. if ($home->left3 != '')
  824. $aAssigned[] = $home->left3->id;
  825. if ($home->right1 != '')
  826. $aAssigned[] = $home->right1->id;
  827. if ($home->right2 != '')
  828. $aAssigned[] = $home->right2->id;
  829. if ($home->right3 != '')
  830. $aAssigned[] = $home->right3->id;
  831. $news = News::where('online', '=', 1)->whereNotIn('id', $aAssigned)->orderBy('date', 'DESC')->limit(1000)->get();
  832. return view('admin.home',compact('home', 'news'));
  833. })->name('home');
  834. Route::post('/home', function () {
  835. $home = Home::first();
  836. if ($home == null)
  837. $home = new Home();
  838. $slide1 = isset($_POST["slide1"]) ? $_POST["slide1"] : '';
  839. $left1 = isset($_POST["left1"]) ? $_POST["left1"] : '';
  840. $left2 = isset($_POST["left2"]) ? $_POST["left2"] : '';
  841. $left3 = isset($_POST["left3"]) ? $_POST["left3"] : '';
  842. $left4 = isset($_POST["left4"]) ? $_POST["left4"] : '';
  843. $left5 = isset($_POST["left5"]) ? $_POST["left5"] : '';
  844. $right1 = isset($_POST["right1"]) ? $_POST["right1"] : '';
  845. $right2 = isset($_POST["right2"]) ? $_POST["right2"] : '';
  846. $right3 = isset($_POST["right3"]) ? $_POST["right3"] : '';
  847. $right4 = isset($_POST["right4"]) ? $_POST["right4"] : '';
  848. $right5 = isset($_POST["right5"]) ? $_POST["right5"] : '';
  849. if (isset($_POST["delete_image"]))
  850. {
  851. $image = '';
  852. $home->image = $image;
  853. }
  854. else
  855. {
  856. if(isset($_POST["image"]))
  857. {
  858. $file = $_POST["image"];
  859. $filename = time() . '_' . $file->getClientOriginalName();
  860. $path = public_path('files');
  861. $_POST["image"]->move($path, $filename);
  862. $image = $filename;
  863. $home->image = $image;
  864. }
  865. }
  866. //$url = isset($_POST["url"]) ? $_POST["url"] : '';
  867. $home->slide1 = $slide1;
  868. $home->left1 = $left1;
  869. $home->left2 = $left2;
  870. $home->left3 = $left3;
  871. $home->left4 = $left4;
  872. $home->left5 = $left5;
  873. $home->right1 = $right1;
  874. $home->right2 = $right2;
  875. $home->right3 = $right3;
  876. $home->right4 = $right4;
  877. $home->right5 = $right5;
  878. //$home->url = $url;
  879. $home->save();
  880. return Redirect::to('/admin/home');
  881. })->name('home');
  882. Route::get('/home_adv', function () {
  883. $home = Home::first();
  884. if ($home == null)
  885. {
  886. $home = new Home();
  887. $home->save();
  888. }
  889. $home->loadData();
  890. return view('admin.home_adv',compact('home'));
  891. })->name('home_adv');
  892. Route::post('/home_adv', function () {
  893. $home = Home::first();
  894. if ($home == null)
  895. $home = new Home();
  896. if (isset($_POST["delete_image"]))
  897. {
  898. $image = '';
  899. $home->image = $image;
  900. }
  901. else
  902. {
  903. if(request()->image)
  904. {
  905. $file = request()->image;
  906. $filename = time() . '_' . $file->getClientOriginalName();
  907. $path = public_path('files');
  908. request()->image->move($path, $filename);
  909. $image = $filename;
  910. $home->image = $image;
  911. }
  912. }
  913. $url = isset($_POST["url"]) ? $_POST["url"] : '';
  914. $home->url = $url;
  915. if (isset($_POST["delete_image_2"]))
  916. {
  917. $image_2 = '';
  918. $home->image_2 = $image_2;
  919. }
  920. else
  921. {
  922. if(request()->image_2)
  923. {
  924. $file = request()->image_2;
  925. $filename = time() . '_' . $file->getClientOriginalName();
  926. $path = public_path('files');
  927. request()->image_2->move($path, $filename);
  928. $image_2 = $filename;
  929. $home->image_2 = $image_2;
  930. }
  931. }
  932. $url_2 = isset($_POST["url_2"]) ? $_POST["url_2"] : '';
  933. $home->url_2 = $url_2;
  934. if (isset($_POST["delete_image_3"]))
  935. {
  936. $image_3 = '';
  937. $home->image_3 = $image_3;
  938. }
  939. else
  940. {
  941. if(request()->image_3)
  942. {
  943. $file = request()->image_3;
  944. $filename = time() . '_' . $file->getClientOriginalName();
  945. $path = public_path('files');
  946. request()->image_3->move($path, $filename);
  947. $image_3 = $filename;
  948. $home->image_3 = $image_3;
  949. }
  950. }
  951. $url_3 = isset($_POST["url_3"]) ? $_POST["url_3"] : '';
  952. $home->url_3 = $url_3;
  953. if (isset($_POST["delete_image_4"]))
  954. {
  955. $image_4 = '';
  956. $home->image_4 = $image_4;
  957. }
  958. else
  959. {
  960. if(request()->image_4)
  961. {
  962. $file = request()->image_4;
  963. $filename = time() . '_' . $file->getClientOriginalName();
  964. $path = public_path('files');
  965. request()->image_4->move($path, $filename);
  966. $image_4 = $filename;
  967. $home->image_4 = $image_4;
  968. }
  969. }
  970. $url_4 = isset($_POST["url_4"]) ? $_POST["url_4"] : '';
  971. $home->url_4 = $url_4;
  972. if (isset($_POST["delete_image_5"]))
  973. {
  974. $image_5 = '';
  975. $home->image_5 = $image_5;
  976. }
  977. else
  978. {
  979. if(request()->image_5)
  980. {
  981. $file = request()->image_5;
  982. $filename = time() . '_' . $file->getClientOriginalName();
  983. $path = public_path('files');
  984. request()->image_5->move($path, $filename);
  985. $image_5 = $filename;
  986. $home->image_5 = $image_5;
  987. }
  988. }
  989. $url_5 = isset($_POST["url_5"]) ? $_POST["url_5"] : '';
  990. $home->url_5 = $url_5;
  991. if (isset($_POST["delete_banner_top"]))
  992. {
  993. $banner_top = '';
  994. $home->banner_top = $banner_top;
  995. }
  996. else
  997. {
  998. if(request()->banner_top)
  999. {
  1000. $file = request()->banner_top;
  1001. $filename = time() . '_' . $file->getClientOriginalName();
  1002. $path = public_path('files');
  1003. request()->banner_top->move($path, $filename);
  1004. $banner_top = $filename;
  1005. $home->banner_top = $banner_top;
  1006. }
  1007. }
  1008. $banner_top_url = isset($_POST["banner_top_url"]) ? $_POST["banner_top_url"] : '';
  1009. $home->banner_top_url = $banner_top_url;
  1010. if (isset($_POST["delete_banner_top_2"]))
  1011. {
  1012. $banner_top_2 = '';
  1013. $home->banner_top_2 = $banner_top_2;
  1014. }
  1015. else
  1016. {
  1017. if(request()->banner_top_2)
  1018. {
  1019. $file = request()->banner_top_2;
  1020. $filename = time() . '_' . $file->getClientOriginalName();
  1021. $path = public_path('files');
  1022. request()->banner_top_2->move($path, $filename);
  1023. $banner_top_2 = $filename;
  1024. $home->banner_top_2 = $banner_top_2;
  1025. }
  1026. }
  1027. $banner_top_2_url = isset($_POST["banner_top_2_url"]) ? $_POST["banner_top_2_url"] : '';
  1028. $home->banner_top_2_url = $banner_top_2_url;
  1029. if (isset($_POST["delete_banner_top_3"]))
  1030. {
  1031. $banner_top_3 = '';
  1032. $home->banner_top_3 = $banner_top_3;
  1033. }
  1034. else
  1035. {
  1036. if(request()->banner_top_3)
  1037. {
  1038. $file = request()->banner_top_3;
  1039. $filename = time() . '_' . $file->getClientOriginalName();
  1040. $path = public_path('files');
  1041. request()->banner_top_3->move($path, $filename);
  1042. $banner_top_3 = $filename;
  1043. $home->banner_top_3 = $banner_top_3;
  1044. }
  1045. }
  1046. $banner_top_3_url = isset($_POST["banner_top_3_url"]) ? $_POST["banner_top_3_url"] : '';
  1047. $home->banner_top_3_url = $banner_top_3_url;
  1048. if (isset($_POST["delete_banner_top_4"]))
  1049. {
  1050. $banner_top_4 = '';
  1051. $home->banner_top_4 = $banner_top_4;
  1052. }
  1053. else
  1054. {
  1055. if(request()->banner_top_4)
  1056. {
  1057. $file = request()->banner_top_4;
  1058. $filename = time() . '_' . $file->getClientOriginalName();
  1059. $path = public_path('files');
  1060. request()->banner_top_4->move($path, $filename);
  1061. $banner_top_4 = $filename;
  1062. $home->banner_top_4 = $banner_top_4;
  1063. }
  1064. }
  1065. $banner_top_4_url = isset($_POST["banner_top_4_url"]) ? $_POST["banner_top_4_url"] : '';
  1066. $home->banner_top_4_url = $banner_top_4_url;
  1067. if (isset($_POST["delete_banner_top_5"]))
  1068. {
  1069. $banner_top_5 = '';
  1070. $home->banner_top_5 = $banner_top_5;
  1071. }
  1072. else
  1073. {
  1074. if(request()->banner_top_5)
  1075. {
  1076. $file = request()->banner_top_5;
  1077. $filename = time() . '_' . $file->getClientOriginalName();
  1078. $path = public_path('files');
  1079. request()->banner_top_5->move($path, $filename);
  1080. $banner_top_5 = $filename;
  1081. $home->banner_top_5 = $banner_top_5;
  1082. }
  1083. }
  1084. $banner_top_5_url = isset($_POST["banner_top_5_url"]) ? $_POST["banner_top_5_url"] : '';
  1085. $home->banner_top_5_url = $banner_top_5_url;
  1086. $banner_top_google = isset($_POST["banner_top_google"]) ? $_POST["banner_top_google"] : '';
  1087. $home->banner_top_google = $banner_top_google;
  1088. if (isset($_POST["delete_banner_underb"]))
  1089. {
  1090. $banner_underb = '';
  1091. $home->banner_underb = $banner_underb;
  1092. }
  1093. else
  1094. {
  1095. if(request()->banner_underb)
  1096. {
  1097. $file = request()->banner_underb;
  1098. $filename = time() . '_' . $file->getClientOriginalName();
  1099. $path = public_path('files');
  1100. request()->banner_underb->move($path, $filename);
  1101. $banner_underb = $filename;
  1102. $home->banner_underb = $banner_underb;
  1103. }
  1104. }
  1105. $banner_underb_url = isset($_POST["banner_underb_url"]) ? $_POST["banner_underb_url"] : '';
  1106. $home->banner_underb_url = $banner_underb_url;
  1107. if (isset($_POST["delete_banner_underb_2"]))
  1108. {
  1109. $banner_underb_2 = '';
  1110. $home->banner_underb_2 = $banner_underb_2;
  1111. }
  1112. else
  1113. {
  1114. if(request()->banner_underb_2)
  1115. {
  1116. $file = request()->banner_underb_2;
  1117. $filename = time() . '_' . $file->getClientOriginalName();
  1118. $path = public_path('files');
  1119. request()->banner_underb_2->move($path, $filename);
  1120. $banner_underb_2 = $filename;
  1121. $home->banner_underb_2 = $banner_underb_2;
  1122. }
  1123. }
  1124. $banner_underb_2_url = isset($_POST["banner_underb_2_url"]) ? $_POST["banner_underb_2_url"] : '';
  1125. $home->banner_underb_2_url = $banner_underb_2_url;
  1126. if (isset($_POST["delete_banner_underb_3"]))
  1127. {
  1128. $banner_underb_3 = '';
  1129. $home->banner_underb_3 = $banner_underb_3;
  1130. }
  1131. else
  1132. {
  1133. if(request()->banner_underb_3)
  1134. {
  1135. $file = request()->banner_underb_3;
  1136. $filename = time() . '_' . $file->getClientOriginalName();
  1137. $path = public_path('files');
  1138. request()->banner_underb_3->move($path, $filename);
  1139. $banner_underb_3 = $filename;
  1140. $home->banner_underb_3 = $banner_underb_3;
  1141. }
  1142. }
  1143. $banner_underb_3_url = isset($_POST["banner_underb_3_url"]) ? $_POST["banner_underb_3_url"] : '';
  1144. $home->banner_underb_3_url = $banner_underb_3_url;
  1145. if (isset($_POST["delete_banner_underb_4"]))
  1146. {
  1147. $banner_underb_4 = '';
  1148. $home->banner_underb_4 = $banner_underb_4;
  1149. }
  1150. else
  1151. {
  1152. if(request()->banner_underb_4)
  1153. {
  1154. $file = request()->banner_underb_4;
  1155. $filename = time() . '_' . $file->getClientOriginalName();
  1156. $path = public_path('files');
  1157. request()->banner_underb_4->move($path, $filename);
  1158. $banner_underb_4 = $filename;
  1159. $home->banner_underb_4 = $banner_underb_4;
  1160. }
  1161. }
  1162. $banner_underb_4_url = isset($_POST["banner_underb_4_url"]) ? $_POST["banner_underb_4_url"] : '';
  1163. $home->banner_underb_4_url = $banner_underb_4_url;
  1164. if (isset($_POST["delete_banner_underb_5"]))
  1165. {
  1166. $banner_underb_5 = '';
  1167. $home->banner_underb_5 = $banner_underb_5;
  1168. }
  1169. else
  1170. {
  1171. if(request()->banner_underb_5)
  1172. {
  1173. $file = request()->banner_underb_5;
  1174. $filename = time() . '_' . $file->getClientOriginalName();
  1175. $path = public_path('files');
  1176. request()->banner_underb_5->move($path, $filename);
  1177. $banner_underb_5 = $filename;
  1178. $home->banner_underb_5 = $banner_underb_5;
  1179. }
  1180. }
  1181. $banner_underb_5_url = isset($_POST["banner_underb_5_url"]) ? $_POST["banner_underb_5_url"] : '';
  1182. $home->banner_underb_5_url = $banner_underb_5_url;
  1183. $banner_underb_google = isset($_POST["banner_underb_google"]) ? $_POST["banner_underb_google"] : '';
  1184. $home->banner_underb_google = $banner_underb_google;
  1185. if (isset($_POST["delete_banner_middle"]))
  1186. {
  1187. $banner_middle = '';
  1188. $home->banner_middle = $banner_middle;
  1189. }
  1190. else
  1191. {
  1192. if(request()->banner_middle)
  1193. {
  1194. $file = request()->banner_middle;
  1195. $filename = time() . '_' . $file->getClientOriginalName();
  1196. $path = public_path('files');
  1197. request()->banner_middle->move($path, $filename);
  1198. $banner_middle = $filename;
  1199. $home->banner_middle = $banner_middle;
  1200. }
  1201. }
  1202. $banner_middle_url = isset($_POST["banner_middle_url"]) ? $_POST["banner_middle_url"] : '';
  1203. $home->banner_middle_url = $banner_middle_url;
  1204. if (isset($_POST["delete_banner_middle_2"]))
  1205. {
  1206. $banner_middle_2 = '';
  1207. $home->banner_middle_2 = $banner_middle_2;
  1208. }
  1209. else
  1210. {
  1211. if(request()->banner_middle_2)
  1212. {
  1213. $file = request()->banner_middle_2;
  1214. $filename = time() . '_' . $file->getClientOriginalName();
  1215. $path = public_path('files');
  1216. request()->banner_middle_2->move($path, $filename);
  1217. $banner_middle_2 = $filename;
  1218. $home->banner_middle_2 = $banner_middle_2;
  1219. }
  1220. }
  1221. $banner_middle_2_url = isset($_POST["banner_middle_2_url"]) ? $_POST["banner_middle_2_url"] : '';
  1222. $home->banner_middle_2_url = $banner_middle_2_url;
  1223. if (isset($_POST["delete_banner_middle_3"]))
  1224. {
  1225. $banner_middle_3 = '';
  1226. $home->banner_middle_3 = $banner_middle_3;
  1227. }
  1228. else
  1229. {
  1230. if(request()->banner_middle_3)
  1231. {
  1232. $file = request()->banner_middle_3;
  1233. $filename = time() . '_' . $file->getClientOriginalName();
  1234. $path = public_path('files');
  1235. request()->banner_middle_3->move($path, $filename);
  1236. $banner_middle_3 = $filename;
  1237. $home->banner_middle_3 = $banner_middle_3;
  1238. }
  1239. }
  1240. $banner_middle_3_url = isset($_POST["banner_middle_3_url"]) ? $_POST["banner_middle_3_url"] : '';
  1241. $home->banner_middle_3_url = $banner_middle_3_url;
  1242. if (isset($_POST["delete_banner_middle_4"]))
  1243. {
  1244. $banner_middle_4 = '';
  1245. $home->banner_middle_4 = $banner_middle_4;
  1246. }
  1247. else
  1248. {
  1249. if(request()->banner_middle_4)
  1250. {
  1251. $file = request()->banner_middle_4;
  1252. $filename = time() . '_' . $file->getClientOriginalName();
  1253. $path = public_path('files');
  1254. request()->banner_middle_4->move($path, $filename);
  1255. $banner_middle_4 = $filename;
  1256. $home->banner_middle_4 = $banner_middle_4;
  1257. }
  1258. }
  1259. $banner_middle_4_url = isset($_POST["banner_middle_4_url"]) ? $_POST["banner_middle_4_url"] : '';
  1260. $home->banner_middle_4_url = $banner_middle_4_url;
  1261. if (isset($_POST["delete_banner_middle_5"]))
  1262. {
  1263. $banner_middle_5 = '';
  1264. $home->banner_middle_5 = $banner_middle_5;
  1265. }
  1266. else
  1267. {
  1268. if(request()->banner_middle_5)
  1269. {
  1270. $file = request()->banner_middle_5;
  1271. $filename = time() . '_' . $file->getClientOriginalName();
  1272. $path = public_path('files');
  1273. request()->banner_middle_5->move($path, $filename);
  1274. $banner_middle_5 = $filename;
  1275. $home->banner_middle_5 = $banner_middle_5;
  1276. }
  1277. }
  1278. $banner_middle_5_url = isset($_POST["banner_middle_5_url"]) ? $_POST["banner_middle_5_url"] : '';
  1279. $home->banner_middle_5_url = $banner_middle_5_url;
  1280. $banner_middle_google = isset($_POST["banner_middle_google"]) ? $_POST["banner_middle_google"] : '';
  1281. $home->banner_middle_google = $banner_middle_google;
  1282. if (isset($_POST["delete_banner_first"]))
  1283. {
  1284. $banner_first = '';
  1285. $home->banner_first = $banner_first;
  1286. }
  1287. else
  1288. {
  1289. if(request()->banner_first)
  1290. {
  1291. $file = request()->banner_first;
  1292. $filename = time() . '_' . $file->getClientOriginalName();
  1293. $path = public_path('files');
  1294. request()->banner_first->move($path, $filename);
  1295. $banner_first = $filename;
  1296. $home->banner_first = $banner_first;
  1297. }
  1298. }
  1299. $banner_first_url = isset($_POST["banner_first_url"]) ? $_POST["banner_first_url"] : '';
  1300. $home->banner_first_url = $banner_first_url;
  1301. if (isset($_POST["delete_banner_first_2"]))
  1302. {
  1303. $banner_first_2 = '';
  1304. $home->banner_first_2 = $banner_first_2;
  1305. }
  1306. else
  1307. {
  1308. if(request()->banner_first_2)
  1309. {
  1310. $file = request()->banner_first_2;
  1311. $filename = time() . '_' . $file->getClientOriginalName();
  1312. $path = public_path('files');
  1313. request()->banner_first_2->move($path, $filename);
  1314. $banner_first_2 = $filename;
  1315. $home->banner_first_2 = $banner_first_2;
  1316. }
  1317. }
  1318. $banner_first_2_url = isset($_POST["banner_first_2_url"]) ? $_POST["banner_first_2_url"] : '';
  1319. $home->banner_first_2_url = $banner_first_2_url;
  1320. if (isset($_POST["delete_banner_first_3"]))
  1321. {
  1322. $banner_first_3 = '';
  1323. $home->banner_first_3 = $banner_first_3;
  1324. }
  1325. else
  1326. {
  1327. if(request()->banner_first_3)
  1328. {
  1329. $file = request()->banner_first_3;
  1330. $filename = time() . '_' . $file->getClientOriginalName();
  1331. $path = public_path('files');
  1332. request()->banner_first_3->move($path, $filename);
  1333. $banner_first_3 = $filename;
  1334. $home->banner_first_3 = $banner_first_3;
  1335. }
  1336. }
  1337. $banner_first_3_url = isset($_POST["banner_first_3_url"]) ? $_POST["banner_first_3_url"] : '';
  1338. $home->banner_first_3_url = $banner_first_3_url;
  1339. if (isset($_POST["delete_banner_first_4"]))
  1340. {
  1341. $banner_first_4 = '';
  1342. $home->banner_first_4 = $banner_first_4;
  1343. }
  1344. else
  1345. {
  1346. if(request()->banner_first_4)
  1347. {
  1348. $file = request()->banner_first_4;
  1349. $filename = time() . '_' . $file->getClientOriginalName();
  1350. $path = public_path('files');
  1351. request()->banner_first_4->move($path, $filename);
  1352. $banner_first_4 = $filename;
  1353. $home->banner_first_4 = $banner_first_4;
  1354. }
  1355. }
  1356. $banner_first_4_url = isset($_POST["banner_first_4_url"]) ? $_POST["banner_first_4_url"] : '';
  1357. $home->banner_first_4_url = $banner_first_4_url;
  1358. if (isset($_POST["delete_banner_first_5"]))
  1359. {
  1360. $banner_first_5 = '';
  1361. $home->banner_first_5 = $banner_first_5;
  1362. }
  1363. else
  1364. {
  1365. if(request()->banner_first_5)
  1366. {
  1367. $file = request()->banner_first_5;
  1368. $filename = time() . '_' . $file->getClientOriginalName();
  1369. $path = public_path('files');
  1370. request()->banner_first_5->move($path, $filename);
  1371. $banner_first_5 = $filename;
  1372. $home->banner_first_5 = $banner_first_5;
  1373. }
  1374. }
  1375. $banner_first_5_url = isset($_POST["banner_first_5_url"]) ? $_POST["banner_first_5_url"] : '';
  1376. $home->banner_first_5_url = $banner_first_5_url;
  1377. $banner_first_google = isset($_POST["banner_first_google"]) ? $_POST["banner_first_google"] : '';
  1378. $home->banner_first_google = $banner_first_google;
  1379. if (isset($_POST["delete_banner_right_top"]))
  1380. {
  1381. $banner_right_top = '';
  1382. $home->banner_right_top = $banner_right_top;
  1383. }
  1384. else
  1385. {
  1386. if(request()->banner_right_top)
  1387. {
  1388. $file = request()->banner_right_top;
  1389. $filename = time() . '_' . $file->getClientOriginalName();
  1390. $path = public_path('files');
  1391. request()->banner_right_top->move($path, $filename);
  1392. $banner_right_top = $filename;
  1393. $home->banner_right_top = $banner_right_top;
  1394. }
  1395. }
  1396. $banner_right_top_url = isset($_POST["banner_right_top_url"]) ? $_POST["banner_right_top_url"] : '';
  1397. $home->banner_right_top_url = $banner_right_top_url;
  1398. if (isset($_POST["delete_banner_right_top_2"]))
  1399. {
  1400. $banner_right_top_2 = '';
  1401. $home->banner_right_top_2 = $banner_right_top_2;
  1402. }
  1403. else
  1404. {
  1405. if(request()->banner_right_top_2)
  1406. {
  1407. $file = request()->banner_right_top_2;
  1408. $filename = time() . '_' . $file->getClientOriginalName();
  1409. $path = public_path('files');
  1410. request()->banner_right_top_2->move($path, $filename);
  1411. $banner_right_top_2 = $filename;
  1412. $home->banner_right_top_2 = $banner_right_top_2;
  1413. }
  1414. }
  1415. $banner_right_top_2_url = isset($_POST["banner_right_top_2_url"]) ? $_POST["banner_right_top_2_url"] : '';
  1416. $home->banner_right_top_2_url = $banner_right_top_2_url;
  1417. if (isset($_POST["delete_banner_right_top_3"]))
  1418. {
  1419. $banner_right_top_3 = '';
  1420. $home->banner_right_top_3 = $banner_right_top_3;
  1421. }
  1422. else
  1423. {
  1424. if(request()->banner_right_top_3)
  1425. {
  1426. $file = request()->banner_right_top_3;
  1427. $filename = time() . '_' . $file->getClientOriginalName();
  1428. $path = public_path('files');
  1429. request()->banner_right_top_3->move($path, $filename);
  1430. $banner_right_top_3 = $filename;
  1431. $home->banner_right_top_3 = $banner_right_top_3;
  1432. }
  1433. }
  1434. $banner_right_top_3_url = isset($_POST["banner_right_top_3_url"]) ? $_POST["banner_right_top_3_url"] : '';
  1435. $home->banner_right_top_3_url = $banner_right_top_3_url;
  1436. if (isset($_POST["delete_banner_right_top_4"]))
  1437. {
  1438. $banner_right_top_4 = '';
  1439. $home->banner_right_top_4 = $banner_right_top_4;
  1440. }
  1441. else
  1442. {
  1443. if(request()->banner_right_top_4)
  1444. {
  1445. $file = request()->banner_right_top_4;
  1446. $filename = time() . '_' . $file->getClientOriginalName();
  1447. $path = public_path('files');
  1448. request()->banner_right_top_4->move($path, $filename);
  1449. $banner_right_top_4 = $filename;
  1450. $home->banner_right_top_4 = $banner_right_top_4;
  1451. }
  1452. }
  1453. $banner_right_top_4_url = isset($_POST["banner_right_top_4_url"]) ? $_POST["banner_right_top_4_url"] : '';
  1454. $home->banner_right_top_4_url = $banner_right_top_4_url;
  1455. if (isset($_POST["delete_banner_right_top_5"]))
  1456. {
  1457. $banner_right_top_5 = '';
  1458. $home->banner_right_top_5 = $banner_right_top_5;
  1459. }
  1460. else
  1461. {
  1462. if(request()->banner_right_top_5)
  1463. {
  1464. $file = request()->banner_right_top_5;
  1465. $filename = time() . '_' . $file->getClientOriginalName();
  1466. $path = public_path('files');
  1467. request()->banner_right_top_5->move($path, $filename);
  1468. $banner_right_top_5 = $filename;
  1469. $home->banner_right_top_5 = $banner_right_top_5;
  1470. }
  1471. }
  1472. $banner_right_top_5_url = isset($_POST["banner_right_top_5_url"]) ? $_POST["banner_right_top_5_url"] : '';
  1473. $home->banner_right_top_5_url = $banner_right_top_5_url;
  1474. $banner_right_top_google = isset($_POST["banner_right_top_google"]) ? $_POST["banner_right_top_google"] : '';
  1475. $home->banner_right_top_google = $banner_right_top_google;
  1476. if (isset($_POST["delete_banner_right_bottom"]))
  1477. {
  1478. $banner_right_bottom = '';
  1479. $home->banner_right_bottom = $banner_right_bottom;
  1480. }
  1481. else
  1482. {
  1483. if(request()->banner_right_bottom)
  1484. {
  1485. $file = request()->banner_right_bottom;
  1486. $filename = time() . '_' . $file->getClientOriginalName();
  1487. $path = public_path('files');
  1488. request()->banner_right_bottom->move($path, $filename);
  1489. $banner_right_bottom = $filename;
  1490. $home->banner_right_bottom = $banner_right_bottom;
  1491. }
  1492. }
  1493. $banner_right_bottom_url = isset($_POST["banner_right_bottom_url"]) ? $_POST["banner_right_bottom_url"] : '';
  1494. $home->banner_right_bottom_url = $banner_right_bottom_url;
  1495. if (isset($_POST["delete_banner_right_bottom_2"]))
  1496. {
  1497. $banner_right_bottom_2 = '';
  1498. $home->banner_right_bottom_2 = $banner_right_bottom_2;
  1499. }
  1500. else
  1501. {
  1502. if(request()->banner_right_bottom_2)
  1503. {
  1504. $file = request()->banner_right_bottom_2;
  1505. $filename = time() . '_' . $file->getClientOriginalName();
  1506. $path = public_path('files');
  1507. request()->banner_right_bottom_2->move($path, $filename);
  1508. $banner_right_bottom_2 = $filename;
  1509. $home->banner_right_bottom_2 = $banner_right_bottom_2;
  1510. }
  1511. }
  1512. $banner_right_bottom_2_url = isset($_POST["banner_right_bottom_2_url"]) ? $_POST["banner_right_bottom_2_url"] : '';
  1513. $home->banner_right_bottom_2_url = $banner_right_bottom_2_url;
  1514. if (isset($_POST["delete_banner_right_bottom_3"]))
  1515. {
  1516. $banner_right_bottom_3 = '';
  1517. $home->banner_right_bottom_3 = $banner_right_bottom_3;
  1518. }
  1519. else
  1520. {
  1521. if(request()->banner_right_bottom_3)
  1522. {
  1523. $file = request()->banner_right_bottom_3;
  1524. $filename = time() . '_' . $file->getClientOriginalName();
  1525. $path = public_path('files');
  1526. request()->banner_right_bottom_3->move($path, $filename);
  1527. $banner_right_bottom_3 = $filename;
  1528. $home->banner_right_bottom_3 = $banner_right_bottom_3;
  1529. }
  1530. }
  1531. $banner_right_bottom_3_url = isset($_POST["banner_right_bottom_3_url"]) ? $_POST["banner_right_bottom_3_url"] : '';
  1532. $home->banner_right_bottom_3_url = $banner_right_bottom_3_url;
  1533. if (isset($_POST["delete_banner_right_bottom_4"]))
  1534. {
  1535. $banner_right_bottom_4 = '';
  1536. $home->banner_right_bottom_4 = $banner_right_bottom_4;
  1537. }
  1538. else
  1539. {
  1540. if(request()->banner_right_bottom_4)
  1541. {
  1542. $file = request()->banner_right_bottom_4;
  1543. $filename = time() . '_' . $file->getClientOriginalName();
  1544. $path = public_path('files');
  1545. request()->banner_right_bottom_4->move($path, $filename);
  1546. $banner_right_bottom_4 = $filename;
  1547. $home->banner_right_bottom_4 = $banner_right_bottom_4;
  1548. }
  1549. }
  1550. $banner_right_bottom_4_url = isset($_POST["banner_right_bottom_4_url"]) ? $_POST["banner_right_bottom_4_url"] : '';
  1551. $home->banner_right_bottom_4_url = $banner_right_bottom_4_url;
  1552. if (isset($_POST["delete_banner_right_bottom_5"]))
  1553. {
  1554. $banner_right_bottom_5 = '';
  1555. $home->banner_right_bottom_5 = $banner_right_bottom_5;
  1556. }
  1557. else
  1558. {
  1559. if(request()->banner_right_bottom_5)
  1560. {
  1561. $file = request()->banner_right_bottom_5;
  1562. $filename = time() . '_' . $file->getClientOriginalName();
  1563. $path = public_path('files');
  1564. request()->banner_right_bottom_5->move($path, $filename);
  1565. $banner_right_bottom_5 = $filename;
  1566. $home->banner_right_bottom_5 = $banner_right_bottom_5;
  1567. }
  1568. }
  1569. $banner_right_bottom_5_url = isset($_POST["banner_right_bottom_5_url"]) ? $_POST["banner_right_bottom_5_url"] : '';
  1570. $home->banner_right_bottom_5_url = $banner_right_bottom_5_url;
  1571. $banner_right_bottom_google = isset($_POST["banner_right_bottom_google"]) ? $_POST["banner_right_bottom_google"] : '';
  1572. $home->banner_right_bottom_google = $banner_right_bottom_google;
  1573. if (isset($_POST["delete_banner_right_big"]))
  1574. {
  1575. $banner_right_big = '';
  1576. $home->banner_right_big = $banner_right_big;
  1577. }
  1578. else
  1579. {
  1580. if(request()->banner_right_big)
  1581. {
  1582. $file = request()->banner_right_big;
  1583. $filename = time() . '_' . $file->getClientOriginalName();
  1584. $path = public_path('files');
  1585. request()->banner_right_big->move($path, $filename);
  1586. $banner_right_big = $filename;
  1587. $home->banner_right_big = $banner_right_big;
  1588. }
  1589. }
  1590. $banner_right_big_url = isset($_POST["banner_right_big_url"]) ? $_POST["banner_right_big_url"] : '';
  1591. $home->banner_right_big_url = $banner_right_big_url;
  1592. if (isset($_POST["delete_banner_right_big_2"]))
  1593. {
  1594. $banner_right_big_2 = '';
  1595. $home->banner_right_big_2 = $banner_right_big_2;
  1596. }
  1597. else
  1598. {
  1599. if(request()->banner_right_big_2)
  1600. {
  1601. $file = request()->banner_right_big_2;
  1602. $filename = time() . '_' . $file->getClientOriginalName();
  1603. $path = public_path('files');
  1604. request()->banner_right_big_2->move($path, $filename);
  1605. $banner_right_big_2 = $filename;
  1606. $home->banner_right_big_2 = $banner_right_big_2;
  1607. }
  1608. }
  1609. $banner_right_big_2_url = isset($_POST["banner_right_big_2_url"]) ? $_POST["banner_right_big_2_url"] : '';
  1610. $home->banner_right_big_2_url = $banner_right_big_2_url;
  1611. if (isset($_POST["delete_banner_right_big_3"]))
  1612. {
  1613. $banner_right_big_3 = '';
  1614. $home->banner_right_big_3 = $banner_right_big_3;
  1615. }
  1616. else
  1617. {
  1618. if(request()->banner_right_big_3)
  1619. {
  1620. $file = request()->banner_right_big_3;
  1621. $filename = time() . '_' . $file->getClientOriginalName();
  1622. $path = public_path('files');
  1623. request()->banner_right_big_3->move($path, $filename);
  1624. $banner_right_big_3 = $filename;
  1625. $home->banner_right_big_3 = $banner_right_big_3;
  1626. }
  1627. }
  1628. $banner_right_big_3_url = isset($_POST["banner_right_big_3_url"]) ? $_POST["banner_right_big_3_url"] : '';
  1629. $home->banner_right_big_3_url = $banner_right_big_3_url;
  1630. if (isset($_POST["delete_banner_right_big_4"]))
  1631. {
  1632. $banner_right_big_4 = '';
  1633. $home->banner_right_big_4 = $banner_right_big_4;
  1634. }
  1635. else
  1636. {
  1637. if(request()->banner_right_big_4)
  1638. {
  1639. $file = request()->banner_right_big_4;
  1640. $filename = time() . '_' . $file->getClientOriginalName();
  1641. $path = public_path('files');
  1642. request()->banner_right_big_4->move($path, $filename);
  1643. $banner_right_big_4 = $filename;
  1644. $home->banner_right_big_4 = $banner_right_big_4;
  1645. }
  1646. }
  1647. $banner_right_big_4_url = isset($_POST["banner_right_big_4_url"]) ? $_POST["banner_right_big_4_url"] : '';
  1648. $home->banner_right_big_4_url = $banner_right_big_4_url;
  1649. if (isset($_POST["delete_banner_right_big_5"]))
  1650. {
  1651. $banner_right_big_5 = '';
  1652. $home->banner_right_big_5 = $banner_right_big_5;
  1653. }
  1654. else
  1655. {
  1656. if(request()->banner_right_big_5)
  1657. {
  1658. $file = request()->banner_right_big_5;
  1659. $filename = time() . '_' . $file->getClientOriginalName();
  1660. $path = public_path('files');
  1661. request()->banner_right_big_5->move($path, $filename);
  1662. $banner_right_big_5 = $filename;
  1663. $home->banner_right_big_5 = $banner_right_big_5;
  1664. }
  1665. }
  1666. $banner_right_big_5_url = isset($_POST["banner_right_big_5_url"]) ? $_POST["banner_right_big_5_url"] : '';
  1667. $home->banner_right_big_5_url = $banner_right_big_5_url;
  1668. $banner_right_big_google = isset($_POST["banner_right_big_google"]) ? $_POST["banner_right_big_google"] : '';
  1669. $home->banner_right_big_google = $banner_right_big_google;
  1670. $home->save();
  1671. return Redirect::to('/admin/home_adv');
  1672. })->name('home_adv');
  1673. Route::get('/home_radio', function () {
  1674. $home = Home::first();
  1675. if ($home == null)
  1676. {
  1677. $home = new Home();
  1678. $home->save();
  1679. }
  1680. $home->loadData();
  1681. return view('admin.home_radio',compact('home'));
  1682. })->name('home_radio');
  1683. Route::post('/home_radio', function () {
  1684. $home = Home::first();
  1685. if ($home == null)
  1686. $home = new Home();
  1687. if (isset($_POST["delete_radio1"]))
  1688. {
  1689. $radio1_file = '';
  1690. $home->radio1_file = $radio1_file;
  1691. }
  1692. else
  1693. {
  1694. if(request()->radio1_file)
  1695. {
  1696. $file = request()->radio1_file;
  1697. $filename = time() . '_' . $file->getClientOriginalName();
  1698. $path = public_path('files');
  1699. request()->radio1_file->move($path, $filename);
  1700. $radio1_file = $filename;
  1701. $home->radio1_file = $radio1_file;
  1702. }
  1703. }
  1704. $radio1_url = isset($_POST["radio1_url"]) ? $_POST["radio1_url"] : '';
  1705. $home->radio1_url = $radio1_url;
  1706. $home->radio1_title = isset($_POST["radio1_title"]) ? $_POST["radio1_title"] : '';
  1707. if (isset($_POST["delete_radio2"]))
  1708. {
  1709. $radio2_file = '';
  1710. $home->radio2_file = $radio2_file;
  1711. }
  1712. else
  1713. {
  1714. if(request()->radio2_file)
  1715. {
  1716. $file = request()->radio2_file;
  1717. $filename = time() . '_' . $file->getClientOriginalName();
  1718. $path = public_path('files');
  1719. request()->radio2_file->move($path, $filename);
  1720. $radio2_file = $filename;
  1721. $home->radio2_file = $radio2_file;
  1722. }
  1723. }
  1724. $radio2_url = isset($_POST["radio2_url"]) ? $_POST["radio2_url"] : '';
  1725. $home->radio2_url = $radio2_url;
  1726. $home->radio2_title = isset($_POST["radio2_title"]) ? $_POST["radio2_title"] : '';
  1727. if (isset($_POST["delete_radio3"]))
  1728. {
  1729. $radio3_file = '';
  1730. $home->radio3_file = $radio3_file;
  1731. }
  1732. else
  1733. {
  1734. if(request()->radio3_file)
  1735. {
  1736. $file = request()->radio3_file;
  1737. $filename = time() . '_' . $file->getClientOriginalName();
  1738. $path = public_path('files');
  1739. request()->radio3_file->move($path, $filename);
  1740. $radio3_file = $filename;
  1741. $home->radio3_file = $radio3_file;
  1742. }
  1743. }
  1744. $radio3_url = isset($_POST["radio3_url"]) ? $_POST["radio3_url"] : '';
  1745. $home->radio3_url = $radio3_url;
  1746. $home->radio3_title = isset($_POST["radio3_title"]) ? $_POST["radio3_title"] : '';
  1747. $home->save();
  1748. return Redirect::to('/admin/home_radio');
  1749. })->name('home_radio');
  1750. Route::get('/news/duplicate/{id}', function ($id) {
  1751. $news = News::findOrFail($id);
  1752. $new_news = $news->replicate();
  1753. $new_news->title .= ' - COPY';
  1754. $new_news->online = false;
  1755. $new_news->save();
  1756. return Redirect::to('/admin/news/' . $new_news->id . "/edit");
  1757. })->name('news.duplicate');
  1758. Route::get('/news/crop', function () {
  1759. return view('news.crop');
  1760. })->name('news.crop');
  1761. Route::post('/news/crop', function () {
  1762. Log::info('=== CROP POST METHOD START ===');
  1763. Log::info('POST data received:', $_POST);
  1764. Log::info('FILES data:', $_FILES ?? 'No files');
  1765. try {
  1766. // Check if required data exists
  1767. if (!isset($_POST["imagebase64H"]) || !isset($_POST["imagebase64V"])) {
  1768. Log::error('Missing required image data');
  1769. Log::error('imagebase64H exists:', [isset($_POST["imagebase64H"])]);
  1770. Log::error('imagebase64V exists:', [isset($_POST["imagebase64V"])]);
  1771. return redirect()->back()->with('error', 'Missing image data');
  1772. }
  1773. $image = $_POST["imagebase64H"];
  1774. Log::info('Processing horizontal image, length:', [strlen($image)]);
  1775. $imageInfo = explode(";base64,", $image);
  1776. if (count($imageInfo) < 2) {
  1777. Log::error('Invalid image format - missing base64 separator');
  1778. return redirect()->back()->with('error', 'Invalid image format');
  1779. }
  1780. $imgExt = str_replace('data:image/', '', $imageInfo[0]);
  1781. $image = str_replace(' ', '+', $imageInfo[1]);
  1782. $imageName = time().".".$imgExt;
  1783. Log::info('Image details:', [
  1784. 'extension' => $imgExt,
  1785. 'filename' => $imageName,
  1786. 'base64_length' => strlen($image)
  1787. ]);
  1788. // Make sure the directory exists
  1789. $newsDir = public_path()."/files/news";
  1790. if (!File::exists($newsDir)) {
  1791. Log::info('Creating news directory:', [$newsDir]);
  1792. File::makeDirectory($newsDir, 0755, true);
  1793. } else {
  1794. Log::info('News directory exists:', [$newsDir]);
  1795. }
  1796. $path = $newsDir."/".$imageName;
  1797. Log::info('Saving image to:', [$path]);
  1798. $result = file_put_contents($path, base64_decode($image));
  1799. if ($result === false) {
  1800. Log::error('Failed to save horizontal image');
  1801. return redirect()->back()->with('error', 'Failed to save image');
  1802. }
  1803. Log::info('Horizontal image saved successfully, bytes written:', [$result]);
  1804. Log::info('File exists after save:', [file_exists($path)]);
  1805. // Process vertical image
  1806. $imageV = $_POST["imagebase64V"];
  1807. Log::info('Processing vertical image, length:', [strlen($imageV)]);
  1808. $imageInfoV = explode(";base64,", $imageV);
  1809. $imgExtV = str_replace('data:image/', '', $imageInfoV[0]);
  1810. $imageV = str_replace(' ', '+', $imageInfoV[1]);
  1811. $imageNameV = "V_".time().".".$imgExt;
  1812. $pathV = $newsDir."/".$imageNameV;
  1813. Log::info('Vertical image details:', [
  1814. 'extension' => $imgExtV,
  1815. 'filename' => $imageNameV,
  1816. 'path' => $pathV
  1817. ]);
  1818. $resultV = file_put_contents($pathV, base64_decode($imageV));
  1819. if ($resultV === false) {
  1820. Log::error('Failed to save vertical image');
  1821. } else {
  1822. Log::info('Vertical image saved successfully, bytes written:', [$resultV]);
  1823. }
  1824. // Check news_id
  1825. $news_id = isset($_POST["news_id"]) ? $_POST["news_id"] : '';
  1826. Log::info('News ID from form:', [$news_id]);
  1827. Log::info('News ID > 0:', [$news_id > 0]);
  1828. if ($news_id > 0) {
  1829. Log::info('Existing news - updating image');
  1830. try {
  1831. $news = News::findOrFail($news_id);
  1832. Log::info('Found existing news:', [
  1833. 'id' => $news->id,
  1834. 'title' => $news->title,
  1835. 'current_image' => $news->image
  1836. ]);
  1837. $news->image = $imageName;
  1838. $news->save();
  1839. Log::info('Updated existing news with new image:', [$imageName]);
  1840. $redirectUrl = '/admin/news/' . $news_id . "/edit";
  1841. Log::info('Redirecting to edit page:', [$redirectUrl]);
  1842. return redirect()->to($redirectUrl);
  1843. } catch (\Exception $e) {
  1844. Log::error('Error updating existing news:', [
  1845. 'message' => $e->getMessage(),
  1846. 'file' => $e->getFile(),
  1847. 'line' => $e->getLine()
  1848. ]);
  1849. return redirect()->back()->with('error', 'Error updating news: ' . $e->getMessage());
  1850. }
  1851. } else {
  1852. Log::info('New news - redirecting to create with filename');
  1853. $redirectUrl = '/admin/news/create?filename=' . $imageName;
  1854. Log::info('Redirecting to create page:', [$redirectUrl]);
  1855. // Also try using the route method
  1856. try {
  1857. Log::info('Attempting route redirect with filename parameter');
  1858. return redirect()->route('news.create', ['filename' => $imageName]);
  1859. } catch (\Exception $e) {
  1860. Log::error('Route redirect failed, using direct redirect:', [$e->getMessage()]);
  1861. return redirect()->to($redirectUrl);
  1862. }
  1863. }
  1864. } catch (\Exception $e) {
  1865. Log::error('=== CROP ERROR ===');
  1866. Log::error('Error message:', [$e->getMessage()]);
  1867. Log::error('Error file:', [$e->getFile()]);
  1868. Log::error('Error line:', [$e->getLine()]);
  1869. Log::error('Stack trace:', [$e->getTraceAsString()]);
  1870. return redirect()->back()->with('error', 'An error occurred while processing the image: ' . $e->getMessage());
  1871. }
  1872. })->name('news.crop_save');
  1873. Route::get('news/load_json', 'NewsController@load_json')->name('load_json');
  1874. Route::get('news/status/{id}/{status}', function ($id, $status) {
  1875. $n = News::findOrFail($id);
  1876. $n->online = $status == 'online';
  1877. if ($status == 'online')
  1878. {
  1879. if ($n->date <= date("Y-m-d H:i:s"))
  1880. {
  1881. if ($n->section_position != '')
  1882. {
  1883. $s = Section::findOrFail($n->section_id);
  1884. $s[$n->section_position] = $n->id;
  1885. $s->save();
  1886. $n->section_position = '';
  1887. }
  1888. if ($n->region_1_position != '')
  1889. {
  1890. $s = Section::findOrFail($n->region_1_id);
  1891. $s[$n->region_1_position] = $n->id;
  1892. $s->save();
  1893. $n->region_1_position = '';
  1894. }
  1895. if ($n->region_2_position != '')
  1896. {
  1897. $s = Section::findOrFail($n->region_2_id);
  1898. $s[$n->region_2_position] = $n->id;
  1899. $s->save();
  1900. $n->region_2_position = '';
  1901. }
  1902. $n->save();
  1903. if (!$n->published)
  1904. {
  1905. // $n->notify(new FacebookPost());
  1906. $n->notify(new TwitterPost());
  1907. $n->published = true;
  1908. }
  1909. }
  1910. }
  1911. else
  1912. {
  1913. }
  1914. $n->save();
  1915. return Redirect::to('/admin/news');
  1916. });
  1917. Route::resource('news','NewsController');
  1918. Route::resource('breaking_news','BreakingNewsController');
  1919. Route::get('/sections/sort/{ids}', function ($ids) {
  1920. $idx = explode(",", $ids);
  1921. foreach($idx as $x => $id)
  1922. {
  1923. $s = Section::findOrFail($id);
  1924. $s->position = $x;
  1925. $s->save();
  1926. }
  1927. });
  1928. Route::get('/sections/layout/{id}', function ($id) {
  1929. $section = Section::findOrFail($id);
  1930. if (isset($_GET["layout"]))
  1931. {
  1932. $section->big = '';
  1933. $section->small1 = '';
  1934. $section->small2 = '';
  1935. $section->small3 = '';
  1936. $section->small4 = '';
  1937. $section->small5 = '';
  1938. $section->small6 = '';
  1939. $section->save();
  1940. }
  1941. $section->loadLayout();
  1942. $aAssigned = array();
  1943. if ($section->big != '')
  1944. $aAssigned[] = @$section->big->id;
  1945. if ($section->small1 != '')
  1946. $aAssigned[] = @$section->small1->id;
  1947. if ($section->small2 != '')
  1948. $aAssigned[] = @$section->small2->id;
  1949. if ($section->small3 != '')
  1950. $aAssigned[] = @$section->small3->id;
  1951. if ($section->small4 != '')
  1952. $aAssigned[] = @$section->small4->id;
  1953. if ($section->small5 != '')
  1954. $aAssigned[] = @$section->small5->id;
  1955. if ($section->small6 != '')
  1956. $aAssigned[] = @$section->small6->id;
  1957. $news = News::whereNotIn('id', $aAssigned)->where(function ($q) use ($id) {
  1958. $q->where('section_id', '=', $id)->orWhere('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
  1959. })->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  1960. return view('sections.layout',compact('section', 'news'));
  1961. })->name('sections.layout');
  1962. Route::post('/sections/layout/{id}', function ($id) {
  1963. $section = Section::findOrFail($id);
  1964. $layout = isset($_POST["layout"]) ? $_POST["layout"] : '';
  1965. $big = isset($_POST["big"]) ? $_POST["big"] : '';
  1966. $small1 = isset($_POST["small1"]) ? $_POST["small1"] : '';
  1967. $small2 = isset($_POST["small2"]) ? $_POST["small2"] : '';
  1968. $small3 = isset($_POST["small3"]) ? $_POST["small3"] : '';
  1969. $small4 = isset($_POST["small4"]) ? $_POST["small4"] : '';
  1970. $small5 = isset($_POST["small5"]) ? $_POST["small5"] : '';
  1971. $small6 = isset($_POST["small6"]) ? $_POST["small6"] : '';
  1972. $aSel = array();
  1973. if (isset($_POST["big"]))
  1974. $aSel[] = $_POST["big"];
  1975. if (isset($_POST["small1"]))
  1976. $aSel[] = $_POST["small1"];
  1977. if (isset($_POST["small2"]))
  1978. $aSel[] = $_POST["small2"];
  1979. if (isset($_POST["small3"]))
  1980. $aSel[] = $_POST["small3"];
  1981. if (isset($_POST["small4"]))
  1982. $aSel[] = $_POST["small4"];
  1983. if (isset($_POST["small5"]))
  1984. $aSel[] = $_POST["small5"];
  1985. if (isset($_POST["small6"]))
  1986. $aSel[] = $_POST["small6"];
  1987. // Riempio i vuoti
  1988. $news = News::whereNotIn('id', $aSel)->where(function ($q) use ($id) {
  1989. $q->where('section_id', '=', $id)->orWhere('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
  1990. })->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  1991. $idx = 0;
  1992. $section->layout = $layout;
  1993. if ($big == '')
  1994. {
  1995. $section->big = @$news[$idx]->id;
  1996. $idx++;
  1997. }
  1998. else
  1999. $section->big = $big;
  2000. if ($small1 == '')
  2001. {
  2002. $section->small1 = @$news[$idx]->id;
  2003. $idx++;
  2004. }
  2005. else
  2006. $section->small1 = $small1;
  2007. if ($small2 == '')
  2008. {
  2009. $section->small2 = @$news[$idx]->id;
  2010. $idx++;
  2011. }
  2012. else
  2013. $section->small2 = $small2;
  2014. if ($small3 == '')
  2015. {
  2016. $section->small3 = @$news[$idx]->id;
  2017. $idx++;
  2018. }
  2019. else
  2020. $section->small3 = $small3;
  2021. if ($layout == 'layout_3' || $layout == 'layout_4' || $layout == 'layout_5' || $layout == 'layout_7')
  2022. {
  2023. if ($small4 == '')
  2024. {
  2025. $section->small4 = @$news[$idx]->id;
  2026. $idx++;
  2027. }
  2028. else
  2029. $section->small4 = $small4;
  2030. if ($layout == 'layout_4')
  2031. {
  2032. if ($small5 == '')
  2033. {
  2034. $section->small5 = @$news[$idx]->id;
  2035. $idx++;
  2036. }
  2037. else
  2038. $section->small5 = $small5;
  2039. if ($small6 == '')
  2040. {
  2041. $section->small6 = @$news[$idx]->id;
  2042. $idx++;
  2043. }
  2044. else
  2045. $section->small6 = $small6;
  2046. }
  2047. else
  2048. {
  2049. $section->small5 = '';
  2050. $section->small6 = '';
  2051. }
  2052. }
  2053. else
  2054. {
  2055. $section->small4 = '';
  2056. $section->small5 = '';
  2057. $section->small6 = '';
  2058. }
  2059. $section->save();
  2060. // CLEARLAYOUT
  2061. // $section->clearLayout();
  2062. return Redirect::to('/admin/sections');
  2063. });
  2064. Route::get('/events/layout/{id}', function ($id) {
  2065. $event = Event::findOrFail($id);
  2066. $event->loadLayout();
  2067. $aAssigned = array();
  2068. if ($event->big != '')
  2069. $aAssigned[] = @$event->big->id;
  2070. if ($event->small1 != '')
  2071. $aAssigned[] = @$event->small1->id;
  2072. if ($event->small2 != '')
  2073. $aAssigned[] = @$event->small2->id;
  2074. if ($event->small3 != '')
  2075. $aAssigned[] = @$event->small3->id;
  2076. if ($event->small4 != '')
  2077. $aAssigned[] = @$event->small4->id;
  2078. $news = News::whereNotIn('id', $aAssigned)->where('event_id', '=', $id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2079. return view('events.layout',compact('event', 'news'));
  2080. })->name('events.layout');
  2081. Route::post('/events/layout/{id}', function ($id) {
  2082. $event = Event::findOrFail($id);
  2083. $big = isset($_POST["big"]) ? $_POST["big"] : '';
  2084. $small1 = isset($_POST["small1"]) ? $_POST["small1"] : '';
  2085. $small2 = isset($_POST["small2"]) ? $_POST["small2"] : '';
  2086. $small3 = isset($_POST["small3"]) ? $_POST["small3"] : '';
  2087. $small4 = isset($_POST["small4"]) ? $_POST["small4"] : '';
  2088. $aSel = array();
  2089. if (isset($_POST["big"]))
  2090. $aSel[] = $_POST["big"];
  2091. if (isset($_POST["small1"]))
  2092. $aSel[] = $_POST["small1"];
  2093. if (isset($_POST["small2"]))
  2094. $aSel[] = $_POST["small2"];
  2095. if (isset($_POST["small3"]))
  2096. $aSel[] = $_POST["small3"];
  2097. if (isset($_POST["small4"]))
  2098. $aSel[] = $_POST["small4"];
  2099. $news = News::whereNotIn('id', $aSel)->where('event_id', '=', $id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2100. $idx = 0;
  2101. if ($big == '')
  2102. {
  2103. $event->big = @$news[$idx]->id;
  2104. $idx++;
  2105. }
  2106. else
  2107. $event->big = $big;
  2108. if ($small1 == '')
  2109. {
  2110. $event->small1 = @$news[$idx]->id;
  2111. $idx++;
  2112. }
  2113. else
  2114. $event->small1 = $small1;
  2115. if ($small2 == '')
  2116. {
  2117. $event->small2 = @$news[$idx]->id;
  2118. $idx++;
  2119. }
  2120. else
  2121. $event->small2 = $small2;
  2122. if ($small3 == '')
  2123. {
  2124. $event->small3 = @$news[$idx]->id;
  2125. $idx++;
  2126. }
  2127. else
  2128. $event->small3 = $small3;
  2129. if ($small4 == '')
  2130. {
  2131. $event->small4 = @$news[$idx]->id;
  2132. $idx++;
  2133. }
  2134. else
  2135. $event->small4 = $small4;
  2136. $event->save();
  2137. return Redirect::to('/admin/events');
  2138. });
  2139. Route::get('/sections/to_event/{id}', function ($id) {
  2140. $section = Section::findOrFail($id);
  2141. $event = new Event();
  2142. $event->title = $section->name;
  2143. $event->text_short = '';
  2144. $event->text = '';
  2145. $event->image = '';
  2146. $event->slug = $section->slug;
  2147. $event->online = true;
  2148. $event->save();
  2149. $news = News::where('section_id', '=', $id)->get();
  2150. foreach($news as $n)
  2151. {
  2152. $n->event_id = $event->id;
  2153. $n->section_id = null;
  2154. $n->save();
  2155. }
  2156. $news = News::where('region_1_id', '=', $id)->get();
  2157. foreach($news as $n)
  2158. {
  2159. $n->event_id = $event->id;
  2160. $n->region_1_id = null;
  2161. $n->save();
  2162. }
  2163. $news = News::where('region_2_id', '=', $id)->get();
  2164. foreach($news as $n)
  2165. {
  2166. $n->event_id = $event->id;
  2167. $n->region_2_id = null;
  2168. $n->save();
  2169. }
  2170. $advs = SectionAdv::where('section_id', '=', $id)->get();
  2171. foreach($advs as $adv)
  2172. {
  2173. $adv->section_id = null;
  2174. $adv->save();
  2175. }
  2176. // $section->slug = $section->slug . "_old";
  2177. $section->delete();
  2178. return Redirect::to('/admin/events/' . $event->id . '/edit');
  2179. })->name('sections.to_event');
  2180. Route::resource('sections.advs','SectionAdvController');
  2181. Route::resource('sections','SectionController');
  2182. Route::resource('categories.groups','GroupController');
  2183. Route::resource('categories','CategoryController');
  2184. Route::get('/adv/sort/{ids}', function ($ids) {
  2185. $idx = explode(",", $ids);
  2186. foreach($idx as $x => $id)
  2187. {
  2188. $s = PageAdv::findOrFail($id);
  2189. $s->sort = $x;
  2190. $s->save();
  2191. }
  2192. });
  2193. Route::resource('pages.advs','PageAdvController');
  2194. Route::resource('pages','PageController');
  2195. Route::resource('events.advs','EventAdvController');
  2196. Route::resource('events','EventController');
  2197. Route::get('/calendars/sort/{ids}', function ($ids) {
  2198. $idx = explode(",", $ids);
  2199. foreach($idx as $x => $id)
  2200. {
  2201. $c = Calendar::findOrFail($id);
  2202. $c->position = $x;
  2203. $c->save();
  2204. }
  2205. });
  2206. Route::resource('calendars','CalendarController');
  2207. Route::get('/calendars/archive/{id}', function ($id) {
  2208. $c = Calendar::findOrFail($id);
  2209. $c->archived = true;
  2210. $c->save();
  2211. return Redirect::to('/admin/calendars');
  2212. })->name('calendars.archive');
  2213. Route::get('/calendars/restore/{id}', function ($id) {
  2214. $c = Calendar::findOrFail($id);
  2215. $c->archived = false;
  2216. $c->save();
  2217. return Redirect::to('/admin/calendars');
  2218. })->name('calendars.restore');
  2219. Route::get('/calendars/games/{id}', function ($id) {
  2220. $calendar = CalendarGame::where('calendar_id', '=', $id)->get();;
  2221. $games = array();
  2222. foreach($calendar as $c)
  2223. {
  2224. $games[$c->day . " " . $c->type][] = $c;
  2225. }
  2226. $c = Calendar::findOrFail($id);
  2227. $aRates = $c->getRates();
  2228. $count = 1;
  2229. foreach($aRates as $idx => $r)
  2230. {
  2231. if ($r["penality"] != '')
  2232. {
  2233. $aRates[$idx]["team"] = $r["team"] . ' ' . str_repeat('*', $count);
  2234. $aRates[$idx]["penality"] = str_repeat('*', $count) . $r["penality"];
  2235. $count += 1;
  2236. }
  2237. }
  2238. return view('calendars.games',compact('games', 'aRates'));
  2239. })->name('calendars.games');
  2240. Route::get('/calendars/games/{id}/{day}/{type}', function ($id, $day, $type) {
  2241. $games = CalendarGame::where('calendar_id', '=', $id)->where('day', '=', $day)->where('type', '=', $type)->get();;
  2242. return view('calendars.games_edit',compact('games', 'id', 'day', 'type'));
  2243. })->name('calendars.games_edit');
  2244. Route::post('/calendars/games/{id}/{day}/{type}', function ($id, $day, $type) {
  2245. $games = CalendarGame::where('calendar_id', '=', $id)->where('day', '=', $day)->where('type', '=', $type)->get();;
  2246. foreach($games as $g)
  2247. {
  2248. $date = isset($_POST["date_" . $g->id]) ? $_POST["date_" . $g->id] : '';
  2249. list($day, $month, $year) = explode("/", $date);
  2250. $g->date = $year . "-" . $month . "-" . $day;
  2251. $g->save();
  2252. $home_goals = isset($_POST["home_goals_" . $g->id]) ? $_POST["home_goals_" . $g->id] : '';
  2253. $away_goals = isset($_POST["away_goals_" . $g->id]) ? $_POST["away_goals_" . $g->id] : '';
  2254. $delete = isset($_POST["delete_" . $g->id]) ? true : false;
  2255. if ($delete)
  2256. {
  2257. $g->played = false;
  2258. $g->home_goals = null;
  2259. $g->away_goals = null;
  2260. $g->home_points = 0;
  2261. $g->away_points = 0;
  2262. $g->save();
  2263. }
  2264. else
  2265. {
  2266. if ($home_goals != '' && $away_goals != '')
  2267. {
  2268. $home_points = 0;
  2269. $away_points = 0;
  2270. if ($home_goals > $away_goals)
  2271. {
  2272. $home_points = 3;
  2273. $away_points = 0;
  2274. }
  2275. else if ($home_goals == $away_goals)
  2276. {
  2277. $home_points = 1;
  2278. $away_points = 1;
  2279. }
  2280. else
  2281. {
  2282. $home_points = 0;
  2283. $away_points = 3;
  2284. }
  2285. $g->played = true;
  2286. $g->home_goals = $home_goals;
  2287. $g->away_goals = $away_goals;
  2288. $g->home_points = $home_points;
  2289. $g->away_points = $away_points;
  2290. $g->save();
  2291. }
  2292. }
  2293. }
  2294. return Redirect::to('/admin/calendars/games/' . $id);
  2295. });
  2296. Route::resource('seasons','SeasonController');
  2297. Route::resource('teams','TeamController');
  2298. Route::get('/videos/sort/{ids}', function ($ids) {
  2299. $idx = explode(",", $ids);
  2300. foreach($idx as $x => $id)
  2301. {
  2302. $v = Video::findOrFail($id);
  2303. $v->position = $x;
  2304. $v->save();
  2305. }
  2306. });
  2307. Route::resource('videos','VideoController');
  2308. Route::resource('users','UserController');
  2309. Route::get('/load_categories/{type}', function ($type) {
  2310. $categories = Category::where('type', '=', $type)->get();
  2311. return $categories->toJson();
  2312. });
  2313. Route::get('/load_groups/{category}', function ($category) {
  2314. $groups = Group::where('category_id', '=', $category)->get();
  2315. return $groups->toJson();
  2316. });
  2317. });
  2318. });
  2319. Route::get('/{slug}/elenco', function ($slug) {
  2320. $home = Home::first();
  2321. if ($home != null)
  2322. $home->loadData();
  2323. $aHome = array();
  2324. if ($home->image != '')
  2325. {
  2326. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2327. }
  2328. if ($home->image_2 != '')
  2329. {
  2330. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2331. }
  2332. if ($home->image_3 != '')
  2333. {
  2334. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2335. }
  2336. if ($home->image_4 != '')
  2337. {
  2338. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2339. }
  2340. if ($home->image_5 != '')
  2341. {
  2342. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2343. }
  2344. if (sizeof($aHome) > 0)
  2345. {
  2346. $rnd = rand (0, sizeof($aHome) - 1);
  2347. $home->image = $aHome[$rnd]["image"];
  2348. $home->url = $aHome[$rnd]["url"];
  2349. }
  2350. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2351. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2352. $sections = Section::orderBy('position')->get();
  2353. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2354. //if($breaking_news->count() == 0)
  2355. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2356. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2357. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2358. $season_id = @Season::where('default', '=', true)->first()->id;
  2359. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2360. $calendars = array();
  2361. foreach($cals as $c)
  2362. {
  2363. if ($c->category->grp != '')
  2364. {
  2365. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2366. if ($c->group_id > 0)
  2367. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2368. else
  2369. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2370. }
  2371. }
  2372. $page = Page::where('slug', '=', $slug)->first();
  2373. if ($page != null)
  2374. {
  2375. $section = $page;
  2376. $news = News::where('page_id', '=', $page->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2377. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2378. }
  2379. });
  2380. Route::get('/eventi/{slug}', function ($slug) {
  2381. $home = Home::first();
  2382. if ($home != null)
  2383. $home->loadData();
  2384. $aHome = array();
  2385. if ($home->image != '')
  2386. {
  2387. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2388. }
  2389. if ($home->image_2 != '')
  2390. {
  2391. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2392. }
  2393. if ($home->image_3 != '')
  2394. {
  2395. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2396. }
  2397. if ($home->image_4 != '')
  2398. {
  2399. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2400. }
  2401. if ($home->image_5 != '')
  2402. {
  2403. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2404. }
  2405. if (sizeof($aHome) > 0)
  2406. {
  2407. $rnd = rand (0, sizeof($aHome) - 1);
  2408. $home->image = $aHome[$rnd]["image"];
  2409. $home->url = $aHome[$rnd]["url"];
  2410. }
  2411. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2412. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2413. $sections = Section::orderBy('position')->get();
  2414. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2415. //if($breaking_news->count() == 0)
  2416. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2417. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2418. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2419. $season_id = @Season::where('default', '=', true)->first()->id;
  2420. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2421. $calendars = array();
  2422. foreach($cals as $c)
  2423. {
  2424. if ($c->category->grp != '')
  2425. {
  2426. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2427. if ($c->group_id > 0)
  2428. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2429. else
  2430. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2431. }
  2432. }
  2433. $event = Event::where('slug', '=', $slug)->first();
  2434. if ($event != null)
  2435. {
  2436. $event->loadLayout();
  2437. /*$aAssigned = array();
  2438. if ($event->big != '')
  2439. $aAssigned[] = @$event->big->id;
  2440. if ($event->small1 != '')
  2441. $aAssigned[] = @$event->small1->id;
  2442. if ($event->small2 != '')
  2443. $aAssigned[] = @$event->small2->id;
  2444. if ($event->small3 != '')
  2445. $aAssigned[] = @$event->small3->id;
  2446. if ($event->small4 != '')
  2447. $aAssigned[] = @$event->small4->id;*/
  2448. $elements = News::where('event_id', '=', $event->id)->take(5)->get();
  2449. return view('event', compact('home', 'event', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2450. }
  2451. });
  2452. Route::get('/eventi/{slug}/elenco', function ($slug) {
  2453. $home = Home::first();
  2454. if ($home != null)
  2455. $home->loadData();
  2456. $aHome = array();
  2457. if ($home->image != '')
  2458. {
  2459. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2460. }
  2461. if ($home->image_2 != '')
  2462. {
  2463. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2464. }
  2465. if ($home->image_3 != '')
  2466. {
  2467. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2468. }
  2469. if ($home->image_4 != '')
  2470. {
  2471. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2472. }
  2473. if ($home->image_5 != '')
  2474. {
  2475. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2476. }
  2477. if (sizeof($aHome) > 0)
  2478. {
  2479. $rnd = rand (0, sizeof($aHome) - 1);
  2480. $home->image = $aHome[$rnd]["image"];
  2481. $home->url = $aHome[$rnd]["url"];
  2482. }
  2483. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2484. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2485. $sections = Section::orderBy('position')->get();
  2486. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2487. //if($breaking_news->count() == 0)
  2488. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2489. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2490. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2491. $season_id = @Season::where('default', '=', true)->first()->id;
  2492. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2493. $calendars = array();
  2494. foreach($cals as $c)
  2495. {
  2496. if ($c->category->grp != '')
  2497. {
  2498. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2499. if ($c->group_id > 0)
  2500. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2501. else
  2502. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2503. }
  2504. }
  2505. $event = Event::where('slug', '=', $slug)->first();
  2506. if ($event != null)
  2507. {
  2508. $section = $event;
  2509. $news = News::where('event_id', '=', $event->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2510. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2511. }
  2512. });
  2513. Route::get('/{slug}/{slug2}', function ($slug, $slug2) {
  2514. $home = Home::first();
  2515. if ($home != null)
  2516. $home->loadData();
  2517. $aHome = array();
  2518. if ($home->image != '')
  2519. {
  2520. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2521. }
  2522. if ($home->image_2 != '')
  2523. {
  2524. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2525. }
  2526. if ($home->image_3 != '')
  2527. {
  2528. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2529. }
  2530. if ($home->image_4 != '')
  2531. {
  2532. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2533. }
  2534. if ($home->image_5 != '')
  2535. {
  2536. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2537. }
  2538. if (sizeof($aHome) > 0)
  2539. {
  2540. $rnd = rand (0, sizeof($aHome) - 1);
  2541. $home->image = $aHome[$rnd]["image"];
  2542. $home->url = $aHome[$rnd]["url"];
  2543. }
  2544. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2545. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2546. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2547. $sections = Section::orderBy('position')->get();
  2548. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2549. //if($breaking_news->count() == 0)
  2550. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2551. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2552. $season_id = @Season::where('default', '=', true)->first()->id;
  2553. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2554. $calendars = array();
  2555. foreach($cals as $c)
  2556. {
  2557. if ($c->category->grp != '')
  2558. {
  2559. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2560. if ($c->group_id > 0)
  2561. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2562. else
  2563. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2564. }
  2565. }
  2566. $page = Page::where('slug', '=', $slug)->first();
  2567. if ($page != null)
  2568. {
  2569. $news = News::where('slug', '=', $slug2)->first();
  2570. $clicks = $news->clicks;
  2571. if (!$clicks || $clicks == null)
  2572. $clicks = 0;
  2573. $news->clicks = $clicks + 1;
  2574. $news->save();
  2575. $aImages = array();
  2576. if ($news->image1 != '')
  2577. $aImages[] = $news->image1;
  2578. if ($news->image2 != '')
  2579. $aImages[] = $news->image2;
  2580. if ($news->image3 != '')
  2581. $aImages[] = $news->image3;
  2582. if ($news->image4 != '')
  2583. $aImages[] = $news->image4;
  2584. if ($news->image5 != '')
  2585. $aImages[] = $news->image5;
  2586. $elements = News::where('page_id', '=', $page->id)->where('id', '<>', $news->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->limit(4)->get();
  2587. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'regions', 'aHome'));
  2588. }
  2589. });
  2590. Route::get('/calendario/{name}/{id}', function ($name, $id) {
  2591. $home = Home::first();
  2592. if ($home != null)
  2593. $home->loadData();
  2594. $aHome = array();
  2595. if ($home->image != '')
  2596. {
  2597. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2598. }
  2599. if ($home->image_2 != '')
  2600. {
  2601. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2602. }
  2603. if ($home->image_3 != '')
  2604. {
  2605. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2606. }
  2607. if ($home->image_4 != '')
  2608. {
  2609. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2610. }
  2611. if ($home->image_5 != '')
  2612. {
  2613. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2614. }
  2615. if (sizeof($aHome) > 0)
  2616. {
  2617. $rnd = rand (0, sizeof($aHome) - 1);
  2618. $home->image = $aHome[$rnd]["image"];
  2619. $home->url = $aHome[$rnd]["url"];
  2620. }
  2621. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2622. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2623. $sections = Section::orderBy('position')->get();
  2624. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2625. //if($breaking_news->count() == 0)
  2626. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2627. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2628. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2629. $calendar_games = CalendarGame::where('calendar_id', '=', $id)->get();
  2630. $season_id = @Season::where('default', '=', true)->first()->id;
  2631. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2632. $calendars = array();
  2633. foreach($cals as $c)
  2634. {
  2635. if ($c->category->grp != '')
  2636. {
  2637. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2638. if ($c->group_id > 0)
  2639. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2640. else
  2641. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2642. }
  2643. }
  2644. $sel = '';
  2645. $games = array();
  2646. $d = '';
  2647. $t = '';
  2648. foreach($calendar_games as $c)
  2649. {
  2650. $games[$c->day . " " . $c->type][] = $c;
  2651. if ($c->date <= date("Y-m-d 00:00:00"))
  2652. {
  2653. $d = $c->day;
  2654. $t = $c->type;
  2655. }
  2656. }
  2657. $c = Calendar::findOrFail($id);
  2658. $aRates = $c->getRates();
  2659. $count = 1;
  2660. foreach($aRates as $idx => $r)
  2661. {
  2662. if ($r["penality"] != '')
  2663. {
  2664. $aRates[$idx]["team"] = $r["team"] . ' ' . str_repeat('*', $count);
  2665. $aRates[$idx]["penality"] = str_repeat('*', $count) . $r["penality"];
  2666. $count += 1;
  2667. }
  2668. }
  2669. $categoryImage = [];
  2670. if ($c->group)
  2671. {
  2672. $categoryImage = array('url' => $c->group->url, "file" => $c->group->image);
  2673. }
  2674. else
  2675. {
  2676. if ($c->category)
  2677. $categoryImage = array('url' => $c->category->url, "file" => $c->category->image);
  2678. }
  2679. return view('calendar', compact('categoryImage', 'home', 'sections', 'pages', 'c', 'games', 'aRates', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome', 'd', 't', 'sel'));
  2680. });
  2681. Route::get('/{slug}', function ($slug) {
  2682. $home = Home::first();
  2683. if ($home != null)
  2684. $home->loadData();
  2685. $aHome = array();
  2686. if ($home->image != '')
  2687. {
  2688. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2689. }
  2690. if ($home->image_2 != '')
  2691. {
  2692. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2693. }
  2694. if ($home->image_3 != '')
  2695. {
  2696. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2697. }
  2698. if ($home->image_4 != '')
  2699. {
  2700. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2701. }
  2702. if ($home->image_5 != '')
  2703. {
  2704. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2705. }
  2706. if (sizeof($aHome) > 0)
  2707. {
  2708. $rnd = rand (0, sizeof($aHome) - 1);
  2709. $home->image = $aHome[$rnd]["image"];
  2710. $home->url = $aHome[$rnd]["url"];
  2711. }
  2712. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2713. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2714. $sections = Section::orderBy('position')->get();
  2715. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2716. //if($breaking_news->count() == 0)
  2717. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2718. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2719. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2720. $season_id = @Season::where('default', '=', true)->first()->id;
  2721. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2722. $calendars = array();
  2723. foreach($cals as $c)
  2724. {
  2725. if ($c->category->grp != '')
  2726. {
  2727. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2728. if ($c->group_id > 0)
  2729. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2730. else
  2731. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2732. }
  2733. }
  2734. // Controllo se è una sezione o regione, altrimenti news
  2735. $section = Section::where('slug', '=', $slug)->first();
  2736. if ($section != null)
  2737. {
  2738. if ($section->type == 'section')
  2739. $news = News::where('section_id', '=', $section->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2740. else
  2741. {
  2742. $news = News::where('online', '=', true)->where(function ($q) use ($section) {
  2743. $q->where('region_1_id', '=', $section->id)->orWhere('region_2_id', '=', $section->id);
  2744. })->orderBy('date', 'DESC')->get();
  2745. }
  2746. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2747. }
  2748. $news = News::where('slug', '=', $slug)->first();
  2749. if ($news != null)
  2750. {
  2751. // Controllo se è online altrimenti vado alla home
  2752. if (!$news->online || $news->date > date("Y-m-d H:i:s"))
  2753. return Redirect::to('/');
  2754. $clicks = $news->clicks;
  2755. if (!$clicks || $clicks == null)
  2756. $clicks = 0;
  2757. $news->clicks = $clicks + 1;
  2758. $news->save();
  2759. $aImages = array();
  2760. if ($news->image1 != '')
  2761. $aImages[] = $news->image1;
  2762. if ($news->image2 != '')
  2763. $aImages[] = $news->image2;
  2764. if ($news->image3 != '')
  2765. $aImages[] = $news->image3;
  2766. if ($news->image4 != '')
  2767. $aImages[] = $news->image4;
  2768. if ($news->image5 != '')
  2769. $aImages[] = $news->image5;
  2770. $elements = News::where('section_id', '=', $news->section_id)->where('id', '<>', $news->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->limit(5)->get();
  2771. // Se la news è associata ad una pagina, carico gli advs di quella pagina
  2772. $advs = array();
  2773. if ($news->page_id > 0)
  2774. {
  2775. $page = $news->page;
  2776. $advs = $news->page->getAdvs();
  2777. $elements = News::where('page_id', '=', $news->page_id)->where('id', '<>', @$news->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->limit(4)->get();
  2778. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2779. }
  2780. else
  2781. return view('news', compact('home', 'news', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2782. }
  2783. $page = Page::where('slug', '=', $slug)->first();
  2784. if ($page != null)
  2785. {
  2786. $news = News::where('page_id', '=', $page->id)->where('online', '=', true)->orderBy('date', 'DESC')->first();
  2787. $aImages = array();
  2788. if ($news)
  2789. {
  2790. if ($news->image1 != '')
  2791. $aImages[] = $news->image1;
  2792. if ($news->image2 != '')
  2793. $aImages[] = $news->image2;
  2794. if ($news->image3 != '')
  2795. $aImages[] = $news->image3;
  2796. if ($news->image4 != '')
  2797. $aImages[] = $news->image4;
  2798. if ($news->image5 != '')
  2799. $aImages[] = $news->image5;
  2800. }
  2801. $elements = News::where('page_id', '=', $page->id)->where('id', '<>', @$news->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->limit(4)->get();
  2802. // $news = $elements->first();
  2803. $advs = $page->getAdvs();
  2804. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2805. }
  2806. /*$event = Event::where('slug', '=', $slug)->first();
  2807. if ($event != null)
  2808. {
  2809. $event->loadLayout();
  2810. $aAssigned = array();
  2811. if ($event->big != '')
  2812. $aAssigned[] = @$event->big->id;
  2813. if ($event->small1 != '')
  2814. $aAssigned[] = @$event->small1->id;
  2815. if ($event->small2 != '')
  2816. $aAssigned[] = @$event->small2->id;
  2817. if ($event->small3 != '')
  2818. $aAssigned[] = @$event->small3->id;
  2819. if ($event->small4 != '')
  2820. $aAssigned[] = @$event->small4->id;
  2821. $elements = News::whereNotIn('id', $aAssigned)->where('event_id', '=', $event->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->limit(5)->get();
  2822. return view('event', compact('home', 'event', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2823. }*/
  2824. });