/**
* Casts a variable to the given type.
*
* @deprecated
*/
function set_var(&$result, $var, $type, $multibyte = false)
{
    // no need for dependency injection here, if you have the object, call the method yourself!
    $type_cast_helper = new \phpbb\request\type_cast_helper();
    $type_cast_helper->set_var($result, $var, $type, $multibyte);
}
Exemple #2
0
 public function escape($var, $multibyte)
 {
     $type_cast_helper = new \phpbb\request\type_cast_helper();
     if (is_array($var)) {
         $result = array();
         foreach ($var as $key => $value) {
             $type_cast_helper->set_var($key, $key, gettype($key), $multibyte);
             $result[$key] = $this->escape($value, $multibyte);
         }
         $var = $result;
     } else {
         $type_cast_helper->set_var($var, $var, 'string', $multibyte);
     }
     return $var;
 }
Exemple #3
0
 /**
  * Gets languages in the specified directory.
  * @param string $path   The path to the language directory without slash at the end.
  * @return array
  */
 public static function get_languages($path)
 {
     $return = array();
     if (@is_dir($path)) {
         $files = @scandir($path);
         if ($files === false) {
             return $return;
         }
         $type_cast_helper = new \phpbb\request\type_cast_helper();
         foreach ($files as $file) {
             if ($file != '.' && $file != '..' && @is_dir($path . '/' . $file)) {
                 $type_cast_helper->set_var($file, $file, gettype($file), true);
                 $return[] = $file;
             }
         }
     }
     return $return;
 }
Exemple #4
0
 /**
  * @dataProvider clean_filename_variables
  */
 public function test_uploadname($filename)
 {
     $type_cast_helper = new \phpbb\request\type_cast_helper();
     $upload_name = '';
     $type_cast_helper->set_var($upload_name, $filename, 'string', true, true);
     $filespec = $this->get_filespec(array('name' => $upload_name));
     $this->assertSame(trim(utf8_basename(htmlspecialchars($filename))), $filespec->uploadname);
 }
	/**
	* 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 (\RuntimeException $exception)
			{
				throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage()));
			}
			$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 \phpbb\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;
	}