/** * Load the database object * @param array */ public function __construct($arrAttributes = null) { $GLOBALS['TL_CSS']['avatar_handler'] = 'system/modules/avatar/assets/handler/handler.min.css'; // Include jQuery $this->addJQuery = true; parent::__construct($arrAttributes); // Set the value if ($this->varValue == '') { $this->varValue = \Avatar::find($this->getId(), $this->getUploadPath()); } }
/** * Load the database object * @param array */ public function __construct($arrAttributes = null) { // Execute the AJAX actions in front end if (\Environment::get('isAjaxRequest') && \Input::get('no_ajax') != 1) { $objHandler = new \Avatar(); $objHandler->executeAjaxActions($this->arrConfiguration); return; } $GLOBALS['TL_CSS']['avatar_fineuploader'] = 'system/modules/avatar/assets/fineuploader/fineuploader-5.0.2.min.css'; parent::__construct($arrAttributes); // Set the value if ($this->varValue == '') { $this->varValue = \Avatar::find($this->getId(), $this->getUploadPath()); } }
function updateAvatars($user) { $touched = false; if (!have_option('q', 'quiet')) { print "Updating avatars for user '" . $user->nickname . "' (" . $user->id . ")..."; } $avatar = new Avatar(); $avatar->profile_id = $user->id; if (!$avatar->find()) { if (have_option('v', 'verbose')) { print "(none found)..."; } } else { while ($avatar->fetch()) { if (have_option('v', 'verbose')) { if ($avatar->original) { print "original..."; } else { print $avatar->width . "..."; } } $orig_url = $avatar->url; $avatar->url = Avatar::url($avatar->filename); if ($avatar->url != $orig_url) { $sql = "UPDATE avatar SET url = '" . $avatar->url . "' " . "WHERE profile_id = " . $avatar->profile_id . " " . "AND width = " . $avatar->width . " " . "AND height = " . $avatar->height . " "; if ($avatar->original) { $sql .= "AND original = 1 "; } if (!$avatar->query($sql)) { throw new Exception("Can't update avatar for user " . $user->nickname . "."); } else { $touched = true; } } } } if ($touched) { $profile = $user->getProfile(); common_broadcast_profile($profile); } if (have_option('v', 'verbose')) { print "DONE."; } if (!have_option('q', 'quiet') || have_option('v', 'verbose')) { print "\n"; } }
private static function afterLogin() { $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $json = $connection->get('users/show', ['user_id' => $_SESSION['twitter-userid']]); $_SESSION['twitter-avatar'] = isset($json->profile_image_url) ? $json->profile_image_url : ''; Avatar::setUsersAvatar($_SESSION['twitter-userid'], $_SESSION['twitter-username'], $_SESSION['twitter-avatar']); $oldAvatars = Avatar::find('1=1 order by dateline asc limit 100'); if ($oldAvatars) { $oldAvatarsIds = Model::pluck($oldAvatars, 'userid'); $json = $connection->get('users/lookup', ['user_id' => implode(',', $oldAvatarsIds)]); foreach ($json as $userdata) { $newavatars[$userdata->id_str] = $userdata->profile_image_url; } foreach ($oldAvatars as $avatar) { $avatar->url = $newavatars[$avatar->userid]; $avatar->dateline = time(); } Model::saveAll($oldAvatars); } }
function updateAvatarUrls($profile) { $avatar = new Avatar(); $avatar->profile_id = $profile->id; if ($avatar->find()) { while ($avatar->fetch()) { $orig_url = $avatar->url; $avatar->url = Avatar::url($avatar->filename); if ($avatar->url != $orig_url) { $sql = "UPDATE avatar SET url = '" . $avatar->url . "' " . "WHERE profile_id = " . $avatar->profile_id . " " . "AND width = " . $avatar->width . " " . "AND height = " . $avatar->height . " "; if ($avatar->original) { $sql .= "AND original = 1 "; } if (!$avatar->query($sql)) { throw new Exception("Can't update avatar for user " . $profile->nickname . "."); } else { $touched = true; } } } } }
function hasGravatar($id) { $avatar = new Avatar(); $avatar->profile_id = $id; if ($avatar->find()) { while ($avatar->fetch()) { if ($avatar->filename == null) { return true; } } } return false; }
/** * Delete attached avatars for this user from the database and filesystem. * This should be used instead of a batch delete() to ensure that files * get removed correctly. * * @param boolean $original true to delete only the original-size file * @return <type> */ function delete_avatars($original = true) { $avatar = new Avatar(); $avatar->profile_id = $this->id; $avatar->find(); while ($avatar->fetch()) { if ($avatar->original) { if ($original == false) { continue; } } $avatar->delete(); } return true; }
public function testCreateAssocObjectExistingObject() { $this->fixtures('users', 'avatars'); $user = User::find($this->users('derek')->id); $avatar = $user->createAvatar(array('filepath' => 'test.gif')); $this->assertEquals($avatar, $user->avatar); // this hasn't saved the associated object yet $newAvatar = Avatar::find('first', array('conditions' => 'filepath=:nm'), array(':nm' => 'test.gif')); $this->assertTrue($newAvatar instanceof Avatar); $this->assertEquals($newAvatar->user_id, $user->id); // save, and make sure the association object is created $user->save(); // make sure both were created, and are associated $user = User::find($this->users('derek')->id); $avatar = Avatar::find('first', array('conditions' => 'filepath=:nm'), array(':nm' => 'test.gif')); $this->assertTrue($user instanceof User); $this->assertTrue($avatar instanceof Avatar); $this->assertEquals($user->id, $avatar->user_id); }
/** * Return the value * @param mixed * @return mixed */ protected function validator($varInput) { // Check the mandatoriness if ($varInput == '' && $this->mandatory) { $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['mandatory'], $this->strLabel)); return ''; } $varReturn = $varInput; // Delete the file if ($varInput == '' && $this->varValue != '') { \Files::getInstance()->delete($this->varValue); } // Move file to the destination folder if (is_file(TL_ROOT . '/' . $varInput) && $this->isTemporaryFile($varInput)) { $strAvatar = \Avatar::find($this->getId(), $this->getUploadPath()); // Delete the current avatar if ($strAvatar != '') { \Files::getInstance()->delete($strAvatar); } $strNew = $this->getUploadPath() . '/' . $this->getId() . '-' . md5(uniqid('', true)) . '.' . pathinfo($varInput, PATHINFO_EXTENSION); if (\Files::getInstance()->rename($varInput, $strNew)) { $varReturn = $strNew; } } return $varReturn; }
/** * @return void */ public function show() { $matches = Match::find('seasonid = ? and result != 0', [$this->season->seasonid]); $matches = Model::indexBy($matches, 'matchid'); $teams = Model::indexBy(Team::find('1=1'), 'teamid'); $matchWinner = []; foreach($matches as $match) { if ($this->season->weekIsPublished($match->week) && !$match->isDelayed()) { $matchWinner[$match->matchid] = $match->getWinner(); } } $totalBets = []; $correctBets = []; $usernames = []; $avatars = Model::pluck(Avatar::find('1=1'), 'url', 'userid'); foreach(Bet::find('1=1') as $bet) { if (isset($matchWinner[$bet->matchid])) { if ($bet->teamid && $matchWinner[$bet->matchid] == $bet->teamid) { $correctBets[$bet->userid]++; } $totalBets[$bet->userid]++; } if ($bet->username) { $usernames[$bet->userid] = $bet->username; } } $tiebreakers = []; foreach(array_keys($correctBets) as $userid) { $tiebreakers[$userid] = [-$correctBets[$userid], $totalBets[$userid], strtolower($usernames[$userid])]; } asort($tiebreakers); if (TwitterAuth::isLogged()) { $userid = TwitterAuth::getUserId(); $userBets = Bet::find('userid = ? order by matchid desc', [$userid]); $userpos = array_search($userid, array_keys($tiebreakers)); $userpos = ($userpos === FALSE) ? 0 : $userpos+1; ?> <div class="inblock" style="text-align: left; margin-right: 20px"> <h2>Tus estadísticas</h2> <table> <thead> <tr> <td>Puesto</td> <td>Nombre</td> <td>Aciertos</td> <td>Fallos</td> </tr> </thead> <tr> <td><?= $userpos ?>º</td> <td style="text-align: left"> <div class="inblock" style="vertical-align: middle"> <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank"> <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px"> </a> </div> <div class="inblock" style="vertical-align: middle"> <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank"> <?= htmlentities($usernames[$userid]) ?> <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?> </a> </div> </td> <td><?= $correctBets[$userid] ?></td> <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td> </tr> </table> <h2>Tus apuestas</h2> <table> <thead> <tr> <td>Jornada</td> <td>Enfrentamiento</td> <td>Acierto</td> </tr> </thead> <? foreach($userBets as $bet) { if (!isset($matches[$bet->matchid])) continue; /** * @var $match Match */ $match = $matches[$bet->matchid]; if (!$match->isPublished() || $match->isDelayed()) continue; $team1 = $teams[$match->team1id]; $team2 = $teams[$match->team2id]; $success = $match->getWinner() == $bet->teamid; ?> <tr> <td><?= $match->week ?></td> <td> <div class="inblock"> <div class="teamimg64"> <img src="/<?= $team1->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team1->teamid ? '' : 'grayscale' ?>"> </div> <? if ($bet->teamid == $team1->teamid) { ?> <br><i style="font-size:11px">Votado</i> <? } ?> </div> <div class="inblock" style="line-height: 64px; margin: 0px 4px"> VS </div> <div class="inblock"> <div class="teamimg64"> <img src="/<?= $team2->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team2->teamid ? '' : 'grayscale' ?>"> </div> <? if ($bet->teamid == $team2->teamid) { ?> <br><i style="font-size:11px">Votado</i> <? } ?> </div> </td> <td> <?= $success ? '<div class="success-icon">✔</div>' : '<div class="fail-icon">✘</div>' ?> </td> </tr> <? } ?> </table> </div> <? } ?> <div class="inblock"> <h2>Clasificación</h2> <table> <thead> <tr> <td>Puesto</td> <td>Nombre</td> <td>Aciertos</td> <td>Fallos</td> </tr> </thead> <? $lastTiebreakers = null; $lastPos = 0; foreach(array_keys($tiebreakers) as $pos => $userid) { unset($tiebreakers[$userid][2]); if ($lastTiebreakers != $tiebreakers[$userid]) { $lastPos = $pos; } if (!isset($avatars[$userid])) { Avatar::setUsersAvatar($userid, $usernames[$userid]); } ?> <tr> <td><?= $lastPos+1 ?>º</td> <td style="text-align: left"> <div class="inblock" style="vertical-align: middle"> <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank"> <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px"> </a> </div> <div class="inblock" style="vertical-align: middle"> <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank"> <?= htmlentities($usernames[$userid]) ?> <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?> </a> </div> </td> <td><?= $correctBets[$userid] ?></td> <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td> </tr> <? $lastTiebreakers = $tiebreakers[$userid]; } ?> </table> </div> <? }
public static function getProfileAvatars(Profile $target) { $avatar = new Avatar(); $avatar->profile_id = $target->id; if (!$avatar->find()) { throw new NoAvatarException($target, $avatar); } return $avatar->fetchAll(); }