admincp_styles.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: admincp_styles.php 36353 2017-01-17 07:19:28Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
  9. exit('Access Denied');
  10. }
  11. if(!empty($_GET['preview'])) {
  12. loadcache('style_'.$_GET['styleid']);
  13. $_G['style'] = $_G['cache']['style_'.$_GET['styleid']];
  14. include template('common/preview', $_G['style']['templateid'], $_G['style']['tpldir']);
  15. exit;
  16. }
  17. require_once libfile('function/cloudaddons');
  18. $scrolltop = $_GET['scrolltop'];
  19. $anchor = $_GET['anchor'];
  20. $namenew = $_GET['namenew'];
  21. $defaultnew = $_GET['defaultnew'];
  22. $newname = $_GET['newname'];
  23. $id = $_GET['id'];
  24. $isplugindeveloper = isset($_G['config']['plugindeveloper']) && $_G['config']['plugindeveloper'] > 0;
  25. $operation = empty($operation) ? 'admin' : $operation;
  26. if($operation == 'export' && $id) {
  27. $stylearray = C::t('common_style')->fetch_by_styleid($id);
  28. if(!$stylearray) {
  29. cpheader();
  30. cpmsg('styles_export_invalid', '', 'error');
  31. }
  32. if(preg_match('/^.?\/template\/([a-z]+[a-z0-9_]*)$/', $stylearray['directory'], $a) && $a[1] != 'default') {
  33. $addonid = $a[1].'.template';
  34. }
  35. if($isplugindeveloper || !$addonid || !cloudaddons_getmd5($addonid)) {
  36. foreach(C::t('common_stylevar')->fetch_all_by_styleid($id) as $style) {
  37. $stylearray['style'][$style['variable']] = $style['substitute'];
  38. }
  39. $stylearray['version'] = strip_tags($_G['setting']['version']);
  40. exportdata('Discuz! Style', $stylearray['name'], $stylearray);
  41. } else {
  42. cpheader();
  43. cpmsg('styles_export_invalid', '', 'error');
  44. }
  45. }
  46. cpheader();
  47. $predefinedvars = array('available' => array(), 'boardimg' => array(), 'imgdir' => array(), 'styleimgdir' => array(), 'stypeid' => array(),
  48. 'headerbgcolor' => array(0, $lang['styles_edit_type_bg']),
  49. 'bgcolor' => array(0),
  50. 'sidebgcolor' => array(0, '', '#FFF sidebg.gif repeat-y 100% 0'),
  51. 'titlebgcolor' => array(0),
  52. 'headerborder' => array(1, $lang['styles_edit_type_header'], '1px'),
  53. 'headertext' => array(0),
  54. 'footertext' => array(0),
  55. 'font' => array(1, $lang['styles_edit_type_font']),
  56. 'fontsize' => array(1),
  57. 'threadtitlefont' => array(1, $lang['styles_edit_type_thread_title']),
  58. 'threadtitlefontsize' => array(1),
  59. 'smfont' => array(1),
  60. 'smfontsize' => array(1),
  61. 'tabletext' => array(0),
  62. 'midtext' => array(0),
  63. 'lighttext' => array(0),
  64. 'link' => array(0, $lang['styles_edit_type_url']),
  65. 'highlightlink' => array(0),
  66. 'lightlink' => array(0),
  67. 'wrapbg' => array(0),
  68. 'wrapbordercolor' => array(0),
  69. 'msgfontsize' => array(1, $lang['styles_edit_type_post'], '14px'),
  70. 'contentwidth' => array(1),
  71. 'contentseparate' => array(0),
  72. 'menubgcolor' => array(0, $lang['styles_edit_type_menu']),
  73. 'menutext' => array(0),
  74. 'menuhoverbgcolor' => array(0),
  75. 'menuhovertext' => array(0),
  76. 'inputborder' => array(0, $lang['styles_edit_type_input']),
  77. 'inputborderdarkcolor' => array(0),
  78. 'inputbg' => array(0, '', '#FFF'),
  79. 'dropmenuborder' => array(0, $lang['styles_edit_type_dropmenu']),
  80. 'dropmenubgcolor' => array(0),
  81. 'floatbgcolor' => array(0, $lang['styles_edit_type_float']),
  82. 'floatmaskbgcolor' => array(0),
  83. 'commonborder' => array(0, $lang['styles_edit_type_other']),
  84. 'commonbg' => array(0),
  85. 'specialborder' => array(0),
  86. 'specialbg' => array(0),
  87. 'noticetext' => array(0),
  88. );
  89. if($operation == 'admin') {
  90. $sarray = $tpldirs = $addonids = array();
  91. foreach(C::t('common_style')->fetch_all_data(true) as $row) {
  92. if(preg_match('/^.?\/template\/([a-z]+[a-z0-9_]*)$/', $row['directory'], $a) && $a[1] != 'default') {
  93. if(!in_array($a[1].'.template', $addonids)) {
  94. $addonids[$row['styleid']] = $a[1].'.template';
  95. }
  96. }
  97. $sarray[$row['styleid']] = $row;
  98. $tpldirs[] = realpath($row['directory']);
  99. }
  100. $defaultid = C::t('common_setting')->fetch('styleid');
  101. $defaultid1 = C::t('common_setting')->fetch('styleid1');
  102. $defaultid2 = C::t('common_setting')->fetch('styleid2');
  103. $defaultid3 = C::t('common_setting')->fetch('styleid3');
  104. if(!submitcheck('stylesubmit')) {
  105. $narray = array();
  106. $dir = DISCUZ_ROOT.'./template/';
  107. $templatedir = dir($dir);$i = -1;
  108. while($entry = $templatedir->read()) {
  109. $tpldir = realpath($dir.'/'.$entry);
  110. if(!in_array($entry, array('.', '..')) && !in_array($tpldir, $tpldirs) && is_dir($tpldir)) {
  111. $styleexist = 0;
  112. $searchdir = dir($tpldir);
  113. while($searchentry = $searchdir->read()) {
  114. if(substr($searchentry, 0, 13) == 'discuz_style_' && fileext($searchentry) == 'xml') {
  115. $styleexist++;
  116. }
  117. }
  118. if($styleexist) {
  119. $narray[$i] = array(
  120. 'styleid' => '',
  121. 'available' => '',
  122. 'name' => $entry,
  123. 'directory' => './template/'.$entry,
  124. 'name' => $entry,
  125. 'tplname' => $entry,
  126. 'filemtime' => @filemtime($dir.'/'.$entry),
  127. 'stylecount' => $styleexist
  128. );
  129. $i--;
  130. }
  131. }
  132. }
  133. uasort($narray, 'filemtimesort');
  134. $sarray += $narray;
  135. $stylelist = '';
  136. $i = 0;
  137. $updatestring = array();
  138. foreach($sarray as $id => $style) {
  139. $style['name'] = dhtmlspecialchars($style['name']);
  140. $isdefault = $id == $defaultid ? 'checked' : '';
  141. $isdefault1 = $id == $defaultid1 ? 'checked' : '';
  142. $isdefault2 = $id == $defaultid2 ? 'checked' : '';
  143. $isdefault3 = $id == $defaultid3 ? 'checked' : '';
  144. $mobile1exists = file_exists($style['directory'].'/mobile');
  145. $d1exists = file_exists($style['directory'].'/mobile');
  146. $d2exists = file_exists($style['directory'].'/touch');
  147. $d3exists = file_exists($style['directory'].'/wml');
  148. $available = $style['available'] ? 'checked' : NULL;
  149. $preview = file_exists($style['directory'].'/preview.jpg') ? $style['directory'].'/preview.jpg' : './static/image/admincp/stylepreview.gif';
  150. $previewlarge = file_exists($style['directory'].'/preview_large.jpg') ? $style['directory'].'/preview_large.jpg' : '';
  151. $styleicons = isset($styleicons[$id]) ? $styleicons[$id] : '';
  152. if($addonids[$style['styleid']]) {
  153. if(!isset($updatestring[$addonids[$style['styleid']]])) {
  154. $updatestring[$addonids[$style['styleid']]] = "<p id=\"update_".$addonids[$style['styleid']]."\"></p>";
  155. } else {
  156. $updatestring[$addonids[$style['styleid']]] = '';
  157. }
  158. }
  159. $stylelist .=
  160. '<table cellspacing="0" cellpadding="0" style="margin-left: 10px; width: 250px;height: 200px;" class="left"><tr><th class="partition" colspan="2">'.$style['tplname'].'</th></tr><tr><td style="width: 130px;height:170px" valign="top">'.
  161. ($id > 0 ? "<p style=\"margin-bottom: 12px;\"><img width=\"110\" height=\"120\" ".($previewlarge ? 'style="cursor:pointer" title="'.$lang['preview_large'].'" onclick="zoom(this, \''.$previewlarge.'\', 1)" ' : '')."src=\"$preview\" alt=\"$lang[preview]\"/></p>
  162. <p style=\"margin: 2px 0\"><input type=\"text\" class=\"txt\" name=\"namenew[$id]\" value=\"$style[name]\" style=\"margin:0; width: 104px;\"></p>".
  163. $updatestring[$addonids[$style['styleid']]]."</td><td valign=\"top\">
  164. <p> $lang[styles_default]</p>
  165. <p style=\"margin: 1px 0\"><label><input type=\"radio\" class=\"radio\" name=\"defaultnew\" value=\"$id\" $isdefault /> $lang[styles_default0]</label></p>
  166. ".($d1exists ? "<p style=\"margin: 1px 0\"><label><input type=\"radio\" class=\"radio\" name=\"defaultnew1\" value=\"$id\" $isdefault1 /> $lang[styles_default1]</label></p>" : "<p style=\"margin: 1px 0\" class=\"lightfont\"><label><input type=\"radio\" class=\"radio\" disabled readonly /> $lang[styles_default1]</label></p>")."
  167. ".($d2exists ? "<p style=\"margin: 1px 0\"><label><input type=\"radio\" class=\"radio\" name=\"defaultnew2\" value=\"$id\" $isdefault2 /> $lang[styles_default2]</label></p>" : "<p style=\"margin: 1px 0\" class=\"lightfont\"><label><input type=\"radio\" class=\"radio\" disabled readonly /> $lang[styles_default2]</label></p>")."
  168. ".($d3exists ? "<p style=\"margin: 1px 0\"><label><input type=\"radio\" class=\"radio\" name=\"defaultnew3\" value=\"$id\" $isdefault3 /> $lang[styles_default3]</label></p>" : "<p style=\"margin: 1px 0\" class=\"lightfont\"><label><input type=\"radio\" class=\"radio\" disabled readonly /> $lang[styles_default3]</label></p>")."
  169. <p style=\"margin: 8px 0 0 0\"><label>".($isdefault ? '<input class="checkbox" type="checkbox" disabled="disabled" />' : '<input class="checkbox" type="checkbox" name="delete[]" value="'.$id.'" />')." $lang[styles_uninstall]</label></p>
  170. <p style=\"margin: 8px 0 2px 0\"><a href=\"".ADMINSCRIPT."?action=styles&operation=edit&id=$id\">$lang[edit]</a> &nbsp;".
  171. ($isplugindeveloper || !$addonids[$id] || !cloudaddons_getmd5($addonids[$id]) ? " <a href=\"".ADMINSCRIPT."?action=styles&operation=export&id=$id\">$lang[export]</a><br />" : '<br />').
  172. "<a href=\"".ADMINSCRIPT."?action=styles&operation=copy&id=$id\">$lang[copy]</a> &nbsp; <a href=\"".ADMINSCRIPT."?action=styles&operation=import&dir=yes&restore=$id\">$lang[restore]</a>
  173. ".($addonids[$id] ? " &nbsp; <a href=\"".ADMINSCRIPT."?action=cloudaddons&id=".basename($style['directory']).".template\" target=\"_blank\" title=\"$lang[cloudaddons_linkto]\">$lang[plugins_visit]</a>" : '')."
  174. </p>"
  175. :
  176. "<img src=\"$preview\" /></td><td valign=\"top\">
  177. <p style=\"margin: 2px 0\"><a href=\"".ADMINSCRIPT."?action=styles&operation=import&dir=$style[name]\">$lang[styles_install]</a></p>
  178. <p style=\"margin: 2px 0\">$lang[styles_stylecount]: $style[stylecount]</p>".
  179. ($style['filemtime'] > $timestamp - 86400 ? '<p style=\"margin-bottom: 2px;\"><font color="red">New!</font></p>' : '')).
  180. "</td></tr></table>\n".($i == 3 ? '</tr>' : '');
  181. $i++;
  182. if($i == 3) {
  183. $i = 0;
  184. }
  185. }
  186. if($i > 0) {
  187. $stylelist .= str_repeat('<td></td>', 3 - $i);
  188. }
  189. shownav('style', 'styles_admin');
  190. showsubmenu('styles_admin', array(
  191. array('admin', 'styles', '1'),
  192. array('import', 'styles&operation=import', '0'),
  193. array('cloudaddons_style_link', 'cloudaddons')
  194. ), '<a href="'.ADMINSCRIPT.'?action=styles&operation=upgradecheck" class="bold" style="float:right;padding-right:40px;">'.$lang['plugins_validator'].'</a>');
  195. showtips('styles_admin_tips');
  196. showformheader('styles');
  197. showhiddenfields(array('updatecsscache' => 0));
  198. showtableheader();
  199. echo $stylelist;
  200. showtablefooter();
  201. showtableheader();
  202. echo '<tr><td>'.$lang['add_new'].'</td><td><input type="text" class="txt" name="newname" size="18">&nbsp;<a href="'.ADMINSCRIPT.'?action=cloudaddons">'.cplang('cloudaddons_style_link').'</a>';
  203. echo '</td><td colspan="5">&nbsp;</td></tr>';
  204. showsubmit('stylesubmit', 'submit', 'del', '<input onclick="this.form.updatecsscache.value=1" type="submit" class="btn" name="stylesubmit" value="'.cplang('styles_csscache_update').'">');
  205. showtablefooter();
  206. showformfooter();
  207. if(empty($_G['cookie']['addoncheck_template'])) {
  208. $checkresult = dunserialize(cloudaddons_upgradecheck($addonids));
  209. savecache('addoncheck_template', $checkresult);
  210. dsetcookie('addoncheck_template', 1, 3600);
  211. } else {
  212. loadcache('addoncheck_template');
  213. $checkresult = $_G['cache']['addoncheck_template'];
  214. }
  215. $newvers = '';
  216. foreach($checkresult as $addonid => $value) {
  217. list($return, $newver) = explode(':', $value);
  218. if($newver) {
  219. $newvers .= "if($('update_$addonid')) $('update_$addonid').innerHTML=' <a href=\"".ADMINSCRIPT."?action=cloudaddons&id=$addonid\"><font color=\"red\">(".cplang('styles_find_newversion')." $newver)</font></a>';";
  220. }
  221. }
  222. if($newvers) {
  223. echo '<script type="text/javascript">'.$newvers.'</script>';
  224. }
  225. } else {
  226. if($_GET['updatecsscache']) {
  227. updatecache(array('setting', 'styles'));
  228. loadcache('style_default', true);
  229. updatecache('updatediytemplate');
  230. $tpl = dir(DISCUZ_ROOT.'./data/template');
  231. while($entry = $tpl->read()) {
  232. if(preg_match("/\.tpl\.php$/", $entry)) {
  233. @unlink(DISCUZ_ROOT.'./data/template/'.$entry);
  234. }
  235. }
  236. $tpl->close();
  237. cpmsg('csscache_update', 'action=styles', 'succeed');
  238. } else {
  239. if(is_numeric($_GET['defaultnew']) && $defaultid != $_GET['defaultnew'] && isset($sarray[$_GET['defaultnew']])) {
  240. $defaultid = $_GET['defaultnew'];
  241. C::t('common_setting')->update('styleid', $defaultid);
  242. }
  243. if(is_numeric($_GET['defaultnew1']) && $defaultid1 != $_GET['defaultnew1'] && isset($sarray[$_GET['defaultnew1']])) {
  244. C::t('common_setting')->update('styleid1', $_GET['defaultnew1']);
  245. }
  246. if(is_numeric($_GET['defaultnew2']) && $defaultid2 != $_GET['defaultnew2'] && isset($sarray[$_GET['defaultnew2']])) {
  247. C::t('common_setting')->update('styleid2', $_GET['defaultnew2']);
  248. }
  249. if(is_numeric($_GET['defaultnew3']) && $defaultid3 != $_GET['defaultnew3'] && isset($sarray[$_GET['defaultnew3']])) {
  250. C::t('common_setting')->update('styleid3', $_GET['defaultnew3']);
  251. }
  252. if(isset($_GET['namenew'])) {
  253. foreach($sarray as $id => $old) {
  254. $namenew[$id] = trim($_GET['namenew'][$id]);
  255. if($namenew[$id] != $old['name']) {
  256. C::t('common_style')->update($id, array('name' => $namenew[$id]));
  257. }
  258. }
  259. }
  260. $delete = $_GET['delete'];
  261. if(!empty($delete) && is_array($delete)) {
  262. $did = array();
  263. foreach($delete as $id) {
  264. $id = intval($id);
  265. if($id == $defaultid) {
  266. cpmsg('styles_delete_invalid', '', 'error');
  267. } elseif($id != 1){
  268. $did[] = intval($id);
  269. }
  270. }
  271. if($did) {
  272. $tplids = array();
  273. foreach(C::t('common_style')->fetch_all_data() as $style) {
  274. $tplids[$style['templateid']] = $style['templateid'];
  275. }
  276. C::t('common_style')->delete($did);
  277. C::t('common_stylevar')->delete_by_styleid($did);
  278. C::t('forum_forum')->update_styleid($did);
  279. foreach(C::t('common_style')->fetch_all_data() as $style) {
  280. unset($tplids[$style['templateid']]);
  281. }
  282. if($tplids) {
  283. foreach(C::t('common_template')->fetch_all($tplids) as $tpl) {
  284. cloudaddons_uninstall(basename($tpl['directory']).'.template', $tpl['directory']);
  285. }
  286. C::t('common_template')->delete($tplids);
  287. }
  288. }
  289. }
  290. if($_GET['newname']) {
  291. $styleidnew = C::t('common_style')->insert(array('name' => $_GET['newname'], 'templateid' => 1), true);
  292. foreach(array_keys($predefinedvars) as $variable) {
  293. $substitute = isset($predefinedvars[$variable][2]) ? $predefinedvars[$variable][2] : '';
  294. C::t('common_stylevar')->insert(array('styleid' => $styleidnew, 'variable' => $_GET['variable'], 'substitute' => $substitute));
  295. }
  296. }
  297. updatecache(array('setting', 'styles'));
  298. loadcache('style_default', true);
  299. updatecache('updatediytemplate');
  300. cpmsg('styles_edit_succeed', 'action=styles', 'succeed');
  301. }
  302. }
  303. } elseif($operation == 'import') {
  304. if(!submitcheck('importsubmit') && !isset($_GET['dir'])) {
  305. shownav('style', 'styles_admin');
  306. showsubmenu('styles_admin', array(
  307. array('admin', 'styles', '0'),
  308. array('import', 'styles&operation=import', '1'),
  309. array('cloudaddons_style_link', 'cloudaddons')
  310. ), '<a href="'.ADMINSCRIPT.'?action=styles&operation=upgradecheck" class="bold" style="float:right;padding-right:40px;">'.$lang['plugins_validator'].'</a>');
  311. showformheader('styles&operation=import', 'enctype');
  312. showtableheader('styles_import');
  313. showimportdata();
  314. showtablerow('', '', '<input class="checkbox" type="checkbox" name="ignoreversion" id="ignoreversion" value="1" /><label for="ignoreversion"> '.cplang('styles_import_ignore_version').'</label>');
  315. showsubmit('importsubmit');
  316. showtablefooter();
  317. showformfooter();
  318. } else {
  319. require_once libfile('function/importdata');
  320. $restore = !empty($_GET['restore']) ? $_GET['restore'] : 0;
  321. if($restore) {
  322. $style = C::t('common_style')->fetch_by_styleid($restore);
  323. $_GET['dir'] = $style['directory'];
  324. }
  325. if(!empty($_GET['dir'])) {
  326. $renamed = import_styles($_GET['ignoreversion'], $_GET['dir'], $restore);
  327. } else {
  328. $renamed = import_styles($_GET['ignoreversion'], $_GET['dir']);
  329. }
  330. dsetcookie('addoncheck_template', '', -1);
  331. cpmsg(!empty($_GET['dir']) ? (!$restore ? 'styles_install_succeed' : 'styles_restore_succeed') : ($renamed ? 'styles_import_succeed_renamed' : 'styles_import_succeed'), 'action=styles', 'succeed');
  332. }
  333. } elseif($operation == 'copy') {
  334. $style = C::t('common_style')->fetch($id);
  335. $style['name'] .= '_'.random(4);
  336. $styleidnew = C::t('common_style')->insert(array('name' => $style['name'], 'available' => $style['available'], 'templateid' => $style['templateid']), true);
  337. foreach(C::t('common_stylevar')->fetch_all_by_styleid($id) as $stylevar) {
  338. C::t('common_stylevar')->insert(array('styleid' => $styleidnew, 'variable' => $stylevar['variable'], 'substitute' => $stylevar['substitute']));
  339. }
  340. updatecache(array('setting', 'styles'));
  341. cpmsg('styles_copy_succeed', 'action=styles', 'succeed');
  342. } elseif($operation == 'edit') {
  343. if(!submitcheck('editsubmit')) {
  344. if(empty($id)) {
  345. $stylelist = "<select name=\"id\" style=\"width: 150px\">\n";
  346. foreach(C::t('common_style')->fetch_all_data() as $style) {
  347. $stylelist .= "<option value=\"$style[styleid]\">$style[name]</option>\n";
  348. }
  349. $stylelist .= '</select>';
  350. cpmsg('styles_nonexistence', 'action=styles&operation=edit'.(!empty($highlight) ? "&highlight=$highlight" : ''), 'form', array(), $stylelist);
  351. }
  352. $style = C::t('common_style')->fetch_by_styleid($id);
  353. if(!$style) {
  354. cpmsg('style_not_found', '', 'error');
  355. }
  356. list($style['extstyle'], $style['defaultextstyle']) = explode('|', $style['extstyle']);
  357. $style['extstyle'] = explode("\t", $style['extstyle']);
  358. $extstyle = $defaultextstyle = array();
  359. if(file_exists($extstyledir = DISCUZ_ROOT.$style['directory'].'/style')) {
  360. $defaultextstyle[] = array('', $lang['default']);
  361. $tpl = dir($extstyledir);
  362. while($entry = $tpl->read()) {
  363. if($entry != '.' && $entry != '..' && file_exists($extstylefile = $extstyledir.'/'.$entry.'/style.css')) {
  364. $content = file_get_contents($extstylefile);
  365. if(preg_match('/\[name\](.+?)\[\/name\]/i', $content, $r1) && preg_match('/\[iconbgcolor](.+?)\[\/iconbgcolor]/i', $content, $r2)) {
  366. $extstyle[] = array($entry, '<em style="background:'.$r2[1].'">&nbsp;&nbsp;&nbsp;&nbsp;</em> '.$r1[1]);
  367. $defaultextstyle[] = array($entry, $r1[1]);
  368. }
  369. }
  370. }
  371. $tpl->close();
  372. }
  373. $stylecustom = '';
  374. $stylestuff = $existvars = array();
  375. foreach(C::t('common_stylevar')->fetch_all_by_styleid($id) as $stylevar) {
  376. if(array_key_exists($stylevar['variable'], $predefinedvars)) {
  377. $stylestuff[$stylevar['variable']] = array('id' => $stylevar['stylevarid'], 'subst' => $stylevar['substitute']);
  378. $existvars[] = $stylevar['variable'];
  379. } else {
  380. $stylecustom .= showtablerow('', array('class="td25"', 'class="td24 bold"', 'class="td26"'), array(
  381. "<input class=\"checkbox\" type=\"checkbox\" name=\"delete[]\" value=\"$stylevar[stylevarid]\">",
  382. '{'.strtoupper($stylevar['variable']).'}',
  383. "<textarea name=\"stylevar[$stylevar[stylevarid]]\" style=\"height: 45px\" cols=\"50\" rows=\"2\">$stylevar[substitute]</textarea>",
  384. ), TRUE);
  385. }
  386. }
  387. if($diffvars = array_diff(array_keys($predefinedvars), $existvars)) {
  388. foreach($diffvars as $variable) {
  389. $stylestuff[$variable] = array(
  390. 'id' => C::t('common_stylevar')->insert(array('styleid' => $id, 'variable' => $variable, 'substitute' => ''), true),
  391. 'subst' => ''
  392. );
  393. }
  394. }
  395. $tplselect = array();
  396. foreach(C::t('common_template')->fetch_all_data() as $template) {
  397. $tplselect[] = array($template['templateid'], $template['name']);
  398. }
  399. $smileytypes = array();
  400. foreach(C::t('forum_imagetype')->fetch_all_available() as $type) {
  401. $smileytypes[] = array($type['typeid'], $type['name']);
  402. }
  403. $adv = !empty($_GET['adv']) ? 1 : 0;
  404. shownav('style', 'styles_edit');
  405. showsubmenu(cplang('styles_admin').' - '.$style['name'], array(
  406. array('admin', 'styles', 0),
  407. array('import', 'styles&operation=import', 0),
  408. array('edit' , 'styles&operation=edit&id='.$id, 1)
  409. ));
  410. ?>
  411. <script type="text/JavaScript">
  412. function imgpre_onload(obj) {
  413. if(!obj.complete) {
  414. setTimeout(function() {imgpre_resize(obj)}, 100);
  415. }
  416. imgpre_resize(obj);
  417. }
  418. function imgpre_resize(obj) {
  419. if(obj.width > 350) {
  420. obj.style.width = '350px';
  421. }
  422. }
  423. function imgpre_update(id, obj) {
  424. url = obj.value;
  425. if(url) {
  426. re = /^(https?:)?\/\//i;
  427. var matches = re.exec(url);
  428. if(matches == null) {
  429. url = ($('styleimgdir').value ? $('styleimgdir').value : ($('imgdir').value ? $('imgdir').value : 'static/image/common')) + '/' + url;
  430. }
  431. $('bgpre_' + id).style.backgroundImage = 'url(' + url + ')';
  432. } else {
  433. $('bgpre_' + id).style.backgroundImage = 'url(static/image/common/none.gif)';
  434. }
  435. }
  436. function imgpre_switch(id) {
  437. if($('bgpre_' + id).innerHTML == '') {
  438. url = $('bgpre_' + id).style.backgroundImage.substring(4, $('bgpre_' + id).style.backgroundImage.length - 1);
  439. $('bgpre_' + id).innerHTML = '<img onload="imgpre_onload(this)" src="' + url + '" />';
  440. $('bgpre_' + id).backgroundImage = $('bgpre_' + id).style.backgroundImage;
  441. $('bgpre_' + id).style.backgroundImage = '';
  442. } else {
  443. $('bgpre_' + id).style.backgroundImage = $('bgpre_' + id).backgroundImage;
  444. $('bgpre_' + id).innerHTML = '';
  445. }
  446. }
  447. </script>
  448. <br />
  449. <iframe class="preview" frameborder="0" src="<?php echo ADMINSCRIPT;?>?action=styles&preview=yes&styleid=<?php echo $id;?>"></iframe>
  450. <?php
  451. showtips('styles_tips');
  452. showformheader("styles&operation=edit&id=$id");
  453. showtableheader($lang['styles_edit'], 'nobottom');
  454. showsetting('styles_edit_name', 'namenew', $style['name'], 'text');
  455. showsetting('styles_edit_tpl', array('templateidnew', $tplselect), $style['templateid'], 'select');
  456. showsetting('styles_edit_extstyle', array('extstylenew', $extstyle), $style['extstyle'], 'mcheckbox');
  457. if($extstyle) {
  458. showsetting('styles_edit_defaultextstyle', array('defaultextstylenew', $defaultextstyle), $style['defaultextstyle'], 'select');
  459. }
  460. showsetting('styles_edit_smileytype', array("stylevar[{$stylestuff[stypeid][id]}]", $smileytypes), $stylestuff['stypeid']['subst'], 'select');
  461. showsetting('styles_edit_imgdir', '', '', '<input type="text" class="txt" name="stylevar['.$stylestuff['imgdir']['id'].']" id="imgdir" value="'.$stylestuff['imgdir']['subst'].'" />');
  462. showsetting('styles_edit_styleimgdir', '', '', '<input type="text" class="txt" name="stylevar['.$stylestuff['styleimgdir']['id'].']" id="styleimgdir" value="'.$stylestuff['styleimgdir']['subst'].'" />');
  463. showsetting('styles_edit_logo', "stylevar[{$stylestuff[boardimg][id]}]", $stylestuff['boardimg']['subst'], 'text');
  464. foreach($predefinedvars as $predefinedvar => $v) {
  465. if($v !== array()) {
  466. if(!empty($v[1])) {
  467. showtitle($v[1]);
  468. }
  469. $type = $v[0] == 1 ? 'text' : 'color';
  470. $extra = '';
  471. $comment = ($type == 'text' ? $lang['styles_edit_'.$predefinedvar.'_comment'] : $lang['styles_edit_hexcolor']).$lang['styles_edit_'.$predefinedvar.'_comment'];
  472. if(substr($predefinedvar, -7, 7) == 'bgcolor') {
  473. $stylestuff[$predefinedvar]['subst'] = explode(' ', $stylestuff[$predefinedvar]['subst']);
  474. $bgimg = $stylestuff[$predefinedvar]['subst'][1];
  475. $bgextra = implode(' ', array_slice($stylestuff[$predefinedvar]['subst'], 2));
  476. $stylestuff[$predefinedvar]['subst'] = $stylestuff[$predefinedvar]['subst'][0];
  477. $bgimgpre = $bgimg ? (preg_match('/^(https?:)?\/\//i', $bgimg) ? $bgimg : ($stylestuff['styleimgdir']['subst'] ? $stylestuff['styleimgdir']['subst'] : ($stylestuff['imgdir']['subst'] ? $stylestuff['imgdir']['subst'] : 'static/image/common')).'/'.$bgimg) : 'static/image/common/none.gif';
  478. $comment .= '<div id="bgpre_'.$stylestuff[$predefinedvar]['id'].'" onclick="imgpre_switch('.$stylestuff[$predefinedvar]['id'].')" style="background-image:url('.$bgimgpre.');cursor:pointer;float:right;width:350px;height:40px;overflow:hidden;border: 1px solid #ccc"></div>'.$lang['styles_edit_'.$predefinedvar.'_comment'].$lang['styles_edit_bg'];
  479. $extra = '<br /><input name="stylevarbgimg['.$stylestuff[$predefinedvar]['id'].']" value="'.$bgimg.'" onchange="imgpre_update('.$stylestuff[$predefinedvar]['id'].', this)" type="text" class="txt" style="margin:5px 0;" />'.
  480. '<br /><input name="stylevarbgextra['.$stylestuff[$predefinedvar]['id'].']" value="'.$bgextra.'" type="text" class="txt" />';
  481. $varcomment = ' {'.strtoupper($predefinedvar).'},{'.strtoupper(substr($predefinedvar, 0, -7)).'BGCODE}:';
  482. } else {
  483. $varcomment = ' {'.strtoupper($predefinedvar).'}:';
  484. }
  485. showsetting(cplang('styles_edit_'.$predefinedvar).$varcomment, 'stylevar['.$stylestuff[$predefinedvar]['id'].']', $stylestuff[$predefinedvar]['subst'], $type, '', 0, $comment, $extra);
  486. }
  487. }
  488. showtablefooter();
  489. showtableheader('styles_edit_customvariable', 'notop');
  490. showsubtitle(array('', 'styles_edit_variable', 'styles_edit_subst'));
  491. echo $stylecustom;
  492. showtablerow('', array('class="td25"', 'class="td24 bold"', 'class="td26"'), array(
  493. cplang('add_new'),
  494. '<input type="text" class="txt" name="newcvar">',
  495. '<textarea name="newcsubst" class="tarea" style="height: 45px" cols="50" rows="2"></textarea>'
  496. ));
  497. showsubmit('editsubmit', 'submit', 'del');
  498. showtablefooter();
  499. showformfooter();
  500. } else {
  501. $templateidnew = $_GET['templateidnew'];
  502. $stylevar = $_GET['stylevar'];
  503. $stylevarbgimg = $_GET['stylevarbgimg'];
  504. $stylevarbgextra = $_GET['stylevarbgextra'];
  505. if(!in_array($_GET['defaultextstylenew'], $_GET['extstylenew'])) {
  506. $_GET['extstylenew'][] = $_GET['defaultextstylenew'];
  507. }
  508. $extstylenew = implode("\t", $_GET['extstylenew']).'|'.$_GET['defaultextstylenew'];
  509. if($_GET['newcvar'] && $_GET['newcsubst']) {
  510. if(C::t('common_stylevar')->check_duplicate($id, $_GET['newcvar'])) {
  511. cpmsg('styles_edit_variable_duplicate', '', 'error');
  512. } elseif(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $_GET['newcvar'])) {
  513. cpmsg('styles_edit_variable_illegal', '', 'error');
  514. }
  515. $newcvar = strtolower($_GET['newcvar']);
  516. C::t('common_stylevar')->insert(array('styleid' => $id, 'variable' => $newcvar, 'substitute' => $_GET['newcsubst']));
  517. }
  518. C::t('common_style')->update($id, array('name' => $namenew, 'templateid' => $templateidnew, 'extstyle' => $extstylenew));
  519. foreach($stylevar as $varid => $substitute) {
  520. if(!empty($stylevarbgimg[$varid])) {
  521. $substitute .= ' '.$stylevarbgimg[$varid];
  522. if(!empty($stylevarbgextra[$varid])) {
  523. $substitute .= ' '.$stylevarbgextra[$varid];
  524. }
  525. }
  526. $substitute = @dhtmlspecialchars($substitute);
  527. $stylevarids = array($varid);
  528. C::t('common_stylevar')->update_substitute_by_styleid($substitute, $id, $stylevarids);
  529. }
  530. if($_GET['delete']) {
  531. C::t('common_stylevar')->delete_by_styleid($id, $_GET['delete']);
  532. }
  533. updatecache(array('setting', 'styles'));
  534. $tpl = dir(DISCUZ_ROOT.'./data/template');
  535. while($entry = $tpl->read()) {
  536. if(preg_match("/\.tpl\.php$/", $entry)) {
  537. @unlink(DISCUZ_ROOT.'./data/template/'.$entry);
  538. }
  539. }
  540. $tpl->close();
  541. cpmsg('styles_edit_succeed', 'action=styles'.($newcvar && $newcsubst ? '&operation=edit&id='.$id : ''), 'succeed');
  542. }
  543. } elseif($operation == 'upgradecheck') {
  544. $templatearray = C::t('common_template')->fetch_all_data();
  545. if(!$templatearray) {
  546. cpmsg('plugin_not_found', '', 'error');
  547. } else {
  548. $addonids = $result = $errarray = $newarray = array();
  549. foreach($templatearray as $k => $row) {
  550. if(preg_match('/^.?\/template\/([a-z]+[a-z0-9_]*)$/', $row['directory'], $a) && $a[1] != 'default') {
  551. $addonids[$k] = $a[1].'.template';
  552. }
  553. }
  554. $checkresult = dunserialize(cloudaddons_upgradecheck($addonids));
  555. foreach($addonids as $k => $addonid) {
  556. if(isset($checkresult[$addonid])) {
  557. list($return, $newver) = explode(':', $checkresult[$addonid]);
  558. $result[$addonid]['result'] = $return;
  559. $result[$addonid]['id'] = $k;
  560. if($newver) {
  561. $result[$addonid]['newver'] = $newver;
  562. }
  563. }
  564. }
  565. }
  566. foreach($result as $id => $row) {
  567. if($row['result'] == 0) {
  568. $errarray[] = '<a href="'.ADMINSCRIPT.'?action=cloudaddons&id='.$id.'" target="_blank">'.$templatearray[$row['id']]['name'].'</a>';
  569. } elseif($row['result'] == 2) {
  570. $newarray[] = '<a href="'.ADMINSCRIPT.'?action=cloudaddons&id='.$id.'" target="_blank">'.$templatearray[$row['id']]['name'].($row['newver'] ? ' -> '.$row['newver'] : '').'</a>';
  571. }
  572. }
  573. if(!$newarray && !$errarray) {
  574. cpmsg('styles_validator_noupdate', '', 'error');
  575. } else {
  576. shownav('style', 'styles_admin');
  577. showsubmenu('styles_admin', array(
  578. array('admin', 'styles', '0'),
  579. array('import', 'styles&operation=import', '0'),
  580. array('cloudaddons_style_link', 'cloudaddons')
  581. ), '<a href="'.ADMINSCRIPT.'?action=styles&operation=upgradecheck" class="bold" style="float:right;padding-right:40px;">'.$lang['plugins_validator'].'</a>');
  582. showtableheader();
  583. if($newarray) {
  584. showtitle('styles_validator_newversion');
  585. foreach($newarray as $row) {
  586. showtablerow('class="hover"', array(), array($row));
  587. }
  588. }
  589. if($errarray) {
  590. showtitle('styles_validator_error');
  591. foreach($errarray as $row) {
  592. showtablerow('class="hover"', array(), array($row));
  593. }
  594. }
  595. showtablefooter();
  596. }
  597. }
  598. ?>