Exemplo n.º 1
0
 public function add($args)
 {
     $dataForDb = array();
     // This data will be saved in the database
     $dataForFile = array();
     // This data will be saved in the file
     $key = $this->generateKey($args['slug'], $args['parent']);
     // The user is always the one loggued.
     $args['username'] = Session::get('username');
     if (Text::isEmpty($args['username'])) {
         return false;
     }
     // Current date.
     $args['date'] = Date::current(DB_DATE_FORMAT);
     // Verify arguments with the database fields.
     foreach ($this->dbFields as $field => $options) {
         if (isset($args[$field])) {
             if ($field == 'tags') {
                 $tmpValue = $this->generateTags($args['tags']);
             } else {
                 // Sanitize if will be saved on database.
                 if (!$options['inFile']) {
                     $tmpValue = Sanitize::html($args[$field]);
                 } else {
                     $tmpValue = $args[$field];
                 }
             }
         } else {
             $tmpValue = $options['value'];
         }
         // Check where the field will be written, in file or database.
         if ($options['inFile']) {
             $dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
         } else {
             // Set type
             settype($tmpValue, gettype($options['value']));
             // Save on database
             $dataForDb[$field] = $tmpValue;
         }
     }
     // Make the directory. Recursive.
     if (Filesystem::mkdir(PATH_PAGES . $key, true) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_PAGES . $key);
         return false;
     }
     // Make the index.txt and save the file.
     $data = implode("\n", $dataForFile);
     if (file_put_contents(PATH_PAGES . $key . '/index.txt', $data) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
         return false;
     }
     // Save the database
     $this->db[$key] = $dataForDb;
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 private function moveDefaultTemplate()
 {
     $this->log('Moving default template...');
     $fileDir = $this->container->getParameter('claroline.param.files_directory');
     $defaultTemplate = $this->container->getParameter('claroline.param.default_template');
     $newTemplateDir = $fileDir . '/templates';
     $newTemplate = $newTemplateDir . '/default.zip';
     $fs = new Filesystem();
     $fs->mkdir($newTemplateDir);
     $fs->copy($defaultTemplate, $newTemplate);
 }
Exemplo n.º 3
0
 /**
  * Instantiates the class.
  *
  * @param string $bundle_id The bundle ID to give to the workflow.
  */
 public function __construct($bundle_id)
 {
     $fs = new Filesystem();
     $this->path = Util::run('pwd');
     $this->home = Util::run('printf $HOME');
     if (file_exists('info.plist')) {
         $plist = new Plist($bundle_id, 'info');
         $this->bundle = $plist->getValue('bundleid');
     }
     if (!is_null($bundle_id)) {
         $this->bundle = $bundle_id;
     }
     $this->cache = $this->home . self::CACHE_PATH . '/' . $this->bundle;
     $this->data = $this->home . self::DATA_PATH . '/' . $this->bundle;
     if (!file_exists($this->cache)) {
         $fs->mkdir($this->cache);
     }
     if (!file_exists($this->data)) {
         $fs->mkdir($this->data);
     }
 }
Exemplo n.º 4
0
 /**
  * Checks if directories are writable and create them if they do not exist.
  *
  * @param array $directoriesToCheck array of directories to check - if not given default Piwik directories that needs write permission are checked
  * @return array  directory name => true|false (is writable)
  */
 public static function checkDirectoriesWritable($directoriesToCheck)
 {
     $resultCheck = array();
     foreach ($directoriesToCheck as $directoryToCheck) {
         if (!preg_match('/^' . preg_quote(PIWIK_USER_PATH, '/') . '/', $directoryToCheck)) {
             $directoryToCheck = PIWIK_USER_PATH . $directoryToCheck;
         }
         $directoryToCheck = SettingsPiwik::rewriteTmpPathWithHostname($directoryToCheck);
         Filesystem::mkdir($directoryToCheck);
         $directory = Filesystem::realpath($directoryToCheck);
         $resultCheck[$directory] = false;
         if ($directory !== false && is_writable($directoryToCheck)) {
             $resultCheck[$directory] = true;
         }
     }
     return $resultCheck;
 }
 public function beforeScenario($event)
 {
     parent::beforeScenario($event);
     // @todo provide our own mail system to ameliorate ensuing ugliness.
     if ($event instanceof ScenarioEvent) {
         if ($event->getScenario()->hasTag('mail')) {
             if (module_exists('devel')) {
                 variable_set('mail_system', array('default-system' => 'DevelMailLog'));
             } else {
                 throw new \Exception('You must ensure that the devel module is enabled');
             }
             $fs = new \Filesystem();
             if ($mail_path = $event->getScenario()->getTitle()) {
                 $fs->remove('/tmp/' . $mail_path);
                 $fs->mkdir($mail_path);
             }
             variable_set('devel_debug_mail_directory', $mail_path);
             // NB: DevelMailLog is going to replace our separator with __.
             variable_set('devel_debug_mail_file_format', '%to::%subject');
             $this->mail = new \DevelMailLog();
         }
     }
     if (!$this->drupalSession) {
         $_SERVER['SERVER_SOFTWARE'] = 'foo';
         $this->drupalSession = (object) array('name' => session_name(), 'id' => session_id());
         $_SESSION['foo'] = 'bar';
         drupal_session_commit();
     }
     session_name($this->drupalSession->name);
     session_id($this->drupalSession->id);
     $_COOKIE[session_name()] = session_id();
     drupal_session_start();
     $base_url = getenv('DRUPAL_BASE_URL');
     if (!empty($base_url)) {
         $this->setMinkParameter('base_url', $base_url);
     }
     $userName = getenv('DRUPAL_BASIC_AUTH_USERNAME');
     $pass = getenv('DRUPAL_BASIC_AUTH_PASS');
     foreach (array('selenium2', 'goutte') as $session) {
         $session = $this->getMink()->getSession($session);
         $session->visit($this->locatePath('/index.php?foo=bar'));
         if (!empty($userName) && !empty($pass)) {
             $this->getMink()->getSession()->setBasicAuth($userName, $pass);
         }
     }
 }
Exemplo n.º 6
0
 public function add($args)
 {
     $dataForDb = array();
     // This data will be saved in the database
     $dataForFile = array();
     // This data will be saved in the file
     $currentDate = Date::current(DB_DATE_FORMAT);
     // Generate the database key.
     $key = $this->generateKey($args['slug']);
     // The user is always who is loggued.
     $args['username'] = Session::get('username');
     if (Text::isEmpty($args['username'])) {
         return false;
     }
     // Date
     if (!Valid::date($args['date'], DB_DATE_FORMAT)) {
         $args['date'] = $currentDate;
     }
     // Schedule post?
     if ($args['date'] > $currentDate && $args['status'] == 'published') {
         $args['status'] = 'scheduled';
     }
     // Verify arguments with the database fields.
     foreach ($this->dbFields as $field => $options) {
         // If the field is in the arguments.
         if (isset($args[$field])) {
             if ($field == 'tags') {
                 $tmpValue = $this->generateTags($args['tags']);
             } else {
                 // Sanitize if will be saved on database.
                 if (!$options['inFile']) {
                     $tmpValue = Sanitize::html($args[$field]);
                 } else {
                     $tmpValue = $args[$field];
                 }
             }
         } else {
             $tmpValue = $options['value'];
         }
         // Check where the field will be written, if in the file or in the database.
         if ($options['inFile']) {
             $dataForFile[$field] = Text::firstCharUp($field) . ': ' . $tmpValue;
         } else {
             // Set type
             settype($tmpValue, gettype($options['value']));
             // Save on database
             $dataForDb[$field] = $tmpValue;
         }
     }
     // Make the directory.
     if (Filesystem::mkdir(PATH_POSTS . $key) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to create the directory ' . PATH_POSTS . $key);
         return false;
     }
     // Make the index.txt and save the file.
     $data = implode("\n", $dataForFile);
     if (file_put_contents(PATH_POSTS . $key . DS . 'index.txt', $data) === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to put the content in the file index.txt');
         return false;
     }
     // Save the database
     $this->db[$key] = $dataForDb;
     // Sort posts before save.
     $this->sortByDate();
     if ($this->save() === false) {
         Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
         return false;
     }
     return $key;
 }
 /**
  * This method allows you to do any additional work beyond unpacking 
  * the files that is required. This could include work such as downloading
  * and unpacking an archive.
  * 
  * The following are some of the methods available to you in this file:
  * $this->curlFile($url, $destFolder)
  * $this->move($src, $dest)
  * $this->unzip($file, $destFolder)
  */
 public function doWork()
 {
     $fs = new Filesystem();
     // Ensure tmp working dir exists
     $tmp = $this->mRootPath . "\\tmp";
     $this->log("Creating temporary build directory: " . $tmp);
     $fs->mkdir($tmp);
     if ($this->p->get('source') != '' && $fs->exists($this->p->get('source'))) {
         // Use WordPress codebase from source parameter
         $this->log("Copying WordPress from " . $this->p->get('source'));
         $fs->copy($this->p->get('source'), $this->mAppRoot);
     } else {
         // Download and unpack WordPress
         $this->log('Downloading WordPress');
         $file = $this->curlFile(WP_URL, $tmp);
         $this->log('Extracting WordPress');
         $this->unzip($file, $tmp);
         $this->log('Moving WordPress files to ' . $this->mAppRoot);
         $fs->move("{$tmp}\\wordpress", $this->mAppRoot);
     }
     // Download and unpack DB abstraction layer
     $this->log('Downloading Database Abstraction Layer');
     $file = $this->curlFile(DB_ABSTRACTION_URL, $tmp);
     $this->log('Extracting Database Abstraction Layer');
     $this->unzip($file, $tmp);
     $this->log('Moving Database Abstraction Layer files to ' . $this->mAppRoot . "\\wp-content\\mu-plugins");
     $fs->copy("{$tmp}\\wordpress-database-abstraction\\wp-db-abstraction\\db.php", $this->mAppRoot . "\\wp-content\\db.php");
     $fs->move("{$tmp}\\wordpress-database-abstraction", $this->mAppRoot . "\\wp-content\\mu-plugins");
     // Download and unpack Azure Storage Plugin
     $this->log('Downloading Azure Storage Plugin');
     $file = $this->curlFile(WAZ_STORAGE_URL, $tmp);
     $this->log('Extracting Azure Storage Plugin');
     $this->unzip($file, $tmp);
     $this->log('Moving Azure Storage Plugin files to ' . $this->mAppRoot . "\\wp-content\\plugins");
     $fs->move("{$tmp}\\windows-azure-storage", $this->mAppRoot . "\\wp-content\\plugins\\windows-azure-storage");
     if ($this->p->get('WP_ALLOW_MULTISITE') && $this->p->get('WP_ALLOW_MULTISITE') != 'false') {
         $fs->mkdir($this->mAppRoot . "\\wp-content\\blogs.dir");
         unlink("{$this->mAppRoot}.config");
         if ($this->p->get('SUBDOMAIN_INSTALL')) {
             copy($this->mAppRoot . "\\resources\\Web-network-subdomains.config", $this->mAppRoot . "\\Web.config");
         } else {
             copy($this->mAppRoot . "\\resources\\Web-network-subfolders.config", $this->mAppRoot . "\\Web.config");
         }
     }
     // Remove tmp build folder
     $fs->rm($tmp);
     $fs->rm($this->mRootPath . "/Params.class.php");
     $fs->rm($this->mRootPath . "/FileSystem.class.php");
     $this->updateWpConfig();
     echo "\n\nCongratulations! You now have a brand new Windows Azure WordPress project at " . $this->mRootPath . "\n";
 }