YaWK  24.1
Yet another WebKit
template-customjs.php
Go to the documentation of this file.
1 <?php
2 
3 use YAWK\backend;
4 use YAWK\db;
5 use YAWK\language;
6 use YAWK\settings;
7 use YAWK\template;
8 use YAWK\user;
9 
10 /** @var $db db */
11 /** @var $lang language */
12 
13 // new template object if not exists
14 if (!isset($template)) { $template = new template(); }
15 
16 // check if any action is requested
17 if (isset($_POST['save']) && (isset($_GET['action']) && (isset($_GET['id']))))
18 {
19  if (isset($_POST) && (!empty($_POST)))
20  {
21  if (isset($_GET['action']))
22  {
23  // process only if $_POST data is set and not empty
24  // walk through save requests
25  // position properties
26  if ($_GET['action'] === "template-customjs")
27  {
28  if (isset($_POST['customJS']) && (!empty($_POST['customJS'])))
29  {
30  // save the content to /system/template/$NAME/css/custom.css
31  $template->setCustomJsFile($db, $_POST['customJS'], 0, $_GET['id']);
32  // save a minified version to /system/template/$NAME/css/custom.min.css
33  $template->setCustomJsFile($db, $_POST['customJS'], 1, $_GET['id']);
34  }
35  }
36  }
37  }
38 }
39 ?>
40 <?php
41 // get settings for editor
42 $editorSettings = settings::getEditorSettings($db, 14);
43 ?>
44 <!-- include summernote css/js-->
45 <!-- include codemirror (codemirror.css, codemirror.js, xml.js) -->
46 <link rel="stylesheet" type="text/css" href="../system/engines/codemirror/codemirror.min.css">
47 <link rel="stylesheet" type="text/css" href="../system/engines/codemirror/themes/<?php echo $editorSettings['editorTheme']; ?>.css">
48 <link rel="stylesheet" type="text/css" href="../system/engines/codemirror/show-hint.min.css">
49 <script type="text/javascript" src="../system/engines/codemirror/codemirror-compressed.js"></script>
50 <script type="text/javascript" src="../system/engines/codemirror/auto-refresh.js"></script>
51 
52 <!-- SUMMERNOTE -->
53 <link href="../system/engines/summernote/dist/summernote.css" rel="stylesheet">
54 <script src="../system/engines/summernote/dist/summernote.min.js"></script>
55 <script src="../system/engines/summernote/dist/summernote-cleaner.js"></script>
56 
57 <script type="text/javascript">
58  $(document).ready(function() {
59  // TRY TO DISABLE CTRL-S browser hotkey
60  function saveHotkey() {
61  // simply disables save event for chrome
62  $(window).keypress(function (event) {
63  if (!(event.which === 115 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) && !(event.which === 19)) return true;
64  $('#savebutton').click(); // SAVE FORM AFTER PRESSING STRG-S hotkey
65  event.preventDefault();
66  formmodified=0; // do not warn user, just save.
67  return false;
68  });
69  // used to process the cmd+s and ctrl+s events
70  $(document).keydown(function (event) {
71  if (event.which === 83 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) {
72  event.preventDefault();
73  $('#savebutton').click(); // SAVE FORM AFTER PRESSING STRG-S hotkey
74  formmodified=0; // do not warn user, just save.
75  // save(event);
76  return false;
77  }
78  });
79  }
80  saveHotkey();
81 
82  // textarea that will be transformed into editor
83  const editor = ('textarea#summernote');
84  const savebutton = ('#savebutton');
85  const savebuttonIcon = ('#savebuttonIcon');
86  // ok, lets go...
87  // we need to check if user clicked on save button
88  $(savebutton).click(function() {
89  $(savebutton).removeClass('btn btn-success').addClass('btn btn-warning disabled');
90  $(savebuttonIcon).removeClass('fa fa-check').addClass('fa fa-spinner fa-spin fa-fw');
91  // to save, even if the editor is currently opened in code view
92  // we need to check if codeview is currently active:
93  if ($(editor).summernote('codeview.isActivated')) {
94  // if so, turn it off.
95  $(editor).summernote('codeview.deactivate');
96  }
97  // to display images in frontend correctly, we need to change the path of every image.
98  // to do that, the current value of textarea will be read into var text and search/replaced
99  // and written back into the textarea. utf-8 encoding/decoding happens in php, before saving into db.
100  // get the value of summernote textarea
101  const text = $(editor).val();
102  // search for <img> tags and revert src ../ to set correct path for frontend
103  const frontend = text.replace(/<img src=\"..\/media/g,"<img src=\"media");
104  // put the new string back into <textarea>
105  $(editor).val(frontend); // to make sure that saving works
106 
107 
108  // replace &gt; with <
109  var newValue = $(editor).val();
110  var replace1 = newValue.replace(/&gt;/g, '>');
111  $(editor).val(replace1);
112 
113  var newValue2 = $(editor).val();
114  var replace2 = newValue2.replace(/&lt;/g, '<');
115  $(editor).val(replace2);
116 
117  });
118 
119  // BEFORE SUMMERNOTE loads: 3 important lines of code!
120  // to display images in backend correctly, we need to change the path of every image.
121  // procedure is the same as above (see #savebutton.click)
122  // get the value of summernote textarea
123  const text = $(editor).val();
124  // search for <img> tags and update src ../ to get images viewed in summernote
125  const backend = text.replace(/<img src=\"media/g,"<img src=\"../media");
126  // put the new string back into <textarea>
127  $(editor).val(backend); // set new value into textarea
128 
129  // summernote.init -
130  // LOAD SUMMERNOTE IN CODEVIEW ON STARTUP
131  $(editor).on('summernote.init', function() {
132  // toggle editor to codeview
133  $(editor).summernote('codeview.toggle');
134  });
135 
136  // INIT SUMMERNOTE EDITOR
137  $(editor).summernote({ // set editor itself
138  height: <?php echo $editorSettings['editorHeight']; ?>, // set editor height
139  minHeight: null, // set minimum height of editor
140  maxHeight: null, // set maximum height of editor
141  focus: true, // set focus to editable area after initializing summernote
142  toolbar: [
143  // load an empty toolbar.
144  // in that case: just a plain code editor. no mice cinema.
145  ],
146  // language for plugin image-attributes.js
147  lang: '<?php echo $lang['CURRENT_LANGUAGE']; ?>',
148 
149  // powerup the codeview with codemirror theme
150  codemirror: { // codemirror options
151  theme: '<?php echo $editorSettings['editorTheme']; ?>', // codeview theme
152  lineNumbers: true, // display lineNumbers true|false
153  undoDepth: <?php echo $editorSettings['editorUndoDepth']; ?>, // how many undo steps should be saved? (default: 200)
154  smartIndent: <?php echo $editorSettings['editorSmartIndent']; ?>, // better indent
155  indentUnit: <?php echo $editorSettings['editorIndentUnit']; ?>, // how many spaces auto indent? (default: 2)
156  scrollbarStyle: null, // styling of the scrollbars
157  matchBrackets: <?php echo $editorSettings['editorMatchBrackets']; ?>, // highlight corresponding brackets
158  autoCloseBrackets: <?php echo $editorSettings['editorCloseBrackets'];?>, // auto insert close brackets
159  autoCloseTags: <?php echo $editorSettings['editorCloseTags']; ?>, // auto insert close tags after opening
160  value: "<html>\n " + document.documentElement.innerHTML + "\n</html>", // all html
161  mode: "javascript", // editor mode
162  matchTags: {bothTags: <?php echo $editorSettings['editorMatchTags']; ?>}, // hightlight matching tags: both
163  extraKeys: {
164  "Ctrl-J": "toMatchingTag", // CTRL-J to jump to next matching tab
165  "Ctrl-Space": "autocomplete" // CTRL-SPACE to open autocomplete window
166  },
167  styleActiveLine: <?php echo $editorSettings['editorActiveLine']; ?>, // highlight the active line (where the cursor is)
168  autoRefresh: true
169  },
170 
171  // plugin: summernote-cleaner.js
172  // this allows to copy/paste from word, browsers etc.
173  cleaner: { // does the job well: no messy code anymore!
174  action: 'both', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
175  newline: '<br>' // Summernote's default is to use '<p><br></p>'
176 
177  // silent mode:
178  // from my pov it is not necessary to notify the user about the code cleaning process.
179  // it throws just a useless, annoying bubble everytime you hit the save button.
180  // BUT: if you need this notification, you can enable it by uncommenting the following 3 lines
181  // notTime:2400, // Time to display notifications.
182  // notStyle:'position:absolute;bottom:0;left:2px', // Position of notification
183  // icon:'<i class="note-icon">[Your Button]</i>' // Display an icon
184  }
185  }); // end summernote
186  }); // end document ready
187 </script>
188 <?php
189 // new template object if not exists
190 if (!isset($template)) { $template = new template(); }
191 // new user object if not exists
192 if (!isset($user)) { $user = new user($db); }
193 
194 // load properties of current active template
195 // get ID of current active template
196 $getID = settings::getSetting($db, "selectedTemplate");
197 // load properties of current active template
198 $template->loadProperties($db, $getID);
199 ?>
200 
201 <?php
202 // TEMPLATE WRAPPER - HEADER & breadcrumbs
203 echo "
204  <!-- Content Wrapper. Contains page content -->
205  <div class=\"content-wrapper\" id=\"content-FX\">
206  <!-- Content Header (Page header) -->
207  <section class=\"content-header\">";
208 // draw Title on top
209 echo backend::getTitle($lang['TPL'], "custom.js");
210 echo backend::getTemplateBreadcrumbs($lang);
211 echo"</section><!-- Main content -->
212  <section class=\"content\">";
213 /* page content start here */
214 ?>
215 <form id="template-edit-form" action="index.php?page=template-customjs&action=template-customjs&id=<?php echo $getID; ?>" method="POST">
216  <!-- title header -->
217  <!-- REDESIGN -->
218  <div class="box">
219  <div class="box-body">
220  <div class="col-md-10">
221  <?php echo "<h4><i class=\"fa fa-code\"></i> &nbsp;$lang[CUSTOM_JS] <small>$lang[TPL_CUSTOMJS_SUBTEXT]</small></h4>"; ?>
222  </div>
223  <div class="col-md-2">
224  <button class="btn btn-success pull-right" id="savebutton" name="save" style="margin-top:2px;"><i class="fa fa-check" id="savebuttonIcon"></i>&nbsp;&nbsp;<?php echo $lang['CUSTOM_JS_SAVE']; ?></button>
225  </div>
226  </div>
227  </div>
228 
229  <!-- CUSTOM JS -->
230  <div class="row">
231  <div class="col-md-8 animated fadeIn">
232  <?php $customJS = $template->getCustomJSFile($db, $template->id); ?>
233  <textarea name="customJS" cols="64" rows="28" id="summernote"><?php echo $customJS; ?></textarea>
234  <label for="summernote"><small><?php echo $lang['YOU_EDIT']; ?>:</small> &nbsp;system/templates/<?php echo $template->name; ?>/js/custom.js</label>
235  </div>
236  <div class="col-md-4">
237  <div class="box box-default">
238  <div class="box-header with-border">
239  <h3 class="box-title"><?php echo $template->name; ?>/js/custom.js</h3>
240  </div>
241  <div class="box-body">
242  <?php echo $lang['CUSTOM_JS_DESC']; ?>
243  <br><br>
244  <i><?php echo $lang['CUSTOM_JS_HELP']; ?></i><br>
245  &raquo; <a href="http://www.w3schools.com/js/" title="open JS overview in new TAB" target="_blank">w3schools.com/js/</a>
246 
247  <hr>
248  <b><i class="fa fa-lightbulb-o"></i> <?php echo $lang['DID_YOU_KNOW']; ?></b><br>
249  <i><?php echo $lang['TIP_STRG_S']; ?></i>
250  </div>
251 
252  </div>
253  </div>
254  </div>
255 </form>
print $lang['FILEMAN_UPLOAD']
Backend class serves a few useful functions for the admin backend.
Definition: backend.php:27
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
Settings class: get and set YaWK system settings.
Definition: settings.php:9
The template controller - get and set template settings.
Definition: template.php:16
The default user class. Provide all functions to handle the user object.
Definition: user.php:17
function window
Definition: fuckAdBlock.js:8
FuckAdBlock prototype on
Definition: fuckAdBlock.js:227
function b(a)
Definition: browser.js:14
function a
Definition: browser.js:14
c jPlayer event
type
Definition: menu-new.php:35
print $page title
Definition: page-edit.php:377
print $_GET['id']
Definition: page-edit.php:357
function i(e, t)
Definition: plyr.js:1
function g(e, t, n, r)
Definition: plyr.js:1
<!-- backend language -->< h3 >< i class="fa fa-language"></i > & nbsp
$template name
if(!isset($template)) if(isset($_POST['save']) &&(isset($_GET['action']) &&(isset($_GET['id'])))) $editorSettings
if(!isset($template)) if(!isset($user)) $getID
document ready(function() { $('a[data-confirm]').click(function(ev) { modal='#dataConfirmModal';var href=$(this).attr('href');var title=$(this).attr('title');var icon=$(this).attr('data-icon');if(!icon) { icon='fa fa-trash-o';} if(!$(modal).length) { $('body').append('< div id="dataConfirmModal" class="modal fade" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true">< div class="modal-dialog">< div class="modal-content">< div class="modal-header">< button type="button" class="close" data-dismiss="modal" aria-hidden="true">< i class="fa fa-times"></i ></button >< br >< div class="col-md-1">< h3 class="modal-title">< i class="'+icon+'"></i ></h3 ></div >< div class="col-md-11">< h3 class="modal-title" id="dataConfirmLabel">'+title+'</h3 ></div ></h3 ></div >< div class="modal-body"></div >< div class="modal-footer">< button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">Abbrechen</button >< a type="button" class="btn btn-danger" id="dataConfirmOK">< i class="'+icon+'"></i > L &ouml;schen</a ></div ></div ></div ></div >');} $(modal).find('.modal-body').text($(this).attr('data-confirm'));$('#dataConfirmOK').attr('href', href);$(modal).modal({show:true});return false;});$('#terminateUser').click(function() { var terminate=window.confirm("ACHTUNG!\nDas wird Deinen Account permanent deaktivieren.\n"+"Bist Du Dir sicher, dass Du das tun willst?");if(terminate===true) { var terminateUser=window.confirm("Bist Du Dir wirklich ganz sicher?\n"+"Diese Aktion kann nicht rueckgaengig gemacht werden.");if(terminateUser===true) { $.get('system/templates/YaWK-bootstrap3/js/terminate-user.php', function(data) { if(data==="true") { setTimeout("window.location='logout.html'", 0);} else { alert("Fehler: "+data);} });} } });function dismissNotifications() { $.ajax({ url:'js/dismiss-notifications.php', type:'POST', success:function(data) { if(!data) { alert('Something went wrong!');return false;} } });$("#bell-label").fadeOut();$('#notification-header').html('You have 0 notifications');$('#notification-menu').fadeOut();} $("#dismiss").click(function() { dismissNotifications();});function disableButtons(delay) { $('#loginButton').removeClass().addClass('btn btn-success disabled').attr('id', 'LOGIN_FORBIDDEN');$('#resetPasswordButton').removeClass().addClass('btn btn-danger disabled');setTimeout(function() { $('#LOGIN_FORBIDDEN').attr('id', 'loginButton').removeClass().addClass('btn btn-success');$('#resetPasswordButton').removeClass().addClass('btn btn-danger');}, delay);} $("#loginButton").click(function(){ if($('#loginButton').length > 0) { if($('#loginButton').hasClass('btn') &&$('#loginButton').hasClass('btn-success') &&$('#loginButton').hasClass('disabled')) { } else { $("#loginForm").submit();disableButtons(10000);} } else if($('#LOGIN_FORBIDDEN').length > 0) { if($('#LOGIN_FORBIDDEN').hasClass('btn') &&$('#LOGIN_FORBIDDEN').hasClass('btn-success') &&$('#LOGIN_FORBIDDEN').hasClass('disabled')) { } else { } } });$("#blockedBtn").hover(function() { $("#blockedBtn").hide();$("#askBtn").fadeIn(820);});})