Esempio n. 1
6
 /**
  * Compiles a template and writes it to a cache file, which is used for inclusion.
  *
  * @param string $file The full path to the template that will be compiled.
  * @param array $options Options for compilation include:
  *        - `path`: Path where the compiled template should be written.
  *        - `fallback`: Boolean indicating that if the compilation failed for some
  *                      reason (e.g. `path` is not writable), that the compiled template
  *                      should still be returned and no exception be thrown.
  * @return string The compiled template.
  */
 public static function template($file, array $options = array())
 {
     $cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
     $defaults = array('path' => $cachePath, 'fallback' => false);
     $options += $defaults;
     $stats = stat($file);
     $oname = basename(dirname($file)) . '_' . basename($file, '.php');
     $oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
     $template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
     $template = "{$options['path']}/{$template}";
     if (file_exists($template)) {
         return $template;
     }
     $compiled = static::compile(file_get_contents($file));
     if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
         foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
             if ($expired !== $template) {
                 unlink($expired);
             }
         }
         return $template;
     }
     if ($options['fallback']) {
         return $file;
     }
     throw new TemplateException("Could not write compiled template `{$template}` to cache.");
 }
Esempio n. 2
4
 function command_dd()
 {
     $args = func_get_args();
     $options = $this->get_options();
     $dd = kernel::single('dev_docbuilder_dd');
     if (empty($args)) {
         $dd->export();
     } else {
         foreach ($args as $app_id) {
             $dd->export_tables($app_id);
         }
     }
     if ($filename = $options['result-file']) {
         ob_start();
         $dd->output();
         $out = ob_get_contents();
         ob_end_clean();
         if (!is_dir(dirname($filename))) {
             throw new Exception('cannot find the ' . dirname($filename) . 'directory');
         } elseif (is_dir($filename)) {
             throw new Exception('the result-file path is a directory.');
         }
         file_put_contents($options['result-file'], $out);
         echo 'data dictionary doc export success.';
     } else {
         $dd->output();
     }
 }
Esempio n. 3
2
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if (is_null($this->dst) || "" === $this->dst) {
         return Result::error($this, 'You must specify a destination file with to() method.');
     }
     if (!$this->checkResources($this->files, 'file')) {
         return Result::error($this, 'Source files are missing!');
     }
     if (file_exists($this->dst) && !is_writable($this->dst)) {
         return Result::error($this, 'Destination already exists and cannot be overwritten.');
     }
     $dump = '';
     foreach ($this->files as $path) {
         foreach (glob($path) as $file) {
             $dump .= file_get_contents($file) . "\n";
         }
     }
     $this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
     $dst = $this->dst . '.part';
     $write_result = file_put_contents($dst, $dump);
     if (false === $write_result) {
         @unlink($dst);
         return Result::error($this, 'File write failed.');
     }
     // Cannot be cross-volume; should always succeed.
     @rename($dst, $this->dst);
     return Result::success($this);
 }
Esempio n. 4
1
 /**
  * Writes a default configuration file to $path if there is none
  * @param string $path
  * @param string $type
  */
 public static function ensureConfigFile($path, $type)
 {
     if (!is_file($path)) {
         $content = self::getExampleConfiguration($type);
         file_put_contents($path, $content);
     }
 }
Esempio n. 5
1
 function handleSave($value, $oldValue)
 {
     global $prefs, $user;
     $tikilib = TikiLib::lib('tiki');
     $trackerId = $this->getConfiguration('trackerId');
     $file_name = $this->getConfiguration('file_name');
     $file_size = $this->getConfiguration('file_size');
     $file_type = $this->getConfiguration('file_type');
     $perms = Perms::get('tracker', $trackerId);
     if ($perms->attach_trackers && $file_name) {
         if ($prefs['t_use_db'] == 'n') {
             $fhash = md5($file_name . $tikilib->now);
             if (file_put_contents($prefs['t_use_dir'] . $fhash, $value) === false) {
                 $smarty = TikiLib::lib('smarty');
                 $smarty->assign('msg', tra('Cannot write to this file:') . $fhash);
                 $smarty->display("error.tpl");
                 die;
             }
             $value = '';
         } else {
             $fhash = 0;
         }
         $trklib = TikiLib::lib('trk');
         $value = $trklib->replace_item_attachment($oldValue, $file_name, $file_type, $file_size, $value, '', $user, $fhash, '', '', $trackerId, $this->getItemId(), '', false);
     }
     return array('value' => $value);
 }
Esempio n. 6
0
 function deactivate()
 {
     file_put_contents($this->config["incron"]["path"] . "/bittorrent.stop", "1");
     do {
         sleep(1);
     } while ($this->isActive());
 }
 /**
  * Execute this task
  *
  * @param \TYPO3\Surf\Domain\Model\Node $node
  * @param \TYPO3\Surf\Domain\Model\Application $application
  * @param \TYPO3\Surf\Domain\Model\Deployment $deployment
  * @param array $options Supported options: "scriptBasePath" and "scriptIdentifier"
  * @return void
  * @throws \TYPO3\Surf\Exception\InvalidConfigurationException
  * @throws \TYPO3\Surf\Exception\TaskExecutionException
  */
 public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
 {
     $workspacePath = $deployment->getWorkspacePath($application);
     $scriptBasePath = isset($options['scriptBasePath']) ? $options['scriptBasePath'] : Files::concatenatePaths(array($workspacePath, 'Web'));
     if (!isset($options['scriptIdentifier'])) {
         // Generate random identifier
         $factory = new \RandomLib\Factory();
         $generator = $factory->getMediumStrengthGenerator();
         $scriptIdentifier = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM);
         // Store the script identifier as an application option
         $application->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask[scriptIdentifier]', $scriptIdentifier);
     } else {
         $scriptIdentifier = $options['scriptIdentifier'];
     }
     $localhost = new Node('localhost');
     $localhost->setHostname('localhost');
     $commands = array('cd ' . escapeshellarg($scriptBasePath), 'rm -f surf-opcache-reset-*');
     $this->shell->executeOrSimulate($commands, $localhost, $deployment);
     if (!$deployment->isDryRun()) {
         $scriptFilename = $scriptBasePath . '/surf-opcache-reset-' . $scriptIdentifier . '.php';
         $result = file_put_contents($scriptFilename, '<?php
             if (function_exists("opcache_reset")) {
                 opcache_reset();
             }
             @unlink(__FILE__);
             echo "success";
         ');
         if ($result === false) {
             throw new \TYPO3\Surf\Exception\TaskExecutionException('Could not write file "' . $scriptFilename . '"', 1421932414);
         }
     }
 }
Esempio n. 8
0
 /**
  * Sets data
  *
  * @param string $key
  * @param string $var
  * @param int $expire
  * @return boolean
  */
 function set($key, $var, $expire = 0)
 {
     $key = $this->get_item_key($key);
     $sub_path = $this->_get_path($key);
     $path = $this->_cache_dir . '/' . $sub_path;
     $sub_dir = dirname($sub_path);
     $dir = dirname($path);
     if (!@is_dir($dir)) {
         if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) {
             return false;
         }
     }
     $fp = @fopen($path, 'w');
     if (!$fp) {
         return false;
     }
     if ($this->_locking) {
         @flock($fp, LOCK_EX);
     }
     @fputs($fp, $var['content']);
     @fclose($fp);
     if ($this->_locking) {
         @flock($fp, LOCK_UN);
     }
     // some hostings create files with restrictive permissions
     // not allowing apache to read it later
     @chmod($path, 0644);
     $old_entry_path = $path . '.old';
     @unlink($old_entry_path);
     if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') {
         file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . "    RemoveType .html_gzip\n" . "    AddType text/xml .html_gzip\n" . "    RemoveType .html\n" . "    AddType text/xml .html\n" . "</IfModule>");
     }
     return true;
 }
Esempio n. 9
0
 /**
  * 将信息写入XML文件中
  * @param string $filename
  * @param array $xml
  * @param string $root 是否给信息添加根节点
  * @return boolean
  * @static 
  */
 function saveToFile($filename, $xml, $root = '')
 {
     $root && ($xml = array($root => $xml));
     $xmlString = ArrayXml::serializeXml($xml);
     file_put_contents($filename, $xmlString);
     return $result;
 }
Esempio n. 10
0
 /**
  * Defined by Zend_Config_Writer
  *
  * @param  string      $filename
  * @param  Zend_Config $config
  * @throws Zend_Config_Exception When filename was not set
  * @throws Zend_Config_Exception When filename is not writable
  * @return void
  */
 public function write($filename = null, Zend_Config $config = null)
 {
     if ($filename !== null) {
         $this->setFilename($filename);
     }
     if ($config !== null) {
         $this->setConfig($config);
     }
     if ($this->_filename === null) {
         require_once 'Zend/Config/Exception.php';
         throw new Zend_Config_Exception('No filename was set');
     }
     if ($this->_config === null) {
         require_once 'Zend/Config/Exception.php';
         throw new Zend_Config_Exception('No config was set');
     }
     $data = $this->_config->toArray();
     $sectionName = $this->_config->getSectionName();
     if (is_string($sectionName)) {
         $data = array($sectionName => $data);
     }
     $arrayString = "<?php\n" . "return " . var_export($data, true) . ";\n";
     $result = @file_put_contents($this->_filename, $arrayString);
     if ($result === false) {
         require_once 'Zend/Config/Exception.php';
         throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
     }
 }
Esempio n. 11
0
 public function driverSet(string $keyword, $value, int $time = 0, bool $not_exist = false) : bool
 {
     $file_path = $this->getFilePath($keyword);
     $temp_path = $file_path . ".tmp";
     $now = time();
     $expiring_time = $time ? $now + $time : 0;
     $object = ['value' => $value, 'expiring_time' => $expiring_time];
     $data = $this->encode($object);
     $to_write = true;
     if ($not_exist && @file_exists($file_path)) {
         $content = file_get_contents($file_path);
         $old = $this->decode($content);
         $to_write = false;
         if ($this->isExpired($old)) {
             $to_write = true;
         }
     }
     $written = false;
     if ($to_write) {
         try {
             $written = @file_put_contents($temp_path, $data, LOCK_EX | LOCK_NB) && @rename($temp_path, $file_path);
         } catch (\Exception $e) {
             $written = false;
         }
     }
     return $written;
 }
Esempio n. 12
0
function stat_write_static_cache($cache_file_path, $config_arr)
{
    $content = "<?php\r\n";
    $content .= "\$data = " . var_export($config_arr, true) . ";\r\n";
    $content .= "?>";
    file_put_contents($cache_file_path, $content, LOCK_EX);
}
Esempio n. 13
0
function query_sbrs_ip_16($ip, $folder)
{
    $end_mark = "No address list shown since no email was detected";
    $re_range = '/Showing (\\d+) - (\\d+) out of (\\d+)/';
    //Showing 1 - 50 out of 83
    $path = '';
    $row = 50;
    $start = 0;
    $total = 0;
    //$ip = "9.17.1.1"; //@
    $path = "{$folder}/{$ip}_{$start}_{$total}.htm";
    $query = build_sbrs_query($ip, $start, $row);
    $page = query_page2($query);
    if (preg_match($re_range, $page, $matches) > 0) {
        $total = $matches[3];
    }
    echo "total: {$total}\n";
    $path = "{$folder}/{$ip}_{$start}_{$total}.htm";
    echo "path={$path}\n";
    file_put_contents($path, $page);
    $start += $row;
    while ($start <= $total) {
        //sleep(1);
        $path = "{$folder}/{$ip}_{$start}_{$total}.htm";
        $query = build_sbrs_query($ip, $start, $row);
        $page = query_page2($query);
        echo "path={$path}\n";
        file_put_contents($path, $page);
        $start += $row;
    }
    //sleep(1);
    if ($page != '') {
        return 'OK';
    }
}
Esempio n. 14
0
 public function postCheckdb()
 {
     if (!Session::get('step2')) {
         return Redirect::to('install/step2');
     }
     $dbhost = Input::get('dbhost');
     $dbuser = Input::get('dbuser');
     $dbpass = Input::get('dbpass');
     $dbname = Input::get('dbname');
     Session::put(array('dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbname' => $dbname));
     try {
         $dbh = new pdo("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
         $sql = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/dump.sql');
         $result = $dbh->exec($sql);
         $databaseFile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/database.php');
         $databaseFile = str_replace(array('{DBHOST}', '{DBNAME}', '{DBUSER}', '{DBPASS}'), array($dbhost, $dbname, $dbuser, $dbpass), $databaseFile);
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/database.php', $databaseFile);
         file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/database.php', $databaseFile);
         Session::put('step3', true);
         return Illuminate\Support\Facades\Redirect::to('install/step4');
     } catch (PDOException $ex) {
         Session::put('step3', false);
         return Illuminate\Support\Facades\Redirect::to('install/step3')->with('conerror', 'Date invalide');
     }
 }
 public function testLifetime()
 {
     $cache = $this->_getCacheDriver();
     // Test save
     $cache->save('test_key', 'testing this out', 10);
     // Test contains to test that save() worked
     $this->assertTrue($cache->contains('test_key'));
     // Test fetch
     $this->assertEquals('testing this out', $cache->fetch('test_key'));
     // access private methods
     $getFilename = new \ReflectionMethod($cache, 'getFilename');
     $getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
     $getFilename->setAccessible(true);
     $getNamespacedId->setAccessible(true);
     $id = $getNamespacedId->invoke($cache, 'test_key');
     $filename = $getFilename->invoke($cache, $id);
     $data = '';
     $lifetime = 0;
     $resource = fopen($filename, "r");
     if (false !== ($line = fgets($resource))) {
         $lifetime = (int) $line;
     }
     while (false !== ($line = fgets($resource))) {
         $data .= $line;
     }
     $this->assertNotEquals(0, $lifetime, 'previous lifetime could not be loaded');
     // update lifetime
     $lifetime = $lifetime - 20;
     file_put_contents($filename, $lifetime . PHP_EOL . $data);
     // test expired data
     $this->assertFalse($cache->contains('test_key'));
     $this->assertFalse($cache->fetch('test_key'));
 }
Esempio n. 16
0
 public function wait()
 {
     $data['current'] = array('data_back' => '', 'user_manage' => '', 'user_data' => '', 'teacher_data' => '', 'add_teacher' => '', 'classify_manage' => '', 'all_classify' => '', 'course_manage' => 'current', 'required_course' => 'current', 'elective_course' => '', 'skill_course' => '', 'video_manage' => '', 'all_video' => '', 'upload_video' => '', 'order_manage' => '', 'all_order' => '', 'account_data' => '', 'feedback_manage' => '', 'all_feedback' => '', 'comment_manage' => '', 'all_comment' => '', 'link_manage' => '', 'all_link' => '', 'add_link' => '', 'activity_manage' => '', 'add_activity' => '', 'all_activity' => '');
     $page_config['perpage'] = 9;
     //每页条数
     $page_config['part'] = 2;
     //当前页前后链接数量
     $page_config['url'] = '/admin/required/check';
     //url
     $page_config['seg'] = 4;
     //参数取 index.php之后的段数,默认为3,即index.php/control/function/18 这种形式
     $page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']) : 1;
     //当前页
     $this->load->library('mypage_class');
     $page_config['total'] = count($this->required_model->query_by_check());
     // file_put_contents("/home/tanxu/www/data.txt", $page_config['total']);
     $this->mypage_class->initialize($page_config);
     if ((int) $page_config['nowindex'] == 1) {
         $data['check'] = $this->required_model->get_num_course(0, (int) $page_config['perpage'], 0);
         file_put_contents("/home/tanxu/www/data.txt", print_r($data['check'], true));
     } else {
         $firstcount = ((int) $page_config['nowindex'] - 1) * (int) $page_config['perpage'];
         $data['check'] = $this->required_model->get_num_course(0, (int) $page_config['perpage'], $firstcount);
     }
     $this->load->view('admin/admin_header.html', $data);
     $this->load->view('admin/admin_required_check.html');
 }
Esempio n. 17
0
 public function log($text)
 {
     $text = '  ' . $text . "\n" . $this->lastString;
     $log = file_get_contents($this->logFile);
     $log = str_replace($this->lastString, $text, $log);
     file_put_contents($this->logFile, $log);
 }
Esempio n. 18
0
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     if (count($arguments['name'])) {
         $files = array();
         foreach ($arguments['name'] as $name) {
             $finder = sfFinder::type('file')->follow_link()->name(basename($name) . 'Test.php');
             $files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir') . '/unit/' . dirname($name)));
         }
         if ($allFiles = $this->filterTestFiles($files, $arguments, $options)) {
             foreach ($allFiles as $file) {
                 include $file;
             }
         } else {
             $this->logSection('test', 'no tests found', null, 'ERROR');
         }
     } else {
         require_once __DIR__ . '/sfLimeHarness.class.php';
         $h = new sfLimeHarness(array('force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'], 'test_path' => sfConfig::get('sf_cache_dir') . '/lime'));
         $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins()));
         $h->base_dir = sfConfig::get('sf_test_dir') . '/unit';
         // filter and register unit tests
         $finder = sfFinder::type('file')->follow_link()->name('*Test.php');
         $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options));
         $ret = $h->run() ? 0 : 1;
         if ($options['xml']) {
             file_put_contents($options['xml'], $h->to_xml());
         }
         return $ret;
     }
 }
 /**
  * @param  EntityMapping $modelMapping
  * @param  string        $namespace
  * @param  string        $path
  * @param  bool          $override
  * @return void
  */
 public function generate(EntityMapping $modelMapping, $namespace, $path, $override = false)
 {
     $abstractNamespace = $namespace . '\\Base';
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $abstractPath = $path . DIRECTORY_SEPARATOR . 'Base';
     if (!is_dir($abstractPath)) {
         mkdir($abstractPath, 0777, true);
     }
     $abstracClassName = 'Abstract' . $modelMapping->getName();
     $classPath = $path . DIRECTORY_SEPARATOR . $modelMapping->getName() . '.php';
     $abstractClassPath = $abstractPath . DIRECTORY_SEPARATOR . $abstracClassName . '.php';
     $nodes = array();
     $nodes = array_merge($nodes, $this->generatePropertyNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateConstructNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateMethodNodes($modelMapping));
     $nodes = array_merge($nodes, $this->generateMetadataNodes($modelMapping));
     $nodes = array(new Node\Stmt\Namespace_(new Name($abstractNamespace), array(new Class_('Abstract' . $modelMapping->getName(), array('type' => 16, 'stmts' => $nodes)))));
     $abstractClassCode = $this->phpGenerator->prettyPrint($nodes);
     file_put_contents($abstractClassPath, '<?php' . PHP_EOL . PHP_EOL . $abstractClassCode);
     if (file_exists($classPath) && !$override) {
         return;
     }
     $nodes = array(new Node\Stmt\Namespace_(new Name($namespace), array(new Class_($modelMapping->getName(), array('extends' => new FullyQualified($abstractNamespace . '\\' . $abstracClassName))))));
     $classCode = $this->phpGenerator->prettyPrint($nodes);
     file_put_contents($classPath, '<?php' . PHP_EOL . PHP_EOL . $classCode);
 }
Esempio n. 20
0
function run_propel_build_sql_diff($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the application.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception(sprintf('The app "%s" does not exist.', $app));
    }
    run_propel_build_sql($task, $args);
    pake_echo_action('propel-sql-diff', "building database patch");
    define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../../..'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', isset($args[1]) ? $args[1] : 'dev');
    define('SF_DEBUG', 1);
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    $i = new dbInfo();
    $i->loadFromDb();
    $i2 = new dbInfo();
    $i2->loadAllFilesInDir(sfConfig::get('sf_data_dir') . '/sql');
    $diff = $i->getDiffWith($i2);
    $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
    if ($diff == '') {
        pake_echo_comment("no difference found");
    }
    pake_echo_action('propel-sql-diff', "writing file {$filename}");
    file_put_contents($filename, $diff);
}
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $tools = $em->getRepository('KoalamonIncidentDashboardBundle:Tool')->findAll();
     /** @var Tool $tool */
     foreach ($tools as $tool) {
         $fixture = $tool->jsonSerialize();
         file_put_contents($this->fixturePath . '/tool_' . $tool->getId() . '.json', json_encode($fixture, JSON_PRETTY_PRINT));
     }
     $systems = $em->getRepository('KoalamonIncidentDashboardBundle:System')->findAll();
     /** @var System $system */
     foreach ($systems as $system) {
         $fixture = $system->jsonSerialize();
         file_put_contents($this->fixturePath . '/system_' . $system->getId() . '.json', json_encode($fixture, JSON_PRETTY_PRINT));
     }
     $projects = $em->getRepository('KoalamonIncidentDashboardBundle:Project')->findAll();
     /** @var Project $project */
     foreach ($projects as $project) {
         $fixture = $project->jsonSerialize();
         file_put_contents($this->fixturePath . '/project_' . $project->getId() . '.json', json_encode($fixture, JSON_PRETTY_PRINT));
     }
     $users = $em->getRepository('KoalamonIncidentDashboardBundle:User')->findAll();
     /** @var User $user */
     foreach ($users as $user) {
         $fixture = $user->jsonSerialize();
         $fixture->password = '******';
         file_put_contents($this->fixturePath . '/user_' . $user->getId() . '.json', json_encode($fixture, JSON_PRETTY_PRINT));
     }
 }
    /**
     * Get the Platform object for this class
     *
     * @return Platform
     */
    protected function getPlatform()
    {
        if (!$this->platform) {
            $this->platform = new MysqlPlatform();
            $configFileContent = <<<EOF
propel:
  database:
    connections:
      bookstore:
        adapter: mysql
        classname: \\Propel\\Runtime\\Connection\\DebugPDO
        dsn: mysql:host=127.0.0.1;dbname=test
        user: root
        password:
    adapters:
      mysql:
        tableType: InnoDB

  generator:
    defaultConnection: bookstore
    connections:
      - bookstore

  runtime:
    defaultConnection: bookstore
    connections:
      - bookstore
EOF;
            $configFile = sys_get_temp_dir() . '/propel.yaml';
            file_put_contents($configFile, $configFileContent);
            $config = new GeneratorConfig($configFile);
            $this->platform->setGeneratorConfig($config);
        }
        return $this->platform;
    }
function batch_find_images()
{
    $log = elgg_get_config('mfp_log');
    $logtime = elgg_get_config('mfp_logtime');
    // only search
    $options = array('type' => 'object', 'subtype' => 'image', 'limit' => 0);
    $images = new ElggBatch('elgg_get_entities', $options);
    $count = 0;
    $bad_images = 0;
    $total = elgg_get_entities(array_merge($options, array('count' => true)));
    file_put_contents($log, "Starting scan of {$total} images" . "\n", FILE_APPEND);
    foreach ($images as $image) {
        $count++;
        // don't use ->exists() because of #5207.
        if (!is_file($image->getFilenameOnFilestore())) {
            $bad_images++;
            $image->mfp_delete_check = $logtime;
        }
        if ($count == 1 || !($count % 25)) {
            $time = date('Y-m-d g:ia');
            $message = "Checked {$count} of {$total} images as of {$time}";
            file_put_contents($log, $message . "\n", FILE_APPEND);
        }
    }
    $message = '<div class="done"><a href="#" id="elgg-tidypics-broken-images-delete" data-time="' . $logtime . '">Delete ' . $bad_images . ' broken images</a></div>';
    file_put_contents($log, $message . "\n", FILE_APPEND);
}
Esempio n. 24
0
 public static function saveConfig()
 {
     $r = file_put_contents(self::$confPath, json_encode(self::$data));
     if ($r === false) {
         throw new Exception('Failed to save config');
     }
 }
Esempio n. 25
0
 public static function create($isoLang = 'pt_BR')
 {
     $xmlDoc = new DOMDocument('1.0', 'utf-8');
     $xmlDoc->formatOutput = true;
     $culture = $xmlDoc->createElement($isoLang);
     $culture = $xmlDoc->appendChild($culture);
     $criteria = new Criteria();
     $criteria->add(TagI18n::TABLE . '.' . TagI18n::ISOLANG, $isoLang);
     $objTagI18n = new TagI18nPeer();
     $arrayObjTagI18n = $objTagI18n->doSelect($criteria);
     if (!is_object($arrayObjTagI18n) && count($arrayObjTagI18n == 0)) {
         $log = new Log();
         $log->setLog(__FILE__, 'There are no tags with that language ' . $isoLang, true);
         throw new Exception('There are no tags with that language ' . $isoLang);
     }
     foreach ($arrayObjTagI18n as $objTagI18nPeer) {
         $item = $xmlDoc->createElement('item');
         $item->setAttribute('idTagI18n', $objTagI18nPeer->getIdTagI18n());
         $item = $culture->appendChild($item);
         $title = $xmlDoc->createElement('tag', utf8_encode($objTagI18nPeer->getTag()));
         $title = $item->appendChild($title);
         $link = $xmlDoc->createElement('i18n', utf8_encode($objTagI18nPeer->getTranslate()));
         $link = $item->appendChild($link);
     }
     //header("Content-type:application/xml; charset=utf-8");
     $file = PATH . PATH_I18N . $isoLang . '.xml';
     try {
         file_put_contents($file, $xmlDoc->saveXML());
     } catch (Exception $e) {
         $log = new Log();
         $log->setLog(__FILE__, 'Unable to write the XML file I18n ' . $e->getMessage(), true);
     }
     return true;
 }
Esempio n. 26
0
 /**
  * 首页
  */
 public function index()
 {
     $file = FCPATH . 'cache/index/home-' . ($this->template->mobile ? 'mb-' : '') . SITE_ID . '.html';
     // 系统开启静态首页、静态文件不存在时,才生成文件
     //zjp添加,动态显示日期天气温度
     if ($_SESSION["de_json"] == '') {
         $city = "宜春";
         $content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=宜春&output=json&ak=i8GFDZTM22uqICZbtioaVbnk");
         $de_json = json_decode($content, TRUE);
         $_SESSION["de_json"] = $de_json;
     }
     /*zjp 0819 添加调取最新的调查问卷start*/
     //echo APP_DIR;
     //echo 1;
     //$this->load->model('category_model');
     //$question_id = $this->category_model->get_question_id();
     /*zjp 0819 添加调取最新的调查问卷end  */
     if (SITE_HOME_INDEX && !is_file($file)) {
         ob_start();
         $this->template->assign(array('indexc' => 1, 'meta_title' => SITE_TITLE, 'meta_keywords' => SITE_KEYWORDS, 'meta_description' => SITE_DESCRIPTION, 'de_json' => $_SESSION["de_json"]));
         $this->template->display('index.html');
         $html = ob_get_clean();
         @file_put_contents($file, $html, LOCK_EX);
         echo $html;
         exit;
     } else {
         $this->template->assign(array('indexc' => 1, 'meta_title' => SITE_TITLE, 'meta_keywords' => SITE_KEYWORDS, 'meta_description' => SITE_DESCRIPTION, 'de_json' => $de_json));
         $this->template->display('index.html');
     }
 }
Esempio n. 27
0
function ParseAllcontacts()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if ($unix->file_time_min($pidtime) < 120) {
        return;
    }
    @file_put_contents($pidtime, time());
    $ldap = new clladp();
    $suffix = $ldap->suffix;
    $arr = array("uid");
    $sr = @ldap_search($ldap->ldap_connection, "dc=organizations,{$suffix}", '(objectclass=userAccount)', $arr);
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            ParseContacts($hash[$i]["uid"][0]);
            if (system_is_overloaded(dirname(__FILE__))) {
                $unix->send_email_events(basename(__FILE__) . " Overloaded aborting task", "Zarafa contacts importation has been canceled due to overloaded system", "mailbox");
                return;
            }
            sleep(1);
        }
    }
}
Esempio n. 28
0
 public function prepare($statement, $driver_options = array())
 {
     if (isset($this->dsn) and stristr($this->dsn, 'anjuke_db') and preg_match('/\\sajk_propertys\\s/i', $statement)) {
         if (stristr($statement, 'select CITYID') or stristr($statement, 'insert') or stristr($statement, 'update ')) {
         } else {
             $dir = '/home/www/logs/propsql';
             if (!is_dir($dir)) {
                 mkdir($dir, 0755, true);
             }
             $content = '-=-=-=-=-=-=-=-=-=-=' . PHP_EOL;
             $content .= 'DSN: ' . $this->dsn . PHP_EOL;
             $content .= 'URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;
             $content .= 'JOB: ' . var_export($_SERVER['argv'], true) . PHP_EOL;
             $content .= 'SQL: ' . $statement . PHP_EOL;
             file_put_contents($dir . '/' . date('Ymd'), $content, FILE_APPEND);
         }
     }
     //add by jackie for record SQL
     APF::get_instance()->pf_benchmark("sql", array($this->i => $statement));
     $stmt = parent::prepare($statement, $driver_options);
     if ($stmt instanceof PDOStatement) {
         $stmt->setFetchMode($this->default_fetch_mode);
     }
     //add by hexin for record SQL execute time
     $stmt->set_i($this->i);
     $this->i++;
     $stmt->_sql = $statement;
     return $stmt;
 }
Esempio n. 29
0
function doAction($action)
{
    $id = $_POST['id'];
    $mapFile = "map/" . $id . ".map";
    $offlineFile = "map/offline/" . $id . ".js";
    switch ($action) {
        case "save":
            if (!is_dir("map")) {
                mkdir("map");
                mkdir("map/offline");
            }
            file_put_contents($mapFile, $_POST['data']);
            file_put_contents($offlineFile, "Map.level[" . $id . "]  = " . $_POST['data']);
            return $_POST['data'];
            break;
        case "load":
            if (!empty($_POST['offlineMode'])) {
                return file_get_contents($offlineFile);
            }
            if (file_exists($mapFile)) {
                return file_get_contents($mapFile);
            }
            echo "Echo file not found: " . $mapFile;
            ThrowNotFound();
            break;
    }
}
Esempio n. 30
0
 function downloadPackage($src, $dst)
 {
     if (ini_get('allow_url_fopen')) {
         $file = @file_get_contents($src);
     } else {
         if (function_exists('curl_init')) {
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $src);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 180);
             $safeMode = @ini_get('safe_mode');
             $openBasedir = @ini_get('open_basedir');
             if (empty($safeMode) && empty($openBasedir)) {
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             }
             $file = curl_exec($ch);
             curl_close($ch);
         } else {
             return false;
         }
     }
     file_put_contents($dst, $file);
     return file_exists($dst);
 }