Example #1
1
 /**
  * Configures a theme to be active for the current user's session.
  */
 public function get_preview_theme()
 {
     $theme_name = $this->handler_vars['theme_name'];
     $theme_dir = $this->handler_vars['theme_dir'];
     if (isset($theme_name) && isset($theme_dir)) {
         if (Themes::get_theme_dir() == $theme_dir) {
             Themes::cancel_preview();
             Session::notice(_t("Ended the preview of the theme '%s'", array($theme_name)));
         } else {
             if (Themes::preview_theme($theme_name, $theme_dir)) {
                 Session::notice(_t("Previewing theme '%s'", array($theme_name)));
             }
         }
     }
     Utils::redirect(URL::get('admin', 'page=themes'));
 }
Example #2
0
 /**
  * get_dir returns a complete filesystem path to the requested item
  *	'config_file' returns the complete path to the config.php file, including the filename
  *	'config' returns the path of the directory containing config.php
  *	'user' returns the path of the user directory
  *	'theme' returns the path of the site's active theme
  *  'admin_theme' returns the path to the admin directory
  *  'vendor' returns the path to the vendor directory
  * @param string $name the name of the path item to return
  * @param bool|string $trail whether to include a trailing slash, or a string to use as the trailing value.  Default: false
  * @return string Path
  */
 public static function get_dir($name, $trail = false)
 {
     $path = '';
     switch (strtolower($name)) {
         case 'config_file':
             $path = Site::get_dir('config') . '/config.php';
             break;
         case 'config':
             if (self::$config_path) {
                 return self::$config_path;
             }
             self::$config_path = HABARI_PATH;
             $config_dirs = preg_replace('/^' . preg_quote(HABARI_PATH, '/') . '\\/user\\/sites\\/(.*)/', '$1', Utils::glob(HABARI_PATH . '/user/sites/*', GLOB_ONLYDIR));
             if (empty($config_dirs)) {
                 return self::$config_path;
             }
             // Collect host parts
             $server = InputFilter::parse_url(Site::get_url('habari'));
             $request = array();
             if (isset($server['port']) && $server['port'] != '' && $server['port'] != '80') {
                 $request[] = $server['port'];
             }
             $request = array_merge($request, explode('.', $server['host']));
             // Collect the subdirectory(s) the core is located in to determine the base path later
             // Don't add them to $request, they will be added with $_SERVER['REQUEST_URI']
             $basesegments = count($request);
             if (!empty($server['path'])) {
                 $coresubdir = explode('/', trim($server['path'], '/'));
                 $basesegments += count($coresubdir);
             }
             // Preserve $request without directories for fallback
             $request_base = $request;
             // Add directory part
             if (!empty(trim($_SERVER['REQUEST_URI'], '/'))) {
                 $subdirectories = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
                 $request = array_merge($request, $subdirectories);
             }
             // Now cut parts until we found a matching site directory
             $cuts = 0;
             $dir_cuts = 0;
             do {
                 $match = implode('.', $request);
                 if (in_array($match, $config_dirs)) {
                     self::$config_dir = $match;
                     self::$config_path = HABARI_PATH . '/user/sites/' . self::$config_dir;
                     self::$config_type = isset($subdirectories) && array_intersect($subdirectories, $request) == $subdirectories ? Site::CONFIG_SUBDIR : Site::CONFIG_SUBDOMAIN;
                     self::$config_urldir = implode('/', array_slice($request, $basesegments + $cuts));
                     break;
                 }
                 // Cut a part from the beginning
                 array_shift($request);
                 $cuts--;
                 // Do not fallback to only the directory part, instead, cut one and start over
                 if ($basesegments + $cuts <= 0 && isset($subdirectories) && $dir_cuts < count($subdirectories)) {
                     $cuts = 0;
                     $dir_cuts++;
                     $request = array_merge($request_base, array_slice($subdirectories, 0, count($subdirectories) - $dir_cuts));
                 }
                 // What does the following check do?!
                 if ($cuts < -10) {
                     echo $cuts;
                     var_dump($request);
                     die('too many ');
                 }
             } while (count($request) > 0);
             $path = self::$config_path;
             break;
         case 'user':
             if (Site::get_dir('config') == HABARI_PATH) {
                 $path = HABARI_PATH . '/user';
             } else {
                 $path = Site::get_dir('config');
             }
             break;
         case 'theme':
             $theme = Themes::get_theme_dir();
             if (file_exists(Site::get_dir('config') . '/themes/' . $theme)) {
                 $path = Site::get_dir('user') . '/themes/' . $theme;
             } elseif (file_exists(HABARI_PATH . '/user/themes/' . $theme)) {
                 $path = HABARI_PATH . '/user/themes/' . $theme;
             } elseif (file_exists(HABARI_PATH . '/3rdparty/themes/' . $theme)) {
                 $path = Site::get_dir('habari') . '/3rdparty/themes/' . $theme;
             } else {
                 $path = HABARI_PATH . '/system/themes/' . $theme;
             }
             break;
         case 'admin_theme':
             $path = HABARI_PATH . '/system/admin';
             break;
         case 'vendor':
             $path = HABARI_PATH . '/system/vendor';
             break;
     }
     $path .= Utils::trail($trail);
     $path = Plugins::filter('site_dir_' . $name, $path);
     return $path;
 }
Example #3
0
	/**
	 * get_dir returns a complete filesystem path to the requested item
	 *	'config_file' returns the complete path to the config.php file, including the filename
	 *	'config' returns the path of the directory containing config.php
	 *	'user' returns the path of the user directory
	 *	'theme' returns the path of the site's active theme
	 * @param string the name of the path item to return
	 * @param bool whether to include a trailing slash.  Default: No
	 * @return string Path
	 */
	public static function get_dir( $name, $trail = false )
	{
		$path = '';

		switch ( strtolower( $name ) ) {
			case 'config_file':
				$path = Site::get_dir( 'config' ) . '/config.php';
				break;
			case 'config':
				if ( self::$config_path ) {
					return self::$config_path;
				}

				self::$config_path = HABARI_PATH;

				$config_dirs = preg_replace( '/^' . preg_quote( HABARI_PATH, '/' ) . '\/user\/sites\/(.*)\/config.php/', '$1', Utils::glob( HABARI_PATH . '/user/sites/*/config.php' ) );

				if ( empty( $config_dirs ) ) {
					return self::$config_path;
				}

				$server = InputFilter::parse_url( Site::get_url( 'habari' ) );
				$server = ( isset( $server['port'] ) ) ? $server['port'] . '.' . $server['host'] . '.' : $server['host'] . '.';

				$request = explode( '/', trim( $_SERVER['REQUEST_URI'], '/' ) );
				$match = trim( $server, '.' );
				$x = count( $request );
				do {
					if ( in_array( $match, $config_dirs ) ) {
						self::$config_dir = $match;
						self::$config_path = HABARI_PATH . '/user/sites/' . self::$config_dir;
						self::$config_type = ( $x > 0 ) ? Site::CONFIG_SUBDOMAIN : Site::CONFIG_SUBDIR;
						break;
					}

					$match = MultiByte::substr( $match, MultiByte::strpos( $match, '.' ) + 1 );
					$x--;
				} while ( MultiByte::strpos( $match, '.' ) !== false );

				$path = self::$config_path;
				break;
			case 'user':
				if ( Site::get_dir( 'config' ) == HABARI_PATH ) {
					$path = HABARI_PATH . '/user';
				}
				else {
					$path = Site::get_dir( 'config' );
				}
				break;
			case 'theme':
				$theme = Themes::get_theme_dir();
				if ( file_exists( Site::get_dir( 'config' ) . '/themes/' . $theme ) ) {
					$path = Site::get_dir( 'user' ) . '/themes/' . $theme;
				}
				elseif ( file_exists( HABARI_PATH . '/user/themes/' . $theme ) ) {
					$path = HABARI_PATH . '/user/themes/' . $theme;
				}
				elseif ( file_exists( HABARI_PATH . '/3rdparty/themes/' . $theme ) ) {
					$url = Site::get_url( 'habari' ) . '/3rdparty/themes/' . $theme;
				}
				else {
					$path = HABARI_PATH . '/system/themes/' . $theme;
				}
				break;
			case 'admin_theme':
				$path = HABARI_PATH . '/system/admin';
				break;
			case 'vendor':
				$path = HABARI_PATH . '/system/vendor';
				break;
		}
		$path .= Utils::trail( $trail );
		$path = Plugins::filter( 'site_dir_' . $name, $path );
		return $path;
	}
Example #4
0
 /**
  * get_dir returns a complete filesystem path to the requested item
  *	'config_file' returns the complete path to the config.php file, including the filename
  *	'config' returns the path of the directory containing config.php
  *	'user' returns the path of the user directory
  *	'theme' returns the path of the site's active theme
  *  'admin_theme' returns the path to the admin directory
  *  'vendor' returns the path to the vendor directory
  * @param string the name of the path item to return
  * @param bool whether to include a trailing slash.  Default: No
  * @return string Path
  */
 public static function get_dir($name, $trail = false)
 {
     $path = '';
     switch (strtolower($name)) {
         case 'config_file':
             $path = Site::get_dir('config') . '/config.php';
             break;
         case 'config':
             if (self::$config_path) {
                 return self::$config_path;
             }
             self::$config_path = HABARI_PATH;
             $config_dirs = preg_replace('/^' . preg_quote(HABARI_PATH, '/') . '\\/user\\/sites\\/(.*)/', '$1', Utils::glob(HABARI_PATH . '/user/sites/*', GLOB_ONLYDIR));
             if (empty($config_dirs)) {
                 return self::$config_path;
             }
             $server = InputFilter::parse_url(Site::get_url('habari'));
             $request = array();
             if (isset($server['port']) && $server['port'] != '' && $server['port'] != '80') {
                 $request[] = $server['port'];
             }
             $request = array_merge($request, explode('.', $server['host']));
             $basesegments = count($request);
             $request = array_merge($request, explode('/', trim($_SERVER['REQUEST_URI'], '/')));
             $x = 0;
             do {
                 $match = implode('.', $request);
                 if (in_array($match, $config_dirs)) {
                     self::$config_dir = $match;
                     self::$config_path = HABARI_PATH . '/user/sites/' . self::$config_dir;
                     self::$config_type = $basesegments > count($request) ? Site::CONFIG_SUBDOMAIN : Site::CONFIG_SUBDIR;
                     self::$config_urldir = implode('/', array_slice($request, $basesegments));
                     break;
                 }
                 array_pop($request);
                 $x--;
                 if ($x < -10) {
                     echo $x;
                     var_dump($request);
                     die('too many ');
                 }
             } while (count($request) > 0);
             $path = self::$config_path;
             break;
         case 'user':
             if (Site::get_dir('config') == HABARI_PATH) {
                 $path = HABARI_PATH . '/user';
             } else {
                 $path = Site::get_dir('config');
             }
             break;
         case 'theme':
             $theme = Themes::get_theme_dir();
             if (file_exists(Site::get_dir('config') . '/themes/' . $theme)) {
                 $path = Site::get_dir('user') . '/themes/' . $theme;
             } elseif (file_exists(HABARI_PATH . '/user/themes/' . $theme)) {
                 $path = HABARI_PATH . '/user/themes/' . $theme;
             } elseif (file_exists(HABARI_PATH . '/3rdparty/themes/' . $theme)) {
                 $url = Site::get_url('habari') . '/3rdparty/themes/' . $theme;
             } else {
                 $path = HABARI_PATH . '/system/themes/' . $theme;
             }
             break;
         case 'admin_theme':
             $path = HABARI_PATH . '/system/admin';
             break;
         case 'vendor':
             $path = HABARI_PATH . '/system/vendor';
             break;
     }
     $path .= Utils::trail($trail);
     $path = Plugins::filter('site_dir_' . $name, $path);
     return $path;
 }