Esempio n. 1
0
 /**
  * Generates a sitemap.xml for the site
  *
  * @return Response
  */
 public function generateSitemap(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // get site
     $site = Site::getById($siteId);
     // get user
     $user = User::getByEmail($email, $siteId);
     // publish site map
     Publish::publishSiteMap($user, $site);
     return response('Ok', 200);
 }
Esempio n. 2
0
 /**
  * Edits the settings
  *
  * @return Response
  */
 public function edit(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // get url, title and description
     $settings = $request->json()->get('settings');
     // get site and user
     $site = Site::getById($siteId);
     $user = User::getByEmail($email, $siteId);
     // update order in file
     $success = Setting::saveAll($settings, $user, $site);
     if ($success === TRUE) {
         return response('Ok', 200);
     } else {
         // return error
         return response('Error', 400);
     }
 }
 /**
  * Removes the gallery image
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // id, galleryId
     $id = $request->json()->get('id');
     $galleryId = $request->json()->get('galleryId');
     // get form
     $gallery = Gallery::getById($galleryId, $siteId);
     if ($gallery != NULL) {
         $index = GalleryImage::getIndexById($id, $galleryId, $siteId);
         array_splice($gallery->images, $index, 1);
         $gallery->save($siteId);
         // get site and user
         $site = Site::getById($siteId);
         $user = User::getByEmail($email, $siteId);
         // re-publish plugins
         Publish::publishPlugins($user, $site);
         return response('Ok', 200);
     }
     return response('Gallery not found', 400);
 }
Esempio n. 4
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);
 }
 /**
  * Removes the form field
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // name, items
     $formId = $request->json()->get('id');
     $index = $request->json()->get('index');
     // get form
     $form = Form::getById($formId, $siteId);
     if ($form != NULL) {
         array_splice($form->fields, $index, 1);
         $form->save($siteId);
         // get site and user
         $site = Site::getById($siteId);
         $user = User::getByEmail($email, $siteId);
         // re-publish plugins
         Publish::publishPlugins($user, $site);
         return response('Ok', 200);
     }
     return response('Form not found', 400);
 }
Esempio n. 6
0
 /**
  * Uploads a file
  *
  * @return Response
  */
 public function upload(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $id = $request->input('auth-id');
     // get site
     $site = Site::getById($id);
     // get file
     $file = $request->file('file');
     // get file info
     $filename = $file->getClientOriginalName();
     $contentType = $file->getMimeType();
     $size = intval($file->getClientSize() / 1024);
     // get the extension
     $ext = $file->getClientOriginalExtension();
     // allowed filetypes
     $allowed = explode(',', env('ALLOWED_FILETYPES'));
     // trim and lowercase all items in the aray
     $allowed = array_map('trim', $allowed);
     $allowed = array_map('strtolower', $allowed);
     // directory to save
     $directory = app()->basePath() . '/public/sites/' . $site->id . '/files';
     // save image
     if ($ext == 'png' || $ext == 'jpg' || $ext == 'gif' || $ext == 'svg') {
         // upload image
         // move the file
         $file->move($directory, $filename);
         // set path
         $path = $directory . '/' . $filename;
         $arr = Utilities::createThumb($site, $path, $filename);
         // create array
         $arr = array('filename' => $filename, 'fullUrl' => '/files/' . $filename, 'thumbUrl' => '/files/thumbs/' . $filename, 'extension' => $ext, 'isImage' => true, 'width' => $arr['width'], 'height' => $arr['height']);
     } else {
         if (in_array($ext, $allowed)) {
             // save file if it is allowed
             // move the file
             $file->move($directory, $filename);
             // set url
             $url = $site->domain;
             $arr = array('filename' => $filename, 'fullUrl' => $url . '/files/' . $filename, 'thumbUrl' => NULL, 'extension' => $ext, 'isImage' => false, 'width' => -1, 'height' => -1);
         } else {
             return response('Unauthorized', 401);
         }
     }
     // return OK
     return response()->json($arr);
 }
 /**
  * Removes the menu item
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $siteId = $request->input('auth-id');
     // name, items
     $menuId = $request->json()->get('id');
     $index = $request->json()->get('index');
     // update order in file
     $menu = Menu::getById($menuId, $siteId);
     if ($menu != NULL) {
         array_splice($menu->items, $index, 1);
         $menu->save($siteId);
         // get site and user
         $site = Site::getById($siteId);
         $user = User::getByEmail($email, $siteId);
         // re-publish plugins
         Publish::publishPlugins($user, $site);
         return response('Ok', 200);
     }
     return response('Menu Item not found', 400);
 }
Esempio n. 8
0
 /**
  * Removes the page
  *
  * @return Response
  */
 public function remove(Request $request)
 {
     // get request data
     $email = $request->input('auth-email');
     $id = $request->input('auth-id');
     // get the site
     $site = Site::getById($id);
     $user = User::getByEmail($email, $id);
     // get url, title and description
     $url = $request->json()->get('url');
     $page = Page::getByUrl($url, $id);
     $page->remove($user, $site);
     // re-publish site map
     Publish::publishSiteMap($user, $site);
     // return OK
     return response('OK, page removed at = ' . $page->url, 200);
 }
Esempio n. 9
0
 /**
  * Resets the password
  *
  * @return Response
  */
 public function reset(Request $request)
 {
     $token = $request->json()->get('token');
     $password = $request->json()->get('password');
     $id = $request->json()->get('id');
     $site = Site::getById($id);
     if ($site != NULL) {
         // get the user from the credentials
         $user = User::getByToken($token, $site->id);
         if ($user != null) {
             // update the password
             $user->password = password_hash($password, PASSWORD_DEFAULT);
             $user->token = '';
             $user->save($site->id);
             // return a successful response (200)
             return response('OK', 200);
         } else {
             // return a bad request
             return response('Token invalid', 400);
         }
     } else {
         // return a bad request
         return response('Token invalid', 400);
     }
 }