PageRenderTime 23ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/elements/custom_style.php

https://github.com/sidealice/concrete5
PHP | 376 lines | 336 code | 40 blank | 0 comment | 25 complexity | f26508c14a0b8625574bf367cdf43ffa MD5 | raw file
  1. <?
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. if (ENABLE_CUSTOM_DESIGN == false) {
  4. die(t('Custom design options have been disabled.'));
  5. }
  6. global $c;
  7. $txt = Loader::helper('text');
  8. $form = Loader::helper('form');
  9. $fh = Loader::helper('form/color');
  10. $ah = Loader::helper("concrete/asset_library");
  11. if (isset($_REQUEST['cspID']) && $_REQUEST['cspID'] > 0) {
  12. $csp = CustomStylePreset::getByID($_REQUEST['cspID']);
  13. if (is_object($csp)) {
  14. $style = $csp->getCustomStylePresetRuleObject();
  15. }
  16. } else if (is_object($style)) {
  17. $selectedCsrID = $style->getCustomStyleRuleID();
  18. }
  19. if(!$style) $style = new CustomStyleRule();
  20. $cssData = $style->getCustomStyleRuleCustomStylesArray();
  21. $presets = CustomStylePreset::getList();
  22. $presetsArray = array();
  23. foreach($presets as $csp) {
  24. $presetsArray[$csp->getCustomStylePresetID()] = $csp->getCustomStylePresetName();
  25. }
  26. $presetsArray[0] = t('** Custom (No Preset)');
  27. if (!isset($_REQUEST['csrID'])) {
  28. $cspID = $style->getCustomStylePresetID();
  29. }
  30. if ($_REQUEST['subtask'] == 'delete_custom_style_preset') {
  31. $cspID = 0;
  32. }
  33. ?>
  34. <? if (!$_REQUEST['refresh']) { ?>
  35. <div id="ccm-custom-style-wrapper">
  36. <? } ?>
  37. <form method="post" id="ccmCustomCssForm" action="<?=$action?>" style="width:96%; margin:auto;">
  38. <input id="ccm-reset-style" name="reset_css" type="hidden" value="0" />
  39. <? if (count($presets) > 0) { ?>
  40. <h2><?=t('Saved Presets')?></h2>
  41. <?=$form->select('cspID', $presetsArray, $cspID, array('style' => 'vertical-align: middle'))?>
  42. <a href="javascript:void(0)" id="ccm-style-delete-preset" style="display: none" onclick="ccmCustomStyle.deletePreset()"><img src="<?=ASSETS_URL_IMAGES?>/icons/delete_small.png" style="vertical-align: middle" width="16" height="16" border="0" /></a>
  43. <br/><br/>
  44. <input type="hidden" id="ccm-custom-style-refresh-action" value="<?=$refreshAction?>" />
  45. <? } ?>
  46. <input type="hidden" name="selectedCsrID" value="<?=$selectedCsrID?>" />
  47. <ul id="ccm-styleEditPane-tabs" class="ccm-dialog-tabs" style="margin-bottom:16px; margin-top:4px;">
  48. <li class="ccm-nav-active"><a id="ccm-styleEditPane-tab-fonts" href="#" onclick="return ccmCustomStyle.tabs(this,'fonts');"><?=t('Fonts') ?></a></li>
  49. <li><a href="javascript:void(0);" onclick="return ccmCustomStyle.tabs(this,'background');"><?=t('Background') ?></a></li>
  50. <li><a href="javascript:void(0);" onclick="return ccmCustomStyle.tabs(this,'border');"><?=t('Border') ?></a></li>
  51. <li><a href="javascript:void(0);" onclick="return ccmCustomStyle.tabs(this,'spacing');"><?=t('Spacing') ?></a></li>
  52. <li><a href="javascript:void(0);" onclick="return ccmCustomStyle.tabs(this,'css');"><?=t('CSS')?></a></li>
  53. </ul>
  54. <div id="ccmCustomCssFormTabs">
  55. <div id="ccm-styleEditPane-fonts" class="ccm-styleEditPane">
  56. <div>
  57. <h2><?php echo t('Fonts')?></h2>
  58. <table class="ccm-style-property-table" border="0" cellspacing="0" cellpadding="0">
  59. <tr>
  60. <td>
  61. <?=t('Face')?>
  62. </td>
  63. <td>
  64. <select name="font_family">
  65. <option <?=($cssData['font_family']=='inherit')?'selected':'' ?> value="inherit"><?=t('Inherit') ?></option>
  66. <option <?=($cssData['font_family']=='Arial')?'selected':'' ?> value="Arial">Arial</option>
  67. <option <?=($cssData['font_family']=='Times New Roman')?'selected':'' ?> value="Times New Roman">Times New Roman</option>
  68. <option <?=($cssData['font_family']=='Courier')?'selected':'' ?> value="Courier">Courier</option>
  69. <option <?=($cssData['font_family']=='Georgia')?'selected':'' ?> value="Georgia">Georgia</option>
  70. <option <?=($cssData['font_family']=='Verdana')?'selected':'' ?> value="Verdana">Verdana</option>
  71. </select>
  72. </td>
  73. <td rowspan="99"><div style="width: 30px">&nbsp;</div></td>
  74. <td>
  75. <?=t('Size')?>
  76. </td>
  77. <td>
  78. <input name="font_size" type="text" value="<?=htmlentities( $cssData['font_size'], ENT_COMPAT, APP_CHARSET) ?>" size=2 />
  79. </td>
  80. </tr>
  81. <tr>
  82. <td>
  83. <?=t('Line Height')?>
  84. </td>
  85. <td>
  86. <input name="line_height" type="text" value="<?=htmlentities( $cssData['line_height'], ENT_COMPAT, APP_CHARSET) ?>" size=2 />
  87. </td>
  88. <td>
  89. <?=t('Color')?>
  90. </td>
  91. <td>
  92. <?=$fh->output( 'color', '', $cssData['color']) ?>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td>
  97. <?=t('Alignment')?>
  98. </td>
  99. <td>
  100. <select name="text_align">
  101. <option <?=($cssData['text_align']=='')?'selected':'' ?> value=""><?=t('Default')?></option>
  102. <option <?=($cssData['text_align']=='left')?'selected':'' ?> value="left"><?=t('Left')?></option>
  103. <option <?=($cssData['text_align']=='center')?'selected':'' ?> value="center"><?=t('Center')?></option>
  104. <option <?=($cssData['text_align']=='right')?'selected':'' ?> value="right"><?=t('Right')?></option>
  105. <option <?=($cssData['text_align']=='justify')?'selected':'' ?> value="justify"><?=t('Justify')?></option>
  106. </select>
  107. </td>
  108. <td colspan="2">&nbsp;</td>
  109. </tr>
  110. </table>
  111. </div>
  112. </div>
  113. <div id="ccm-styleEditPane-background" class="ccm-styleEditPane" style="display:none">
  114. <div>
  115. <h2><?php echo t('Background')?></h2>
  116. <table border="0" cellspacing="0" cellpadding="0" class="ccm-style-property-table">
  117. <tr>
  118. <td><?=$fh->output( 'background_color', '', $cssData['background_color']) ?></td>
  119. <?
  120. $bf = false;
  121. if ($cssData['background_image'] > 0) {
  122. $bf = File::getByID($cssData['background_image']);
  123. } ?>
  124. <td><?=$ah->image('background_image', 'background_image', t('Background Image'), $bf)?></td>
  125. </tr>
  126. <tr>
  127. <td>&nbsp;</td>
  128. <td><strong><?=t('Repeat')?></strong>:<br/>
  129. <input type="radio" value="no-repeat" name="background_repeat" <? if ($cssData['background_repeat'] == 'no-repeat' || !$cssData['backgroundImageRepeat']) { ?> checked <? } ?> /> <?=t('None')?>
  130. <input type="radio" value="repeat-x" name="background_repeat" <? if ($cssData['background_repeat'] == 'repeat-x') { ?> checked <? } ?> /> <?=t('Horizontal')?>
  131. <input type="radio" value="repeat-y" name="background_repeat" <? if ($cssData['background_repeat'] == 'repeat-y') { ?> checked <? } ?>/> <?=t('Vertical')?>
  132. <input type="radio" value="repeat" name="background_repeat" <? if ($cssData['background_repeat'] == 'repeat') { ?> checked <? } ?>/> <?=t('All')?>
  133. </table>
  134. <div class="ccm-spacer"></div>
  135. </div>
  136. </div>
  137. <div id="ccm-styleEditPane-border" class="ccm-styleEditPane" style="display:none">
  138. <div>
  139. <h2><?php echo t('Border')?></h2>
  140. <table class="ccm-style-property-table" border="0" cellspacing="0" cellpadding="0">
  141. <tr>
  142. <td>
  143. <?=t('Style')?>
  144. </td>
  145. <td>
  146. <select name="border_style" >
  147. <option <?=($cssData['border_style']=='none')?'selected':'' ?> value="none"><?=t('none')?></option>
  148. <option <?=($cssData['border_style']=='solid')?'selected':'' ?> value="solid"><?=t('solid')?></option>
  149. <option <?=($cssData['border_style']=='dotted')?'selected':'' ?> value="dotted"><?=t('dotted')?></option>
  150. <option <?=($cssData['border_style']=='dashed')?'selected':'' ?> value="dashed"><?=t('dashed')?></option>
  151. <option <?=($cssData['border_style']=='double')?'selected':'' ?> value="double"><?=t('double')?></option>
  152. <option <?=($cssData['border_style']=='groove')?'selected':'' ?> value="groove"><?=t('groove')?></option>
  153. <option <?=($cssData['border_style']=='inset')?'selected':'' ?> value="inset"><?=t('inset')?></option>
  154. <option <?=($cssData['border_style']=='outset')?'selected':'' ?> value="outset"><?=t('outset')?></option>
  155. <option <?=($cssData['border_style']=='ridge')?'selected':'' ?> value="ridge"><?=t('ridge')?></option>
  156. </select>
  157. </td>
  158. <td rowspan="99"><div style="width: 30px">&nbsp;</div></td>
  159. <td>
  160. <?=t('Width')?>
  161. </td>
  162. <td>
  163. <input name="border_width" type="text" value="<?=intval($cssData['border_width'])?>" size="2" style="width:20px" /> <span class="ccm-note"><?=t('px')?></span>
  164. </td>
  165. </tr>
  166. <tr>
  167. <td>
  168. <?=t('Direction')?>
  169. </td>
  170. <td>
  171. <select name="border_position" >
  172. <option <?=($cssData['border_position']=='full')?'selected':'' ?> value="full"><?=t('Full')?></option>
  173. <option <?=($cssData['border_position']=='top')?'selected':'' ?> value="top"><?=t('Top')?></option>
  174. <option <?=($cssData['border_position']=='right')?'selected':'' ?> value="right"><?=t('Right')?></option>
  175. <option <?=($cssData['border_position']=='bottom')?'selected':'' ?> value="bottom"><?=t('Bottom')?></option>
  176. <option <?=($cssData['border_position']=='left')?'selected':'' ?> value="left"><?=t('Left')?></option>
  177. </select>
  178. </td>
  179. <td><?=t('Color')?></td>
  180. <td>
  181. <?=$fh->output( 'border_color', '', $cssData['border_color']) ?>
  182. </td>
  183. </tr>
  184. </table>
  185. </div>
  186. </div>
  187. <div id="ccm-styleEditPane-spacing" class="ccm-styleEditPane" style="display:none">
  188. <div>
  189. <table style="width:100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="width:50%" valign="top">
  190. <h2 style="margin-top: 0px"><?php echo t('Margin ')?></h2>
  191. <table class="ccm-style-property-table" border="0" cellspacing="0" cellpadding="0">
  192. <tr>
  193. <td>
  194. <?=t('Top')?>
  195. </td>
  196. <td>
  197. <input name="margin_top" type="text" value="<?=htmlentities( $cssData['margin_top'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  198. </td>
  199. </tr>
  200. <tr>
  201. <td>
  202. <?=t('Right')?>
  203. </td>
  204. <td>
  205. <input name="margin_right" type="text" value="<?=htmlentities( $cssData['margin_right'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  206. </td>
  207. </tr>
  208. <tr>
  209. <td>
  210. <?=t('Bottom')?>&nbsp;&nbsp;
  211. </td>
  212. <td>
  213. <input name="margin_bottom" type="text" value="<?=htmlentities( $cssData['margin_bottom'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  214. </td>
  215. </tr>
  216. <tr>
  217. <td>
  218. <?=t('Left')?>
  219. </td>
  220. <td>
  221. <input name="margin_left" type="text" value="<?=htmlentities( $cssData['margin_left'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  222. </td>
  223. </tr>
  224. </table>
  225. </td><td valign="top">
  226. <h2 style="margin-top: 0px"><?php echo t('Padding ')?></h2>
  227. <table class="ccm-style-property-table" border="0" cellspacing="0" cellpadding="0">
  228. <tr>
  229. <td>
  230. <?=t('Top')?>
  231. </td>
  232. <td>
  233. <input name="padding_top" type="text" value="<?=htmlentities( $cssData['padding_top'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  234. </td>
  235. </tr>
  236. <tr>
  237. <td>
  238. <?=t('Right')?>
  239. </td>
  240. <td>
  241. <input name="padding_right" type="text" value="<?=htmlentities( $cssData['padding_right'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  242. </td>
  243. </tr>
  244. <tr>
  245. <td>
  246. <?=t('Bottom')?>&nbsp;&nbsp;
  247. </td>
  248. <td>
  249. <input name="padding_bottom" type="text" value="<?=htmlentities( $cssData['padding_bottom'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  250. </td>
  251. </tr>
  252. <tr>
  253. <td>
  254. <?=t('Left')?>
  255. </td>
  256. <td>
  257. <input name="padding_left" type="text" value="<?=htmlentities( $cssData['padding_left'], ENT_COMPAT, APP_CHARSET) ?>" size=2 style="width:40px" />
  258. </td>
  259. </tr>
  260. </table>
  261. </tr></table>
  262. </div>
  263. </div>
  264. <div id="ccm-styleEditPane-css" class="ccm-styleEditPane" style="display:none">
  265. <div>
  266. <table class="ccm-style-property-table" border="0" cellspacing="0" cellpadding="0" width="100%">
  267. <tr>
  268. <td style="width: 50%" valign="top">
  269. <h2 style="margin-top: 0px"><?php echo t('CSS ID')?></h2>
  270. <input name="css_id" type="text" value="<?=htmlentities(trim($style->getCustomStyleRuleCSSID()), ENT_COMPAT, APP_CHARSET) ?>" style="width:99%"
  271. onkeyup="ccmCustomStyle.validIdCheck(this,'<?=str_replace(array("'",'"'),'',$style->getCustomStyleRuleCSSID()) ?>')" />
  272. <div id="ccm-styles-invalid-id" class="ccm-error" style="display:none; padding-top:4px;">
  273. <?=t('Invalid ID. This id is currently being used by another element on this page.')?>
  274. </div>
  275. </div>
  276. </td>
  277. <td valign="top" style="width: 50%">
  278. <h2 style="margin-top: 0px"><?php echo t('CSS Class Name(s)')?></h2>
  279. <input name="css_class_name" type="text" value="<?=htmlentities(trim($style->getCustomStyleRuleClassName()), ENT_COMPAT, APP_CHARSET) ?>" style="width:99%" />
  280. </td>
  281. </tr>
  282. </table>
  283. </div>
  284. <div>
  285. <h2><?php echo t('Additional CSS')?></h2>
  286. <textarea name="css_custom" cols="50" rows="4" style="width:99%"><?=htmlentities($style->getCustomStyleRuleCSSCustom(), ENT_COMPAT, APP_CHARSET) ?></textarea>
  287. </div>
  288. </div>
  289. </div>
  290. <br/>
  291. <? if ($cspID > 0) {
  292. $cspx = CustomStylePreset::getByID($cspID);
  293. ?>
  294. <div id="cspFooterPreset" style="display: none">
  295. <div class="ccm-note-important">
  296. <h2><?=t('You are changing a preset')?></h2>
  297. <div><?=$form->radio('cspPresetAction', 'update_existing_preset', true)?> <?=t('Update "%s" preset everywhere it is used', $cspx->getCustomStylePresetName())?></div>
  298. <div><?=$form->radio('cspPresetAction', 'save_as_custom_style')?> <?=t('Use this style here, and leave "%s" unchanged', $cspx->getCustomStylePresetName())?></div>
  299. <div><?=$form->radio('cspPresetAction', 'create_new_preset')?> <?=t('Save this style as a new preset')?><br/><span style="margin-left: 20px"><?=$form->text('cspName', array('style' => 'width: 127px', 'disabled' => true))?></span></div>
  300. </div>
  301. </div>
  302. <? } ?>
  303. <div id="cspFooterNoPreset" ><?=$form->checkbox('cspPresetAction', 'create_new_preset')?> <label for="cspPresetAction" style="display: inline; color: #555"><?=t('Save this style as a new preset.')?></label><span style="margin-left: 10px"><?=$form->text('cspName', array('style' => 'width: 127px', 'disabled' => true))?></span></div>
  304. <br/>
  305. <div class="ccm-buttons">
  306. <a href="#" class="ccm-button-left cancel" onclick="jQuery.fn.dialog.closeTop()"><span><em class="ccm-button-close"><?=t('Cancel')?></em></span></a>
  307. <a href="javascript:void(0)" onclick="$('#ccmCustomCssForm').submit()" class="ccm-button-right accept"><span><?=t('Update')?></span></a>
  308. <? if ($cspID < 1) { ?>
  309. <a onclick="return ccmCustomStyle.resetAll();" id="ccm-reset-style-button" class="ccm-button-right accept" style="margin-right:8px; "><span><?=t('Reset')?></span></a>
  310. <? } ?>
  311. </div>
  312. <div class="ccm-spacer"></div>
  313. <div class="ccm-note" style="margin-top:16px;">
  314. <?=t('Note: Styles set here are often overridden by those defined within the various block types.')?>
  315. </div>
  316. <?
  317. $valt = Loader::helper('validation/token');
  318. $valt->output();
  319. ?>
  320. </form>
  321. <script type="text/javascript">
  322. $(function() {
  323. ccmCustomStyle.initForm();
  324. });
  325. </script>
  326. <? if (!$_REQUEST['refresh']) { ?>
  327. </div>
  328. <? } ?>