web.php 114 KB

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