/** * 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]; }
/** * 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; }