Skip to content

Commit abc65b9

Browse files
committed
Initial Public Release
1 parent e69fb91 commit abc65b9

File tree

266 files changed

+42612
-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.

266 files changed

+42612
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @package ExpandableFAQ
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace ExpandableFAQ\Controllers\Admin;
9+
use ExpandableFAQ\Models\Configuration\ConfigurationInterface;
10+
use ExpandableFAQ\Models\Language\LanguageInterface;
11+
use ExpandableFAQ\Models\Cache\StaticSession;
12+
use ExpandableFAQ\Models\Settings\SettingsObserver;
13+
use ExpandableFAQ\Models\Validation\StaticValidator;
14+
use ExpandableFAQ\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 sanitation 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+
$printDebugMessage = StaticValidator::inWPDebug() ? StaticSession::getHTMLOnce('admin_debug_message') : '';
35+
$printErrorMessage = StaticSession::getValueOnce('admin_error_message');
36+
$printOkayMessage = 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->debugMessage = $printDebugMessage;
44+
$this->view->errorMessage = $printErrorMessage;
45+
$this->view->okayMessage = $printOkayMessage;
46+
}
47+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 ExpandableFAQ
6+
* @author KestutisIT
7+
* @copyright KestutisIT
8+
* @license MIT License. See Legal/License.txt for details.
9+
*/
10+
namespace ExpandableFAQ\Controllers\Admin;
11+
use ExpandableFAQ\Models\Configuration\ConfigurationInterface;
12+
use ExpandableFAQ\Models\Language\LanguageInterface;
13+
use ExpandableFAQ\Models\Node\LinkedNode;
14+
use ExpandableFAQ\Models\Node\LinkedNodesObserver;
15+
use ExpandableFAQ\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 sanitation 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->getPrint('DATATABLES_LANG').'.json';
42+
if(is_readable($this->conf->getRouting()->get3rdPartyAssetsPath($dataTablesRelPath.$dataTablesLangFilename)) === FALSE)
43+
{
44+
$dataTablesLangFilename = 'English.json';
45+
}
46+
47+
$extVars = array(
48+
'DATATABLES_LANG_URL' => $this->conf->getRouting()->get3rdPartyAssetsURL($dataTablesRelURL.$dataTablesLangFilename, TRUE),
49+
);
50+
$extLang = array(
51+
'LANG_FAQ_DELETING_DIALOG_TEXT' => $this->lang->getPrint('LANG_FAQ_DELETING_DIALOG_TEXT'),
52+
);
53+
54+
if(static::$mandatoryPlainJSInitialized === FALSE)
55+
{
56+
static::$mandatoryPlainJSInitialized = TRUE;
57+
?>
58+
<script type="text/javascript">var <?=$this->conf->getPluginJS_ClassPrefix();?>Vars;</script>
59+
<script type="text/javascript">var <?=$this->conf->getPluginJS_ClassPrefix();?>Lang;</script>
60+
<?php
61+
}
62+
?>
63+
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Vars = <?=json_encode($extVars, JSON_FORCE_OBJECT);?>;</script>
64+
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Lang = <?=json_encode($extLang, JSON_FORCE_OBJECT);?>;</script>
65+
<?php
66+
}
67+
68+
public function registerScripts()
69+
{
70+
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
71+
{
72+
// Debug scripts
73+
74+
// 1. Datatables with Responsive support
75+
wp_register_script('datatables-jquery-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/jquery.dataTables.js'));
76+
wp_register_script('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/dataTables.jqueryui.js'));
77+
wp_register_script('datatables-responsive-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/dataTables.responsive.js'));
78+
wp_register_script('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/responsive.jqueryui.js'));
79+
} else
80+
{
81+
// Regular scripts
82+
83+
// 1. Datatables with Responsive support
84+
wp_register_script('datatables-jquery-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/jquery.dataTables.min.js'));
85+
wp_register_script('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/js/dataTables.jqueryui.min.js'));
86+
wp_register_script('datatables-responsive-datatables', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/dataTables.responsive.min.js'));
87+
wp_register_script('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/js/responsive.jqueryui.min.js'));
88+
}
89+
90+
// 2. jQuery validate
91+
wp_register_script('jquery-validate', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-validation/jquery.validate.js'));
92+
93+
// 3. NS Admin script
94+
$filename = $this->conf->getPluginJS_ClassPrefix().'Admin.js';
95+
wp_register_script($this->conf->getPluginHandlePrefix().'admin', $this->conf->getRouting()->getAdminJS_URL($filename), array(), '1.0', TRUE);
96+
}
97+
98+
public function registerStyles()
99+
{
100+
// Register 3rd party styles for further use (register even it the file is '' - WordPress will process that as needed)
101+
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
102+
{
103+
// Debug style
104+
105+
// 1. Font-Awesome styles
106+
wp_register_style('font-awesome', $this->conf->getRouting()->get3rdPartyAssetsURL('font-awesome/css/font-awesome.css'));
107+
108+
// 2. Modern tabs styles
109+
wp_register_style('modern-tabs', $this->conf->getRouting()->get3rdPartyAssetsURL('ModernTabs/ModernTabs.css'));
110+
111+
// 3. jQuery UI theme (currently used for DataTables)
112+
wp_register_style('jquery-ui-theme', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-ui/themes/custom/jquery-ui.css'));
113+
114+
// 4. Datatables with Responsive support
115+
wp_register_style('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/css/dataTables.jqueryui.css'));
116+
wp_register_style('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/css/responsive.jqueryui.css'));
117+
} else
118+
{
119+
// Regular style
120+
121+
// 1. Font-Awesome styles
122+
wp_register_style('font-awesome', $this->conf->getRouting()->get3rdPartyAssetsURL('font-awesome/css/font-awesome.min.css'));
123+
124+
// 2. Modern tabs styles
125+
wp_register_style('modern-tabs', $this->conf->getRouting()->get3rdPartyAssetsURL('ModernTabs/ModernTabs.css'));
126+
127+
// 3. jQuery UI theme (currently used for DataTables)
128+
wp_register_style('jquery-ui-theme', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-ui/themes/custom/jquery-ui.min.css'));
129+
130+
// 4. Datatables with Responsive support
131+
wp_register_style('datatables-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/DataTables-1.10.18/css/dataTables.jqueryui.min.css'));
132+
wp_register_style('datatables-responsive-jqueryui', $this->conf->getRouting()->get3rdPartyAssetsURL('DataTables/Responsive-2.2.2/css/responsive.jqueryui.min.css'));
133+
}
134+
135+
// 5. jQuery Validate
136+
wp_register_style('jquery-validate', $this->conf->getRouting()->get3rdPartyAssetsURL('jquery-validation/jquery.validate.css'));
137+
138+
// 6. Plugin style
139+
wp_register_style($this->conf->getPluginURL_Prefix().'admin', $this->conf->getRouting()->getAdminCSS_URL('Admin.css'));
140+
}
141+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* @package ExpandableFAQ
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace ExpandableFAQ\Controllers\Admin\Demos;
9+
use ExpandableFAQ\Models\Configuration\ConfigurationInterface;
10+
use ExpandableFAQ\Models\Formatting\StaticFormatter;
11+
use ExpandableFAQ\Models\Import\DemosObserver;
12+
use ExpandableFAQ\Models\Language\LanguageInterface;
13+
use ExpandableFAQ\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->demosDropdownOptions = $objDemosObserver->getDropdownOptions(0, 0, $this->lang->getPrint('LANG_DEMO_SELECT_TEXT'));
32+
33+
// Get the tab values
34+
$tabs = StaticFormatter::getTabParams(array(
35+
'demos'
36+
), 'demos', isset($_GET['tab']) ? $_GET['tab'] : '');
37+
38+
// 1. Set the view variables - Tab settings
39+
$this->view->demosTabChecked = !empty($tabs['demos']) ? ' checked="checked"' : '';
40+
41+
// Print the template
42+
$templateRelPathAndFileName = 'Demos'.DIRECTORY_SEPARATOR.'Tabs.php';
43+
echo $this->view->render($this->conf->getRouting()->getAdminTemplatesPath($templateRelPathAndFileName));
44+
}
45+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* @package ExpandableFAQ
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace ExpandableFAQ\Controllers\Admin\Demos;
9+
use ExpandableFAQ\Models\Configuration\ConfigurationInterface;
10+
use ExpandableFAQ\Models\Import\Demo;
11+
use ExpandableFAQ\Models\Language\LanguageInterface;
12+
use ExpandableFAQ\Controllers\Admin\AbstractController;
13+
use ExpandableFAQ\Models\Language\LanguagesObserver;
14+
use ExpandableFAQ\Models\Cache\StaticSession;
15+
16+
final class ImportDemoController extends AbstractController
17+
{
18+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
19+
{
20+
parent::__construct($paramConf, $paramLang);
21+
}
22+
23+
private function processImportDemo()
24+
{
25+
$paramDemoId = isset($_POST['demo_id']) ? $_POST['demo_id'] : 0;
26+
27+
// Create mandatory instances
28+
$objDemo = new Demo($this->conf, $this->lang, $paramDemoId);
29+
$objLanguagesObserver = new LanguagesObserver($this->conf, $this->lang);
30+
31+
// Delete all existing content and then insert new content
32+
$objDemo->deleteContent();
33+
// INFO: This plugin does not use custom post types
34+
$objDemo->replaceContent();
35+
36+
// Register newly imported database data for translation
37+
if($this->lang->canTranslateSQL())
38+
{
39+
// If WPML is enabled
40+
$objLanguagesObserver->registerAllForTranslation();
41+
}
42+
43+
// INFO: This plugin does not use custom post types
44+
45+
StaticSession::cacheHTMLArray('admin_debug_message', $objDemo->getDebugMessages());
46+
StaticSession::cacheValueArray('admin_okay_message', $objDemo->getOkayMessages());
47+
StaticSession::cacheValueArray('admin_error_message', $objDemo->getErrorMessages());
48+
49+
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'demos&tab=demos');
50+
exit;
51+
}
52+
53+
/**
54+
* @throws \Exception
55+
* @return void
56+
*/
57+
public function printContent()
58+
{
59+
// First - process actions
60+
if(isset($_POST['import_demo'])) { $this->processImportDemo(); }
61+
}
62+
}

Controllers/Admin/Demos/index.html

Whitespace-only changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* @package ExpandableFAQ
4+
* @author KestutisIT
5+
* @copyright KestutisIT
6+
* @license MIT License. See Legal/License.txt for details.
7+
*/
8+
namespace ExpandableFAQ\Controllers\Admin\FAQ;
9+
use ExpandableFAQ\Models\Configuration\ConfigurationInterface;
10+
use ExpandableFAQ\Models\FAQ\FAQ;
11+
use ExpandableFAQ\Models\Language\LanguageInterface;
12+
use ExpandableFAQ\Controllers\Admin\AbstractController;
13+
use ExpandableFAQ\Models\Cache\StaticSession;
14+
15+
final class AddEditFAQ_Controller extends AbstractController
16+
{
17+
public function __construct(ConfigurationInterface &$paramConf, LanguageInterface &$paramLang)
18+
{
19+
parent::__construct($paramConf, $paramLang);
20+
}
21+
22+
private function processDelete($paramFAQId)
23+
{
24+
$objFAQ = new FAQ($this->conf, $this->lang, $this->dbSets->getAll(), $paramFAQId);
25+
$objFAQ->delete();
26+
27+
StaticSession::cacheHTMLArray('admin_debug_message', $objFAQ->getDebugMessages());
28+
StaticSession::cacheValueArray('admin_okay_message', $objFAQ->getOkayMessages());
29+
StaticSession::cacheValueArray('admin_error_message', $objFAQ->getErrorMessages());
30+
31+
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'faq-manager&tab=faqs');
32+
exit;
33+
}
34+
35+
private function processSave($paramFAQ_Id)
36+
{
37+
// Create mandatory instances
38+
$objFAQ = new FAQ($this->conf, $this->lang, $this->dbSets->getAll(), $paramFAQ_Id);
39+
40+
$saved = $objFAQ->save($_POST);
41+
if($saved && $this->lang->canTranslateSQL())
42+
{
43+
$objFAQ->registerForTranslation();
44+
}
45+
46+
StaticSession::cacheHTMLArray('admin_debug_message', $objFAQ->getDebugMessages());
47+
StaticSession::cacheValueArray('admin_okay_message', $objFAQ->getOkayMessages());
48+
StaticSession::cacheValueArray('admin_error_message', $objFAQ->getErrorMessages());
49+
50+
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'faq-manager&tab=faqs');
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_faq'])) { $this->processDelete($_GET['delete_faq']); }
62+
if(isset($_POST['save_faq'], $_POST['faq_id'])) { $this->processSave($_POST['faq_id']); }
63+
64+
$paramFAQId = isset($_GET['faq_id']) ? $_GET['faq_id'] : 0;
65+
$objFAQ = new FAQ($this->conf, $this->lang, $this->dbSets->getAll(), $paramFAQId);
66+
$localDetails = $objFAQ->getDetails();
67+
68+
// Set the view variables
69+
$this->view->backToListURL = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'faq-manager&tab=faqs');
70+
$this->view->formAction = admin_url('admin.php?page='.$this->conf->getPluginURL_Prefix().'add-edit-faq&noheader=true');
71+
if(!is_null($localDetails))
72+
{
73+
$this->view->faqId = $localDetails['faq_id'];
74+
$this->view->faqQuestion = $localDetails['edit_faq_question'];
75+
$this->view->faqAnswer = $localDetails['edit_faq_answer'];
76+
$this->view->faqOrder = $localDetails['faq_order'];
77+
} else
78+
{
79+
$this->view->faqId = 0;
80+
$this->view->faqQuestion = '';
81+
$this->view->faqAnswer = '';
82+
$this->view->faqOrder = '';
83+
}
84+
85+
// Print the template
86+
$templateRelPathAndFileName = 'FAQ'.DIRECTORY_SEPARATOR.'AddEditFAQ_Form.php';
87+
echo $this->view->render($this->conf->getRouting()->getAdminTemplatesPath($templateRelPathAndFileName));
88+
}
89+
}

0 commit comments

Comments
 (0)