web.php 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379
  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::orderBy('name')->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. $image = $_POST["imagebase64H"];
  1763. $imageInfo = explode(";base64,", $image);
  1764. $imgExt = str_replace('data:image/', '', $imageInfo[0]);
  1765. $image = str_replace(' ', '+', $imageInfo[1]);
  1766. $imageName = time().".".$imgExt;
  1767. $path = public_path()."/files/news/".$imageName;
  1768. file_put_contents($path, base64_decode($image));
  1769. $imageV = $_POST["imagebase64V"];
  1770. $imageInfoV = explode(";base64,", $imageV);
  1771. $imgExtV = str_replace('data:image/', '', $imageInfoV[0]);
  1772. $imageV = str_replace(' ', '+', $imageInfoV[1]);
  1773. $imageNameV = "V_".time().".".$imgExt;
  1774. $pathV = public_path()."/files/news/".$imageNameV;
  1775. file_put_contents($pathV, base64_decode($imageV));
  1776. if ($_POST["news_id"] > 0)
  1777. {
  1778. $news = News::findOrFail($_POST["news_id"]);
  1779. $news->image = $imageName;
  1780. $news->save();
  1781. return Redirect::to('/admin/news/' . $_POST["news_id"] . "/edit");
  1782. }
  1783. else
  1784. return Redirect::to('/admin/news/create?filename=' . $imageName);
  1785. })->name('news.crop_save');
  1786. Route::get('news/load_json', 'NewsController@load_json')->name('load_json');
  1787. Route::get('news/status/{id}/{status}', function ($id, $status) {
  1788. $n = News::findOrFail($id);
  1789. $n->online = $status == 'online';
  1790. if ($status == 'online')
  1791. {
  1792. if ($n->date <= date("Y-m-d H:i:s"))
  1793. {
  1794. if ($n->section_position != '')
  1795. {
  1796. $s = Section::findOrFail($n->section_id);
  1797. $s[$n->section_position] = $n->id;
  1798. $s->save();
  1799. $n->section_position = '';
  1800. }
  1801. if ($n->region_1_position != '')
  1802. {
  1803. $s = Section::findOrFail($n->region_1_id);
  1804. $s[$n->region_1_position] = $n->id;
  1805. $s->save();
  1806. $n->region_1_position = '';
  1807. }
  1808. if ($n->region_2_position != '')
  1809. {
  1810. $s = Section::findOrFail($n->region_2_id);
  1811. $s[$n->region_2_position] = $n->id;
  1812. $s->save();
  1813. $n->region_2_position = '';
  1814. }
  1815. $n->save();
  1816. if (!$n->published)
  1817. {
  1818. // $n->notify(new FacebookPost());
  1819. $n->notify(new TwitterPost());
  1820. $n->published = true;
  1821. }
  1822. }
  1823. }
  1824. else
  1825. {
  1826. }
  1827. $n->save();
  1828. return Redirect::to('/admin/news');
  1829. });
  1830. Route::resource('news','NewsController');
  1831. Route::resource('breaking_news','BreakingNewsController');
  1832. Route::get('/sections/sort/{ids}', function ($ids) {
  1833. $idx = explode(",", $ids);
  1834. foreach($idx as $x => $id)
  1835. {
  1836. $s = Section::findOrFail($id);
  1837. $s->position = $x;
  1838. $s->save();
  1839. }
  1840. });
  1841. Route::get('/sections/layout/{id}', function ($id) {
  1842. $section = Section::findOrFail($id);
  1843. if (isset($_GET["layout"]))
  1844. {
  1845. $section->big = '';
  1846. $section->small1 = '';
  1847. $section->small2 = '';
  1848. $section->small3 = '';
  1849. $section->small4 = '';
  1850. $section->small5 = '';
  1851. $section->small6 = '';
  1852. $section->save();
  1853. }
  1854. $section->loadLayout();
  1855. $aAssigned = array();
  1856. if ($section->big != '')
  1857. $aAssigned[] = @$section->big->id;
  1858. if ($section->small1 != '')
  1859. $aAssigned[] = @$section->small1->id;
  1860. if ($section->small2 != '')
  1861. $aAssigned[] = @$section->small2->id;
  1862. if ($section->small3 != '')
  1863. $aAssigned[] = @$section->small3->id;
  1864. if ($section->small4 != '')
  1865. $aAssigned[] = @$section->small4->id;
  1866. if ($section->small5 != '')
  1867. $aAssigned[] = @$section->small5->id;
  1868. if ($section->small6 != '')
  1869. $aAssigned[] = @$section->small6->id;
  1870. $news = News::whereNotIn('id', $aAssigned)->where(function ($q) use ($id) {
  1871. $q->where('section_id', '=', $id)->orWhere('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
  1872. })->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  1873. return view('sections.layout',compact('section', 'news'));
  1874. })->name('sections.layout');
  1875. Route::post('/sections/layout/{id}', function ($id) {
  1876. $section = Section::findOrFail($id);
  1877. $layout = isset($_POST["layout"]) ? $_POST["layout"] : '';
  1878. $big = isset($_POST["big"]) ? $_POST["big"] : '';
  1879. $small1 = isset($_POST["small1"]) ? $_POST["small1"] : '';
  1880. $small2 = isset($_POST["small2"]) ? $_POST["small2"] : '';
  1881. $small3 = isset($_POST["small3"]) ? $_POST["small3"] : '';
  1882. $small4 = isset($_POST["small4"]) ? $_POST["small4"] : '';
  1883. $small5 = isset($_POST["small5"]) ? $_POST["small5"] : '';
  1884. $small6 = isset($_POST["small6"]) ? $_POST["small6"] : '';
  1885. $aSel = array();
  1886. if (isset($_POST["big"]))
  1887. $aSel[] = $_POST["big"];
  1888. if (isset($_POST["small1"]))
  1889. $aSel[] = $_POST["small1"];
  1890. if (isset($_POST["small2"]))
  1891. $aSel[] = $_POST["small2"];
  1892. if (isset($_POST["small3"]))
  1893. $aSel[] = $_POST["small3"];
  1894. if (isset($_POST["small4"]))
  1895. $aSel[] = $_POST["small4"];
  1896. if (isset($_POST["small5"]))
  1897. $aSel[] = $_POST["small5"];
  1898. if (isset($_POST["small6"]))
  1899. $aSel[] = $_POST["small6"];
  1900. // Riempio i vuoti
  1901. $news = News::whereNotIn('id', $aSel)->where(function ($q) use ($id) {
  1902. $q->where('section_id', '=', $id)->orWhere('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
  1903. })->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  1904. $idx = 0;
  1905. $section->layout = $layout;
  1906. if ($big == '')
  1907. {
  1908. $section->big = @$news[$idx]->id;
  1909. $idx++;
  1910. }
  1911. else
  1912. $section->big = $big;
  1913. if ($small1 == '')
  1914. {
  1915. $section->small1 = @$news[$idx]->id;
  1916. $idx++;
  1917. }
  1918. else
  1919. $section->small1 = $small1;
  1920. if ($small2 == '')
  1921. {
  1922. $section->small2 = @$news[$idx]->id;
  1923. $idx++;
  1924. }
  1925. else
  1926. $section->small2 = $small2;
  1927. if ($small3 == '')
  1928. {
  1929. $section->small3 = @$news[$idx]->id;
  1930. $idx++;
  1931. }
  1932. else
  1933. $section->small3 = $small3;
  1934. if ($layout == 'layout_3' || $layout == 'layout_4' || $layout == 'layout_5' || $layout == 'layout_7')
  1935. {
  1936. if ($small4 == '')
  1937. {
  1938. $section->small4 = @$news[$idx]->id;
  1939. $idx++;
  1940. }
  1941. else
  1942. $section->small4 = $small4;
  1943. if ($layout == 'layout_4')
  1944. {
  1945. if ($small5 == '')
  1946. {
  1947. $section->small5 = @$news[$idx]->id;
  1948. $idx++;
  1949. }
  1950. else
  1951. $section->small5 = $small5;
  1952. if ($small6 == '')
  1953. {
  1954. $section->small6 = @$news[$idx]->id;
  1955. $idx++;
  1956. }
  1957. else
  1958. $section->small6 = $small6;
  1959. }
  1960. else
  1961. {
  1962. $section->small5 = '';
  1963. $section->small6 = '';
  1964. }
  1965. }
  1966. else
  1967. {
  1968. $section->small4 = '';
  1969. $section->small5 = '';
  1970. $section->small6 = '';
  1971. }
  1972. $section->save();
  1973. // CLEARLAYOUT
  1974. // $section->clearLayout();
  1975. return Redirect::to('/admin/sections');
  1976. });
  1977. Route::get('/events/layout/{id}', function ($id) {
  1978. $event = Event::findOrFail($id);
  1979. $event->loadLayout();
  1980. $aAssigned = array();
  1981. if ($event->big != '')
  1982. $aAssigned[] = @$event->big->id;
  1983. if ($event->small1 != '')
  1984. $aAssigned[] = @$event->small1->id;
  1985. if ($event->small2 != '')
  1986. $aAssigned[] = @$event->small2->id;
  1987. if ($event->small3 != '')
  1988. $aAssigned[] = @$event->small3->id;
  1989. if ($event->small4 != '')
  1990. $aAssigned[] = @$event->small4->id;
  1991. $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();
  1992. return view('events.layout',compact('event', 'news'));
  1993. })->name('events.layout');
  1994. Route::post('/events/layout/{id}', function ($id) {
  1995. $event = Event::findOrFail($id);
  1996. $big = isset($_POST["big"]) ? $_POST["big"] : '';
  1997. $small1 = isset($_POST["small1"]) ? $_POST["small1"] : '';
  1998. $small2 = isset($_POST["small2"]) ? $_POST["small2"] : '';
  1999. $small3 = isset($_POST["small3"]) ? $_POST["small3"] : '';
  2000. $small4 = isset($_POST["small4"]) ? $_POST["small4"] : '';
  2001. $aSel = array();
  2002. if (isset($_POST["big"]))
  2003. $aSel[] = $_POST["big"];
  2004. if (isset($_POST["small1"]))
  2005. $aSel[] = $_POST["small1"];
  2006. if (isset($_POST["small2"]))
  2007. $aSel[] = $_POST["small2"];
  2008. if (isset($_POST["small3"]))
  2009. $aSel[] = $_POST["small3"];
  2010. if (isset($_POST["small4"]))
  2011. $aSel[] = $_POST["small4"];
  2012. $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();
  2013. $idx = 0;
  2014. if ($big == '')
  2015. {
  2016. $event->big = @$news[$idx]->id;
  2017. $idx++;
  2018. }
  2019. else
  2020. $event->big = $big;
  2021. if ($small1 == '')
  2022. {
  2023. $event->small1 = @$news[$idx]->id;
  2024. $idx++;
  2025. }
  2026. else
  2027. $event->small1 = $small1;
  2028. if ($small2 == '')
  2029. {
  2030. $event->small2 = @$news[$idx]->id;
  2031. $idx++;
  2032. }
  2033. else
  2034. $event->small2 = $small2;
  2035. if ($small3 == '')
  2036. {
  2037. $event->small3 = @$news[$idx]->id;
  2038. $idx++;
  2039. }
  2040. else
  2041. $event->small3 = $small3;
  2042. if ($small4 == '')
  2043. {
  2044. $event->small4 = @$news[$idx]->id;
  2045. $idx++;
  2046. }
  2047. else
  2048. $event->small4 = $small4;
  2049. $event->save();
  2050. return Redirect::to('/admin/events');
  2051. });
  2052. Route::get('/sections/to_event/{id}', function ($id) {
  2053. $section = Section::findOrFail($id);
  2054. $event = new Event();
  2055. $event->title = $section->name;
  2056. $event->text_short = '';
  2057. $event->text = '';
  2058. $event->image = '';
  2059. $event->slug = $section->slug;
  2060. $event->online = true;
  2061. $event->save();
  2062. $news = News::where('section_id', '=', $id)->get();
  2063. foreach($news as $n)
  2064. {
  2065. $n->event_id = $event->id;
  2066. $n->section_id = null;
  2067. $n->save();
  2068. }
  2069. $news = News::where('region_1_id', '=', $id)->get();
  2070. foreach($news as $n)
  2071. {
  2072. $n->event_id = $event->id;
  2073. $n->region_1_id = null;
  2074. $n->save();
  2075. }
  2076. $news = News::where('region_2_id', '=', $id)->get();
  2077. foreach($news as $n)
  2078. {
  2079. $n->event_id = $event->id;
  2080. $n->region_2_id = null;
  2081. $n->save();
  2082. }
  2083. $advs = SectionAdv::where('section_id', '=', $id)->get();
  2084. foreach($advs as $adv)
  2085. {
  2086. $adv->section_id = null;
  2087. $adv->save();
  2088. }
  2089. // $section->slug = $section->slug . "_old";
  2090. $section->delete();
  2091. return Redirect::to('/admin/events/' . $event->id . '/edit');
  2092. })->name('sections.to_event');
  2093. Route::resource('sections.advs','SectionAdvController');
  2094. Route::resource('sections','SectionController');
  2095. Route::resource('categories.groups','GroupController');
  2096. Route::resource('categories','CategoryController');
  2097. Route::get('/adv/sort/{ids}', function ($ids) {
  2098. $idx = explode(",", $ids);
  2099. foreach($idx as $x => $id)
  2100. {
  2101. $s = PageAdv::findOrFail($id);
  2102. $s->sort = $x;
  2103. $s->save();
  2104. }
  2105. });
  2106. Route::resource('pages.advs','PageAdvController');
  2107. Route::resource('pages','PageController');
  2108. Route::resource('events.advs','EventAdvController');
  2109. Route::resource('events','EventController');
  2110. Route::get('/calendars/sort/{ids}', function ($ids) {
  2111. $idx = explode(",", $ids);
  2112. foreach($idx as $x => $id)
  2113. {
  2114. $c = Calendar::findOrFail($id);
  2115. $c->position = $x;
  2116. $c->save();
  2117. }
  2118. });
  2119. Route::resource('calendars','CalendarController');
  2120. Route::get('/calendars/archive/{id}', function ($id) {
  2121. $c = Calendar::findOrFail($id);
  2122. $c->archived = true;
  2123. $c->save();
  2124. return Redirect::to('/admin/calendars');
  2125. })->name('calendars.archive');
  2126. Route::get('/calendars/games/{id}', function ($id) {
  2127. $calendar = CalendarGame::where('calendar_id', '=', $id)->get();;
  2128. $games = array();
  2129. foreach($calendar as $c)
  2130. {
  2131. $games[$c->day . " " . $c->type][] = $c;
  2132. }
  2133. $c = Calendar::findOrFail($id);
  2134. $aRates = $c->getRates();
  2135. $count = 1;
  2136. foreach($aRates as $idx => $r)
  2137. {
  2138. if ($r["penality"] != '')
  2139. {
  2140. $aRates[$idx]["team"] = $r["team"] . ' ' . str_repeat('*', $count);
  2141. $aRates[$idx]["penality"] = str_repeat('*', $count) . $r["penality"];
  2142. $count += 1;
  2143. }
  2144. }
  2145. return view('calendars.games',compact('games', 'aRates'));
  2146. })->name('calendars.games');
  2147. Route::get('/calendars/games/{id}/{day}/{type}', function ($id, $day, $type) {
  2148. $games = CalendarGame::where('calendar_id', '=', $id)->where('day', '=', $day)->where('type', '=', $type)->get();;
  2149. return view('calendars.games_edit',compact('games', 'id', 'day', 'type'));
  2150. })->name('calendars.games_edit');
  2151. Route::post('/calendars/games/{id}/{day}/{type}', function ($id, $day, $type) {
  2152. $games = CalendarGame::where('calendar_id', '=', $id)->where('day', '=', $day)->where('type', '=', $type)->get();;
  2153. foreach($games as $g)
  2154. {
  2155. $date = isset($_POST["date_" . $g->id]) ? $_POST["date_" . $g->id] : '';
  2156. list($day, $month, $year) = explode("/", $date);
  2157. $g->date = $year . "-" . $month . "-" . $day;
  2158. $g->save();
  2159. $home_goals = isset($_POST["home_goals_" . $g->id]) ? $_POST["home_goals_" . $g->id] : '';
  2160. $away_goals = isset($_POST["away_goals_" . $g->id]) ? $_POST["away_goals_" . $g->id] : '';
  2161. $delete = isset($_POST["delete_" . $g->id]) ? true : false;
  2162. if ($delete)
  2163. {
  2164. $g->played = false;
  2165. $g->home_goals = null;
  2166. $g->away_goals = null;
  2167. $g->home_points = 0;
  2168. $g->away_points = 0;
  2169. $g->save();
  2170. }
  2171. else
  2172. {
  2173. if ($home_goals != '' && $away_goals != '')
  2174. {
  2175. $home_points = 0;
  2176. $away_points = 0;
  2177. if ($home_goals > $away_goals)
  2178. {
  2179. $home_points = 3;
  2180. $away_points = 0;
  2181. }
  2182. else if ($home_goals == $away_goals)
  2183. {
  2184. $home_points = 1;
  2185. $away_points = 1;
  2186. }
  2187. else
  2188. {
  2189. $home_points = 0;
  2190. $away_points = 3;
  2191. }
  2192. $g->played = true;
  2193. $g->home_goals = $home_goals;
  2194. $g->away_goals = $away_goals;
  2195. $g->home_points = $home_points;
  2196. $g->away_points = $away_points;
  2197. $g->save();
  2198. }
  2199. }
  2200. }
  2201. return Redirect::to('/admin/calendars/games/' . $id);
  2202. });
  2203. Route::resource('seasons','SeasonController');
  2204. Route::resource('teams','TeamController');
  2205. Route::get('/videos/sort/{ids}', function ($ids) {
  2206. $idx = explode(",", $ids);
  2207. foreach($idx as $x => $id)
  2208. {
  2209. $v = Video::findOrFail($id);
  2210. $v->position = $x;
  2211. $v->save();
  2212. }
  2213. });
  2214. Route::resource('videos','VideoController');
  2215. Route::resource('users','UserController');
  2216. Route::get('/load_categories/{type}', function ($type) {
  2217. $categories = Category::where('type', '=', $type)->get();
  2218. return $categories->toJson();
  2219. });
  2220. Route::get('/load_groups/{category}', function ($category) {
  2221. $groups = Group::where('category_id', '=', $category)->get();
  2222. return $groups->toJson();
  2223. });
  2224. });
  2225. });
  2226. Route::get('/{slug}/elenco', function ($slug) {
  2227. $home = Home::first();
  2228. if ($home != null)
  2229. $home->loadData();
  2230. $aHome = array();
  2231. if ($home->image != '')
  2232. {
  2233. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2234. }
  2235. if ($home->image_2 != '')
  2236. {
  2237. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2238. }
  2239. if ($home->image_3 != '')
  2240. {
  2241. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2242. }
  2243. if ($home->image_4 != '')
  2244. {
  2245. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2246. }
  2247. if ($home->image_5 != '')
  2248. {
  2249. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2250. }
  2251. if (sizeof($aHome) > 0)
  2252. {
  2253. $rnd = rand (0, sizeof($aHome) - 1);
  2254. $home->image = $aHome[$rnd]["image"];
  2255. $home->url = $aHome[$rnd]["url"];
  2256. }
  2257. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2258. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2259. $sections = Section::orderBy('position')->get();
  2260. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2261. //if($breaking_news->count() == 0)
  2262. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2263. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2264. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2265. $season_id = @Season::where('default', '=', true)->first()->id;
  2266. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2267. $calendars = array();
  2268. foreach($cals as $c)
  2269. {
  2270. if ($c->category->grp != '')
  2271. {
  2272. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2273. if ($c->group_id > 0)
  2274. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2275. else
  2276. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2277. }
  2278. }
  2279. $page = Page::where('slug', '=', $slug)->first();
  2280. if ($page != null)
  2281. {
  2282. $section = $page;
  2283. $news = News::where('page_id', '=', $page->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2284. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2285. }
  2286. });
  2287. Route::get('/eventi/{slug}', function ($slug) {
  2288. $home = Home::first();
  2289. if ($home != null)
  2290. $home->loadData();
  2291. $aHome = array();
  2292. if ($home->image != '')
  2293. {
  2294. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2295. }
  2296. if ($home->image_2 != '')
  2297. {
  2298. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2299. }
  2300. if ($home->image_3 != '')
  2301. {
  2302. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2303. }
  2304. if ($home->image_4 != '')
  2305. {
  2306. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2307. }
  2308. if ($home->image_5 != '')
  2309. {
  2310. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2311. }
  2312. if (sizeof($aHome) > 0)
  2313. {
  2314. $rnd = rand (0, sizeof($aHome) - 1);
  2315. $home->image = $aHome[$rnd]["image"];
  2316. $home->url = $aHome[$rnd]["url"];
  2317. }
  2318. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2319. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2320. $sections = Section::orderBy('position')->get();
  2321. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2322. //if($breaking_news->count() == 0)
  2323. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2324. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2325. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2326. $season_id = @Season::where('default', '=', true)->first()->id;
  2327. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2328. $calendars = array();
  2329. foreach($cals as $c)
  2330. {
  2331. if ($c->category->grp != '')
  2332. {
  2333. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2334. if ($c->group_id > 0)
  2335. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2336. else
  2337. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2338. }
  2339. }
  2340. $event = Event::where('slug', '=', $slug)->first();
  2341. if ($event != null)
  2342. {
  2343. $event->loadLayout();
  2344. /*$aAssigned = array();
  2345. if ($event->big != '')
  2346. $aAssigned[] = @$event->big->id;
  2347. if ($event->small1 != '')
  2348. $aAssigned[] = @$event->small1->id;
  2349. if ($event->small2 != '')
  2350. $aAssigned[] = @$event->small2->id;
  2351. if ($event->small3 != '')
  2352. $aAssigned[] = @$event->small3->id;
  2353. if ($event->small4 != '')
  2354. $aAssigned[] = @$event->small4->id;*/
  2355. $elements = News::where('event_id', '=', $event->id)->take(5)->get();
  2356. return view('event', compact('home', 'event', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2357. }
  2358. });
  2359. Route::get('/eventi/{slug}/elenco', function ($slug) {
  2360. $home = Home::first();
  2361. if ($home != null)
  2362. $home->loadData();
  2363. $aHome = array();
  2364. if ($home->image != '')
  2365. {
  2366. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2367. }
  2368. if ($home->image_2 != '')
  2369. {
  2370. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2371. }
  2372. if ($home->image_3 != '')
  2373. {
  2374. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2375. }
  2376. if ($home->image_4 != '')
  2377. {
  2378. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2379. }
  2380. if ($home->image_5 != '')
  2381. {
  2382. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2383. }
  2384. if (sizeof($aHome) > 0)
  2385. {
  2386. $rnd = rand (0, sizeof($aHome) - 1);
  2387. $home->image = $aHome[$rnd]["image"];
  2388. $home->url = $aHome[$rnd]["url"];
  2389. }
  2390. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2391. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2392. $sections = Section::orderBy('position')->get();
  2393. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2394. //if($breaking_news->count() == 0)
  2395. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2396. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2397. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2398. $season_id = @Season::where('default', '=', true)->first()->id;
  2399. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2400. $calendars = array();
  2401. foreach($cals as $c)
  2402. {
  2403. if ($c->category->grp != '')
  2404. {
  2405. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2406. if ($c->group_id > 0)
  2407. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2408. else
  2409. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2410. }
  2411. }
  2412. $event = Event::where('slug', '=', $slug)->first();
  2413. if ($event != null)
  2414. {
  2415. $section = $event;
  2416. $news = News::where('event_id', '=', $event->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2417. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2418. }
  2419. });
  2420. Route::get('/{slug}/{slug2}', function ($slug, $slug2) {
  2421. $home = Home::first();
  2422. if ($home != null)
  2423. $home->loadData();
  2424. $aHome = array();
  2425. if ($home->image != '')
  2426. {
  2427. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2428. }
  2429. if ($home->image_2 != '')
  2430. {
  2431. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2432. }
  2433. if ($home->image_3 != '')
  2434. {
  2435. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2436. }
  2437. if ($home->image_4 != '')
  2438. {
  2439. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2440. }
  2441. if ($home->image_5 != '')
  2442. {
  2443. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2444. }
  2445. if (sizeof($aHome) > 0)
  2446. {
  2447. $rnd = rand (0, sizeof($aHome) - 1);
  2448. $home->image = $aHome[$rnd]["image"];
  2449. $home->url = $aHome[$rnd]["url"];
  2450. }
  2451. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2452. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2453. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2454. $sections = Section::orderBy('position')->get();
  2455. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2456. //if($breaking_news->count() == 0)
  2457. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2458. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2459. $season_id = @Season::where('default', '=', true)->first()->id;
  2460. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2461. $calendars = array();
  2462. foreach($cals as $c)
  2463. {
  2464. if ($c->category->grp != '')
  2465. {
  2466. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2467. if ($c->group_id > 0)
  2468. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2469. else
  2470. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2471. }
  2472. }
  2473. $page = Page::where('slug', '=', $slug)->first();
  2474. if ($page != null)
  2475. {
  2476. $news = News::where('slug', '=', $slug2)->first();
  2477. $clicks = $news->clicks;
  2478. if (!$clicks || $clicks == null)
  2479. $clicks = 0;
  2480. $news->clicks = $clicks + 1;
  2481. $news->save();
  2482. $aImages = array();
  2483. if ($news->image1 != '')
  2484. $aImages[] = $news->image1;
  2485. if ($news->image2 != '')
  2486. $aImages[] = $news->image2;
  2487. if ($news->image3 != '')
  2488. $aImages[] = $news->image3;
  2489. if ($news->image4 != '')
  2490. $aImages[] = $news->image4;
  2491. if ($news->image5 != '')
  2492. $aImages[] = $news->image5;
  2493. $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();
  2494. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'regions', 'aHome'));
  2495. }
  2496. });
  2497. Route::get('/calendario/{name}/{id}', function ($name, $id) {
  2498. $home = Home::first();
  2499. if ($home != null)
  2500. $home->loadData();
  2501. $aHome = array();
  2502. if ($home->image != '')
  2503. {
  2504. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2505. }
  2506. if ($home->image_2 != '')
  2507. {
  2508. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2509. }
  2510. if ($home->image_3 != '')
  2511. {
  2512. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2513. }
  2514. if ($home->image_4 != '')
  2515. {
  2516. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2517. }
  2518. if ($home->image_5 != '')
  2519. {
  2520. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2521. }
  2522. if (sizeof($aHome) > 0)
  2523. {
  2524. $rnd = rand (0, sizeof($aHome) - 1);
  2525. $home->image = $aHome[$rnd]["image"];
  2526. $home->url = $aHome[$rnd]["url"];
  2527. }
  2528. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2529. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2530. $sections = Section::orderBy('position')->get();
  2531. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2532. //if($breaking_news->count() == 0)
  2533. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2534. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2535. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2536. $calendar_games = CalendarGame::where('calendar_id', '=', $id)->get();
  2537. $season_id = @Season::where('default', '=', true)->first()->id;
  2538. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2539. $calendars = array();
  2540. foreach($cals as $c)
  2541. {
  2542. if ($c->category->grp != '')
  2543. {
  2544. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2545. if ($c->group_id > 0)
  2546. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2547. else
  2548. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2549. }
  2550. }
  2551. $sel = '';
  2552. $games = array();
  2553. $d = '';
  2554. $t = '';
  2555. foreach($calendar_games as $c)
  2556. {
  2557. $games[$c->day . " " . $c->type][] = $c;
  2558. if ($c->date <= date("Y-m-d 00:00:00"))
  2559. {
  2560. $d = $c->day;
  2561. $t = $c->type;
  2562. }
  2563. }
  2564. $c = Calendar::findOrFail($id);
  2565. $aRates = $c->getRates();
  2566. $count = 1;
  2567. foreach($aRates as $idx => $r)
  2568. {
  2569. if ($r["penality"] != '')
  2570. {
  2571. $aRates[$idx]["team"] = $r["team"] . ' ' . str_repeat('*', $count);
  2572. $aRates[$idx]["penality"] = str_repeat('*', $count) . $r["penality"];
  2573. $count += 1;
  2574. }
  2575. }
  2576. $categoryImage = [];
  2577. if ($c->group)
  2578. {
  2579. $categoryImage = array('url' => $c->group->url, "file" => $c->group->image);
  2580. }
  2581. else
  2582. {
  2583. if ($c->category)
  2584. $categoryImage = array('url' => $c->category->url, "file" => $c->category->image);
  2585. }
  2586. return view('calendar', compact('categoryImage', 'home', 'sections', 'pages', 'c', 'games', 'aRates', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome', 'd', 't', 'sel'));
  2587. });
  2588. Route::get('/{slug}', function ($slug) {
  2589. $home = Home::first();
  2590. if ($home != null)
  2591. $home->loadData();
  2592. $aHome = array();
  2593. if ($home->image != '')
  2594. {
  2595. $aHome[] = ['image' => $home->image, 'url' => $home->url];
  2596. }
  2597. if ($home->image_2 != '')
  2598. {
  2599. $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
  2600. }
  2601. if ($home->image_3 != '')
  2602. {
  2603. $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
  2604. }
  2605. if ($home->image_4 != '')
  2606. {
  2607. $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
  2608. }
  2609. if ($home->image_5 != '')
  2610. {
  2611. $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
  2612. }
  2613. if (sizeof($aHome) > 0)
  2614. {
  2615. $rnd = rand (0, sizeof($aHome) - 1);
  2616. $home->image = $aHome[$rnd]["image"];
  2617. $home->url = $aHome[$rnd]["url"];
  2618. }
  2619. $pages = Page::where('online', '=', true)->orderBy('title')->get();
  2620. $events = Event::where('online', '=', true)->orderBy('title')->get();
  2621. $sections = Section::orderBy('position')->get();
  2622. $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
  2623. //if($breaking_news->count() == 0)
  2624. // $breaking_news = News::where('breaking_news', '=', true)->orderBy('date', "DESC")->get();
  2625. $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
  2626. $regions = Section::where('type', '=', 'region')->orderBy('name')->get();
  2627. $season_id = @Season::where('default', '=', true)->first()->id;
  2628. $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
  2629. $calendars = array();
  2630. foreach($cals as $c)
  2631. {
  2632. if ($c->category->grp != '')
  2633. {
  2634. $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
  2635. if ($c->group_id > 0)
  2636. $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
  2637. else
  2638. $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
  2639. }
  2640. }
  2641. // Controllo se è una sezione o regione, altrimenti news
  2642. $section = Section::where('slug', '=', $slug)->first();
  2643. if ($section != null)
  2644. {
  2645. if ($section->type == 'section')
  2646. $news = News::where('section_id', '=', $section->id)->where('online', '=', true)->where('date', '<=', date("Y-m-d H:i:s"))->orderBy('date', 'DESC')->get();
  2647. else
  2648. {
  2649. $news = News::where('online', '=', true)->where(function ($q) use ($section) {
  2650. $q->where('region_1_id', '=', $section->id)->orWhere('region_2_id', '=', $section->id);
  2651. })->orderBy('date', 'DESC')->get();
  2652. }
  2653. return view('section', compact('home', 'news', 'sections', 'pages', 'section', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2654. }
  2655. $news = News::where('slug', '=', $slug)->first();
  2656. if ($news != null)
  2657. {
  2658. // Controllo se è online altrimenti vado alla home
  2659. if (!$news->online || $news->date > date("Y-m-d H:i:s"))
  2660. return Redirect::to('/');
  2661. $clicks = $news->clicks;
  2662. if (!$clicks || $clicks == null)
  2663. $clicks = 0;
  2664. $news->clicks = $clicks + 1;
  2665. $news->save();
  2666. $aImages = array();
  2667. if ($news->image1 != '')
  2668. $aImages[] = $news->image1;
  2669. if ($news->image2 != '')
  2670. $aImages[] = $news->image2;
  2671. if ($news->image3 != '')
  2672. $aImages[] = $news->image3;
  2673. if ($news->image4 != '')
  2674. $aImages[] = $news->image4;
  2675. if ($news->image5 != '')
  2676. $aImages[] = $news->image5;
  2677. $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();
  2678. // Se la news è associata ad una pagina, carico gli advs di quella pagina
  2679. $advs = array();
  2680. if ($news->page_id > 0)
  2681. {
  2682. $page = $news->page;
  2683. $advs = $news->page->getAdvs();
  2684. $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();
  2685. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2686. }
  2687. else
  2688. return view('news', compact('home', 'news', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2689. }
  2690. $page = Page::where('slug', '=', $slug)->first();
  2691. if ($page != null)
  2692. {
  2693. $news = News::where('page_id', '=', $page->id)->orderBy('date', 'DESC')->first();
  2694. $aImages = array();
  2695. if ($news)
  2696. {
  2697. if ($news->image1 != '')
  2698. $aImages[] = $news->image1;
  2699. if ($news->image2 != '')
  2700. $aImages[] = $news->image2;
  2701. if ($news->image3 != '')
  2702. $aImages[] = $news->image3;
  2703. if ($news->image4 != '')
  2704. $aImages[] = $news->image4;
  2705. if ($news->image5 != '')
  2706. $aImages[] = $news->image5;
  2707. }
  2708. $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();
  2709. // $news = $elements->first();
  2710. $advs = $page->getAdvs();
  2711. return view('page', compact('home', 'page', 'elements', 'sections', 'pages', 'news', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aImages', 'aHome', 'advs'));
  2712. }
  2713. /*$event = Event::where('slug', '=', $slug)->first();
  2714. if ($event != null)
  2715. {
  2716. $event->loadLayout();
  2717. $aAssigned = array();
  2718. if ($event->big != '')
  2719. $aAssigned[] = @$event->big->id;
  2720. if ($event->small1 != '')
  2721. $aAssigned[] = @$event->small1->id;
  2722. if ($event->small2 != '')
  2723. $aAssigned[] = @$event->small2->id;
  2724. if ($event->small3 != '')
  2725. $aAssigned[] = @$event->small3->id;
  2726. if ($event->small4 != '')
  2727. $aAssigned[] = @$event->small4->id;
  2728. $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();
  2729. return view('event', compact('home', 'event', 'elements', 'sections', 'pages', 'sections_menu', 'regions', 'events', 'breaking_news', 'sections_menu', 'calendars', 'aHome'));
  2730. }*/
  2731. });