/**
  * Loads the search type objects.
  */
 public static function loadSearchTypeObjects()
 {
     if (self::$searchTypeObjects !== null) {
         return;
     }
     // get cache
     WCF::getCache()->addResource('searchableMessageTypes-' . PACKAGE_ID, WCF_DIR . 'cache/cache.searchableMessageTypes-' . PACKAGE_ID . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderSearchableMessageType.class.php');
     self::$searchTypeData = WCF::getCache()->get('searchableMessageTypes-' . PACKAGE_ID);
     // get objects
     self::$searchTypeObjects = array();
     foreach (self::$searchTypeData as $type) {
         // calculate class path
         $path = '';
         if (empty($type['packageDir'])) {
             $path = WCF_DIR;
         } else {
             $path = FileUtil::getRealPath(WCF_DIR . $type['packageDir']);
         }
         // include class file
         if (!file_exists($path . $type['classPath'])) {
             throw new SystemException("unable to find class file '" . $path . $type['classPath'] . "'", 11000);
         }
         require_once $path . $type['classPath'];
         // create instance
         $className = StringUtil::getClassName($type['classPath']);
         if (!class_exists($className)) {
             throw new SystemException("unable to find class '" . $className . "'", 11001);
         }
         self::$searchTypeObjects[$type['typeName']] = new $className();
     }
 }
 /**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     list($cache, $packageID) = explode('-', $cacheResource['cache']);
     $data = array('actions' => array('user' => array(), 'admin' => array()), 'inheritedActions' => array('user' => array(), 'admin' => array()));
     // get all listeners and filter options with low priority
     $sql = "SELECT\t\tlistener.*, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency,\n\t\t\t\t\twcf" . WCF_N . "_event_listener listener\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = listener.packageID)\n\t\t\tWHERE \t\tlistener.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . $packageID . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $row['listenerClassName'] = StringUtil::getClassName($row['listenerClassFile']);
         // distinguish between inherited actions and non-inherited actions
         if (!$row['inherit']) {
             $data['actions'][$row['environment']][EventHandler::generateKey($row['eventClassName'], $row['eventName'])][] = $row;
         } else {
             if (!isset($data['inheritedActions'][$row['environment']][$row['eventClassName']])) {
                 $data['inheritedActions'][$row['eventClassName']] = array();
             }
             $data['inheritedActions'][$row['environment']][$row['eventClassName']][$row['eventName']][] = $row;
         }
     }
     // sort data by class name
     foreach ($data['actions'] as $environment => $listenerMap) {
         foreach ($listenerMap as $key => $listeners) {
             uasort($data['actions'][$environment][$key], array('CacheBuilderEventListener', 'sortListeners'));
         }
     }
     foreach ($data['inheritedActions'] as $environment => $listenerMap) {
         foreach ($listenerMap as $class => $listeners) {
             foreach ($listeners as $key => $val) {
                 uasort($data['inheritedActions'][$environment][$class][$key], array('CacheBuilderEventListener', 'sortListeners'));
             }
         }
     }
     return $data;
 }
 /**
  * Creates a new planet.
  * 
  * @param	int		galaxy
  * @param	int		system
  * @param	int		planet
  * @param	string	name
  * @param	int		user id
  * @param	float	default metal
  * @param	float	default crystal
  * @param	float	default deuterium
  * @param	int		planet type id
  * @param	int		timestamp
  * @param	int		fields
  * @param	int		max temperature
  * @param	int		package id
  * @return	Planet
  */
 public static function create($galaxy, $system, $planet, $name, $userID, $metal = 0, $crystal = 0, $deuterium = 0, $planetTypeID = 1, $time = TIME_NOW, $fields = null, $maxTemp = 40, $packageID = PACKAGE_ID)
 {
     // get planet type information
     $sql = "SELECT classPath,\n\t\t\t\t\tplanetKind,\n\t\t\t\t\tforceImage\n\t\t\t\tFROM ugml_planet_type\n\t\t\t\tWHERE planetTypeID = " . $planetTypeID;
     $row = WCF::getDB()->getFirstRow($sql);
     $classPath = $row['classPath'];
     $className = StringUtil::getClassName($classPath);
     $planetKind = $row['planetKind'];
     // collect other data
     $information = PlanetUtil::getLocationEnvironment($planet);
     if (empty($row['forceImage'])) {
         $image = $information['image'];
     } else {
         $image = $row['forceImage'];
     }
     if ($fields === null) {
         $fields = $information['fields'];
     }
     $diameter = PlanetUtil::getDiameter($fields);
     if ($maxTemp === null) {
         $maxTemp = $information['maxTemp'];
     }
     $minTemp = $maxTemp - 40;
     // insert
     $planetID = self::insert($galaxy, $system, $planet, $planetKind, $planetTypeID, $className, $name, $userID, $fields, $diameter, $minTemp, $maxTemp, $image, $time, $packageID);
     $planet = Planet::getInstance($planetID);
     // add resources
     $planet->getEditor()->changeResources($metal, $crystal, $deuterium);
     return $planet;
 }
Exemple #4
0
 /**
  *
  */
 protected function createGroup($groupOptions = array())
 {
     require_once WCF_DIR . 'lib/util/StringUtil.class.php';
     require_once WCF_DIR . 'lib/data/user/group/GroupEditor.class.php';
     $group = GroupEditor::create($groupName = StringUtil::getRandomID(), $groupOptions);
     // WCF does not clear instance caches... so rebuild
     $classFile = WCF_DIR . 'lib/system/cache/CacheBuilderGroups.class.php';
     WCF::getCache()->rebuild(array('cache' => 'groups', 'file' => WCF_DIR . 'cache/cache.groups.php', 'className' => StringUtil::getClassName($classFile), 'classFile' => $classFile));
     return $group;
 }
 /**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     $data = array();
     $sql = "SELECT\t\taction.*, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_pm_rule_action action\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = action.packageID)";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $row['ruleActionClassName'] = StringUtil::getClassName($row['ruleActionClassFile']);
         $data[] = $row;
     }
     return $data;
 }
 /**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     list($cache, $packageID) = explode('-', $cacheResource['cache']);
     $data = array();
     $sql = "SELECT\t\tlocation.*, package.packageDir\n\t\t\tFROM\t\twcf" . WCF_N . "_package_dependency package_dependency,\n\t\t\t\t\twcf" . WCF_N . "_page_location location\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\tON\t\t(package.packageID = location.packageID)\n\t\t\tWHERE \t\tlocation.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . $packageID . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $row['className'] = StringUtil::getClassName($row['classPath']);
         $data[$row['locationName']] = $row;
     }
     return $data;
 }
 /**
  * autoload method for classname
  *
  * @param 	string		$className
  */
 public function autoload($className)
 {
     if (!isset($className)) {
         throw new SystemException('missing className');
     }
     $className = StringUtil::getClassName($className);
     $dir = StringUtil::toLowercase(StringUtil::substring($className, StringUtil::length('ViewableContest')));
     if (empty($dir)) {
         throw new SystemException('wrong dir: ' . $dir);
     }
     $file = WCF_DIR . 'lib/data/contest/' . $dir . '/' . $className . '.class.php';
     if (!is_file($file)) {
         throw new SystemException('wrong file: ' . $file);
     }
     require_once $file;
     if (!class_exists($className)) {
         throw new SystemException('class does not exist: ' . $className);
     }
 }
 /**
  * @see CacheBuilder::getData()
  */
 public function getData($cacheResource)
 {
     list($cache, $packageID) = explode('-', $cacheResource['cache']);
     $data = array();
     // get type ids
     $typeIDArray = array();
     $sql = "SELECT\t\tsuspensionType, suspensionTypeID \n\t\t\tFROM\t\twcf" . WCF_N . "_user_infraction_suspension_type suspension_type,\n\t\t\t\t\twcf" . WCF_N . "_package_dependency package_dependency\n\t\t\tWHERE \t\tsuspension_type.packageID = package_dependency.dependency\n\t\t\t\t\tAND package_dependency.packageID = " . $packageID . "\n\t\t\tORDER BY\tpackage_dependency.priority";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $typeIDArray[$row['suspensionType']] = $row['suspensionTypeID'];
     }
     if (count($typeIDArray) > 0) {
         $sql = "SELECT\t\tsuspension_type.*, package.packageDir\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_infraction_suspension_type suspension_type\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_package package\n\t\t\t\tON\t\t(package.packageID = suspension_type.packageID)\n\t\t\t\tWHERE\t\tsuspension_type.suspensionTypeID IN (" . implode(',', $typeIDArray) . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $row['className'] = StringUtil::getClassName($row['classFile']);
             $data[] = $row;
         }
     }
     return $data;
 }
Exemple #9
0
 /**
  * Reads the needed class from the database and returns the fleet object
  *
  * @param	int		fleet id
  * @param	array	fleet row
  *
  * @return	Fleet	planet
  */
 public static function getInstance($fleetID, $row = null)
 {
     if ($fleetID !== null) {
         $fleetID = intval($fleetID);
     }
     FleetQueue::readCache();
     if (isset(self::$fleets[$fleetID])) {
         $fleet = self::$fleets[$fleetID];
     } else {
         if (isset(self::$fleets[$row['fleetID']])) {
             $fleetID = $row['fleetID'];
             $fleet = self::$fleets[$row['fleetID']];
         } else {
             if ($fleetID === null) {
                 $fleetID = $row['fleetID'];
                 $classPath = FleetQueue::$cache[$row['missionID']]['classPath'];
                 $className = StringUtil::getClassName($classPath);
                 if (!$row) {
                     $className = self::STANDARD_CLASS;
                     $classPath = 'lib/data/fleet/' . self::STANDARD_CLASS . '.class.php';
                 }
                 require_once LW_DIR . 'lib/data/fleet/' . $className . '.class.php';
                 $fleet = new $className($fleetID, $row);
             } else {
                 $sql = "SELECT ugml_fleet.*,\r\n\t\t\t\t\t\tGROUP_CONCAT(\r\n\t\t\t\t\t\t\tCONCAT(specID, ',', shipCount) \r\n\t\t\t\t\t\t\tSEPARATOR ';')\r\n\t\t\t\t\t\tAS fleet\r\n\t\t\t\t\tFROM ugml_fleet\r\n\t\t    \t\tLEFT JOIN ugml_fleet_spec\r\n\t\t    \t\t\tON ugml_fleet.fleetID = ugml_fleet_spec.fleetID\r\n\t\t    \t\tWHERE ugml_fleet.fleetID = " . $fleetID . "\r\n\t\t    \t\tGROUP BY ugml_fleet.fleetID";
                 $row = WCF::getDB()->getFirstRow($sql);
                 $classPath = FleetQueue::$cache[$row['missionID']]['classPath'];
                 $className = StringUtil::getClassName($classPath);
                 if (!$row) {
                     $className = self::STANDARD_CLASS;
                     $classPath = 'lib/data/fleet/' . self::STANDARD_CLASS . '.class.php';
                 }
                 require_once LW_DIR . $classPath;
                 $fleet = new $className($fleetID, $row);
             }
         }
     }
     self::$fleets[$fleetID] = $fleet;
     return $fleet;
 }
Exemple #10
0
 /**
  * Returns the available missions.
  * 
  * @return	array
  */
 public function getMissions()
 {
     $missions = array();
     $startPlanetTypeID = $this->getStartPlanet()->planetTypeID;
     if (is_object($this->getTargetPlanet())) {
         $endPlanetTypeID = $this->getTargetPlanet()->planetTypeID;
     } else {
         $endPlanetTypeID = null;
     }
     self::readCache();
     foreach (self::$cache as $missionID => $mission) {
         // check route
         if (!isset($mission['route'][$startPlanetTypeID][$endPlanetTypeID])) {
             continue;
         }
         // execute method
         require_once LW_DIR . $mission['classPath'];
         $className = StringUtil::getClassName($mission['classPath']);
         if (!class_exists($className)) {
             require_once WCF_DIR . 'lib/system/exception/SystemException.class.php';
             throw new SystemException("unable to find class '" . $className . "'", 11001);
         }
         $available = call_user_func(array($className, 'check'), $this);
         if ($available) {
             $missions[$missionID] = $mission['route'][$startPlanetTypeID][$endPlanetTypeID];
         }
     }
     return $missions;
 }
 /**
  * Actually execute the cronjob.
  * 
  * @param	array		$cronjobsCache
  * @return	boolean		success
  */
 protected function execPendingCronjobs($cronjobsCache = array())
 {
     // include class file
     if (!file_exists(WCF_DIR . $cronjobsCache['classPath'])) {
         throw new SystemException("unable to find class file '" . WCF_DIR . $cronjobsCache['classPath'] . "'", 11000);
     }
     require_once WCF_DIR . $cronjobsCache['classPath'];
     $i = 0;
     while ($i < $this->countMultipleExecs) {
         // omit 1970-01-01T01:00:00.
         if ($this->execMultiple == 1) {
             $cronjobsCache['nextExec'] = $this->timebase;
         }
         if (isset($this->plannedExecs) && count($this->plannedExecs)) {
             $cronjobsCache['nextExec'] = $this->plannedExecs[$i];
         }
         // create instance.
         $className = StringUtil::getClassName($cronjobsCache['classPath']);
         if (!class_exists($className)) {
             throw new SystemException("unable to find class '" . $className . "'", 11001);
         }
         // execute cronjob.
         $cronjobExec = new $className();
         if (method_exists($cronjobExec, 'execute')) {
             $cronjobExec->execute($cronjobsCache);
         }
         // log success.
         CronjobEditor::logSuccess($cronjobsCache['newLogID'], true);
         $i++;
     }
 }
 /**
  * Loads the taggable objects.
  */
 protected function loadTaggables()
 {
     if ($this->taggables !== null) {
         return;
     }
     // get cache
     WCF::getCache()->addResource('taggables-' . PACKAGE_ID, WCF_DIR . 'cache/cache.taggables-' . PACKAGE_ID . '.php', WCF_DIR . 'lib/system/cache/CacheBuilderTaggable.class.php');
     $this->taggablesData = WCF::getCache()->get('taggables-' . PACKAGE_ID);
     // get objects
     $this->taggables = array();
     foreach ($this->taggablesData as $type) {
         // calculate class path
         $path = '';
         if (empty($type['packageDir'])) {
             $path = WCF_DIR;
         } else {
             $path = FileUtil::getRealPath(WCF_DIR . $type['packageDir']);
         }
         // include class file
         if (!file_exists($path . $type['classPath'])) {
             throw new SystemException("unable to find class file '" . $path . $type['classPath'] . "'", 11000);
         }
         require_once $path . $type['classPath'];
         // create instance
         $className = StringUtil::getClassName($type['classPath']);
         if (!class_exists($className)) {
             throw new SystemException("unable to find class '" . $className . "'", 11001);
         }
         $this->taggables[$type['taggableID']] = new $className($type['taggableID'], $type['name']);
     }
 }
Exemple #13
0
 /**
  * Reads all rows matching the given conditions an returns an array of Ovent objects.
  */
 public static function getByConditions($conditions)
 {
     self::initCache();
     $sql = "SELECT *\r\n\t\t\t\tFROM ugml_ovent\r\n\t\t\t\tWHERE ";
     foreach ($conditions as $key => $value) {
         $sql .= "`" . $key . "` = " . $value . " AND ";
     }
     $result = WCF::getDB()->sendQuery(substr($sql, 0, -5) . " ORDER BY `time` ASC");
     $rows = array();
     while ($row = WCF::getDB()->fetchArray($result)) {
         $classPath = self::$cache[$row['oventTypeID']]['classPath'];
         $className = StringUtil::getClassName($classPath);
         require_once LW_DIR . $classPath;
         $rows[] = new $className(null, $row);
     }
     return $rows;
 }
 /**
  * Executes the events.
  */
 protected function executeEvents()
 {
     WCF::getDB()->sendQuery("SET AUTOCOMMIT = 0");
     foreach ($this->events as $eventID => $eventObj) {
         WCF::getDB()->sendQuery("START TRANSACTION");
         try {
             // delete
             if (!empty($this->eventIDsStr)) {
                 $this->eventIDsStr .= ",";
             }
             $this->eventIDsStr .= $eventID;
             // execute
             $classPath = WOTEventEditor::$cache[$eventObj->eventTypeID]['classPath'];
             $className = StringUtil::getClassName($classPath);
             require_once LW_DIR . $classPath;
             // look for singleton
             if (in_array('WOTEventSingleton', class_implements($className))) {
                 $h = call_user_func(array($className, 'getInstance'), $eventObj->specificID);
                 echo "s";
             } else {
                 $h = new $className($eventObj->specificID);
                 echo "n";
             }
             echo "b";
             $h->execute($eventObj->eventData);
             echo "a";
             // protect against fatal errors in following events
             if ($this->enableSafeMode) {
                 if (!empty($this->eventIDsStr)) {
                     WOTEventEditor::deleteEvents($this->eventIDsStr);
                 }
                 $this->eventIDsStr = "";
             }
         } catch (Exception $e) {
             WCF::getDB()->sendQuery("ROLLBACK");
             WCF::getDB()->sendQuery("START TRANSACTION");
             $this->deleteEvents();
             throw new WOTEventExecuteException($e, $h, $eventID);
         }
         WCF::getDB()->sendQuery("COMMIT");
     }
     WCF::getDB()->sendQuery("SET AUTOCOMMIT = 1");
 }
 /**
  * Registers a new cache resource.
  * 
  * @param	string		$cache		name of this resource
  * @param	string		$file		data file for this resource
  * @param	string		$classFile
  * @param	integer		$minLifetime
  * @param	integer		$maxLifetime
  */
 public function addResource($cache, $file, $classFile, $minLifetime = 0, $maxLifetime = 0)
 {
     $className = StringUtil::getClassName($classFile);
     $this->cacheResources[$cache] = array('cache' => $cache, 'file' => $file, 'className' => $className, 'classFile' => $classFile, 'minLifetime' => $minLifetime, 'maxLifetime' => $maxLifetime);
 }
 /**
  * Executes this cronjob.
  */
 public function execute()
 {
     // create log entry
     $logID = CronjobEditor::logExec();
     // include class file
     $classPath = FileUtil::getRealPath(WCF_DIR . $this->packageDir . $this->classPath);
     if (!file_exists($classPath)) {
         throw new SystemException("unable to find class file '" . $classPath . "'", 11000);
     }
     require_once $classPath;
     // create instance.
     $className = StringUtil::getClassName($this->classPath);
     if (!class_exists($className)) {
         throw new SystemException("unable to find class '" . $className . "'", 11001);
     }
     // execute cronjob.
     $cronjobExec = new $className();
     if (method_exists($cronjobExec, 'execute')) {
         $cronjobExec->execute($this->data);
     }
     // log success.
     CronjobEditor::logSuccess($logID, true);
 }
 /**
  * Get the loggable with the given name.
  * 
  * @param	string	$loggableName
  * 
  * @return	Loggable
  * @throws	SystemException
  */
 public static function getLoggable($loggableName)
 {
     if (self::$loggablesData == null) {
         self::loadLoggables();
     }
     if (!isset(self::$loggables[$loggableName])) {
         if (!isset(self::$loggablesData[$loggableName])) {
             throw new SystemException("Unable to find loggable '" . $loggableName . "'");
         }
         $loggableData = self::$loggablesData[$loggableName];
         // calculate class path
         $path = '';
         if (empty($loggableData['packageDir'])) {
             $path = WCF_DIR;
         } else {
             $path = FileUtil::getRealPath(WCF_DIR . $loggableData['packageDir']);
         }
         // include class file
         if (!file_exists($path . $loggableData['classPath'])) {
             throw new SystemException("Unable to find class file '" . $path . $loggableData['classPath'] . "'");
         }
         require_once $path . $loggableData['classPath'];
         // create instance
         $className = StringUtil::getClassName($loggableData['classPath']);
         if (!class_exists($className)) {
             throw new SystemException("Unable to find class '" . $className . "'");
         }
         self::$loggables[$loggableName] = new $className(null, $loggableData);
         // save memory ;)
         unset(self::$loggablesData[$loggableName]);
     }
     return self::$loggables[$loggableName];
 }