예제 #1
0
 /**
  * Page loading function
  * ---------------------
  * $options = array(
  *     'title' => string,     - Page title
  *     'no-robots',           - Disable crawlers (that respect meta tags)
  *     'no-default-css',      - Disable loading of default CSS files
  *     'no-default-js'        - Disable loading of default JS files
  *     'css' => string|array, - Specify a single/multiple CSS files to load
  *     'js' => string|array,  - Specify a single/multiple JS files to load
  *     'view' => string,      - Which view file to open (defaults to $do)
  *     'do-css',              - Load the CSS file whose name matches $do
  *     'do-js',               - Load the JS file whose name matches $do
  *     'url' => string,       - A URL which will replace the one sent to the browser
  * );
  *
  * @param array $options
  */
 static function loadPage($options)
 {
     // Page <title>
     if (isset($options['title'])) {
         $GLOBALS['title'] = $options['title'];
     }
     // Page heading
     if (isset($options['heading'])) {
         $GLOBALS['heading'] = $options['heading'];
     }
     // SE crawling disable
     if (in_array('no-robots', $options)) {
         $norobots = true;
     }
     // Set new URL option
     if (!empty($options['url'])) {
         $redirectto = $options['url'];
     }
     # CSS
     $DEFAULT_CSS = array('theme');
     $customCSS = array();
     // Only add defaults when needed
     if (array_search('no-default-css', $options) === false) {
         $customCSS = array_merge($customCSS, $DEFAULT_CSS);
     }
     # JavaScript
     $DEFAULT_JS = array('moment', 'global', 'dialog');
     $customJS = array();
     // Only add defaults when needed
     if (array_search('no-default-js', $options) === false) {
         $customJS = array_merge($customJS, $DEFAULT_JS);
     }
     # Check assests
     self::_checkAssets($options, $customCSS, 'scss/min', 'css');
     self::_checkAssets($options, $customJS, 'js/min', 'js');
     # Import global variables
     foreach ($GLOBALS as $k => $v) {
         if (!isset(${$k})) {
             ${$k} = $v;
         }
     }
     # Putting it together
     $view = empty($options['view']) ? $GLOBALS['do'] : $options['view'];
     $viewPath = INCPATH . "views/{$view}.php";
     header('Content-Type: text/html; charset=utf-8;');
     if (empty($_GET['via-js'])) {
         ob_start();
         require INCPATH . 'views/header.php';
         require $viewPath;
         require INCPATH . 'views/footer.php';
         $content = ob_get_clean();
         echo self::_clearIndentation($content);
         die;
     } else {
         $_SERVER['REQUEST_URI'] = rtrim(str_replace('via-js=true', '', CSRFProtection::removeParamFromURL($_SERVER['REQUEST_URI'])), '?&');
         ob_start();
         require INCPATH . 'views/sidebar.php';
         $sidebar = ob_get_clean();
         ob_start();
         require $viewPath;
         $content = ob_get_clean();
         Response::done(array('css' => $customCSS, 'js' => $customJS, 'title' => (isset($GLOBALS['title']) ? $GLOBALS['title'] . ' - ' : '') . SITE_TITLE, 'content' => self::_clearIndentation($content), 'sidebar' => self::_clearIndentation($sidebar), 'footer' => CoreUtils::getFooter(WITH_GIT_INFO), 'avatar' => $GLOBALS['signedIn'] ? $GLOBALS['currentUser']->avatar_url : GUEST_AVATAR, 'responseURL' => $_SERVER['REQUEST_URI'], 'signedIn' => $GLOBALS['signedIn']));
     }
 }
예제 #2
0
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';
    $val = $currentUser->Session['id'];
}
if (!$Database->where($col, $val)->delete('sessions')) {
    Response::fail('Could not remove information from database');
}
if (empty($TargetUser)) {
    Cookie::delete('access', Cookie::HTTPONLY);
}
Response::done();
예제 #3
0
파일: post.php 프로젝트: ponydevs/MLPVC-RR
$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));
예제 #4
0
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) {
    Response::done(array('value' => $newvalue));
}
if (!GlobalSettings::set($key, $newvalue)) {
    Response::dbError();
}
Response::done(array('value' => $newvalue));
예제 #5
0
                            Response::dbError('Episode tag creation failed');
                        }
                    }
                }
            }
        }
        if ($editing) {
            $logentry = array('target' => $Episode->formatTitle(AS_ARRAY, 'id'));
            $changes = 0;
            if (!empty($Episode->airs)) {
                $Episode->airs = date('c', strtotime($Episode->airs));
            }
            foreach (array('season', 'episode', 'twoparter', 'title', 'airs') as $k) {
                if (isset($insert[$k]) && $insert[$k] != $Episode->{$k}) {
                    $logentry["old{$k}"] = $Episode->{$k};
                    $logentry["new{$k}"] = $insert[$k];
                    $changes++;
                }
            }
            if ($changes > 0) {
                Logs::action('episode_modify', $logentry);
            }
        } else {
            Logs::action('episodes', array('action' => 'add', 'season' => $insert['season'], 'episode' => $insert['episode'], 'twoparter' => isset($insert['twoparter']) ? $insert['twoparter'] : 0, 'title' => $insert['title'], 'airs' => $insert['airs']));
        }
        if ($editing) {
            Response::done();
        }
        Response::done(array('url' => (new Episode($insert))->formatURL()));
        break;
}
예제 #6
0
    if (!empty($search['hits']['hits'])) {
        $ids = [];
        foreach ($search['hits']['hits'] as $hit) {
            $ids[] = $hit['_id'];
        }
        $Ponies = $CGDb->where('id IN (' . implode(',', $ids) . ')')->orderBy('order', 'ASC')->get('appearances');
    }
}
if (!$elasticAvail) {
    $_EntryCount = $CGDb->where('ishuman', $EQG)->where('id != 0')->count('appearances');
    $Pagination = new Pagination('cg', $AppearancesPerPage, $_EntryCount);
    $Ponies = Appearances::get($EQG, $Pagination->getLimit());
}
if (isset($_REQUEST['GOFAST'])) {
    if (empty($Ponies[0]['id'])) {
        Response::fail('The search returned no results.');
    }
    Response::done(array('goto' => "{$CGPath}/v/{$Ponies[0]['id']}-" . Appearances::getSafeLabel($Ponies[0])));
}
CoreUtils::fixPath("{$CGPath}/{$Pagination->page}" . (!empty($Restrictions) ? "?q={$SearchQuery}" : ''));
$heading = ($EQG ? 'EQG ' : '') . "{$Color} Guide";
$title .= "Page {$Pagination->page} - {$heading}";
if (isset($_GET['js'])) {
    $Pagination->respond(Appearances::getHTML($Ponies, NOWRAP), '#list');
}
$settings = array('title' => $title, 'heading' => $heading, 'css' => array($do), 'js' => array('jquery.qtip', 'jquery.ctxmenu', $do, 'paginate'));
if (Permission::sufficient('staff')) {
    $settings['css'] = array_merge($settings['css'], $GUIDE_MANAGE_CSS);
    $settings['js'] = array_merge($settings['js'], $GUIDE_MANAGE_JS);
}
CoreUtils::loadPage($settings);
예제 #7
0
파일: user.php 프로젝트: ponydevs/MLPVC-RR
                Response::fail("You cannot {$action} yourself");
            }
            if (Permission::sufficient('staff', $targetUser->role)) {
                Response::fail("You cannot {$action} people within the assistant or any higher group");
            }
            if ($action == 'banish' && $targetUser->role === 'ban' || $action == 'un-banish' && $targetUser->role !== 'ban') {
                Response::fail("This user has already been {$action}ed");
            }
            $reason = (new Input('reason', 'string', array(Input::IN_RANGE => [5, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Please specify a reason', Input::ERROR_RANGE => 'Reason length must be between @min and @max characters'))))->out();
            $changes = array('role' => $action == 'banish' ? 'ban' : 'user');
            $Database->where('id', $targetUser->id)->update('users', $changes);
            Logs::action($action, array('target' => $targetUser->id, 'reason' => $reason));
            $changes['role'] = Permission::ROLES_ASSOC[$changes['role']];
            $changes['badge'] = Permission::labelInitials($changes['role']);
            if ($action == 'banish') {
                Response::done($changes);
            }
            Response::success("We welcome {$targetUser->name} back with open hooves!", $changes);
        } else {
            CoreUtils::notFound();
        }
    }
}
if (strtolower($data) === 'immortalsexgod') {
    $data = 'DJDavid98';
}
if (empty($data)) {
    if ($signedIn) {
        $un = $currentUser->name;
    } else {
        $MSG = 'Sign in to view your settings';
예제 #8
0
파일: about.php 프로젝트: ponydevs/MLPVC-RR
                    Statistics::processUsageData($RequestData, $Dataset);
                    $Data['datasets'][] = $Dataset;
                }
                $ReservationData = $Database->rawQuery(str_replace('table_name', 'reservations', $query));
                if (!empty($ReservationData)) {
                    $Dataset = array('label' => 'Reservations', 'clrkey' => 1);
                    Statistics::processUsageData($ReservationData, $Dataset);
                    $Data['datasets'][] = $Dataset;
                }
                break;
            case 'approvals':
                $Labels = $Database->rawQuery("SELECT to_char(timestamp,'{$LabelFormat}') AS key\n\t\t\t\t\tFROM log\n\t\t\t\t\tWHERE timestamp > NOW() - INTERVAL '2 MONTHS' AND reftype = 'post_lock'\n\t\t\t\t\tGROUP BY key\n\t\t\t\t\tORDER BY MIN(timestamp)");
                Statistics::processLabels($Labels, $Data);
                $Approvals = $Database->rawQuery("SELECT\n\t\t\t\t\t\tto_char(MIN(timestamp),'{$LabelFormat}') AS key,\n\t\t\t\t\t\tCOUNT(*)::INT AS cnt\n\t\t\t\t\tFROM log\n\t\t\t\t\tWHERE timestamp > NOW() - INTERVAL '2 MONTHS' AND reftype = 'post_lock'\n\t\t\t\t\tGROUP BY to_char(timestamp,'{$LabelFormat}')\n\t\t\t\t\tORDER BY MIN(timestamp)");
                if (!empty($Approvals)) {
                    $Dataset = array('label' => 'Approved posts');
                    Statistics::processUsageData($Approvals, $Dataset);
                    $Data['datasets'][] = $Dataset;
                }
                break;
        }
        Statistics::postprocessTimedData($Data);
        CoreUtils::createUploadFolder($CachePath);
        file_put_contents($CachePath, JSON::encode($Data));
        Response::done(array('data' => $Data));
    }
    CoreUtils::notFound();
}
HTTP::pushResource('/about/stats-posts');
HTTP::pushResource('/about/stats-approvals');
CoreUtils::loadPage(array('title' => 'About', 'do-css', 'js' => array('Chart', $do)));