/**
* 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);
}
Ejemplo n.º 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;
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
	/**
	* 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;
	}
 function main($id, $mode)
 {
     global $db, $config, $user, $cache, $template, $request, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $phpbb_container, $phpbb_dispatcher;
     $this->page_title = $user->lang['ACP_CRON_STATUS_TITLE'];
     $this->tpl_name = 'acp_cronstatus';
     $user->add_lang_ext('boardtools/cronstatus', 'cronstatus');
     list($sk_config, $sd_config) = explode("|", $config['cronstatus_default_sort']);
     $sk = $request->variable('sk', $sk_config);
     $sd = $request->variable('sd', $sd_config);
     if ($sk != $sk_config || $sd != $sd_config) {
         $config->set("cronstatus_default_sort", $sk . "|" . $sd);
     }
     $action = $request->variable('action', '');
     switch ($action) {
         case 'details':
             $user->add_lang(array('install', 'acp/extensions', 'migrator'));
             $ext_name = 'boardtools/cronstatus';
             $md_manager = new \phpbb\extension\metadata_manager($ext_name, $config, $phpbb_extension_manager, $template, $user, $phpbb_root_path);
             try {
                 $this->metadata = $md_manager->get_metadata('all');
             } catch (\phpbb\extension\exception $e) {
                 trigger_error($e, E_USER_WARNING);
             }
             $md_manager->output_template_data();
             try {
                 $updates_available = $this->version_check($md_manager, $request->variable('versioncheck_force', false));
                 $template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name'))));
                 foreach ($updates_available as $branch => $version_data) {
                     $template->assign_block_vars('updates_available', $version_data);
                 }
             } catch (\RuntimeException $e) {
                 $template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
             }
             if ($request->is_ajax()) {
                 $template->assign_vars(array('IS_AJAX' => true));
             } else {
                 $template->assign_vars(array('U_BACK' => $this->u_action));
             }
             $this->tpl_name = 'acp_ext_details';
             break;
         default:
             $view_table = $request->variable('table', false);
             $cron_type = $request->variable('cron_type', '');
             if (!$request->is_ajax() && $cron_type) {
                 $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $cron_type);
                 $template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="" />');
                 meta_refresh(60, $this->u_action . '&amp;sk=' . $sk . '&amp;sd=' . $sd);
             }
             $tasks = $task_array = array();
             $tasks = $phpbb_container->get('cron.manager')->get_tasks();
             $cronlock = '';
             $rows = $phpbb_container->get('boardtools.cronstatus.listener')->get_cron_tasks($cronlock);
             if (sizeof($tasks) && is_array($rows)) {
                 foreach ($tasks as $task) {
                     $task_name = $task->get_name();
                     if (empty($task_name)) {
                         continue;
                     }
                     $task_date = -1;
                     $find = strpos($task_name, 'tidy');
                     if ($find !== false) {
                         $name = substr($task_name, $find + 5);
                         $name = $name == 'sessions' ? 'session' : $name;
                         $task_date = (int) $this->array_find($name . '_last_gc', $rows);
                     } else {
                         if (strpos($task_name, 'prune_notifications')) {
                             $task_date = (int) $this->array_find('read_notification_last_gc', $rows);
                             $name = 'read_notification';
                         } else {
                             if (strpos($task_name, 'queue')) {
                                 $task_date = (int) $this->array_find('last_queue_run', $rows);
                                 $name = 'queue_interval';
                             } else {
                                 $name = strrpos($task_name, ".") !== false ? substr($task_name, strrpos($task_name, ".") + 1) : $task_name;
                                 $task_last_gc = $this->array_find($name . '_last_gc', $rows);
                                 $task_date = $task_last_gc !== false ? (int) $task_last_gc : -1;
                             }
                         }
                     }
                     $new_task_interval = $task_date > 0 ? $this->array_find($name . ($name != 'queue_interval' ? '_gc' : ''), $rows) : 0;
                     $new_task_date = $new_task_interval > 0 ? $task_date + $new_task_interval : 0;
                     /**
                      * Event to modify task variables before displaying cron information
                      *
                      * @event boardtools.cronstatus.modify_cron_task
                      * @var	object	task			Task object
                      * @var	object	task_name		Task name ($task->get_name())
                      * @var	object	name			Task name for new task date
                      * @var	object	task_date		Last task date
                      * @var	object	new_task_date	Next task date
                      * @since 3.1.0-RC3
                      * @changed 3.1.1 Added new_task_date variable
                      */
                     $vars = array('task', 'task_name', 'name', 'task_date', 'new_task_date');
                     extract($phpbb_dispatcher->trigger_event('boardtools.cronstatus.modify_cron_task', compact($vars)));
                     $task_array[] = array('task_sort' => $task->is_ready() ? 'ready' : 'not_ready', 'display_name' => $task_name, 'task_date' => $task_date, 'task_date_print' => $task_date == -1 ? $user->lang['CRON_TASK_AUTO'] : ($task_date ? $user->format_date($task_date, $config['cronstatus_dateformat']) : $user->lang['CRON_TASK_NEVER_STARTED']), 'new_date' => $new_task_date, 'new_date_print' => $new_task_date > 0 ? $user->format_date($new_task_date, $config['cronstatus_dateformat']) : '-', 'task_ok' => $task_date > 0 && $new_task_date > time() ? false : true, 'locked' => $config['cron_lock'] && $cronlock == $name ? true : false);
                 }
                 unset($tasks, $rows);
                 $task_array = $this->array_sort($task_array, $sk, $sd == 'a' ? SORT_ASC : SORT_DESC);
                 foreach ($task_array as $row) {
                     $template->assign_block_vars($row['task_sort'], array('DISPLAY_NAME' => $row['display_name'], 'TASK_DATE' => $row['task_date_print'], 'NEW_DATE' => $row['new_date_print'], 'TASK_OK' => $row['task_ok'], 'LOCKED' => $row['locked'], 'CRON_TASK_RUN' => $request->is_ajax() ? '' : ($row['display_name'] != $cron_type ? '<a href="' . $this->u_action . '&amp;cron_type=' . $row['display_name'] . '&amp;sk=' . $sk . '&amp;sd=' . $sd . '" class="cron_run_link">' . $user->lang['CRON_TASK_RUN'] . '</a>' : '<span class="cron_running_update">' . $user->lang['CRON_TASK_RUNNING'] . '</span>')));
                 }
             }
             $cron_url = append_sid($phpbb_root_path . 'cron.' . $phpEx, false, false);
             // This is used in JavaScript (no &amp;).
             $type_cast_helper = new \phpbb\request\type_cast_helper();
             // We need to use a special class because addslashes() is thought to be not valid by EPV.
             $type_cast_helper->addslashes_recursively($cron_url);
             $template->assign_vars(array('U_ACTION' => $this->u_action, 'U_NAME' => $sk, 'U_SORT' => $sd, 'CRON_URL' => $cron_url, 'VIEW_TABLE' => $view_table));
     }
 }