/** * Get the notification type id from the name * * @param string $notification_type_name The name * @return int the notification_type_id * @throws \src\notification\exception */ public function get_notification_type_id($notification_type_name) { $notification_type_ids = $this->cache->get('notification_type_ids'); if ($notification_type_ids === false) { $notification_type_ids = array(); $sql = 'SELECT notification_type_id, notification_type_name FROM ' . $this->notification_types_table; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id']; } $this->db->sql_freeresult($result); $this->cache->put('notification_type_ids', $notification_type_ids); } if (!isset($notification_type_ids[$notification_type_name])) { if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name])) { throw new \src\notification\exception($this->user->lang('NOTIFICATION_TYPE_NOT_EXIST', $notification_type_name)); } $sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array('notification_type_name' => $notification_type_name, 'notification_type_enabled' => 1)); $this->db->sql_query($sql); $notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid(); $this->cache->put('notification_type_ids', $notification_type_ids); } return $notification_type_ids[$notification_type_name]; }
/** * Permission Remove * * Remove a permission (auth) option * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, * False for a local permission setting * @return null */ public function remove($auth_option, $global = true) { if (!$this->exists($auth_option, $global)) { return; } if ($global) { $type_sql = ' AND is_global = 1'; } else { $type_sql = ' AND is_local = 1'; } $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\tWHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . $type_sql; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $id = (int) $row['auth_option_id']; // If it is a local and global permission, do not remove the row! :P if ($row['is_global'] && $row['is_local']) { $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' SET ' . ($global ? 'is_global = 0' : 'is_local = 0') . ' WHERE auth_option_id = ' . $id; $this->db->sql_query($sql); } else { // Delete time $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE); foreach ($tables as $table) { $this->db->sql_query('DELETE FROM ' . $table . ' WHERE auth_option_id = ' . $id); } } // Purge the auth cache $this->cache->destroy('_acl_options'); $this->auth->acl_clear_prefetch(); }
/** * Obtains the latest version information * * @param bool $force_update Ignores cached data. Defaults to false. * @param bool $force_cache Force the use of the cache. Override $force_update. * @return string Version info, includes stable and unstable data * @throws \RuntimeException */ public function get_versions($force_update = false, $force_cache = false) { $cache_file = '_versioncheck_' . $this->host . $this->path . $this->file; $info = $this->cache->get($cache_file); if ($info === false && $force_cache) { throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); } else { if ($info === false || $force_update) { try { $info = $this->file_downloader->get($this->host, $this->path, $this->file); } catch (\src\exception\runtime_exception $exception) { $prepare_parameters = array_merge(array($exception->getMessage()), $exception->get_parameters()); throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $prepare_parameters)); } $error_string = $this->file_downloader->get_error_string(); if (!empty($error_string)) { throw new \RuntimeException($error_string); } $info = json_decode($info, true); // Sanitize any data we retrieve from a server if (!empty($info)) { $json_sanitizer = function (&$value, $key) { $type_cast_helper = new \src\request\type_cast_helper(); $type_cast_helper->set_var($value, $value, gettype($value), true); }; array_walk_recursive($info, $json_sanitizer); } if (empty($info['stable']) && empty($info['unstable'])) { $this->user->add_lang('acp/common'); throw new \RuntimeException($this->user->lang('VERSIONCHECK_FAIL')); } $info['stable'] = empty($info['stable']) ? array() : $info['stable']; $info['unstable'] = empty($info['unstable']) ? $info['stable'] : $info['unstable']; $this->cache->put($cache_file, $info, 86400); // 24 hours } } return $info; }
/** * Module Remove * * Remove a module * * @param string $class The module class(acp|mcp|ucp) * @param int|string|bool $parent The parent module_id|module_langname(0 for no parent). * Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname * specify that here * @return null * @throws \src\db\migration\exception */ public function remove($class, $parent = 0, $module = '') { // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto if (is_array($module)) { if (isset($module['module_langname'])) { // Manual Method return $this->remove($class, $parent, $module['module_langname']); } // Failed. if (!isset($module['module_basename'])) { throw new \src\db\migration\exception('MODULE_NOT_EXIST'); } // Automatic method $basename = $module['module_basename']; $module_info = $this->get_module_info($class, $basename); foreach ($module_info['modes'] as $mode => $info) { if (!isset($module['modes']) || in_array($mode, $module['modes'])) { $this->remove($class, $parent, $info['title']); } } } else { if (!$this->exists($class, $parent, $module)) { return; } $parent_sql = ''; if ($parent !== false) { // Allows '' to be sent as 0 $parent = $parent ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // we know it exists from the module_exists check $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { $parent_sql = 'AND parent_id = ' . (int) $parent; } } $module_ids = array(); if (!is_numeric($module)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($module) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'\n\t\t\t\t\t\t{$parent_sql}"; $result = $this->db->sql_query($sql); while ($module_id = $this->db->sql_fetchfield('module_id')) { $module_ids[] = (int) $module_id; } $this->db->sql_freeresult($result); } else { $module_ids[] = (int) $module; } if (!class_exists('acp_modules')) { include $this->src_root_path . 'includes/acp/acp_modules.' . $this->php_ext; $this->user->add_lang('acp/modules'); } $acp_modules = new \acp_modules(); $acp_modules->module_class = $class; foreach ($module_ids as $module_id) { $result = $acp_modules->delete_module($module_id); if (!empty($result)) { return; } } $this->cache->destroy("_modules_{$class}"); } }
protected function finalise_update() { $this->cache->purge(); $this->config->increment('assets_version', 1); }
/** * Looks at the list of allowed extensions and generates a string * appropriate for use in configuring plupload with * * @param \src\cache\service $cache * @param string $forum_id The ID of the forum * * @return string */ public function generate_filter_string(\src\cache\service $cache, $forum_id) { $attach_extensions = $cache->obtain_attach_extensions($forum_id); unset($attach_extensions['_allowed_']); $groups = array(); // Re-arrange the extension array to $groups[$group_name][] foreach ($attach_extensions as $extension => $extension_info) { if (!isset($groups[$extension_info['group_name']])) { $groups[$extension_info['group_name']] = array(); } $groups[$extension_info['group_name']][] = $extension; } $filters = array(); foreach ($groups as $group => $extensions) { $filters[] = sprintf("{title: '%s', extensions: '%s'}", addslashes(ucfirst(strtolower($group))), addslashes(implode(',', $extensions))); } return implode(',', $filters); }