/** * Set up needed stuff for the plugin **/ public function install() { Post::add_new_type('project'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_project', 'read'); }
public function action_plugin_activation($file) { DB::register_table('abbrev'); /* * Create the database table, or upgrade it */ $dbms = DB::get_driver_name(); $sql = 'CREATE TABLE ' . DB::table('abbrev') . ' ' . '('; if ($dbms == 'sqlite') { $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'; } else { if ($dbms == 'mysql') { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } else { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } } $sql .= 'abbrev VARCHAR(255),' . 'caseful INTEGER DEFAULT 0,' . "prefix VARCHAR(16) DEFAULT '\\b'," . "postfix VARCHAR(16) DEFAULT '\\b'," . 'priority INTEGER DEFAULT 100,' . 'definition VARCHAR(255)' . ')'; if (!DB::dbdelta($sql)) { Utils::debug(DB::get_errors()); } if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Abbrev plugin'), 'Category', false); $group = UserGroup::get_by_name('admin'); $group->grant(self::PLUGIN_TOKEN); } }
/** * Register content type **/ public function action_plugin_activation($plugin_file) { // add the content type. Post::add_new_type('event'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_event', 'read'); }
/** * install: * - post type * - permissions */ public static function install() { Post::add_new_type('event'); Post::activate_post_type('event'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_event', 'read'); }
public function action_plugin_activation($file) { if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of AtomIcon plugin'), 'Category', false); $group = UserGroup::get_by_name('admin'); $group->grant(self::PLUGIN_TOKEN); } }
/** * Add the category vocabulary and create the admin token * **/ public function action_plugin_activation($file) { $params = array('name' => self::$vocabulary, 'description' => 'A vocabulary for describing Categories', 'features' => array('multiple', 'hierarchical')); Vocabulary::create($params); // create default access token ACL::create_token('manage_categories', _t('Manage categories'), 'Administration', false); $group = UserGroup::get_by_name('admin'); $group->grant('manage_categories'); }
/** * install various stuff we need */ public static function install() { /** * Register content type **/ Post::add_new_type('report'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_report', 'read'); }
/** * Create an admin token for editing menus **/ public function action_plugin_activation($file) { // create default access token ACL::create_token('manage_menus', _t('Manage menus', 'termmenus'), 'Administration', false); $group = UserGroup::get_by_name('admin'); $group->grant('manage_menus'); // register menu types Vocabulary::add_object_type('menu_link'); Vocabulary::add_object_type('menu_spacer'); }
/** * install various stuff we need */ public static function install() { Post::add_new_type('link'); // Give anonymous users access $group = UserGroup::get_by_name('anonymous'); $group->grant('post_link', 'read'); // Set default settings Options::set('linkblog__original', '<p><a href="{permalink}">Permalink</a></p>'); Options::set('linkblog__atom_permalink', false); self::database(); }
/** * Add the shelf vocabulary and create the admin token * **/ public function action_plugin_activation($file) { if (Plugins::id_from_file($file) == Plugins::id_from_file(__FILE__)) { $params = array('name' => self::$vocabulary, 'description' => 'A vocabulary for describing Shelves', 'features' => array('hierarchical')); Vocabulary::create($params); // create default access token ACL::create_token('manage_shelves', _t('Manage ') . Options::get('shelves__plural', _t('shelves', 'shelves')), 'Administration', false); $group = UserGroup::get_by_name('admin'); $group->grant('manage_shelves'); } }
/** * function test_admin_access * **/ public function test_admin_access() { // Add acl-alice to the admin group //(which has been granted admin priviliges in installhandler). $this->acl_user_alice->add_to_group('admin'); $admin_group = UserGroup::get_by_name('admin'); if ($admin_group instanceof UserGroup) { $admin_group->update(); } $this->assert_true($this->acl_user_alice->can('admin'), 'Admin user does not have admin permission.'); $this->assert_false($this->acl_user_bob->can('admin'), 'Unpriviliged user has admin permission.'); }
/** * Create a new UserGroup object and save it to the database * @param array $paramarray An associative array of UserGroup fields * @return UserGroup the UserGroup that was created * @todo Make this function accept only a name, since you can't set an id into an autoincrement field, and we don't try. */ public static function create($paramarray) { $usergroup = new UserGroup($paramarray); if ($usergroup->insert()) { return $usergroup; } else { // Does the group already exist? if (isset($paramarray['name'])) { $exists = DB::get_value('SELECT count(1) FROM {groups} WHERE name = ?', array($paramarray['name'])); if ($exists) { return UserGroup::get_by_name($paramarray['name']); } } return false; } }
/** * Hook on activation of this plugin */ public function action_plugin_activation() { // add the new content types Post::add_new_type('addon'); // allow reading the new content types UserGroup::get_by_name('anonymous')->grant('post_addon', 'read'); // create a permissions token ACL::create_token('manage_versions', _t('Manage Addon Versions', 'addon_catalog'), 'Addon Catalog', false); // create the addon vocabulary (type) Vocabulary::add_object_type('addon'); // create the addon vocabulary $params = array('name' => self::CATALOG_VOCABULARY, 'description' => _t('A vocabulary for addon versions in the addons catalog', 'addon_catalog')); $vocabulary = Vocabulary::create($params); // @TODO: notification/log of some sort? // create the default content include 'create_core_addons.php'; }
/** * Run activation routines, and setup default options. */ public function action_plugin_activation() { if (!CronTab::get_cronjob('blogroll:update')) { CronTab::add_hourly_cron('blogroll:update', 'blogroll_update_cron', 'Updates the blog updated timestamp from weblogs.com'); } Options::set('blogroll__api_version', self::API_VERSION); Options::set('blogroll__use_updated', true); Options::set('blogroll__max_links', '10'); Options::set('blogroll__sort_by', 'id'); Options::set('blogroll__direction', 'ASC'); Options::set('blogroll__list_title', 'Blogroll'); Post::add_new_type(self::CONTENT_TYPE); // Give anonymous users access, if the group exists $group = UserGroup::get_by_name('anonymous'); if ($group) { $group->grant(self::CONTENT_TYPE, 'read'); } }
public function action_plugin_activation($plugin_file) { Post::add_new_type('urlbounce'); $group = UserGroup::get_by_name('anonymous'); $group->grant('post_urlbounce', 'read'); }
/** * Action: plugin activation * * Sets up this plugin when activated, including: * * - Creates the ACL token for admin users * - Creates plugin options with initial values of 0 (off) * * @return void */ public function action_plugin_activation($file) { if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token('manage_options', _t('Manage Options'), 'Options', FALSE); $group = UserGroup::get_by_name('admin'); $group->grant('manage_options'); } Options::set(strtolower(get_class($this)) . '__allow_delete_core', 0); Options::set(strtolower(get_class($this)) . '__allow_delete_other', 0); }
/** * Set up needed permissions */ private static function install() { // Create post types Post::add_new_type('forum'); Post::add_new_type('thread'); Post::add_new_type('reply'); // Create vocabulary $params = array('name' => self::$vocab, 'description' => 'A vocabulary for describing relationships between threads', 'features' => array('hierarchical')); $vocabulary = new Vocabulary($params); $vocabulary->insert(); // Create tokens ACL::create_token('forum_see_private', _t('See Private Threads'), 'Forum', false); ACL::create_token('forum_close_thread', _t('Close Threads'), 'Forum', false); // Grant tokens $group = UserGroup::get_by_name('admin'); $group->grant('forum_close_thread'); $group->grant('forum_see_private'); }
public function action_plugin_activation($file) { DB::register_table('macro'); /* * Create the database table, or upgrade it */ $dbms = DB::get_driver_name(); $sql = 'CREATE TABLE ' . DB::table('macro') . ' ' . '('; if ($dbms == 'sqlite') { $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, '; } else { if ($dbms == 'mysql') { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT, ' . 'UNIQUE KEY xid (xid), '; } else { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT, ' . 'UNIQUE KEY xid (xid), '; } } $sql .= 'name VARCHAR(255), ' . 'enabled INTEGER DEFAULT 1, ' . 'modified INTEGER, ' . 'description TEXT, ' . 'definition TEXT NOT NULL, ' . 'container INTEGER DEFAULT 0, ' . 'nargs INTEGER DEFAULT 0, ' . 'eval INTEGER DEFAULT 0' . ')'; if (!DB::dbdelta($sql)) { // Utils::debug(DB::get_errors()); } if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Macros plugin'), 'Category', false); $group = UserGroup::get_by_name('admin'); $group->grant(self::PLUGIN_TOKEN); } }
/** * Reset premissions to their default state */ public static function rebuild_permissions($user = null) { // Clear out all permission-related values DB::query('DELETE FROM {tokens}'); DB::query('DELETE FROM {group_token_permissions}'); //DB::query( 'DELETE FROM {groups}' ); DB::query('DELETE FROM {post_tokens}'); DB::query('DELETE FROM {user_token_permissions}'); //DB::query('DELETE FROM {users_groups}'); // Create initial groups if they don't already exist $admin_group = UserGroup::get_by_name(_t('admin')); if (!$admin_group instanceof UserGroup) { $admin_group = UserGroup::create(array('name' => _t('admin'))); } $anonymous_group = UserGroup::get_by_name(_t('anonymous')); if (!$anonymous_group instanceof UserGroup) { $anonymous_group = UserGroup::create(array('name' => _t('anonymous'))); } // Add all users or the passed user to the admin group if (empty($user)) { $users = Users::get_all(); $ids = array(); foreach ($users as $user) { $ids[] = $user->id; } $admin_group->add($ids); } else { $admin_group->add($user); } // create default permissions self::create_default_tokens(); // Make the admin group all superusers $admin_group->grant('super_user'); // Add entry and page read access to the anonymous group $anonymous_group->grant('post_entry', 'read'); $anonymous_group->grant('post_page', 'read'); $anonymous_group->grant('comment'); $anonymous_group->deny('post_unpublished'); // Add the anonymous user to the anonymous group $anonymous_group->add(0); // Create the default authenticated group $authenticated_group = UserGroup::get_by_name(_t('authenticated')); if (!$authenticated_group instanceof UserGroup) { $authenticated_group = UserGroup::create(array('name' => _t('authenticated'))); } $authenticated_group->grant('post_entry', 'read'); $authenticated_group->grant('post_page', 'read'); $authenticated_group->grant('comment'); }
private function upgrade_db_post_3236() { // Add a default to the number of posts of a feed $atom_entries = Options::get('atom_entries'); if (empty($atom_entries)) { Options::set('atom_entries', '5'); } // Create the default authenticated group $authenticated_group = UserGroup::get_by_name(_t('authenticated')); if (!$authenticated_group instanceof UserGroup) { $authenticated_group = UserGroup::create(array('name' => _t('authenticated'))); } $authenticated_group->grant('post_entry', 'read'); $authenticated_group->grant('post_page', 'read'); $authenticated_group->grant('comment'); }
/** * Returns a user or users based on supplied parameters. * @todo This class should cache query results! * * @param array $paramarray An associated array of parameters, or a querystring * @return array An array of User objects, or a single User object, depending on request */ public static function get($paramarray = array()) { $params = array(); $fns = array('get_results', 'get_row', 'get_value'); $select = ''; // what to select -- by default, everything foreach (User::default_fields() as $field => $value) { $select .= '' == $select ? "{users}.{$field}" : ", {users}.{$field}"; } // defaults $orderby = 'id ASC'; $nolimit = true; // Put incoming parameters into the local scope $paramarray = Utils::get_params($paramarray); // Transact on possible multiple sets of where information that is to be OR'ed if (isset($paramarray['where']) && is_array($paramarray['where'])) { $wheresets = $paramarray['where']; } else { $wheresets = array(array()); } $wheres = array(); $join = ''; if (isset($paramarray['orderby'])) { $orderby = $paramarray['orderby']; } if (isset($paramarray['where']) && is_string($paramarray['where'])) { $wheres[] = $paramarray['where']; } else { foreach ($wheresets as $paramset) { // safety mechanism to prevent empty queries $where = array(); $paramset = array_merge((array) $paramarray, (array) $paramset); $default_fields = User::default_fields(); unset($default_fields['id']); foreach ($default_fields as $field => $scrap) { if (!isset($paramset[$field])) { continue; } switch ($field) { default: $where[] = "{$field} = ?"; $params[] = $paramset[$field]; } } if (isset($paramset['info']) && is_array($paramset['info'])) { $join .= 'INNER JOIN {userinfo} ON {users}.id = {userinfo}.user_id'; foreach ($paramset['info'] as $info_name => $info_value) { $where[] = '{userinfo}.name = ? AND {userinfo}.value = ?'; $params[] = $info_name; $params[] = $info_value; } } if (isset($paramset['group']) && is_array($paramset['group'])) { $join .= ' INNER JOIN {users_groups} ON {users}.id = {users_groups}.user_id'; foreach ($paramset['group'] as $group) { $group_id = UserGroup::get_by_name($group)->id; $where[] = '{users_groups}.group_id = ?'; $params[] = $group_id; } } if (isset($paramset['id'])) { if (is_array($paramset['id'])) { array_walk($paramset['id'], function (&$a) { $a = intval($a); }); $where[] = "{users}.id IN (" . implode(',', array_fill(0, count($paramset['id']), '?')) . ")"; $params = array_merge($params, $paramset['id']); } else { $where[] = "{users}.id = ?"; $params[] = (int) $paramset['id']; } } if (isset($paramset['not:id'])) { if (is_array($paramset['not:id'])) { array_walk($paramset['not:id'], function (&$a) { $a = intval($a); }); $where[] = "{users}.id NOT IN (" . implode(',', array_fill(0, count($paramset['not:id']), '?')) . ")"; $params = array_merge($params, $paramset['not:id']); } else { $where[] = "{users}.id != ?"; $params[] = (int) $paramset['not:id']; } } if (isset($paramset['criteria'])) { if (isset($paramset['criteria_fields'])) { // Support 'criteria_fields' => 'author,ip' rather than 'criteria_fields' => array( 'author', 'ip' ) if (!is_array($paramset['criteria_fields']) && is_string($paramset['criteria_fields'])) { $paramset['criteria_fields'] = explode(',', $paramset['criteria_fields']); } } else { $paramset['criteria_fields'] = array('username'); } $paramset['criteria_fields'] = array_unique($paramset['criteria_fields']); // this regex matches any unicode letters (\p{L}) or numbers (\p{N}) inside a set of quotes (but strips the quotes) OR not in a set of quotes preg_match_all('/(?<=")([\\p{L}\\p{N}]+[^"]*)(?=")|([\\p{L}\\p{N}]+)/u', $paramset['criteria'], $matches); $where_search = array(); foreach ($matches[0] as $word) { foreach ($paramset['criteria_fields'] as $criteria_field) { $where_search[] .= "( LOWER( {users}.{$criteria_field} ) LIKE ? )"; $params[] = '%' . MultiByte::strtolower($word) . '%'; } } if (count($where_search) > 0) { $where[] = '(' . implode(" \nOR\n ", $where_search) . ')'; } } if (count($where) > 0) { $wheres[] = ' (' . implode(' AND ', $where) . ') '; } } } // Get any full-query parameters $possible = array('fetch_fn', 'count', 'nolimit', 'limit', 'offset'); foreach ($possible as $varname) { if (isset($paramarray[$varname])) { ${$varname} = $paramarray[$varname]; } } if (isset($fetch_fn)) { if (!in_array($fetch_fn, $fns)) { $fetch_fn = $fns[0]; } } else { $fetch_fn = $fns[0]; } // is a count being request? if (isset($count)) { $select = "COUNT({$count})"; $fetch_fn = 'get_value'; $orderby = ''; } if (isset($limit)) { unset($nolimit); $limit = " LIMIT {$limit}"; if (isset($offset)) { $limit .= " OFFSET {$offset}"; } } if (isset($nolimit)) { $limit = ''; } $query = ' SELECT ' . $select . ' FROM {users} ' . $join; if (count($wheres) > 0) { $query .= ' WHERE ' . implode(" \nOR\n ", $wheres); } $query .= ($orderby == '' ? '' : ' ORDER BY ' . $orderby) . $limit; DB::set_fetch_mode(\PDO::FETCH_CLASS); DB::set_fetch_class('User'); $results = DB::$fetch_fn($query, $params, 'User'); if ('get_results' != $fetch_fn) { // return the results return $results; } elseif (is_array($results)) { $c = __CLASS__; $return_value = new $c($results); $return_value->get_param_cache = $paramarray; return $return_value; } }