Exemplo n.º 1
0
 public function actionSave()
 {
     $dwInput = $this->_input->filter(array('event_id' => XenForo_Input::STRING, 'description' => XenForo_Input::STRING, 'callback_class' => XenForo_Input::STRING, 'callback_method' => XenForo_Input::STRING, 'hint' => XenForo_Input::STRING, 'addon_id' => XenForo_Input::STRING));
     if (!empty($dwInput['event_id']) && empty($dwInput['description']) && empty($dwInput['callback_class']) && empty($dwInput['callback_class']) && !empty($dwInput['hint']) && !empty($dwInput['addon_id'])) {
         /** @var XenForo_Model_AddOn $addOnModel */
         $addOnModel = $this->getModelFromCache('XenForo_Model_AddOn');
         $addOn = $addOnModel->getAddOnById($dwInput['addon_id']);
         /** @var DevHelper_Model_Config $configModel */
         $configModel = $this->getModelFromCache('DevHelper_Model_Config');
         $config = $configModel->loadAddOnConfig($addOn);
         if (strpos($dwInput['event_id'], 'load_class') === 0) {
             $classPath = DevHelper_Generator_File::getClassPath($dwInput['hint']);
             if (is_file($classPath)) {
                 $method = DevHelper_Generator_Code_Listener::generateLoadClass($dwInput['hint'], $addOn, $config);
                 if ($method) {
                     $clazz = DevHelper_Generator_Code_Listener::getClassName($addOn, $config);
                     $this->_request->setParam('description', $dwInput['hint']);
                     $this->_request->setParam('callback_class', $clazz);
                     $this->_request->setParam('callback_method', $method);
                     XenForo_DataWriter::create('XenForo_DataWriter_CodeEventListener');
                 }
             }
         }
     }
     return parent::actionSave();
 }
Exemplo n.º 2
0
 public static function generateXfcpClass($clazz, $realClazz, DevHelper_Config_Base $config)
 {
     $ghostClazz = str_replace($config->getClassPrefix(), $config->getClassPrefix() . '_DevHelper_XFCP', $clazz);
     $ghostPath = DevHelper_Generator_File::getClassPath($ghostClazz);
     if (file_exists($ghostPath)) {
         // ghost file exists, yay!
         return true;
     }
     $ghostContents = "<?php\n\nclass XFCP_{$clazz} extends {$realClazz}\n{\n}\n";
     return DevHelper_Generator_File::filePutContents($ghostPath, $ghostContents);
 }
Exemplo n.º 3
0
 public function actionCodeEventListenersHint()
 {
     $q = $this->_input->filterSingle('q', XenForo_Input::STRING);
     $classes = array();
     /** @var XenForo_Application $app */
     $app = XenForo_Application::getInstance();
     $libraryPath = sprintf('%s/library/', $app->getRootDir());
     if (strlen($q) > 0 && preg_match('/[A-Z]/', $q)) {
         $dirPath = '';
         $pattern = '';
         $classPath = DevHelper_Generator_File::getClassPath($q);
         if (is_file($classPath)) {
             $classes[] = $q;
         }
         $_dirPath = preg_replace('/\\.php$/', '', $classPath);
         if (is_dir($_dirPath)) {
             $dirPath = $_dirPath;
         } else {
             $_parentDirPath = dirname($_dirPath);
             if (is_dir($_parentDirPath)) {
                 $dirPath = $_parentDirPath;
                 $pattern = basename($_dirPath);
             }
         }
         if ($dirPath !== '') {
             $files = scandir($dirPath);
             foreach ($files as $file) {
                 if (substr($file, 0, 1) === '.') {
                     continue;
                 }
                 if ($pattern !== '' && strpos($file, $pattern) !== 0) {
                     continue;
                 }
                 $filePath = sprintf('%s/%s', $dirPath, $file);
                 if (is_file($filePath)) {
                     $contents = file_get_contents($filePath);
                     if (preg_match('/class\\s(?<class>.+?)(\\sextends|{)/', $contents, $matches)) {
                         $classes[] = $matches['class'];
                     }
                 } elseif (is_dir($filePath)) {
                     $classes[] = str_replace('/', '_', str_replace($libraryPath, '', $filePath));
                 }
             }
         }
     }
     $results = array();
     foreach ($classes as $class) {
         $results[$class] = $class;
     }
     $view = $this->responseView();
     $view->jsonParams = array('results' => $results);
     return $view;
 }
Exemplo n.º 4
0
 public function getDataClass($name)
 {
     $name = $this->_normalizeDbName($name);
     if (!$this->checkDataClassExists($name)) {
         return array();
     }
     $dataClass = $this->_dataClasses[$name];
     foreach ($dataClass['files'] as &$file) {
         if (!empty($file)) {
             $path = DevHelper_Generator_File::getClassPath($file['className']);
             $hash = DevHelper_Generator_File::calcHash($path);
             if ($hash != $file['hash']) {
                 $file['changed'] = true;
             }
         }
     }
     return $dataClass;
 }
Exemplo n.º 5
0
 protected static function _write(array $addOn, DevHelper_Config_Base $config, $contents)
 {
     $className = self::getClassName($addOn, $config);
     $path = DevHelper_Generator_File::getClassPath($className);
     return DevHelper_Generator_File::writeFile($path, $contents, true, false) === true;
 }