1: <?php
  2: require_once('../qcubed.inc.php');
  3: 
  4: class PluginEditForm extends QForm {        
  5:       6:   7: 
  8:     private $objPlugin = null;
  9:     
 10:     private $strPluginType; 
 11:     
 12:     protected $lblName;
 13:     protected $lblDescription;
 14:     protected $lblPluginVersion;
 15:     protected $lblPlatformVersion;
 16:     protected $lblAuthorName;
 17:     protected $lblAuthorEmail;
 18:     protected $lblFiles;
 19:     protected $dlgStatus;
 20:     
 21:     protected $btnInstall;
 22:     protected $btnCancelInstallation;
 23:     protected $btnUninstall;
 24:     
 25:     const TYPE_INSTALLING_NEW = "new";
 26:     const TYPE_VIEWING_ALREADY_INSTALLED = "installed";
 27:     
 28:     protected function Form_Run() {
 29:         QApplication::CheckRemoteAdmin();
 30:     }
 31: 
 32:     protected function Form_Create() {
 33:         $strPluginName = QApplication::QueryString('strName');
 34:         $this->strPluginType = QApplication::QueryString('strType');
 35:         if (!isset($strPluginName) || !isset($this->strPluginType) ||
 36:             strlen($strPluginName) == 0 || strlen($this->strPluginType) == 0) {
 37:             throw new Exception("Mandatory parameter was not set");
 38:         }
 39:         
 40:         if ($this->strPluginType == self::TYPE_VIEWING_ALREADY_INSTALLED) {
 41:             $installedPlugins = QPluginConfigParser::parseInstalledPlugins();
 42:             
 43:             foreach ($installedPlugins as $item) {
 44:                 if ($item->strName == $strPluginName) {
 45:                     $this->objPlugin = $item;
 46:                 }
 47:             }
 48:         } else if ($this->strPluginType == self::TYPE_INSTALLING_NEW) {
 49:             $configFile = __INCLUDES__ . QPluginInstaller::PLUGIN_EXTRACTION_DIR .
 50:                             $strPluginName . '/' . QPluginInstaller::PLUGIN_CONFIG_FILE;
 51:             $this->objPlugin = QPluginConfigParser::parseNewPlugin($configFile);
 52:         } else {
 53:             throw new Exception("Invalid value of the type URL parameter: " . $this->strPluginType);
 54:         }
 55:         
 56:         if ($this->objPlugin == null) {
 57:             throw new Exception ("Plugin not found: " . $strPluginName);
 58:         }
 59:         
 60:         $this->lblName_Create();
 61:         $this->lblDescription_Create();
 62:         $this->lblPluginVersion_Create();
 63:         $this->lblPlatformVersion_Create();
 64:         $this->lblAuthorName_Create();
 65:         $this->lblAuthorEmail_Create();
 66:         $this->lblFiles_Create();
 67:         $this->dlgStatus_Create();
 68:         
 69:         $this->btnInstall_Create();
 70:         $this->btnCancelInstallation_Create();
 71:         $this->btnUninstall_Create();
 72:         
 73:         $this->objDefaultWaitIcon = new QWaitIcon($this);
 74:     }
 75:     
 76:     private function dlgStatus_Create(){
 77:         $this->dlgStatus = new QDialogBox($this);
 78: 
 79:         
 80:         
 81:         $this->dlgStatus->Width = '500px';
 82:         $this->dlgStatus->Height = 'auto';
 83:         $this->dlgStatus->Overflow = QOverflow::Auto;
 84:         $this->dlgStatus->Padding = '10px';
 85:         $this->dlgStatus->MatteClickable = false;
 86:         $this->dlgStatus->Display = false;
 87:     }
 88:     
 89:     private function btnInstall_Create() {
 90:         $this->btnInstall = new QButton($this);
 91:         $this->btnInstall->Text = "Install this Plugin";
 92:         $this->btnInstall->AddAction(new QClickEvent(), new QAjaxAction('btnInstall_click'));
 93:         
 94:         if ($this->strPluginType != self::TYPE_INSTALLING_NEW) {
 95:             $this->btnInstall->Visible = false;
 96:         }
 97:     }
 98:     
 99:     public function btnInstall_Click() {
100:         list($status, $log) = QPluginInstaller::installFromExpanded(QApplication::QueryString('strName'));
101:         
102:         $linkToProceed = "<h2><a href='plugin_manager.php'>Click here to continue</a></h2>";
103:         $this->dlgStatus->Text = $status.'<br/>'.$linkToProceed.'<a href="#" onclick="jQuery(\'#install_details\').toggle()">Details</a><div id="install_details" style="display:none;border:1px solid black;height:300px; overflow-y:auto;margin-top:20px;padding:10px;">'.nl2br($log).'</div>';
104:         $this->dlgStatus->ShowDialogBox();
105:     }
106:     
107:     private function btnUninstall_Create() {
108:         $this->btnUninstall = new QButton($this);
109:         $this->btnUninstall->Text = "Uninstall (delete) this Plugin";
110:         $this->btnUninstall->AddAction(new QClickEvent(), new QConfirmAction('Are you SURE you want to uninstall this plugin?'));
111:         $this->btnUninstall->AddAction(new QClickEvent(), new QAjaxAction('btnUninstall_click'));
112:         
113:         if ($this->strPluginType != self::TYPE_VIEWING_ALREADY_INSTALLED) {
114:             $this->btnUninstall->Visible = false;
115:         }
116:     }
117:     
118:     public function btnUninstall_Click() {
119:         list($status,$log) = QPluginUninstaller::uninstallExisting(QApplication::QueryString('strName'));
120: 
121:         $linkToProceed = "<h2><a href='plugin_manager.php'>Click here to continue</h2></a>";
122:         $this->dlgStatus->Text = $status.'<br/>'.$linkToProceed.'<a href="#" onclick="jQuery(\'#uninstall_details\').toggle()">Details</a><div id="uninstall_details" style="display:none;border:1px solid black;height:300px; overflow-y:auto;margin-top:20px;padding:10px;">'.nl2br($log).'</div>';
123:         $this->dlgStatus->ShowDialogBox();
124:     }
125: 
126: 
127:     private function btnCancelInstallation_Create() {
128:         $this->btnCancelInstallation = new QButton($this);
129:         $this->btnCancelInstallation->Text = "Cancel Installation";
130:         $this->btnCancelInstallation->AddAction(new QClickEvent(), new QAjaxAction('btnCancelInstallation_click'));
131: 
132:         if ($this->strPluginType != self::TYPE_INSTALLING_NEW) {
133:             $this->btnCancelInstallation->Visible = false;
134:         }
135:     }
136:     
137:     public function btnCancelInstallation_click() {
138:         QPluginInstaller::cleanupExtractedFiles(QApplication::QueryString('strName'));
139:         self::redirectToListPage();
140:     }
141:             
142:     private function lblName_Create() {
143:         $this->lblName = new QLabel($this);
144:         $this->lblName->Text = $this->objPlugin->strName;
145:         $this->lblName->Name = QApplication::Translate('Title');
146:     }
147:     
148:     private function lblDescription_Create() {
149:         $this->lblDescription = new QLabel($this);
150:         $this->lblDescription->Text = $this->objPlugin->strDescription;
151:         $this->lblDescription->Name = QApplication::Translate('Description');
152:     }
153:     
154:     private function lblPluginVersion_Create() {
155:         $this->lblPluginVersion = new QLabel($this);
156:         $this->lblPluginVersion->Text = $this->objPlugin->strVersion;
157:         $this->lblPluginVersion->Name = QApplication::Translate('Plugin Version');
158:     }
159:     
160:     private function lblPlatformVersion_Create() {
161:         $this->lblPlatformVersion = new QLabel($this);
162:         $this->lblPlatformVersion->Text = $this->objPlugin->strPlatformVersion;
163:         $this->lblPlatformVersion->Name = QApplication::Translate('Compatible QCubed Version');
164:     }
165:     
166:     private function lblAuthorName_Create() {
167:         $this->lblAuthorName = new QLabel($this);
168:         $this->lblAuthorName->Text = $this->objPlugin->strAuthorName;
169:         $this->lblAuthorName->Name = QApplication::Translate('Author');
170:     }
171:     
172:     private function lblAuthorEmail_Create() {
173:         $this->lblAuthorEmail = new QLabel($this);
174:         $this->lblAuthorEmail->Name = QApplication::Translate('Author\'s email');
175:         $this->lblAuthorEmail->HtmlEntities = false;
176: 
177:         if (strlen($this->objPlugin->strAuthorEmail) > 0) {     
178:             $email = $this->objPlugin->strAuthorEmail;
179:             
180:             
181:             $email = str_replace(" ", "", $email);
182:             $braceOpen = "[\<\[{\(]";
183:             $braceClosed = "[\]}\)\>]";
184:             
185:             $email = preg_replace("/" . $braceOpen . "at" . $braceClosed . "/", "@", $email);
186:             $email = preg_replace("/" . $braceOpen . "dot" . $braceClosed . "/", ".", $email);
187:             
188:             $this->lblAuthorEmail->Text = "<a href='mailto:{$email}'>{$email}</a>";
189:         }
190:     }
191: 
192:     private function lblFiles_Create() {
193:         $this->lblFiles = new QLabel($this);
194:         $this->lblFiles->Name = QApplication::Translate("Contains: ");
195:         $this->lblFiles->Text = count($this->objPlugin->objAllFilesArray) . ' ' . QApplication::Translate("file(s)") . "; ";
196:         $this->lblFiles->Text .=  count($this->objPlugin->objIncludesArray) . ' ' . QApplication::Translate("include(s)") . "; ";
197:         $this->lblFiles->Text .=  count($this->objPlugin->objExamplesArray) . ' ' . QApplication::Translate("example(s)");
198:     }
199:     
200:     private function redirectToListPage() {
201:         QApplication::Redirect('plugin_manager.php');
202:     }
203: }
204: 
205: PluginEditForm::Run('PluginEditForm');