public static function getList() { $serverKey = MagentoDebugger::getKeyFromString($_SERVER['SERVER_NAME']); $profilerDir = MagentoDebugger::getDebuggerVarDir() . '/profiler'; $dir = opendir($profilerDir); $files = array(); while ($item = readdir($dir)) { $pathinfo = pathinfo($item); if (!isset($pathinfo['extension']) || $pathinfo['extension'] != 'jshe') { continue; } if (substr($item, 0, strlen($serverKey) + 1) != $serverKey . '.') { continue; } $headerJson = file_get_contents($profilerDir . '/' . $item); if (!$headerJson) { continue; } $header = json_decode(trim($headerJson)); $time = $header->time; $header->time = @date('Y.m.d H:i:s', $time); $files[$time] = $header; } sort($files); echo json_encode($files); }
public static function enableProfiler($status = true) { self::$_profilerEnabled = $status; if (!$status) { return; } require_once MagentoDebugger::getProjectDir() . '/lib/Varien/Profiler.php'; //require_once(self::getDebuggerDir() . '/libs/Varien/Profiler.php'); Varien_Profiler::enable(); $serverKey = MagentoDebugger::getKeyFromString(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'console'); $time = time(); self::$_uniqId = $time . '_' . uniqid(); self::$_jsonLog = MagentoDebugger::getDebuggerVarDir() . '/profiler/' . $serverKey . '.' . self::$_uniqId; $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'Not specified'; $profilerHeader = array('time' => $time, 'url' => $url, 'key' => self::$_uniqId); file_put_contents(self::$_jsonLog . '.jshe', json_encode($profilerHeader)); }
public static function run($version = null) { if (!$version) { throw new Exception('Can not update version becouse version does not specified.', self::ERROR_VERSION_NOT_SPECIFIED); } $updatePath = MagentoDebugger::getDebuggerDir(); //$updatePath = '/home/tereta/Work/Server/MagentoDebugger_2'; if (!self::verifyPermissions($updatePath)) { throw new Exception("Wrong permitions for files to update", self::ERROR_PRIVILEGES); } $updateDir = MagentoDebugger::getDebuggerVarDir() . '/update'; if (is_dir($updateDir)) { MagentoDebugger::removeDirectory($updateDir); } mkdir($updateDir); // Downloading $sourceUrl = 'https://github.com/w3site/magento_debugger_backend/archive/version-' . $version . '.zip'; $saveFile = $updateDir . '/downloaded.zip'; $copyed = @copy($sourceUrl, $saveFile); if (!$copyed) { throw new Exception(error_get_last()['message'], self::ERROR_CAN_NOT_DOWNLOAD); } // Unzip if (!class_exists('ZipArchive')) { throw new Exception('ZipArchive class does not found, please install and configure php to work with this extension class.', self::ERROR_ZIP); } $zip = new ZipArchive(); $res = $zip->open($saveFile); $zip->extractTo($updateDir); $zip->close(); // Prepare files $updateVersionDir = $updateDir . '/magento_debugger_backend-version-' . $version; $dirResource = opendir($updateVersionDir); while ($item = readdir($dirResource)) { if ($item == '.' || $item == '..') { continue; } if (in_array($item, self::$_excludeUpdateFiles)) { MagentoDebugger::removeDirectory($updateVersionDir . '/' . $item); } } // Update self::updateFiles($updateVersionDir, $updatePath, true); return true; }
public static function getList() { $serverKey = MagentoDebugger::getKeyFromString($_SERVER['SERVER_NAME']); $mailDir = MagentoDebugger::getDebuggerVarDir() . '/mails'; $dir = opendir($mailDir); $files = array(); while ($item = readdir($dir)) { $pathinfo = pathinfo($item); if (!isset($pathinfo['extension']) || $pathinfo['extension'] != 'json') { continue; } $itemConfigurationString = file_get_contents($mailDir . '/' . $item); $itemConfiguration = (array) json_decode($itemConfigurationString); $itemConfiguration['identifier'] = $pathinfo['filename']; $itemConfiguration['time'] = filemtime($mailDir . '/' . $item); $itemConfiguration['datetime'] = @date('Y-m-d H:i:s', $itemConfiguration['time']); $files[$itemConfiguration['time'] . '_' . uniqid()] = $itemConfiguration; } sort($files); echo json_encode($files); }
Varien_Db_Adapter_Pdo_Mysql::setLogCallStack(); } if ($_COOKIE['magento_debug_mysql'] == 'all') { Varien_Db_Adapter_Pdo_Mysql::setLogQueryTime(); } if ($_COOKIE['magento_debug_mysql'] == 'value' && isset($_COOKIE['magento_debug_mysql'])) { Varien_Db_Adapter_Pdo_Mysql::setLogQueryTime((double) $_COOKIE['magento_debug_mysql']); } } // Blocks debug if (isset($_COOKIE['magento_debug_blocks']) && $_COOKIE['magento_debug_blocks'] == 'yes') { require_once 'libs/Mage/Core/Block/Template.php'; } if (isset($_GET['magento_debug'])) { if ($_GET['magento_debug'] == 'message' && isset($_POST['message'])) { $file = MagentoDebugger::getDebuggerVarDir() . '/ajax-console.log'; file_put_contents($file, $_POST['message'] . "\n", FILE_APPEND); return; } if ($_GET['magento_debug'] == 'model' && isset($_GET['magento_debug_model_method'])) { $modelMethodName = $_GET['magento_debug_model_method']; header('Content-Type: text/plain'); require_once MagentoDebugger::getDebuggerDir() . '/libs/Debugger/model.php'; } if ($_GET['magento_debug'] == 'maillist' && isset($_GET['magento_debug_action'])) { require_once MagentoDebugger::getDebuggerDir() . '/libs/Debugger/mails.php'; } if ($_GET['magento_debug'] == 'profiler' && isset($_GET['magento_debug_action'])) { require_once MagentoDebugger::getDebuggerDir() . '/libs/Debugger/profiler.php'; } if ($_GET['magento_debug'] == 'mysql' && isset($_GET['magento_debug_action'])) {
<?php require_once dirname(__FILE__) . '/libs/Debugger/debugger.php'; MagentoDebugger::setDebuggerDir(dirname(__FILE__)); $targetDir = MagentoDebugger::getDebuggerDir(); require_once MagentoDebugger::getDebuggerDir() . '/libs/Debugger/update.php'; $filePermissions = fileperms(MagentoDebugger::getDebuggerVarDir() . '/required.version'); $dirPermissions = fileperms(MagentoDebugger::getDebuggerVarDir() . '/required.dir'); $owner = fileowner(MagentoDebugger::getDebuggerVarDir() . '/required.version'); $fixed = MagentoDebugger_Update::fixPermissions($targetDir, $owner, $filePermissions, $dirPermissions);
/** * Send mail to recipient * * @param array|string $email E-mail(s) * @param array|string|null $name receiver name(s) * @param array $variables template variables * @return boolean **/ public function send($email, $name = null, array $variables = array()) { if (!$this->isValidForSend()) { Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted return false; } $emails = array_values((array) $email); $names = is_array($name) ? $name : (array) $name; $names = array_values($names); foreach ($emails as $key => $email) { if (!isset($names[$key])) { $names[$key] = substr($email, 0, strpos($email, '@')); } } $variables['email'] = reset($emails); $variables['name'] = reset($names); ini_set('SMTP', Mage::getStoreConfig('system/smtp/host')); ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); $mail = $this->getMail(); $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH); switch ($setReturnPath) { case 1: $returnPathEmail = $this->getSenderEmail(); break; case 2: $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL); break; default: $returnPathEmail = null; break; } if ($returnPathEmail !== null) { $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $returnPathEmail); Zend_Mail::setDefaultTransport($mailTransport); } $debugToArray = array(); foreach ($emails as $key => $email) { array_push($debugToArray, $email); $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?='); } $this->setUseAbsoluteLinks(true); $text = $this->getProcessedTemplate($variables, true); $this->_mailDebuggerInfo->setEmailSubject($this->getProcessedTemplateSubject($variables)); $this->_mailDebuggerInfo->setEmailBody($text); $this->_mailDebuggerInfo->setEmailIsPlan($this->isPlain()); $this->_mailDebuggerInfo->setBacktrace(Varien_Debug::backtrace(true)); if ($this->isPlain()) { $mail->setBodyText($text); } else { $mail->setBodyHTML($text); } $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?='); $mail->setFrom($this->getSenderEmail(), $this->getSenderName()); $this->_mailDebuggerInfo->setEmailTo(implode("; ", $debugToArray)); $this->_mailDebuggerInfo->setEmailFrom($mail->getFrom()); $jsonDebugData = Mage::helper('core')->jsonEncode($this->_mailDebuggerInfo->getData()); $serverKey = MagentoDebugger::getKeyFromString(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'console'); $jsonDebugFile = MagentoDebugger::getDebuggerVarDir() . '/mails/' . $serverKey . '.' . time() . '_' . uniqid() . '.json'; if (!is_dir(MagentoDebugger::getDebuggerVarDir() . '/mails/')) { mkdir(MagentoDebugger::getDebuggerVarDir() . '/mails/'); } //file_put_contents($jsonDebugFile . '.html', $text); file_put_contents($jsonDebugFile, $jsonDebugData); try { $mail->send(); $this->_mail = null; } catch (Exception $e) { $this->_mail = null; Mage::logException($e); return false; } return true; }