本文整理汇总了PHP中Base::requireLogged方法的典型用法代码示例。如果您正苦于以下问题:PHP Base::requireLogged方法的具体用法?PHP Base::requireLogged怎么用?PHP Base::requireLogged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Base
的用法示例。
在下文中一共展示了Base::requireLogged方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newsfeed
private function newsfeed()
{
Base::requireLogged();
// Stream
$feedPlaylists = Base::$g['logged']->feedPlaylists();
Base::eagerLoadingPlaylistTags($feedPlaylists);
View::set('feed_playlists', $feedPlaylists);
View::show('newsfeed');
}
示例2: logout
/**
* User log out
*/
private function logout()
{
Base::requireLogged();
// Deletes session, thus logging the user out
Session::logout();
// Redirects to home page
Base::redirect('', 'Successfully logged out');
}
示例3: tracksearch
/**
* Track search
*/
private function tracksearch()
{
Base::requireLogged();
$ret = array('status' => 0);
if (!$_GET['q']) {
return $ret;
}
// Filter search
$query = Base::searchQuery($_GET['q']);
if (!$query) {
return $ret;
}
// Get tracks
$tracks = Track::filter('bySearchQuery', $query)->paginate(-1, 6);
if ($tracks['num'] <= 6 || $_GET['page'] === '2' && $tracks['num'] <= 12) {
$query = str_replace('%', ' ', $query);
$rows = Soundcloud::search($query);
$rows = array_slice($rows, 0, 6);
$tracks = array('rows' => $rows);
}
$ret['tracks'] = $tracks;
$ret['status'] = isset($tracks['rows']) && !!$tracks['rows'];
// // Get favourite tracks
// $favTracks = $tracks->select('t.*')
// ->join('track_fav', 'tf.track_id = t.id', 'tf')
// ->where('tf.user_id', LOGGED)
// ->where('tf.active', 1)
// ->paginate();
// $ret['fav_tracks'] = $favTracks;
return $ret;
}
示例4: edit
/**
* Edit a playlist
*/
private function edit()
{
Base::requireLogged();
if (LOGGED !== $this->playlist->user_id) {
Base::requireAdmin();
}
// Set page title
View::set('page_title', 'Edit playlist');
// Set playlist
$playlist = $this->playlist->asArray();
$playlist['tracks'] = $this->playlist->tracks();
$tags = $this->playlist->tags();
if ($tags) {
$playlist['tags'] = implode(', ', $tags);
}
View::set('playlist', $playlist);
// Not submitted
if (!isset($_POST['playlist']) && !isset($_POST['draft'])) {
View::show('playlist/edit');
}
/**
* Add playlist title and playlist description
*/
if (!Validate::len($_POST['title'], 2, 64)) {
$error = 'Playlist title must be between 2 and 64 chars';
} elseif (!Validate::len($_POST['description'], 0, 512)) {
$error = 'Playlist description must be lesser than 512 chars';
}
if ($error) {
View::error('playlist/edit', $error);
}
// Raw HTML may enter the db but it's automatically
// encoded at output by Mustache
$this->playlist->title = $_POST['title'];
$this->playlist->description = $_POST['description'];
/**
* Uploads cover image
*/
if (!empty($_FILES['cover']) && $_FILES['cover']['size'] > 0) {
Base::uploadImage($_FILES['cover'], $cover, $error);
if ($error) {
View::error('playlist/edit', $error);
}
$this->playlist->cover = $cover;
}
/**
* Inserts tags into database
*/
if (!empty($_POST['tags'])) {
// Separates tags by commas
$tags = strtolower($_POST['tags']);
$tags = explode(',', $tags, 6);
// Tag limit
$tags = array_slice($tags, 0, 5);
// Filter tags
foreach ($tags as $k => &$tag) {
if (!ADMIN && $tag === 'staff') {
continue;
}
$tag = preg_replace('/[^a-z]+/', ' ', $tag);
$tag = trim($tag, ' ');
// Tag must have at least 2 chars
// And it must be lesser than 32 chars
if (!Validate::len($tag, 1, 32)) {
unset($tags[$k]);
}
}
if (!empty($tags)) {
// Remove tags from PlaylistTag
PlaylistTag::where('playlist_id', $this->playlist->id)->deleteMany();
// Insert tags
$sql = str_repeat(',(?)', count($tags));
$sql[0] = ' ';
Tag::rawExecute("INSERT IGNORE INTO tag(name) VALUES {$sql}", $tags);
// Get inserted tags ids and point them to the new playlist
$tags = Tag::select('id')->whereIn('name', $tags)->findMany();
foreach ($tags as $tag) {
$link = PlaylistTag::create();
$link->playlist_id = $this->playlist->id;
$link->tag_id = $tag->id;
$link->save();
}
}
}
// Published status
$this->playlist->published = isset($_POST['playlist']);
/**
* Add tracks into db
*/
if (!isset($_POST['tracks'])) {
$error = 'You can\'t publish without any tracks';
$this->playlist->published = 0;
} else {
if (is_array($_POST['tracks'])) {
$max = Base::$g['playlist_max_tracks'];
$min = Base::$g['playlist_min_tracks'];
$tracks = $_POST['tracks'];
//.........这里部分代码省略.........
示例5: settings
/**
* User settings
*/
private function settings()
{
Base::requireLogged();
if (LOGGED !== $this->user->id) {
Base::requireAdmin();
}
if (!isset($_POST['usr']) && !isset($_POST['avatar']) && !isset($_POST['pwd'])) {
View::show('profile/settings');
}
// Username or email change
if (isset($_POST['usr'])) {
} elseif (isset($_POST['avatar'])) {
Base::uploadImage($_FILES['avatar'], $avatar, $error);
if ($error) {
View::error('profile/settings', $error);
}
$this->user->avatar = $avatar;
$this->user->save();
View::set('success', 'Avatar successfully changed');
View::set('user', $this->user->asArray());
// Actualized user
View::show('profile/settings');
} elseif (isset($_POST['password'])) {
$currentPwd = $_POST['current_pwd'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
if (!Base::checkPassword($currentPwd, $this->user->password)) {
$error = 'You misspelled your current password';
// Need help? Forgot pwd
} elseif (!Validate::len($password, 4, 128)) {
$error = 'Password must have more than 4 characters';
} elseif ($password != $password2) {
$error = 'Passwords don\'t match';
}
if ($error) {
View::error('profile/settings', $error);
}
$this->user->password = Base::hashPassword($password);
$this->user->save();
View::set('success', 'Password successfully changed');
View::show('profile/settings');
}
}