/**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     if ($input->post('FORM_SUBMIT') == 'tl_composer_migrate_undo') {
         /** @var RootPackage $rootPackage */
         $rootPackage = $this->composer->getPackage();
         $requires = $rootPackage->getRequires();
         foreach (array_keys($requires) as $package) {
             if ($package != 'contao-community-alliance/composer') {
                 unset($requires[$package]);
             }
         }
         $rootPackage->setRequires($requires);
         $lockPathname = preg_replace('#\\.json$#', '.lock', $this->configPathname);
         /** @var DownloadManager $downloadManager */
         $downloadManager = $this->composer->getDownloadManager();
         $downloadManager->setOutputProgress(false);
         $installer = Installer::create($this->io, $this->composer);
         if (file_exists(TL_ROOT . '/' . $lockPathname)) {
             $installer->setUpdate(true);
         }
         if ($installer->run()) {
             $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
         } else {
             $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
             $this->redirect('contao/main.php?do=composer&migrate=undo');
         }
         // load config
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         // remove migration status
         unset($config['extra']['contao']['migrated']);
         // write config
         $json->write($config);
         // disable composer client and enable repository client
         $inactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']);
         $inactiveModules[] = '!composer';
         foreach (array('rep_base', 'rep_client', 'repository') as $module) {
             $pos = array_search($module, $inactiveModules);
             if ($pos !== false) {
                 unset($inactiveModules[$pos]);
             }
         }
         if (version_compare(VERSION, '3', '>=')) {
             $skipFile = new \File('system/modules/!composer/.skip');
             $skipFile->write('Remove this file to enable the module');
             $skipFile->close();
         }
         if (file_exists(TL_ROOT . '/system/modules/repository/.skip')) {
             $skipFile = new \File('system/modules/repository/.skip');
             $skipFile->delete();
         }
         $this->Config->update("\$GLOBALS['TL_CONFIG']['inactiveModules']", serialize($inactiveModules));
         $this->redirect('contao/main.php?do=repository_manager');
     }
     $template = new \BackendTemplate('be_composer_client_migrate_undo');
     $template->composer = $this->composer;
     $template->output = $_SESSION['COMPOSER_OUTPUT'];
     unset($_SESSION['COMPOSER_OUTPUT']);
     return $template->parse();
 }
Example #2
0
File: Alias.php Project: ayaou/Zuha
 /**
  * afterSave
  * 
  * Write out the routes.php file
  */
 public function afterSave($created, $options = array())
 {
     $aliases = $this->find('all');
     $routes = '';
     foreach ($aliases as $alias) {
         $alias['Alias']['name'] = $alias['Alias']['name'] == 'home' ? '' : $alias['Alias']['name'];
         // keyword home is the homepage
         $plugin = !empty($alias['Alias']['plugin']) ? '/' . $alias['Alias']['plugin'] : null;
         $controller = !empty($alias['Alias']['controller']) ? '/' . $alias['Alias']['controller'] : null;
         $action = !empty($alias['Alias']['action']) ? '/' . $alias['Alias']['action'] : null;
         $value = !empty($alias['Alias']['value']) ? '/' . $alias['Alias']['value'] : null;
         $url = $plugin . $controller . $action . $value;
         $routes .= 'Router::redirect(\'' . $url . '\', \'/' . $alias['Alias']['name'] . '\', array(\'status\' => 301));' . PHP_EOL;
         $routes .= 'Router::connect(\'/' . $alias['Alias']['name'] . '\', array(\'plugin\' => \'' . $alias['Alias']['plugin'] . '\', \'controller\' => \'' . $alias['Alias']['controller'] . '\', \'action\' => \'' . $alias['Alias']['action'] . '\', \'' . implode('\', \'', explode('/', $alias['Alias']['value'])) . '\'));' . PHP_EOL;
     }
     App::uses('File', 'Utility');
     $file = new File(ROOT . DS . SITE_DIR . DS . 'Config' . DS . 'routes.php');
     $currentRoutes = str_replace(array('<?php ', '<?php'), '', explode('// below this gets overwritten', $file->read()));
     $routes = '<?php ' . $currentRoutes[0] . '// below this gets overwritten' . PHP_EOL . PHP_EOL . $routes;
     if ($file->write($routes)) {
         $file->close();
     } else {
         $file->close();
         // Be sure to close the file when you're done
         throw new Exception(__('Error writing routes file'));
     }
     // <?php
     // Router::redirect('/webpages/webpages/view/113', '/lenovo', array('status' => 301));
     // Router::connect('/lenovo', array('plugin' => 'webpages', 'controller' => 'webpages', 'action' => 'view', 113));
 }
Example #3
0
 public function login()
 {
     if ($this->request->is('post')) {
         if ($this->Auth->login()) {
             /* ログイン時に定期バックアップを判定して作成ここから */
             $file_pass = '******';
             $file_name = 'sister_backup';
             $backup_flg = 1;
             $folder = new Folder($file_pass);
             $lists = $folder->read();
             foreach ($lists[1] as $list) {
                 //ファイル名から日付を取得
                 $name = str_replace(array($file_name . '_', '.txt'), '', $list);
                 if (date('Ymd', strtotime('-7 day')) < date($name)) {
                     //直近のファイルがあればflgを消去
                     $backup_flg = 0;
                     break;
                 }
             }
             if ($backup_flg == 1) {
                 //flgがあればバックアップを作成
                 //DBデータを取得する
                 $array_model = array('Administrator', 'Banner', 'Birthday', 'Diary', 'DiaryGenre', 'Game', 'Information', 'Link', 'Maker', 'Music', 'Photo', 'Product', 'SisterComment', 'Voice');
                 foreach ($array_model as $model) {
                     $this->{$model}->Behaviors->disable('SoftDelete');
                     $datas = $this->{$model}->find('all', array('order' => $model . '.id', 'recursive' => -1));
                     $this->set($model . '_datas', $datas);
                     $this->set($model . '_tbl', $this->{$model}->useTable);
                 }
                 $this->set('array_model', $array_model);
                 $this->layout = false;
                 $sql = $this->render('sql_backup');
                 $file = new File($file_pass . '/' . $file_name . '_' . date('Ymd') . '.sql', true);
                 if ($file->write($sql)) {
                     //バックアップ成功時の処理
                     $file->close();
                     foreach ($lists[1] as $list) {
                         $file = new File($file_pass . '/' . $list);
                         $file->delete();
                         $file->close();
                     }
                 } else {
                     //バックアップ失敗時の処理
                     $file->close();
                     $admin_mail = Configure::read('admin_mail');
                     $email = new CakeEmail('gmail');
                     $email->to($admin_mail)->subject('【虹妹prprシステム通知】バックアップエラー通知')->template('backup_error', 'sister_mail')->viewVars(array('name' => '管理者'));
                     //mailに渡す変数
                     $email->send();
                 }
             }
             /* ログイン時に定期バックアップを判定して作成ここまで */
             $this->redirect($this->Auth->redirect());
         } else {
             $this->Flash->error(__('ユーザ名かパスワードが間違っています。'));
             $this->redirect('/login/');
         }
     }
 }
Example #4
0
 function dot($projects, $relations, $userId, $calculatedProjectIds, $filtertype = "hide")
 {
     // TODO secure $graphname!
     App::import('Model', 'ProjectsUsers');
     $projectsUsersClass = new ProjectsUsers();
     $projectAssocs = $projectsUsersClass->find('list', array('conditions' => array('ProjectsUsers.user_id' => $userId, 'OR' => array('ProjectsUsers.done' => 1, 'ProjectsUsers.wanted' => 1)), 'fields' => array('ProjectsUsers.project_id', 'ProjectsUsers.wanted')));
     $data = 'digraph go4d {' . "\n";
     foreach ($projects as $id => $name) {
         $dotProjectArr = array('label = "WP0' . $id . ': ' . $name . '"');
         $dotProjectArr[] = 'href="project_' . $id . '_imap"';
         if (in_array($id, array_keys($projectAssocs)) && $projectAssocs[$id]['wanted'] == 1) {
             $dotProjectArr[] = 'color="red"';
         } elseif (in_array($id, array_keys($projectAssocs))) {
             $dotProjectArr[] = 'color="green"';
         } elseif (in_array($id, $calculatedProjectIds)) {
             $dotProjectArr[] = 'color="black"';
         } else {
             if ($filtertype == "focus") {
                 $dotProjectArr[] = 'color="#aaaaaa"';
                 $dotProjectArr[] = 'fontcolor="#aaaaaa"';
             } elseif ($filtertype == "hide") {
                 $dotProjectArr = null;
             }
         }
         if ($dotProjectArr) {
             $data .= $id . ' [' . implode(', ', $dotProjectArr) . ']' . ";\n";
         }
     }
     foreach ($relations as $r) {
         $relStart = $r['Relation']['project_preceding_id'] . ' -> ' . $r['Relation']['project_id'];
         $relData = array('color' => 'color="#000044"');
         if ($r['Relation']['type'] == 'constraint') {
             $relData['color'] = 'color="green"';
         }
         if (!(in_array($r['Relation']['project_preceding_id'], $calculatedProjectIds) && in_array($r['Relation']['project_id'], $calculatedProjectIds))) {
             if ($filtertype == "focus") {
                 $relData = array('color' => 'color="#aaaaaa"');
             } elseif ($filtertype == "hide") {
                 $relData = null;
             }
         }
         if ($relData) {
             $data .= $relStart . ' [' . implode(', ', $relData) . "];\n";
         }
     }
     $data .= '}';
     $file = new File(TMP . 'graphs' . DS . $userId . '.dot', true);
     $file->write($data);
     $file->close();
     $cmd = 'dot -v -Tpng -o"' . IMAGES . 'graphs' . DS . $userId . '.png" -Timap_np -o"' . TMP . 'graphs' . DS . $userId . '.map" ' . TMP . 'graphs' . DS . $userId . '.dot';
     $graphOutput = shell_exec($cmd);
     $fn = IMAGES . 'graphs' . DS . $userId . '.png';
     //        header('Content-Length: '.filesize($fn));
     Configure::write('debug', 0);
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT', true, 200);
     header('Content-Type: image/png');
     print file_get_contents($fn);
     exit;
     //      return $graphOutput;
 }
Example #5
0
 function find($conditions = null, $fields = array(), $order = null, $recursive = null)
 {
     if ($conditions != 'range') {
         return parent::find($conditions, $fields, $order, $recursive);
     }
     $file = Set::extract($fields, 'file');
     if (empty($file)) {
         $file = ROOT . DS . APP_DIR . DS . 'plugins/mobileip/config/mobile_ips.yml';
     }
     if (!file_exists($file)) {
         return false;
     }
     $cacheDir = $this->getCacheDir();
     $folder = new Folder($cacheDir);
     $folder->create($cacheDir, 0777);
     $cacheFile = $this->getCacheFile();
     if (file_exists($cacheFile) && $this->_getLastModified($file) <= filemtime($cacheFile)) {
         return include $cacheFile;
     }
     $mobile_ips =& Spyc::YAMLLoad($file);
     if (!is_array($mobile_ips)) {
         return false;
     }
     $data = $this->_get_ranges($mobile_ips);
     $file = new File($cacheFile, true);
     $file->write($data);
     $file->close();
     return include $cacheFile;
 }
 /**
  * Bower update
  *
  * @param Model $model Model using this behavior
  * @param string $plugin Plugin namespace
  * @param string $option It is '' or '--save'. '--save' is used install.
  * @return bool True on success
  */
 public function updateBower(Model $model, $plugin, $option = '')
 {
     if (!$plugin) {
         return false;
     }
     $pluginPath = ROOT . DS . 'app' . DS . 'Plugin' . DS . Inflector::camelize($plugin) . DS;
     if (!file_exists($pluginPath . 'bower.json')) {
         return true;
     }
     $file = new File($pluginPath . 'bower.json');
     $bower = json_decode($file->read(), true);
     $file->close();
     foreach ($bower['dependencies'] as $package => $version) {
         CakeLog::info(sprintf('[bower] Start bower install %s#%s for %s', $package, $version, $plugin));
         $messages = array();
         $ret = null;
         exec(sprintf('cd %s && `which bower` --allow-root install %s#%s %s', ROOT, $package, $version, $option), $messages, $ret);
         // Write logs
         if (Configure::read('debug')) {
             foreach ($messages as $message) {
                 CakeLog::info(sprintf('[bower]   %s', $message));
             }
         }
         CakeLog::info(sprintf('[bower] Successfully bower install %s#%s for %s', $package, $version, $plugin));
     }
     return true;
 }
 /**
  * [ADMIN] サイトマップXML生成実行ページ
  */
 public function admin_index()
 {
     $path = WWW_ROOT . Configure::read('Sitemapxml.filename');
     if ($this->request->data) {
         $sitemap = $this->requestAction('/admin/sitemapxml/sitemapxml/create', array('return', $this->request->data));
         ClassRegistry::removeObject('View');
         $File = new File($path);
         $File->write($sitemap);
         $File->close();
         $this->setMessage('サイトマップの生成が完了しました。');
         chmod($path, 0666);
     }
     $dirWritable = true;
     $fileWritable = true;
     if (file_exists($path)) {
         if (!is_writable($path)) {
             $fileWritable = false;
         }
     } else {
         if (!is_writable(dirname($path))) {
             $dirWritable = false;
         }
     }
     $this->set('path', $path);
     $this->set('fileWritable', $fileWritable);
     $this->set('dirWritable', $dirWritable);
     $this->pageTitle = 'サイトマップXML作成';
     $this->render('index');
 }
Example #8
0
 public function admin_reset($user_id)
 {
     if ($this->Auth->user('role') > 1) {
         $dir = new Folder('../webroot/img/avatars/');
         if ($dir->path != null) {
             // On supprime le fichier
             $files = $dir->find($user_id . '.jpg');
             foreach ($files as $file) {
                 $file = new File($dir->pwd() . DS . $file);
                 $file->delete();
                 $file->close();
             }
             // On sauvegarde
             $user = $this->User->find('first', ['conditions' => ['User.id' => $user_id]]);
             $username = $user['User']['username'];
             $avatar = 'http://cravatar.eu/helmavatar/' . $username;
             $this->User->id = $user_id;
             $this->User->saveField('avatar', $avatar);
             // Redirection
             $this->Session->setFlash('L\'avatar de ' . $username . ' a été réinitialisé', 'toastr_success');
             return $this->redirect(['controller' => 'users', 'action' => 'edit', $user_id]);
         }
     } else {
         throw new NotFoundException();
     }
 }
Example #9
0
 function download()
 {
     $result = array('success' => true, 'error' => null);
     $home = Configure::read('20Couch.home');
     App::import('Core', array('HttpSocket', 'File'));
     $Http = new HttpSocket();
     $Setting = ClassRegistry::init('Setting');
     $url = sprintf('%s/registrations/direct/%s/' . Configure::read('Update.file'), $home, $Setting->find('value', 'registration_key'));
     $latest = $Http->get($url);
     if ($latest === false || $Http->response['status']['code'] != 200) {
         if ($Http->response['status']['code'] == 401) {
             $msg = 'Invalid registration key';
         } else {
             $msg = 'Unable to retrieve latest file from ' . $home;
         }
         $this->log($url);
         $this->log($Http->response);
         $result = array('success' => false, 'error' => $msg);
         $this->set('result', $result);
         return;
     }
     $File = new File(TMP . Configure::read('Update.file'), false);
     $File->write($latest);
     $File->close();
     $latestChecksum = trim($Http->get($home . '/checksum'));
     $yourChecksum = sha1_file(TMP . Configure::read('Update.file'));
     if ($yourChecksum != $latestChecksum) {
         $result = array('success' => false, 'error' => 'Checksum doesn\'t match (' . $yourChecksum . ' vs ' . $latestChecksum . ')');
         $this->set('result', $result);
         return;
     }
     $result = array('success' => true, 'error' => null);
     $this->set('result', $result);
 }
Example #10
0
 private function _rawParse($filename, $attributes)
 {
     App::import('Vendor', 'import.excelreader/excelreader');
     $buffer = array();
     if (file_exists($filename)) {
         if (isset($attributes['delimiter']) && (isset($attributes['excel_reader']) && $attributes['excel_reader'])) {
             $xl = new ExcelReader();
             $xl->read($filename);
             $tmp_array = $xl->toArray();
             for ($i = 0; $i < 10; $i++) {
                 if (isset($tmp_array[$i])) {
                     $buffer[] = implode("\t", $tmp_array[$i]);
                 }
             }
         } else {
             $file = new File($filename);
             if ($file->open('r', true)) {
                 for ($i = 0; $i < 10; $i++) {
                     if (isset($attributes['delimiter']) && $attributes['delimiter'] != "") {
                         if (isset($attributes['qualifier']) && $attributes['qualifier'] != "") {
                             $buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter'], $attributes['qualifier']);
                         } else {
                             $buffer[] = @fgetcsv($file->handle, null, $attributes['delimiter']);
                         }
                     }
                 }
                 $file->close();
             } else {
                 // Error
             }
         }
     }
     return $buffer;
 }
 /**
  * Delete all values from the cache
  *
  * @param boolean $check Optional - only delete expired cache items
  * @return boolean True if the cache was succesfully cleared, false otherwise
  * @access public
  */
 function clear($check)
 {
     if (!$this->__init) {
         return false;
     }
     $dir = dir($this->settings['path']);
     if ($check) {
         $now = time();
         $threshold = $now - $this->settings['duration'];
     }
     while (($entry = $dir->read()) !== false) {
         if ($this->__setKey($entry) === false) {
             continue;
         }
         if ($check) {
             $mtime = $this->__File->lastChange();
             if ($mtime === false || $mtime > $threshold) {
                 continue;
             }
             $expires = $this->__File->read(11);
             $this->__File->close();
             if ($expires > $now) {
                 continue;
             }
         }
         $this->__File->delete();
     }
     $dir->close();
     return true;
 }
Example #12
0
 /**
  * Execute Config/cakegallery.sql to create the tables
  * Create the config File
  * @param $db
  */
 private function _setupDatabase($db)
 {
     # Execute the SQL to create the tables
     $sqlFile = new File(App::pluginPath('Gallery') . 'Config' . DS . 'cakegallery.sql', false);
     $db->rawQuery($sqlFile->read());
     $sqlFile->close();
 }
Example #13
0
 /**
  * add uuids to tl_gallery_creator_pictures version added in 4.8.0
  */
 public static function addUuids()
 {
     // add field
     if (!\Database::getInstance()->fieldExists('uuid', 'tl_gallery_creator_pictures')) {
         \Database::getInstance()->query("ALTER TABLE `tl_gallery_creator_pictures` ADD `uuid` BINARY(16) NULL");
     }
     $objDB = \Database::getInstance()->execute("SELECT * FROM tl_gallery_creator_pictures WHERE uuid IS NULL");
     while ($objDB->next()) {
         if ($objDB->path == '') {
             continue;
         }
         if (is_file(TL_ROOT . '/' . $objDB->path)) {
             \Dbafs::addResource($objDB->path);
         } else {
             continue;
         }
         $oFile = new \File($objDB->path);
         $oFile->close();
         $fileModel = $oFile->getModel();
         if (\Validator::isUuid($fileModel->uuid)) {
             \Database::getInstance()->prepare("UPDATE tl_gallery_creator_pictures SET uuid=? WHERE id=?")->execute($fileModel->uuid, $objDB->id);
             $_SESSION["TL_CONFIRM"][] = "Added a valid file-uuid into tl_gallery_creator_pictures.uuid ID " . $objDB->id . ". Please check if all the galleries are running properly.";
         }
     }
 }
 public function loadDebuggerstate($varValue, $dc)
 {
     $objFile = new File('system/config/initconfig.php');
     $strContent = $objFile->getContent();
     $objFile->close();
     return $varValue && strpos($strContent, self::DEBUGCONFIG_STRING);
 }
Example #15
0
 protected function _rawParse()
 {
     if (file_exists($this->filename)) {
         if (isset($this->options['delimiter']) && (isset($this->options['excel_reader']) && $this->options['excel_reader'])) {
             $xl = new ExcelReader();
             $xl->read($this->filename);
             $tmp_array = $xl->toArray();
             for ($i = 0; $i < 10; $i++) {
                 if (isset($tmp_array[$i])) {
                     $buffer[] = implode("\t", $tmp_array[$i]);
                 }
             }
         } else {
             $file = new File($this->filename);
             if ($file->open('r', true)) {
                 for ($i = 0; $i < 10; $i++) {
                     if (isset($this->options['delimiter']) && $this->options['delimiter'] != "") {
                         if (isset($this->options['qualifier']) && $this->options['qualifier'] != "") {
                             $buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter'], $this->options['qualifier']);
                         } else {
                             $buffer[] = @fgetcsv($file->handle, null, $this->options['delimiter']);
                         }
                     }
                 }
                 $file->close();
             } else {
                 // Error
             }
         }
     }
     return $buffer;
 }
Example #16
0
 /**
  * Update the inactive modules
  * @param mixed
  * @return mixed
  */
 public function updateInactiveModules($varValue)
 {
     $arrModules = deserialize($varValue);
     if (!is_array($arrModules)) {
         $arrModules = array();
     }
     foreach (scan(TL_ROOT . '/system/modules') as $strModule) {
         if (strncmp($strModule, '.', 1) === 0) {
             continue;
         }
         // Add the .skip file to disable the module
         if (in_array($strModule, $arrModules)) {
             if (!file_exists(TL_ROOT . '/system/modules/' . $strModule . '/.skip')) {
                 $objFile = new File('system/modules/' . $strModule . '/.skip');
                 $objFile->write('As long as this file exists, the module will be ignored.');
                 $objFile->close();
             }
         } else {
             if (file_exists(TL_ROOT . '/system/modules/' . $strModule . '/.skip')) {
                 $objFile = new File('system/modules/' . $strModule . '/.skip');
                 $objFile->delete();
             }
         }
     }
     return $varValue;
 }
Example #17
0
 /**
  * init
  *
  * @return
  */
 function init()
 {
     $this->out(__($this->binPath . ' Initialize..', true));
     $this->_setArgs();
     $command = $this->binPath . ' config-create ' . $this->baseDir . ' ' . $this->baseDir . 'pear.conf';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf channel-discover ' . $this->channel;
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set bin_dir ' . $this->baseDir . 'pear' . DS . 'bin';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set php_dir ' . $this->baseDir . 'pear' . DS;
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set data_dir ' . $this->baseDir . 'pear' . DS . 'data';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set cache_dir ' . TMP . 'pear';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set doc_dir ' . $this->baseDir . 'pear' . DS . 'data';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set download_dir ' . DS . 'tmp' . DS . 'pear' . DS . 'build';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set ext_dir ' . $this->baseDir . 'pear' . DS . 'ext';
     system($command);
     $command = $this->binPath . ' -c ' . $this->baseDir . 'pear.conf config-set test_dir ' . $this->baseDir . 'pear' . DS . 'test';
     system($command);
     $code = '<?php set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());';
     $fp = new File($this->baseDir . 'pear' . DS . 'pear_init.php');
     $fp->write($code);
     $fp->close();
     return true;
 }
 /**
  * Returns an abstract of the file content.
  * 
  * @return	string
  */
 public function getContentPreview()
 {
     if ($this->contentPreview === null) {
         $this->contentPreview = '';
         if (ATTACHMENT_ENABLE_CONTENT_PREVIEW && !$this->isBinary && $this->attachmentSize != 0) {
             try {
                 $file = new File(WCF_DIR . 'attachments/attachment-' . $this->attachmentID, 'rb');
                 $this->contentPreview = $file->read(2003);
                 $file->close();
                 if (CHARSET == 'UTF-8') {
                     if (!StringUtil::isASCII($this->contentPreview) && !StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $this->contentPreview);
                     }
                     $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                     if (strlen($this->contentPreview) < $file->filesize()) {
                         $this->contentPreview .= '...';
                     }
                 } else {
                     if (StringUtil::isUTF8($this->contentPreview)) {
                         $this->contentPreview = '';
                     } else {
                         $this->contentPreview = StringUtil::substring($this->contentPreview, 0, 500);
                         if ($file->filesize() > 500) {
                             $this->contentPreview .= '...';
                         }
                     }
                 }
             } catch (Exception $e) {
             }
             // ignore errors
         }
     }
     return $this->contentPreview;
 }
 /**
  * Returns an abstract of the file content.
  * 
  * @param	array		$data
  * @return	string
  */
 protected static function getContentPreview($data)
 {
     if (!ATTACHMENT_ENABLE_CONTENT_PREVIEW || $data['isBinary'] || $data['attachmentSize'] == 0) {
         return '';
     }
     $content = '';
     try {
         $file = new File(WCF_DIR . 'attachments/attachment-' . $data['attachmentID'], 'rb');
         $content = $file->read(2003);
         $file->close();
         if (CHARSET == 'UTF-8') {
             if (!StringUtil::isASCII($content) && !StringUtil::isUTF8($content)) {
                 $content = StringUtil::convertEncoding('ISO-8859-1', CHARSET, $content);
             }
             $content = StringUtil::substring($content, 0, 500);
             if (strlen($content) < $file->filesize()) {
                 $content .= '...';
             }
         } else {
             if (StringUtil::isUTF8($content)) {
                 return '';
             }
             $content = StringUtil::substring($content, 0, 500);
             if ($file->filesize() > 500) {
                 $content .= '...';
             }
         }
     } catch (Exception $e) {
     }
     // ignore errors
     return $content;
 }
Example #20
0
 public function shutdown()
 {
     parent::close();
     if (is_file($this->Filename())) {
         unlink($this->Filename());
     }
 }
 public function buildCss()
 {
     App::import('Vendor', 'AssetMinify.JSMinPlus');
     // Ouverture des fichiers de config
     $dir = new Folder(Configure::read('App.www_root') . 'css' . DS . 'minified');
     if ($dir->path !== null) {
         foreach ($dir->find('config_.*.ini') as $file) {
             preg_match('`^config_(.*)\\.ini$`', $file, $grep);
             $file = new File($dir->pwd() . DS . $file);
             $ini = parse_ini_file($file->path, true);
             $fileFull = new File($dir->path . DS . 'full_' . $grep[1] . '.css', true, 0644);
             $fileGz = new File($dir->path . DS . 'gz_' . $grep[1] . '.css', true, 0644);
             $contentFull = '';
             foreach ($ini as $data) {
                 // On a pas de version minifié
                 if (!($fileMin = $dir->find('file_' . md5($data['url'] . $data['md5']) . '.css'))) {
                     $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css', true, 0644);
                     $this->out("Compression de " . $data['file'] . ' ... ', 0);
                     $fileMin->write(MinifyUtils::compressCss(MinifyUtils::cssAbsoluteUrl($data['url'], file_get_contents($data['file']))));
                     $this->out('OK');
                 } else {
                     $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css');
                 }
                 $contentFull .= $fileMin->read() . PHP_EOL;
             }
             // version full
             $fileFull->write($contentFull);
             $fileFull->close();
             // compression
             $fileGz->write(gzencode($contentFull, 6));
         }
     }
 }
Example #22
0
 public function disableOldClientHook()
 {
     // disable the repo client
     $reset = false;
     $activeModules = $this->Config->getActiveModules();
     $inactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']);
     if (in_array('rep_base', $activeModules)) {
         $inactiveModules[] = 'rep_base';
         $reset = true;
     }
     if (in_array('rep_client', $activeModules)) {
         $inactiveModules[] = 'rep_client';
         $reset = true;
     }
     if (in_array('repository', $activeModules)) {
         $inactiveModules[] = 'repository';
         $skipFile = new \File('system/modules/repository/.skip');
         $skipFile->write('Remove this file to enable the module');
         $skipFile->close();
         $reset = true;
     }
     if ($reset) {
         $this->Config->update("\$GLOBALS['TL_CONFIG']['inactiveModules']", serialize($inactiveModules));
         $this->reload();
     }
     unset($GLOBALS['TL_HOOK']['loadLanguageFiles']['composer']);
 }
 /**
  * Cache the content and return the cache file.
  *
  * @param int         $formId  The form id.
  * @param string      $content The javascript.
  * @param string|null $locale  The locale.
  *
  * @return string
  */
 public function save($formId, $content, $locale = null)
 {
     $fileName = $this->filename($formId, $locale);
     $file = new \File($fileName);
     $file->write($content);
     $file->close();
     return $fileName;
 }
Example #24
0
 /**
  * Locks a account for a specific time.
  * 
  * @param	int		user id
  * @param	int		seconds to lock
  */
 public static function setLock($identifier, $lockTime)
 {
     require_once WCF_DIR . 'lib/system/io/File.class.php';
     $lockFile = new File(LW_DIR . 'lock/lock' . $identifier . '.lock.php');
     $lockTimeEnd = microtime(true) + $lockTime;
     $lockFile->write("<?php\r\n/*\r\n  This file is part of WOT Game.\r\n\r\n    WOT Game is free software: you can redistribute it and/or modify\r\n    it under the terms of the GNU Affero General Public License as published by\r\n    the Free Software Foundation, either version 3 of the License, or\r\n    (at your option) any later version.\r\n\r\n    WOT Game is distributed in the hope that it will be useful,\r\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\n    GNU Affero General Public License for more details.\r\n\r\n    You should have received a copy of the GNU Affero General Public License\r\n    along with WOT Game.  If not, see <http://www.gnu.org/licenses/>.\r\n*/\r\n\n\$lockTimeEnd = " . $lockTimeEnd . ";\n?>");
     $lockFile->close();
 }
Example #25
0
 /**
  * Create the rendered view cache file
  *
  * @param string $file The view file path
  *
  * @return string The file path
  */
 protected function _createRenderedView($file)
 {
     $content = $this->_renderHaml($file);
     $tmpFile = new File($this->_cacheFileName(), true);
     $tmpFile->write($content);
     $tmpFile->close();
     return $tmpFile->pwd();
 }
Example #26
0
 function writeFile()
 {
     //write to www_root
     $file = new File(ROOT . DS . APP_DIR . $this->filename);
     rewind($this->buffer);
     $output = stream_get_contents($this->buffer);
     $file->write($output);
     $file->close();
 }
Example #27
0
 /**
  * Create temporary file for upload test.
  *
  * @param string $fileName Temporary file name
  * @return void
  */
 public function createTmpFile($fileName)
 {
     //アップロードテストのためのテンポラリファイル生成
     $folder = new Folder();
     $folder->create(TMP . 'tests' . DS . 'files' . DS . 'tmp');
     $file = new File(APP . 'Plugin' . DS . 'Files' . DS . 'Test' . DS . 'Fixture' . DS . $fileName);
     $file->copy(TMP . 'tests' . DS . 'files' . DS . 'tmp' . DS . $fileName);
     $file->close();
     unset($folder, $file);
 }
 /**
  * Saves the pdf to file
  *
  * @param        $strFolder   string The folder as a path without TL_ROOT
  * @param string $strFilename The filename without the path
  *
  * @throws \MpdfException
  */
 public function saveToFile($strFolder, $strFilename = '')
 {
     $strFilename = $strFilename ?: $this->buildFilename();
     // create if not exists
     new \Folder($strFolder);
     $this->objPdf->Output(TL_ROOT . '/' . trim($strFolder, '/') . '/' . $strFilename, 'F');
     // save database entity
     $objFile = new \File(trim($strFolder, '/') . '/' . $strFilename);
     $objFile->close();
 }
Example #29
0
 /**
  * セッションに保存した一時ファイルを出力する
  * @param string $name
  * @return void
  * @access public
  */
 function tmp()
 {
     $size = '';
     $args = func_get_args();
     if (func_num_args() > 1) {
         $size = $args[0];
         $name = $args[1];
     } else {
         $name = $args[0];
     }
     $sessioName = str_replace('.', '_', $name);
     $sessionData = $this->Session->read('Upload.' . $sessioName);
     Configure::write('debug', 0);
     $type = $sessionData['type'];
     $ext = decodeContent($type, $name);
     if (!$ext) {
         $this->notFound();
     }
     $fileInfo = array();
     if (isset($sessionData['imagecopy'][$size])) {
         $fileInfo = $sessionData['imagecopy'][$size];
     } elseif (isset($sessionData['imageresize'])) {
         $fileInfo = $sessionData['imageresize'];
     } else {
         $size = '';
     }
     if (!$size) {
         $data = $this->Session->read('Upload.' . $sessioName . '.data');
     } else {
         if (is_dir(TMP . 'uploads')) {
             mkdir(TMP . 'uploads');
             chmod(TMP . 'uploads', 0777);
         }
         $path = TMP . 'uploads' . DS . $name;
         $file = new File($path, true);
         $file->write($this->Session->read('Upload.' . $sessioName . '.data'), 'wb');
         $file->close();
         $thumb = false;
         if (!empty($fileInfo['thumb'])) {
             $thumb = $fileInfo['thumb'];
         }
         App::import('Vendor', 'Imageresizer');
         $imageresizer = new Imageresizer(APP . 'tmp');
         $imageresizer->resize($path, $path, $fileInfo['width'], $fileInfo['height'], $thumb);
         $data = file_get_contents($path);
         unlink($path);
     }
     if ($ext != 'gif' && $ext != 'jpg' && $ext != 'png') {
         Header("Content-disposition: attachment; filename=" . $name);
     }
     Header("Content-type: " . $type . "; name=" . $name);
     echo $data;
     $this->Session->del('Upload.' . $sessioName);
     exit;
 }
 public function getResponsePart($strFilename, $intFilecount)
 {
     $strFilepath = "/system/tmp/" . $intFilecount . "_" . $strFilename;
     if (!file_exists(TL_ROOT . $strFilepath)) {
         throw new \RuntimeException("Missing partfile {$strFilepath}");
     }
     $objFile = new \File($strFilepath);
     $strReturn = $objFile->getContent();
     $objFile->close();
     return $strReturn;
 }