本文整理汇总了PHP中ACL::user_tokens方法的典型用法代码示例。如果您正苦于以下问题:PHP ACL::user_tokens方法的具体用法?PHP ACL::user_tokens怎么用?PHP ACL::user_tokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACL
的用法示例。
在下文中一共展示了ACL::user_tokens方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
//.........这里部分代码省略.........
} elseif (isset($paramset['year'])) {
$where[] = 'pubdate BETWEEN ? AND ?';
$startDate = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1);
$startDate = HabariDateTime::date_create($startDate);
$params[] = $startDate->sql;
$params[] = $startDate->modify('+1 year')->sql;
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, 1, 1, $paramset['year'] ) );
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, -1, 1, 1, $paramset['year'] + 1 ) );
}
if (isset($paramset['after'])) {
$where[] = 'pubdate > ?';
$params[] = HabariDateTime::date_create($paramset['after'])->sql;
}
if (isset($paramset['before'])) {
$where[] = 'pubdate < ?';
$params[] = HabariDateTime::date_create($paramset['before'])->sql;
}
// Concatenate the WHERE clauses
if (count($where) > 0) {
$wheres[] = ' (' . implode(' AND ', $where) . ') ';
}
}
}
// Only show posts to which the current user has permission
if (isset($paramset['ignore_permissions'])) {
$master_perm_where = '';
} else {
// This set of wheres will be used to generate a list of post_ids that this user can read
$perm_where = array();
$perm_where_denied = array();
$params_where = array();
$where = array();
// Get the tokens that this user is granted or denied access to read
$read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true);
$deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true);
// If a user can read his own posts, let him
if (User::identify()->can('own_posts', 'read')) {
$perm_where['own_posts_id'] = '{posts}.user_id = ?';
$params_where[] = User::identify()->id;
}
// If a user can read any post type, let him
if (User::identify()->can('post_any', 'read')) {
$perm_where = array('post_any' => '(1=1)');
$params_where = array();
} else {
// If a user can read specific post types, let him
$permitted_post_types = array();
foreach (Post::list_active_post_types() as $name => $posttype) {
if (User::identify()->can('post_' . Utils::slugify($name), 'read')) {
$permitted_post_types[] = $posttype;
}
}
if (count($permitted_post_types) > 0) {
$perm_where[] = '{posts}.content_type IN (' . implode(',', $permitted_post_types) . ')';
}
// If a user can read posts with specific tokens, let him
if (count($read_tokens) > 0) {
$joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')';
$perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL';
}
}
// If a user is denied access to all posts, do so
if (User::identify()->cannot('post_any')) {
$perm_where_denied = array('(1=0)');
} else {
// If a user is denied read access to specific post types, deny him
示例2: get
//.........这里部分代码省略.........
$where->add('pubdate BETWEEN :start_date AND :end_date', array('start_date' => $start_date->sql, 'end_date' => $start_date->modify('+1 year -1 second')->sql));
}
if (isset($paramset['after'])) {
$where->add('pubdate > :after_date', array('after_date' => DateTime::create($paramset['after'])->sql));
}
if (isset($paramset['before'])) {
$where->add('pubdate < :before_date', array('before_date' => DateTime::create($paramset['before'])->sql));
}
// Concatenate the WHERE clauses
$query->where()->add($where);
}
if (isset($paramset['post_join'])) {
$post_joins = Utils::single_array($paramset['post_join']);
foreach ($post_joins as $post_join) {
if (preg_match('#^(\\S+)(?:\\s+as)?\\s+(\\S+)$#i', $post_join, $matches)) {
$query->join("LEFT JOIN {$matches[1]} {$matches[2]} ON {$matches[2]}.post_id = {posts}.id ");
} else {
$query->join("LEFT JOIN {$post_join} ON {$post_join}.post_id = {posts}.id ");
}
}
}
// Only show posts to which the current user has permission
if (isset($paramset['ignore_permissions'])) {
$master_perm_where = new QueryWhere();
// Set up the merge params
$merge_params = array($join_params, $params);
$params = call_user_func_array('array_merge', $merge_params);
} else {
$master_perm_where = new QueryWhere();
// This set of wheres will be used to generate a list of post_ids that this user can read
$perm_where = new QueryWhere('OR');
$perm_where_denied = new QueryWhere('AND');
// Get the tokens that this user is granted or denied access to read
$read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true);
$deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true);
// If a user can read any post type, let him
if (User::identify()->can('post_any', 'read')) {
$perm_where->add('(1=1)');
} else {
// If a user can read his own posts, let him
if (User::identify()->can('own_posts', 'read')) {
$perm_where->add('{posts}.user_id = :current_user_id', array('current_user_id' => User::identify()->id));
}
// If a user can read specific post types, let him
$permitted_post_types = array();
foreach (Post::list_active_post_types() as $name => $posttype) {
if (User::identify()->can('post_' . Utils::slugify($name), 'read')) {
$permitted_post_types[] = $posttype;
}
}
if (count($permitted_post_types) > 0) {
$perm_where->in('{posts}.content_type', $permitted_post_types, 'posts_permitted_types', 'intval');
}
// If a user can read posts with specific tokens, let him
if (count($read_tokens) > 0) {
$query->join('LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')', array(), 'post_tokens__allowed');
$perm_where->add('pt_allowed.post_id IS NOT NULL', array(), 'perms_join_not_null');
}
// If a user has access to read other users' unpublished posts, let him
if (User::identify()->can('post_unpublished', 'read')) {
$perm_where->add('({posts}.status <> :status_published AND {posts}.user_id <> :current_user_id)', array('current_user_id' => User::identify()->id, 'status_published' => Post::status('published')));
}
}
// If a user is denied access to all posts, do so
if (User::identify()->cannot('post_any')) {
$perm_where_denied->add('(1=0)');
示例3: get
//.........这里部分代码省略.........
$params[] = $startDate->sql;
$params[] = $startDate->modify('+1 day')->sql;
} elseif (isset($paramset['month'])) {
$where[] = 'date BETWEEN ? AND ?';
$startDate = sprintf('%d-%02d-%02d', $paramset['year'], $paramset['month'], 1);
$startDate = HabariDateTime::date_create($startDate);
$params[] = $startDate->sql;
$params[] = $startDate->modify('+1 month')->sql;
} elseif (isset($paramset['year'])) {
$where[] = 'date BETWEEN ? AND ?';
$startDate = sprintf('%d-%02d-%02d', $paramset['year'], 1, 1);
$startDate = HabariDateTime::date_create($startDate);
$params[] = $startDate->sql;
$params[] = $startDate->modify('+1 year')->sql;
}
// Concatenate the WHERE clauses
if (count($where) > 0) {
$wheres[] = ' (' . implode(' AND ', $where) . ') ';
}
}
}
// Only show comments to which the current user has permission to read the associated post
if (isset($paramset['ignore_permissions'])) {
$master_perm_where = '';
} else {
// This set of wheres will be used to generate a list of comment_ids that this user can read
$perm_where = array();
$perm_where_denied = array();
$params_where = array();
$where = array();
// every condition here will require a join with the posts table
$joins['posts'] = 'INNER JOIN {posts} ON {comments}.post_id={posts}.id';
// Get the tokens that this user is granted or denied access to read
$read_tokens = isset($paramset['read_tokens']) ? $paramset['read_tokens'] : ACL::user_tokens(User::identify(), 'read', true);
$deny_tokens = isset($paramset['deny_tokens']) ? $paramset['deny_tokens'] : ACL::user_tokens(User::identify(), 'deny', true);
// If a user can read his own posts, let him
if (User::identify()->can('own_posts', 'read')) {
$perm_where['own_posts_id'] = '{posts}.user_id = ?';
$params_where[] = User::identify()->id;
}
// If a user can read any post type, let him
if (User::identify()->can('post_any', 'read')) {
$perm_where = array('post_any' => '(1=1)');
$params_where = array();
} else {
// If a user can read specific post types, let him
$permitted_post_types = array();
foreach (Post::list_active_post_types() as $name => $posttype) {
if (User::identify()->can('post_' . Utils::slugify($name), 'read')) {
$permitted_post_types[] = $posttype;
}
}
if (count($permitted_post_types) > 0) {
$perm_where[] = '{posts}.content_type IN (' . implode(',', $permitted_post_types) . ')';
}
// If a user can read posts with specific tokens, let him see comments on those posts
if (count($read_tokens) > 0) {
$joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN (' . implode(',', $read_tokens) . ')';
$perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL';
}
}
// If a user is denied access to all posts, do so
if (User::identify()->cannot('post_any')) {
$perm_where_denied = array('(0=1)');
} else {
// If a user is denied read access to specific post types, deny him
示例4: get
//.........这里部分代码省略.........
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, 1, 1, $paramset['year'] ) );
//$params[] = date( 'Y-m-d H:i:s', mktime( 0, 0, -1, 1, 1, $paramset['year'] + 1 ) );
}
if ( isset( $paramset['after'] ) ) {
$where[] = 'pubdate > ?';
$params[] = HabariDateTime::date_create( $paramset['after'] )->sql;
}
if ( isset( $paramset['before'] ) ) {
$where[] = 'pubdate < ?';
$params[] = HabariDateTime::date_create( $paramset['before'] )->sql;
}
// Concatenate the WHERE clauses
if ( count( $where ) > 0 ) {
$wheres[] = ' (' . implode( ' AND ', $where ) . ') ';
}
}
}
// Only show posts to which the current user has permission
if ( isset( $paramset['ignore_permissions'] ) ) {
$master_perm_where = '';
}
else {
// This set of wheres will be used to generate a list of post_ids that this user can read
$perm_where = array();
$perm_where_denied = array();
$params_where = array();
$where = array();
// Get the tokens that this user is granted or denied access to read
$read_tokens = isset( $paramset['read_tokens'] ) ? $paramset['read_tokens'] : ACL::user_tokens( User::identify(), 'read', true );
$deny_tokens = isset( $paramset['deny_tokens'] ) ? $paramset['deny_tokens'] : ACL::user_tokens( User::identify(), 'deny', true );
// If a user can read any post type, let him
if ( User::identify()->can( 'post_any', 'read' ) ) {
$perm_where = array( 'post_any' => '(1=1)' );
}
else {
// If a user can read his own posts, let him
if ( User::identify()->can( 'own_posts', 'read' ) ) {
$perm_where['own_posts_id'] = '{posts}.user_id = ?';
$params_where[] = User::identify()->id;
}
// If a user can read specific post types, let him
$permitted_post_types = array();
foreach ( Post::list_active_post_types() as $name => $posttype ) {
if ( User::identify()->can( 'post_' . Utils::slugify( $name ), 'read' ) ) {
$permitted_post_types[] = $posttype;
}
}
if ( count( $permitted_post_types ) > 0 ) {
$perm_where[] = '{posts}.content_type IN (' . implode( ',', $permitted_post_types ) . ')';
}
// If a user can read posts with specific tokens, let him
if ( count( $read_tokens ) > 0 ) {
$joins['post_tokens__allowed'] = ' LEFT JOIN {post_tokens} pt_allowed ON {posts}.id= pt_allowed.post_id AND pt_allowed.token_id IN ('.implode( ',', $read_tokens ).')';
$perm_where['perms_join_null'] = 'pt_allowed.post_id IS NOT NULL';
}
// If a user has access to read other users' unpublished posts, let him
if ( User::identify()->can( 'post_unpublished', 'read' ) ) {