Esempio n. 1
0
    Response::success("You've already signed out");
}
CSRFProtection::protect();
if (isset($_REQUEST['unlink'])) {
    try {
        DeviantArt::request('https://www.deviantart.com/oauth2/revoke', null, array('token' => $currentUser->Session['access']));
    } catch (CURLRequestException $e) {
        Response::fail("Coulnd not revoke the site's access: {$e->getMessage()} (HTTP {$e->getCode()})");
    }
}
if (isset($_REQUEST['unlink']) || isset($_REQUEST['everywhere'])) {
    $col = 'user';
    $val = $currentUser->id;
    $username = Users::validateName('username', null, true);
    if (isset($username)) {
        if (!Permission::sufficient('staff') || isset($_REQUEST['unlink'])) {
            Response::fail();
        }
        /** @var $TargetUser User */
        $TargetUser = $Database->where('name', $username)->getOne('users', 'id,name');
        if (empty($TargetUser)) {
            Response::fail("Target user doesn't exist");
        }
        if ($TargetUser->id !== $currentUser->id) {
            $val = $TargetUser->id;
        } else {
            unset($TargetUser);
        }
    }
} else {
    $col = 'id';
Esempio n. 2
0
<?php

use App\CoreUtils;
use App\CSRFProtection;
use App\GlobalSettings;
use App\Permission;
use App\RegExp;
use App\Response;
/** @var $data string */
if (!Permission::sufficient('staff') || !POST_REQUEST) {
    CoreUtils::notFound();
}
CSRFProtection::protect();
if (!preg_match(new RegExp('^([gs]et)/([a-z_]+)$'), CoreUtils::trim($data), $_match)) {
    Response::fail('Setting key invalid');
}
$getting = $_match[1] === 'get';
$key = $_match[2];
$currvalue = GlobalSettings::get($key);
if ($getting) {
    Response::done(array('value' => $currvalue));
}
if (!isset($_POST['value'])) {
    Response::fail('Missing setting value');
}
try {
    $newvalue = GlobalSettings::process($key);
} catch (Exception $e) {
    Response::fail('Preference value error: ' . $e->getMessage());
}
if ($newvalue === $currvalue) {
Esempio n. 3
0
echo !empty($_GET['q']) ? " value='" . CoreUtils::aposEncode($_GET['q']) . "'" : '';
?>
 title='Search'>
		<button type='submit'  class='blue'>Search</button>
		<button type='button' class='green typcn typcn-flash sanic-button' title="I'm feeling lucky"></button>
		<button type='reset' class='red typcn typcn-times' title='Clear'<?php 
echo empty($_GET['q']) ? ' disabled' : '';
?>
></button>
	</form>
<?  }
	else echo CoreUtils::notice('warn','<span class="typcn typcn-warning"></span> <strong>ElasticSearch server is down!</strong> Please <a class="send-feedback">let us know</a>, and in the meantime, use the <a class="btn darkblue typcn typcn-th-menu" href="/cg'.($EQG?'/eqg':'').'/full">Full List</a> to find appearances faster. Sorry for the inconvenience.',true); ?>
	<?php 
echo $Pagination->HTML . Appearances::getHTML($Ponies) . $Pagination->HTML;
?>
</div>

<?  $export = array(
		'Color' => $Color,
		'color' => $color,
		'EQG' => $EQG,
		'AppearancePage' => false,
	);
	if (Permission::sufficient('staff'))
		$export = array_merge($export, array(
			'TAG_TYPES_ASSOC' => Tags::$TAG_TYPES_ASSOC,
			'MAX_SIZE' => CoreUtils::getMaxUploadSize(),
			'HEX_COLOR_PATTERN' => $HEX_COLOR_REGEX,
		));
	echo CoreUtils::exportVars($export); ?>
Esempio n. 4
0
 /**
  * Caches information about a deviation in the 'deviation_cache' table
  * Returns null on failure
  *
  * @param string      $ID
  * @param null|string $type
  * @param bool        $mass
  *
  * @return array|null
  */
 static function getCachedSubmission($ID, $type = 'fav.me', $mass = false)
 {
     global $Database, $FULLSIZE_MATCH_REGEX;
     if ($type === 'sta.sh') {
         $ID = CoreUtils::nomralizeStashID($ID);
     }
     $Deviation = $Database->where('id', $ID)->where('provider', $type)->getOne('deviation_cache');
     $cacheExhausted = self::$_MASS_CACHE_USED > self::$_MASS_CACHE_LIMIT;
     $cacheExpired = empty($Deviation['updated_on']) ? true : strtotime($Deviation['updated_on']) + Time::$IN_SECONDS['hour'] * 12 < time();
     $lastRequestSuccessful = !self::$_CACHE_BAILOUT;
     $localDataMissing = empty($Deviation);
     $massCachingWithinLimit = $mass && !$cacheExhausted;
     $notMassCachingAndCacheExpired = !$mass && $cacheExpired;
     if ($lastRequestSuccessful && ($localDataMissing || ($massCachingWithinLimit && $cacheExpired || $notMassCachingAndCacheExpired))) {
         try {
             $json = self::oEmbed($ID, $type);
             if (empty($json)) {
                 throw new \Exception();
             }
         } catch (\Exception $e) {
             if (!empty($Deviation)) {
                 $Database->where('id', $Deviation['id'])->update('deviation_cache', array('updated_on' => date('c', time() + Time::$IN_SECONDS['minute'])));
             }
             $ErrorMSG = "Saving local data for {$ID}@{$type} failed: " . $e->getMessage();
             if (!Permission::sufficient('developer')) {
                 trigger_error($ErrorMSG);
             }
             if (POST_REQUEST) {
                 Response::fail($ErrorMSG);
             } else {
                 echo "<div class='notice fail'><label>da_cache_deviation({$ID}, {$type})</label><p>{$ErrorMSG}</p></div>";
             }
             self::$_CACHE_BAILOUT = true;
             return $Deviation;
         }
         $insert = array('title' => preg_replace(new RegExp('\\\\\''), "'", $json['title']), 'preview' => URL::makeHttps($json['thumbnail_url']), 'fullsize' => URL::makeHttps(isset($json['fullsize_url']) ? $json['fullsize_url'] : $json['url']), 'provider' => $type, 'author' => $json['author_name'], 'updated_on' => date('c'));
         if (!preg_match($FULLSIZE_MATCH_REGEX, $insert['fullsize'])) {
             $fullsize_attempt = CoreUtils::getFullsizeURL($ID, $type);
             if (is_string($fullsize_attempt)) {
                 $insert['fullsize'] = $fullsize_attempt;
             }
         }
         if (empty($Deviation)) {
             $Deviation = $Database->where('id', $ID)->where('provider', $type)->getOne('deviation_cache');
         }
         if (empty($Deviation)) {
             $insert['id'] = $ID;
             $Database->insert('deviation_cache', $insert);
         } else {
             $Database->where('id', $Deviation['id'])->update('deviation_cache', $insert);
             $insert['id'] = $ID;
         }
         self::$_MASS_CACHE_USED++;
         $Deviation = $insert;
     } else {
         if (!empty($Deviation['updated_on'])) {
             $Deviation['updated_on'] = date('c', strtotime($Deviation['updated_on']));
             if (self::$_CACHE_BAILOUT) {
                 $Database->where('id', $Deviation['id'])->update('deviation_cache', array('updated_on' => $Deviation['updated_on']));
             }
         }
     }
     return $Deviation;
 }
Esempio n. 5
0
 }
 $url = (new Input('url', 'url', array(Input::IN_RANGE => [3, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Link URL is missing', Input::ERROR_RANGE => 'Link URL must be between @min and @max characters long'))))->out();
 if ($creating || $Link['url'] !== $url) {
     $data['url'] = $url;
 }
 $title = (new Input('title', 'string', array(Input::IS_OPTIONAL => true, Input::IN_RANGE => [3, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_RANGE => 'Link title must be between @min and @max characters long'))))->out();
 if (!isset($title)) {
     $data['title'] = '';
 } else {
     if ($creating || $Link['title'] !== $title) {
         CoreUtils::checkStringValidity($title, 'Link title', INVERSE_PRINTABLE_ASCII_PATTERN);
         $data['title'] = $title;
     }
 }
 $minrole = (new Input('minrole', function ($value) {
     if (empty(Permission::ROLES_ASSOC[$value]) || !Permission::sufficient('user', $value)) {
         Response::fail();
     }
 }, array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Minumum role is missing', Input::ERROR_INVALID => 'Minumum role (@value) is invalid'))))->out();
 if ($creating || $Link['minrole'] !== $minrole) {
     $data['minrole'] = $minrole;
 }
 if (empty($data)) {
     Response::fail('Nothing was changed');
 }
 $query = $creating ? $Database->insert('usefullinks', $data) : $Database->where('id', $Link['id'])->update('usefullinks', $data);
 if (!$query) {
     Response::dbError();
 }
 Response::done();
 break;
Esempio n. 6
0
 /**
  * Returns the HTML code of the navigation in the header
  *
  * @param bool $disabled
  *
  * @return string
  */
 static function getNavigationHTML($disabled = false)
 {
     if (!empty($GLOBALS['NavHTML'])) {
         return $GLOBALS['NavHTML'];
     }
     global $do;
     // Navigation items
     if (!$disabled) {
         $NavItems = array('latest' => array('/', 'Latest episode'), 'eps' => array('/episodes', 'Episodes'));
         if ($do === 'episodes') {
             global $Episodes, $Pagination;
             if (isset($Episodes)) {
                 $NavItems['eps'][1] .= " - Page {$Pagination->page}";
             }
         }
         global $CurrentEpisode;
         if (($do === 'episode' || $do === 's' || $do === 'movie') && !empty($CurrentEpisode)) {
             if ($CurrentEpisode->isMovie) {
                 $NavItems['eps'][1] = 'Movies';
             }
             if ($CurrentEpisode->isLatest()) {
                 $NavItems['latest'][0] = $_SERVER['REQUEST_URI'];
             } else {
                 $NavItems['eps']['subitem'] = CoreUtils::cutoff($GLOBALS['heading'], Episodes::TITLE_CUTOFF);
             }
         }
         global $Color, $EQG;
         $NavItems['colorguide'] = array("/cg" . (!empty($EQG) ? '/eqg' : ''), (!empty($EQG) ? 'EQG ' : '') . "{$Color} Guide");
         if ($do === 'colorguide') {
             global $Tags, $Changes, $Ponies, $Pagination, $Appearance, $Map;
             if (!empty($Appearance)) {
                 $NavItems['colorguide']['subitem'] = (isset($Map) ? "Sprite {$Color}s - " : '') . CoreUtils::escapeHTML($Appearance['label']);
             } else {
                 if (isset($Ponies)) {
                     $NavItems['colorguide'][1] .= " - Page {$Pagination->page}";
                 } else {
                     if ($GLOBALS['data'] === 'full') {
                         $NavItems['colorguide']['subitem'] = 'Full List';
                     } else {
                         if (isset($Tags)) {
                             $pagePrefix = 'Tags';
                         } else {
                             if (isset($Changes)) {
                                 $pagePrefix = "Major {$Color} Changes";
                             }
                         }
                         $NavItems['colorguide']['subitem'] = (isset($pagePrefix) ? "{$pagePrefix} - " : '') . "Page {$Pagination->page}";
                     }
                 }
             }
         }
         if ($GLOBALS['signedIn']) {
             $NavItems['u'] = array("/@{$GLOBALS['currentUser']->name}", 'Account');
         }
         if ($do === 'user' || Permission::sufficient('staff')) {
             global $User, $sameUser;
             $NavItems['users'] = array('/users', 'Users', Permission::sufficient('staff'));
             if (!empty($User) && empty($sameUser)) {
                 $NavItems['users']['subitem'] = $User->name;
             }
         }
         if (Permission::sufficient('staff')) {
             $NavItems['admin'] = array('/admin', 'Admin');
             global $task;
             if ($task === 'logs') {
                 global $Pagination;
                 $NavItems['admin']['subitem'] = "Logs - Page {$Pagination->page}";
             }
         }
         $NavItems[] = array('/about', 'About');
     } else {
         $NavItems = array(array(true, 'HTTP 503', false, 'subitem' => 'Service Temporarily Unavailable'));
     }
     $GLOBALS['NavHTML'] = '';
     foreach ($NavItems as $item) {
         $sublink = '';
         if (isset($item['subitem'])) {
             list($class, $sublink) = self::_processHeaderLink(array(true, $item['subitem']));
             $sublink = " &rsaquo; {$sublink}";
             $link = self::_processHeaderLink($item, HTML_ONLY);
         } else {
             if (isset($item[2]) && !$item[2]) {
                 continue;
             } else {
                 list($class, $link) = self::_processHeaderLink($item);
             }
         }
         $GLOBALS['NavHTML'] .= "<li{$class}>{$link}{$sublink}</li>";
     }
     $GLOBALS['NavHTML'] .= '<li><a href="http://mlp-vectorclub.deviantart.com/" target="_blank">MLP-VectorClub</a></li>';
     return $GLOBALS['NavHTML'];
 }
Esempio n. 7
0
<?php

use App\CoreUtils;
use App\CSRFProtection;
use App\Permission;
use App\RegExp;
use App\Response;
use App\UserPrefs;
/** @var $data string */
if (!Permission::sufficient('user') || !POST_REQUEST) {
    CoreUtils::notFound();
}
CSRFProtection::protect();
if (!preg_match(new RegExp('^([gs]et)/([a-z_]+)$'), CoreUtils::trim($data), $_match)) {
    Response::fail('Preference key invalid');
}
$getting = $_match[1] === 'get';
$key = $_match[2];
// TODO Support changing some preferences of other users by staff
$currvalue = UserPrefs::get($key);
if ($getting) {
    Response::done(array('value' => $currvalue));
}
try {
    $newvalue = UserPrefs::process($key);
} catch (Exception $e) {
    Response::fail('Preference value error: ' . $e->getMessage());
}
if ($newvalue === $currvalue) {
    Response::done(array('value' => $newvalue));
}
Esempio n. 8
0
        $SubMSG = "Check the name for typos and try again";
    }
    if (!isset($MSG)) {
        $MSG = 'Local user data missing';
        if (!$signedIn) {
            $exists = 'exists on DeviantArt';
            if (isset($un)) {
                $exists = "<a href='http://{$un}.deviantart.com/'>{$exists}</a>";
            }
            $SubMSG = "If this user {$exists}, sign in to import their details.";
        }
    }
    $canEdit = $sameUser = false;
} else {
    $sameUser = $signedIn && $User->id === $currentUser->id;
    $canEdit = !$sameUser && Permission::sufficient('staff') && Permission::sufficient($User->role);
    $pagePath = "/@{$User->name}";
    CoreUtils::fixPath($pagePath);
}
if (isset($MSG)) {
    HTTP::statusCode(404);
} else {
    if ($sameUser) {
        $CurrentSession = $currentUser->Session;
        $Database->where('id != ?', array($CurrentSession['id']));
    }
    $Sessions = $Database->where('user', $User->id)->orderBy('lastvisit', 'DESC')->get('sessions', null, 'id,created,lastvisit,platform,browser_name,browser_ver,user_agent,scope');
}
$settings = array('title' => !isset($MSG) ? ($sameUser ? 'Your' : CoreUtils::posess($User->name)) . ' ' . ($sameUser || $canEdit ? 'account' : 'profile') : 'Account', 'no-robots', 'do-css', 'js' => array('user'));
if ($canEdit) {
    $settings['js'][] = 'user-manage';
Esempio n. 9
0
?>
 items/page</p>
	<p class='align-center links'>
		<a class='btn darkblue typcn typcn-arrow-back' href="/cg">Back to <?php 
echo $Color;
?>
 Guide</a>
		<a class='btn darkblue typcn typcn-warning' href="/cg/changes">Major Changes</a>
	</p>
	<?php 
echo $Pagination->HTML;
?>
	<table id="tags">
		<thead><?php 
$cspan = Permission::sufficient('staff') ? '" colspan="2' : '';
$refresher = Permission::sufficient('staff') ? " <button class='typcn typcn-arrow-sync refresh-all' title='Refresh usage data on this page'></button>" : '';
echo $thead = <<<HTML
\t\t\t<tr>
\t\t\t\t<th class="tid">ID</th>
\t\t\t\t<th class="name{$cspan}">Name</th>
\t\t\t\t<th class="title">Description</th>
\t\t\t\t<th class="type">Type</th>
\t\t\t\t<th class="uses">Uses{$refresher}</th>
\t\t\t</tr>
HTML;
?>
</thead>
		<?php 
echo Tags::getTagListHTML($Tags);
?>
		<tfoot><?php 
Esempio n. 10
0
 /**
  * Generate HTML for post action buttons
  *
  * @param Post         $Post
  * @param bool         $isRequest
  * @param false|string $view_only Only show the "View" button
  *                                Contains HREF attribute of button if string
  *
  * @return string
  */
 private static function _getPostActions(Post $Post, bool $isRequest, $view_only) : string
 {
     global $signedIn, $currentUser;
     $By = $Post->Reserver;
     $requestedByUser = $isRequest && $signedIn && $Post->requested_by === $currentUser->id;
     $isNotReserved = empty($By);
     $sameUser = $signedIn && $Post->reserved_by === $currentUser->id;
     $CanEdit = empty($Post->lock) && Permission::sufficient('staff') || Permission::sufficient('developer') || $requestedByUser && $isNotReserved;
     $Buttons = array();
     $HTML = self::getPostReserveButton($Post, $By, $view_only);
     if (!empty($Post->reserved_by)) {
         $finished = !empty($Post->deviation_id);
         $staffOrSameUser = $sameUser && Permission::sufficient('member') || Permission::sufficient('staff');
         if (!$finished) {
             if (!$sameUser && Permission::sufficient('member') && $Post->isTransferable() && !$Post->isOverdue()) {
                 $Buttons[] = array('user-add darkblue pls-transfer', 'Take on');
             }
             if ($staffOrSameUser) {
                 $Buttons[] = array('user-delete red cancel', 'Cancel Reservation');
                 $Buttons[] = array('attachment green finish', ($sameUser ? "I'm" : 'Mark as') . ' finished');
             }
         }
         if ($finished && empty($Post->lock)) {
             if (Permission::sufficient('staff')) {
                 $Buttons[] = array((empty($Post->preview) ? 'trash delete-only red' : 'media-eject orange') . ' unfinish', empty($Post->preview) ? 'Delete' : 'Unfinish');
             }
             if ($staffOrSameUser) {
                 $Buttons[] = array('tick green check', 'Check');
             }
         }
     }
     if (empty($Post->lock) && empty($Buttons) && (Permission::sufficient('staff') || $requestedByUser && $isNotReserved)) {
         $Buttons[] = array('trash red delete', 'Delete');
     }
     if ($CanEdit) {
         array_splice($Buttons, 0, 0, array(array('pencil darkblue edit', 'Edit')));
     }
     if ($Post->lock && Permission::sufficient('staff')) {
         $Buttons[] = array('lock-open orange unlock', 'Unlock');
     }
     $HTML .= "<div class='actions'>";
     if (!$view_only) {
         $Buttons[] = array('export blue share', 'Share');
     }
     if (!empty($Buttons)) {
         if ($view_only) {
             $HTML .= "<div><a href='{$view_only}' class='btn blue typcn typcn-arrow-forward'>View</a></div>";
         } else {
             $regularButton = count($Buttons) < 3;
             foreach ($Buttons as $b) {
                 $WriteOut = "'" . ($regularButton ? ">{$b[1]}" : " title='" . CoreUtils::aposEncode($b[1]) . "'>");
                 $HTML .= "<button class='typcn typcn-{$b[0]}{$WriteOut}</button>";
             }
         }
     }
     $HTML .= '</div>';
     return $HTML;
 }
Esempio n. 11
0
?>
</tbody>
	</table>
<?  }
	echo $Pagination;
	$Movies = $Database->where('season', 0)->orderBy('episode','DESC')->get('episodes'); ?>
	<h1>Movies</h1>
<?  if (empty($Episodes)){ ?>
	<p>There are no movies stored in the database</p>
<?  }
	if (Permission::sufficient('staff')) { ?>
	<div class="actions">
		<button id="add-movie" class="green typcn typcn-plus">Add Movie</button>
	</div>
<?  }
	if (!empty($Episodes) || (empty($Episodes) && Permission::sufficient('staff'))){ ?>
	<table id="movies">
		<thead>
			<tr>
				<th><span class="mobile-hide">Overall </span>#</th>
				<th>Title &amp; Air Date</th>
			</tr>
		</thead>
		<tbody><?php 
echo Episodes::getTableTbody($Movies, true);
?>
</tbody>
	</table>
<?  } ?>
</div>
Esempio n. 12
0
 /**
  * Returns the markup for the time of last update displayed under an appaerance
  *
  * @param int  $PonyID
  * @param bool $wrap
  *
  * @return string
  */
 static function getUpdatesHTML($PonyID, $wrap = WRAP)
 {
     global $Database;
     $update = Updates::get($PonyID, MOST_RECENT);
     if (!empty($update)) {
         $update = "Last updated " . Time::tag($update['timestamp']);
     } else {
         if (!Permission::sufficient('staff')) {
             return '';
         }
         $update = '';
     }
     return $wrap ? "<div class='update'>{$update}</div>" : $update;
 }
Esempio n. 13
0
    if (isset($_GET['error_description'])) {
        $errdesc = $_GET['error_description'];
    }
    global $signedIn;
    if ($signedIn) {
        HTTP::redirect($_GET['state']);
    }
    Episodes::loadPage();
}
$currentUser = DeviantArt::getToken($_GET['code']);
$signedIn = !empty($currentUser);
if (isset($_GET['error'])) {
    $err = $_GET['error'];
    if (isset($_GET['error_description'])) {
        $errdesc = $_GET['error_description'];
    }
    if ($err === 'user_banned') {
        $errdesc .= "\n\nIf you'd like to appeal your ban, please <a href='http://mlp-vectorclub.deviantart.com/notes/'>send the group a note</a>.";
    }
    Episodes::loadPage();
}
if (preg_match(new RegExp('^[a-z\\d]+$', 'i'), $_GET['state'], $_match)) {
    $confirm = str_replace('{{CODE}}', $_match[0], file_get_contents(INCPATH . 'views/loginConfrim.html'));
    $confirm = str_replace('{{USERID}}', Permission::sufficient('developer') || UserPrefs::get('p_disable_ga') ? '' : $currentUser->id, $confirm);
    die($confirm);
} else {
    if (preg_match($REWRITE_REGEX, $_GET['state'])) {
        HTTP::redirect($_GET['state']);
    }
}
HTTP::redirect('/');
Esempio n. 14
0
<?php

use App\CoreUtils;
use App\Permission;
use App\RegExp;
/** @var $data string */
$AgentString = null;
if (is_numeric($data) && Permission::sufficient('developer')) {
    $SessionID = intval($data, 10);
    $Session = $Database->where('id', $SessionID)->getOne('sessions');
    if (!empty($Session)) {
        $AgentString = $Session['user_agent'];
    }
}
$browser = CoreUtils::detectBrowser($AgentString);
if (empty($browser['platform'])) {
    error_log('Could not find platform based on the following UA string: ' . preg_replace(new RegExp(INVERSE_PRINTABLE_ASCII_PATTERN), '', $AgentString));
}
CoreUtils::fixPath('/browser' . (!empty($Session) ? "/{$Session['id']}" : ''));
CoreUtils::loadPage(array('title' => 'Browser recognition test page', 'do-css', 'no-robots'));
Esempio n. 15
0
}
$insert = array('preview' => $Image->preview, 'fullsize' => $Image->fullsize);
$season = Episodes::validateSeason(Episodes::ALLOW_MOVIES);
$episode = Episodes::validateEpisode();
$epdata = Episodes::getActual($season, $episode, Episodes::ALLOW_MOVIES);
if (empty($epdata)) {
    Response::fail("The specified episode (S{$season}E{$episode}) does not exist");
}
$insert['season'] = $epdata->season;
$insert['episode'] = $epdata->episode;
$ByID = $currentUser->id;
if (Permission::sufficient('developer')) {
    $username = Posts::validatePostAs();
    if (isset($username)) {
        $PostAs = Users::get($username, 'name', 'id,role');
        if (empty($PostAs)) {
            Response::fail('The user you wanted to post as does not exist');
        }
        if ($type === 'reservation' && !Permission::sufficient('member', $PostAs->role) && !isset($_POST['allow_nonmember'])) {
            Response::fail('The user you wanted to post as is not a club member, do you want to post as them anyway?', array('canforce' => true));
        }
        $ByID = $PostAs->id;
    }
}
$insert[$type === 'reservation' ? 'reserved_by' : 'requested_by'] = $ByID;
Posts::checkPostDetails($type, $insert);
$PostID = $Database->insert("{$type}s", $insert, 'id');
if (!$PostID) {
    Response::dbError();
}
Response::done(array('id' => $PostID));
Esempio n. 16
0
    static function getPendingReservationsHTML($UserID, $sameUser, &$YouHave = null)
    {
        global $Database, $currentUser;
        $YouHave = $sameUser ? 'You have' : 'This user has';
        $PrivateSection = $sameUser ? Users::PROFILE_SECTION_PRIVACY_LEVEL['staff'] : '';
        $cols = "id, season, episode, preview, label, posted, reserved_by";
        $PendingReservations = $Database->where('reserved_by', $UserID)->where('deviation_id IS NULL')->get('reservations', null, $cols);
        $PendingRequestReservations = $Database->where('reserved_by', $UserID)->where('deviation_id IS NULL')->get('requests', null, "{$cols}, reserved_at, true as requested_by");
        $TotalPending = count($PendingReservations) + count($PendingRequestReservations);
        $hasPending = $TotalPending > 0;
        $HTML = '';
        if (Permission::sufficient('staff') || $sameUser) {
            $pendingCountReadable = $hasPending > 0 ? "<strong>{$TotalPending}</strong>" : 'no';
            $posts = CoreUtils::makePlural('reservation', $TotalPending);
            $gamble = $TotalPending < 4 && $sameUser ? ' <button id="suggestion" class="btn orange typcn typcn-lightbulb">Suggestion</button>' : '';
            $HTML .= <<<HTML
<section class='pending-reservations'>
<h2>{$PrivateSection}Pending reservations{$gamble}</h2>
\t\t\t\t<span>{$YouHave} {$pendingCountReadable} pending {$posts}
HTML;
            if ($hasPending) {
                $HTML .= " which ha" . ($TotalPending !== 1 ? 've' : 's') . "n't been marked as finished yet";
            }
            $HTML .= ".";
            if ($sameUser) {
                $HTML .= " Please keep in mind that the global limit is 4 at any given time. If you reach the limit, you can't reserve any more images until you finish or cancel some of your pending reservations.";
            }
            $HTML .= "</span>";
            if ($hasPending) {
                /** @var $Posts Post[] */
                $Posts = array_merge(Posts::getReservationsSection($PendingReservations, RETURN_ARRANGED)['unfinished'], array_filter(array_values(Posts::getRequestsSection($PendingRequestReservations, RETURN_ARRANGED)['unfinished'])));
                usort($Posts, function (Post $a, Post $b) {
                    $a = strtotime($a->posted);
                    $b = strtotime($b->posted);
                    return -($a < $b ? -1 : ($a === $b ? 0 : 1));
                });
                $LIST = '';
                foreach ($Posts as $Post) {
                    unset($_);
                    $postLink = $Post->toLink($_);
                    $postAnchor = $Post->toAnchor(null, $_);
                    $label = !empty($Post->label) ? "<span class='label'>{$Post->label}</span>" : '';
                    $is_request = isset($Post->rq);
                    $reservation_time_known = !empty($Post->reserved_at);
                    $posted = Time::tag($is_request && $reservation_time_known ? $Post->reserved_at : $Post->posted);
                    $PostedAction = $is_request && !$reservation_time_known ? 'Posted' : 'Reserved';
                    $contestable = $Post->isOverdue() ? Posts::CONTESTABLE : '';
                    $LIST .= <<<HTML
<li>
<div class='image screencap'>
\t<a href='{$postLink}'><img src='{$Post->preview}'></a>
</div>
{$label}
<em>{$PostedAction} under {$postAnchor} {$posted}</em>{$contestable}
<div>
\t<a href='{$postLink}' class='btn blue typcn typcn-arrow-forward'>View</a>
\t<button class='red typcn typcn-user-delete cancel'>Cancel</button>
</div>
</li>
HTML;
                }
                $HTML .= "<ul>{$LIST}</ul>";
            }
            $HTML .= "</section>";
        }
        return $HTML;
    }
Esempio n. 17
0
 /**
  * Get HTML for a color group
  *
  * @param int|array  $GroupID
  * @param array|null $AllColors
  * @param bool       $wrap
  * @param bool       $colon
  * @param bool       $colorNames
  * @param bool       $force_extra_info
  *
  * @return string
  */
 static function getHTML($GroupID, $AllColors = null, bool $wrap = true, bool $colon = true, bool $colorNames = false, bool $force_extra_info = false) : string
 {
     global $CGDb;
     if (is_array($GroupID)) {
         $Group = $GroupID;
     } else {
         $Group = $CGDb->where('groupid', $GroupID)->getOne('colorgroups');
     }
     $label = CoreUtils::escapeHTML($Group['label']) . ($colon ? ': ' : '');
     $HTML = "<span class='cat'>{$label}" . ($colorNames && Permission::sufficient('staff') ? '<span class="admin"><button class="blue typcn typcn-pencil edit-cg"></button><button class="red typcn typcn-trash delete-cg"></button></span>' : '') . "</span>";
     if (!isset($AllColors)) {
         $Colors = self::getColors($Group['groupid']);
     } else {
         $Colors = $AllColors[$Group['groupid']] ?? null;
     }
     if (!empty($Colors)) {
         $extraInfo = $force_extra_info || !UserPrefs::get('cg_hideclrinfo');
         foreach ($Colors as $i => $c) {
             $title = CoreUtils::aposEncode($c['label']);
             $color = '';
             if (!empty($c['hex'])) {
                 $color = $c['hex'];
                 $title .= "' style='background-color:{$color}' class='valid-color";
             }
             $append = "<span title='{$title}'>{$color}</span>";
             if ($colorNames) {
                 $append = "<div class='color-line" . (!$extraInfo || empty($color) ? ' no-detail' : '') . "'>{$append}<span><span class='label'>{$c['label']}";
                 if ($extraInfo && !empty($color)) {
                     $rgb = CoreUtils::hex2Rgb($color);
                     $rgb = 'rgb(' . implode(',', $rgb) . ')';
                     $append .= "</span><span class='ext'>{$color} &bull; {$rgb}";
                 }
                 $append .= '</span></div>';
             }
             $HTML .= $append;
         }
     }
     return $wrap ? "<li id='cg{$Group['groupid']}'>{$HTML}</li>" : $HTML;
 }
Esempio n. 18
0
 static function getAppearancesSectionHTML(Episode $Episode) : string
 {
     global $CGDb, $Color;
     $HTML = '';
     $EpTagIDs = Episodes::getTagIDs($Episode);
     if (!empty($EpTagIDs)) {
         $TaggedAppearances = $CGDb->rawQuery("SELECT p.id, p.label, p.private\n\t\t\t\tFROM tagged t\n\t\t\t\tLEFT JOIN appearances p ON t.ponyid = p.id\n\t\t\t\tWHERE t.tid IN (" . implode(',', $EpTagIDs) . ") && p.ishuman = ?\n\t\t\t\tORDER BY p.label", array($Episode->isMovie));
         if (!empty($TaggedAppearances)) {
             $hidePreviews = UserPrefs::get('ep_noappprev');
             $pages = CoreUtils::makePlural('page', count($TaggedAppearances));
             $HTML .= "<section class='appearances'><h2>Related <a href='/cg'>{$Color} Guide</a> {$pages}</h2>";
             $LINKS = '<ul>';
             $isStaff = Permission::sufficient('staff');
             foreach ($TaggedAppearances as $p) {
                 $safeLabel = Appearances::getSafeLabel($p);
                 if (Appearances::isPrivate($p, true)) {
                     $preview = "<span class='typcn typcn-" . ($isStaff ? 'lock-closed' : 'time') . " color-" . ($isStaff ? 'orange' : 'darkblue') . "'></span> ";
                 } else {
                     if ($hidePreviews) {
                         $preview = '';
                     } else {
                         $preview = Appearances::getPreviewURL($p);
                         $preview = "<img src='{$preview}' class='preview'>";
                     }
                 }
                 $LINKS .= "<li><a href='/cg/v/{$p['id']}-{$safeLabel}'>{$preview}{$p['label']}</a></li>";
             }
             $HTML .= "{$LINKS}</ul></section>";
         }
     }
     return $HTML;
 }
Esempio n. 19
0
			<ul class="session-list"><?php
				if (isset($CurrentSession)) Users::renderSessionLi($CurrentSession,CURRENT);
				if (!empty($Sessions)){
					foreach ($Sessions as $s) Users::renderSessionLi($s);
				}
			?></ul>
			<p><button class="typcn typcn-arrow-back yellow" id="signout-everywhere">Sign out everywhere</button></p>
<?php   }
		else { ?>
			<p><?=$sameUser?'You are':'This user is'?>n't logged in anywhere.</p>
<?php   } ?>
		</section>
<?php
	}
	if ($sameUser){
		if (Permission::sufficient('member') && Permission::insufficient('staff')){ ?>
		<section id="verify-discord-identity">
			<h2><?=$sameUser? Users::PROFILE_SECTION_PRIVACY_LEVEL['private']:''?>Verify identity on Discord server</h2>
			<p>If you're not yet part of the Club Members role on our Discord server you can use an automated mechanism to verify your identity. Press the button below, and a command will be displayed which you just need to send to any text channel on the server to have your identity verified.</p>
			<button id="discord-verify" class="green typcn typcn-chevron-right">Show me the command</button>
		</section>
<?php   } ?>
		<section>
			<h2><?=$sameUser? Users::PROFILE_SECTION_PRIVACY_LEVEL['private']:''?>Unlink account</h2>
			<p>By unlinking your account you revoke this site's access to your account information. This will also log you out on every device where you're currently logged in. The next time you want to log in, you'll have to link your account again. This will not remove any of your <strong>public</strong> data from our site, it's still kept locally.</p>
	        <button id="unlink" class="orange typcn typcn-times">Unlink Account</button>
	    </section>
<?  } ?></div>
<?php
} ?>
</div>
Esempio n. 20
0
    /**
     * Generates the markup for the tags sub-page
     *
     * @param array $Tags
     * @param bool  $wrap
     *
     * @return string
     */
    static function getTagListHTML($Tags, $wrap = WRAP)
    {
        global $CGDb;
        $HTML = $utils = $refresh = '';
        $canEdit = Permission::sufficient('staff');
        if ($canEdit) {
            $refresh = " <button class='typcn typcn-arrow-sync refresh' title='Refresh use count'></button>";
            $utils = "<td class='utils align-center'><button class='typcn typcn-minus delete' title='Delete'></button> " . "<button class='typcn typcn-flow-merge merge' title='Merge'></button> <button class='typcn typcn-flow-children synon' title='Synonymize'></button></td>";
        }
        if (!empty($Tags)) {
            foreach ($Tags as $t) {
                $trClass = $t['type'] ? " class='typ-{$t['type']}'" : '';
                $type = $t['type'] ? self::$TAG_TYPES_ASSOC[$t['type']] : '';
                $search = CoreUtils::aposEncode(urlencode($t['name']));
                $titleName = CoreUtils::aposEncode($t['name']);
                if (!empty($t['synonym_of'])) {
                    $Syn = self::getSynonymOf($t, 'name');
                    $t['title'] .= (empty($t['title']) ? '' : '<br>') . "<em>Synonym of <strong>{$Syn['name']}</strong></em>";
                }
                $HTML .= <<<HTML
\t\t\t<tr {$trClass}>
\t\t\t\t<td class="tid">{$t['tid']}</td>
\t\t\t\t<td class="name"><a href='/cg?q={$search}' title='Search for {$titleName}'><span class="typcn typcn-zoom"></span>{$t['name']}</a></td>{$utils}
\t\t\t\t<td class="title">{$t['title']}</td>
\t\t\t\t<td class="type">{$type}</td>
\t\t\t\t<td class="uses"><span>{$t['uses']}</span>{$refresh}</td>
\t\t\t</tr>
HTML;
            }
        }
        return $wrap ? "<tbody>{$HTML}</tbody>" : $HTML;
    }