debugTable . ' VALUES(NULL, %s, %s, %s, %s)'; $db->query($sql, date('Y-m-d H:i:s'), $value, $caller, $name); } catch (Exception $e) { echo InstapageCmsPluginConnector::escapeHTML($e->getMessage()); } } /** * Clears the debug log. */ public function clear() { $db = InstapageCmsPluginDBModel::getInstance(); $sql = 'DELETE FROM ' . $db->debugTable; $db->query($sql); } /** * Gets the entries from debug log. * * @return array List of entries. */ public function read() { $db = InstapageCmsPluginDBModel::getInstance(); $sql = 'SELECT * FROM ' . $db->debugTable; $results = $db->getResults($sql); return $results; } /** * Gets the HTML with debug log. Template for th og is in /templates/log.php file. * * @return string Log in HTML format. */ public function getLogHTML() { if (InstapageCmsPluginConnector::currentUserCanManage() && $this->isDiagnosticMode()) { try { $pluginsHtml = InstapageCmsPluginConnector::getSelectedConnector()->getPluginsDebugHTML(); $optionsHtml = InstapageCmsPluginConnector::getSelectedConnector()->getOptionsDebugHTML(); $phpinfoHtml = $this->getPhpInfoHTML(); $rows = $this->read(); $view = InstapageCmsPluginViewModel::getInstance(); $view->init(INSTAPAGE_PLUGIN_PATH . '/templates/log.php'); $view->rows = $rows; $view->currentDate = date("Ymd_His"); $view->dbStructure = $this->getDbStructure(); $view->pluginsHtml = $pluginsHtml; $view->optionsHtml = $optionsHtml; $view->phpinfoHtml = $phpinfoHtml; $html = $view->fetch(); return $html; } catch (Exception $e) { throw $e; } } else { throw new Exception(__('Instapage log can be downloaded only in diagnostic mode.')); } } /** * Gets phpinfo and formats it. * * @return string Info about PHP in HTML format. */ private function getPhpInfoHTML() { ob_start(); phpinfo(INFO_GENERAL | INFO_CREDITS | INFO_CONFIGURATION | INFO_MODULES | INFO_ENVIRONMENT | INFO_VARIABLES); $contents = ob_get_contents(); ob_end_clean(); $pattern = '//s'; $contents = preg_replace($pattern, '', $contents); $contents = '
' . $contents . '
'; return $contents; } /** * Gets database structure * * @uses InstapageCmsPluginDBModel::getInstance() * * @return array Array of table structure descriptions */ protected function getDbStructure() { $db = InstapageCmsPluginDBModel::getInstance(); $tablesDescriptions = array(); // get description of tables $sql = 'DESCRIBE ' . $db->pagesTable; $tablesDescriptions[] = [ 'tableName' => $db->pagesTable, 'description' => $db->getResults($sql) ]; $sql = 'DESCRIBE ' . $db->optionsTable; $tablesDescriptions[] = [ 'tableName' => $db->optionsTable, 'description' => $db->getResults($sql) ]; $sql = 'DESCRIBE ' . $db->debugTable; $tablesDescriptions[] = [ 'tableName' => $db->debugTable, 'description' => $db->getResults($sql) ]; return $tablesDescriptions; } }