public function testSimple() { $file = OC::$SERVERROOT . '/3rdparty/MDB2.php'; $original = file_get_contents($file); OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled = false; $stored = OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled = true; $fromFile = OC_Filesystem::file_get_contents('/file'); $this->assertNotEqual($original, $stored); $this->assertEqual($original, $fromFile); }
* This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ // Init owncloud // Check if we are a user OCP\JSON::checkLoggedIn(); // Set the session key for the file we are about to edit. $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; $filename = isset($_GET['file']) ? $_GET['file'] : ''; if (!empty($filename)) { $path = $dir . '/' . $filename; if (OC_Filesystem::is_writable($path)) { $mtime = OC_Filesystem::filemtime($path); $filecontents = OC_Filesystem::file_get_contents($path); $filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents); OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'write' => 'true', 'mtime' => $mtime))); } else { $mtime = OC_Filesystem::filemtime($path); $filecontents = OC_Filesystem::file_get_contents($path); $filecontents = iconv(mb_detect_encoding($filecontents), "UTF-8", $filecontents); OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'write' => 'false', 'mtime' => $mtime))); } } else { OCP\JSON::error(array('data' => array('message' => 'Invalid file path supplied.'))); }
/** * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\App::checkAppEnabled('calendar'); OCP\JSON::callCheck(); session_write_close(); if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) { echo OCP\JSON::success(array('percent' => OC_Cache::get($_POST['progresskey']))); exit; } $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); if (!$file) { OCP\JSON::error(array('error' => '404')); } $import = new OC_Calendar_Import($file); $import->setUserID(OCP\User::getUser()); $import->setTimeZone(OC_Calendar_App::$tz); $import->enableProgressCache(); $import->setProgresskey($_POST['progresskey']); if (!$import->isValid()) { OCP\JSON::error(array('error' => 'notvalid')); exit; } $newcal = false; if ($_POST['method'] == 'new') { $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser());
/** * @NoAdminRequired */ public function prepare() { $request = $this->request; $params = $this->request->urlParams; $response = new JSONResponse(); $filename = $request->post['filename']; $path = $request->post['path']; $view = \OCP\Files::getStorage('contacts'); if (!$view->file_exists('imports')) { $view->mkdir('imports'); } $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $content = \OC_Filesystem::file_get_contents($path . '/' . $filename); //$content = file_get_contents('oc://' . $path . '/' . $filename); if ($view->file_put_contents('/imports/' . $filename, $content)) { \OC_FileProxy::$enabled = $proxyStatus; $count = substr_count($content, 'BEGIN:'); $progresskey = 'contacts-import-' . rand(); $response->setParams(array('filename' => $filename, 'count' => $count, 'progresskey' => $progresskey, 'backend' => $params['backend'], 'addressBookId' => $params['addressBookId'])); \OC_Cache::set($progresskey, '10', 300); } else { \OC_FileProxy::$enabled = $proxyStatus; $response->bailOut(App::$l10n->t('Error moving file to imports folder.')); } return $response; }
} if ($_GET["path"] != "") { $filename = $_GET["path"] . "/" . $_GET["file"]; } else { $filename = "/" . $_GET["file"]; } } else { $id = OC_Calendar_Calendar::addCalendar(OC_User::getUser(), $_POST['calname']); OC_Calendar_Calendar::setCalendarActive($id, 1); $calid = $id; if ($_POST["path"] != "") { $filename = $_POST["path"] . "/" . $_POST["file"]; } else { $filename = "/" . $_POST["file"]; } } $vcalendar = OC_Filesystem::file_get_contents($filename); $vcalendar = explode("BEGIN:VEVENT", $vcalendar); for ($i = 1; $i < count($vcalendar); $i++) { $vcalendar[$i] = "BEGIN:VEVENT" . $vcalendar[$i]; } for ($i = 1; $i < count($vcalendar) - 1; $i++) { $vcalendar[$i] = $vcalendar[$i] . "END:VCALENDAR"; } for ($i = 1; $i < count($vcalendar); $i++) { $vcalendar[$i] = $vcalendar[0] . $vcalendar[$i]; } for ($i = 1; $i < count($vcalendar); $i++) { OC_Calendar_Object::add($calid, $vcalendar[$i]); } OC_JSON::success();
/** * @brief Loads an image from a local file. * @param $imageref The path to a local file. * @returns An image resource or false on error */ public function loadFromFile($imagepath=false) { if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) { // Debug output disabled because this method is tried before loadFromBase64? OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.$imagepath, OC_Log::DEBUG); return false; } $itype = exif_imagetype($imagepath); switch($itype) { case IMAGETYPE_GIF: if (imagetypes() & IMG_GIF) { $this->resource = imagecreatefromgif($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_JPEG: if (imagetypes() & IMG_JPG) { $this->resource = imagecreatefromjpeg($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_PNG: if (imagetypes() & IMG_PNG) { $this->resource = imagecreatefrompng($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_XBM: if (imagetypes() & IMG_XPM) { $this->resource = imagecreatefromxbm($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_WBMP: if (imagetypes() & IMG_WBMP) { $this->resource = imagecreatefromwbmp($imagepath); } else { OC_Log::write('core', 'OC_Image->loadFromFile, WBMP images not supported: '.$imagepath, OC_Log::DEBUG); } break; case IMAGETYPE_BMP: $this->resource = $this->imagecreatefrombmp($imagepath); break; /* case IMAGETYPE_TIFF_II: // (intel byte order) break; case IMAGETYPE_TIFF_MM: // (motorola byte order) break; case IMAGETYPE_JPC: break; case IMAGETYPE_JP2: break; case IMAGETYPE_JPX: break; case IMAGETYPE_JB2: break; case IMAGETYPE_SWC: break; case IMAGETYPE_IFF: break; case IMAGETYPE_ICO: break; case IMAGETYPE_SWF: break; case IMAGETYPE_PSD: break; */ default: // this is mostly file created from encrypted file $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath))); $itype = IMAGETYPE_PNG; OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG); break; } if($this->valid()) { $this->imagetype = $itype; $this->filepath = $imagepath; } return $this->resource; }
<?php //Prerendering for iCalendar file $file = OC_Filesystem::file_get_contents($_['path'] . '/' . $_['filename']); if (!$file) { OCP\JSON::error(array('error' => '404')); } $import = new OC_Calendar_Import($file); $import->setUserID(OCP\User::getUser()); $newcalendarname = strip_tags($import->createCalendarName()); $guessedcalendarname = strip_tags($import->guessCalendarName()); $calendarcolor = strip_tags($import->createCalendarColor()); //loading calendars for select box $calendar_options = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser()); $calendar_options[] = array('id' => 'newcal', 'displayname' => $l->t('create a new calendar')); $defaultcolors = OC_Calendar_Calendar::getCalendarColorOptions(); ?> <div id="calendar_import_dialog" title="<?php echo $l->t("Import a calendar file"); ?> "> <div id="calendar_import_form"> <form> <input type="hidden" id="calendar_import_filename" value="<?php echo $_['filename']; ?> "> <input type="hidden" id="calendar_import_path" value="<?php echo $_['path']; ?> ">
* */ require_once 'lib/impressionist.php'; // Check if we are a user OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('impressionist'); $filename = OCP\Util::sanitizeHTML($_GET['file']); $title = OCP\Util::sanitizeHTML($_GET['name']); if (!OC_Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OCP\Template('', '404', 'guest'); $tmpl->assign('file', $filename); $tmpl->printPage(); exit; } $data = OC_Filesystem::file_get_contents($filename); // Validity for the Impress file (From impress app) if (stripos($data, '<html') != false or stripos($data, '<head') != false or stripos($data, '<body') != false) { echo '<br /><center>This is not a valid impress file. Please check the documentation.</center>'; exit; } if (stripos($data, '<script') != false) { echo '<br /><center>Please don\'t use javascript in impress files.</center>'; exit; } header('Content-Type: text/html', true); OCP\Response::disableCaching(); @ob_end_clean(); \OCA_Impressionist\Storage::showHeader($title); OC_Filesystem::readfile($filename); \OCA_Impressionist\Storage::showFooter();
public function testBinary() { $file = __DIR__ . '/binary'; $original = file_get_contents($file); OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled = false; $stored = OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled = true; $fromFile = OC_Filesystem::file_get_contents('/file'); $this->assertNotEqual($original, $stored); $this->assertEqual(strlen($original), strlen($fromFile)); $this->assertEqual($original, $fromFile); $file = __DIR__ . '/zeros'; $original = file_get_contents($file); OC_Filesystem::file_put_contents('/file', $original); OC_FileProxy::$enabled = false; $stored = OC_Filesystem::file_get_contents('/file'); OC_FileProxy::$enabled = true; $fromFile = OC_Filesystem::file_get_contents('/file'); $this->assertNotEqual($original, $stored); $this->assertEqual(strlen($original), strlen($fromFile)); }
/** * Returns an associative array with the info associated with a running job * the array contains the keys: * status (either RUNNING, KILLED, FINISHED) * pid (numeric) * start_date * * if the $study parameter does not represent a valid case study, or if $jobid does not exist * or if the * * @param type $study * @param type $jobid * @return array an array with the job info, containing the key "pid", "job_id" */ function get_job_info($study, $jobid) { $path = get_job_info_file($study, $jobid); if (OC_Filesystem::is_file($path)) { $json = OC_Filesystem::file_get_contents($path); return json_decode($json, true); // true for returning an associative array } else { return false; } }
/** * Returns the data * * @return string */ public function get() { return OC_Filesystem::file_get_contents($this->path); }