/** * @param $match Match * @param $team Team * @param $team1votes * @param $votesCount */ private function showTeamBox($match, $team, $team1votes, $votesCount) { $video = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team->teamid, 1]); $canVote = $this->canVote; $team1per = 50; if ($votesCount != 0) { $team1per = round($team1votes / $votesCount * 100); } $team2 = ($match->team1id == $team->teamid) ? $match->getTeam2() : $match->getTeam1(); $isGray = ($match->isPublished() && $match->getWinner() && $match->getWinner() != $team->teamid); ?> <div class="teambox"> <div class="votecount"><?=$team1votes?> votos (<?=$team1per?>%)</div> <? if ($canVote) { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->hasVoted()) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <button type="submit" class="vote">Votar</button> <input type="hidden" name="teamid" value="<?=$team->teamid?>"> <input type="hidden" name="matchid" value="<?=$match->matchid?>"> </form> <? } else if ($match->hasVoted() == $team->teamid) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <div class="login"> <button type="submit">Quitar voto</button> <a target="_blank" class="twitter-share-button" href="https://twitter.com/intent/tweet?text=<?=urlencode("¡He votado que #".$team->getHashtag()." ganará a #".$team2->getHashtag()." en la @LCE_Pokemon! http://lce.wz.tl")?>"> ¡Twittear!</a> </div> <input type="hidden" name="unteamid" value="<?=$team->teamid?>"> <input type="hidden" name="unmatchid" value="<?=$match->matchid?>"> </form> <? } ?> <? } else { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Usa Twitter para votar!</a> <? } ?> <? } else { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->isPublished() || !$match->getWinner()) { ?> <? if ($match->hasVoted() == $team->teamid) { ?> <span class="login">Has votado por este equipo</span> <? } ?> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } else if (!$match->isPublished()) { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Entra para ver tus votos!</a> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } ?> <a href="/<?=$this->season->getLink()?>/equipos/<?=$team->getLink()?>/"><img class="<?=$isGray?'_grayscale':''?>" src="/<?=$team->getImageLink(200, 150)?>"></a> </div> <? }
private function showFriendlyMatches() { $csrf = $_SESSION['csrf']; $opponents = Model::indexBy($this->season->getTeams(), 'teamid'); $postCsrf = HTMLResponse::fromPOST('friendlycsrf', ''); if ($postCsrf == $csrf && $this->team->isManager()) { $url = HTMLResponse::fromPOST('friendlyurl'); $opponentsId = HTMLResponse::fromPOST('friendlyopponentsid'); $publishDate = HTMLResponse::fromPOST('friendlydate'); $publishTime = HTMLResponse::fromPOST('friendlytime'); if (!strlen($publishDate)) $publishDate = date('Y-m-d'); if (!strlen($publishTime)) $publishTime = date('H').':00'; $possibleOpponents = Model::pluck($this->season->getTeams(), 'teamid'); $regex = '/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/'; $timeRegex = "'^[0-9]{2}:[0-9]{2}$'"; $dateRegex = "'^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}$'"; $removeId = HTMLResponse::fromPOST('removeid'); if ($removeId) { /** @var Video $video */ if ($video = Video::findOne('seasonid = ? and type = ? and videoid = ? and teamid = ?', [$this->season->seasonid, 3, $removeId, $this->team->teamid])) { $video->delete(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } } if (!strlen($opponentsId) || !strlen($publishTime) || !strlen($publishDate) || !strlen($url)) { $this->design->addJavaScript(" $(function() { alert(\"No has rellenado todos los datos\"); }) ", false); } else { if ($opponentsId != $this->team->teamid && in_array($opponentsId, $possibleOpponents)) { if (!preg_match($regex, $url)) { $this->design->addJavaScript(" $(function() { alert(\"El enlace que has puesto no es un enlace de YouTube válido\"); }) ", false); } else { if (!preg_match($timeRegex, $publishTime)) { $this->design->addJavaScript(" $(function() { alert(\"La hora que has puesto tiene un formato inválido (ha de ser 08:06)\"); }) ", false); } else { if (!preg_match($dateRegex, $publishDate)) { $this->design->addJavaScript(" $(function() { alert(\"La fecha que has puesto tiene un formato inválido (ha de ser 2099-12-31)\"); }) ", false); } else { $video = Video::create(); $video->dateline = time(); $video->publishdate = $publishDate; $video->publishtime = $publishTime; $video->link = $url; $video->opponentid = $opponentsId * 1; $video->teamid = $this->team->teamid; $video->type = 3; $video->seasonid = $this->season->seasonid; $video->save(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } } } } } } $videos = Video::find('seasonid = ? and teamid = ? and type = ? order by publishdate asc, publishtime asc', [$this->season->seasonid, $this->team->teamid, 3]); if ($videos || $this->team->isManager()) { ?> <h2>Combates amistosos</h2> <? if ($this->team->isManager()) { ?> <form action="<?=HTMLResponse::getRoute()?>" method="post"> <? } ?> <table> <thead> <tr> <td>Fecha</td> <td>Hora</td> <td>Oponentes</td> <td>Vídeo</td> </tr> </thead> <? foreach($videos as $video) { if (!$this->team->isManager() && ($video->publishdate > date('Y-m-d') || ($video->publishdate == date('Y-m-d') && $video->publishtime > date('H:i')))) { continue; } ?> <tr> <td><?= $video->publishdate ?></td> <td><?= $video->publishtime ?></td> <td> <a href="/<?=$this->season->getLink()?>/equipos/<?=$opponents[$video->opponentid]->getLink()?>/"> <?= htmlentities($opponents[$video->opponentid]->name) ?> </a> </td> <td> <a href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? if ($this->team->isManager()) { ?> <a style="font-size: 10px" href="javascript:void(0)" onclick="removeFriendlyVideo(this, <?=$video->videoid?>)"> (Quitar) </a> <? } ?> </td> </tr> <? } ?> <? if ($this->team->isManager()) { ?> <tr> <td> <input type="date" name="friendlydate" placeholder="<?=date('Y-m-d')?>" style="width:80px"> </td> <td> <input name="friendlytime" placeholder="<?=date('H:i')?>" style="width: 64px"> </td> <td> <select name="friendlyopponentsid"> <option value="">-- Elige oponentes --</option> <? foreach($this->season->getTeams() as $team) { if ($team->teamid == $this->team->teamid) continue; ?> <option value="<?=$team->teamid?>"> <?= htmlentities($team->name) ?> </option> <? } ?> </select> </td> <td> <input name="friendlyurl" placeholder="http://youtube.com/..." style="width:200px"> </td> </tr> <? } ?> </table> <? if ($this->team->isManager()) { ?> <div style="height: 6px"></div> <button type="submit">Añadir amostoso</button> <input type="hidden" name="friendlycsrf" value="<?=$csrf?>"> <input type="hidden" name="removeid" value=""> </form> <? } } }
if (date('H') * 1 == 17 && date('i') * 1 < 15) { // 17:00 - 17:15 // Videos foreach (Season::find('1=1') as $season) { $weeksCount = $season->getWeeksCount(); for ($week = 1; $week <= $weeksCount; $week++) { if ($season->getWeekDate($week) == $date) { $weekName = $season->getWeekName($week); $matches = Match::find('seasonid = ? and week = ?', [$season->seasonid, $week]); foreach ($matches as $match) { /** @var Team $team1 */ $team1 = $match->getTeam1(); /** @var Team $team2 */ $team2 = $match->getTeam2(); $video1 = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team1->teamid, 1]); $video2 = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team2->teamid, 1]); if ($video1 || $video2) { $msg = "{$weekName} {$season->name}: #" . $team1->getHashtag() . " VS #" . $team2->getHashtag(); $msg .= " @{$team1->username} VS @{$team2->username}"; if ($video1) { $msg .= " {$video1->link}"; } if ($video2) { $msg .= " {$video2->link}"; } echo "-> {$msg}\n"; TwitterAuth::botSendTweet($msg); sleep(1); } } }