Ejemplo n.º 1
0
$base = new TeraWurfl();
if ($base->db->connected !== true) {
    throw new Exception("Cannot connect to database: " . $base->db->errors[0]);
}
if (isset($_GET['action']) && $_GET['action'] == 'rebuildCache') {
    $base->db->rebuildCacheTable();
    header("Location: index.php?msg=" . urlencode("The cache has been successfully rebuilt ({$base->db->numQueries} queries).") . "&severity=notice");
    exit(0);
}
if (isset($_GET['action']) && $_GET['action'] == 'clearCache') {
    $base->db->createCacheTable();
    header("Location: index.php?msg=" . urlencode("The cache has been successfully cleared ({$base->db->numQueries} queries).") . "&severity=notice");
    exit(0);
}
$newfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE . ".zip";
$wurflfile = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE;
if ($source == "remote" || $source == "remote_cvs") {
    if ($source == "remote") {
        $dl_url = TeraWurflConfig::$WURFL_DL_URL;
    } elseif ($source == "remote_cvs") {
        $dl_url = TeraWurflConfig::$WURFL_CVS_URL;
    }
    echo "Downloading WURFL from {$dl_url} ...\n<br/>";
    flush();
    if (!file_exists($newfile) && !is_writable($base->rootdir . TeraWurflConfig::$DATADIR)) {
        $base->toLog("Cannot write to data directory (permission denied)", LOG_ERR);
        throw new Exception("Fatal Error: Cannot write to data directory (permission denied). (" . $base->rootdir . TeraWurflConfig::$DATADIR . ")<br/><br/><strong>Please make the data directory writable by the user or group that runs the webserver process, in Linux this command would do the trick if you're not too concerned about security: <pre>chmod -R 777 " . $base->rootdir . TeraWurflConfig::$DATADIR . "</pre></strong>");
        exit(1);
    }
    if (file_exists($newfile) && !is_writable($newfile)) {
        $base->toLog("Cannot overwrite WURFL file (permission denied)", LOG_ERR);
 public function __construct(TeraWurfl $wurfl)
 {
     $this->wurfl = $wurfl;
     $this->wurfl_file_zipped = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE . ".zip";
     $this->wurfl_file_xml = TeraWurfl::absoluteDataDir() . TeraWurflConfig::$WURFL_FILE;
     $this->download_url = TeraWurflConfig::$WURFL_DL_URL;
     $twversion = $this->wurfl->release_branch . " " . $this->wurfl->release_version;
     @ini_set('user_agent', "WURFL/Database API {$twversion}");
     $this->checkPermissions();
 }
Ejemplo n.º 3
0
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return Bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }
 /**
  * Loads the patch files from TeraWurflConfig::PATCH_FILE
  * @return bool Success
  */
 public function loadPatches()
 {
     if (!TeraWurflConfig::$PATCH_ENABLE) {
         return true;
     }
     $this->timepatch = microtime(true);
     // Explode the patchfile string into an array of patch files (normally just one file)
     $patches = explode(';', TeraWurflConfig::$PATCH_FILE);
     foreach ($patches as $patch) {
         $patch_devices = array();
         $this->wurfl->toLog("Loading patch: " . $patch, LOG_WARNING);
         $patch_parser = TeraWurflXMLParser::getInstance();
         $patch_parser->open(TeraWurfl::absoluteDataDir() . $patch, TeraWurflXMLParser::$TYPE_PATCH);
         $patch_parser->process($patch_devices);
         foreach ($patch_devices as $id => &$device) {
             // if the fall_back is blank, or equal to it's id, or the fall_back ID doesn't exist in the device table or this patch file,
             // then it will cause the API to fail.  We'll skip this device and report the error.  There is also the possibility that the
             // device has a valid fallback in a patch file that hasn't been prosessed yet, but this is not worth trying to detect.
             if (!isset($device['fall_back']) || $id == $device['fall_back'] || !$this->validID($device['fall_back']) && !in_array($device['fall_back'], $patch_devices)) {
                 $this->errors[] = "The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.";
                 $this->wurfl->toLog("The device '{$id}' from patch file '{$patch}' has an invalid fall_back device ID and has been skipped.", LOG_WARNING);
                 continue;
             }
             if ($this->validID($id)) {
                 // Merge this device on top of the existing device
                 TeraWurfl::mergeCapabilities($this->devices[$id], $device);
                 $this->patchMergedDevices++;
             } else {
                 // Add this new device to the table
                 $this->devices[$id] = $device;
                 $this->patchAddedDevices++;
             }
         }
         unset($this->parser);
     }
     return true;
 }