/** * This will fetch all XML files from the host * * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function fetchRemoteXmlFiles() { if (!$this->isServer()) { // kernel_config is not in the list of packager tables $tables = $this->mTables; $tables[] = 'kernel_config'; foreach ($tables as $table) { $xmlFile = $this->getXmlFilepath($table); // make sure we only update when local files are older than a day if (!is_file($xmlFile) || is_file($xmlFile) && mktime() - filemtime($xmlFile) > 86400) { $xml = bit_http_request($this->getXmlUrl($table, TRUE)); if (!preg_match("/404 Not Found/", $xml) && !preg_match("/DOCTYPE html PUBLIC/", $xml)) { if ($handle = fopen($xmlFile, 'w')) { fwrite($handle, $xml); fclose($handle); } else { $this->mErrors['write'] = tra('There was a problem trying to write the files to your server.'); } } else { $this->mErrors['download'] = tra('There was a problem trying to download the files from the server.'); } } else { $this->mErrors['download'] = tra('The files are up to date and were not updated again.'); } } } else { $this->mErrors['download'] = tra('You can not run the database upgrader on a package server.'); } return count($this->mErrors) == 0; }
function fetchRemotePackage($pPackagerId = NULL) { if ($this->isValid(TRUE)) { // determine if we need to download the file at all if (!$this->isDownloaded()) { if ($content = bit_http_request($this->mInfo['package_url'])) { //echo( $content); if ($handle = fopen($this->getPackageFilepath(), 'w')) { fwrite($handle, $content); fclose($handle); } else { $this->mErrors['write'] = tra('There was a problem trying to write the file to your server.'); } } else { $this->mErrors['download'] = tra('There was a problem trying to download the file from the server.'); } } } return count($this->mErrors) == 0; }
/** * checkBitVersion Check for new version of bitweaver * * @access public * @return returns an array with information on bitweaver version */ function checkBitVersion() { $local = $this->getBitVersion(FALSE); $ret['local'] = $local; $error['number'] = 0; $error['string'] = $data = ''; // cache the bitversion.txt file locally and update only once a day // if you don't have a connection to bitweaver.org, you can set a cronjob to 'touch' this file once a day to avoid waiting for a timeout. if (!is_file(TEMP_PKG_PATH . 'bitversion.txt') || time() - filemtime(TEMP_PKG_PATH . 'bitversion.txt') > 86400) { if ($h = fopen(TEMP_PKG_PATH . 'bitversion.txt', 'w')) { $data = bit_http_request('http://www.bitweaver.org/bitversion.txt'); if (!preg_match("/not found/i", $data)) { fwrite($h, $data); fclose($h); } } } if (is_readable(TEMP_PKG_PATH . 'bitversion.txt')) { $h = fopen(TEMP_PKG_PATH . 'bitversion.txt', 'r'); if (isset($h)) { $data = fread($h, 1024); fclose($h); } // nuke all lines that don't just contain a version number $lines = explode("\n", $data); foreach ($lines as $line) { if (preg_match("/^\\d+\\.\\d+\\.\\d+\$/", $line)) { $versions[] = $line; } } if (!empty($data) && !empty($versions) && preg_match("/\\d+\\.\\d+\\.\\d+/", $versions[0])) { sort($versions); foreach ($versions as $version) { if (preg_match("/^" . BIT_MAJOR_VERSION . "\\./", $version)) { $ret['compare'] = version_compare($local, $version); $ret['upgrade'] = $version; $ret['page'] = preg_replace("/\\.\\d+\$/", "", $version); } } // check if there have been any major releases $release = explode('.', array_pop($versions)); if ($release[0] > BIT_MAJOR_VERSION) { $ret['release'] = implode('.', $release); $ret['page'] = $release[0] . '.' . $release[1]; } elseif ($release[0] < BIT_MAJOR_VERSION) { $ret['compare'] = version_compare($local, $version); $ret['upgrade'] = $version; } } else { $error['number'] = 1; $error['string'] = tra('No version information available. Check your connection to bitweaver.org'); } } // append any release level $ret['local'] .= ' ' . BIT_LEVEL; $ret['error'] = $error; return $ret; }
function refresh_rss_module($rss_id) { $info = $this->get_rss_module($rss_id); if ($info) { global $gBitSystem; $data = $this->rss_iconv(bit_http_request($info['url'])); $now = $gBitSystem->getUTCTime(); $query = "update `" . BIT_DB_PREFIX . "rss_modules` set `content`=?, `last_updated`=? where `rss_id`=?"; $result = $this->mDb->query($query, array((string) $data, (int) $now, (int) $rss_id)); return $data; } else { return false; } }
// we'll just use the themes package to play with. $testdir = $gInstall->getInstallPath('themes'); $backup = $gInstall->getStoragePath('backups') . '_dummy'; $tempfile = $gInstall->getStoragePath('packages') . 'temp.zip'; $pp['download']['note'] = tra('Try to download a file from www.bitweaver.org.<br />If this does not work, you can not connect to www.bitweaver.org directly.'); $pp['write']['note'] = tra('Try to write the downloaded file to your server.<br />If this does not work, the permissions on your <em>storage</em> directory are wrong. Try doing') . ':<br />chmod -R 777 ' . STORAGE_PKG_PATH; $pp['extract']['note'] = tra('Try to extract the downloaded zip file on your server.<br />This requires the unzip program to be in your $PATH on the server.'); $pp['move']['note'] = tra('Try to move one of the installed packages to a backup location.<br />We will test this with the <em>Themes</em> package.<br />If this does not work, you need to change the permissions in your bitweaver directory') . ':<br />' . BIT_ROOT_PATH; $pp['replace']['note'] = tra('Try to move the extracted files to your bitweaver root directy.'); // assume that something went wrong if we didn't explicitly spcify that it didn't. foreach ($pp as $key => $item) { $pp[$key]['result'] = 'error'; } if (!empty($_REQUEST['perform_checks'])) { // download if ($content = bit_http_request("http://www.bitweaver.org/storage/test.zip")) { $pp['download']['result'] = 'ok'; // write if ($handle = fopen($tempfile, 'w')) { fwrite($handle, $content); fclose($handle); $pp['write']['result'] = 'ok'; // extract archive $fileHash = array('tmp_name' => $tempfile, 'type' => 'application/zip', 'name' => 'temp.zip'); if ($extracted = liberty_process_archive($fileHash)) { if (is_file($extracted . "/test.txt")) { $pp['extract']['result'] = 'ok'; $dummyfile = BIT_ROOT_PATH . "___bitdummy.txt"; if (@rename($extracted . "/test.txt", $dummyfile)) { $pp['replace']['result'] = 'ok'; unlink($dummyfile);
/** * Load the color scheme * * @param array $pRemotePath Remote path to daily color scheme e.g.: 2006/04/28 * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function load() { $scheme = array(); if ($this->isValid() && ($xml = bit_http_request('http://www.bitweaver.org' . $this->mRemotePath))) { if (preg_match("/not found/i", $xml)) { $this->mErrors['load'] = tra('There is no scheme for this day.'); } else { $schemeInfo = $this->xmlToArray($xml); foreach ($schemeInfo['service'] as $key => $info) { $this->mInfo = array_merge($this->mInfo, $info); // this is very dodgy... if (is_numeric($key)) { $this->mCascaderId = $key; } if (!empty($info['colors'])) { foreach ($info['colors'] as $id => $color) { $this->mInfo['colors'][$id] = '#' . $color['hex']; } } } $this->mTitle = $this->mInfo['title']; $this->mCascaderId = $schemeInfo['cascader_id']; // $this->mTitle = $this->mInfo['title']; // vd($this->mCascaderId); // vd($this->mInfo); /* $parser = xml_parser_create(); xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0); if( !xml_parse_into_struct( $parser, $xml, $data, $index ) ) { $this->mErrors['xml_parsing'] = print_error(); } xml_parser_free($parser); //vd($data); //vd($index); // parse the data we extracted // cycle all <color> tags. // $index['color'] contains all pointers to <color> tags for( $i = 0; $i < count( $index['color'] ); $i++ ) { // extract needed information if( $data[$i]['type'] == 'complete' && $data[$i]['tag'] != 'hex' ) { $this->mInfo[$data[$i]['tag']] = $data[$i]['value']; } // since we have <color> nested inside the <colors> tag, // we have to check if pointer is to open type tag. if( $data[$index['color'][$i]]['type'] == 'open' ) { // extract needed information for( $j = $index['color'][$i]; $j < $index['color'][$i+1]; $j++ ) { if( $data[$j]['tag'] == 'hex' ) { $this->mInfo['colors'][] = '#'.$data[$j]['value']; } } } } foreach( $index['scheme'] as $idx ) { if( $data[$idx]['type'] == 'open' ) { $this->mCascaderId = $data[$idx]['attributes']['id']; } } $this->mTitle = $this->mInfo['title']; vd($this->mCascaderId); vd($this->mInfo); */ } } elseif ($this->isValid()) { $this->mErrors['load'] = tra('There is no scheme for this day.'); } $this->loadProperties(); return !empty($scheme); }