Exemple #1
0
 /**
  * Gets a site for a given Id
  *
  * @param {string} $id the ID for the user
  * @return {Site}
  */
 public static function create($name, $theme, $email, $password)
 {
     // create an id
     $id = strtolower($name);
     // replaces all spaces with hyphens
     $id = str_replace(' ', '-', $id);
     // replaces all spaces with hyphens
     $id = $new_id = preg_replace('/[^A-Za-z0-9\\-]/', '', $id);
     // find a unique $id (e.g. myid, myid1, myid2, etc.)
     $x = 1;
     $folder = app()->basePath() . '/public/sites/' . $id;
     while (file_exists($folder) === TRUE) {
         // increment id and folder
         $new_id = $id . $x;
         $folder = app()->basePath() . '/public/sites/' . $new_id;
         $x++;
     }
     // set id to new_id
     $id = $new_id;
     // create a site
     $site_arr = array('id' => $id, 'name' => $name, 'email' => $email, 'theme' => $theme);
     // create and save the site
     $site = new Site($site_arr);
     $site->save();
     // create and save the user
     $user = new User(array('email' => $email, 'password' => password_hash($password, PASSWORD_DEFAULT), 'firstName' => 'New', 'lastName' => 'User', 'language' => 'en', 'photo' => '', 'token' => ''));
     $user->save($site->id);
     // publish theme
     Publish::publishTheme($theme, $site);
     // publish plugins
     Publish::publishPlugins($user, $site);
     // return site information
     return array('id' => $id, 'name' => $name);
 }