YaWK  24.1
Yet another WebKit
newsletter.php
Go to the documentation of this file.
1 <?php
3 {
4  /**
5  * @details<b>Let your users subscribe to a newsletter database.</b>
6  *
7  * <p>With this widget, you are able to collect email addresses to build up your newsletter database.
8  * The user can enter his email address and (or) his/hers name. The form will be processed via ajax
9  * which means the page will not refresh by clicking on submit. Data will be entered in the newsletter
10  * database, which other plugins and widgets can access easily. In future releases, it is planned to
11  * implement a newsletter plugin, where admins can manage and send newsletters within the backend.</p>
12  *
13  *
14  * @author Daniel Retzl <[email protected]>
15  * @copyright 2018 Daniel Retzl
16  * @version 1.0.0
17  * @brief Embed any YouTube Video on your pages.
18  */
19  class newsletter
20  {
21  /** @param object global widget object data */
22  public $widget = '';
23  /** @param string Title Text */
24  public $newsletterTitle = 'Newsletter';
25  /** @param string Thank You Subtext */
26  public $newsletterSubtext = 'subscribe';
27  /** @param string Thank You Title Text */
28  public $newsletterThankYouTitle = 'Thank You';
29  /** @param string Thank You SubText */
30  public $newsletterThankYouSubtext = 'for subscribing to our newsletter!';
31  /** @param string Button Text */
32  public $newsletterBtnText = 'Subscribe Newsletter';
33  /** @param string Button CSS Class */
34  public $newsletterBtnClass = 'btn btn-success';
35  /** @param string Name Field Placeholder */
36  public $newsletterNamePlaceholder = 'Name';
37  /** @param string Email Field Placeholder */
38  public $newsletterEmailPlaceholder = 'Email';
39  /** @param string Button Button Margin Top */
40  public $newsletterBtnMarginTop = '5px';
41  /** @param string Button Button Alignment */
42  public $newsletterBtnAlign = 'text-center';
43  /** @param string Hide Form Labels? */
44  public $newsletterHideLabels = 'false';
45  /** @param string Newsletter Icon (eg. font awesome or glyphicons) */
46  public $newsletterIcon = 'fa fa-envelope-o';
47  /** @param string Font size of icon, heading and subtext */
48  public $newsletterFontSize = 'h2';
49  /** @param string Width of the form elements */
50  public $newsletterWidth = '';
51  /** @param string Btn Margin HTML Markup */
52  public $markupBtnMarginTop = '';
53  /** @param string Btn Class HTML Markup */
54  public $markupBtnClass = '';
55  /** @param string Btn Alignment HTML Markup */
56  public $markupBtnAlign = '';
57  /** @param string Name Label HTML Markup */
58  public $markupNameLabel = '';
59  /** @param string Email Label HTML Markup */
60  public $markupEmailLabel = '';
61  /** @param string Icon HTML Markup */
62  public $markupIcon = '';
63  /** @param string Font Size (H1-H6) HTML Markup Start */
64  public $markupFontSizeStart = '<H2>';
65  /** @param string Font Size (H1-H6) HTML Markup End */
66  public $markupFontSizeEnd = '</H2>';
67  /** @param string Form width HTML Markup */
68  public $markupFormWidth = '';
69 
70  /**
71  * @brief Load all widget settings from database and fill object params
72  * @param object $db Database Object
73  * @brief Load all widget settings on object init.
74  */
75  public function __construct($db)
76  {
77  // load this widget settings from db
78  $this->widget = new \YAWK\widget();
80  foreach ($settings as $property => $value) {
81  $this->$property = $value;
82  }
83  }
84 
85  /**
86  * @brief Print all object data
87  * @brief (for development and testing purpose)
88  */
89  public function printObject()
90  {
91  echo "<pre>";
92  print_r($this);
93  echo "</pre>";
94  }
95 
96  /**
97  * @brief Init Function: Loads the required JS, set properties and draw the form
98  * @brief This method does the setup and embed job
99  */
100  public function init()
101  {
102  // load required javascript files
103  $this->includeJS();
104  // prepare properties and settings
105  $this->setProperties();
106  // lets start - draw newsletter form
107  $this->drawForm();
108  }
109 
110  /**
111  * @brief Load all required javascript files
112  * @brief include required javascript assets (validade, messages and ajax js file)
113  */
114  public function includeJS()
115  {
116  // load validate js
117  echo "<script type=\"text/javascript\" src=\"system/engines/jquery/jquery.validate.min.js\"></script>";
118  // if current language is german
119  if (\YAWK\language::getCurrentLanguageStatic() == "de-DE")
120  { // load german language file
121  echo "<script type=\"text/javascript\" src=\"system/engines/jquery/messages_de.min.js\"></script>";
122  }
123  // load ajax file
124  echo "<script type=\"text/javascript\" src=\"system/widgets/newsletter/js/nl.js\"></script>";
125  }
126 
127  /**
128  * @brief Set all object properties and html markup codes depending on current widget settings
129  * @brief Set object properties and html markup
130  */
131  public function setProperties()
132  {
133  // check if btn margin top is set
134  if (isset($this->newsletterBtnMarginTop) && (!empty($this->newsletterBtnMarginTop)))
135  { // set markup
136  $this->markupBtnMarginTop = " style=\"margin-top:$this->newsletterBtnMarginTop\"";
137  }
138  else
139  { // no btn margin set, leave markup empty
140  $this->markupBtnMarginTop = '';
141  }
142 
143  // check btn class and alignment
144  if (isset($this->newsletterBtnClass) && (!empty($this->newsletterBtnClass)))
145  { // set markup
146  $this->markupBtnClass = "$this->newsletterBtnClass";
147  }
148  else
149  { // no btn margin set, leave markup empty
150  $this->markupBtnClass = '';
151  }
152 
153  // check button alignment
154  if (isset($this->newsletterBtnAlign) && (!empty($this->newsletterBtnAlign)))
155  { // set btn align markup
156  $this->markupBtnAlign = " class=\"$this->newsletterBtnAlign\"";
157  }
158  else
159  { // no markup needed, leave empty
160  $this->markupBtnAlign = '';
161  }
162 
163  // check if labels should be hidden
164  if (isset($this->newsletterHideLabels) && ($this->newsletterHideLabels == "false"))
165  { // label html markup code
166  $this->markupNameLabel = "<label for=\"name\">$this->newsletterNamePlaceholder</label>";
167  $this->markupEmailLabel = "<br><label for=\"email\">$this->newsletterEmailPlaceholder</label>";
168  }
169  else
170  { // no labels
171  $this->markupNameLabel = '';
172  $this->markupEmailLabel = '';
173  }
174 
175  // check if icon is set
176  if (isset($this->newsletterIcon) && (!empty($this->newsletterIcon)))
177  { // icon html markup
178  $this->markupIcon = "<i class=\"$this->newsletterIcon\"></i>&nbsp;";
179  }
180  else
181  { // no icon, no markup
182  $this->markupIcon = '';
183  }
184 
185  // check which font size is set
186  if (isset($this->newsletterFontSize) && (!empty($this->newsletterFontSize)))
187  { // set markup for h tags
188  $this->markupFontSizeStart = "<$this->newsletterFontSize>";
189  $this->markupFontSizeEnd = "</$this->newsletterFontSize>";
190  }
191  else
192  { // if font size is not set, use default:
193  $this->markupFontSizeStart = "<H2>";
194  $this->markupFontSizeEnd = "</H2>";
195  }
196 
197  // check if form width is set
198  if (isset($this->newsletterWidth) && (!empty($this->newsletterWidth)))
199  { // check if user appended a % sign
200  if (substr($this->newsletterWidth, -1) != "%")
201  { // if not, append it for the user
202  $this->newsletterWidth = $this->newsletterWidth."%";
203  }
204  // set html markup
205  $this->markupFormWidth = " style=\"width: $this->newsletterWidth;\"";
206  }
207  else
208  { // no width requested, leave empty
209  $this->markupFormWidth = '';
210  }
211  }
212 
213  /**
214  * @brief Draw the newsletter html form
215  *
216  */
217  public function drawForm()
218  {
219  echo"
220  <div class=\"container-fluid\">
221  <div class=\"row\">
222  <div class=\"col-md-12\">
223  <div id=\"formWrapper\">
224  <div id=\"newsletterTitle\">$this->markupFontSizeStart$this->markupIcon$this->newsletterTitle <small>$this->newsletterSubtext</small>$this->markupFontSizeEnd</div>
225  <form class=\"form-horizontal\" id=\"form\" method=\"post\">
226  $this->markupNameLabel
227  <input type=\"text\" name=\"name\" id=\"name\" class=\"form-control\" placeholder=\"$this->newsletterNamePlaceholder\"$this->markupFormWidth>
228  $this->markupEmailLabel
229  <input type=\"text\" name=\"email\" id=\"email\" class=\"form-control\" placeholder=\"$this->newsletterEmailPlaceholder\"$this->markupFormWidth>
230  <input type=\"hidden\" name=\"thankYouTitle\" id=\"thankYouTitle\" value=\"$this->newsletterThankYouTitle\">
231  <input type=\"hidden\" name=\"thankYouSubtext\" id=\"thankYouSubtext\" value=\"$this->newsletterThankYouSubtext\">
232  <div$this->markupBtnAlign$this->markupFormWidth>
233  <input type=\"button\" class=\"$this->markupBtnClass\" id=\"submit\" name=\"submit\" value=\"$this->newsletterBtnText\"$this->markupBtnMarginTop>
234  </div>
235  </form>
236  </div>
237  <div id=\"thankYouMessage\"></div>
238  </div>
239  </div>
240  </div>";
241  }
242  }
243 }
Embed any YouTube Video on your pages.
Definition: newsletter.php:19
includeJS()
Load all required javascript files.
Definition: newsletter.php:113
drawForm()
Draw the newsletter html form.
Definition: newsletter.php:216
init()
Init Function: Loads the required JS, set properties and draw the form.
Definition: newsletter.php:99
__construct($db)
Load all widget settings from database and fill object params.
Definition: newsletter.php:74
setProperties()
Set all object properties and html markup codes depending on current widget settings.
Definition: newsletter.php:130
static getCurrentLanguageStatic()
returns the currently set backend language, but is static callable
Definition: language.php:146
Widgets are small, useful tools that you can include everywhere in your website.
Definition: widget.php:22
getWidgetSettingsArray($db)
Get widget settings and return it as array.
Definition: widget.php:69
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
if(isset($_POST['save'])) $settings
$value