function EditableFile($filename) { import('file.FileWrapper'); $this->filename = $filename; $wrapper =& FileWrapper::wrapper($this->filename); $this->setContents($wrapper->contents()); }
/** * Constructor * @param $filename string Filename */ function __construct($filename) { import('lib.pkp.classes.file.FileWrapper'); $this->filename = $filename; $wrapper = FileWrapper::wrapper($this->filename); $this->setContents($wrapper->contents()); }
function search_files() { if (isset($_POST['search']) && $_POST['search'] != "") { $search = " name LIKE '%" . $_POST['search'] . "%' "; } else { $files = File::find('all'); } echo FileWrapper::display($files); wp_die(); }
function close() { if ($this->fp) { parent::close(); $rc = $this->_receive(); // FIXME Check rc == 226 ? } $this->_send('QUIT'); // FIXME Check rc == 221? $rc = $this->_receive(); fclose($this->ctrl); $this->ctrl = null; }
/** * Parse an XML file using xml_parse_into_struct and return data in an array. * This is best suited for XML documents with fairly simple structure. * @param $file string full path to the XML file * @param $tagsToMatch array optional, if set tags not in the array will be skipped * @return array a struct of the form ($TAG => array('attributes' => array( ... ), 'value' => $VALUE), ... ) */ function &parseStruct($file, $tagsToMatch = array()) { import('lib.pkp.classes.file.FileWrapper'); $wrapper =& FileWrapper::wrapper($file); $fileContents = $wrapper->contents(); if (!$fileContents) { $result = false; return $result; } $returner =& $this->parseTextStruct($fileContents, $tagsToMatch); return $returner; }
function open($mode = 'r') { $realHost = $host = isset($this->info['host']) ? $this->info['host'] : $this->defaultHost; $port = isset($this->info['port']) ? (int) $this->info['port'] : $this->defaultPort; $path = isset($this->info['path']) ? $this->info['path'] : $this->defaultPath; if (isset($this->info['query'])) { $path .= '?' . $this->info['query']; } if (!empty($this->proxyHost)) { $realHost = $host; $host = $this->proxyHost; $port = $this->proxyPort; if (!empty($this->proxyUsername)) { $this->headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->proxyUsername . ':' . $this->proxyPassword); } } if (!($this->fp = fsockopen($host, $port))) { return false; } $additionalHeadersString = ''; if (is_array($this->headers)) { foreach ($this->headers as $name => $value) { $additionalHeadersString .= "{$name}: {$value}\r\n"; } } $requestHost = preg_replace("!^.*://!", "", $realHost); $request = 'GET ' . (empty($this->proxyHost) ? $path : $this->url) . " HTTP/1.0\r\n" . "Host: {$requestHost}\r\n" . $additionalHeadersString . "Connection: Close\r\n\r\n"; fwrite($this->fp, $request); $response = fgets($this->fp, 4096); $rc = 0; sscanf($response, "HTTP/%*s %u %*[^\r\n]\r\n", $rc); if ($rc == 200) { while (fgets($this->fp, 4096) !== "\r\n") { } return true; } if (preg_match('!^3\\d\\d$!', $rc) && $this->redirects >= 1) { for ($response = '', $time = time(); !feof($this->fp) && $time >= time() - 15;) { $response .= fgets($this->fp, 128); } if (preg_match('!^(?:(?:Location)|(?:URI)|(?:location)): ([^\\s]+)[\\r\\n]!m', $response, $matches)) { $this->close(); $location = $matches[1]; if (preg_match('!^[a-z]+://!', $location)) { $this->url = $location; } else { $newPath = ($this->info['path'] !== '' && strpos($location, '/') !== 0 ? dirname($this->info['path']) . '/' : (strpos($location, '/') === 0 ? '' : '/')) . $location; $this->info['path'] = $newPath; $this->url = $this->glue_url($this->info); } $returner =& FileWrapper::wrapper($this->url); $returner->redirects = $this->redirects - 1; return $returner; } } $this->close(); return false; }
/** * Download and install a locale. * @param $locale string * @param $errors array * @return boolean */ function downloadLocale($locale, &$errors) { $downloadableLocales =& $this->getDownloadableLocales(); if (!is_array($downloadableLocales) || !isset($downloadableLocales[$locale])) { $errors[] = Locale::translate('admin.languages.download.cannotOpen'); return false; } $versionDao =& DAORegistry::getDAO('VersionDAO'); $version =& $versionDao->getCurrentVersion(); $versionString = $version->getVersionString(); // Set up to download and extract the language pack $fds = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $pipes = null; $process = proc_open('tar -x -z --wildcards \\*' . $locale . '\\*.xml \\*' . $locale . '\\*.png', $fds, $pipes); if (!is_resource($process)) { return false; } // Download and feed the pack to the tar process $languagePackUrl = sprintf(LANGUAGE_PACK_TAR_URL, $versionString, $locale); $wrapper =& FileWrapper::wrapper($languagePackUrl); if (!$wrapper->open()) { $errors[] = Locale::translate('admin.languages.download.cannotOpen'); } stream_set_blocking($pipes[0], 0); stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0); $pipeStdout = $pipeStderr = ''; while ($data = $wrapper->read()) { fwrite($pipes[0], $data); $pipeStdout .= fgets($pipes[1]); $pipeStderr .= fgets($pipes[2]); } fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); unset($wrapper); if (!empty($pipeStderr)) { $errors[] = $pipeStderr; return false; } // Finish up the tar process if (proc_close($process) !== 0) { return false; } // The tar file has now been extracted -- check whether the // locales list needs to have the new locale added. $locales = Locale::getAllLocales(); if (!isset($locales[$locale])) { // The locale does not exist in the local locale list $wrapper =& FileWrapper::wrapper(LOCALE_REGISTRY_FILE); $contents = $wrapper->contents(); $pos = strpos($contents, '</locales>'); if ($pos === false) { // Unable to locate insert point for new locale $errors[] = Locale::translate('admin.languages.download.cannotModifyRegistry'); return false; } $contents = substr_replace($contents, "\t<locale key=\"{$locale}\" name=\"" . $downloadableLocales[$locale]['name'] . "\" />\n", $pos, 0); $fp = fopen(LOCALE_REGISTRY_FILE, 'w'); if (!$fp) { // Unable to locate insert point for new locale $errors[] = Locale::translate('admin.languages.download.cannotModifyRegistry'); return false; } fwrite($fp, $contents); fclose($fwrite); } return true; }
/** * @copydoc GridHandler::loadData */ function loadData($request, $filter = null) { $plugin = $this->getPlugin(); $press = $request->getPress(); $addThisProfileId = $press->getSetting('addThisProfileId'); $addThisUsername = $press->getSetting('addThisUsername'); $addThisPassword = $press->getSetting('addThisPassword'); $data = array(); if (isset($addThisProfileId) && isset($addThisUsername) && isset($addThisPassword)) { $topSharedUrls = 'https://api.addthis.com/analytics/1.0/pub/shares/url.json?period=week&pubid=' . urlencode($addThisProfileId) . '&username='******'&password='******'lib.pkp.classes.file.FileWrapper'); $wrapper = FileWrapper::wrapper($topSharedUrls); $jsonData = $wrapper->contents(); if ($jsonData != '') { $jsonMessage = json_decode($jsonData); foreach ($jsonMessage as $statElement) { $data[] = array('url' => $statElement->url, 'shares' => $statElement->shares); } } } return $data; }
/** * Parse an XML file using xml_parse_into_struct and return data in an array. * This is best suited for XML documents with fairly simple structure. * @param $file string full path to the XML file * @param $tagsToMatch array optional, if set tags not in the array will be skipped * @return array a struct of the form ($TAG => array('attributes' => array( ... ), 'value' => $VALUE), ... ) */ function &parseStruct($file, $tagsToMatch = array()) { $parser =& $this->createParser(); import('file.FileWrapper'); $wrapper =& FileWrapper::wrapper($file); $fileContents = $wrapper->contents(); if (!$fileContents) { $result = false; return $result; } xml_parse_into_struct($parser, $fileContents, $values, $tags); $this->destroyParser($parser); // Clean up data struct, removing undesired tags if necessary foreach ($tags as $key => $indices) { if (!empty($tagsToMatch) && !in_array($key, $tagsToMatch)) { continue; } $data[$key] = array(); foreach ($indices as $index) { if (!isset($values[$index]['type']) || $values[$index]['type'] != 'open' && $values[$index]['type'] != 'complete') { continue; } $data[$key][] = array('attributes' => isset($values[$index]['attributes']) ? $values[$index]['attributes'] : array(), 'value' => isset($values[$index]['value']) ? trim($values[$index]['value']) : ''); } } return $data; }