1: <?php
2:
3: require_once('../qcubed.inc.php');
4:
5: class PluginManagerForm extends QForm {
6: // Local instance of the Meta DataGrid to list Addresses
7: protected $dtgPlugins;
8: protected $btnNewPlugin;
9: protected $dlgUpload;
10:
11: private $objPluginArray;
12:
13: protected function Form_Run() {
14: QApplication::CheckRemoteAdmin();
15: }
16:
17: protected function Form_Create() {
18: $this->dtgPlugins_Create();
19: //$this->btnNewPlugin_Create();
20: //$this->dlgUpload_Create();
21: }
22:
23: private function btnNewPlugin_Create() {
24: $this->btnNewPlugin = new QButton($this);
25: $this->btnNewPlugin->Text = "Install a New Plugin";
26: $this->btnNewPlugin->AddAction(new QClickEvent(), new QAjaxAction('btnNewPlugin_Click'));
27: }
28: /*
29: public function btnNewPlugin_Click() {
30: $this->dlgUpload->ShowDialogBox();
31: }*/
32:
33: private function dtgPlugins_Create() {
34: $this->dtgPlugins = new QDataGrid($this, 'dtgPlugins');
35: $this->dtgPlugins->SetDataBinder('dtgPlugins_Bind');
36:
37: $this->dtgPlugins->CssClass = 'datagrid';
38:
39: $this->dtgPlugins->CreateIndexedColumn('Name', 'Name');
40: $this->dtgPlugins->CreateIndexedColumn('Description', 'Description');
41: $col = $this->dtgPlugins->CreateCallableColumn('Examples', [$this, 'RenderExampleLink']);
42: $col->HtmlEntities = false;
43: }
44:
45: public function dtgPlugins_Bind() {
46: if (!is_dir(__PLUGINS__)) {
47: return;
48: }
49: $pluginDirArray = scandir ( __PLUGINS__);
50: $itemArray = array();
51:
52: foreach ($pluginDirArray as $dirItem) {
53: $strComposerFilePath = __PLUGINS__ . '/' . $dirItem . '/' .'composer.json';
54: if (file_exists($strComposerFilePath)) {
55: $composerDetails = json_decode(file_get_contents($strComposerFilePath ), true);
56:
57: $arrayItem['Name'] = $dirItem;
58: $arrayItem['Description'] = '';
59: if (!empty($composerDetails['description'])) {
60: $arrayItem['Description'] = $composerDetails['description'];
61: }
62: $arrayItem['Examples'] = null;
63: if (!empty($composerDetails['extra']['examples'])) { // embed example page name into composer file for convenience
64: foreach ($composerDetails['extra']['examples'] as $strExample) {
65: $strExamplePath = __PLUGINS__ . '/' . $dirItem . '/examples/' . $strExample;
66: if (file_exists ($strExamplePath)) {
67: $arrayItem['Examples'][] = $strExample;
68: }
69: }
70: }
71: $itemArray[] = $arrayItem;
72: }
73: }
74: $this->dtgPlugins->DataSource = $itemArray;
75: }
76: /*
77: public function RenderDescription($objItem) {
78: $exampleSnippet = "";
79:
80: if (sizeof($objItem->objExamplesArray) > 0) {
81: $exampleSnippet .= "<br />";
82: foreach ($objItem->objExamplesArray as $example) {
83: $exampleSnippet .= "Example: <a href='" .
84: __PLUGIN_ASSETS__ . '/' . $objItem->strName . '/' .
85: $example->strFilename . "'>" . $example->strDescription . "</a><br>";
86: }
87: }
88:
89: return $objItem->strDescription . $exampleSnippet;
90: }*/
91:
92: public function RenderExampleLink($item) {
93: if ($item['Examples']) {
94: $strRet = '';
95: foreach ($item['Examples'] as $strItem) {
96: $strRet .= '<a href="' . __PLUGIN_ASSETS__ . '/' . $item['Name'] . '/examples/' . $strItem .
97: '">' . QApplication::HtmlEntities($strItem) . '</a><br />';
98: }
99: return $strRet;
100: }
101: return null;
102: }
103: /*
104: private function dlgUpload_Create() {
105: $this->dlgUpload = new QFileAssetDialog($this, 'dlgUpload_done');
106: $this->dlgUpload->Title = "Install a New Plugin";
107: $this->dlgUpload->Width = null; // auto width
108: $this->dlgUpload->lblMessage->Text = "<p>Please upload a plugin .zip file.</p>" .
109: "<p>You can get the latest plugins from the " .
110: "<a target='_blank' href='" . QPluginInstaller::ONLINE_PLUGIN_REPOSITORY .
111: "'>online repository</a>.</p>";
112: $this->dlgUpload->btnUpload->Text = "Upload";
113: $this->dlgUpload->btnCancel->Text = "Cancel";
114: }
115:
116: public function dlgUpload_done($strFormId, $strControlId, $strParameter) {
117: $this->dlgUpload->HideDialogBox();
118:
119: $originalFileName = $this->dlgUpload->flcFileAsset->FileName;
120: if (strtolower(substr($originalFileName, -3)) != "zip") {
121: QApplication::DisplayAlert("Invalid uploaded plugin file - only ZIP allowed: " . $originalFileName);
122: return;
123: }
124:
125: $pluginFolder = QPluginInstaller::installPluginFromZip($this->dlgUpload->flcFileAsset->File);
126:
127: if ($pluginFolder == null) {
128: QApplication::DisplayAlert(QPluginInstaller::getLastError());
129: return;
130: }
131:
132: QApplication::Redirect('plugin_edit.php?strType=new&strName=' . $pluginFolder);
133: }
134: */
135: }
136:
137: PluginManagerForm::Run('PluginManagerForm');