public function convert() { $excel = new COM('excel.application') or die('Unable to instantiate Excel'); $excel->Visible = false; $excel->WorkBooks->Open($this->source_file); $excel->WorkBooks[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]); $excel->Quit(); unset($excel); $result = AkFileSystem::file_get_contents($this->destination_file); $this->delete_source_file ? @AkFileSystem::file_delete($this->source_file) : null; $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file); return $result; }
public function test_should_get_the_right_temp_dir() { $tmp_dir = Ak::get_tmp_dir_name(); $tmp_file = $tmp_dir . DS . 'ak_test_' . __CLASS__; $tmp_file2 = $tmp_dir . DS . 'ak_test_dir' . DS . 'level_one' . DS . 'file.txt'; $this->assertTrue(is_dir($tmp_dir), 'Could not find temporary directory at: ' . $tmp_dir); $this->assertTrue(touch($tmp_dir . DS . 'ak_test_' . __CLASS__), 'Can\'t touch files on the temporary directory ' . $tmp_dir); $this->assertTrue(AkFileSystem::file_put_contents($tmp_file, 'abc'), 'Can\'t write on the temporary file ' . $tmp_file); $this->assertTrue(AkFileSystem::file_get_contents($tmp_file) == 'abc', 'Can\'t write on the temporary file ' . $tmp_file); $this->assertTrue(AkFileSystem::file_put_contents($tmp_file2, 'abce'), 'Can\'t write on the temporary file ' . $tmp_file2); $this->assertTrue(AkFileSystem::file_get_contents($tmp_file2) == 'abce', 'Can\'t write on the temporary file ' . $tmp_file2); $this->assertEqual($tmp_dir, AK_TMP_DIR); }
public function convert() { $word = new COM('word.application') or die('Unable to instantiate Word'); $word->Visible = false; $word->Documents->Open($this->source_file); $word->Documents[1]->SaveAs($this->destination_file, $this->_file_type_codes[$this->convert_to]); $word->Quit(); $word = null; $result = AkFileSystem::file_get_contents($this->destination_file); $this->delete_source_file ? AkFileSystem::file_delete($this->source_file) : null; $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file); return $result; }
public function raiseError($code = null) { $code = empty($code) ? @$this->_options['code'] : $code; if (AK_DEBUG) { // We can't halt execution while testing and the error message is too large for trigger_error if (AK_ENVIRONMENT == 'testing') { trigger_error(join("\n", $this->getErrors()), E_USER_WARNING); } else { echo '<h1>' . Ak::t('Template %template_file security error', array('%template_file' => @$this->_options['file_path'])) . ':</h1>' . "<ul><li>" . join("</li>\n<li>", $this->getErrors()) . "</li></ul><hr />\n" . '<h2>' . Ak::t('Showing template source from %file:', array('%file' => $this->_options['file_path'])) . '</h2>' . (isset($this->_options['file_path']) ? '<pre>' . htmlentities(AkFileSystem::file_get_contents($this->_options['file_path'])) . '</pre><hr />' : '') . '<h2>' . Ak::t('Showing compiled template source:') . '</h2>' . highlight_string($code, true); die; } } else { trigger_error(Ak::t('Template compilation error'), E_USER_ERROR); } }
public function convert() { $xdoc2txt_bin = AK_CONTRIB_DIR . DS . 'hyperestraier' . DS . 'xdoc2txt.exe'; if (!AK_WIN) { trigger_error(Ak::t('Xdoc2Text is a windows only application. Please use wvWare instead'), E_USER_WARNING); return false; } if (!file_exists($xdoc2txt_bin)) { trigger_error(Ak::t('Could not find xdoc2txt.exe on %path. Please download it from http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html', array('%path' => $xdoc2txt_bin)), E_USER_WARNING); return false; } exec('@"' . $xdoc2txt_bin . '" -f "' . $this->source_file . '" "' . $this->destination_file . '"'); $result = AkFileSystem::file_get_contents($this->destination_file); $this->delete_source_file ? @AkFileSystem::file_delete($this->source_file) : null; $this->keep_destination_file ? null : AkFileSystem::file_delete($this->destination_file); return $result; }
public function relativizeStylesheetPaths() { $url_suffix = AkConsole::promptUserVar('The admin plugin comes with some fancy CSS background images. Your application might be accessible at /myapp, and your images folder might be at /myapp/public Insert the relative path where your images folder is so you don\'t need to manually edit the CSS files', array('default' => '/')); $url_suffix = trim(preg_replace('/\\/?images\\/admin\\/?$/', '', $url_suffix), '/'); if (!empty($url_suffix)) { $stylesheets = array('admin/admin', 'admin/menu'); foreach ($stylesheets as $stylesheet) { $filename = AK_PUBLIC_DIR . DS . 'stylesheets' . DS . $stylesheet . '.css'; $relativized_css = preg_replace("/url\\((\\'|\")?\\/images/", "url(\$1/{$url_suffix}/images", @AkFileSystem::file_get_contents($filename)); !empty($relativized_css) && @AkFileSystem::file_put_contents($filename, $relativized_css); } } }
/** * This method tries to determine if url rewrite is enabled on this server. * It has only been tested on apache. * It is strongly recomended that you manually define the constant * AK_URL_REWRITE_ENABLED on your config file to the avoid overload * this function causes and to prevent from missfunctioning */ static function loadUrlRewriteSettings() { static $result; if (isset($result)) { return $result; } if (defined('AK_URL_REWRITE_ENABLED')) { $result = AK_URL_REWRITE_ENABLED; return AK_URL_REWRITE_ENABLED; } if (defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE == false) { if (!defined('AK_URL_REWRITE_ENABLED')) { define('AK_URL_REWRITE_ENABLED', false); } $result = AK_URL_REWRITE_ENABLED; return false; } $url_rewrite_status = false; //echo '<pre>'.print_r(get_defined_functions(), true).'</pre>'; if (isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200 && isset($_SERVER['REDIRECT_QUERY_STRING']) && strstr($_SERVER['REDIRECT_QUERY_STRING'], 'ak=')) { if (strstr($_SERVER['REDIRECT_QUERY_STRING'], '&')) { $tmp_arr = explode('&', $_SERVER['REDIRECT_QUERY_STRING']); $ak_request = $tmp_arr[0]; } else { $ak_request = $_SERVER['REDIRECT_QUERY_STRING']; } $ak_request = trim(str_replace('ak=', '', $ak_request), '/'); if (strstr($_SERVER['REDIRECT_URL'], $ak_request)) { $url_rewrite_status = true; } else { $url_rewrite_status = false; } } elseif (function_exists('apache_get_modules')) { $available_modules = apache_get_modules(); if (in_array('mod_rewrite', (array) $available_modules)) { // Local session name is changed intentionally from .htaccess // So we can see if the file has been loaded. // if so, we restore the session.name to its original // value if (ini_get('session.name') == 'AK_SESSID') { $session_name = defined('AK_SESSION_NAME') ? AK_SESSION_NAME : get_cfg_var('session.name'); ini_set('session.name', $session_name); $url_rewrite_status = true; // In some cases where session.name cant be set up by htaccess file, // we can check for modrewrite status on this file } elseif (file_exists(AK_BASE_DIR . DS . '.htaccess')) { $htaccess_file = AkFileSystem::file_get_contents(AK_BASE_DIR . DS . '.htaccess'); if (stristr($htaccess_file, 'RewriteEngine on')) { $url_rewrite_status = true; } } } // If none of the above works we try to fetch a file that should be remaped } elseif (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] == '/' && isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200) { $url_rewrite_test_url = AK_URL . 'mod_rewrite_test'; if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { $url_rewrite_test_url = AK_PROTOCOL . $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW'] . '@' . AK_HOST . '/mod_rewrite_test'; } $url_rewrite_status = strstr(@file_get_contents($url_rewrite_test_url), 'AK_URL_REWRITE_ENABLED'); $AK_URL_REWRITE_ENABLED = "define(\\'AK_URL_REWRITE_ENABLED\\', " . ($url_rewrite_status ? 'true' : 'false') . ");\n"; register_shutdown_function(create_function('', "AkFileSystem::file_put_contents(AkConfig::getDir('config').DS.'config.php',\n str_replace('<?php\n','<?php\n\n{$AK_URL_REWRITE_ENABLED}',AkFileSystem::file_get_contents(AkConfig::getDir('config').DS.'config.php')));")); } if (!defined('AK_URL_REWRITE_ENABLED')) { define('AK_URL_REWRITE_ENABLED', $url_rewrite_status); } $result = AK_URL_REWRITE_ENABLED; return AK_URL_REWRITE_ENABLED; }
public function test_file_get_contents() { if (!RUN_FTP_TESTS) { return; } $file_name = 'cache' . DS . 'test_file_1.txt'; $content = 'This is the NEW content for file 1'; $this->assertTrue(AkFileSystem::file_get_contents($file_name) === $content); $file_name = 'cache' . DS . 'test_file_2.txt'; $content = "\n\rThis is the content of file 2\n"; $this->assertTrue(AkFileSystem::file_get_contents($file_name) === $content); $file_name = 'cache' . DS . 'test_file_3.txt'; $content = "\rThis is the content of file 3\r\n"; $this->assertTrue(AkFileSystem::file_get_contents($file_name) === $content); $file_name = 'cache\\test_file_4.txt'; $content = "\rThis is the content of file 4\r\n"; $this->assertTrue(AkFileSystem::file_get_contents($file_name) === $content); }
/** * Gets a list of available plugins. * * Goes through each trusted plugin server and retrieves the name of the * folders (plugins) on the repository path. * * @param boolean $force_update If it is not set to true, it will only check remote sources once per hour * @return array Returns an array containing "plugin_name" => "repository URL" * @access public */ public function getPlugins($force_update = false) { if ($force_update || !is_file($this->_getRepositoriesCahePath()) || filemtime($this->_getRepositoriesCahePath()) > 3600) { if (!$this->_updateRemotePluginsList()) { return array(); } } return array_map('trim', Ak::convert('yaml', 'array', AkFileSystem::file_get_contents($this->_getRepositoriesCahePath()))); }
protected function _removeMethodFromClass($path, $name, $pluginName) { return AkFileSystem::file_put_contents($path, preg_replace("|(\n[^\n]*?/\\*\\* AUTOMATED START: {$pluginName}::{$name} \\*/.*?/\\*\\* AUTOMATED END: {$pluginName}::{$name} \\*/\n)|s", "", AkFileSystem::file_get_contents($path)), array('skip_path_restriction' => true)); }
static function uncompress($compressed_data, $format = 'gzip') { $key = Ak::randomString(15); $compressed_file = AK_TMP_DIR . DS . 's' . $key; $uncompressed_file = AK_TMP_DIR . DS . 'd' . $key; if (AkFileSystem::file_put_contents($compressed_file, $compressed_data, array('base_path' => AK_TMP_DIR)) !== false) { $compressed = gzopen($compressed_file, "r"); $uncompressed = fopen($uncompressed_file, "w"); while (!gzeof($compressed)) { $string = gzread($compressed, 4096); fwrite($uncompressed, $string, strlen($string)); } gzclose($compressed); fclose($uncompressed); } else { trigger_error(Ak::t('Could not write to temporary directory for generating uncompressing file using Ak::uncompress(). Please provide write access to %dirname', array('%dirname' => AK_TMP_DIR)), E_USER_ERROR); } $result = AkFileSystem::file_get_contents($uncompressed_file, array('base_path' => AK_TMP_DIR)); AkFileSystem::file_delete($uncompressed_file, array('base_path' => AK_TMP_DIR)); AkFileSystem::file_delete($compressed_file, array('base_path' => AK_TMP_DIR)); return $result; }
public function getPersistedCookie() { if (file_exists(AkConfig::getDir('tmp') . DS . $this->_cookie_path)) { return AkFileSystem::file_get_contents($this->_cookie_path, array('base_path' => AkConfig::getDir('tmp'))); } return false; }
function _canIncludeMergedFile($class_name_to_extend, $checksum) { $merge_path = AK_TMP_DIR . DS . '.lib'; if (AK_CLASS_EXTENDER_ENABLE_CACHE && file_exists($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php') && AkFileSystem::file_get_contents($merge_path . DS . 'checksums' . DS . 'Extensible' . $class_name_to_extend) == $checksum) { return true; } return false; }
public function test_should_read_files_using_scoped_file_get_contents_function() { $this->assertEqual(AkFileSystem::file_get_contents(__FILE__, array('base_path' => dirname(__FILE__))), file_get_contents(__FILE__)); }
public function relativizeStylesheetPaths() { $asset_path = $this->_getAssetBasePath(); if ($this->hasUrlSuffix() || !empty($asset_path)) { $url_suffix = trim($this->getUrlSuffix(), '/'); if (!empty($asset_path)) { $url_suffix = trim($url_suffix . '/' . $asset_path, '/'); } foreach ($this->stylesheets as $stylesheet) { $filename = AK_PUBLIC_DIR . DS . 'stylesheets' . DS . $stylesheet . '.css'; $relativized_css = preg_replace("/url\\((\\'|\")?\\/images/", "url(\$1/{$url_suffix}/images", @AkFileSystem::file_get_contents($filename)); empty($relativized_css) || @AkFileSystem::file_put_contents($filename, $relativized_css); } } }
protected function _removeOldVersionsFileAndUseMigrationsTable($options) { $oldfile = $this->_versionPath($options); $version = AkFileSystem::file_get_contents($oldfile); AkFileSystem::copy($oldfile, $oldfile . '.backup'); AkFileSystem::file_delete($oldfile); $this->log('message', 'got old version from file:' . $oldfile . '=' . $version . ' moved to backup-file:' . $oldfile . '.backup'); $this->setInstalledVersion($version, $options); $this->AkelosMigration->create(array('name' => $this->getInstallerName(), 'version' => $version)); }
protected function _extractCssRulesFromFile($path, $cssRules = false) { if (empty($cssRules)) { $cssRules = array('id' => array(), 'class' => array(), 'element' => array()); } $path = $this->_getStylesheetPath($path); $contents = AkFileSystem::file_get_contents($path); $cssRules = $this->_extractCssRulesFromContent($contents); return $cssRules; }
/** * Sends the file by streaming it 4096 bytes at a time. This way the * whole file doesn't need to be read into memory at once. This makes * it feasible to send even large files. * * Be careful to sanitize the path parameter if it coming from a web * page. sendFile($params['path']) allows a malicious user to * download any file on your server. * * Options: * * <tt>filename</tt> - suggests a filename for the browser to use. * Defaults to realpath($path). * * <tt>type</tt> - specifies an HTTP content type. * Defaults to 'application/octet-stream'. * * <tt>disposition</tt> - specifies whether the file will be shown inline or downloaded. * Valid values are 'inline' and 'attachment' (default). * * <tt>stream</tt> - whether to send the file to the user agent as it is read (true) * or to read the entire file before sending (false). Defaults to true. * * <tt>buffer_size</tt> - specifies size (in bytes) of the buffer used to stream the file. * Defaults to 4096. * <tt>:x_sendfile</tt> - uses X-Sendfile to send the file when set to +true+. This is currently only available with Lighttpd/Apache2 and specific modules installed and activated. Since this * uses the web server to send the file, this may lower memory consumption on your server and * it will not block your application for further requests. * See http://blog.lighttpd.net/articles/2006/07/02/x-sendfile and * http://tn123.ath.cx/mod_xsendfile/ for details. Defaults to +false+. * * The default Content-Type and Content-Disposition headers are * set to download arbitrary binary files in as many browsers as * possible. IE versions 4, 5, 5.5, and 6 are all known to have * a variety of quirks (especially when downloading over SSL). * * Simple download: * sendFile('/path/to.zip'); * * Show a JPEG in browser: * sendFile('/path/to.jpeg', array('type' => 'image/jpeg', 'disposition' => 'inline')); * * Read about the other Content-* HTTP headers if you'd like to * provide the user with more information (such as Content-Description). * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11 * * Also be aware that the document may be cached by proxies and browsers. * The Pragma and Cache-Control headers declare how the file may be cached * by intermediaries. They default to require clients to validate with * the server before releasing cached responses. See * http://www.mnot.net/cache_docs/ for an overview of web caching and * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 * for the Cache-Control header spec. */ public function sendFile($path, $options = array()) { $path = realpath($path); if (!file_exists($path)) { $Exception = new ControllerException(Ak::t('Cannot read file %path', array('%path' => $path))); $Exception->status = 500; throw $Exception; } $this->performed_render = false; if (!empty($options['x_sendfile'])) { $this->_log("Sending X-Sendfile header {$path}"); $this->Response->addHeader(array('X-Sendfile' => $path)); $this->renderNothing(empty($options['status']) ? 200 : $options['status']); return; } $options['length'] = empty($options['length']) ? filesize($path) : $options['length']; $options['filename'] = empty($options['filename']) ? basename($path) : $options['filename']; $options['type'] = empty($options['type']) ? Ak::mime_content_type($path) : $options['type']; $this->_sendFileHeaders($options); if (!empty($options['stream'])) { $this->render(array('text' => new AkStream($path, $options['buffer_size']))); } else { $this->render(array('text' => AkFileSystem::file_get_contents($path))); } }