YaWK  24.1
Yet another WebKit
template-assets.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 // new template object if not exists
13 if (!isset($template)) { $template = new template(); }
14 // new user object if not exists
15 if (!isset($user)) { $user = new user($db); }
16 // $_GET['id'] or $_POST['id'] holds the template ID to edit.
17 // If any one of these two is set, we're in "preview mode" - this means:
18 // The user database holds two extra cols: overrideTemplate(int|0,1) and templateID
19 // Any user who is allowed to override the Template, can edit a template and view it
20 // in the frontend. -Without affecting the current active theme for any other user.
21 // This is pretty cool when working on a new design: because you see changes, while others wont.
22 // In theory, thereby every user can have a different frontend template activated.
23 
24 // get ID of current active template
25 $template->id = settings::getSetting($db, "selectedTemplate");
26 $template->name = template::getTemplateNameById($db, $template->id);
27 ?>
28 
29 <?php
30 /**
31  *
32  */
33 
34 
35 // OVERRIDE TEMPLATE
36 // check if call comes from template-manage or template-edit form
37 if (isset($_GET['id']) && (is_numeric($_GET['id']) || (isset($_POST['id']) && (is_numeric($_POST['id'])))))
38 {
39  if (empty($_GET['id']) || (!empty($_POST['id']))) { $getID = $_POST['id']; }
40  else if (!empty($_GET['id']) || (empty($_POST['id']))) { $getID = $_GET['id']; }
41  else { $getID = settings::getSetting($db, "selectedTemplate"); }
42 
43  if ($user->isTemplateEqual($db, $getID))
44  { // user template equals selectedTemplate
45  // update template in user table row
46  $user->setUserTemplate($db, 0, $getID, $user->id);
47  $user->overrideTemplate = 0;
48  // info badge to inform user that this is visible to everyone
49  $infoBadge = "<span class=\"label label-success\"><i class=\"fa fa-check\"></i>&nbsp;&nbsp;$lang[VISIBLE_TO_EVERYONE]</span>";
50  // info button on top
51  $previewButton = "";
52  }
53  else
54  { // show preview button and set template active for this user
55  $user->setUserTemplate($db, 1, $getID, $user->id);
56  $user->overrideTemplate = 1;
57  // info badge to inform user that this is HIS preview
58  $infoBadge = "<span class=\"label label-danger\"><i class=\"fa fa-eye\"></i>&nbsp;&nbsp;$lang[PREVIEW]</span>";
59  // close preview button on top
60  $previewButton = "<a class=\"btn btn-danger\" href=\"index.php?page=template-manage&overrideTemplate=0&id=$getID\"><i class=\"fa fa-times\"></i>&nbsp;&nbsp;$lang[CLOSE_PREVIEW]</a>";
61  }
62 
63  // check if user/admin is allowed to override the template
64  if ($user->isAllowedToOverrideTemplate($db, $user->id) === true)
65  { // ok, user is allowed to override: set tpl from user database
66  if (isset($_GET['overrideTemplate']) && ($_GET['overrideTemplate'] === "1"))
67  {
68  $user->setUserTemplate($db, 1, $getID, $user->id);
69  $user->overrideTemplate = 1;
70  $template->loadProperties($db, $getID);
71  }
72  else
73  {
74  $user->setUserTemplate($db, 0, $getID, $user->id);
75  $user->overrideTemplate = 0;
76  $template->loadProperties($db, $getID);
77  }
78 
79  // $userTemplateID = \YAWK\user::getUserTemplateID($db, $user->id);
80  // load template properties for userTemplateID
81  // $template->loadProperties($db, $getID);
82  }
83  else
84  { // user is not allowed to override, so we load the default (global) selectedTemplate settings
85  // $template->loadProperties($db, YAWK\settings::getSetting($db, "selectedTemplate"));
86  $template->loadProperties($db, $getID);
87  }
88 }
89 else {
90  $previewButton = "";
91 }
92 
93 ?>
94 
95 <?php
96 if (isset($_GET['action']) && ($_GET['action'] === "setup"))
97 {
98  // update asset configuration
99  if (isset($_POST['save']) && (!empty($_POST['save'])))
100  {
101  $title = '';
102  $sortation = '';
103  // first of all: delete all assets of this templateID to avoid duplicates
104  if ($db->query("DELETE FROM {assets} WHERE templateID = '".$template->id."'"))
105  {
106  // walk through post data
107  foreach ($_POST as $param => $value)
108  {
109  // check file types
110  // .js file
111  if (substr($value, -3) == ".js")
112  { // type 1 = javascript file
113  $type = "js";
114  }
115  // .css file
116  if (substr($value, -4) == ".css") {
117  // type 2 = css file
118  $type = "css";
119  }
120  // title
121  if (substr($param, 0, 6) == "title-") {
122  $title = $value;
123  $value = '';
124  }
125  // sortation
126  if (substr($param, 0, 10) == "sortation-") {
127  $sortation = $value;
128  $value = '';
129  }
130 
131  // if value is not empty
132  if (!empty($value) && ($value != "save"))
133  { // add asset to database
134  $db->query("INSERT INTO {assets} (templateID, type, sortation, asset, link) VALUES ('" . $template->id . "', '" . $type . "', '" . $sortation . "','" . $title . "', '" . $value . "')");
135  }
136  }
137  }
138  }
139 }
140 
141 ?>
142 <script type="text/javascript">
143  $(document).ready(function() {
144  // TRY TO DISABLE CTRL-S browser hotkey
145  function saveHotkey() {
146  // simply disables save event for chrome
147  $(window).keypress(function (event) {
148  if (!(event.which === 115 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) && !(event.which === 19)) return true;
149  event.preventDefault();
150  formmodified=0; // do not warn user, just save.
151  return false;
152  });
153  // used to process the cmd+s and ctrl+s events
154  $(document).keydown(function (event) {
155  if (event.which === 83 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) {
156  event.preventDefault();
157  $('#savebutton').click(); // SAVE FORM AFTER PRESSING STRG-S hotkey
158  formmodified=0; // do not warn user, just save.
159  // save(event);
160  return false;
161  }
162  });
163  }
164  saveHotkey();
165 
166 
167  var savebutton = ('#savebutton');
168  var savebuttonIcon = ('#savebuttonIcon');
169  // ok, lets go...
170  // we need to check if user clicked on save button
171  $(savebutton).click(function() {
172  $(savebutton).removeClass('btn btn-success').addClass('btn btn-warning disabled');
173  $(savebuttonIcon).removeClass('fa fa-check').addClass('fa fa-spinner fa-spin fa-fw');
174  });
175  }); // end document ready
176 </script>
177 
178 
179 <?php
180 // TEMPLATE WRAPPER - HEADER & breadcrumbs
181 echo "
182  <!-- Content Wrapper. Contains page content -->
183  <div class=\"content-wrapper\" id=\"content-FX\">
184  <!-- Content Header (Page header) -->
185  <section class=\"content-header\">";
186 // draw Title on top
187 echo backend::getTitle($lang['TPL'], $lang['TPL_ASSETS_SETTINGS']);
188 echo backend::getTemplateBreadcrumbs($lang);
189 echo"</section><!-- Main content -->
190  <section class=\"content\">";
191 /* page content start here */
192 ?>
193 <form id="template-edit-form" action="index.php?page=template-assets&action=setup&id=<?php echo $template->id; ?>" method="POST">
194  <!-- title header -->
195  <!-- REDESIGN -->
196  <div class="box">
197  <div class="box-body">
198  <div class="col-md-10">
199  <?php echo "<h4><i class=\"fa fa-puzzle-piece\"></i> &nbsp;$lang[ASSETS] <small>$lang[TPL_ASSETS_SUBTEXT]</small></h4>"; ?>
200  </div>
201  <div class="col-md-2">
202  <button class="btn btn-success pull-right" type="submit" value="save" id="savebutton" name="save" style="margin-top:2px;"><i class="fa fa-check" id="savebuttonIcon"></i>&nbsp;&nbsp;<?php echo $lang['DESIGN_SAVE']; ?></button>
203  </div>
204  </div>
205  </div>
206 <!-- SETTINGS -->
207 <div class="row animated fadeIn">
208 
209  <div class="col-md-4">
210  <div class="box box-default">
211  <div class="box-header with-border">
212  <h3 class="box-title"><?php echo $lang['SYSTEM_ASSETS']; ?></h3>
213  </div>
214  <div class="box-body">
215  <?php template::drawAssetsSelectFields($db, 1, $template->id, $lang); ?>
216  </div>
217  </div>
218  </div>
219  <div class="col-md-4">
220 
221  <div class="box box-default">
222  <div class="box-header with-border">
223  <h3 class="box-title"><?php echo $lang['OPTIONAL_ASSETS']; ?></h3>
224  </div>
225  <div class="box-body">
226  <?php template::drawAssetsSelectFields($db, 2, $template->id, $lang); ?>
227  </div>
228  </div>
229  </div>
230  <div class="col-md-4">
231  <div class="box box-default">
232  <div class="box-header with-border">
233  <h3 class="box-title"><?php echo $lang['USER_DEFINED_ASSETS']; ?></h3>
234  </div>
235  <div class="box-body">
236  <?php template::drawAssetsSelectFields($db, 3, $template->id, $lang); ?>
237  </div>
238  </div>
239  </div>
240 </div>
241 </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
c jPlayer event
type
Definition: menu-new.php:35
$type
print $page title
Definition: page-edit.php:377
print $_GET['id']
Definition: page-edit.php:357
function i(e, t)
Definition: plyr.js:1
<!-- backend language -->< h3 >< i class="fa fa-language"></i > & nbsp
$template name
if(!isset($template)) if(!isset($user)) $getID
$previewButton
$value
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);});})