Exemple #1
0
 /**
  * Default run method
  * TODO: Needs more work
  * @return	void
  */
 public function run()
 {
     $this->printMessage('Generating code event listener...');
     $config = XDT_CLI_Application::getConfig();
     $namespace = $config['namespace'] . '_';
     $className = $namespace . 'Listener';
     if (!$namespace) {
         $namespace = '';
     }
     if (!XDT_CLI_Helper::classExists($className, false)) {
         //$extendName = 'XenForo_Controller' . XfCli_Helpers::camelcaseString($type, false) . '_Abstract';
         $class = new Zend_CodeGenerator_Php_Class();
         $class->setName($className);
         //$class->setExtendedClass($extendName);
         XDT_CLI_ClassGenerator::create($className, $class);
         $this->printMessage('ok');
     } else {
         $this->printMessage('skipped (already exists)');
     }
     $this->printMessage($namespace);
     if (!empty($config['name'])) {
         $this->printMessage($this->colorText('Active Add-on: ', XDT_CLI_Abstract::BROWN), false);
         $this->printMessage($config['name']);
     } else {
         $this->printMessage($this->colorText('No add-on selected.', XDT_CLI_Abstract::RED));
     }
 }
 /**
  * Get path of file the class is stored in
  *
  * @param	string			$className
  * @param	bool			$relative
  *
  * @return	string
  */
 public static function getClassPath($className, $relative = false)
 {
     $fileName = XDT_CLI_Autoloader::getFileName($className);
     if ($relative) {
         return $fileName;
     }
     return XDT_CLI_Application::xfBaseDir() . 'library' . DIRECTORY_SEPARATOR . $fileName;
 }
Exemple #3
0
 /**
  * Default run method
  *
  * @return	void
  */
 public function run()
 {
     $config = XDT_CLI_Application::getConfig();
     if (!empty($config['name'])) {
         $this->printMessage($this->colorText('Active Add-on: ', XDT_CLI_Abstract::BROWN), false);
         $this->printMessage($config['name']);
     } else {
         $this->printMessage($this->colorText('No add-on selected.', XDT_CLI_Abstract::RED));
     }
 }
Exemple #4
0
 /**
  * Run the command
  *
  * @param	string			$addonId
  *
  * @return	void
  */
 public function run($addonId)
 {
     // Detect addon
     if (!($addon = $this->getParent()->getAddonById($addonId)) and !($addon = $this->getParent()->getAddonByName($addonId)) and !($addon = $this->getParent()->getAddonByPath($addonId))) {
         $this->bail('Could not find addon: ' . $addonId);
     }
     // Define full file path
     $base = XDT_CLI_Application::xfBaseDir();
     $file = isset($addon['config_file']) ? dirname($addon['config_file']) : '';
     // Validate file path
     if ($this->hasFlag('delete-files') and (empty($file) or !is_dir($base . $file))) {
         $this->bail('Could not locate files');
     }
     // Confirmation
     if (!$this->hasFlag('y')) {
         $this->printMessage('You are about to delete..');
         // Print summary of data that is to be deleted
         if ($this->hasFlag('delete-files')) {
             $files = trim(shell_exec('find ' . $base . $file . ' -type f | wc -l'));
             $folders = trim(shell_exec('find ' . $base . $file . ' -type d | wc -l'));
             $this->printTable(array(array('Addon:', $addon['title'], 'id: ' . $addon['addon_id']), array('Directory:', $file, "{$files} files, {$folders} folders")), '   ', false);
             $this->printEmptyLine();
         } else {
             $this->printEmptyLine();
             $this->printMessage('  Addon: ' . $addon['title'] . ' (' . $addon['addon_id'] . ')');
         }
         // Ask for confirmation
         $this->printEmptyLine();
         $really = $this->confirm('Are you sure you want to do this?');
         $this->printEmptyLine();
         // Fail if not confirmed
         if (!$really) {
             return $this->printMessage('Addon delete canceled');
         }
     }
     // Delete DB data
     $this->printMessage('Deleting DB data.. ', false);
     /** @var XenForo_Model_AddOn $addonModel */
     $addonModel = XenForo_Model::create('XenForo_Model_AddOn');
     $addonModel->deleteAddOnMasterData($addonId);
     $this->printMessage('ok');
     // Delete files
     if ($this->hasFlag('delete-files')) {
         $this->printMessage('Deleting files.. ', false);
         if ($deleted = shell_exec('rm -Rv ' . $base . $file)) {
             $this->printMessage('ok');
         } else {
             $this->bail('failed: ' . $deleted);
         }
     }
     // Done
     $this->printEmptyLine();
     $this->printMessage('Addon delete');
 }
Exemple #5
0
 /**
  * Detect XenForo installation
  *
  * @return	void
  */
 protected static function detectXenForo()
 {
     $ds = DIRECTORY_SEPARATOR;
     $baseDir = getcwd() . $ds;
     if ($baseDir = XDT_CLI_Helper::locate('Application.php', array('XenForo', 'library/XenForo'))) {
         self::$_baseDir = realpath(dirname($baseDir) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR;
     } else {
         echo chr(27) . '[1;31m' . 'A valid XenForo installation could not be found. Aborting.' . chr(27) . '[0m';
         echo "\n";
         die;
     }
 }
Exemple #6
0
 public static function writeToFile($file, $contents, $createPath = false)
 {
     $config = XDT_CLI_Application::getConfig();
     $filePath = dirname($file);
     if (!is_dir($filePath) and $createPath) {
         mkdir($filePath, octdec($config->dir_mask), true);
     }
     if (!is_dir($filePath) or !file_put_contents($file, trim($contents))) {
         XDT_CLI_Abstract::getInstance()->bail("File could not be created: " . $file);
         return false;
     }
     chmod($file, octdec($config['file_mask']));
     return true;
 }
Exemple #7
0
 /**
  * Get file path for class
  *
  * @param		string		$className
  *
  * @return		string|bool
  */
 public static function getClassPath($className)
 {
     $fileName = self::getFileName($className);
     $dirs = array(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
     if (class_exists('XDT_CLI_Application', false)) {
         $xfBase = XDT_CLI_Application::xfBaseDir();
         array_unshift($dirs, $xfBase . 'library' . DIRECTORY_SEPARATOR);
     }
     foreach ($dirs as $dir) {
         if (file_exists($dir . $fileName)) {
             return $dir . $fileName;
         }
     }
     return false;
 }
Exemple #8
0
 public function run()
 {
     $addOnId = $this->getOption('addon-id');
     $config = XDT_CLI_Application::getConfig();
     if (!$addOnId) {
         if (!$config or empty($config['addon_id'])) {
             $this->bail('There is no addon selected and the --addon-id is not set');
         }
         $addOnId = $config['addon_id'];
     }
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn');
     $dw->setExistingData($addOnId);
     $dw->set('active', 0);
     $dw->save();
     $this->printInfo($this->colorText($addOnId . ' was disabled successfully.', self::LIGHT_GREEN));
 }
Exemple #9
0
 /**
  * Attempt to retreive addon config file for given addon
  *
  * @param		array|string		$addon
  *
  * @return		bool|string
  */
 public function getAddonConfigFile($addon)
 {
     // Convert string to the array input we're expecting
     if (is_string($addon)) {
         $addon = array('addon_id' => $addon, 'title' => $addon);
     }
     // Validate input
     if (!is_array($addon) or !isset($addon['addon_id'], $addon['title'])) {
         return false;
     }
     // Define the addon folder names we will be checking for
     $names = array($addon['addon_id'], strtolower($addon['addon_id']), XDT_CLI_Helper::camelcaseString($addon['addon_id'], false), XDT_CLI_Helper::camelcaseString($addon['title'], false));
     // If title contains the '-' character, turn it into folder bits
     $bits = explode('-', $addon['title']);
     if (count($bits) > 1) {
         foreach ($bits as &$bit) {
             $bit = XDT_CLI_Helper::camelcaseString($bit, false);
         }
         $names[] = implode('/', $bits);
         $names[] = strtolower(implode('/', $bits));
     }
     // Set variations (with and without library folder)
     $variations = array();
     foreach ($names as $name) {
         $variations = array_merge($variations, array($name, 'library/' . $name));
     }
     // Locate the config file
     $base = XDT_CLI_Application::xfBaseDir();
     return XDT_CLI_Helper::locate('.xfcli-config', $variations, $base, array($base));
 }
Exemple #10
0
 public function run()
 {
     $config = XDT_CLI_Application::getConfig();
     $this->printMessage($this->colorText('Active Add-on: ', XDT_CLI_Abstract::BROWN), false);
     // TODO: Not yet finished...
 }
Exemple #11
0
 /**
  * Create files and folders
  * 
  * @param	object			$addon
  * 
  * @return	void							
  */
 protected function createStructure(&$addon)
 {
     $this->printMessage('Creating folder structure.. ', false);
     $base = XDT_CLI_Application::xfBaseDir();
     // Check if path option was given
     if ($this->getOption('path')) {
         $path = $this->getOption('path');
         // Check if path given is absolute or relative, requires that relative paths start alphabetical or with a dot
         if (preg_match('/[a-z.]/i', substr($path, 0, 1))) {
             if (substr($path, 0, 7) != 'library') {
                 $path = 'library' . DIRECTORY_SEPARATOR . $path;
                 // prepend library folder
             }
         }
         $addon->path = $path;
     } else {
         // Otherwise generate the path based on addon id
         $addon->path = 'library' . DIRECTORY_SEPARATOR . ucfirst($addon->id);
     }
     // Strip the base path from the addon path
     if (strpos(realpath($addon->path), realpath($base)) === 0) {
         $addon->path = substr(realpath($addon->path), strlen(realpath($base)) + 1);
     }
     // Check if we need to create the directory
     if (!is_dir($base . $addon->path)) {
         if (!mkdir($base . $addon->path, 0755, true)) {
             $this->bail('Could not locate or create addon directory: ' . $addon->path);
         }
         $this->printMessage('ok');
     } else {
         $this->printMessage('skipped (already exists)');
     }
     // Append directory separator at the end of the path
     if (substr($addon->path, -1) != DIRECTORY_SEPARATOR) {
         $addon->path .= DIRECTORY_SEPARATOR;
     }
     if ($pos = strpos($addon->path, 'library/') !== false) {
         $namespace = substr($addon->path, $pos + 7);
         $namespace = substr($namespace, 0, strlen($namespace) - 1);
         $namespace = str_replace(DIRECTORY_SEPARATOR, '_', $namespace);
         $addon->namespace = $namespace;
     }
 }