Permalink
Browse files

Made template selectible from webinterface

Made several changes to the templating system
- Removed the ICONSET setting from config.inc.php
- Removed the int.css from the webinterface
- Replaced both by int.template setting
- Zoph now discovers which templates there are in the templates
directory
- Images and icons have been moved inside the template directory
- Zoph finds out if a template has an icon, image or css file and falls
back to the "default" template if it has not. (other template file not
yet)
- made some changes to the language class so the CLI could find them as
well

#28
#8
  • Loading branch information...
1 parent f1a2586 commit 9c8dda562f699be18cf214d89e2be4176e1eb32d @jeroenrnl committed Dec 7, 2012
Showing with 2,013 additions and 1,903 deletions.
  1. +1 −0 lang/zoph_strings.txt
  2. +2 −2 php/admin.inc.php
  3. +7 −8 php/classes/conf.inc.php
  4. +11 −13 php/classes/language.inc.php
  5. +62 −8 php/{ → classes}/template.inc.php
  6. +1 −1 php/code.inc.php
  7. +1 −1 php/config.inc.php
  8. +6 −1,827 php/css.php
  9. +25 −1 php/header.inc.php
  10. BIN php/images/icons/default/remove.png
  11. BIN php/images/mailaddr.png
  12. +0 −1 php/include.inc.php
  13. +1 −1 php/info.php
  14. +2 −2 php/js/autocomplete.js
  15. +2 −4 php/js/import.js
  16. +1 −1 php/js/maps.js
  17. +1 −10 php/js/thumbview.js
  18. +4 −4 php/js/xml.js
  19. +1 −1 php/logon.php
  20. +1 −1 php/photo.inc.php
  21. +14 −4 php/photos.php
  22. +1 −1 php/place.inc.php
  23. +6 −1 php/settings.inc.php
  24. +1 −1 php/slideshow.php
  25. +1 −1 php/templates/default/admin.tpl.php
  26. +1 −1 php/templates/default/blocks/map.tpl.php
  27. +1,852 −0 php/templates/default/css.php
  28. BIN php/{ → templates/default}/images/down1.gif
  29. BIN php/{ → templates/default}/images/down2.gif
  30. BIN php/{images/icons/default → templates/default/images/icons}/1downarrow.png
  31. BIN php/{images/icons/default → templates/default/images/icons}/1rightarrow.png
  32. BIN php/{images/icons/default → templates/default/images/icons}/archive.png
  33. BIN php/{images/icons/default → templates/default/images/icons}/configure.png
  34. +1 −1 php/{images/icons/default → templates/default/images/icons}/credits.txt
  35. BIN php/{images/icons/default → templates/default/images/icons}/date.png
  36. BIN php/{images/icons/default → templates/default/images/icons}/error.png
  37. BIN php/{images/icons/default → templates/default/images/icons}/folder.png
  38. BIN php/{images/icons/default → templates/default/images/icons}/geo-photo.png
  39. BIN php/{images/icons/default → templates/default/images/icons}/geo-place.png
  40. BIN php/{images/icons/default → templates/default/images/icons}/groups.png
  41. BIN php/{images/icons/default → templates/default/images/icons}/html.png
  42. BIN php/{images/icons/default → templates/default/images/icons}/link.png
  43. BIN php/{images/icons/default → templates/default/images/icons}/modified.png
  44. BIN php/{images/icons/default → templates/default/images/icons}/pages.png
  45. BIN php/{images/icons/default → templates/default/images/icons}/pagesets.png
  46. BIN php/{images/icons/default → templates/default/images/icons}/pause.png
  47. BIN php/{images/icons/default → templates/default/images/icons}/photo.png
  48. BIN php/{images/icons/default → templates/default/images/icons}/rating.png
  49. BIN php/templates/default/images/icons/remove.png
  50. BIN php/{images/icons/default → templates/default/images/icons}/resize.png
  51. BIN php/{images/icons/default → templates/default/images/icons}/share-icon-24x24.png
  52. BIN php/{images/icons/default → templates/default/images/icons}/tracks.png
  53. BIN php/{images/icons/default → templates/default/images/icons}/unpack.png
  54. BIN php/{images/icons/default → templates/default/images/icons}/users.png
  55. BIN php/{images/icons/default → templates/default/images/icons}/warning.png
  56. BIN php/templates/default/images/mailaddr.png
  57. BIN php/{ → templates/default}/images/pleasewait.gif
  58. BIN php/{ → templates/default}/images/smileys/icon_arrow.gif
  59. BIN php/{ → templates/default}/images/smileys/icon_biggrin.gif
  60. BIN php/{ → templates/default}/images/smileys/icon_confused.gif
  61. BIN php/{ → templates/default}/images/smileys/icon_cool.gif
  62. BIN php/{ → templates/default}/images/smileys/icon_cry.gif
  63. BIN php/{ → templates/default}/images/smileys/icon_eek.gif
  64. BIN php/{ → templates/default}/images/smileys/icon_evil.gif
  65. BIN php/{ → templates/default}/images/smileys/icon_exclaim.gif
  66. BIN php/{ → templates/default}/images/smileys/icon_frown.gif
  67. BIN php/{ → templates/default}/images/smileys/icon_idea.gif
  68. BIN php/{ → templates/default}/images/smileys/icon_lol.gif
  69. BIN php/{ → templates/default}/images/smileys/icon_mad.gif
  70. BIN php/{ → templates/default}/images/smileys/icon_mrgreen.gif
  71. BIN php/{ → templates/default}/images/smileys/icon_neutral.gif
  72. BIN php/{ → templates/default}/images/smileys/icon_question.gif
  73. BIN php/{ → templates/default}/images/smileys/icon_razz.gif
  74. BIN php/{ → templates/default}/images/smileys/icon_redface.gif
  75. BIN php/{ → templates/default}/images/smileys/icon_rolleyes.gif
  76. BIN php/{ → templates/default}/images/smileys/icon_sad.gif
  77. BIN php/{ → templates/default}/images/smileys/icon_smile.gif
  78. BIN php/{ → templates/default}/images/smileys/icon_surprised.gif
  79. BIN php/{ → templates/default}/images/smileys/icon_twisted.gif
  80. BIN php/{ → templates/default}/images/smileys/icon_wink.gif
  81. BIN php/{ → templates/default}/images/up1.gif
  82. BIN php/{ → templates/default}/images/up2.gif
  83. +1 −1 php/templates/default/import.tpl.php
  84. +1 −1 php/templates/default/photo_share.tpl.php
  85. +1 −1 php/util.inc.php
  86. +4 −4 php/webimport.inc.php
View
@@ -211,6 +211,7 @@ These options are always available in the tabs on the upper right. Use the %s ho
This feature is not available because the photo was not found.=
This may also be caused by the max_post_size (%s) in php.ini.=
This page is used in the following pagesets:=
+This page needs Javascript switched on and will not function without it.=
This photo is not in any albums.=
This photo is not in any categories.=
Thumbnails=
View
@@ -37,13 +37,13 @@ class admin {
* @param string Name
* @param string Description
* @param string URL to point to
- * @param string Icon file (only <filename>.png, no path)
+ * @param string Icon name (only <filename>.png, no path)
*/
function __construct($name, $desc, $url, $icon) {
$this->name=$name;
$this->url=$url;
$this->desc=$desc;
- $this->icon=ICONSET . "/" . $icon;
+ $this->icon=template::getImage("icons/" . $icon);
}
/**
View
@@ -60,7 +60,6 @@ public static function loadFromDB() {
echo $e->getMessage();
$sql="DELETE FROM " . DB_PREFIX . "conf WHERE " .
"conf_id='" . escape_string($key) . "';";
- echo $sql;
query($sql);
}
@@ -180,13 +179,13 @@ private static function getDefault() {
$int_width->setRegex("^[0-9]+(px|%)$");
$interface[]=$int_width;
- $int_css = new confItemString();
- $int_css->setName("interface.css");
- $int_css->setLabel("Style Sheet");
- $int_css->setDesc("The CSS file Zoph uses");
- $int_css->setDefault("css.php");
- $int_css->setRegex("^[A-Za-z0-9_\.]+$");
- $interface[]=$int_css;
+ $int_tpl = new confItemSelect();
+ $int_tpl->setName("interface.template");
+ $int_tpl->setLabel("Template");
+ $int_tpl->setDesc("The template Zoph uses");
+ $int_tpl->addOptions(template::getAll());
+ $int_tpl->setDefault("default");
+ $interface[]=$int_tpl;
$int_share = new confItemBool();
$int_share->setName("interface.share");
@@ -145,29 +145,27 @@ function translate($string, $error = true) {
*/
public static function getAll() {
$langs=array();
- if(is_dir(self::LANG_DIR) && is_readable(self::LANG_DIR)) {
- $handle=opendir(self::LANG_DIR);
- while ($filename = trim(readdir($handle))) {
- if(!is_dir(self::LANG_DIR . "/" . $filename)) {
- if(is_readable(strtolower(self::LANG_DIR . "/" . $filename))) {
+ $dir=settings::$php_loc . "/" . self::LANG_DIR;
+ if(is_dir($dir) && is_readable($dir)) {
+ foreach(glob($dir . "/*") as $filename) {
+ if(!is_dir($filename) && is_readable($filename)) {
+ $iso=basename($filename);
+ if($iso == strtolower($iso)) {
# making filename lowercase, so we won't include
# any capitalized filenames... Zoph will not able
# to find them back later...
# is isocode nl file NL Nl or nl?
- $lang=new language($filename);
+ $lang=new language($iso);
if($lang->readHeader()) {
- $langs[$filename]=$lang;
+ $langs[$iso]=$lang;
}
} else {
- if($filename == strtolower($filename)) {
- log::msg("Cannot read <b>" . $filename . "</b>, skipping. ", log::ERROR, log::LANG);
- } else {
- log::msg("Language files should have lowercase names, cannot open <b>" . $filename . "</b>", log::WARN, log::LANG);
- }
+ log::msg("Language files should have lowercase names, cannot open <b>" . $filename . "</b>", log::WARN, log::LANG);
}
+ } else {
+ log::msg("Cannot read <b>" . $filename . "</b>, skipping. ", log::ERROR, log::LANG);
}
}
- closedir($handle);
} else {
log::msg("Cannot read language dir!", log::WARN, log::LANG);
}
@@ -49,12 +49,38 @@ class template {
* @return template
*/
public function __construct($template, $vars=null) {
- $this->css[]=conf::get("interface.css");
+ $tpl=conf::get("interface.template");
$this->vars=$vars;
- if(!preg_match("/^[A-Za-z0-9_]+$/", $template)) {
- log::msg("Illegal characters in template", log::FATAL, log::GENERAL);
+ if(preg_match("/^[A-Za-z0-9_\-]+$/", $tpl) && preg_match("/^[A-Za-z0-9_\-]+$/", $template)) {
+ $file="templates/" . $tpl . "/" . $template . ".tpl.php";
+ if(!file_exists($file)) {
+ $file="templates/default/" . $template . ".tpl.php";
+ }
+ $this->template=$file;
+
+ $this->css[]="css.php";
} else {
- $this->template="templates/default/" . $template . ".tpl.php";
+ log::msg("Illegal characters in template", log::FATAL, log::GENERAL);
+ }
+ }
+ /**
+ * Get image URL for specific template
+ * if the image does not exist in the current template, the default will be be returned
+ * This enables template builders to only include the parts of the template that
+ * have been changed
+ * @param string image name
+ * @return string relative image url
+ */
+ public static function getImage($image) {
+ $tpl=conf::get("interface.template");
+ if(preg_match("/^[A-Za-z0-9_\-\/\.]+$/", $image) && !preg_match("/\.\./", $image)) {
+ $file="templates/" . $tpl . "/images/" . $image;
+ if(!file_exists($file)) {
+ $file="templates/default/images/" . $image;
+ }
+ return $file;
+ } else {
+ log::msg("Illegal characters in icon name", log::FATAL, log::GENERAL);
}
}
@@ -127,19 +153,24 @@ private function getHead() {
/**
* Add a block
+ * @param block Block to be added
*/
public function addBlock(block $block) {
$this->blocks[]=$block;
}
/**
- * Get an array of blocks
+ * Get the blocks inside this template
+ * @return array blocks
*/
-
protected function getBlocks() {
return $this->blocks;
}
+ /**
+ * Display the blocks inside this template
+ * @return string HTML code for the blocks
+ */
protected function displayBlocks() {
$html="";
foreach($this->getBlocks() as $block) {
@@ -151,13 +182,16 @@ protected function displayBlocks() {
/**
* Add an actionlink
+ * @param string Title to be displayed
+ * @param string URL
*/
public function addActionlink($title, $link) {
$this->actionlinks[$title]=$link;
}
/**
* Add multiple actionlinks
+ * @param array of actionlinks
*/
public function addActionlinks(array $al) {
foreach($al as $title => $link) {
@@ -167,6 +201,7 @@ public function addActionlinks(array $al) {
/**
* Markup an array of actionlinks using the actionlinks template
+ * @param array Optional array of actionlinks, otherwise use the ones in the class
*/
private function getActionlinks(array $actionlinks=null) {
if($actionlinks==null) {
@@ -184,8 +219,12 @@ private function getActionlinks(array $actionlinks=null) {
* Create a link list
* Creates a comma separated list of links from the given records.
* The class of the records must implement the getLink function.
+ * @param array Array of records to be displayed
+ * @return string Comma separated links to records
+ * @todo Could maybe better move into zophTable?
+ * @todo Should check whether the object is of a supported class
*/
- public static function createLinkList($records) {
+ public static function createLinkList(array $records) {
$links = "";
if ($records) {
foreach ($records as $rec) {
@@ -201,8 +240,11 @@ public static function createLinkList($records) {
* Creates an array to be used in the create_pulldown methods. The
* values of the fields in the name_fields parameter are concatentated
* together to construnct the titles of the selections.
+ * @param array Records to be processed
+ * @param array fields to use to contruct title
+ * @return array Array that can be fed to the create_pulldown methods.
*/
- public static function createSelectArray($records, $name_fields) {
+ public static function createSelectArray(array $records, array $name_fields) {
if (!$records || !$name_fields) { return; }
foreach ($records as $rec) {
@@ -221,4 +263,16 @@ public static function createSelectArray($records, $name_fields) {
return $sa;
}
+ /**
+ * Get all templates
+ * Search the template directory for directory entries
+ */
+ public static function getAll() {
+ $templates=array();
+ foreach(glob(settings::$php_loc . "/templates/*", GLOB_ONLYDIR) as $tpl) {
+ $tpl=basename($tpl);
+ $templates[$tpl]=$tpl;
+ }
+ return $templates;
+ }
}
View
@@ -158,7 +158,7 @@ private static function createArray() {
* @todo contains HTML
*/
public function __toString() {
- return "<img src=\"images/smileys/" . $this->file ."\" alt=\"" . $this->description . "\">";
+ return "<img src=\"" . template::getImage("smileys/" . $this->file) . "\" alt=\"" . $this->description . "\">";
}
/**
View
@@ -26,7 +26,7 @@
// Define how Zoph looks by choosing a stylesheet and iconset.
// Deprecated: Modify through admin -> config in web interface.
//define('CSS_SHEET', 'css.php');
- define('ICONSET', 'default');
+ //define('ICONSET', 'default');
// Deprecated: Modify through admin -> config in web interface.
//define('IMAGE_DIR', "/data/images/");
Oops, something went wrong.

0 comments on commit 9c8dda5

Please sign in to comment.