PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/PNphpBB2/includes/functions_styles.php

https://gitlab.com/bulwye/reliquerunt
PHP | 324 lines | 212 code | 50 blank | 62 comment | 25 complexity | 1f3e907ee073d61c710abd59d20af9ae MD5 | raw file
  1. <?php
  2. /***************************************************************************
  3. * Module : PNphpBB2 (The forum for Postnuke)
  4. * Filename : functions_styles.php
  5. * Begin : June, 2004
  6. * Original file by : Carl Slaughter
  7. * Copyright : (C) 2003 The PNphpBB Group
  8. * Contact : support@pnphpbb.com
  9. * : http://www.pnphpbb.com
  10. *
  11. * $Id: functions_styles.php,v 1.6 2004/10/18 19:47:28 carls Exp $
  12. *
  13. ***************************************************************************/
  14. /***************************************************************************
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. ***************************************************************************/
  22. if ( !defined('IN_PHPBB') )
  23. {
  24. die("Hacking attempt");
  25. }
  26. function create_cellpic($img, $filename)
  27. {
  28. // Does the file exist?
  29. if ( @is_file($filename) )
  30. { // We need to delete it
  31. $succ = @unlink($filename);
  32. if (!$succ) { return false; }
  33. }
  34. // Create the new file
  35. $succ = @imagejpeg($img, $filename);
  36. if (!$succ) { return false; }
  37. // Make it so admins can delete the files ;-)
  38. $succ = @chmod($filename, 0666);
  39. if (!$succ) { return false; }
  40. // Destroy the image
  41. @imagedestroy($img);
  42. return true;
  43. }
  44. function colorchange($color, $step)
  45. {
  46. // This function takes a color passed to $color and creates
  47. // two new "shades" of the same color based on the $step value.
  48. // It returns the value of $colors in 5 elements:
  49. // 0 = ready to use hex value of a lighter shade of original $color
  50. // 1 = ready to use hex value of a darker shade of original $color
  51. // 2 = Array containing RGB of a lighter shade of original $color
  52. // 3 = Array containing RGB of original $color
  53. // 4 = Array containing RGB of a darker shade of original $color
  54. $rd = hexdec(substr($color, 1, 2));
  55. $bl = hexdec(substr($color, 3, 2));
  56. $gn = hexdec(substr($color, 5, 2));
  57. $med[0] = $rd;
  58. $med[1] = $bl;
  59. $med[2] = $gn;
  60. $lit[0] = ( $rd + $step ) > 255 ? 255 : $rd + $step;
  61. $lit[1] = ( $bl + $step ) > 255 ? 255 : $bl + $step;
  62. $lit[2] = ( $gn + $step ) > 255 ? 255 : $gn + $step;
  63. $dar[0] = ( $rd - $step ) < 0 ? 0 : $rd - $step;
  64. $dar[1] = ( $bl - $step ) < 0 ? 0 : $bl - $step;
  65. $dar[2] = ( $gn - $step ) < 0 ? 0 : $gn - $step;
  66. $colors[0] = "#" . dechex(($lit[0]<<16)|($lit[1]<<8)|$lit[2]);
  67. $colors[1] = "#" . dechex(($dar[0]<<16)|($dar[1]<<8)|$dar[2]);
  68. $colors[2] = $lit;
  69. $colors[3] = $med;
  70. $colors[4] = $dar;
  71. return $colors;
  72. }
  73. function imagecolorgradient($img, $hv, $x1, $y1, $x2, $y2, $f_c, $s_c)
  74. {
  75. // Modified version of code by info@solanki.ch taken from php.net
  76. // posted: 14-Feb-2004 07:43
  77. // $img is the image handle.
  78. // $hv is either horizontal 'h' or vertical 'v' gradient.
  79. // $x1 and $y1 are the start points.
  80. // $x2 and $y2 the ending points.
  81. // $f_c and $s_c are the first and second color ARRAYs.
  82. $y = ($y2 > $y1) ? $y2-$y1 : $y1-$y2;
  83. $x = ($x2 > $x1) ? $x2-$x1 : $x1-$x2;
  84. $r_range = ($f_c[0] > $s_c[0]) ? $f_c[0] - $s_c[0] : $s_c[0] - $f_c[0];
  85. $g_range = ($f_c[1] > $s_c[1]) ? $f_c[1] - $s_c[1] : $s_c[1] - $f_c[1];
  86. $b_range = ($f_c[2] > $s_c[2]) ? $f_c[2] - $s_c[2] : $s_c[2] - $f_c[2];
  87. switch ($hv)
  88. {
  89. case 'v':
  90. $r_px = $r_range / $y;
  91. $g_px = $g_range / $y;
  92. $b_px = $b_range / $y;
  93. $xy = $y;
  94. break;
  95. default:
  96. $r_px = $r_range / $x;
  97. $g_px = $g_range / $x;
  98. $b_px = $b_range / $x;
  99. $xy = $x;
  100. break;
  101. }
  102. $r = $f_c[0];
  103. $g = $f_c[1];
  104. $b = $f_c[2];
  105. for($i = 0;$i <= $xy;$i++)
  106. {
  107. $col = imagecolorallocate($img, round($r), round($g), round($b));
  108. if ($hv == 'v')
  109. {
  110. imageline($img, $x1, $y1+$i, $x2, $y1+$i, $col);
  111. }
  112. else
  113. {
  114. imageline($img, $x1+$i, $y1, $x1+$i, $y2, $col);
  115. }
  116. $r = ($f_c[0] < $s_c[0]) ? $r + $r_px : $r - $r_px;
  117. $g = ($f_c[1] < $s_c[1]) ? $g + $g_px : $g - $g_px;
  118. $b = ($f_c[2] < $s_c[2]) ? $b + $b_px : $b - $b_px;
  119. }
  120. return $img;
  121. }
  122. function create_css ( $stylesheet, $theme_name )
  123. {
  124. global $board_config, $lang;
  125. $stylesheet->set_filenames(array(
  126. 'body' => 'default_style.tpl'
  127. )
  128. );
  129. // is this a Xanthia theme?
  130. if ( @$GLOBALS['xanthia_theme'] )
  131. {
  132. // Yes!
  133. // get the theme id
  134. $skinID = pnModAPIFunc('Xanthia','user','getSkinID', array('skin' => $theme_name));
  135. // check which palette to use
  136. $paletteid = pnModGetVar('Xanthia',''.$theme_name.'use');
  137. // get the color scheme
  138. $colors = pnModAPIFunc('Xanthia','user','getSkinColors',
  139. array('skinid' => $skinID,
  140. 'paletteid' => $paletteid));
  141. // Get colors
  142. $colorset1 = colorchange($colors['color1'], 0x40);
  143. $colorset2 = colorchange($colors['color2'], 0x40);
  144. $colorset3 = colorchange($colors['color3'], 0x40);
  145. $colorset4 = ( $colors['color4'] ) ? colorchange($colors['color4'], 0x40) : colorchange($colors['color2'], 0x40);
  146. $colorset5 = ( $colors['color5'] ) ? colorchange($colors['color5'], 0x40) : colorchange($colors['color1'], 0x40);
  147. $stylesheet->assign_vars(array(
  148. 'CSS_THEMENAME' => $theme_name,
  149. 'CSS_BACKGROUND' => $colors['background'],
  150. 'CSS_COLOR1' => $colors['color1'],
  151. 'CSS_COLOR2' => $colors['color2'],
  152. 'CSS_COLOR3' => $colors['color3'],
  153. 'CSS_COLOR4' => $colors['color4'],
  154. 'CSS_COLOR5' => $colors['color5'],
  155. 'CSS_COLOR6' => $colors['color6'],
  156. 'CSS_COLOR7' => $colors['color7'],
  157. 'CSS_COLOR8' => $colors['color8'],
  158. 'CSS_SEPCOLOR' => $colors['sepcolor'],
  159. 'CSS_TEXT1' => $colors['text1'],
  160. 'CSS_TEXT2' => $colors['text2'],
  161. 'CSS_LINK' => $colors['link'],
  162. 'CSS_VLINK' => $colors['vlink'],
  163. 'CSS_HOVER' => $colors['hover'])
  164. );
  165. }
  166. else
  167. {
  168. // Legacy PN theme
  169. pnThemeLoad($theme_name);
  170. // Get Pn globals colors from legacy themes
  171. $colorset1 = colorchange(pnThemeGetVar('bgcolor1'), 0x40);
  172. $colorset2 = colorchange(pnThemeGetVar('bgcolor2'), 0x40);
  173. $colorset3 = colorchange(pnThemeGetVar('bgcolor3'), 0x40);
  174. $colorset4 = ( pnThemeGetVar('bgcolor4') ) ? colorchange(pnThemeGetVar('bgcolor4'), 0x40) : colorchange(pnThemeGetVar('bgcolor2'), 0x40);
  175. $colorset5 = ( pnThemeGetVar('bgcolor5') ) ? colorchange(pnThemeGetVar('bgcolor5'), 0x40) : colorchange(pnThemeGetVar('bgcolor1'), 0x40);
  176. $stylesheet->assign_vars(array(
  177. 'CSS_THEMENAME' => $theme_name,
  178. 'CSS_BACKGROUND' => pnThemeGetVar('bgcolor1'),
  179. 'CSS_COLOR1' => pnThemeGetVar('bgcolor1'),
  180. 'CSS_COLOR2' => pnThemeGetVar('bgcolor2'),
  181. 'CSS_COLOR3' => pnThemeGetVar('bgcolor3'),
  182. 'CSS_COLOR4' => pnThemeGetVar('bgcolor4'),
  183. 'CSS_COLOR5' => pnThemeGetVar('bgcolor5'),
  184. 'CSS_COLOR6' => pnThemeGetVar('bgcolor4'),
  185. 'CSS_COLOR7' => pnThemeGetVar('bgcolor3'),
  186. 'CSS_COLOR8' => pnThemeGetVar('bgcolor2'),
  187. 'CSS_SEPCOLOR' => pnThemeGetVar('bgcolor1'),
  188. 'CSS_TEXT1' => pnThemeGetVar('textcolor1'),
  189. 'CSS_TEXT2' => pnThemeGetVar('textcolor2'),
  190. 'CSS_LINK' => ( pnThemeGetVar('textcolor3') ) ? pnThemeGetVar('textcolor3') : pnThemeGetVar('textcolor1'),
  191. 'CSS_VLINK' => ( pnThemeGetVar('textcolor4') ) ? pnThemeGetVar('textcolor4') : pnThemeGetVar('textcolor2'),
  192. 'CSS_HOVER' => pnThemeGetVar('textcolor1'))
  193. );
  194. }
  195. // Build the cellpics
  196. //
  197. $cellpics_path = $board_config['template_path'] . "/cellpics/" . $theme_name;
  198. // Does the cellpic directory exist?
  199. if (!is_dir($cellpics_path))
  200. {
  201. // Nope lets create it
  202. // @umask(0);
  203. $succ = @mkdir($cellpics_path);
  204. if ($succ)
  205. {
  206. $succ = @chmod($cellpics_path, 0777);
  207. }
  208. if (!$succ) { return false; }
  209. }
  210. // Does the directory exist now?
  211. if (@is_dir($cellpics_path))
  212. {
  213. // Ok lets make the cellpics
  214. // Only if they do not already exisit
  215. // cellpic1
  216. if ( @!is_file($cellpics_path . '/cellpic1.jpg') )
  217. {
  218. $img = @imagecreatetruecolor(8, 27);
  219. $im = imagecolorgradient($img, 'v', 0, 0, 8, 27, $colorset1[3], $colorset1[2]);
  220. $succ = create_cellpic($img, $cellpics_path . '/cellpic1.jpg');
  221. if (!$succ) { return false; }
  222. }
  223. // cellpic2
  224. if ( @!is_file($cellpics_path . '/cellpic2.jpg') )
  225. {
  226. $img = @imagecreatetruecolor(300, 27);
  227. $im = imagecolorgradient($img, 'v', 0, 0, 300, 27, $colorset1[3], $colorset1[2]);
  228. $succ = create_cellpic($img, $cellpics_path . '/cellpic2.jpg');
  229. if (!$succ) { return false; }
  230. }
  231. // cellpic3
  232. if ( @!is_file($cellpics_path . '/cellpic3.jpg') )
  233. {
  234. $img = @imagecreatetruecolor(8, 38);
  235. $im = imagecolorgradient($img, 'v', 0, 0, 8, 38, $colorset4[4], $colorset4[2]);
  236. $succ = create_cellpic($img, $cellpics_path . '/cellpic3.jpg');
  237. if (!$succ) { return false; }
  238. }
  239. // cellpic4
  240. if ( @!is_file($cellpics_path . '/cellpic4.jpg') )
  241. {
  242. $img = @imagecreatetruecolor(8, 27);
  243. $im = imagecolorgradient($img, 'v', 0, 0, 8, 27, $colorset3[4], $colorset3[2]);
  244. $succ = create_cellpic($img, $cellpics_path . '/cellpic4.jpg');
  245. if (!$succ) { return false; }
  246. }
  247. // cellpic_bkg
  248. if ( @!is_file($cellpics_path . '/cellpic_bkg.jpg') )
  249. {
  250. $img = @imagecreatetruecolor(10, 80);
  251. $im = imagecolorgradient($img, 'v', 0, 0, 10, 70, $colorset5[4], $colorset5[2]);
  252. $im = imagecolorgradient($img, 'v', 0, 70, 10, 80, $colorset5[2], $colorset5[4]);
  253. $succ = create_cellpic($img, $cellpics_path . '/cellpic_bkg.jpg');
  254. if (!$succ) { return false; }
  255. }
  256. }
  257. // rmdir($board_config['template_path'] . '/cellpics/' . $theme_name);
  258. $stylesheet->assign_var_from_handle('CSS_OUTPUT', 'body');
  259. $style_name = $board_config['template_path'] . "/styles/" . $theme_name . ".css";
  260. if ( $fp = @fopen($style_name, "wb") )
  261. {
  262. $find_output = ( isset($stylesheet->vars['CSS_OUTPUT']) ) ? $stylesheet->vars['CSS_OUTPUT'] : $stylesheet->_tpldata['.'][0]['CSS_OUTPUT'];
  263. @fwrite($fp, $find_output);
  264. //echo $find_output;
  265. @fclose($fp);
  266. }
  267. else
  268. {
  269. return false;
  270. }
  271. $stylesheet->destroy;
  272. return true;
  273. }
  274. ?>