Skip to content

Commit c20f03a

Browse files
committed
Initial Deals Repo (6.1.7)
1 parent 11610b6 commit c20f03a

File tree

306 files changed

+48785
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+48785
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @package Deals
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace Deals\Controllers\Admin;
9+
use Deals\Models\Configuration\ConfigurationInterface;
10+
use Deals\Models\Language\LanguageInterface;
11+
use Deals\Models\Cache\StaticSession;
12+
use Deals\Models\Settings\SettingsObserver;
13+
use Deals\Models\Validation\StaticValidator;
14+
use Deals\Views\PageView;
15+
16+
abstract class AbstractController
17+
{
18+
protected $conf = NULL;
19+
protected $lang = NULL;
20+
protected $view = NULL;
21+
protected $dbSets = NULL;
22+
23+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
24+
{
25+
// Set class settings
26+
$this->conf = $paramConf;
27+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
28+
$this->lang = $paramLang;
29+
// Set database settings
30+
$this->dbSets = new SettingsObserver($this->conf, $this->lang);
31+
$this->dbSets->setAll();
32+
33+
// Message handler - should always be at the begging of method
34+
$ksesedDebugHTML = StaticValidator::inWP_Debug() ? StaticSession::getKsesedHTML_Once('admin_debug_html') : '';
35+
$errorMessage = StaticSession::getValueOnce('admin_error_message');
36+
$okayMessage = StaticSession::getValueOnce('admin_okay_message');
37+
38+
// Initialize the page view and set it's conf and lang objects
39+
$this->view = new PageView();
40+
$this->view->staticURLs = $this->conf->getRouting()->getFolderURLs();
41+
$this->view->lang = $this->lang->getAll();
42+
$this->view->settings = $this->dbSets->getAll();
43+
$this->view->ksesedDebugHTML = $ksesedDebugHTML;
44+
$this->view->errorMessage = $errorMessage;
45+
$this->view->okayMessage = $okayMessage;
46+
}
47+
}

Controllers/Admin/AssetController.php

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* Initializer class to load admin section
4+
* Final class cannot be inherited anymore. We use them when creating new instances
5+
* @package Deals
6+
* @author KestutisIT
7+
* @copyright KestutisIT
8+
* @license MIT License. See Legal/License.txt for details.
9+
*/
10+
namespace Deals\Controllers\Admin;
11+
use Deals\Models\Configuration\ConfigurationInterface;
12+
use Deals\Models\Language\LanguageInterface;
13+
use Deals\Models\Node\LinkedNode;
14+
use Deals\Models\Node\LinkedNodesObserver;
15+
use Deals\Models\Node\LinkedNodesTable;
16+
17+
final class AssetController
18+
{
19+
private $conf = NULL;
20+
private $lang = NULL;
21+
private static $mandatoryPlainJSInitialized = FALSE;
22+
23+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
24+
{
25+
// Set class settings
26+
$this->conf = $paramConf;
27+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
28+
$this->lang = $paramLang;
29+
}
30+
31+
/**
32+
* We use this method, because WP_LOCALIZE_SCRIPT does not do the great job,
33+
* and even the 'l10n_print_after' param is a backward-compatible feature, that has issues of initializing first or second count
34+
* NOTE: About dynamic properties:
35+
* https://stackoverflow.com/questions/11040472/how-to-check-if-object-property-exists-with-a-variable-holding-the-property-name/30148756
36+
*/
37+
public function enqueueMandatoryPlainJS()
38+
{
39+
$dataTablesRelPath = 'DataTables'.DIRECTORY_SEPARATOR.'Plugins'.DIRECTORY_SEPARATOR.'i18n'.DIRECTORY_SEPARATOR;
40+
$dataTablesRelURL = 'DataTables/Plugins/i18n/';
41+
$dataTablesLangFilename = $this->lang->getText('DATATABLES_LANG').'.json';
42+
if(is_readable($this->conf->getRouting()->get3rdPartyAssetsPath($dataTablesRelPath.$dataTablesLangFilename)) === FALSE)
43+
{
44+
$dataTablesLangFilename = 'English.json';
45+
}
46+
47+
$pluginVars = array(
48+
// NOTE: As this is a JS context, we should use 'esc_js' instead of 'esc_url' even for URL JS var,
49+
// See for more information: https://wordpress.stackexchange.com/a/13580/45227
50+
'DATATABLES_LANG_URL' => esc_js($this->conf->getRouting()->get3rdPartyAssetsURL($dataTablesRelURL.$dataTablesLangFilename, TRUE)),
51+
);
52+
$pluginLang = array(
53+
'LANG_DEAL_DELETING_DIALOG_TEXT' => $this->lang->escJS('LANG_DEAL_DELETING_DIALOG_TEXT'),
54+
);
55+
56+
if(static::$mandatoryPlainJSInitialized === FALSE)
57+
{
58+
static::$mandatoryPlainJSInitialized = TRUE;
59+
?>
60+
<script type="text/javascript">var DealsVars;</script>
61+
<script type="text/javascript">var DealsLang;</script>
62+
<?php
63+
}
64+
?>
65+
<script type="text/javascript">DealsVars = <?=json_encode($pluginVars, JSON_FORCE_OBJECT);?>;</script>
66+
<script type="text/javascript">DealsLang = <?=json_encode($pluginLang, JSON_FORCE_OBJECT);?>;</script>
67+
<?php
68+
}
69+
70+
public function registerScripts()
71+
{
72+
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
73+
{
74+
// Debug scripts
75+
76+
// 1. Datatables with Responsive support
77+
wp_register_script('datatables-jquery-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/jquery.dataTables.js'));
78+
wp_register_script('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/dataTables.jqueryui.js'));
79+
wp_register_script('datatables-responsive-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/dataTables.responsive.js'));
80+
wp_register_script('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/responsive.jqueryui.js'));
81+
} else
82+
{
83+
// Regular scripts
84+
85+
// 1. Datatables with Responsive support
86+
wp_register_script('datatables-jquery-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/jquery.dataTables.min.js'));
87+
wp_register_script('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/dataTables.jqueryui.min.js'));
88+
wp_register_script('datatables-responsive-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/dataTables.responsive.min.js'));
89+
wp_register_script('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/responsive.jqueryui.min.js'));
90+
}
91+
92+
// 2. jQuery validate
93+
wp_register_script('jquery-validate', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-validation/jquery.validate.js'));
94+
95+
// 3. NS Admin script
96+
wp_register_script($this->conf->getPluginHandlePrefix().'admin', $this->conf->getRouting()->getAdminJS_URL('DealsAdmin.js'), array(), '1.0', TRUE);
97+
}
98+
99+
public function registerStyles()
100+
{
101+
// Register 3rd party styles for further use (register even it the file is '' - WordPress will process that as needed)
102+
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
103+
{
104+
// Debug style
105+
106+
// 1. Font-Awesome styles
107+
wp_register_style('font-awesome', $this->conf->getRouting()->get3rdPartyAssetsURL('font-awesome/css/font-awesome.css'));
108+
109+
// 2. Modern tabs styles
110+
wp_register_style('modern-tabs', $this->conf->getRouting()->get3rdPartyAssetsURL('ModernTabs/ModernTabs.css'));
111+
112+
// 3. jQuery UI theme (currently used for DataTables)
113+
wp_register_style('jquery-ui-theme', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-ui/themes/custom/jquery-ui.css'));
114+
115+
// 4. Datatables with Responsive support
116+
wp_register_style('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/css/dataTables.jqueryui.css'));
117+
wp_register_style('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/css/responsive.jqueryui.css'));
118+
} else
119+
{
120+
// Regular style
121+
122+
// 1. Font-Awesome styles
123+
wp_register_style('font-awesome', $this->conf->getRouting()->get3rdPartyAssetsURL('font-awesome/css/font-awesome.min.css'));
124+
125+
// 2. Modern tabs styles
126+
wp_register_style('modern-tabs', $this->conf->getRouting()->get3rdPartyAssetsURL('ModernTabs/ModernTabs.css'));
127+
128+
// 3. jQuery UI theme (currently used for DataTables)
129+
wp_register_style('jquery-ui-theme', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-ui/themes/custom/jquery-ui.min.css'));
130+
131+
// 4. Datatables with Responsive support
132+
wp_register_style('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/css/dataTables.jqueryui.min.css'));
133+
wp_register_style('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/css/responsive.jqueryui.min.css'));
134+
}
135+
136+
// 5. jQuery Validate
137+
wp_register_style('jquery-validate', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-validation/jquery.validate.css'));
138+
139+
// 6. Plugin style
140+
wp_register_style($this->conf->getPluginURL_Prefix().'admin', $this->conf->getRouting()->getAdminCSS_URL('Admin.css'));
141+
}
142+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* @package Deals
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace Deals\Controllers\Admin\Deal;
9+
use Deals\Models\Configuration\ConfigurationInterface;
10+
use Deals\Models\Deal\Deal;
11+
use Deals\Models\Language\LanguageInterface;
12+
use Deals\Controllers\Admin\AbstractController;
13+
use Deals\Models\Cache\StaticSession;
14+
15+
final class AddEditDealController extends AbstractController
16+
{
17+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
18+
{
19+
parent::__construct($paramConf, $paramLang);
20+
}
21+
22+
private function processDelete($paramDealId)
23+
{
24+
$objDeal = new Deal($this->conf, $this->lang, $this->dbSets->getAll(), $paramDealId);
25+
$objDeal->delete();
26+
27+
StaticSession::cacheHTML_Array('admin_debug_html', $objDeal->getDebugMessages());
28+
StaticSession::cacheValueArray('admin_okay_message', $objDeal->getOkayMessages());
29+
StaticSession::cacheValueArray('admin_error_message', $objDeal->getErrorMessages());
30+
31+
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'deal-manager&tab=deals');
32+
exit;
33+
}
34+
35+
private function processSave($paramDealId)
36+
{
37+
// Create mandatory instances
38+
$objDeal = new Deal($this->conf, $this->lang, $this->dbSets->getAll(), $paramDealId);
39+
40+
$saved = $objDeal->save($_POST);
41+
if($saved && $this->lang->canTranslateSQL())
42+
{
43+
$objDeal->registerForTranslation();
44+
}
45+
46+
StaticSession::cacheHTML_Array('admin_debug_html', $objDeal->getDebugMessages());
47+
StaticSession::cacheValueArray('admin_okay_message', $objDeal->getOkayMessages());
48+
StaticSession::cacheValueArray('admin_error_message', $objDeal->getErrorMessages());
49+
50+
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'deal-manager&tab=deals');
51+
exit;
52+
}
53+
54+
/**
55+
* @throws \Exception
56+
* @return void
57+
*/
58+
public function printContent()
59+
{
60+
// Process actions
61+
if(isset($_GET['delete_deal'])) { $this->processDelete($_GET['delete_deal']); }
62+
if(isset($_POST['save_deal'], $_POST['deal_id'])) { $this->processSave($_POST['deal_id']); }
63+
64+
$paramDealId = isset($_GET['deal_id']) ? $_GET['deal_id'] : 0;
65+
$objDeal = new Deal($this->conf, $this->lang, $this->dbSets->getAll(), $paramDealId);
66+
$localDetails = $objDeal->getDetails();
67+
68+
// Set the view variables
69+
$this->view->backToListURL = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'deal-manager&tab=deals');
70+
$this->view->formAction = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'add-edit-deal&noheader=true');
71+
if(!is_null($localDetails))
72+
{
73+
$this->view->dealId = $localDetails['deal_id'];
74+
$this->view->dealTitle = $localDetails['deal_title'];
75+
$this->view->dealImageURL = $localDetails['deal_image_url'];
76+
$this->view->demoDealImage = $localDetails['demo_deal_image'];
77+
$this->view->targetURL = $localDetails['target_url'];
78+
$this->view->dealDescription = $localDetails['deal_description'];
79+
$this->view->dealEnabled = $localDetails['deal_enabled'] == 1;
80+
$this->view->dealOrder = $localDetails['deal_order'];
81+
} else
82+
{
83+
$this->view->dealId = 0;
84+
$this->view->dealTitle = '';
85+
$this->view->dealImageURL = '';
86+
$this->view->demoDealImageURL = 0;
87+
$this->view->targetURL = '';
88+
$this->view->dealDescription = '';
89+
$this->view->dealEnabled = TRUE; // Default is TRUE
90+
$this->view->dealOrder = '';
91+
}
92+
93+
// Print the template
94+
$templateRelPathAndFileName = 'Deal'.DIRECTORY_SEPARATOR.'AddEditDealForm.php';
95+
echo $this->view->render($this->conf->getRouting()->getAdminTemplatesPath($templateRelPathAndFileName));
96+
}
97+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @package Deals
4+
* @note Variables prefixed with 'local' are not used in templates
5+
* @author KestutisIT
6+
* @copyright KestutisIT
7+
* @license MIT License. See Legal/License.txt for details.
8+
*/
9+
namespace Deals\Controllers\Admin\Deal;
10+
use Deals\Controllers\Admin\AbstractController;
11+
use Deals\Models\Configuration\ConfigurationInterface;
12+
use Deals\Models\Deal\DealsObserver;
13+
use Deals\Models\Formatting\StaticFormatter;
14+
use Deals\Models\Language\LanguageInterface;
15+
16+
final class DealController extends AbstractController
17+
{
18+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
19+
{
20+
parent::__construct($paramConf, $paramLang);
21+
}
22+
23+
/**
24+
* @throws \Exception
25+
* @return void
26+
*/
27+
public function printContent()
28+
{
29+
// Create mandatory instances
30+
$objDealsObserver = new DealsObserver($this->conf, $this->lang, $this->dbSets->getAll());
31+
32+
// 1. Set the view variables - Tabs
33+
$this->view->tabs = StaticFormatter::getTabParams(
34+
array('deals'), 'deals', isset($_GET['tab']) ? $_GET['tab'] : ''
35+
);
36+
37+
// 2. Set the view variables - deals tab
38+
$this->view->addNewDealURL = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'add-edit-deal&deal_id=0');
39+
$this->view->trustedAdminDealListHTML = $objDealsObserver->getTrustedAdminListHTML();
40+
41+
// Print the template
42+
$templateRelPathAndFileName = 'Deal'.DIRECTORY_SEPARATOR.'ManagerTabs.php';
43+
echo $this->view->render($this->conf->getRouting()->getAdminTemplatesPath($templateRelPathAndFileName));
44+
}
45+
}

Controllers/Admin/Deal/index.html

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* @package Deals
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace Deals\Controllers\Admin\Demos;
9+
use Deals\Models\Configuration\ConfigurationInterface;
10+
use Deals\Models\Formatting\StaticFormatter;
11+
use Deals\Models\Import\DemosObserver;
12+
use Deals\Models\Language\LanguageInterface;
13+
use Deals\Controllers\Admin\AbstractController;
14+
15+
final class DemosController extends AbstractController
16+
{
17+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
18+
{
19+
parent::__construct($paramConf, $paramLang);
20+
}
21+
22+
/**
23+
* @throws \Exception
24+
* @return void
25+
*/
26+
public function printContent()
27+
{
28+
// Tab - import demo
29+
$objDemosObserver = new DemosObserver($this->conf, $this->lang);
30+
$this->view->importDemoTabFormAction = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'import-demo&noheader=true');
31+
$this->view->trustedDemosDropdownOptionsHTML = $objDemosObserver->getTrustedDropdownOptionsHTML(0, 0, $this->lang->getText('LANG_DEMO_SELECT_TEXT'));
32+
33+
// 1. Set the view variables - Tabs
34+
$this->view->tabs = StaticFormatter::getTabParams(array(
35+
'demos'
36+
), 'demos', isset($_GET['tab']) ? $_GET['tab'] : '');
37+
38+
// Print the template
39+
$templateRelPathAndFileName = 'Demos'.DIRECTORY_SEPARATOR.'Tabs.php';
40+
echo $this->view->render($this->conf->getRouting()->getAdminTemplatesPath($templateRelPathAndFileName));
41+
}
42+
}

0 commit comments

Comments
 (0)