summaryrefslogtreecommitdiff
path: root/lib/theme.php
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-11-19 20:12:46 -0800
committerZach Copley <zach@status.net>2009-11-19 20:12:46 -0800
commit4b98edf75f4e255f8c61087bd1525d89653a521f (patch)
treeb2a7eb6d77429eadb1beabe2d5e6ae1c1a2831d6 /lib/theme.php
parentf92574dbcb1f2d7cd0aaf3c9362db46fa066e888 (diff)
parentc213477081afefb1720c8ae729d1965e7a1dac63 (diff)
Merge branch '0.9-release'
* 0.9-release: (874 commits) Removed call to NewDirectMessage() until IE return is fixed i.e., Don't show flag user button your own profile Fixed HXR response for flag user Using the right form class name Using common_redirect Left a form_data class of a <ul> in the user admin panel Added validation to fields in user admin panel Added a user admin panel Added mobile logos for default and identica themes Changed gif to png Changed this to action. THANKS zach! Doing content negotiation only once Add execute bit to pingqueuehandler Localisation updates for !StatusNet from !translatewiki.net Use the browser's geolocation API to set the location on the notice form Add geometa library, and include it. Add location form elements to the noticeform, and save their values on submission Use the $user object nickname, as login name doesnt have to == nickname anymore with plugins such as ldap/etc Revert "Re added NICKNAME_FMT constant to router.php." Moved most path and server settings to a new paths admin panel ... Conflicts: js/util.js locale/it_IT/LC_MESSAGES/statusnet.mo locale/mk_MK/LC_MESSAGES/statusnet.mo locale/mk_MK/LC_MESSAGES/statusnet.po locale/pt_BR/LC_MESSAGES/statusnet.mo locale/vi_VN/LC_MESSAGES/statusnet.mo plugins/InfiniteScroll/infinitescroll.js plugins/Realtime/realtimeupdate.js
Diffstat (limited to 'lib/theme.php')
-rw-r--r--lib/theme.php227
1 files changed, 190 insertions, 37 deletions
diff --git a/lib/theme.php b/lib/theme.php
index 08e3e8538..020ce1ac4 100644
--- a/lib/theme.php
+++ b/lib/theme.php
@@ -23,7 +23,7 @@
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
- * @copyright 2008 StatusNet, Inc.
+ * @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
@@ -33,62 +33,215 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
}
/**
- * Gets the full path of a file in a theme dir based on its relative name
+ * Class for querying and manipulating a theme
*
- * @param string $relative relative path within the theme directory
- * @param string $theme name of the theme; defaults to current theme
+ * Themes are directories with some expected sub-directories and files
+ * in them. They're found in either local/theme (for locally-installed themes)
+ * or theme/ subdir of installation dir.
*
- * @return string File path to the theme file
+ * This used to be a couple of functions, but for various reasons it's nice
+ * to have a class instead.
+ *
+ * @category Output
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
*/
-function theme_file($relative, $theme=null)
+class Theme
{
- if (empty($theme)) {
- $theme = common_config('site', 'theme');
+ var $dir = null;
+ var $path = null;
+
+ /**
+ * Constructor
+ *
+ * Determines the proper directory and path for this theme.
+ *
+ * @param string $name Name of the theme; defaults to config value
+ */
+
+ function __construct($name=null)
+ {
+ if (empty($name)) {
+ $name = common_config('site', 'theme');
+ }
+
+ // Check to see if it's in the local dir
+
+ $localroot = self::localRoot();
+
+ $fulldir = $localroot.'/'.$name;
+
+ if (file_exists($fulldir) && is_dir($fulldir)) {
+ $this->dir = $fulldir;
+ $this->path = common_path('local/theme/'.$name.'/');
+ return;
+ }
+
+ // Check to see if it's in the distribution dir
+
+ $instroot = self::installRoot();
+
+ $fulldir = $instroot.'/'.$name;
+
+ if (file_exists($fulldir) && is_dir($fulldir)) {
+
+ $this->dir = $fulldir;
+
+ $path = common_config('theme', 'path');
+
+ if (empty($path)) {
+ $path = common_config('site', 'path') . '/theme/';
+ }
+
+ if ($path[strlen($path)-1] != '/') {
+ $path .= '/';
+ }
+
+ if ($path[0] != '/') {
+ $path = '/'.$path;
+ }
+
+ $server = common_config('theme', 'server');
+
+ if (empty($server)) {
+ $server = common_config('site', 'server');
+ }
+
+ // XXX: protocol
+
+ $this->path = 'http://'.$server.$path.$name;
+ }
}
- $dir = common_config('theme', 'dir');
- if (empty($dir)) {
- $dir = INSTALLDIR.'/theme';
+
+ /**
+ * Gets the full local filename of a file in this theme.
+ *
+ * @param string $relative relative name, like 'logo.png'
+ *
+ * @return string full pathname, like /var/www/mublog/theme/default/logo.png
+ */
+
+ function getFile($relative)
+ {
+ return $this->dir.'/'.$relative;
}
- return $dir.'/'.$theme.'/'.$relative;
-}
-/**
- * Gets the full URL of a file in a theme dir based on its relative name
- *
- * @param string $relative relative path within the theme directory
- * @param string $theme name of the theme; defaults to current theme
- *
- * @return string URL of the file
- */
+ /**
+ * Gets the full HTTP url of a file in this theme
+ *
+ * @param string $relative relative name, like 'logo.png'
+ *
+ * @return string full URL, like 'http://example.com/theme/default/logo.png'
+ */
-function theme_path($relative, $theme=null)
-{
- if (empty($theme)) {
- $theme = common_config('site', 'theme');
+ function getPath($relative)
+ {
+ return $this->path.'/'.$relative;
+ }
+
+ /**
+ * Gets the full path of a file in a theme dir based on its relative name
+ *
+ * @param string $relative relative path within the theme directory
+ * @param string $name name of the theme; defaults to current theme
+ *
+ * @return string File path to the theme file
+ */
+
+ static function file($relative, $name=null)
+ {
+ $theme = new Theme($name);
+ return $theme->getFile($relative);
}
- $path = common_config('theme', 'path');
+ /**
+ * Gets the full URL of a file in a theme dir based on its relative name
+ *
+ * @param string $relative relative path within the theme directory
+ * @param string $name name of the theme; defaults to current theme
+ *
+ * @return string URL of the file
+ */
- if (empty($path)) {
- $path = common_config('site', 'path') . '/theme/';
+ static function path($relative, $name=null)
+ {
+ $theme = new Theme($name);
+ return $theme->getPath($relative);
}
- if ($path[strlen($path)-1] != '/') {
- $path .= '/';
+ /**
+ * list available theme names
+ *
+ * @return array list of available theme names
+ */
+
+ static function listAvailable()
+ {
+ $local = self::subdirsOf(self::localRoot());
+ $install = self::subdirsOf(self::installRoot());
+
+ $i = array_search('base', $install);
+
+ unset($install[$i]);
+
+ return array_merge($local, $install);
}
- if ($path[0] != '/') {
- $path = '/'.$path;
+ /**
+ * Utility for getting subdirs of a directory
+ *
+ * @param string $dir full path to directory to check
+ *
+ * @return array relative filenames of subdirs, or empty array
+ */
+
+ protected static function subdirsOf($dir)
+ {
+ $subdirs = array();
+
+ if (is_dir($dir)) {
+ if ($dh = opendir($dir)) {
+ while (($filename = readdir($dh)) !== false) {
+ if ($filename != '..' && $filename !== '.' &&
+ is_dir($dir.'/'.$filename)) {
+ $subdirs[] = $filename;
+ }
+ }
+ closedir($dh);
+ }
+ }
+
+ return $subdirs;
}
- $server = common_config('theme', 'server');
+ /**
+ * Local root dir for themes
+ *
+ * @return string local root dir for themes
+ */
- if (empty($server)) {
- $server = common_config('site', 'server');
+ protected static function localRoot()
+ {
+ return INSTALLDIR.'/local/theme';
}
- // XXX: protocol
+ /**
+ * Root dir for themes that are shipped with StatusNet
+ *
+ * @return string root dir for StatusNet themes
+ */
+
+ protected static function installRoot()
+ {
+ $instroot = common_config('theme', 'dir');
- return 'http://'.$server.$path.$theme.'/'.$relative;
+ if (empty($instroot)) {
+ $instroot = INSTALLDIR.'/theme';
+ }
+
+ return $instroot;
+ }
}