public function set_preset($preset) { if ($preset->valid_for_setting != $this->id) { trigger_warning("can't use setting {$preset->name} for FilterSetting {$id}", E_USER_NOTICE); return NULL; } foreach ($preset->active_filters as $f) { } }
final function __construct($dumb_key, $settings = NULL) { if ($dumb_key == 'do_not_instantiate_me_directly') { if (isset($settings['constants'])) { foreach ($settings['constants'] as $k => $v) { if (!defined($k)) { define($k, $v); } } } if (isset($settings)) { $this->setup_custom($settings); } $this->validated = $this->validate(); } else { trigger_warning('A cache type cannot be instantiated directly - instantiate an ObjectCache object, and set its type appropriately.', 1); } }
/** * Determines the MIME type of a file based solely on its file extension. * Requires that the configuration constant {@link APACHE_MIME_TYPES} has been * defined and contains the path to an Apache mime.types file. * * {@internal Adapted from <code>ReasonAssetAccess.get_mime_type()</code>.} * * @param string $extension the file extension whose MIME type is desired * @param string $default what to return if the type cannot be determined * @return string the determined MIME type, or <code>$default</code> if the * type could not be determined **/ function mime_type_from_extension($extension, $default = null) { static $cache = array(); static $error_reported = false; $extension = ltrim(strtolower($extension), '.'); if (isset($cache[$extension])) { return $cache[$extension]; } if (!defined('APACHE_MIME_TYPES')) { if (!$error_reported) { $error_reported = true; trigger_warning('cannot determine MIME type of file based on its ' . 'extension: the APACHE_MIME_TYPES constant is not defined'); return $default; } } if (!is_file(APACHE_MIME_TYPES)) { if (!$error_reported) { $error_reported = true; trigger_warning('cannot determine MIME type of file based on its ' . 'extension: no such file: ' . var_export(APACHE_MIME_TYPES, true)); return $default; } } $file = fopen(APACHE_MIME_TYPES, 'rt'); $result = $default; while (!feof($file)) { if (fscanf($file, "%s\t%[^\n]", $type, $extension_list)) { if ($type[0] == '#' || empty($extension_list)) { continue; } if (in_array($extension, explode(' ', $extension_list))) { // match! $cache[$extension] = $result = $type; break; } } } fclose($file); return $result; }
/** * Include a file if needed - we allow a relative path from minisite_templates/modules/ or an absolute path. */ private final function _setup_mvc($type, $params = NULL) { if (!in_array($type, array('controller', 'model', 'view'))) { trigger_warning('The type passed (' . $type . ') to _setup_mvc must be "controller", "model", or "view"', 1); return NULL; } if (!empty($params['file']) || !empty($this->{$type})) { if (empty($params['file']) || !empty($this->{$type})) { $params['file'] = $this->{$type}; } if (reason_file_exists('minisite_templates/modules/' . $params['file'])) { reason_include_once('minisite_templates/modules/' . $params['file']); $full_path = reason_resolve_path('minisite_templates/modules/' . $params['file']); } elseif (reason_file_exists($params['file'])) { reason_include_once($params['file']); $full_path = reason_resolve_path($params['file']); } elseif (file_exists($params['file'])) { include_once $params['file']; $full_path = realpath($params['file']); } else { trigger_error('The mvc module was unable to load the ' . $type . ' (' . $params['file'] . ')', FATAL); } if (isset($GLOBALS['_reason_mvc_' . $type . '_class_names'][reason_basename($full_path)])) { $class_name = $GLOBALS['_reason_mvc_' . $type . '_class_names'][reason_basename($full_path)]; } else { trigger_error('The mvc module was unable to determine the class name for the ' . $type . ' (' . $params['file'] . ') - check that the file properly registers itself.', FATAL); } unset($params['file']); } else { if ($type == 'controller') { $class_name = 'ReasonMVCController'; } // setup the default controller } // instantiate and return it. if (isset($class_name)) { $obj = new $class_name(); $this->configure_mvc($type, $obj, $params); return $obj; } }
/** * Examines the state of the upload and generates relevant PHP warnings. * * If there is anything wrong with the upload that should be communicated * to the site admins, this function should raise that information as PHP * error messages. * * @access protected * @return void */ function _generate_warnings() { static $admin_warnings = null; if ($admin_warnings === null) { $symbolic_warnings = array("UPLOAD_ERR_NO_TMP_DIR" => "PHP has no temporary directory to save the upload to.", "UPLOAD_ERR_CANT_WRITE" => "PHP could not write the uploaded file to disk.", "UPLOAD_ERR_EXTENSION" => "The file upload was stopped by a PHP extension."); $admin_warnings = array(); foreach ($symbolic_warnings as $constant => $message) { if (defined($constant)) { $admin_warnings[constant($constant)] = $message; } } } $error = $this->_get_upload_error(); if (isset($admin_warnings[$error])) { trigger_warning($admin_warnings[$error], 2); } }
private function _get_page_type_array($page_type_name) { reason_include_once('minisite_templates/page_types.php'); if (isset($GLOBALS['_reason_page_types'][$page_type_name])) { $page_type = $GLOBALS['_reason_page_types']['default']; if ($page_type_name != 'default') { $specific_page_type = $GLOBALS['_reason_page_types'][$page_type_name]; foreach ($specific_page_type as $region => $info) { if (isset($page_type[$region])) { unset($page_type[$region]); } $page_type[$region] = $info; } } } else { trigger_warning('Page type specified (' . htmlspecialchars($page_type_name, ENT_QUOTES, 'UTF-8') . ') does not exist. You should either reinstate or change the page type.', 1); } return isset($page_type) ? $page_type : false; }
/** * Return authentication credentials for the specified database connection. * * @param string $conn_name The name of the db connection you want to retrieve * @param boolean $lack_of_creds_is_fatal defaults to true for historical purposes * @return array Array with all the db connection info defined for the specified named connection. */ function _legacy_get_db_credentials($conn_name, $lack_of_creds_is_fatal = true) { static $db_info; // if db_info has not been set, this is the first time this function has been run. if (!isset($db_info)) { trigger_warning('Using _legacy_get_db_credentials - please upgrade to PHP 5.1 or later to use faster XML functions.'); if (!defined('DB_CREDENTIALS_FILEPATH')) { trigger_fatal_error('The DB_CREDENTIALS_FILEPATH constant is not defined.'); } $db_info = array(); require_once INCLUDE_PATH . 'xml/xmlparser.php'; if (file_exists(DB_CREDENTIALS_FILEPATH) && ($xml = trim(file_get_contents(DB_CREDENTIALS_FILEPATH)))) { $xml_parse = new XMLParser($xml); $parse = $xml_parse->Parse(); if (isset($xml_parse->document->database)) { foreach ($xml_parse->document->database as $database) { $tmp = array(); $db_conn_name = isset($database->connection_name[0]->tagData) ? $database->connection_name[0]->tagData : false; $tmp['db'] = isset($database->db[0]->tagData) ? $database->db[0]->tagData : false; $tmp['user'] = isset($database->user[0]->tagData) ? $database->user[0]->tagData : false; $tmp['password'] = isset($database->password[0]->tagData) ? $database->password[0]->tagData : false; $tmp['host'] = isset($database->host[0]->tagData) ? $database->host[0]->tagData : false; if ($db_conn_name && $tmp['db'] !== false && $tmp['user'] !== false && $tmp['password'] !== false && $tmp['host'] !== false) { $db_info[$db_conn_name] = $tmp; } else { $invalid_entries[] = $db_conn_name; } } } if (isset($invalid_entries)) { $invalid_str = $invalid_entries == 1 ? $invalid_entries . ' entry appears' : $invalid_entries . ' entries appear'; turn_carl_util_error_context_off(); foreach ($invalid_entries as $conn_name) { if (!empty($conn_name)) { trigger_error('The connection ' . $conn_name . ' in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ') appears to have missing or invalid values.', WARNING); } else { trigger_error('An entry without a connection name is defined in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ')', WARNING); } } turn_carl_util_error_context_on(); } if (empty($db_info)) { trigger_error('Check the xml in the db credentials XML file (' . DB_CREDENTIALS_FILEPATH . ') - no valid database connection information could be built.', WARNING); } } else { trigger_fatal_error('The DB_CREDENTIALS_FILEPATH (' . DB_CREDENTIALS_FILEPATH . ') refers to a file that is missing or does not have any content.'); } } // if this was the first time, the code above should have run successfully so db_info is populated. // if this is not the first time, then the code above should have been skipped since it was populated the first // run of the function. if (isset($db_info[$conn_name])) { return $db_info[$conn_name]; } else { // disable context display so we do not show passwords on screen. turn_carl_util_error_context_off(); if ($lack_of_creds_is_fatal) { trigger_fatal_error('Unable to use database connection ' . $conn_name . ' - No credential information found for the connection named ' . $conn_name . ' in database credential file (' . DB_CREDENTIALS_FILEPATH . ').', 2); } else { trigger_warning('Unable to use database connection ' . $conn_name . ' - No credential information found for the connection named ' . $conn_name . ' in database credential file (' . DB_CREDENTIALS_FILEPATH . ').', 2); } turn_carl_util_error_context_on(); } return false; }
/** * Gets information about a specific file, whether it was uploaded in the POST * body of the current request or in the asynchronous upload session identified * by the given ID. * * If no such file was received, if an empty file was received, or if there was * an error in receiving or storing the file or if it was rejected by PHP, * <code>null</code> will be returned. * * If an asynchronous upload session ID is given, but no session with that ID * actually exists, a notice is triggered. * * @param string $name the form field name under which the file was submitted * @param string $async_session_id the ID for the asynchronous upload session * @param boolean $clear if true, and the uploaded file is found in the * asynchronous session, the file's record will be removed from the * session * @return UploadedFile information about the uploaded file, or * <code>null</code> if no such file was uploaded or if there was an * error in uploading it */ function reason_get_uploaded_file($name, $async_session_id = null, $clear = false) { if ($async_session_id) { $async_session = _get_async_upload_session($async_session_id); if ($async_session) { if (isset($async_session['files'][$name])) { $records = $async_session['files'][$name]; if (is_array($records) && count($records) > 0) { $keys = array_keys($records); $key = $keys[count($keys) - 1]; $async_file = $records[$key]; $file = _uploaded_file_from_async($async_file); if (!$file || $clear) { unset($async_session['files'][$name][$key]); $session =& get_reason_session(); $id = $async_session_id; $session->set(_async_upload_session_key($id), $async_session); } if ($file) { return $file; } } } } else { trigger_warning("tried to get the file {$name} from asynchronous " . 'upload session ' . var_export($async_session_id, true) . ', but ' . 'no such session exists'); } } return isset($_FILES[$name]) ? _uploaded_file_from_php($_FILES[$name]) : null; }