/** * Verifica se os menus do banco estão atualizados com os do arquivo * @param $aDados- array de menus do banco * @return boolean */ public function isUpToDate($aDados) { $aDados = Set::combine($aDados, "/Menu/id", "/Menu"); App::import("Xml"); App::import("Folder"); App::import("File"); $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus"); $oFolder = new Folder($sCaminhosArquivos); $aConteudo = $oFolder->read(); $aArquivos = Set::sort($aConteudo[1], "{n}", "desc"); if (empty($aArquivos)) { return false; } $oFile = new File($sCaminhosArquivos . $aArquivos[0]); $oXml = new Xml($oFile->read()); $aAntigo = $oXml->toArray(); foreach ($aDados as &$aMenu) { $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']); } if (isset($aAntigo["menus"])) { $aAntigo["Menus"] = $aAntigo["menus"]; unset($aAntigo["menus"]); } if (isset($aAntigo["Menus"])) { $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu"); $aRetorno = Set::diff($aDados, $aAntigo); } return empty($aRetorno); }
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)); } } }
function _write() { // Load library App::uses('File', 'Utility'); $translations = $this->Translation->find('all'); $trunced = array(); foreach ($translations as $t) { $t = $t['Translation']; if (empty($t['value'])) { continue; } $lang = $t['language']; $domain = $t['domain']; $filePath = APP . 'Locale' . DS . $lang . DS . 'LC_MESSAGES' . DS . $domain . '.po'; $file = new File($filePath); if (!isset($trunced[$filePath])) { $file->open('w'); $trunced[$filePath] = true; $file->close(); } $append = 'msgid "' . str_replace('"', '\\"', $t['name']) . "\"\n"; $append .= 'msgstr "' . str_replace('"', '\\"', $t['value']) . "\"\n\n"; $file->write($append, 'a'); } }
public function testDeletingFileMarksBackedPagesAsBroken() { // Test entry $file = new File(); $file->Filename = 'test-file.pdf'; $file->write(); $obj = $this->objFromFixture('Page', 'content'); $obj->Content = sprintf('<p><a href="[file_link,id=%d]">Working Link</a></p>', $file->ID); $obj->write(); $this->assertTrue($obj->doPublish()); // Confirm that it isn't marked as broken to begin with $obj->flushCache(); $obj = DataObject::get_by_id("SiteTree", $obj->ID); $this->assertEquals(0, $obj->HasBrokenFile); $liveObj = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = {$obj->ID}"); $this->assertEquals(0, $liveObj->HasBrokenFile); // Delete the file $file->delete(); // Confirm that it is marked as broken in both stage and live $obj->flushCache(); $obj = DataObject::get_by_id("SiteTree", $obj->ID); $this->assertEquals(1, $obj->HasBrokenFile); $liveObj = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = {$obj->ID}"); $this->assertEquals(1, $liveObj->HasBrokenFile); }
/** * 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; }
/** * Handle all files * @return void */ public function upload() { foreach ($this->files as $source => $dest) { $file = new File($source); $file->move($dest['path'], $dest['filename']); } }
/** * 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)); }
public function toArray() { $array = array('title' => $this->title); if ($this->subarea != null) { $array['subarea'] = $this->subarea->toArray(); } if ($this->file != null) { $array['file'] = $this->file->toArray(); } if ($this->state != null) { $array['state'] = $this->state->toArray(); } if ($this->date != null) { $array['date'] = $this->date(); } if ($this->type != null) { $array['type'] = $this->getType(); } if ($this->year != null) { $array['year'] = $this->getYear(); } if ($this->event != null) { $array['event'] = $this->getEvent(); } return $array; }
public static function uploadFileToStorage(File $file) { $filename = 'file_' . substr(md5(uniqid(rand())), 6) . '_' . $file->getClientOriginalName(); $path = self::uploadPath(); $file->move($path, $filename); return $path . DIRECTORY_SEPARATOR . $filename; }
/** * @covers Respect\Validation\Rules\File::validate */ public function testShouldValidateObjects() { $rule = new File(); $object = $this->createMock('SplFileInfo', ['isFile'], ['somefile.txt']); $object->expects($this->once())->method('isFile')->will($this->returnValue(true)); $this->assertTrue($rule->validate($object)); }
/** * Step 1: database * * @return void */ function database() { $this->pageTitle = __('Step 1: Database', true); if (!empty($this->data)) { // test database connection if (mysql_connect($this->data['Install']['host'], $this->data['Install']['login'], $this->data['Install']['password']) && mysql_select_db($this->data['Install']['database'])) { // rename database.php.install rename(APP . 'config' . DS . 'database.php.install', APP . 'config' . DS . 'database.php'); // open database.php file App::import('Core', 'File'); $file = new File(APP . 'config' . DS . 'database.php', true); $content = $file->read(); // write database.php file $content = str_replace('{default_host}', $this->data['Install']['host'], $content); $content = str_replace('{default_login}', $this->data['Install']['login'], $content); $content = str_replace('{default_password}', $this->data['Install']['password'], $content); $content = str_replace('{default_database}', $this->data['Install']['database'], $content); // The database import script does not support prefixes at this point $content = str_replace('{default_prefix}', '', $content); if ($file->write($content)) { $this->redirect(array('action' => 'data')); } else { $this->Session->setFlash(__('Could not write database.php file.', true)); } } else { $this->Session->setFlash(__('Could not connect to database.', true)); } } }
public function saveAsThumbnail($folderPath, $fileName_withExtension, $targetHeight, $targetWidth) { /* load up the image */ $image = Yii::app()->image->load($this->filePath); /* determine the original image property landscape or protrait */ $imageWidth = $image->width; $imageHeight = $image->height; $isImageLandscape = $imageWidth > $imageHeight; $isImageProtrait = $imageHeight > $imageWidth; $isImageSquare = $imageHeight == $imageWidth; /* determine the target image property */ $isTargetImageLandscape = $targetWidth > $targetHeight; $isTargetImageProtrait = $targetHeight > $targetWidth; $isTargetImageSquare = $targetHeight == $targetWidth; $finalImagePath = $folderPath . '/' . $fileName_withExtension; if (file_exists($finalImagePath)) { $file = new File($finalImagePath); $file->delete(); } $image->resize($targetWidth, $targetHeight, Image::WIDTH); $resizeFactor = $targetWidth / $imageWidth; $resizedImageHeight = ceil($imageHeight * $resizeFactor); if ($resizedImageHeight < $targetHeight) { $image->crop($targetHeight, $targetWidth); $image->resize($targetWidth, $targetHeight, Image::HEIGHT); } else { if ($resizedImageHeight > $targetHeight) { $image->crop($targetHeight, $targetWidth); } } $image->save($finalImagePath); return $finalImagePath; //$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20); //$image->save(); // or $image->save('images/small.jpg'); }
public function SubsiteList() { if ($this->owner->class == 'AssetAdmin') { // See if the right decorator is there.... $file = new File(); if (!$file->hasExtension('FileSubsites')) { return false; } } $list = $this->Subsites(); $currentSubsiteID = Subsite::currentSubsiteID(); if ($list->Count() > 1) { $output = '<select id="SubsitesSelect">'; foreach ($list as $subsite) { $selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : ''; $output .= "\n<option value=\"{$subsite->ID}\"{$selected}>" . htmlspecialchars($subsite->Title, ENT_QUOTES) . "</option>"; } $output .= '</select>'; Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js'); return $output; } else { if ($list->Count() == 1) { return $list->First()->Title; } } }
function testWritingSubsiteID() { $this->objFromFixture('Member', 'admin')->logIn(); $subsite = $this->objFromFixture('Subsite', 'domaintest1'); FileSubsites::$default_root_folders_global = true; Subsite::changeSubsite(0); $file = new File(); $file->write(); $file->onAfterUpload(); $this->assertEquals((int) $file->SubsiteID, 0); Subsite::changeSubsite($subsite->ID); $this->assertTrue($file->canEdit()); $file = new File(); $file->write(); $this->assertEquals((int) $file->SubsiteID, 0); $this->assertTrue($file->canEdit()); FileSubsites::$default_root_folders_global = false; Subsite::changeSubsite($subsite->ID); $file = new File(); $file->write(); $this->assertEquals($file->SubsiteID, $subsite->ID); // Test inheriting from parent folder $folder = new Folder(); $folder->write(); $this->assertEquals($folder->SubsiteID, $subsite->ID); FileSubsites::$default_root_folders_global = true; $file = new File(); $file->ParentID = $folder->ID; $file->onAfterUpload(); $this->assertEquals($folder->SubsiteID, $file->SubsiteID); }
/** * Completes the job by zipping up the generated export and creating an * export record for it. */ protected function complete() { $siteTitle = SiteConfig::current_site_config()->Title; $filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c'))); $dir = Folder::findOrMake(SiteExportExtension::EXPORTS_DIR); $dirname = ASSETS_PATH . '/' . SiteExportExtension::EXPORTS_DIR; $pathname = "{$dirname}/{$filename}"; SiteExportUtils::zip_directory($this->tempDir, "{$dirname}/{$filename}"); Filesystem::removeFolder($this->tempDir); $file = new File(); $file->ParentID = $dir->ID; $file->Title = $siteTitle . ' ' . date('c'); $file->Filename = $dir->Filename . $filename; $file->write(); $export = new SiteExport(); $export->ParentClass = $this->rootClass; $export->ParentID = $this->rootId; $export->Theme = $this->theme; $export->BaseUrlType = ucfirst($this->baseUrlType); $export->BaseUrl = $this->baseUrl; $export->ArchiveID = $file->ID; $export->write(); if ($this->email) { $email = new Email(); $email->setTo($this->email); $email->setTemplate('SiteExportCompleteEmail'); $email->setSubject(sprintf('Site Export For "%s" Complete', $siteTitle)); $email->populateTemplate(array('SiteTitle' => $siteTitle, 'Link' => $file->getAbsoluteURL())); $email->send(); } }
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']); }
function execute() { $file_or_folder = $this->file_or_folder; if (self::$dummy_mode) { echo "Adding : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); $file_or_folder = str_replace("\\", "/", $file_or_folder); $file_list = array(); //se finisce con lo slash è una directory if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") { //creo la cartella $target_dir = new Dir(DS . $root_dir_path . $file_or_folder); $target_dir->touch(); $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); foreach ($source_dir->listFiles() as $elem) { if ($elem->isDir()) { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS)); } else { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename())); } } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); $target_dir = $target_file->getDirectory(); $target_dir->touch(); $source_file->copy($target_dir); $file_list[] = $target_dir->newFile($source_file->getFilename())->getPath(); } return $file_list; }
function getFile($fID) { Loader::model('file'); $mf = new File(); $file_obj = $mf->getByID($fID); $fileversion_obj = $file_obj->getVersion(); $bf = new LibraryFileBlockController; $ftype = FileTypeList::getType($fileversion_obj->getExtension()); $this->generictype = strtolower($ftype->getGenericTypeText($ftype->getGenericType())); $this->filename = $fileversion_obj->getFileName(); $this->type = $fileversion_obj->getType(); $this->url = $fileversion_obj->getURL(); $this->filepath = $fileversion_obj->getPath(); $this->relpath = $fileversion_obj->getRelativePath(); $this->origfilename = $fileversion_obj->getRelativePath(); $this->filesize = $fileversion_obj->getFullSize(); $len = strlen(REL_DIR_FILES_UPLOADED); $fh = Loader::helper('concrete/file'); $bf->bID = $fileversion_obj->getFileID(); $bf->generictype = $this->generictype; $bf->type = $this->type; $bf->url = $this->url; $bf->filepath = $this->filepath; $bf->relpath = $this->relpath; $bf->filename = substr($this->relpath, $len); // for backwards compatibility this must include the prefixes $bf->filesize = $this->filesize; return $bf; }
public function save() { $file = new File(); $file->setFromValidatedFile($this->getValue('file')); $file->setName(sprintf('admin_%s_%d', $this->getValue('imageName'), time())); return $file->save(); }
/** * Render a single message content element. * * @param RenderMessageContentEvent $event * * @return string */ public function renderContent(RenderMessageContentEvent $event) { global $container; $content = $event->getMessageContent(); if ($content->getType() != 'downloads' || $event->getRenderedContent()) { return; } /** @var EntityAccessor $entityAccessor */ $entityAccessor = $container['doctrine.orm.entityAccessor']; $context = $entityAccessor->getProperties($content); $context['files'] = array(); foreach ($context['downloadSources'] as $index => $downloadSource) { $context['downloadSources'][$index] = $downloadSource = \Compat::resolveFile($downloadSource); $file = new \File($downloadSource, true); if (!$file->exists()) { unset($context['downloadSources'][$index]); continue; } $context['files'][$index] = array('url' => $downloadSource, 'size' => \System::getReadableSize(filesize(TL_ROOT . DIRECTORY_SEPARATOR . $downloadSource)), 'icon' => 'assets/contao/images/' . $file->icon, 'title' => basename($downloadSource)); } if (empty($context['files'])) { return; } $template = new \TwigTemplate('avisota/message/renderer/default/mce_downloads', 'html'); $buffer = $template->parse($context); $event->setRenderedContent($buffer); }
protected function updateFileHeaders(File $file, array $headers) { $status = $file->getRepo()->getBackend()->describe(['src' => $file->getPath(), 'headers' => $headers]); if (!$status->isGood()) { $this->error("Encountered error: " . print_r($status, true)); } }
public function executeImage(sfWebRequest $request) { $member = $this->getRoute()->getMember(); if (!$member) { return sfView::NONE; } $community = Doctrine::getTable('Community')->find($request->getParameter('id')); if (!$community) { return sfView::ERROR; } $isAdmin = Doctrine::getTable('CommunityMember')->isAdmin($member->getId(), $community->getId()); if (!$isAdmin || $community->getImageFileName()) { return sfView::ERROR; } $message = $request->getMailMessage(); if ($images = $message->getImages()) { $image = array_shift($images); $validator = new opValidatorImageFile(); $validFile = $validator->clean($image); $file = new File(); $file->setFromValidatedFile($validFile); $file->setName('c_' . $community->getId() . '_' . $file->getName()); $community->setFile($file); $community->save(); } return sfView::NONE; }
public function testUploadFile() { $album = $this->Album->init(); $tmp_file = "/tmp/111111111.jpg"; # Generate custom image to test upload $im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color); imagejpeg($im, $tmp_file); # Generate path to save file $file_path = $this->Picture->generateFilePath($album['Album']['id'], 'picturetests.jpg'); $file = new File($file_path); # Get resize options $resize_attrs = $this->Picture->getResizeToSize(); # Upload and save $should_return_3 = $this->Picture->uploadFile($file_path, $album['Album']['id'], 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true); # File was saved? $this->assertEqual(3, $should_return_3); # File was uploaded? $this->assertTrue($file->exists()); # Should rise exception try { $this->Picture->uploadFile($file_path, null, 'samplepicture.jpg', $tmp_file, $resize_attrs['width'], $resize_attrs['height'], $resize_attrs['action'], true); } catch (ForbiddenException $e) { $this->assertEqual($e->getMessage(), "The album ID is required"); } }
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; }
public function display() { //parse image uri $preset = $this->uri->segment(2); $fileId = $this->uri->segment(3); $file = new File($fileId); if (!$file->isFileOfUser($this->c_user->id)) { return false; } $imageFile = $file->image->get(); $updated = (string) $file->image->updated; $manipulator = $this->get('core.image.manipulator'); if ($this->input->post()) { $this->cropParamUpdate($file); echo 'images/' . $preset . '/' . $fileId . '/' . $imageFile->updated . '?prev=' . $updated; } else { $path = FCPATH . $file->path . '/' . $file->fullname; $output = $manipulator->getImagePreset($path, $preset, $imageFile, Arr::get($_GET, 'prev', null)); if ($output) { $info = getimagesize($output); header("Content-Disposition: filename={$output};"); header("Content-Type: {$info["mime"]}"); header('Content-Transfer-Encoding: binary'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); readfile($output); } } }
/** * @param GetEditModeButtonsEvent $objEvent */ public function addButton(GetEditModeButtonsEvent $objEvent) { if (!$this->isRightContext($objEvent->getEnvironment())) { return; } // Check the file cache. $strInitFilePath = '/system/config/initconfig.php'; if (file_exists(TL_ROOT . $strInitFilePath)) { $strFile = new \File($strInitFilePath); $arrFileContent = $strFile->getContentAsArray(); foreach ($arrFileContent as $strContent) { if (!preg_match("/(\\/\\*|\\*|\\*\\/|\\/\\/)/", $strContent)) { //system/tmp. if (preg_match("/system\\/tmp/", $strContent)) { // Set data. \Message::addInfo($GLOBALS['TL_LANG']['MSC']['disabled_cache']); } } } } // Update a field with last sync information $objSyncTime = \Database::getInstance()->prepare("SELECT cl.syncFrom_tstamp as syncFrom_tstamp, user.name as syncFrom_user, user.username as syncFrom_alias\n FROM tl_synccto_clients as cl\n INNER JOIN tl_user as user\n ON cl.syncTo_user = user.id\n WHERE cl.id = ?")->limit(1)->execute(\Input::get("id")); if ($objSyncTime->syncFrom_tstamp != 0 && strlen($objSyncTime->syncFrom_user) != 0 && strlen($objSyncTime->syncFrom_alias) != 0) { $strLastSync = vsprintf($GLOBALS['TL_LANG']['MSC']['last_sync'], array(date($GLOBALS['TL_CONFIG']['timeFormat'], $objSyncTime->syncFrom_tstamp), date($GLOBALS['TL_CONFIG']['dateFormat'], $objSyncTime->syncFrom_tstamp), $objSyncTime->syncFrom_user, $objSyncTime->syncFrom_alias)); // Set data \Message::addInfo($strLastSync); } // Set buttons. $objEvent->setButtons(array('start_sync' => '<input type="submit" name="start_sync" id="start_sync" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['sync']) . '" />', 'start_sync_all' => '<input type="submit" name="start_sync_all" id="start_sync_all" class="tl_submit" accesskey="o" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['syncAll']) . '" />')); }
public function createDatabaseFile($data) { App::uses('File', 'Utility'); App::uses('ConnectionManager', 'Model'); $config = $this->defaultConfig; foreach ($data['Install'] as $key => $value) { if (isset($data['Install'][$key])) { $config[$key] = $value; } } $result = copy(APP . 'Config' . DS . 'database.php.install', APP . 'Config' . DS . 'database.php'); if (!$result) { return __d('croogo', 'Could not copy database.php file.'); } $file = new File(APP . 'Config' . DS . 'database.php', true); $content = $file->read(); foreach ($config as $configKey => $configValue) { $content = str_replace('{default_' . $configKey . '}', $configValue, $content); } if (!$file->write($content)) { return __d('croogo', 'Could not write database.php file.'); } try { ConnectionManager::create('default', $config); $db = ConnectionManager::getDataSource('default'); } catch (MissingConnectionException $e) { return __d('croogo', 'Could not connect to database: ') . $e->getMessage(); } if (!$db->isConnected()) { return __d('croogo', 'Could not connect to database.'); } return true; }
public function generar($etapa_id) { $etapa = Doctrine::getTable('Etapa')->find($etapa_id); $filename_uniqid = uniqid(); //Generamos el file $file = new File(); $file->tramite_id = $etapa->tramite_id; $file->tipo = 'documento'; $file->llave = strtolower(random_string('alnum', 12)); $file->llave_copia = $this->tipo == 'certificado' ? strtolower(random_string('alnum', 12)) : null; $file->llave_firma = strtolower(random_string('alnum', 12)); if($this->tipo=='certificado'){ $file->validez = $this->validez; $file->validez_habiles= $this->validez_habiles; } $file->filename = $filename_uniqid . '.pdf'; $file->save(); //Renderizamos $this->render($file->id, $file->llave_copia, $etapa->id, $file->filename, false); $filename_copia = $filename_uniqid . '.copia.pdf'; $this->render($file->id, $file->llave_copia, $etapa->id,$filename_copia, true); return $file; }
/** * Writes given message to a log file in the logs directory. * * @param string $type Type of log, becomes part of the log's filename * @param string $msg Message to log * @return boolean Success */ function write($type, $msg) { $filename = LOGS . $type . '.log'; $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n"; $log = new File($filename); return $log->append($output); }
public function actionCreates() { $model = new News(); $file = new File(); $model->member_id = Yii::app()->user->id; $model->create_at = date('Y-m-d H:i:s'); $model->update_at = date('Y-m-d H:i:s'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['News']) && isset($_POST['File'])) { $model->attributes = $_POST['News']; $file->attributes = $_POST['File']; $model->pic = 'noimage.jpg'; $model->validate(); $file->validate(); if ($model->getErrors() == null && $file->getErrors() == null) { $file->file = CUploadedFile::getInstance($file, 'file'); if ($file->file != null) { $filename = time() . '.' . $file->file->getExtensionName(); $file->file->saveAs(Yii::app()->params['pathUpload'] . $filename); $model->pic = $filename; } else { $model->pic = 'noimage.jpg'; } if ($model->save()) { $this->redirect(array('view', 'id' => $model->news_id)); } } } $this->render('create', array('model' => $model, 'file' => $file)); }