public static function updateConfig($key, $value)
 {
     /** @var XenForo_Application $app */
     $app = XenForo_Application::getInstance();
     $path = $app->getRootDir() . '/library/config.php';
     $originalContents = file_get_contents($path);
     $varNamePattern = '#(\\n|^)(?<varName>\\$config';
     foreach (explode('.', $key) as $i => $keyPart) {
         // try to match the quote
         $varNamePattern .= '\\[([\'"]?)' . preg_quote($keyPart, '#') . '\\' . ($i + 3) . '\\]';
     }
     $varNamePattern .= ').+(\\n|$)#';
     $candidates = array();
     $offset = 0;
     while (true) {
         if (!preg_match($varNamePattern, $originalContents, $matches, PREG_OFFSET_CAPTURE, $offset)) {
             break;
         }
         $offset = $matches[0][1] + strlen($matches[0][0]);
         $candidates[] = $matches;
     }
     if (count($candidates) !== 1) {
         XenForo_Helper_File::log(__METHOD__, sprintf('count($candidates) = %d', count($candidates)));
         return;
     }
     $matches = reset($candidates);
     $replacement = $matches[1][0] . $matches['varName'][0] . ' = ' . var_export($value, true) . ';' . $matches[5][0];
     $contents = substr_replace($originalContents, $replacement, $matches[0][1], strlen($matches[0][0]));
     DevHelper_Generator_File::writeFile($path, $contents, true, false);
 }
 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();
 }
Beispiel #3
0
 public function prepareParams()
 {
     if (!empty($this->_params['addOn']) && empty($this->_params['serverFile'])) {
         $addOn = $this->_params['addOn'];
         $this->_params['serverFile'] = DevHelper_Generator_File::getAddOnXmlPath($addOn);
     }
     parent::prepareParams();
 }
 public static function checkForUpdate($path)
 {
     if (strpos($path, '/ShippableHelper/') !== false) {
         $contents = DevHelper_Generator_File::fileGetContents($path);
         if (preg_match('#class\\s(?<class>[^\\s]+_ShippableHelper_[^\\s]+)\\s#', $contents, $matches)) {
             class_exists($matches['class']);
         }
     }
 }
Beispiel #5
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);
 }
Beispiel #6
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;
 }
 public static function getViewClassName(array $addOn, DevHelper_Config_Base $config, array $dataClass, $view)
 {
     return DevHelper_Generator_File::getClassName($addOn['addon_id'], 'ViewAdmin_' . $dataClass['camelCase'] . '_' . ucwords($view));
 }
Beispiel #8
0
 public static function getClassName(array $addOn, DevHelper_Config_Base $config, array $dataClass)
 {
     return DevHelper_Generator_File::getClassName($addOn['addon_id'], 'DataWriter_' . $dataClass['camelCase']);
 }
Beispiel #9
0
 public function actionFileExport()
 {
     $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING);
     $addOn = $this->_getAddOnOrError($addOnId);
     $config = $this->_getConfigModel()->loadAddOnConfig($addOn);
     $exportPath = $config->getExportPath();
     if ($exportPath === false) {
         return $this->responseNoPermission();
     }
     echo '<pre>';
     DevHelper_Generator_File::fileExport($addOn, $config, $exportPath);
     echo '</pre>';
     die('done');
 }
Beispiel #10
0
 public function actionFileExport()
 {
     $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING);
     $addOn = $this->_getAddOnOrError($addOnId);
     $config = $this->_getConfigModel()->loadAddOnConfig($addOn);
     $exportPath = $config->getExportPath();
     if ($exportPath === false) {
         return $this->responseNoPermission();
     }
     DevHelper_Helper_Phrase::startLookingForPhraseTitles();
     DevHelper_Helper_Xfcp::startLookingForXfcpClasses();
     echo '<pre>';
     DevHelper_Generator_File::fileExport($addOn, $config, $exportPath);
     /** @var XenForo_Model_Template $templateModel */
     $templateModel = $this->getModelFromCache('XenForo_Model_Template');
     $templates = $templateModel->getMasterTemplatesInAddOn($addOn['addon_id']);
     foreach ($templates as $template) {
         /** @var DevHelper_XenForo_DataWriter_Template $dw */
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template');
         $dw->setExistingData($template, true);
         if ($dw->DevHelper_saveTemplate()) {
             echo "Saved template {$template['title']}\n";
         }
     }
     /** @var XenForo_Model_Phrase $phraseModel */
     $phraseModel = $this->getModelFromCache('XenForo_Model_Phrase');
     $phrases = $phraseModel->getMasterPhrasesInAddOn($addOnId);
     DevHelper_Helper_Phrase::finishLookingForPhraseTitles($phrases, $phraseModel);
     DevHelper_Helper_Xfcp::finishLookingForXfcpClasses($addOn, $config);
     echo '</pre>';
     DevHelper_Generator_Code_XenForoConfig::updateConfig('development.default_addon', $addOn['addon_id']);
     die('Done');
 }
Beispiel #11
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;
 }
Beispiel #12
0
 protected function _processJsUrls(array $jsFiles)
 {
     DevHelper_Generator_File::minifyJs($jsFiles);
     return parent::_processJsUrls($jsFiles);
 }
Beispiel #13
0
    public function outputSelf()
    {
        $className = get_class($this);
        foreach ($this->_dataClasses as $dataClass) {
            if (empty($dataClass['id_field'])) {
                throw new XenForo_Exception("{$dataClass['name']} does not have an id_field.", true);
            }
        }
        $dataClasses = DevHelper_Generator_File::varExport($this->_dataClasses);
        $dataPatches = DevHelper_Generator_File::varExport($this->_dataPatches);
        $exportPath = DevHelper_Generator_File::varExport($this->_exportPath);
        $contents = <<<EOF
<?php
class {$className} extends DevHelper_Config_Base {
\tprotected \$_dataClasses = {$dataClasses};
\tprotected \$_dataPatches = {$dataPatches};
\tprotected \$_exportPath = {$exportPath};
\t
\t/**
\t * Return false to trigger the upgrade!
\t * common use methods:
\t * \tpublic function addDataClass(\$name, \$fields = array(), \$primaryKey = false, \$indeces = array())
\t *\tpublic function addDataPatch(\$table, array \$field)
\t *\tpublic function setExportPath(\$path)
\t**/
\tprotected function _upgrade() {
\t\treturn true; // remove this line to trigger update
\t\t
\t\t/*
\t\t\$this->addDataClass(
\t\t\t'name_here',
\t\t\tarray( // fields
\t\t\t\t'field_here' => array(
\t\t\t\t\t'type' => 'type_here',
\t\t\t\t\t// 'length' => 'length_here',
\t\t\t\t\t// 'required' => true,
\t\t\t\t\t// 'allowedValues' => array('value_1', 'value_2'), 
\t\t\t\t),
\t\t\t\t// other fields go here
\t\t\t),
\t\t\t'primary_key_field_here',
\t\t\tarray( // indeces
\t\t\t\tarray(
\t\t\t\t\t'fields' => array('field_1', 'field_2'),
\t\t\t\t\t'type' => 'NORMAL', // UNIQUE or FULLTEXT
\t\t\t\t),
\t\t\t),
\t\t);
\t\t*/
\t}
}
EOF;
        return $contents;
    }
Beispiel #14
0
 public function saveAddOnConfig($addOn, DevHelper_Config_Base $config)
 {
     $className = DevHelper_Generator_File::getClassName($addOn['addon_id'], 'DevHelper_Config');
     DevHelper_Generator_File::write($className, $config->outputSelf());
 }
Beispiel #15
0
    public function outputSelf()
    {
        $className = get_class($this);
        $dataClasses = DevHelper_Generator_File::varExport($this->_dataClasses);
        $dataPatches = DevHelper_Generator_File::varExport($this->_dataPatches);
        $exportPath = DevHelper_Generator_File::varExport($this->_exportPath);
        $exportIncludes = DevHelper_Generator_File::varExport($this->_exportIncludes);
        $exportExcludes = DevHelper_Generator_File::varExport($this->_exportExcludes);
        $exportAddOns = DevHelper_Generator_File::varExport($this->_exportAddOns);
        $exportStyles = DevHelper_Generator_File::varExport($this->_exportStyles);
        $options = DevHelper_Generator_File::varExport($this->_options);
        $contents = <<<EOF
<?php

class {$className} extends DevHelper_Config_Base
{
    protected \$_dataClasses = {$dataClasses};
    protected \$_dataPatches = {$dataPatches};
    protected \$_exportPath = {$exportPath};
    protected \$_exportIncludes = {$exportIncludes};
    protected \$_exportExcludes = {$exportExcludes};
    protected \$_exportAddOns = {$exportAddOns};
    protected \$_exportStyles = {$exportStyles};
    protected \$_options = {$options};

    /**
     * Return false to trigger the upgrade!
     **/
    protected function _upgrade()
    {
        return true; // remove this line to trigger update

        /*
        \$this->addDataClass(
            'name_here',
            array( // fields
                'field_here' => array(
                    'type' => 'type_here',
                    // 'length' => 'length_here',
                    // 'required' => true,
                    // 'allowedValues' => array('value_1', 'value_2'),
                    // 'default' => 0,
                    // 'autoIncrement' => true,
                ),
                // other fields go here
            ),
            array('primary_key_1', 'primary_key_2'), // or 'primary_key', both are okie
            array( // indeces
                array(
                    'fields' => array('field_1', 'field_2'),
                    'type' => 'NORMAL', // UNIQUE or FULLTEXT
                ),
            ),
        );
        */
    }
}
EOF;
        return $contents;
    }
Beispiel #16
0
 public static function getClassName(array $addOn, DevHelper_Config_Base $config)
 {
     return DevHelper_Generator_File::getClassName($addOn['addon_id'], 'Installer');
 }
 public static function getClassName(array $addOn, DevHelper_Config_Base $config, array $dataClass)
 {
     return DevHelper_Generator_File::getClassName($addOn['addon_id'], 'Route_PrefixAdmin_' . $dataClass['camelCase'], $config);
 }