示例#1
0
 /**
  * Calls all init functions of the WCF class.
  */
 public function __construct()
 {
     // add autoload directory
     self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
     // define tmp directory
     if (!defined('TMP_DIR')) {
         define('TMP_DIR', FileUtil::getTempFolder());
     }
     // register additional autoloaders
     require_once WCF_DIR . 'lib/system/api/phpline/phpline.phar';
     require_once WCF_DIR . 'lib/system/api/zend/Loader/StandardAutoloader.php';
     $zendLoader = new ZendLoader(array(ZendLoader::AUTOREGISTER_ZF => true));
     $zendLoader->register();
     $argv = new ArgvParser(array('packageID=i' => ''));
     $argv->setOption(ArgvParser::CONFIG_FREEFORM_FLAGS, true);
     $argv->parse();
     define('PACKAGE_ID', $argv->packageID ?: 1);
     // disable benchmark
     define('ENABLE_BENCHMARK', 0);
     // start initialization
     $this->initDB();
     $this->loadOptions();
     $this->initSession();
     $this->initLanguage();
     $this->initTPL();
     $this->initCoreObjects();
     $this->initApplications();
     // the destructor registered in core.functions.php will only call the destructor of the parent class
     register_shutdown_function(array('wcf\\system\\CLIWCF', 'destruct'));
     $this->initArgv();
     $this->initPHPLine();
     $this->initAuth();
     $this->checkForUpdates();
     $this->initCommands();
 }
	/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::uninstall()
	 */
	public function uninstall() {
		// create ACP-templates list
		$templates = array();
		
		// get ACP-templates from log
		$sql = "SELECT	*
			FROM	wcf".WCF_N."_acp_template
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array($this->installation->getPackageID()));
		while ($row = $statement->fetchArray()) {
			// store acp template with suffix (_$packageID)
			$templates[] = 'acp/templates/'.$row['templateName'].'.tpl';
		}
		
		if (!empty($templates)) {
			// delete template files
			$packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$this->installation->getPackage()->packageDir));
			$deleteEmptyDirectories = $this->installation->getPackage()->isApplication;
			$this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories);
			
			// delete log entries
			parent::uninstall();
		}
	}
示例#3
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // check if file is uploaded or linked
     if (!empty($this->file['tmp_name'])) {
         $this->backup = $this->file['tmp_name'];
     } else {
         if ($this->fileLink != '') {
             //check if file is external url
             if (FileUtil::isURL($this->fileLink)) {
                 try {
                     //download file
                     $this->backup = FileUtil::downloadFileFromHttp($this->fileLink, 'cms_backup');
                 } catch (SystemException $e) {
                     //download failed
                     throw new UserInputException('fileLink', 'downloadFailed');
                 }
             } else {
                 //file not found
                 if (!file_exists($this->fileLink)) {
                     throw new UserInputException('fileLink', 'notFound');
                 } else {
                     $this->backup = $this->fileLink;
                 }
             }
         } else {
             throw new UserInputException('file', 'empty');
         }
     }
 }
 /**
  * Handles uploaded files.
  */
 public function upload()
 {
     // save files
     $files = $this->parameters['__files']->getFiles();
     $file = $files[0];
     try {
         if (!$file->getValidationErrorType()) {
             $data = array('userID' => WCF::getUser()->userID ?: null, 'filename' => $file->getFilename(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
             // save file
             $upload = FileUploadEditor::create($data);
             // move uploaded file
             if (@copy($file->getLocation(), $upload->getLocation())) {
                 @unlink($file->getLocation());
                 // return result
                 return array('uploadID' => $upload->uploadID, 'filename' => $upload->filename, 'filesize' => $upload->filesize, 'formattedFilesize' => FileUtil::formatFilesize($upload->filesize));
             } else {
                 // moving failed; delete file
                 $editor = new FileUploadEditor($upload);
                 $editor->delete();
                 throw new UserInputException('fileUpload', 'uploadFailed');
             }
         }
     } catch (UserInputException $e) {
         $file->setValidationErrorType($e->getType());
     }
     return array('errorType' => $file->getValidationErrorType());
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $returnValues = $this->objectAction->getReturnValues();
     // create folder for pictures of this category
     FileUtil::makePath(NEWS_DIR . 'images/news/' . $returnValues['returnValues']->categoryID . '/');
 }
示例#6
0
	/**
	 * Calls all init functions of the WCF and the WCFACP class. 
	 */
	public function __construct() {
		// add autoload directory
		self::$autoloadDirectories['wcf'] = WCF_DIR . 'lib/';
		
		// define tmp directory
		if (!defined('TMP_DIR')) define('TMP_DIR', FileUtil::getTempFolder());
		
		// start initialization
		$this->initMagicQuotes();
		$this->initDB();
		$this->loadOptions();
		$this->initPackage();
		$this->initSession();
		$this->initLanguage();
		$this->initTPL();
		$this->initCronjobs();
		$this->initCoreObjects();
		
		// prevent application loading during setup
		if (PACKAGE_ID) {
			$this->initApplications();
		}
		
		$this->initBlacklist();
		$this->initAuth();
	}
 /**
  * @see wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/spiderlist/spider');
     if (count($spiders)) {
         // delete old entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
             $name = $xpath->query('name', $spider)->item(0);
             $info = $xpath->query('info', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t(?, ?, ?)";
             $statement = WCF::getDB()->prepareStatement($sql);
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
         }
         // clear spider cache
         CacheHandler::getInstance()->clear(WCF_DIR . 'cache', 'cache.spiders.php');
     }
     // delete tmp file
     @unlink($filename);
 }
示例#8
0
 /**
  * @see	\wcf\system\option\IOptionType::getData()
  */
 public function getData(Option $option, $newValue)
 {
     $this->createUploadHandler($option);
     if ($this->uploadHandlers[$option->optionName] === null) {
         return '';
     }
     $files = $this->uploadHandlers[$option->optionName]->getFiles();
     $file = reset($files);
     // check if file has been uploaded
     if (!$file->getFilename()) {
         // if checkbox is checked, remove file
         if ($newValue) {
             @unlink($option->optionValue);
             return '';
         }
         // use old value
         return $option->optionValue;
     } else {
         if ($option->optionValue) {
             // delete old file first
             @unlink($option->optionValue);
         }
     }
     // determine location the file will be stored at
     $package = PackageCache::getInstance()->getPackage($option->packageID);
     $fileLocation = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir)) . $option->filelocation . '.' . $file->getFileExtension();
     // save file
     move_uploaded_file($file->getLocation(), $fileLocation);
     // return file location as the value to store in the database
     return $fileLocation;
 }
	/**
	 * @see	wcf\system\package\plugin\IPackageInstallationPlugin::install()
	 */
	public function install() {
		parent::install();
		
		// get installation path of package
		$sql = "SELECT	packageDir
			FROM	wcf".WCF_N."_package
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute(array($this->installation->getPackageID()));
		$packageDir = $statement->fetchArray();
		$packageDir = $packageDir['packageDir'];
		
		// get relative path of script
		$path = FileUtil::getRealPath(WCF_DIR.$packageDir);
		
		// reset WCF cache
		CacheHandler::getInstance()->flushAll();
		
		// run script
		$this->run($path.$this->instruction['value']);
		
		// delete script
		if (@unlink($path.$this->instruction['value'])) {
			// delete file log entry
			$sql = "DELETE FROM	wcf".WCF_N."_package_installation_file_log
				WHERE		packageID = ?
						AND filename = ?";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array(
				$this->installation->getPackageID(),
				$this->instruction['value']
			));
		}
	}
 /**
  * @see	\wcf\system\package\plugin\IPackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     $abbreviation = 'wcf';
     $path = '';
     if (isset($this->instruction['attributes']['application'])) {
         $abbreviation = $this->instruction['attributes']['application'];
     } else {
         if ($this->installation->getPackage()->isApplication) {
             $path = FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir);
         }
     }
     if (empty($path)) {
         $dirConstant = strtoupper($abbreviation) . '_DIR';
         if (!defined($dirConstant)) {
             throw new SystemException("Cannot execute script-PIP, abbreviation '" . $abbreviation . "' is unknown");
         }
         $path = constant($dirConstant);
     }
     // reset WCF cache
     CacheHandler::getInstance()->flushAll();
     // run script
     $this->run($path . $this->instruction['value']);
     // delete script
     if (@unlink($path . $this->instruction['value'])) {
         // delete file log entry
         $sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\t\tWHERE\t\tpackageID = ?\n\t\t\t\t\t\tAND filename = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->installation->getPackageID(), $this->instruction['value']));
     }
 }
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // check file location
     if (!@file_exists($additionalData['fileLocation'])) {
         return 0;
     }
     // get image size
     $imageData = @getimagesize($additionalData['fileLocation']);
     if ($imageData === false) {
         return 0;
     }
     $data['width'] = $imageData[0];
     $data['height'] = $imageData[1];
     // check min size
     if ($data['width'] < 48 || $data['height'] < 48) {
         return 0;
     }
     // check image type
     if ($imageData[2] != IMAGETYPE_GIF && $imageData[2] != IMAGETYPE_JPEG && $imageData[2] != IMAGETYPE_PNG) {
         return 0;
     }
     // get file hash
     if (empty($data['fileHash'])) {
         $data['fileHash'] = sha1_file($additionalData['fileLocation']);
     }
     // get user id
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     if (!$data['userID']) {
         return 0;
     }
     // save avatar
     $avatar = UserAvatarEditor::create($data);
     // check avatar directory
     // and create subdirectory if necessary
     $dir = dirname($avatar->getLocation());
     if (!@file_exists($dir)) {
         FileUtil::makePath($dir, 0777);
     }
     // copy file
     try {
         if (!copy($additionalData['fileLocation'], $avatar->getLocation())) {
             throw new SystemException();
         }
         // create thumbnails
         $action = new UserAvatarAction(array($avatar), 'generateThumbnails');
         $action->executeAction();
         // update owner
         $sql = "UPDATE\twcf" . WCF_N . "_user\n\t\t\t\tSET\tavatarID = ?\n\t\t\t\tWHERE\tuserID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($avatar->avatarID, $data['userID']));
         return $avatar->avatarID;
     } catch (SystemException $e) {
         // copy failed; delete avatar
         $editor = new UserAvatarEditor($avatar);
         $editor->delete();
     }
     return 0;
 }
示例#12
0
	/**
	 * Assigns a list of applications to a group and computes cookie domain and path.
	 */
	public function rebuild() {
		if (empty($this->objects)) {
			$this->readObjects();
		}
		
		$sql = "UPDATE	wcf".WCF_N."_application
			SET	cookieDomain = ?,
				cookiePath = ?
			WHERE	packageID = ?";
		$statement = WCF::getDB()->prepareStatement($sql);
		
		// calculate cookie path
		$domains = array();
		foreach ($this->objects as $application) {
			if (!isset($domains[$application->domainName])) {
				$domains[$application->domainName] = array();
			}
			
			$domains[$application->domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
		}
		
		WCF::getDB()->beginTransaction();
		foreach ($domains as $domainName => $data) {
			$path = null;
			foreach ($data as $domainPath) {
				if ($path === null) {
					$path = $domainPath;
				}
				else {
					foreach ($path as $i => $part) {
						if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
							// remove all following elements including current one
							foreach ($path as $j => $innerPart) {
								if ($j >= $i) {
									unset($path[$j]);
								}
							}
							
							// skip to next domain
							continue 2;
						}
					}
				}
			}
			
			$path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
			
			foreach (array_keys($data) as $packageID) {
				$statement->execute(array(
					$domainName,
					$path,
					$packageID
				));
			}
		}
		WCF::getDB()->commitTransaction();
	}
示例#13
0
 /**
  * @see	\cms\system\content\type\IContentType::validate()
  */
 public function validate($data)
 {
     if (!isset($data['video'])) {
         throw new UserInputException('data[video]');
     }
     if (!FileUtil::isURL($data['video'])) {
         throw new UserInputException('data[video]', 'notValid');
     }
 }
示例#14
0
	/**
	 * Removes files matching given pattern.
	 * 
	 * @param	string		$pattern
	 */
	protected function removeFiles($pattern) {
		$directory = FileUtil::unifyDirSeperator(WCF_DIR.'cache/');
		$pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern));
		
		DirectoryUtil::getInstance($directory)->executeCallback(new Callback(function ($filename) {
			if (!@touch($filename, 1)) {
				@unlink($filename);
			}
		}), new Regex('^'.$directory.$pattern.'$', Regex::CASE_INSENSITIVE));
	}
示例#15
0
 /**
  * Creates a new UploadHandler object.
  * 
  * @param	array<mixed>	$rawFileData
  */
 protected function __construct(array $rawFileData)
 {
     if (is_array($rawFileData['name'])) {
         // multiple uploads
         for ($i = 0, $l = count($rawFileData['name']); $i < $l; $i++) {
             $this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], FileUtil::getMimeType($rawFileData['tmp_name'][$i]) ?: $rawFileData['type'][$i]);
         }
     } else {
         $this->files[] = new UploadFile($rawFileData['name'], $rawFileData['tmp_name'], $rawFileData['size'], $rawFileData['error'], FileUtil::getMimeType($rawFileData['tmp_name']) ?: $rawFileData['type']);
     }
 }
示例#16
0
 /**
  * @see	wcf\system\cache\source\ICacheSource::clear()
  */
 public function clear($directory, $filepattern)
 {
     $pattern = preg_quote(FileUtil::addTrailingSlash($directory), '%') . str_replace('*', '.*', str_replace('.', '\\.', $filepattern));
     $apcinfo = apc_cache_info('user');
     $cacheList = $apcinfo['cache_list'];
     foreach ($cacheList as $cache) {
         if (preg_match('%^' . $pattern . '$%i', $cache['info'])) {
             apc_delete($cache['info']);
         }
     }
 }
示例#17
0
 /**
  * Creates a new ActiveStyle object.
  * 
  * @param	Style	$object
  */
 public function __construct(Style $object)
 {
     parent::__construct($object);
     // calculate page logo path
     if (!empty($this->object->data['variables']['page.logo.image']) && !FileUtil::isURL($this->object->data['variables']['page.logo.image']) && StringUtil::substring($this->object->data['variables']['page.logo.image'], 0, 1) !== '/') {
         $this->object->data['variables']['page.logo.image'] = RELATIVE_WCF_DIR . $this->object->data['variables']['page.logo.image'];
     }
     // load icon cache
     $cacheName = 'icon-' . PACKAGE_ID . '-' . $this->styleID;
     CacheHandler::getInstance()->addResource($cacheName, WCF_DIR . 'cache/cache.' . $cacheName . '.php', 'wcf\\system\\cache\\builder\\IconCacheBuilder');
     $this->iconCache = CacheHandler::getInstance()->get($cacheName);
 }
示例#18
0
 /**
  * Assigns a list of applications to a group and computes cookie domain and path.
  */
 public function rebuild()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $sql = "UPDATE\twcf" . WCF_N . "_application\n\t\t\tSET\tcookieDomain = ?,\n\t\t\t\tcookiePath = ?\n\t\t\tWHERE\tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     // calculate cookie path
     $domains = array();
     $regex = new Regex(':[0-9]+');
     foreach ($this->objects as $application) {
         $domainName = $application->domainName;
         if (StringUtil::endsWith($regex->replace($domainName, ''), $application->cookieDomain)) {
             $domainName = $application->cookieDomain;
         }
         if (!isset($domains[$domainName])) {
             $domains[$domainName] = array();
         }
         $domains[$domainName][$application->packageID] = explode('/', FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($application->domainPath)));
     }
     WCF::getDB()->beginTransaction();
     foreach ($domains as $domainName => $data) {
         $path = null;
         foreach ($data as $domainPath) {
             if ($path === null) {
                 $path = $domainPath;
             } else {
                 foreach ($path as $i => $part) {
                     if (!isset($domainPath[$i]) || $domainPath[$i] != $part) {
                         // remove all following elements including current one
                         foreach ($path as $j => $innerPart) {
                             if ($j >= $i) {
                                 unset($path[$j]);
                             }
                         }
                         // skip to next domain
                         continue 2;
                     }
                 }
             }
         }
         $path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path)));
         foreach (array_keys($data) as $packageID) {
             $statement->execute(array($domainName, $path, $packageID));
         }
     }
     WCF::getDB()->commitTransaction();
     // rebuild templates
     LanguageFactory::getInstance()->deleteLanguageCache();
     // reset application cache
     ApplicationCacheBuilder::getInstance()->reset();
 }
 /**
  * Deletes the folders of this template group.
  */
 public function deleteFolders()
 {
     // default template dir
     $folders = array(WCF_DIR . 'templates/' . $this->templateGroupFolderName);
     // get package dirs
     $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackageDir <> ''";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute();
     while ($row = $statement->fetchArray()) {
         $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
         DirectoryUtil::getInstance($packageDir . 'templates/' . $this->templateGroupFolderName)->deleteAll();
     }
 }
示例#20
0
 /**
  * Writes the given e-mail in a log file.
  * 
  * @param	Mail	$mail
  */
 public function sendMail(Mail $mail)
 {
     if ($this->log === null) {
         $logFilePath = '';
         if (MAIL_DEBUG_LOGFILE_PATH) {
             $logFilePath = FileUtil::addTrailingSlash(MAIL_DEBUG_LOGFILE_PATH);
         } else {
             $logFilePath = WCF_DIR . 'log/';
         }
         $this->log = new File($logFilePath . 'mail.log', 'ab');
     }
     $this->log->write($this->printMail($mail));
 }
示例#21
0
 /**
  * Saves the source of this template.
  * 
  * @param	string		$source
  */
 public function setSource($source)
 {
     $path = $this->getPath();
     // create dir
     $folder = dirname($path);
     if (!file_exists($folder)) {
         mkdir($folder, 0777);
     }
     // set source
     $file = new File($path);
     $file->write($source);
     $file->close();
     FileUtil::makeWritable($path);
 }
 /**
  * @see	\wcf\form\IForm::readFormParameters()
  */
 public function readFormParameters()
 {
     parent::readFormParameters();
     if (isset($_POST['templateGroupName'])) {
         $this->templateGroupName = StringUtil::trim($_POST['templateGroupName']);
     }
     if (!empty($_POST['templateGroupFolderName'])) {
         $this->templateGroupFolderName = StringUtil::trim($_POST['templateGroupFolderName']);
         if ($this->templateGroupFolderName) {
             $this->templateGroupFolderName = FileUtil::addTrailingSlash($this->templateGroupFolderName);
         }
     }
     if (isset($_POST['parentTemplateGroupID'])) {
         $this->parentTemplateGroupID = intval($_POST['parentTemplateGroupID']);
     }
 }
示例#23
0
 /**
  * Adds a folder to the Zip archive.
  * 
  * @param	string		$name		dirname
  */
 public function addDir($name, $date = TIME_NOW)
 {
     // replace backward slashes with forward slashes in the dirname
     $name = str_replace("\\", "/", $name);
     $name = FileUtil::addTrailingSlash($name);
     // construct the general header information for the directory
     $header = "PK";
     $header .= "\n";
     $header .= "";
     $header .= "";
     // construct the directory header specific information
     $header .= pack("V", 0);
     $header .= pack("V", 0);
     $header .= pack("V", 0);
     $header .= pack("v", strlen($name));
     $header .= pack("v", 0);
     $header .= $name;
     $header .= pack("V", 0);
     $header .= pack("V", 0);
     $header .= pack("V", 0);
     // store the complete header information into the $headers array
     $this->headers[] = $header;
     // calculate the new offset that will be used the next time a segment is added
     $newOffset = strlen(implode('', $this->headers));
     // construct the general header for the central index record
     $record = "PK";
     $record .= "\n";
     $record .= "";
     //$record .= "\x00\x00\x00\x00";
     $record .= $this->getDosDatetime($date);
     $record .= pack("V", 0);
     $record .= pack("V", 0);
     $record .= pack("V", 0);
     $record .= pack("v", strlen($name));
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     $record .= pack("v", 0);
     //$ext = "\x00\x00\x10\x00";
     //$ext = "\xff\xff\xff\xff";
     $record .= pack("V", 16);
     $record .= pack("V", $this->lastOffset);
     $record .= $name;
     // save the central index record in the array $data
     $this->data[] = $record;
     $this->lastOffset = $newOffset;
 }
示例#24
0
 /**
  * Returns the directory of the application with the given abbrevation.
  * 
  * @param	string		$abbreviation
  * @return	string
  */
 public static function getDirectory($abbreviation)
 {
     if (static::$directories === null) {
         static::$directories = array();
         // read application directories
         $packageList = new PackageList();
         $packageList->getConditionBuilder()->add('package.isApplication = ?', array(1));
         $packageList->readObjects();
         foreach ($packageList as $package) {
             $abbr = Package::getAbbreviation($package->package);
             static::$directories[$abbr] = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $package->packageDir));
         }
     }
     if (!isset(static::$directories[$abbreviation])) {
         throw new SystemException("Unknown application '" . $abbreviation . "'");
     }
     return static::$directories[$abbreviation];
 }
示例#25
0
 /**
  * Opens a new file. The file is always opened in binary mode.
  * 
  * @param	string		$filename
  */
 public function __construct($filename)
 {
     $this->targetFilename = $filename;
     $i = 0;
     while (true) {
         try {
             parent::__construct(FileUtil::getTemporaryFilename('atomic_'), 'xb');
             break;
         } catch (SystemException $e) {
             // allow at most 5 failures
             if (++$i === 5) {
                 throw $e;
             }
         }
     }
     if (!flock($this->resource, LOCK_EX)) {
         throw new SystemException('Could not get lock on temporary file');
     }
 }
 /**
  * Uninstalls the files of this package.
  */
 public function uninstall()
 {
     // get absolute package dir
     $packageDir = FileUtil::addTrailingSlash(FileUtil::unifyDirSeperator(realpath(WCF_DIR . $this->installation->getPackage()->packageDir)));
     // create file list
     $files = array();
     // get files from log
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_file_log\n\t\t\tWHERE \tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->installation->getPackageID()));
     while ($row = $statement->fetchArray()) {
         $files[] = $row['filename'];
     }
     if (count($files) > 0) {
         // delete files
         $this->installation->deleteFiles($packageDir, $files);
         // delete log entries
         parent::uninstall();
     }
 }
 /**
  * Uninstalls the templates of this package.
  */
 public function uninstall()
 {
     // create templates list
     $templates = array();
     // get templates from log
     $sql = "SELECT\ttemplateName\n\t\t\tFROM\twcf" . WCF_N . "_template\n\t\t\tWHERE \tpackageID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->installation->getPackageID()));
     while ($row = $statement->fetchArray()) {
         $templates[] = 'templates/' . $row['templateName'] . '.tpl';
     }
     if (count($templates) > 0) {
         // delete template files
         $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR . $this->installation->getPackage()->packageDir));
         $deleteEmptyDirectories = $this->installation->getPackage()->isApplication;
         $this->installation->deleteFiles($packageDir, $templates, false, $deleteEmptyDirectories);
         // delete log entries
         parent::uninstall();
     }
 }
 /**
  * @see	\wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://assets.woltlab.com/spiderlist/typhoon/list.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/ns:data/ns:spider');
     if (!empty($spiders)) {
         $existingSpiders = SpiderCacheBuilder::getInstance()->getData();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = mb_strtolower($spider->getAttribute('ident'));
             $name = $xpath->query('ns:name', $spider)->item(0);
             $info = $xpath->query('ns:url', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\t\t\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t\t\t(?, ?, ?)\n\t\t\t\t\tON DUPLICATE KEY UPDATE\t\tspiderName = VALUES(spiderName),\n\t\t\t\t\t\t\t\t\tspiderURL = VALUES(spiderURL)";
             $statement = WCF::getDB()->prepareStatement($sql);
             WCF::getDB()->beginTransaction();
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
             WCF::getDB()->commitTransaction();
         }
         // delete obsolete entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider WHERE spiderIdentifier = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($existingSpiders as $spider) {
             if (!isset($statementParameters[$spider->spiderIdentifier])) {
                 $statement->execute(array($spider->spiderIdentifier));
             }
         }
         // clear spider cache
         SpiderCacheBuilder::getInstance()->reset();
     }
     // delete tmp file
     @unlink($filename);
 }
示例#29
0
 /**
  * @see	\wcf\page\IPage::readData()
  */
 public function readData()
 {
     parent::readData();
     // init cache data
     $this->cacheData = array('source' => get_class(CacheHandler::getInstance()->getCacheSource()), 'version' => '', 'size' => 0, 'files' => 0);
     switch ($this->cacheData['source']) {
         case 'wcf\\system\\cache\\source\\DiskCacheSource':
             // set version
             $this->cacheData['version'] = WCF_VERSION;
             $this->readCacheFiles('data', WCF_DIR . 'cache');
             break;
         case 'wcf\\system\\cache\\source\\MemcachedCacheSource':
             // set version
             $this->cacheData['version'] = WCF_VERSION;
             break;
     }
     $this->readCacheFiles('language', FileUtil::unifyDirSeparator(WCF_DIR . 'language'));
     $this->readCacheFiles('template', FileUtil::unifyDirSeparator(WCF_DIR . 'templates/compiled'), new Regex('\\.meta\\.php$'));
     $this->readCacheFiles('template', FileUtil::unifyDirSeparator(WCF_DIR . 'acp/templates/compiled'), new Regex('\\.meta\\.php$'));
     $this->readCacheFiles('style', FileUtil::unifyDirSeparator(WCF_DIR . 'style'), null, 'css');
     $this->readCacheFiles('style', FileUtil::unifyDirSeparator(WCF_DIR . 'acp/style'), new Regex('WCFSetup.css$'), 'css');
 }
示例#30
0
 /**
  * @see wcf\action\IAction::execute()
  */
 public function execute()
 {
     parent::execute();
     // delete language cache and compiled templates as well
     LanguageFactory::getInstance()->deleteLanguageCache();
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("packageID IN (?)", array(PackageDependencyHandler::getInstance()->getDependencies()));
     $conditions->add("isApplication = ?", array(1));
     // get package dirs
     $sql = "SELECT\tpackageDir\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']);
         try {
             CacheHandler::getInstance()->clear($packageDir . 'cache', '*.php');
         } catch (SystemException $e) {
         }
     }
     $this->executed();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('CacheList'));
     exit;
 }