repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.search | public function search(Request $request)
{
$input = $request->all();
$result = $this->repository->search($input);
return view('cms::modules.files.index')
->with('files', $result[0]->get())
->with('pagination', $result[2])
->with('term', $result[1]);
} | php | public function search(Request $request)
{
$input = $request->all();
$result = $this->repository->search($input);
return view('cms::modules.files.index')
->with('files', $result[0]->get())
->with('pagination', $result[2])
->with('term', $result[1]);
} | [
"public",
"function",
"search",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"input",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"repository",
"->",
"search",
"(",
"$",
"input",
")",
";",
"return",
"vi... | Search.
@param Request $request
@return Response | [
"Search",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L58-L68 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.store | public function store(Request $request)
{
$validation = $this->validation->check(File::$rules);
if (!$validation['errors']) {
$file = $this->repository->store($request->all());
} else {
return $validation['redirect'];
}
Cms::notification('File saved successfully.', 'success');
return redirect(route($this->routeBase.'.files.index'));
} | php | public function store(Request $request)
{
$validation = $this->validation->check(File::$rules);
if (!$validation['errors']) {
$file = $this->repository->store($request->all());
} else {
return $validation['redirect'];
}
Cms::notification('File saved successfully.', 'success');
return redirect(route($this->routeBase.'.files.index'));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"validation",
"->",
"check",
"(",
"File",
"::",
"$",
"rules",
")",
";",
"if",
"(",
"!",
"$",
"validation",
"[",
"'errors'",
"]",
")",
... | Store a newly created Files in storage.
@param FileRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Files",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L87-L100 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.upload | public function upload(Request $request)
{
$validation = $this->validation->check([
'location' => [],
]);
if (!$validation['errors']) {
$file = $request->file('location');
$fileSaved = $this->fileService->saveFile($file, 'files/');
$fileSaved['name'] = CryptoService::encrypt($fileSaved['name']);
$fileSaved['mime'] = $file->getClientMimeType();
$fileSaved['size'] = $file->getClientSize();
$response = $this->responseService->apiResponse('success', $fileSaved);
} else {
$response = $this->responseService->apiErrorResponse($validation['errors'], $validation['inputs']);
}
return $response;
} | php | public function upload(Request $request)
{
$validation = $this->validation->check([
'location' => [],
]);
if (!$validation['errors']) {
$file = $request->file('location');
$fileSaved = $this->fileService->saveFile($file, 'files/');
$fileSaved['name'] = CryptoService::encrypt($fileSaved['name']);
$fileSaved['mime'] = $file->getClientMimeType();
$fileSaved['size'] = $file->getClientSize();
$response = $this->responseService->apiResponse('success', $fileSaved);
} else {
$response = $this->responseService->apiErrorResponse($validation['errors'], $validation['inputs']);
}
return $response;
} | [
"public",
"function",
"upload",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"validation",
"->",
"check",
"(",
"[",
"'location'",
"=>",
"[",
"]",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"validation",
"[",
"'... | Store a newly created Files in storage.
@param FileRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Files",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L109-L127 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.remove | public function remove($id)
{
try {
Storage::delete($id);
$response = $this->responseService->apiResponse('success', 'success!');
} catch (Exception $e) {
$response = $this->responseService->apiResponse('error', $e->getMessage());
}
return $response;
} | php | public function remove($id)
{
try {
Storage::delete($id);
$response = $this->responseService->apiResponse('success', 'success!');
} catch (Exception $e) {
$response = $this->responseService->apiResponse('error', $e->getMessage());
}
return $response;
} | [
"public",
"function",
"remove",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"Storage",
"::",
"delete",
"(",
"$",
"id",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"responseService",
"->",
"apiResponse",
"(",
"'success'",
",",
"'success!'",
")",
";",
... | Remove a file.
@param string $id
@return Response | [
"Remove",
"a",
"file",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L136-L146 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.update | public function update($id, FileRequest $request)
{
$files = $this->repository->find($id);
if (empty($files)) {
Cms::notification('File not found', 'warning');
return redirect(route($this->routeBase.'.files.index'));
}
$files = $this->repository->update($files, $request->all());
Cms::notification('File updated successfully.', 'success');
return Redirect::back();
} | php | public function update($id, FileRequest $request)
{
$files = $this->repository->find($id);
if (empty($files)) {
Cms::notification('File not found', 'warning');
return redirect(route($this->routeBase.'.files.index'));
}
$files = $this->repository->update($files, $request->all());
Cms::notification('File updated successfully.', 'success');
return Redirect::back();
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"FileRequest",
"$",
"request",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"Cms",... | Update the specified Files in storage.
@param int $id
@param FileRequest $request
@return Response | [
"Update",
"the",
"specified",
"Files",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L176-L191 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.destroy | public function destroy($id)
{
$files = $this->repository->find($id);
if (empty($files)) {
Cms::notification('File not found', 'warning');
return redirect(route($this->routeBase.'.files.index'));
}
if (is_file(storage_path($files->location))) {
Storage::delete($files->location);
} else {
Storage::disk(config('cms.storage-location', 'local'))->delete($files->location);
}
$files->delete();
Cms::notification('File deleted successfully.', 'success');
return redirect(route($this->routeBase.'.files.index'));
} | php | public function destroy($id)
{
$files = $this->repository->find($id);
if (empty($files)) {
Cms::notification('File not found', 'warning');
return redirect(route($this->routeBase.'.files.index'));
}
if (is_file(storage_path($files->location))) {
Storage::delete($files->location);
} else {
Storage::disk(config('cms.storage-location', 'local'))->delete($files->location);
}
$files->delete();
Cms::notification('File deleted successfully.', 'success');
return redirect(route($this->routeBase.'.files.index'));
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"Cms",
"::",
"notification",
"(",
"'File ... | Remove the specified Files from storage.
@param int $id
@return Response | [
"Remove",
"the",
"specified",
"Files",
"from",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L200-L221 |
GrafiteInc/CMS | src/Controllers/FilesController.php | FilesController.apiList | public function apiList(Request $request)
{
if (config('cms.api-key') != $request->header('cms')) {
return $this->responseService->apiResponse('error', []);
}
$files = $this->repository->apiPrepared();
return $this->responseService->apiResponse('success', $files);
} | php | public function apiList(Request $request)
{
if (config('cms.api-key') != $request->header('cms')) {
return $this->responseService->apiResponse('error', []);
}
$files = $this->repository->apiPrepared();
return $this->responseService->apiResponse('success', $files);
} | [
"public",
"function",
"apiList",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"config",
"(",
"'cms.api-key'",
")",
"!=",
"$",
"request",
"->",
"header",
"(",
"'cms'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"responseService",
"->",
"apiRespon... | Display the specified Images.
@return Response | [
"Display",
"the",
"specified",
"Images",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FilesController.php#L228-L237 |
GrafiteInc/CMS | src/Controllers/EventController.php | EventController.update | public function update($id, EventRequest $request)
{
$event = $this->repository->find($id);
if (empty($event)) {
Cms::notification('Event not found', 'warning');
return redirect(route($this->routeBase.'.events.index'));
}
$event = $this->repository->update($event, $request->all());
Cms::notification('Event updated successfully.', 'success');
if (!$event) {
Cms::notification('Event could not be saved.', 'warning');
}
return redirect(URL::previous());
} | php | public function update($id, EventRequest $request)
{
$event = $this->repository->find($id);
if (empty($event)) {
Cms::notification('Event not found', 'warning');
return redirect(route($this->routeBase.'.events.index'));
}
$event = $this->repository->update($event, $request->all());
Cms::notification('Event updated successfully.', 'success');
if (!$event) {
Cms::notification('Event could not be saved.', 'warning');
}
return redirect(URL::previous());
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"EventRequest",
"$",
"request",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"Cms"... | Update the specified Event in storage.
@param int $id
@param EventRequest $request
@return Response | [
"Update",
"the",
"specified",
"Event",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/EventController.php#L118-L136 |
GrafiteInc/CMS | src/Controllers/EventController.php | EventController.history | public function history($id)
{
$event = $this->repository->find($id);
return view('cms::modules.events.history')
->with('event', $event);
} | php | public function history($id)
{
$event = $this->repository->find($id);
return view('cms::modules.events.history')
->with('event', $event);
} | [
"public",
"function",
"history",
"(",
"$",
"id",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"return",
"view",
"(",
"'cms::modules.events.history'",
")",
"->",
"with",
"(",
"'event'",
",",
"$",
... | Page history.
@param int $id
@return Response | [
"Page",
"history",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/EventController.php#L169-L175 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/EventsController.php | EventsController.calendar | public function calendar($date = null)
{
if (is_null($date)) {
$date = date('Y-m-d');
}
$events = $this->service->calendar($date);
$calendar = $this->service->generate($date);
if (empty($calendar)) {
abort(404);
}
return view('cms-frontend::events.calendar')
->with('events', $events)
->with('calendar', $calendar);
} | php | public function calendar($date = null)
{
if (is_null($date)) {
$date = date('Y-m-d');
}
$events = $this->service->calendar($date);
$calendar = $this->service->generate($date);
if (empty($calendar)) {
abort(404);
}
return view('cms-frontend::events.calendar')
->with('events', $events)
->with('calendar', $calendar);
} | [
"public",
"function",
"calendar",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"date",
")",
")",
"{",
"$",
"date",
"=",
"date",
"(",
"'Y-m-d'",
")",
";",
"}",
"$",
"events",
"=",
"$",
"this",
"->",
"service",
"->",
"... | Calendar.
@param string $date
@return Response | [
"Calendar",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/EventsController.php#L30-L46 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/EventsController.php | EventsController.date | public function date($date)
{
$events = $this->repository->findEventsByDate($date);
if (empty($events)) {
abort(404);
}
return view('cms-frontend::events.date')->with('events', $events);
} | php | public function date($date)
{
$events = $this->repository->findEventsByDate($date);
if (empty($events)) {
abort(404);
}
return view('cms-frontend::events.date')->with('events', $events);
} | [
"public",
"function",
"date",
"(",
"$",
"date",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"repository",
"->",
"findEventsByDate",
"(",
"$",
"date",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"events",
")",
")",
"{",
"abort",
"(",
"404",
")",
... | Display page list.
@return Response | [
"Display",
"page",
"list",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/EventsController.php#L53-L62 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/EventsController.php | EventsController.all | public function all()
{
$events = $this->repository->published();
if (empty($events)) {
abort(404);
}
return view('cms-frontend::events.all')->with('events', $events);
} | php | public function all()
{
$events = $this->repository->published();
if (empty($events)) {
abort(404);
}
return view('cms-frontend::events.all')->with('events', $events);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"repository",
"->",
"published",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"events",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"return",
"view",
"(",
... | Display page list.
@return Response | [
"Display",
"page",
"list",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/EventsController.php#L69-L78 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/EventsController.php | EventsController.show | public function show($id)
{
$event = $this->repository->find($id);
if (empty($event)) {
abort(404);
}
return view('cms-frontend::events.'.$event->template)->with('event', $event);
} | php | public function show($id)
{
$event = $this->repository->find($id);
if (empty($event)) {
abort(404);
}
return view('cms-frontend::events.'.$event->template)->with('event', $event);
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"ret... | Display the specified Page.
@param string $date
@return Response | [
"Display",
"the",
"specified",
"Page",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/EventsController.php#L87-L96 |
GrafiteInc/CMS | src/Migrations/2017_07_05_002825_add_blocks.php | AddBlocks.up | public function up()
{
Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
Schema::table(config('cms.db-prefix', '').'events', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
} | php | public function up()
{
Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
Schema::table(config('cms.db-prefix', '').'events', function (Blueprint $table) {
$table->text('blocks')->nullable();
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"table",
"(",
"config",
"(",
"'cms.db-prefix'",
",",
"''",
")",
".",
"'pages'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"text",
"(",
"'blocks'",
")",
"-... | Run the migrations. | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2017_07_05_002825_add_blocks.php#L11-L24 |
GrafiteInc/CMS | src/Migrations/2017_07_05_002825_add_blocks.php | AddBlocks.down | public function down()
{
Schema::table(config('cms.db-prefix', '').'pages', function ($table) {
$table->dropColumn('blocks');
});
Schema::table(config('cms.db-prefix', '').'blogs', function ($table) {
$table->dropColumn('blocks');
});
Schema::table(config('cms.db-prefix', '').'events', function ($table) {
$table->dropColumn('blocks');
});
} | php | public function down()
{
Schema::table(config('cms.db-prefix', '').'pages', function ($table) {
$table->dropColumn('blocks');
});
Schema::table(config('cms.db-prefix', '').'blogs', function ($table) {
$table->dropColumn('blocks');
});
Schema::table(config('cms.db-prefix', '').'events', function ($table) {
$table->dropColumn('blocks');
});
} | [
"public",
"function",
"down",
"(",
")",
"{",
"Schema",
"::",
"table",
"(",
"config",
"(",
"'cms.db-prefix'",
",",
"''",
")",
".",
"'pages'",
",",
"function",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"dropColumn",
"(",
"'blocks'",
")",
";",
"}... | Reverse the migrations. | [
"Reverse",
"the",
"migrations",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2017_07_05_002825_add_blocks.php#L29-L42 |
GrafiteInc/CMS | src/Controllers/LinksController.php | LinksController.store | public function store(LinksRequest $request)
{
try {
$validation = app(ValidationService::class)->check(Link::$rules);
if (!$validation['errors']) {
$links = $this->repository->store($request->all());
Cms::notification('Link saved successfully.', 'success');
if (!$links) {
Cms::notification('Link could not be saved.', 'danger');
}
} else {
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Link could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$request->get('menu_id')]));
} | php | public function store(LinksRequest $request)
{
try {
$validation = app(ValidationService::class)->check(Link::$rules);
if (!$validation['errors']) {
$links = $this->repository->store($request->all());
Cms::notification('Link saved successfully.', 'success');
if (!$links) {
Cms::notification('Link could not be saved.', 'danger');
}
} else {
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Link could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$request->get('menu_id')]));
} | [
"public",
"function",
"store",
"(",
"LinksRequest",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"validation",
"=",
"app",
"(",
"ValidationService",
"::",
"class",
")",
"->",
"check",
"(",
"Link",
"::",
"$",
"rules",
")",
";",
"if",
"(",
"!",
"$",
"val... | Store a newly created Links in storage.
@param LinksRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Links",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/LinksController.php#L56-L76 |
GrafiteInc/CMS | src/Controllers/LinksController.php | LinksController.destroy | public function destroy($id)
{
$link = $this->repository->find($id);
$menu = $link->menu_id;
if (empty($link)) {
Cms::notification('Link not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$order = json_decode($link->menu->order);
$key = array_search($id, $order);
unset($order[$key]);
$link->menu->update([
'order' => json_encode(array_values($order)),
]);
$link->delete();
Cms::notification('Link deleted successfully.', 'success');
return redirect(route($this->routeBase.'.menus.edit', [$link->menu_id]));
} | php | public function destroy($id)
{
$link = $this->repository->find($id);
$menu = $link->menu_id;
if (empty($link)) {
Cms::notification('Link not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$order = json_decode($link->menu->order);
$key = array_search($id, $order);
unset($order[$key]);
$link->menu->update([
'order' => json_encode(array_values($order)),
]);
$link->delete();
Cms::notification('Link deleted successfully.', 'success');
return redirect(route($this->routeBase.'.menus.edit', [$link->menu_id]));
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"menu",
"=",
"$",
"link",
"->",
"menu_id",
";",
"if",
"(",
"empty",
"(",
"$",
"link",
")"... | Remove the specified Links from storage.
@param int $id
@return Response | [
"Remove",
"the",
"specified",
"Links",
"from",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/LinksController.php#L137-L161 |
GrafiteInc/CMS | src/Console/ModuleComposer.php | ModuleComposer.handle | public function handle()
{
$moduleDir = base_path(config('cms.module-directory')).'/'.ucfirst($this->argument('module'));
if (is_dir($moduleDir)) {
$readMeStub = file_get_contents(__DIR__.'/../Templates/Composer/readme.stub');
$composerStub = file_get_contents(__DIR__.'/../Templates/Composer/composer.stub');
$packageDir = $this->option('directory');
$namespace = $this->argument('namespace');
$module = $this->argument('module');
$system = app(Filesystem::class);
if (is_null($packageDir)) {
$packageDir = $moduleDir.'/../../packages/'.ucfirst($module);
}
if (!is_dir($moduleDir.'/../../packages/')) {
$system->makeDirectory($moduleDir.'/../../packages/');
}
if (!is_dir($packageDir)) {
$system->makeDirectory($packageDir);
}
$system->put($packageDir.'/README.md', $readMeStub);
$system->put($packageDir.'/composer.json', $composerStub);
$this->copyModuleToPackageDir($moduleDir, $packageDir);
$files = $system->glob($packageDir.'/*');
foreach ($files as $file) {
if ($system->isFile($file)) {
$this->updateFile($file, $namespace, $module);
}
}
$this->line('Your comploser package is now complete.');
} else {
$this->line('We\'ve encountered an issue, please check you spelled the module name correctly');
}
} | php | public function handle()
{
$moduleDir = base_path(config('cms.module-directory')).'/'.ucfirst($this->argument('module'));
if (is_dir($moduleDir)) {
$readMeStub = file_get_contents(__DIR__.'/../Templates/Composer/readme.stub');
$composerStub = file_get_contents(__DIR__.'/../Templates/Composer/composer.stub');
$packageDir = $this->option('directory');
$namespace = $this->argument('namespace');
$module = $this->argument('module');
$system = app(Filesystem::class);
if (is_null($packageDir)) {
$packageDir = $moduleDir.'/../../packages/'.ucfirst($module);
}
if (!is_dir($moduleDir.'/../../packages/')) {
$system->makeDirectory($moduleDir.'/../../packages/');
}
if (!is_dir($packageDir)) {
$system->makeDirectory($packageDir);
}
$system->put($packageDir.'/README.md', $readMeStub);
$system->put($packageDir.'/composer.json', $composerStub);
$this->copyModuleToPackageDir($moduleDir, $packageDir);
$files = $system->glob($packageDir.'/*');
foreach ($files as $file) {
if ($system->isFile($file)) {
$this->updateFile($file, $namespace, $module);
}
}
$this->line('Your comploser package is now complete.');
} else {
$this->line('We\'ve encountered an issue, please check you spelled the module name correctly');
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"moduleDir",
"=",
"base_path",
"(",
"config",
"(",
"'cms.module-directory'",
")",
")",
".",
"'/'",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'module'",
")",
")",
";",
"if",
"(",
"is_di... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ModuleComposer.php#L30-L70 |
GrafiteInc/CMS | src/Repositories/BlogRepository.php | BlogRepository.tags | public function tags($tag)
{
return $this->model->where('is_published', 1)
->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))
->where('tags', 'LIKE', '%'.$tag.'%')->orderBy('created_at', 'desc')
->paginate(config('cms.pagination', 24));
} | php | public function tags($tag)
{
return $this->model->where('is_published', 1)
->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))
->where('tags', 'LIKE', '%'.$tag.'%')->orderBy('created_at', 'desc')
->paginate(config('cms.pagination', 24));
} | [
"public",
"function",
"tags",
"(",
"$",
"tag",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"'is_published'",
",",
"1",
")",
"->",
"where",
"(",
"'published_at'",
",",
"'<='",
",",
"Carbon",
"::",
"now",
"(",
"config",
"(",
"'a... | Blog tags, with similar name
@param string $tag
@return Illuminate\Support\Collection | [
"Blog",
"tags",
"with",
"similar",
"name"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/BlogRepository.php#L46-L52 |
GrafiteInc/CMS | src/Repositories/BlogRepository.php | BlogRepository.allTags | public function allTags()
{
$tags = [];
if (app()->getLocale() !== config('cms.default-language', 'en')) {
$blogs = $this->translationRepo->getEntitiesByTypeAndLang(app()->getLocale(), 'Grafite\Cms\Models\Blog');
} else {
$blogs = $this->model->orderBy('published_at', 'desc')->get();
}
foreach ($blogs as $blog) {
foreach (explode(',', $blog->tags) as $tag) {
if ($tag !== '') {
array_push($tags, $tag);
}
}
}
return collect(array_unique($tags));
} | php | public function allTags()
{
$tags = [];
if (app()->getLocale() !== config('cms.default-language', 'en')) {
$blogs = $this->translationRepo->getEntitiesByTypeAndLang(app()->getLocale(), 'Grafite\Cms\Models\Blog');
} else {
$blogs = $this->model->orderBy('published_at', 'desc')->get();
}
foreach ($blogs as $blog) {
foreach (explode(',', $blog->tags) as $tag) {
if ($tag !== '') {
array_push($tags, $tag);
}
}
}
return collect(array_unique($tags));
} | [
"public",
"function",
"allTags",
"(",
")",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"if",
"(",
"app",
"(",
")",
"->",
"getLocale",
"(",
")",
"!==",
"config",
"(",
"'cms.default-language'",
",",
"'en'",
")",
")",
"{",
"$",
"blogs",
"=",
"$",
"this",
... | Gets all tags of an entry
@return Illuminate\Support\Collection | [
"Gets",
"all",
"tags",
"of",
"an",
"entry"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/BlogRepository.php#L59-L78 |
GrafiteInc/CMS | src/Repositories/BlogRepository.php | BlogRepository.store | public function store($payload)
{
$payload = $this->parseBlocks($payload, 'blog');
$payload['title'] = htmlentities($payload['title']);
$payload['url'] = Cms::convertToURL($payload['url']);
$payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');
if (isset($payload['hero_image'])) {
$file = request()->file('hero_image');
$path = app(FileService::class)->saveFile($file, 'public/images', [], true);
$payload['hero_image'] = $path['name'];
}
return $this->model->create($payload);
} | php | public function store($payload)
{
$payload = $this->parseBlocks($payload, 'blog');
$payload['title'] = htmlentities($payload['title']);
$payload['url'] = Cms::convertToURL($payload['url']);
$payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');
if (isset($payload['hero_image'])) {
$file = request()->file('hero_image');
$path = app(FileService::class)->saveFile($file, 'public/images', [], true);
$payload['hero_image'] = $path['name'];
}
return $this->model->create($payload);
} | [
"public",
"function",
"store",
"(",
"$",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"parseBlocks",
"(",
"$",
"payload",
",",
"'blog'",
")",
";",
"$",
"payload",
"[",
"'title'",
"]",
"=",
"htmlentities",
"(",
"$",
"payload",
"[",
"'t... | Stores Blog into database.
@param array $input
@return Blog | [
"Stores",
"Blog",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/BlogRepository.php#L87-L103 |
GrafiteInc/CMS | src/Repositories/BlogRepository.php | BlogRepository.findBlogsByURL | public function findBlogsByURL($url)
{
$blog = null;
$blog = $this->model->where('url', $url)->where('is_published', 1)->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))->first();
if (!$blog) {
$blog = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Blog');
}
return $blog;
} | php | public function findBlogsByURL($url)
{
$blog = null;
$blog = $this->model->where('url', $url)->where('is_published', 1)->where('published_at', '<=', Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s'))->first();
if (!$blog) {
$blog = $this->translationRepo->findByUrl($url, 'Grafite\Cms\Models\Blog');
}
return $blog;
} | [
"public",
"function",
"findBlogsByURL",
"(",
"$",
"url",
")",
"{",
"$",
"blog",
"=",
"null",
";",
"$",
"blog",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"'url'",
",",
"$",
"url",
")",
"->",
"where",
"(",
"'is_published'",
",",
"1",
")",
... | Find Blog by given URL.
@param string $url
@return \Illuminate\Support\Collection|null|static|Pages | [
"Find",
"Blog",
"by",
"given",
"URL",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/BlogRepository.php#L112-L123 |
GrafiteInc/CMS | src/Repositories/BlogRepository.php | BlogRepository.update | public function update($blog, $payload)
{
$payload = $this->parseBlocks($payload, 'blog');
$payload['title'] = htmlentities($payload['title']);
if (isset($payload['hero_image'])) {
app(FileService::class)->delete($blog->hero_image);
$file = request()->file('hero_image');
$path = app(FileService::class)->saveFile($file, 'public/images', [], true);
$payload['hero_image'] = $path['name'];
}
if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) {
return $this->translationRepo->createOrUpdate($blog->id, 'Grafite\Cms\Models\Blog', $payload['lang'], $payload);
} else {
$payload['url'] = Cms::convertToURL($payload['url']);
$payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');
unset($payload['lang']);
return $blog->update($payload);
}
} | php | public function update($blog, $payload)
{
$payload = $this->parseBlocks($payload, 'blog');
$payload['title'] = htmlentities($payload['title']);
if (isset($payload['hero_image'])) {
app(FileService::class)->delete($blog->hero_image);
$file = request()->file('hero_image');
$path = app(FileService::class)->saveFile($file, 'public/images', [], true);
$payload['hero_image'] = $path['name'];
}
if (!empty($payload['lang']) && $payload['lang'] !== config('cms.default-language', 'en')) {
return $this->translationRepo->createOrUpdate($blog->id, 'Grafite\Cms\Models\Blog', $payload['lang'], $payload);
} else {
$payload['url'] = Cms::convertToURL($payload['url']);
$payload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$payload['published_at'] = (isset($payload['published_at']) && !empty($payload['published_at'])) ? Carbon::parse($payload['published_at'])->format('Y-m-d H:i:s') : Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s');
unset($payload['lang']);
return $blog->update($payload);
}
} | [
"public",
"function",
"update",
"(",
"$",
"blog",
",",
"$",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"parseBlocks",
"(",
"$",
"payload",
",",
"'blog'",
")",
";",
"$",
"payload",
"[",
"'title'",
"]",
"=",
"htmlentities",
"(",
"$",
... | Updates Blog into database.
@param Blog $blog
@param array $input
@return Blog | [
"Updates",
"Blog",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/BlogRepository.php#L145-L169 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.asPublic | public function asPublic($encFileName)
{
try {
return Cache::remember($encFileName.'_asPublic', 3600, function () use ($encFileName) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
$filePath = $this->getFilePath($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($fileName, $contentType, $ext);
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
return Response::make('file not found');
}
} | php | public function asPublic($encFileName)
{
try {
return Cache::remember($encFileName.'_asPublic', 3600, function () use ($encFileName) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
$filePath = $this->getFilePath($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($fileName, $contentType, $ext);
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
return Response::make('file not found');
}
} | [
"public",
"function",
"asPublic",
"(",
"$",
"encFileName",
")",
"{",
"try",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"encFileName",
".",
"'_asPublic'",
",",
"3600",
",",
"function",
"(",
")",
"use",
"(",
"$",
"encFileName",
")",
"{",
"$",
"f... | Provide the File as a Public Asset.
@param string $encFileName
@return Download | [
"Provide",
"the",
"File",
"as",
"a",
"Public",
"Asset",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L34-L56 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.asPreview | public function asPreview($encFileName, Filesystem $fileSystem)
{
try {
return Cache::remember($encFileName.'_preview', 3600, function () use ($encFileName, $fileSystem) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
if (config('cms.storage-location') === 'local' || config('cms.storage-location') === null) {
$filePath = storage_path('app/'.$fileName);
$contentType = $fileSystem->mimeType($filePath);
$ext = strtoupper($fileSystem->extension($filePath));
} else {
$filePath = Storage::disk(config('cms.storage-location', 'local'))->url($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
}
if (stristr($contentType, 'image')) {
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($fileName, $contentType, $ext);
} else {
$fileContent = file_get_contents($this->generateImage($ext));
}
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
return Response::make('file not found');
}
} | php | public function asPreview($encFileName, Filesystem $fileSystem)
{
try {
return Cache::remember($encFileName.'_preview', 3600, function () use ($encFileName, $fileSystem) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
if (config('cms.storage-location') === 'local' || config('cms.storage-location') === null) {
$filePath = storage_path('app/'.$fileName);
$contentType = $fileSystem->mimeType($filePath);
$ext = strtoupper($fileSystem->extension($filePath));
} else {
$filePath = Storage::disk(config('cms.storage-location', 'local'))->url($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
}
if (stristr($contentType, 'image')) {
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($fileName, $contentType, $ext);
} else {
$fileContent = file_get_contents($this->generateImage($ext));
}
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
return Response::make('file not found');
}
} | [
"public",
"function",
"asPreview",
"(",
"$",
"encFileName",
",",
"Filesystem",
"$",
"fileSystem",
")",
"{",
"try",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"encFileName",
".",
"'_preview'",
",",
"3600",
",",
"function",
"(",
")",
"use",
"(",
"... | Provide the File as a Public Preview.
@param string $encFileName
@return Download | [
"Provide",
"the",
"File",
"as",
"a",
"Public",
"Preview",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L65-L97 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.asDownload | public function asDownload($encFileName, $encRealFileName)
{
try {
return Cache::remember($encFileName.'_asDownload', 3600, function () use ($encFileName, $encRealFileName) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
$realFileName = CryptoServiceFacade::url_decode($encRealFileName);
$filePath = $this->getFilePath($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($realFileName, $contentType, $ext);
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
Cms::notification('We encountered an error with that file', 'danger');
return redirect('errors/general');
}
} | php | public function asDownload($encFileName, $encRealFileName)
{
try {
return Cache::remember($encFileName.'_asDownload', 3600, function () use ($encFileName, $encRealFileName) {
$fileName = CryptoServiceFacade::url_decode($encFileName);
$realFileName = CryptoServiceFacade::url_decode($encRealFileName);
$filePath = $this->getFilePath($fileName);
$fileTool = new SplFileInfo($filePath);
$ext = $fileTool->getExtension();
$contentType = $this->getMimeType($ext);
$headers = ['Content-Type' => $contentType];
$fileContent = $this->getFileContent($realFileName, $contentType, $ext);
return Response::make($fileContent, 200, [
'Content-Type' => $contentType,
'Content-Disposition' => 'attachment; filename="'.$fileName.'"',
]);
});
} catch (Exception $e) {
Cms::notification('We encountered an error with that file', 'danger');
return redirect('errors/general');
}
} | [
"public",
"function",
"asDownload",
"(",
"$",
"encFileName",
",",
"$",
"encRealFileName",
")",
"{",
"try",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"encFileName",
".",
"'_asDownload'",
",",
"3600",
",",
"function",
"(",
")",
"use",
"(",
"$",
"... | Provide file as download.
@param string $encFileName
@param string $encRealFileName
@return Downlaod | [
"Provide",
"file",
"as",
"download",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L107-L132 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.asset | public function asset($encPath, $contentType, Filesystem $fileSystem)
{
try {
$path = CryptoServiceFacade::url_decode($encPath);
if (Request::get('isModule') === 'true') {
$filePath = $path;
} else {
if (str_contains($path, 'dist/') || str_contains($path, 'themes/')) {
$filePath = __DIR__.'/../Assets/'.$path;
} else {
$filePath = __DIR__.'/../Assets/src/'.$path;
}
}
$fileName = basename($filePath);
if (!is_null($contentType)) {
$contentType = CryptoServiceFacade::url_decode($contentType);
} else {
$contentType = $fileSystem->mimeType($fileName);
}
$headers = ['Content-Type' => $contentType];
return response()->download($filePath, $fileName, $headers);
} catch (Exception $e) {
return Response::make('file not found');
}
} | php | public function asset($encPath, $contentType, Filesystem $fileSystem)
{
try {
$path = CryptoServiceFacade::url_decode($encPath);
if (Request::get('isModule') === 'true') {
$filePath = $path;
} else {
if (str_contains($path, 'dist/') || str_contains($path, 'themes/')) {
$filePath = __DIR__.'/../Assets/'.$path;
} else {
$filePath = __DIR__.'/../Assets/src/'.$path;
}
}
$fileName = basename($filePath);
if (!is_null($contentType)) {
$contentType = CryptoServiceFacade::url_decode($contentType);
} else {
$contentType = $fileSystem->mimeType($fileName);
}
$headers = ['Content-Type' => $contentType];
return response()->download($filePath, $fileName, $headers);
} catch (Exception $e) {
return Response::make('file not found');
}
} | [
"public",
"function",
"asset",
"(",
"$",
"encPath",
",",
"$",
"contentType",
",",
"Filesystem",
"$",
"fileSystem",
")",
"{",
"try",
"{",
"$",
"path",
"=",
"CryptoServiceFacade",
"::",
"url_decode",
"(",
"$",
"encPath",
")",
";",
"if",
"(",
"Request",
"::... | Gets an asset.
@param string $encPath
@param string $contentType
@return Provides the valid | [
"Gets",
"an",
"asset",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L142-L171 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.getMimeType | public function getMimeType($extension)
{
if (isset($this->mimeTypes['.'.strtolower($extension)])) {
return $this->mimeTypes['.'.strtolower($extension)];
}
return 'text/plain';
} | php | public function getMimeType($extension)
{
if (isset($this->mimeTypes['.'.strtolower($extension)])) {
return $this->mimeTypes['.'.strtolower($extension)];
}
return 'text/plain';
} | [
"public",
"function",
"getMimeType",
"(",
"$",
"extension",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mimeTypes",
"[",
"'.'",
".",
"strtolower",
"(",
"$",
"extension",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"mimeTypes",
"[... | Get the mime type.
@param string $extension
@return string | [
"Get",
"the",
"mime",
"type",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L180-L187 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.getFilePath | public function getFilePath($fileName)
{
if (file_exists(storage_path('app/'.$fileName))) {
$filePath = storage_path('app/'.$fileName);
} else {
$filePath = Storage::disk(config('cms.storage-location', 'local'))->url($fileName);
}
return $filePath;
} | php | public function getFilePath($fileName)
{
if (file_exists(storage_path('app/'.$fileName))) {
$filePath = storage_path('app/'.$fileName);
} else {
$filePath = Storage::disk(config('cms.storage-location', 'local'))->url($fileName);
}
return $filePath;
} | [
"public",
"function",
"getFilePath",
"(",
"$",
"fileName",
")",
"{",
"if",
"(",
"file_exists",
"(",
"storage_path",
"(",
"'app/'",
".",
"$",
"fileName",
")",
")",
")",
"{",
"$",
"filePath",
"=",
"storage_path",
"(",
"'app/'",
".",
"$",
"fileName",
")",
... | Get a file's path
@param string $fileName
@return string | [
"Get",
"a",
"file",
"s",
"path"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L196-L205 |
GrafiteInc/CMS | src/Services/AssetService.php | AssetService.getFileContent | public function getFileContent($fileName, $contentType, $ext)
{
if (Storage::disk(config('cms.storage-location', 'local'))->exists($fileName)) {
$fileContent = Storage::disk(config('cms.storage-location', 'local'))->get($fileName);
} elseif (!is_null(config('filesystems.cloud.key'))) {
$fileContent = Storage::disk('cloud')->get($fileName);
} else {
$fileContent = file_get_contents($this->generateImage('File Not Found'));
}
if (stristr($fileName, 'image') || stristr($contentType, 'image')) {
if (! is_null(config('cms.preview-image-size'))) {
$img = Image::make($fileContent);
$img->resize(config('cms.preview-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
return $img->encode($ext);
}
}
return $fileContent;
} | php | public function getFileContent($fileName, $contentType, $ext)
{
if (Storage::disk(config('cms.storage-location', 'local'))->exists($fileName)) {
$fileContent = Storage::disk(config('cms.storage-location', 'local'))->get($fileName);
} elseif (!is_null(config('filesystems.cloud.key'))) {
$fileContent = Storage::disk('cloud')->get($fileName);
} else {
$fileContent = file_get_contents($this->generateImage('File Not Found'));
}
if (stristr($fileName, 'image') || stristr($contentType, 'image')) {
if (! is_null(config('cms.preview-image-size'))) {
$img = Image::make($fileContent);
$img->resize(config('cms.preview-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
return $img->encode($ext);
}
}
return $fileContent;
} | [
"public",
"function",
"getFileContent",
"(",
"$",
"fileName",
",",
"$",
"contentType",
",",
"$",
"ext",
")",
"{",
"if",
"(",
"Storage",
"::",
"disk",
"(",
"config",
"(",
"'cms.storage-location'",
",",
"'local'",
")",
")",
"->",
"exists",
"(",
"$",
"fileN... | Get a files content
@param string $fileName
@param string $contentType
@param string $ext
@return mixed | [
"Get",
"a",
"files",
"content"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/AssetService.php#L216-L238 |
GrafiteInc/CMS | src/Console/ThemePublish.php | ThemePublish.handle | public function handle()
{
$name = $this->argument('name');
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(base_path('resources/themes/'.strtolower($name).'/public'));
foreach ($files as $file) {
if ($file->getType() === 'file') {
$this->line(public_path($file->getBasename()));
}
}
$this->info("\n\nThese files will be overwritten\n");
if (!$this->option('forced')) {
$result = $this->confirm('Are you sure you want to overwrite any files of the same name?');
} else {
$result = true;
}
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(base_path('resources/themes/'.strtolower($name).'/public'), '', $file);
$this->line('Copying '.public_path($newFileName).'...');
if (is_dir($file)) {
$fileSystem->copyDirectory($file, public_path($newFileName));
} else {
@mkdir(public_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, public_path($newFileName));
}
}
} else {
$this->info("\n\nNo files were published\n");
}
} | php | public function handle()
{
$name = $this->argument('name');
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(base_path('resources/themes/'.strtolower($name).'/public'));
foreach ($files as $file) {
if ($file->getType() === 'file') {
$this->line(public_path($file->getBasename()));
}
}
$this->info("\n\nThese files will be overwritten\n");
if (!$this->option('forced')) {
$result = $this->confirm('Are you sure you want to overwrite any files of the same name?');
} else {
$result = true;
}
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(base_path('resources/themes/'.strtolower($name).'/public'), '', $file);
$this->line('Copying '.public_path($newFileName).'...');
if (is_dir($file)) {
$fileSystem->copyDirectory($file, public_path($newFileName));
} else {
@mkdir(public_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, public_path($newFileName));
}
}
} else {
$this->info("\n\nNo files were published\n");
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
";",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fileSystem",
"->",
"allFiles",
"(",
"base_pa... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ThemePublish.php#L29-L65 |
GrafiteInc/CMS | src/Console/ModulePublish.php | ModulePublish.handle | public function handle()
{
if (is_dir(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes')) {
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes');
$this->line("\n");
foreach ($files as $file) {
if ($file->getType() == 'file') {
$this->line(str_replace(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes'.DIRECTORY_SEPARATOR, '', $file));
}
}
$this->info("\n\nThese files will be published\n");
$result = $this->confirm('Are you sure you want to overwrite any files of the same name?');
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(base_path(Config::get('cms.module-directory').DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes'.DIRECTORY_SEPARATOR), '', $file);
if (strstr($newFileName, 'resources'.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR)) {
$newFileName = str_replace(DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR.Config::get('cms.frontend-theme').DIRECTORY_SEPARATOR, $newFileName);
$this->line('Copying '.$newFileName.' using current Cms theme...');
} else {
$this->line('Copying '.$newFileName.'...');
}
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
$this->info('Finished publishing this module.');
} else {
$this->info('You cancelled publishing this module');
}
} else {
$this->line('This module may have been installed via composer, if so please run:');
$this->info('php artisan vendor:publish');
$this->line('You will need to ensure that you copy the published views of this module in the default theme into your custom themes.');
}
} | php | public function handle()
{
if (is_dir(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes')) {
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes');
$this->line("\n");
foreach ($files as $file) {
if ($file->getType() == 'file') {
$this->line(str_replace(base_path(Config::get('cms.module-directory')).DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes'.DIRECTORY_SEPARATOR, '', $file));
}
}
$this->info("\n\nThese files will be published\n");
$result = $this->confirm('Are you sure you want to overwrite any files of the same name?');
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(base_path(Config::get('cms.module-directory').DIRECTORY_SEPARATOR.ucfirst($this->argument('module')).DIRECTORY_SEPARATOR.'Publishes'.DIRECTORY_SEPARATOR), '', $file);
if (strstr($newFileName, 'resources'.DIRECTORY_SEPARATOR.'themes'.DIRECTORY_SEPARATOR)) {
$newFileName = str_replace(DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR.Config::get('cms.frontend-theme').DIRECTORY_SEPARATOR, $newFileName);
$this->line('Copying '.$newFileName.' using current Cms theme...');
} else {
$this->line('Copying '.$newFileName.'...');
}
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
$this->info('Finished publishing this module.');
} else {
$this->info('You cancelled publishing this module');
}
} else {
$this->line('This module may have been installed via composer, if so please run:');
$this->info('php artisan vendor:publish');
$this->line('You will need to ensure that you copy the published views of this module in the default theme into your custom themes.');
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"is_dir",
"(",
"base_path",
"(",
"Config",
"::",
"get",
"(",
"'cms.module-directory'",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'module'",
")",... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ModulePublish.php#L31-L74 |
GrafiteInc/CMS | src/Middleware/GrafiteCmsAnalytics.php | GrafiteCmsAnalytics.handle | public function handle($request, Closure $next)
{
if (!$request->ajax()) {
app(AnalyticsService::class)->log($request);
}
return $next($request);
} | php | public function handle($request, Closure $next)
{
if (!$request->ajax()) {
app(AnalyticsService::class)->log($request);
}
return $next($request);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"if",
"(",
"!",
"$",
"request",
"->",
"ajax",
"(",
")",
")",
"{",
"app",
"(",
"AnalyticsService",
"::",
"class",
")",
"->",
"log",
"(",
"$",
"request",
")",... | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Middleware/GrafiteCmsAnalytics.php#L18-L25 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.index | public function index(Request $request)
{
$input = $request->all();
$result = $this->repository->paginated();
return view('cms::modules.images.index')
->with('images', $result)
->with('pagination', $result->render());
} | php | public function index(Request $request)
{
$input = $request->all();
$result = $this->repository->paginated();
return view('cms::modules.images.index')
->with('images', $result)
->with('pagination', $result->render());
} | [
"public",
"function",
"index",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"input",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"repository",
"->",
"paginated",
"(",
")",
";",
"return",
"view",
"(",
"'... | Display a listing of the Images.
@param Request $request
@return Response | [
"Display",
"a",
"listing",
"of",
"the",
"Images",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L33-L42 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.store | public function store(Request $request)
{
try {
$validation = app(ValidationService::class)->check(['location' => 'required']);
if (!$validation['errors']) {
foreach ($request->input('location') as $image) {
$imageSaved = $this->repository->store([
'location' => $image,
'is_published' => $request->input('is_published'),
'tags' => $request->input('tags'),
]);
}
Cms::notification('Image saved successfully.', 'success');
if (!$imageSaved) {
Cms::notification('Image was not saved.', 'danger');
}
} else {
Cms::notification('Image could not be saved', 'danger');
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Image could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.images.index'));
} | php | public function store(Request $request)
{
try {
$validation = app(ValidationService::class)->check(['location' => 'required']);
if (!$validation['errors']) {
foreach ($request->input('location') as $image) {
$imageSaved = $this->repository->store([
'location' => $image,
'is_published' => $request->input('is_published'),
'tags' => $request->input('tags'),
]);
}
Cms::notification('Image saved successfully.', 'success');
if (!$imageSaved) {
Cms::notification('Image was not saved.', 'danger');
}
} else {
Cms::notification('Image could not be saved', 'danger');
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Image could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.images.index'));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"validation",
"=",
"app",
"(",
"ValidationService",
"::",
"class",
")",
"->",
"check",
"(",
"[",
"'location'",
"=>",
"'required'",
"]",
")",
";",
"if",
"(",
"!",
... | Store a newly created Images in storage.
@param ImagesRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Images",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L80-L108 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.upload | public function upload(Request $request)
{
$validation = app(ValidationService::class)->check([
'location' => ['required'],
]);
if (!$validation['errors']) {
$file = $request->file('location');
$fileSaved = app(FileService::class)->saveFile($file, 'public/images', [], true);
$fileSaved['name'] = CryptoService::encrypt($fileSaved['name']);
$fileSaved['mime'] = $file->getClientMimeType();
$fileSaved['size'] = $file->getClientSize();
$response = app(CmsResponseService::class)->apiResponse('success', $fileSaved);
} else {
$response = app(CmsResponseService::class)->apiErrorResponse($validation['errors'], $validation['inputs']);
}
return $response;
} | php | public function upload(Request $request)
{
$validation = app(ValidationService::class)->check([
'location' => ['required'],
]);
if (!$validation['errors']) {
$file = $request->file('location');
$fileSaved = app(FileService::class)->saveFile($file, 'public/images', [], true);
$fileSaved['name'] = CryptoService::encrypt($fileSaved['name']);
$fileSaved['mime'] = $file->getClientMimeType();
$fileSaved['size'] = $file->getClientSize();
$response = app(CmsResponseService::class)->apiResponse('success', $fileSaved);
} else {
$response = app(CmsResponseService::class)->apiErrorResponse($validation['errors'], $validation['inputs']);
}
return $response;
} | [
"public",
"function",
"upload",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"validation",
"=",
"app",
"(",
"ValidationService",
"::",
"class",
")",
"->",
"check",
"(",
"[",
"'location'",
"=>",
"[",
"'required'",
"]",
",",
"]",
")",
";",
"if",
"(",
... | Store a newly created Files in storage.
@param FileRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Files",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L117-L135 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.destroy | public function destroy($id)
{
$image = $this->repository->find($id);
if (is_file(storage_path($image->location))) {
Storage::delete($image->location);
} else {
Storage::disk(Config::get('cms.storage-location', 'local'))->delete($image->location);
}
if (empty($image)) {
Cms::notification('Image not found', 'warning');
return redirect(route($this->routeBase.'.images.index'));
}
$image->forgetCache();
$image->delete();
Cms::notification('Image deleted successfully.', 'success');
return redirect(route($this->routeBase.'.images.index'));
} | php | public function destroy($id)
{
$image = $this->repository->find($id);
if (is_file(storage_path($image->location))) {
Storage::delete($image->location);
} else {
Storage::disk(Config::get('cms.storage-location', 'local'))->delete($image->location);
}
if (empty($image)) {
Cms::notification('Image not found', 'warning');
return redirect(route($this->routeBase.'.images.index'));
}
$image->forgetCache();
$image->delete();
Cms::notification('Image deleted successfully.', 'success');
return redirect(route($this->routeBase.'.images.index'));
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_file",
"(",
"storage_path",
"(",
"$",
"image",
"->",
"location",
")",
")",
")",
... | Remove the specified Images from storage.
@param int $id
@return Response | [
"Remove",
"the",
"specified",
"Images",
"from",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L197-L219 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.bulkDelete | public function bulkDelete($ids)
{
$ids = explode('-', $ids);
foreach ($ids as $id) {
$image = $this->repository->find($id);
if (is_file(storage_path($image->location))) {
Storage::delete($image->location);
} else {
Storage::disk(Config::get('cms.storage-location', 'local'))->delete($image->location);
}
$image->delete();
}
Cms::notification('Bulk Image deletes completed successfully.', 'success');
return redirect(route($this->routeBase.'.images.index'));
} | php | public function bulkDelete($ids)
{
$ids = explode('-', $ids);
foreach ($ids as $id) {
$image = $this->repository->find($id);
if (is_file(storage_path($image->location))) {
Storage::delete($image->location);
} else {
Storage::disk(Config::get('cms.storage-location', 'local'))->delete($image->location);
}
$image->delete();
}
Cms::notification('Bulk Image deletes completed successfully.', 'success');
return redirect(route($this->routeBase.'.images.index'));
} | [
"public",
"function",
"bulkDelete",
"(",
"$",
"ids",
")",
"{",
"$",
"ids",
"=",
"explode",
"(",
"'-'",
",",
"$",
"ids",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"repository",
"->",
"... | Bulk image delete
@param string $ids
@return Redirect | [
"Bulk",
"image",
"delete"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L228-L247 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.apiList | public function apiList(Request $request)
{
if (config('cms.api-key') != $request->header('cms')) {
return app(CmsResponseService::class)->apiResponse('error', []);
}
$images = $this->repository->apiPrepared();
return app(CmsResponseService::class)->apiResponse('success', $images);
} | php | public function apiList(Request $request)
{
if (config('cms.api-key') != $request->header('cms')) {
return app(CmsResponseService::class)->apiResponse('error', []);
}
$images = $this->repository->apiPrepared();
return app(CmsResponseService::class)->apiResponse('success', $images);
} | [
"public",
"function",
"apiList",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"config",
"(",
"'cms.api-key'",
")",
"!=",
"$",
"request",
"->",
"header",
"(",
"'cms'",
")",
")",
"{",
"return",
"app",
"(",
"CmsResponseService",
"::",
"class",
")",
... | Display the specified Images.
@return Response | [
"Display",
"the",
"specified",
"Images",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L260-L269 |
GrafiteInc/CMS | src/Controllers/ImagesController.php | ImagesController.apiStore | public function apiStore(Request $request)
{
$image = $this->repository->apiStore($request->all());
return app(CmsResponseService::class)->apiResponse('success', $image);
} | php | public function apiStore(Request $request)
{
$image = $this->repository->apiStore($request->all());
return app(CmsResponseService::class)->apiResponse('success', $image);
} | [
"public",
"function",
"apiStore",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"repository",
"->",
"apiStore",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"return",
"app",
"(",
"CmsResponseService",
"::",
"c... | Store a newly created Images in storage.
@param ImagesRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Images",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/ImagesController.php#L278-L283 |
GrafiteInc/CMS | src/Services/FileService.php | FileService.getFileClass | public function getFileClass($file)
{
$sections = explode(DIRECTORY_SEPARATOR, $file);
$fileName = $sections[count($sections) - 1];
$class = str_replace('.php', '', $fileName);
return $class;
} | php | public function getFileClass($file)
{
$sections = explode(DIRECTORY_SEPARATOR, $file);
$fileName = $sections[count($sections) - 1];
$class = str_replace('.php', '', $fileName);
return $class;
} | [
"public",
"function",
"getFileClass",
"(",
"$",
"file",
")",
"{",
"$",
"sections",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"file",
")",
";",
"$",
"fileName",
"=",
"$",
"sections",
"[",
"count",
"(",
"$",
"sections",
")",
"-",
"1",
"]",
... | Generate a name from the file path.
@param string $file File path
@return string | [
"Generate",
"a",
"name",
"from",
"the",
"file",
"path",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/FileService.php#L22-L30 |
GrafiteInc/CMS | src/Services/FileService.php | FileService.saveClone | public function saveClone($fileName, $directory = '', $fileTypes = [])
{
$fileInfo = pathinfo($fileName);
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $fileInfo['extension'];
$newFileName = md5(rand(1111, 9999).time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('cms.storage-location', 'local'))->put($directory.$newFileName.'.'.$extension, file_get_contents($fileName));
return [
'original' => basename($fileName),
'name' => $directory.$newFileName.'.'.$extension,
];
} | php | public function saveClone($fileName, $directory = '', $fileTypes = [])
{
$fileInfo = pathinfo($fileName);
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $fileInfo['extension'];
$newFileName = md5(rand(1111, 9999).time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('cms.storage-location', 'local'))->put($directory.$newFileName.'.'.$extension, file_get_contents($fileName));
return [
'original' => basename($fileName),
'name' => $directory.$newFileName.'.'.$extension,
];
} | [
"public",
"function",
"saveClone",
"(",
"$",
"fileName",
",",
"$",
"directory",
"=",
"''",
",",
"$",
"fileTypes",
"=",
"[",
"]",
")",
"{",
"$",
"fileInfo",
"=",
"pathinfo",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"directory",
... | Saves File.
@param string $fileName File input name
@param string $location Storage location
@return array | [
"Saves",
"File",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/FileService.php#L40-L64 |
GrafiteInc/CMS | src/Services/FileService.php | FileService.saveFile | public function saveFile($fileName, $directory = '', $fileTypes = [], $isImage = false)
{
if (is_object($fileName)) {
$file = $fileName;
$originalName = $file->getClientOriginalName();
} else {
$file = Request::file($fileName);
$originalName = false;
}
if (is_null($file)) {
return false;
}
if (File::size($file) > Config::get('cms.max-file-upload-size', 6291456)) {
throw new Exception('This file is too large', 1);
}
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $file->getClientOriginalExtension();
$newFileName = md5(rand(1111, 9999).time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('cms.storage-location', 'local'))->put($directory.$newFileName.'.'.$extension, File::get($file));
// Resize images only
if ($isImage) {
$storage = Storage::disk(Config::get('cms.storage-location', 'local'));
$image = $storage->get($directory.$newFileName.'.'.$extension);
$image = InterventionImage::make($image)->resize(config('cms.max-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
$imageResized = $image->stream();
$storage->delete($directory.$newFileName.'.'.$extension);
$storage->put($directory.$newFileName.'.'.$extension, $imageResized->__toString());
}
return [
'original' => $originalName ?: $file->getFilename().'.'.$extension,
'name' => $directory.$newFileName.'.'.$extension,
];
} | php | public function saveFile($fileName, $directory = '', $fileTypes = [], $isImage = false)
{
if (is_object($fileName)) {
$file = $fileName;
$originalName = $file->getClientOriginalName();
} else {
$file = Request::file($fileName);
$originalName = false;
}
if (is_null($file)) {
return false;
}
if (File::size($file) > Config::get('cms.max-file-upload-size', 6291456)) {
throw new Exception('This file is too large', 1);
}
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $file->getClientOriginalExtension();
$newFileName = md5(rand(1111, 9999).time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('cms.storage-location', 'local'))->put($directory.$newFileName.'.'.$extension, File::get($file));
// Resize images only
if ($isImage) {
$storage = Storage::disk(Config::get('cms.storage-location', 'local'));
$image = $storage->get($directory.$newFileName.'.'.$extension);
$image = InterventionImage::make($image)->resize(config('cms.max-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
$imageResized = $image->stream();
$storage->delete($directory.$newFileName.'.'.$extension);
$storage->put($directory.$newFileName.'.'.$extension, $imageResized->__toString());
}
return [
'original' => $originalName ?: $file->getFilename().'.'.$extension,
'name' => $directory.$newFileName.'.'.$extension,
];
} | [
"public",
"function",
"saveFile",
"(",
"$",
"fileName",
",",
"$",
"directory",
"=",
"''",
",",
"$",
"fileTypes",
"=",
"[",
"]",
",",
"$",
"isImage",
"=",
"false",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"file",
... | Saves File.
@param string $fileName File input name
@param string $location Storage location
@return array | [
"Saves",
"File",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/FileService.php#L83-L136 |
GrafiteInc/CMS | src/Services/Traits/ModuleServiceTrait.php | ModuleServiceTrait.getModule | public function getModule()
{
$module = request()->segment(1);
$defaultModules = config('cms.active-core-modules');
$extraModules = array_keys(config('cms.modules', []));
$modules = array_merge($defaultModules, $extraModules);
if (in_array($module, $modules)) {
return str_singular($module);
}
return 'page';
} | php | public function getModule()
{
$module = request()->segment(1);
$defaultModules = config('cms.active-core-modules');
$extraModules = array_keys(config('cms.modules', []));
$modules = array_merge($defaultModules, $extraModules);
if (in_array($module, $modules)) {
return str_singular($module);
}
return 'page';
} | [
"public",
"function",
"getModule",
"(",
")",
"{",
"$",
"module",
"=",
"request",
"(",
")",
"->",
"segment",
"(",
"1",
")",
";",
"$",
"defaultModules",
"=",
"config",
"(",
"'cms.active-core-modules'",
")",
";",
"$",
"extraModules",
"=",
"array_keys",
"(",
... | Determine the module based on URL
@return string | [
"Determine",
"the",
"module",
"based",
"on",
"URL"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/ModuleServiceTrait.php#L15-L29 |
GrafiteInc/CMS | src/Services/Traits/ModuleServiceTrait.php | ModuleServiceTrait.moduleAsset | public function moduleAsset($module, $path, $contentType = 'null')
{
$assetPath = base_path(Config::get('cms.module-directory').'/'.ucfirst($module).'/Assets/'.$path);
if (!is_file($assetPath)) {
$assetPath = config('cms.modules.'.$module.'.asset_path').'/'.$path;
}
return url(config('cms.backend-route-prefix', 'cms').'/asset/'.CryptoServiceFacade::url_encode($assetPath).'/'.CryptoServiceFacade::url_encode($contentType).'/?isModule=true');
} | php | public function moduleAsset($module, $path, $contentType = 'null')
{
$assetPath = base_path(Config::get('cms.module-directory').'/'.ucfirst($module).'/Assets/'.$path);
if (!is_file($assetPath)) {
$assetPath = config('cms.modules.'.$module.'.asset_path').'/'.$path;
}
return url(config('cms.backend-route-prefix', 'cms').'/asset/'.CryptoServiceFacade::url_encode($assetPath).'/'.CryptoServiceFacade::url_encode($contentType).'/?isModule=true');
} | [
"public",
"function",
"moduleAsset",
"(",
"$",
"module",
",",
"$",
"path",
",",
"$",
"contentType",
"=",
"'null'",
")",
"{",
"$",
"assetPath",
"=",
"base_path",
"(",
"Config",
"::",
"get",
"(",
"'cms.module-directory'",
")",
".",
"'/'",
".",
"ucfirst",
"... | Module Assets.
@param string $module Module name
@param string $path Asset path
@param string $contentType Content type
@return string | [
"Module",
"Assets",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/ModuleServiceTrait.php#L40-L49 |
GrafiteInc/CMS | src/Services/Traits/ModuleServiceTrait.php | ModuleServiceTrait.moduleConfig | public function moduleConfig($module, $path)
{
$configArray = @include base_path(Config::get('cms.module-directory').'/'.ucfirst($module).'/config.php');
if (!$configArray) {
return config('cms.modules.'.$module.'.'.$path);
}
return self::assignArrayByPath($configArray, $path);
} | php | public function moduleConfig($module, $path)
{
$configArray = @include base_path(Config::get('cms.module-directory').'/'.ucfirst($module).'/config.php');
if (!$configArray) {
return config('cms.modules.'.$module.'.'.$path);
}
return self::assignArrayByPath($configArray, $path);
} | [
"public",
"function",
"moduleConfig",
"(",
"$",
"module",
",",
"$",
"path",
")",
"{",
"$",
"configArray",
"=",
"@",
"include",
"base_path",
"(",
"Config",
"::",
"get",
"(",
"'cms.module-directory'",
")",
".",
"'/'",
".",
"ucfirst",
"(",
"$",
"module",
")... | Module Config.
@param string $module Module name
@param string $path Asset path
@param string $contentType Content type
@return string | [
"Module",
"Config",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/ModuleServiceTrait.php#L60-L69 |
GrafiteInc/CMS | src/Services/Traits/ModuleServiceTrait.php | ModuleServiceTrait.moduleLinks | public function moduleLinks($ignoredModules = [], $linkClass = 'nav-link', $listClass = 'nav-item')
{
$links = '';
$modules = config('cms.modules', []);
foreach ($ignoredModules as $ignoredModule) {
if (in_array(strtolower($ignoredModule), array_keys($modules))) {
unset($modules[strtolower($ignoredModule)]);
}
}
foreach ($modules as $module => $config) {
$link = $module;
if (isset($config['url'])) {
$link = $config['url'];
}
$displayLink = true;
if (isset($config['is_ignored_in_menu']) && $config['is_ignored_in_menu']) {
$displayLink = false;
}
if ($displayLink) {
$links .= '<li class="'.$listClass.'"><a class="'.$linkClass.'" href="'.url($link).'">'.ucfirst($link).'</a></li>';
}
}
return $links;
} | php | public function moduleLinks($ignoredModules = [], $linkClass = 'nav-link', $listClass = 'nav-item')
{
$links = '';
$modules = config('cms.modules', []);
foreach ($ignoredModules as $ignoredModule) {
if (in_array(strtolower($ignoredModule), array_keys($modules))) {
unset($modules[strtolower($ignoredModule)]);
}
}
foreach ($modules as $module => $config) {
$link = $module;
if (isset($config['url'])) {
$link = $config['url'];
}
$displayLink = true;
if (isset($config['is_ignored_in_menu']) && $config['is_ignored_in_menu']) {
$displayLink = false;
}
if ($displayLink) {
$links .= '<li class="'.$listClass.'"><a class="'.$linkClass.'" href="'.url($link).'">'.ucfirst($link).'</a></li>';
}
}
return $links;
} | [
"public",
"function",
"moduleLinks",
"(",
"$",
"ignoredModules",
"=",
"[",
"]",
",",
"$",
"linkClass",
"=",
"'nav-link'",
",",
"$",
"listClass",
"=",
"'nav-item'",
")",
"{",
"$",
"links",
"=",
"''",
";",
"$",
"modules",
"=",
"config",
"(",
"'cms.modules'... | Module Links.
@param array $ignoredModules A list of ignored links
@return string | [
"Module",
"Links",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/ModuleServiceTrait.php#L78-L109 |
GrafiteInc/CMS | src/Repositories/TranslationRepository.php | TranslationRepository.createOrUpdate | public function createOrUpdate($entityId, $entityType, $lang, $payload)
{
$translation = $this->model->firstOrCreate([
'entity_id' => $entityId,
'entity_type' => $entityType,
'language' => $lang,
]);
unset($payload['_method']);
unset($payload['_token']);
$translation->entity_data = json_encode($payload);
return $translation->save();
} | php | public function createOrUpdate($entityId, $entityType, $lang, $payload)
{
$translation = $this->model->firstOrCreate([
'entity_id' => $entityId,
'entity_type' => $entityType,
'language' => $lang,
]);
unset($payload['_method']);
unset($payload['_token']);
$translation->entity_data = json_encode($payload);
return $translation->save();
} | [
"public",
"function",
"createOrUpdate",
"(",
"$",
"entityId",
",",
"$",
"entityType",
",",
"$",
"lang",
",",
"$",
"payload",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"model",
"->",
"firstOrCreate",
"(",
"[",
"'entity_id'",
"=>",
"$",
"entity... | Create or Update an entry
@param integer $entityId
@param string $entityType
@param string $lang
@param array $payload
@return boolean | [
"Create",
"or",
"Update",
"an",
"entry"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/TranslationRepository.php#L27-L41 |
GrafiteInc/CMS | src/Repositories/TranslationRepository.php | TranslationRepository.findByUrl | public function findByUrl($url, $type)
{
$item = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"url":"'.$url.'"%')->first();
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) {
return $item->data;
}
return null;
} | php | public function findByUrl($url, $type)
{
$item = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"url":"'.$url.'"%')->first();
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) {
return $item->data;
}
return null;
} | [
"public",
"function",
"findByUrl",
"(",
"$",
"url",
",",
"$",
"type",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"type",
")",
"->",
"where",
"(",
"'entity_data'",
",",
"'LIKE'",
",",
"'%\"ur... | Find by URL
@param string $url
@param string $type
@return Object|null | [
"Find",
"by",
"URL"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/TranslationRepository.php#L51-L60 |
GrafiteInc/CMS | src/Repositories/TranslationRepository.php | TranslationRepository.findByEntityId | public function findByEntityId($entityId, $entityType)
{
$item = $this->model->where('entity_type', $entityType)->where('entity_id', $entityId)->first();
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) {
return $item->data;
}
return null;
} | php | public function findByEntityId($entityId, $entityType)
{
$item = $this->model->where('entity_type', $entityType)->where('entity_id', $entityId)->first();
if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) {
return $item->data;
}
return null;
} | [
"public",
"function",
"findByEntityId",
"(",
"$",
"entityId",
",",
"$",
"entityType",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"entityType",
")",
"->",
"where",
"(",
"'entity_id'",
",",
"$",
... | Find an entity by its Id
@param integer $entityId
@param string $entityType
@return Object|null | [
"Find",
"an",
"entity",
"by",
"its",
"Id"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/TranslationRepository.php#L70-L79 |
GrafiteInc/CMS | src/Repositories/TranslationRepository.php | TranslationRepository.getEntitiesByTypeAndLang | public function getEntitiesByTypeAndLang($lang, $type)
{
$entities = collect();
$collection = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"lang":"'.$lang.'"%')->get();
foreach ($collection as $item) {
$instance = app($item->type)->attributes = $item->data;
$entities->push($instance);
}
return $entities;
} | php | public function getEntitiesByTypeAndLang($lang, $type)
{
$entities = collect();
$collection = $this->model->where('entity_type', $type)->where('entity_data', 'LIKE', '%"lang":"'.$lang.'"%')->get();
foreach ($collection as $item) {
$instance = app($item->type)->attributes = $item->data;
$entities->push($instance);
}
return $entities;
} | [
"public",
"function",
"getEntitiesByTypeAndLang",
"(",
"$",
"lang",
",",
"$",
"type",
")",
"{",
"$",
"entities",
"=",
"collect",
"(",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"'entity_type'",
",",
"$",
"type",
"... | Get entities by type and language
@param string $lang
@param string $type
@return Illuminate\Support\Collection | [
"Get",
"entities",
"by",
"type",
"and",
"language"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/TranslationRepository.php#L89-L100 |
GrafiteInc/CMS | src/Services/PageService.php | PageService.getPagesAsOptions | public function getPagesAsOptions()
{
$pages = [];
$publishedPages = $this->repo->all();
foreach ($publishedPages as $page) {
$pages[$page->title] = $page->id;
}
return $pages;
} | php | public function getPagesAsOptions()
{
$pages = [];
$publishedPages = $this->repo->all();
foreach ($publishedPages as $page) {
$pages[$page->title] = $page->id;
}
return $pages;
} | [
"public",
"function",
"getPagesAsOptions",
"(",
")",
"{",
"$",
"pages",
"=",
"[",
"]",
";",
"$",
"publishedPages",
"=",
"$",
"this",
"->",
"repo",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"publishedPages",
"as",
"$",
"page",
")",
"{",
"$",
... | Get pages as options
@return array | [
"Get",
"pages",
"as",
"options"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/PageService.php#L21-L31 |
GrafiteInc/CMS | src/Models/Image.php | Image.getUrlAttribute | public function getUrlAttribute()
{
if ($this->isLocalFile()) {
return url(str_replace('public/', 'storage/', $this->location));
} elseif ($this->fileExists()) {
return $this->getS3Image();
}
return $this->lostImage();
} | php | public function getUrlAttribute()
{
if ($this->isLocalFile()) {
return url(str_replace('public/', 'storage/', $this->location));
} elseif ($this->fileExists()) {
return $this->getS3Image();
}
return $this->lostImage();
} | [
"public",
"function",
"getUrlAttribute",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLocalFile",
"(",
")",
")",
"{",
"return",
"url",
"(",
"str_replace",
"(",
"'public/'",
",",
"'storage/'",
",",
"$",
"this",
"->",
"location",
")",
")",
";",
"}",
... | Get the images url location.
@param string $value
@return string | [
"Get",
"the",
"images",
"url",
"location",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L60-L69 |
GrafiteInc/CMS | src/Models/Image.php | Image.getS3Image | public function getS3Image()
{
$url = Storage::disk(Config::get('cms.storage-location', 'local'))->url($this->location);
if (!is_null(config('cms.cloudfront'))) {
$url = str_replace(config('filesystems.disks.s3.bucket').'.s3.'.config('filesystems.disks.s3.region').'.amazonaws.com', config('cms.cloudfront'), $url);
}
return $url;
} | php | public function getS3Image()
{
$url = Storage::disk(Config::get('cms.storage-location', 'local'))->url($this->location);
if (!is_null(config('cms.cloudfront'))) {
$url = str_replace(config('filesystems.disks.s3.bucket').'.s3.'.config('filesystems.disks.s3.region').'.amazonaws.com', config('cms.cloudfront'), $url);
}
return $url;
} | [
"public",
"function",
"getS3Image",
"(",
")",
"{",
"$",
"url",
"=",
"Storage",
"::",
"disk",
"(",
"Config",
"::",
"get",
"(",
"'cms.storage-location'",
",",
"'local'",
")",
")",
"->",
"url",
"(",
"$",
"this",
"->",
"location",
")",
";",
"if",
"(",
"!... | Get an S3 image
@return string | [
"Get",
"an",
"S3",
"image"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L76-L85 |
GrafiteInc/CMS | src/Models/Image.php | Image.remember | public function remember($attribute, $closure)
{
$key = $attribute.'_'.$this->location;
if (!Cache::has($key)) {
$result = $closure();
Cache::forever($key, $result);
}
return Cache::get($key);
} | php | public function remember($attribute, $closure)
{
$key = $attribute.'_'.$this->location;
if (!Cache::has($key)) {
$result = $closure();
Cache::forever($key, $result);
}
return Cache::get($key);
} | [
"public",
"function",
"remember",
"(",
"$",
"attribute",
",",
"$",
"closure",
")",
"{",
"$",
"key",
"=",
"$",
"attribute",
".",
"'_'",
".",
"$",
"this",
"->",
"location",
";",
"if",
"(",
"!",
"Cache",
"::",
"has",
"(",
"$",
"key",
")",
")",
"{",
... | Simple caching tool
@param string $attribute
@param Clousre $closure
@return mixed | [
"Simple",
"caching",
"tool"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L119-L129 |
GrafiteInc/CMS | src/Models/Image.php | Image.forgetCache | public function forgetCache()
{
foreach (['url', 'js_url'] as $attribute) {
$key = $attribute.'_'.$this->location;
Cache::forget($key);
}
} | php | public function forgetCache()
{
foreach (['url', 'js_url'] as $attribute) {
$key = $attribute.'_'.$this->location;
Cache::forget($key);
}
} | [
"public",
"function",
"forgetCache",
"(",
")",
"{",
"foreach",
"(",
"[",
"'url'",
",",
"'js_url'",
"]",
"as",
"$",
"attribute",
")",
"{",
"$",
"key",
"=",
"$",
"attribute",
".",
"'_'",
".",
"$",
"this",
"->",
"location",
";",
"Cache",
"::",
"forget",... | Forget the current Image caches | [
"Forget",
"the",
"current",
"Image",
"caches"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L134-L140 |
GrafiteInc/CMS | src/Models/Image.php | Image.isLocalFile | private function isLocalFile()
{
try {
if (file_exists(storage_path('app/'.$this->location))) {
return true;
}
} catch (Exception $e) {
Log::debug('Could not find the image');
return false;
}
return false;
} | php | private function isLocalFile()
{
try {
if (file_exists(storage_path('app/'.$this->location))) {
return true;
}
} catch (Exception $e) {
Log::debug('Could not find the image');
return false;
}
return false;
} | [
"private",
"function",
"isLocalFile",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"file_exists",
"(",
"storage_path",
"(",
"'app/'",
".",
"$",
"this",
"->",
"location",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e... | Check the location of the file.
@return bool | [
"Check",
"the",
"location",
"of",
"the",
"file",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L147-L160 |
GrafiteInc/CMS | src/Models/Image.php | Image.lostImage | public function lostImage()
{
$imagePath = app(AssetService::class)->generateImage('File Not Found');
$image = InterventionImage::make($imagePath)->resize(config('cms.preview-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
return (string) $image->encode('data-url');
} | php | public function lostImage()
{
$imagePath = app(AssetService::class)->generateImage('File Not Found');
$image = InterventionImage::make($imagePath)->resize(config('cms.preview-image-size', 800), null, function ($constraint) {
$constraint->aspectRatio();
});
return (string) $image->encode('data-url');
} | [
"public",
"function",
"lostImage",
"(",
")",
"{",
"$",
"imagePath",
"=",
"app",
"(",
"AssetService",
"::",
"class",
")",
"->",
"generateImage",
"(",
"'File Not Found'",
")",
";",
"$",
"image",
"=",
"InterventionImage",
"::",
"make",
"(",
"$",
"imagePath",
... | Staged image if none are found
@return string | [
"Staged",
"image",
"if",
"none",
"are",
"found"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/Image.php#L177-L186 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/FaqController.php | FaqController.all | public function all()
{
$faqs = $this->repository->published();
if (empty($faqs)) {
abort(404);
}
return view('cms-frontend::faqs.all')->with('faqs', $faqs);
} | php | public function all()
{
$faqs = $this->repository->published();
if (empty($faqs)) {
abort(404);
}
return view('cms-frontend::faqs.all')->with('faqs', $faqs);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"faqs",
"=",
"$",
"this",
"->",
"repository",
"->",
"published",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"faqs",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"return",
"view",
"(",
"'c... | Display all Faq entries.
@param int $id
@return Response | [
"Display",
"all",
"Faq",
"entries",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/FaqController.php#L28-L37 |
GrafiteInc/CMS | src/Controllers/FAQController.php | FAQController.update | public function update($id, FAQRequest $request)
{
$faq = $this->repository->find($id);
if (empty($faq)) {
Cms::notification('FAQ not found', 'warning');
return redirect(route($this->routeBase.'.faqs.index'));
}
$validation = app(ValidationService::class)->check(FAQ::$rules);
if (!$validation['errors']) {
$faq = $this->repository->update($faq, $request->all());
Cms::notification('FAQ updated successfully.', 'success');
if (!$faq) {
Cms::notification('FAQ could not be saved.', 'warning');
}
} else {
return $validation['redirect'];
}
return redirect(URL::previous());
} | php | public function update($id, FAQRequest $request)
{
$faq = $this->repository->find($id);
if (empty($faq)) {
Cms::notification('FAQ not found', 'warning');
return redirect(route($this->routeBase.'.faqs.index'));
}
$validation = app(ValidationService::class)->check(FAQ::$rules);
if (!$validation['errors']) {
$faq = $this->repository->update($faq, $request->all());
Cms::notification('FAQ updated successfully.', 'success');
if (!$faq) {
Cms::notification('FAQ could not be saved.', 'warning');
}
} else {
return $validation['redirect'];
}
return redirect(URL::previous());
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"FAQRequest",
"$",
"request",
")",
"{",
"$",
"faq",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"faq",
")",
")",
"{",
"Cms",
":... | Update the specified FAQ in storage.
@param int $id
@param FAQRequest $request
@return Response | [
"Update",
"the",
"specified",
"FAQ",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FAQController.php#L118-L142 |
GrafiteInc/CMS | src/Controllers/FAQController.php | FAQController.destroy | public function destroy($id)
{
$faq = $this->repository->find($id);
if (empty($faq)) {
Cms::notification('FAQ not found', 'warning');
return redirect(route($this->routeBase.'.faqs.index'));
}
$faq->delete();
Cms::notification('FAQ deleted successfully.', 'success');
return redirect(route($this->routeBase.'.faqs.index'));
} | php | public function destroy($id)
{
$faq = $this->repository->find($id);
if (empty($faq)) {
Cms::notification('FAQ not found', 'warning');
return redirect(route($this->routeBase.'.faqs.index'));
}
$faq->delete();
Cms::notification('FAQ deleted successfully.', 'success');
return redirect(route($this->routeBase.'.faqs.index'));
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"faq",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"faq",
")",
")",
"{",
"Cms",
"::",
"notification",
"(",
"'FAQ not f... | Remove the specified FAQ from storage.
@param int $id
@return Response | [
"Remove",
"the",
"specified",
"FAQ",
"from",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/FAQController.php#L151-L166 |
GrafiteInc/CMS | src/Console/ThemeGenerate.php | ThemeGenerate.handle | public function handle()
{
$name = $this->argument('name');
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(__DIR__.'/../PublishedAssets/Theme');
$this->line("\n");
foreach ($files as $file) {
$this->line(str_replace(__DIR__.'/../PublishedAssets/Theme/', '', str_replace('themeTemplate', strtolower($name), $file)));
}
$this->info("\n\nThese files will be generated\n");
$result = $this->confirm('Are you sure you want to generate this theme?');
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(__DIR__.'/../PublishedAssets/Theme', '', $file);
$newFileName = str_replace('themeTemplate', strtolower($name), $newFileName);
$this->line('Copying '.$newFileName.'...');
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
$sass = file_get_contents(base_path('resources/themes/'.strtolower($name).'/assets/sass/_theme.scss'));
$sassRepairs = str_replace('themeTemplate', strtolower($name), $sass);
file_put_contents(base_path('resources/themes/'.strtolower($name).'/assets/sass/_theme.scss'), $sassRepairs);
$layout = file_get_contents(base_path('resources/themes/'.strtolower($name).'/layout/master.blade.php'));
$layoutRepairs = str_replace('themeTemplate', strtolower($name), $layout);
file_put_contents(base_path('resources/themes/'.strtolower($name).'/layout/master.blade.php'), $layoutRepairs);
$this->info('Finished generating your theme');
$this->line("\n");
$this->info('Please add this to your gulpfile.js in the scripts elixir:');
$this->comment('../../themes/'.strtolower($name).'/assets/js/theme.js');
$this->line("\n");
$this->info('Please add this to your app.scss:');
$this->comment('@import "resources/themes/'.strtolower($name).'/assets/sass/_theme.scss"');
} else {
$this->info('Nothing has been changed or added');
}
} | php | public function handle()
{
$name = $this->argument('name');
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(__DIR__.'/../PublishedAssets/Theme');
$this->line("\n");
foreach ($files as $file) {
$this->line(str_replace(__DIR__.'/../PublishedAssets/Theme/', '', str_replace('themeTemplate', strtolower($name), $file)));
}
$this->info("\n\nThese files will be generated\n");
$result = $this->confirm('Are you sure you want to generate this theme?');
if ($result) {
foreach ($files as $file) {
$newFileName = str_replace(__DIR__.'/../PublishedAssets/Theme', '', $file);
$newFileName = str_replace('themeTemplate', strtolower($name), $newFileName);
$this->line('Copying '.$newFileName.'...');
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
$sass = file_get_contents(base_path('resources/themes/'.strtolower($name).'/assets/sass/_theme.scss'));
$sassRepairs = str_replace('themeTemplate', strtolower($name), $sass);
file_put_contents(base_path('resources/themes/'.strtolower($name).'/assets/sass/_theme.scss'), $sassRepairs);
$layout = file_get_contents(base_path('resources/themes/'.strtolower($name).'/layout/master.blade.php'));
$layoutRepairs = str_replace('themeTemplate', strtolower($name), $layout);
file_put_contents(base_path('resources/themes/'.strtolower($name).'/layout/master.blade.php'), $layoutRepairs);
$this->info('Finished generating your theme');
$this->line("\n");
$this->info('Please add this to your gulpfile.js in the scripts elixir:');
$this->comment('../../themes/'.strtolower($name).'/assets/js/theme.js');
$this->line("\n");
$this->info('Please add this to your app.scss:');
$this->comment('@import "resources/themes/'.strtolower($name).'/assets/sass/_theme.scss"');
} else {
$this->info('Nothing has been changed or added');
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
";",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fileSystem",
"->",
"allFiles",
"(",
"__DIR__... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ThemeGenerate.php#L29-L76 |
GrafiteInc/CMS | src/Controllers/PagesController.php | PagesController.update | public function update($id, PagesRequest $request)
{
$pages = $this->repository->find($id);
if (empty($pages)) {
Cms::notification('Page not found', 'warning');
return redirect(route($this->routeBase.'.pages.index'));
}
$pages = $this->repository->update($pages, $request->all());
Cms::notification('Page updated successfully.', 'success');
if (!$pages) {
Cms::notification('Page could not be saved.', 'warning');
}
return redirect(url()->previous());
} | php | public function update($id, PagesRequest $request)
{
$pages = $this->repository->find($id);
if (empty($pages)) {
Cms::notification('Page not found', 'warning');
return redirect(route($this->routeBase.'.pages.index'));
}
$pages = $this->repository->update($pages, $request->all());
Cms::notification('Page updated successfully.', 'success');
if (!$pages) {
Cms::notification('Page could not be saved.', 'warning');
}
return redirect(url()->previous());
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"PagesRequest",
"$",
"request",
")",
"{",
"$",
"pages",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"pages",
")",
")",
"{",
"Cms"... | Update the specified Pages in storage.
@param int $id
@param PagesRequest $request
@return Response | [
"Update",
"the",
"specified",
"Pages",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/PagesController.php#L117-L135 |
GrafiteInc/CMS | src/Controllers/PagesController.php | PagesController.history | public function history($id)
{
$page = $this->repository->find($id);
return view('cms::modules.pages.history')
->with('page', $page);
} | php | public function history($id)
{
$page = $this->repository->find($id);
return view('cms::modules.pages.history')
->with('page', $page);
} | [
"public",
"function",
"history",
"(",
"$",
"id",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"return",
"view",
"(",
"'cms::modules.pages.history'",
")",
"->",
"with",
"(",
"'page'",
",",
"$",
"... | Page history.
@param int $id
@return Response | [
"Page",
"history",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/PagesController.php#L168-L174 |
GrafiteInc/CMS | src/PublishedAssets/Middleware/GrafiteCmsApi.php | GrafiteCmsApi.handle | public function handle($request, Closure $next)
{
if (Config::get('cms.api-token') == $request->get('token')) {
return $next($request);
}
return response('Unauthorized.', 401);
} | php | public function handle($request, Closure $next)
{
if (Config::get('cms.api-token') == $request->get('token')) {
return $next($request);
}
return response('Unauthorized.', 401);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"if",
"(",
"Config",
"::",
"get",
"(",
"'cms.api-token'",
")",
"==",
"$",
"request",
"->",
"get",
"(",
"'token'",
")",
")",
"{",
"return",
"$",
"next",
"(",
... | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Middleware/GrafiteCmsApi.php#L18-L25 |
GrafiteInc/CMS | src/Controllers/MenuController.php | MenuController.store | public function store(Request $request)
{
try {
$validation = app(ValidationService::class)->check(Menu::$rules);
if (!$validation['errors']) {
$menu = $this->repository->store($request->all());
Cms::notification('Menu saved successfully.', 'success');
if (!$menu) {
Cms::notification('Menu could not be saved.', 'danger');
}
} else {
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Menu could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$menu->id]));
} | php | public function store(Request $request)
{
try {
$validation = app(ValidationService::class)->check(Menu::$rules);
if (!$validation['errors']) {
$menu = $this->repository->store($request->all());
Cms::notification('Menu saved successfully.', 'success');
if (!$menu) {
Cms::notification('Menu could not be saved.', 'danger');
}
} else {
return $validation['redirect'];
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Menu could not be saved.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$menu->id]));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"validation",
"=",
"app",
"(",
"ValidationService",
"::",
"class",
")",
"->",
"check",
"(",
"Menu",
"::",
"$",
"rules",
")",
";",
"if",
"(",
"!",
"$",
"validati... | Store a newly created Menu in storage.
@param MenuRequest $request
@return Response | [
"Store",
"a",
"newly",
"created",
"Menu",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/MenuController.php#L77-L97 |
GrafiteInc/CMS | src/Controllers/MenuController.php | MenuController.edit | public function edit($id)
{
$menu = $this->repository->find($id);
if (empty($menu)) {
Cms::notification('Menu not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$links = $this->linkRepository->getLinksByMenu($menu->id);
return view('cms::modules.menus.edit')->with('menu', $menu)->with('links', $links);
} | php | public function edit($id)
{
$menu = $this->repository->find($id);
if (empty($menu)) {
Cms::notification('Menu not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$links = $this->linkRepository->getLinksByMenu($menu->id);
return view('cms::modules.menus.edit')->with('menu', $menu)->with('links', $links);
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"menu",
")",
")",
"{",
"Cms",
"::",
"notification",
"(",
"'Menu not f... | Show the form for editing the specified Menu.
@param int $id
@return Response | [
"Show",
"the",
"form",
"for",
"editing",
"the",
"specified",
"Menu",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/MenuController.php#L106-L119 |
GrafiteInc/CMS | src/Controllers/MenuController.php | MenuController.update | public function update($id, MenuRequest $request)
{
try {
$menu = $this->repository->find($id);
if (empty($menu)) {
Cms::notification('Menu not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$menu = $this->repository->update($menu, $request->all());
Cms::notification('Menu updated successfully.', 'success');
if (!$menu) {
Cms::notification('Menu could not be updated.', 'danger');
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Menu could not be updated.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$id]));
} | php | public function update($id, MenuRequest $request)
{
try {
$menu = $this->repository->find($id);
if (empty($menu)) {
Cms::notification('Menu not found', 'warning');
return redirect(route($this->routeBase.'.menus.index'));
}
$menu = $this->repository->update($menu, $request->all());
Cms::notification('Menu updated successfully.', 'success');
if (!$menu) {
Cms::notification('Menu could not be updated.', 'danger');
}
} catch (Exception $e) {
Cms::notification($e->getMessage() ?: 'Menu could not be updated.', 'danger');
}
return redirect(route($this->routeBase.'.menus.edit', [$id]));
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"MenuRequest",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"menu",
")",
")",
... | Update the specified Menu in storage.
@param int $id
@param MenuRequest $request
@return Response | [
"Update",
"the",
"specified",
"Menu",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/MenuController.php#L129-L151 |
GrafiteInc/CMS | src/Controllers/MenuController.php | MenuController.setOrder | public function setOrder($id, Request $request)
{
$menu = $this->repository->find($id);
$result = $this->repository->setOrder($menu, $request->except('_token'));
return app(CmsResponseService::class)->apiResponse('success', $result);
} | php | public function setOrder($id, Request $request)
{
$menu = $this->repository->find($id);
$result = $this->repository->setOrder($menu, $request->except('_token'));
return app(CmsResponseService::class)->apiResponse('success', $result);
} | [
"public",
"function",
"setOrder",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"repository",
"->",
"setOr... | Set the order
@return Response | [
"Set",
"the",
"order"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/MenuController.php#L189-L195 |
GrafiteInc/CMS | src/Services/Traits/MenuServiceTrait.php | MenuServiceTrait.menu | public function menu($slug, $view = null, $class = '')
{
$pageRepository = app(PageRepository::class);
$menu = app(MenuRepository::class)->getBySlug($slug);
if (!$menu) {
return '';
}
$links = app(LinkRepository::class)->getLinksByMenu($menu->id);
$order = json_decode($menu->order);
// Sort the links by the order from the menu
$links = $this->sortByKeys($links, $order);
$response = '';
$processedLinks = [];
foreach ($links as $key => $link) {
if ($link->external) {
if (config('app.locale') != config('cms.default-language', $this->config('cms.default-language'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.$link->external_url.'">'.$link->translation(config('app.locale'))->name.'</a>';
} else {
$processedLinks[] = '<a class="'.$class.'" href="'.$link->external_url.'">'.$link->name.'</a>';
}
} else {
$page = $pageRepository->find($link->page_id);
// if the page is published
if ($page && $page->is_published && $page->published_at <= Carbon::now(config('app.timezone'))) {
if (config('app.locale') === config('cms.default-language', $this->config('cms.default-language'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.url('page/'.$page->url)."\">$link->name</a>";
} elseif (config('app.locale') != config('cms.default-language', $this->config('cms.default-language'))) {
// if the page has a translation
if ($page->translation(config('app.locale'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.url('page/'.$page->translation(config('app.locale'))->data->url).'">'.$link->translation(config('app.locale'))->name.'</a>';
}
}
} else {
unset($links[$key]);
}
}
}
if (!is_null($view)) {
$response = view($view, ['links' => $links, 'processed_links' => $processedLinks]);
}
if (Gate::allows('cms', Auth::user())) {
if (is_null($view)) {
$response = implode(',', $processedLinks);
}
$response .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/menus/'.$menu->id.'/edit').'" class="btn btn-sm ml-2 btn-outline-secondary"><span class="fa fa-edit"></span> Edit</a>';
}
return $response;
} | php | public function menu($slug, $view = null, $class = '')
{
$pageRepository = app(PageRepository::class);
$menu = app(MenuRepository::class)->getBySlug($slug);
if (!$menu) {
return '';
}
$links = app(LinkRepository::class)->getLinksByMenu($menu->id);
$order = json_decode($menu->order);
// Sort the links by the order from the menu
$links = $this->sortByKeys($links, $order);
$response = '';
$processedLinks = [];
foreach ($links as $key => $link) {
if ($link->external) {
if (config('app.locale') != config('cms.default-language', $this->config('cms.default-language'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.$link->external_url.'">'.$link->translation(config('app.locale'))->name.'</a>';
} else {
$processedLinks[] = '<a class="'.$class.'" href="'.$link->external_url.'">'.$link->name.'</a>';
}
} else {
$page = $pageRepository->find($link->page_id);
// if the page is published
if ($page && $page->is_published && $page->published_at <= Carbon::now(config('app.timezone'))) {
if (config('app.locale') === config('cms.default-language', $this->config('cms.default-language'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.url('page/'.$page->url)."\">$link->name</a>";
} elseif (config('app.locale') != config('cms.default-language', $this->config('cms.default-language'))) {
// if the page has a translation
if ($page->translation(config('app.locale'))) {
$processedLinks[] = '<a class="'.$class.'" href="'.url('page/'.$page->translation(config('app.locale'))->data->url).'">'.$link->translation(config('app.locale'))->name.'</a>';
}
}
} else {
unset($links[$key]);
}
}
}
if (!is_null($view)) {
$response = view($view, ['links' => $links, 'processed_links' => $processedLinks]);
}
if (Gate::allows('cms', Auth::user())) {
if (is_null($view)) {
$response = implode(',', $processedLinks);
}
$response .= '<a href="'.url(config('cms.backend-route-prefix', 'cms').'/menus/'.$menu->id.'/edit').'" class="btn btn-sm ml-2 btn-outline-secondary"><span class="fa fa-edit"></span> Edit</a>';
}
return $response;
} | [
"public",
"function",
"menu",
"(",
"$",
"slug",
",",
"$",
"view",
"=",
"null",
",",
"$",
"class",
"=",
"''",
")",
"{",
"$",
"pageRepository",
"=",
"app",
"(",
"PageRepository",
"::",
"class",
")",
";",
"$",
"menu",
"=",
"app",
"(",
"MenuRepository",
... | Get a view.
@param string $slug
@param View $view
@return string | [
"Get",
"a",
"view",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/MenuServiceTrait.php#L37-L89 |
GrafiteInc/CMS | src/Services/Traits/MenuServiceTrait.php | MenuServiceTrait.sortByKeys | public function sortByKeys($links, $keys)
{
if (! is_null($keys)) {
$links = $links->keyBy('id');
$sortedLinks = [];
foreach ($keys as $key) {
$sortedLinks[] = $links[$key];
}
return collect($sortedLinks);
}
return $links;
} | php | public function sortByKeys($links, $keys)
{
if (! is_null($keys)) {
$links = $links->keyBy('id');
$sortedLinks = [];
foreach ($keys as $key) {
$sortedLinks[] = $links[$key];
}
return collect($sortedLinks);
}
return $links;
} | [
"public",
"function",
"sortByKeys",
"(",
"$",
"links",
",",
"$",
"keys",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"links",
"=",
"$",
"links",
"->",
"keyBy",
"(",
"'id'",
")",
";",
"$",
"sortedLinks",
"=",
"[",
... | Sort by an existing set of keys
@param collection $links
@param array $keys
@return collection | [
"Sort",
"by",
"an",
"existing",
"set",
"of",
"keys"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/Traits/MenuServiceTrait.php#L99-L113 |
GrafiteInc/CMS | src/Controllers/WidgetsController.php | WidgetsController.update | public function update($id, WidgetRequest $request)
{
$widgets = $this->repository->find($id);
if (empty($widgets)) {
Cms::notification('Widgets not found', 'warning');
return redirect(route($this->routeBase.'.widgets.index'));
}
$widgets = $this->repository->update($widgets, $request->all());
Cms::notification('Widgets updated successfully.', 'success');
return redirect(url()->previous());
} | php | public function update($id, WidgetRequest $request)
{
$widgets = $this->repository->find($id);
if (empty($widgets)) {
Cms::notification('Widgets not found', 'warning');
return redirect(route($this->routeBase.'.widgets.index'));
}
$widgets = $this->repository->update($widgets, $request->all());
Cms::notification('Widgets updated successfully.', 'success');
return redirect(url()->previous());
} | [
"public",
"function",
"update",
"(",
"$",
"id",
",",
"WidgetRequest",
"$",
"request",
")",
"{",
"$",
"widgets",
"=",
"$",
"this",
"->",
"repository",
"->",
"find",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"widgets",
")",
")",
"{",
... | Update the specified Widgets in storage.
@param int $id
@param WidgetRequest $request
@return Response | [
"Update",
"the",
"specified",
"Widgets",
"in",
"storage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Controllers/WidgetsController.php#L114-L129 |
GrafiteInc/CMS | src/Providers/CmsServiceProvider.php | CmsServiceProvider.register | public function register()
{
$loader = AliasLoader::getInstance();
$loader->alias('Cms', \Grafite\Cms\Facades\CmsServiceFacade::class);
$loader->alias('PageService', \Grafite\Cms\Facades\PageServiceFacade::class);
$loader->alias('EventService', \Grafite\Cms\Facades\EventServiceFacade::class);
$loader->alias('CryptoService', \Grafite\Cms\Facades\CryptoServiceFacade::class);
$loader->alias('ModuleService', \Grafite\Cms\Facades\ModuleServiceFacade::class);
$loader->alias('BlogService', \Grafite\Cms\Facades\BlogServiceFacade::class);
$loader->alias('FileService', \Grafite\Cms\Services\FileService::class);
$this->app->bind('CmsService', function ($app) {
return new CmsService();
});
$this->app->bind('PageService', function ($app) {
return new PageService();
});
$this->app->bind('EventService', function ($app) {
return App::make(EventService::class);
});
$this->app->bind('CryptoService', function ($app) {
return new CryptoService();
});
$this->app->bind('ModuleService', function ($app) {
return new ModuleService();
});
$this->app->bind('BlogService', function ($app) {
return new BlogService();
});
} | php | public function register()
{
$loader = AliasLoader::getInstance();
$loader->alias('Cms', \Grafite\Cms\Facades\CmsServiceFacade::class);
$loader->alias('PageService', \Grafite\Cms\Facades\PageServiceFacade::class);
$loader->alias('EventService', \Grafite\Cms\Facades\EventServiceFacade::class);
$loader->alias('CryptoService', \Grafite\Cms\Facades\CryptoServiceFacade::class);
$loader->alias('ModuleService', \Grafite\Cms\Facades\ModuleServiceFacade::class);
$loader->alias('BlogService', \Grafite\Cms\Facades\BlogServiceFacade::class);
$loader->alias('FileService', \Grafite\Cms\Services\FileService::class);
$this->app->bind('CmsService', function ($app) {
return new CmsService();
});
$this->app->bind('PageService', function ($app) {
return new PageService();
});
$this->app->bind('EventService', function ($app) {
return App::make(EventService::class);
});
$this->app->bind('CryptoService', function ($app) {
return new CryptoService();
});
$this->app->bind('ModuleService', function ($app) {
return new ModuleService();
});
$this->app->bind('BlogService', function ($app) {
return new BlogService();
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"loader",
"=",
"AliasLoader",
"::",
"getInstance",
"(",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Cms'",
",",
"\\",
"Grafite",
"\\",
"Cms",
"\\",
"Facades",
"\\",
"CmsServiceFacade",
"::",
"class... | Register the services. | [
"Register",
"the",
"services",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Providers/CmsServiceProvider.php#L20-L55 |
GrafiteInc/CMS | src/Models/CmsModel.php | CmsModel.afterSaved | public function afterSaved($payload)
{
if (!request()->is('cms/revert/*') && !request()->is('cms/rollback/*/*')) {
unset($payload->attributes['created_at']);
unset($payload->attributes['updated_at']);
unset($payload->original['created_at']);
unset($payload->original['updated_at']);
if ($payload->attributes != $payload->original) {
Archive::create([
'token' => md5(time()),
'entity_id' => $payload->attributes['id'],
'entity_type' => get_class($payload),
'entity_data' => json_encode($payload->attributes),
]);
Log::info(get_class($payload).' #'.$payload->attributes['id'].' was archived');
}
}
} | php | public function afterSaved($payload)
{
if (!request()->is('cms/revert/*') && !request()->is('cms/rollback/*/*')) {
unset($payload->attributes['created_at']);
unset($payload->attributes['updated_at']);
unset($payload->original['created_at']);
unset($payload->original['updated_at']);
if ($payload->attributes != $payload->original) {
Archive::create([
'token' => md5(time()),
'entity_id' => $payload->attributes['id'],
'entity_type' => get_class($payload),
'entity_data' => json_encode($payload->attributes),
]);
Log::info(get_class($payload).' #'.$payload->attributes['id'].' was archived');
}
}
} | [
"public",
"function",
"afterSaved",
"(",
"$",
"payload",
")",
"{",
"if",
"(",
"!",
"request",
"(",
")",
"->",
"is",
"(",
"'cms/revert/*'",
")",
"&&",
"!",
"request",
"(",
")",
"->",
"is",
"(",
"'cms/rollback/*/*'",
")",
")",
"{",
"unset",
"(",
"$",
... | After the item is saved to the database.
@param object $payload | [
"After",
"the",
"item",
"is",
"saved",
"to",
"the",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/CmsModel.php#L44-L62 |
GrafiteInc/CMS | src/Models/CmsModel.php | CmsModel.beingDeleted | public function beingDeleted($payload)
{
$type = get_class($payload);
$id = $payload->id;
Translation::where('entity_id', $id)->where('entity_type', $type)->delete();
Archive::where('entity_id', $id)->where('entity_type', $type)->delete();
Archive::where('entity_type', 'Grafite\Cms\Models\Translation')
->where('entity_data', 'LIKE', '%"entity_id":'.$id.'%')
->where('entity_data', 'LIKE', '%"entity_type":"'.$type.'"%')
->delete();
if ($type == 'Grafite\Cms\Models\Page') {
Link::where('page_id', $id)->delete();
}
} | php | public function beingDeleted($payload)
{
$type = get_class($payload);
$id = $payload->id;
Translation::where('entity_id', $id)->where('entity_type', $type)->delete();
Archive::where('entity_id', $id)->where('entity_type', $type)->delete();
Archive::where('entity_type', 'Grafite\Cms\Models\Translation')
->where('entity_data', 'LIKE', '%"entity_id":'.$id.'%')
->where('entity_data', 'LIKE', '%"entity_type":"'.$type.'"%')
->delete();
if ($type == 'Grafite\Cms\Models\Page') {
Link::where('page_id', $id)->delete();
}
} | [
"public",
"function",
"beingDeleted",
"(",
"$",
"payload",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"payload",
")",
";",
"$",
"id",
"=",
"$",
"payload",
"->",
"id",
";",
"Translation",
"::",
"where",
"(",
"'entity_id'",
",",
"$",
"id",
")",... | When the item is being deleted.
@param object $payload | [
"When",
"the",
"item",
"is",
"being",
"deleted",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/CmsModel.php#L69-L85 |
GrafiteInc/CMS | src/Models/CmsModel.php | CmsModel.block | public function block($slug)
{
$block = $this->findABlock($slug);
if (!$block) {
$this->update([
'blocks' => json_encode(array_merge($this->blocks, [ $slug => '' ]))
]);
}
return $block;
} | php | public function block($slug)
{
$block = $this->findABlock($slug);
if (!$block) {
$this->update([
'blocks' => json_encode(array_merge($this->blocks, [ $slug => '' ]))
]);
}
return $block;
} | [
"public",
"function",
"block",
"(",
"$",
"slug",
")",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"findABlock",
"(",
"$",
"slug",
")",
";",
"if",
"(",
"!",
"$",
"block",
")",
"{",
"$",
"this",
"->",
"update",
"(",
"[",
"'blocks'",
"=>",
"json_enco... | A method for getting / setting blocks
@param string $slug
@return string | [
"A",
"method",
"for",
"getting",
"/",
"setting",
"blocks"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/CmsModel.php#L93-L104 |
GrafiteInc/CMS | src/Models/CmsModel.php | CmsModel.findABlock | public function findABlock($slug)
{
if (isset($this->blocks[$slug])) {
return $this->blocks[$slug];
}
return false;
} | php | public function findABlock($slug)
{
if (isset($this->blocks[$slug])) {
return $this->blocks[$slug];
}
return false;
} | [
"public",
"function",
"findABlock",
"(",
"$",
"slug",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"blocks",
"[",
"$",
"slug",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"blocks",
"[",
"$",
"slug",
"]",
";",
"}",
"return",
"false",... | Find a block based on slug
@param string $slug
@return string | [
"Find",
"a",
"block",
"based",
"on",
"slug"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Models/CmsModel.php#L112-L119 |
GrafiteInc/CMS | src/Repositories/ImageRepository.php | ImageRepository.getImagesByTag | public function getImagesByTag($tag = null)
{
$images = $this->model->orderBy('created_at', 'desc')->where('is_published', 1);
if (!is_null($tag)) {
$images->where('tags', 'LIKE', '%'.$tag.'%');
}
return $images;
} | php | public function getImagesByTag($tag = null)
{
$images = $this->model->orderBy('created_at', 'desc')->where('is_published', 1);
if (!is_null($tag)) {
$images->where('tags', 'LIKE', '%'.$tag.'%');
}
return $images;
} | [
"public",
"function",
"getImagesByTag",
"(",
"$",
"tag",
"=",
"null",
")",
"{",
"$",
"images",
"=",
"$",
"this",
"->",
"model",
"->",
"orderBy",
"(",
"'created_at'",
",",
"'desc'",
")",
"->",
"where",
"(",
"'is_published'",
",",
"1",
")",
";",
"if",
... | Returns all Images for the API.
@return \Illuminate\Database\Eloquent\Collection|static[] | [
"Returns",
"all",
"Images",
"for",
"the",
"API",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/ImageRepository.php#L46-L55 |
GrafiteInc/CMS | src/Repositories/ImageRepository.php | ImageRepository.allTags | public function allTags()
{
$tags = [];
$images = $this->model->orderBy('created_at', 'desc')->where('is_published', 1)->get();
foreach ($images as $image) {
foreach (explode(',', $image->tags) as $tag) {
if ($tag > '') {
array_push($tags, $tag);
}
}
}
return array_unique($tags);
} | php | public function allTags()
{
$tags = [];
$images = $this->model->orderBy('created_at', 'desc')->where('is_published', 1)->get();
foreach ($images as $image) {
foreach (explode(',', $image->tags) as $tag) {
if ($tag > '') {
array_push($tags, $tag);
}
}
}
return array_unique($tags);
} | [
"public",
"function",
"allTags",
"(",
")",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"$",
"images",
"=",
"$",
"this",
"->",
"model",
"->",
"orderBy",
"(",
"'created_at'",
",",
"'desc'",
")",
"->",
"where",
"(",
"'is_published'",
",",
"1",
")",
"->",
"g... | Returns all Images tags.
@return \Illuminate\Database\Eloquent\Collection|static[] | [
"Returns",
"all",
"Images",
"tags",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/ImageRepository.php#L62-L76 |
GrafiteInc/CMS | src/Repositories/ImageRepository.php | ImageRepository.apiStore | public function apiStore($input)
{
$savedFile = app(FileService::class)->saveClone($input['location'], 'public/images');
if (!$savedFile) {
return false;
}
$input['is_published'] = 1;
$input['location'] = $savedFile['name'];
$input['storage_location'] = config('cms.storage-location');
$input['original_name'] = $savedFile['original'];
$image = $this->model->create($input);
$image->setCaches();
return $image;
} | php | public function apiStore($input)
{
$savedFile = app(FileService::class)->saveClone($input['location'], 'public/images');
if (!$savedFile) {
return false;
}
$input['is_published'] = 1;
$input['location'] = $savedFile['name'];
$input['storage_location'] = config('cms.storage-location');
$input['original_name'] = $savedFile['original'];
$image = $this->model->create($input);
$image->setCaches();
return $image;
} | [
"public",
"function",
"apiStore",
"(",
"$",
"input",
")",
"{",
"$",
"savedFile",
"=",
"app",
"(",
"FileService",
"::",
"class",
")",
"->",
"saveClone",
"(",
"$",
"input",
"[",
"'location'",
"]",
",",
"'public/images'",
")",
";",
"if",
"(",
"!",
"$",
... | Stores Images into database.
@param array $input
@return Images | [
"Stores",
"Images",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/ImageRepository.php#L85-L102 |
GrafiteInc/CMS | src/Repositories/ImageRepository.php | ImageRepository.store | public function store($input)
{
$savedFile = $input['location'];
if (!$savedFile) {
Cms::notification('Image could not be saved.', 'danger');
return false;
}
if (!isset($input['is_published'])) {
$input['is_published'] = 0;
} else {
$input['is_published'] = 1;
}
$input['location'] = CryptoService::decrypt($savedFile['name']);
$input['storage_location'] = config('cms.storage-location');
$input['original_name'] = $savedFile['original'];
$image = $this->model->create($input);
$image->setCaches();
return $image;
} | php | public function store($input)
{
$savedFile = $input['location'];
if (!$savedFile) {
Cms::notification('Image could not be saved.', 'danger');
return false;
}
if (!isset($input['is_published'])) {
$input['is_published'] = 0;
} else {
$input['is_published'] = 1;
}
$input['location'] = CryptoService::decrypt($savedFile['name']);
$input['storage_location'] = config('cms.storage-location');
$input['original_name'] = $savedFile['original'];
$image = $this->model->create($input);
$image->setCaches();
return $image;
} | [
"public",
"function",
"store",
"(",
"$",
"input",
")",
"{",
"$",
"savedFile",
"=",
"$",
"input",
"[",
"'location'",
"]",
";",
"if",
"(",
"!",
"$",
"savedFile",
")",
"{",
"Cms",
"::",
"notification",
"(",
"'Image could not be saved.'",
",",
"'danger'",
")... | Stores Images into database.
@param array $input
@return Images | [
"Stores",
"Images",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/ImageRepository.php#L111-L135 |
GrafiteInc/CMS | src/Repositories/ImageRepository.php | ImageRepository.update | public function update($image, $input)
{
if (isset($input['location']) && !empty($input['location'])) {
$savedFile = app(FileService::class)->saveFile($input['location'], 'public/images', [], true);
if (!$savedFile) {
Cms::notification('Image could not be updated.', 'danger');
return false;
}
$input['location'] = $savedFile['name'];
$input['original_name'] = $savedFile['original'];
} else {
$input['location'] = $image->location;
}
if (!isset($input['is_published'])) {
$input['is_published'] = 0;
} else {
$input['is_published'] = 1;
}
$image->forgetCache();
$image->update($input);
$image->setCaches();
return $image;
} | php | public function update($image, $input)
{
if (isset($input['location']) && !empty($input['location'])) {
$savedFile = app(FileService::class)->saveFile($input['location'], 'public/images', [], true);
if (!$savedFile) {
Cms::notification('Image could not be updated.', 'danger');
return false;
}
$input['location'] = $savedFile['name'];
$input['original_name'] = $savedFile['original'];
} else {
$input['location'] = $image->location;
}
if (!isset($input['is_published'])) {
$input['is_published'] = 0;
} else {
$input['is_published'] = 1;
}
$image->forgetCache();
$image->update($input);
$image->setCaches();
return $image;
} | [
"public",
"function",
"update",
"(",
"$",
"image",
",",
"$",
"input",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input",
"[",
"'location'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"input",
"[",
"'location'",
"]",
")",
")",
"{",
"$",
"savedFile",
"=... | Updates Images
@param Images $images
@param array $input
@return Images | [
"Updates",
"Images"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/ImageRepository.php#L145-L175 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/BlogController.php | BlogController.all | public function all()
{
$blogs = $this->repository->published();
$tags = $this->repository->allTags();
if (empty($blogs)) {
abort(404);
}
return view('cms-frontend::blog.all')
->with('tags', $tags)
->with('blogs', $blogs);
} | php | public function all()
{
$blogs = $this->repository->published();
$tags = $this->repository->allTags();
if (empty($blogs)) {
abort(404);
}
return view('cms-frontend::blog.all')
->with('tags', $tags)
->with('blogs', $blogs);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"blogs",
"=",
"$",
"this",
"->",
"repository",
"->",
"published",
"(",
")",
";",
"$",
"tags",
"=",
"$",
"this",
"->",
"repository",
"->",
"allTags",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"bl... | Display all Blog entries.
@param int $id
@return Response | [
"Display",
"all",
"Blog",
"entries",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/BlogController.php#L28-L40 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/BlogController.php | BlogController.tag | public function tag($tag)
{
$blogs = $this->repository->tags($tag);
$tags = $this->repository->allTags();
if (empty($blogs)) {
abort(404);
}
return view('cms-frontend::blog.all')
->with('tags', $tags)
->with('blogs', $blogs);
} | php | public function tag($tag)
{
$blogs = $this->repository->tags($tag);
$tags = $this->repository->allTags();
if (empty($blogs)) {
abort(404);
}
return view('cms-frontend::blog.all')
->with('tags', $tags)
->with('blogs', $blogs);
} | [
"public",
"function",
"tag",
"(",
"$",
"tag",
")",
"{",
"$",
"blogs",
"=",
"$",
"this",
"->",
"repository",
"->",
"tags",
"(",
"$",
"tag",
")",
";",
"$",
"tags",
"=",
"$",
"this",
"->",
"repository",
"->",
"allTags",
"(",
")",
";",
"if",
"(",
"... | Display all Blog entries.
@param int $id
@return Response | [
"Display",
"all",
"Blog",
"entries",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/BlogController.php#L49-L61 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/BlogController.php | BlogController.show | public function show($url)
{
$blog = $this->repository->findBlogsByURL($url);
if (empty($blog)) {
abort(404);
}
return view('cms-frontend::blog.'.$blog->template)->with('blog', $blog);
} | php | public function show($url)
{
$blog = $this->repository->findBlogsByURL($url);
if (empty($blog)) {
abort(404);
}
return view('cms-frontend::blog.'.$blog->template)->with('blog', $blog);
} | [
"public",
"function",
"show",
"(",
"$",
"url",
")",
"{",
"$",
"blog",
"=",
"$",
"this",
"->",
"repository",
"->",
"findBlogsByURL",
"(",
"$",
"url",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"blog",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"... | Display the specified Blog.
@param int $id
@return Response | [
"Display",
"the",
"specified",
"Blog",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/BlogController.php#L70-L79 |
GrafiteInc/CMS | src/Console/Keys.php | Keys.handle | public function handle()
{
$keyOne = sha1(str_random(12));
$keyTwo = sha1(str_random(40));
$content = file_get_contents(base_path('.env'));
if (strpos($content, 'CMS_API_TOKEN=') > -1) {
$content = str_replace('CMS_API_TOKEN=', 'CMS_API_TOKEN='.$keyOne, $content);
} else {
$content .= "\nCMS_API_TOKEN=".$keyOne;
}
if (strpos($content, 'CMS_API_KEY=') > -1) {
$content = str_replace('CMS_API_KEY=', 'CMS_API_KEY='.$keyTwo, $content)."\n";
} else {
$content .= "\nCMS_API_KEY=".$keyTwo."\n";
}
file_put_contents(base_path('.env'), $content);
$this->info('Your keys have been generated.');
} | php | public function handle()
{
$keyOne = sha1(str_random(12));
$keyTwo = sha1(str_random(40));
$content = file_get_contents(base_path('.env'));
if (strpos($content, 'CMS_API_TOKEN=') > -1) {
$content = str_replace('CMS_API_TOKEN=', 'CMS_API_TOKEN='.$keyOne, $content);
} else {
$content .= "\nCMS_API_TOKEN=".$keyOne;
}
if (strpos($content, 'CMS_API_KEY=') > -1) {
$content = str_replace('CMS_API_KEY=', 'CMS_API_KEY='.$keyTwo, $content)."\n";
} else {
$content .= "\nCMS_API_KEY=".$keyTwo."\n";
}
file_put_contents(base_path('.env'), $content);
$this->info('Your keys have been generated.');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"keyOne",
"=",
"sha1",
"(",
"str_random",
"(",
"12",
")",
")",
";",
"$",
"keyTwo",
"=",
"sha1",
"(",
"str_random",
"(",
"40",
")",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"base_path... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/Keys.php#L28-L50 |
GrafiteInc/CMS | src/Services/CmsResponseService.php | CmsResponseService.apiErrorResponse | public function apiErrorResponse($errors, $inputs)
{
$message = [];
foreach ($inputs as $key => $value) {
if (!isset($errors[$key])) {
$message[$key] = [
'status' => 'valid',
'value' => $value,
];
} else {
$message[$key] = [
'status' => 'invalid',
'error' => $errors[$key],
'value' => $value,
];
}
}
return Response::json(['status' => 'error', 'data' => $message]);
} | php | public function apiErrorResponse($errors, $inputs)
{
$message = [];
foreach ($inputs as $key => $value) {
if (!isset($errors[$key])) {
$message[$key] = [
'status' => 'valid',
'value' => $value,
];
} else {
$message[$key] = [
'status' => 'invalid',
'error' => $errors[$key],
'value' => $value,
];
}
}
return Response::json(['status' => 'error', 'data' => $message]);
} | [
"public",
"function",
"apiErrorResponse",
"(",
"$",
"errors",
",",
"$",
"inputs",
")",
"{",
"$",
"message",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"inputs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"err... | Generate an API error response.
@param array $errors Validation errors
@param array $inputs Input values
@return Response | [
"Generate",
"an",
"API",
"error",
"response",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Services/CmsResponseService.php#L30-L49 |
GrafiteInc/CMS | src/Console/Setup.php | Setup.handle | public function handle()
{
Artisan::call('vendor:publish', [
'--provider' => 'Grafite\Cms\GrafiteCmsProvider',
'--force' => true,
]);
Artisan::call('vendor:publish', [
'--provider' => 'Grafite\Builder\GrafiteBuilderProvider',
'--force' => true,
]);
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter');
$this->line('Copying routes...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/routes', base_path('routes'));
$this->line('Copying config...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/config', base_path('config'));
$this->line('Copying app/Http...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Http', app_path('Http'));
$this->line('Copying app/Events...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Events', app_path('Events'));
$this->line('Copying app/Listeners...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Listeners', app_path('Listeners'));
$this->line('Copying app/Notifications...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Notifications', app_path('Notifications'));
$this->line('Copying app/Models...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Models', app_path('Models'));
$this->line('Copying app/Services...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Services', app_path('Services'));
$this->line('Copying database...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/database', base_path('database'));
$this->line('Copying resources/views...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/resources/views', base_path('resources/views'));
$this->line('Copying tests...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/tests', base_path('tests'));
$this->fileManager();
$this->info('Publishing theme');
Artisan::call('theme:publish', [
'name' => 'default',
'--forced' => true,
]);
$dbReady = $this->confirm('Please confirm that you have a database set and configured in your .env file.');
if ($dbReady) {
$this->info('Migrating database');
Artisan::call('migrate:refresh', [
'--force' => true,
]);
$this->info('Setting roles');
if (!Role::where('name', 'member')->first()) {
Role::create([
'name' => 'member',
'label' => 'Member',
]);
Role::create([
'name' => 'admin',
'label' => 'Admin',
]);
}
$this->info('Creating default account');
$service = app(UserService::class);
if (!User::where('name', 'admin')->first()) {
$user = User::create([
'name' => 'Admin',
'email' => 'admin@example.com',
'password' => bcrypt('admin'),
]);
}
$service->create($user, 'admin', 'admin', false);
$this->info('Finished setting up your site with Grafite CMS!');
$this->line('You can now login with the following username and password:');
$this->comment('admin@example.com');
$this->comment('admin');
}
$this->info('Please add to your app.scss:');
$this->comment("@import '../../themes/default/assets/sass/_theme.scss';");
$this->info('Please run:');
$this->comment('npm install');
$this->info('and:');
$this->comment('npm run dev');
} | php | public function handle()
{
Artisan::call('vendor:publish', [
'--provider' => 'Grafite\Cms\GrafiteCmsProvider',
'--force' => true,
]);
Artisan::call('vendor:publish', [
'--provider' => 'Grafite\Builder\GrafiteBuilderProvider',
'--force' => true,
]);
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter');
$this->line('Copying routes...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/routes', base_path('routes'));
$this->line('Copying config...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/config', base_path('config'));
$this->line('Copying app/Http...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Http', app_path('Http'));
$this->line('Copying app/Events...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Events', app_path('Events'));
$this->line('Copying app/Listeners...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Listeners', app_path('Listeners'));
$this->line('Copying app/Notifications...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Notifications', app_path('Notifications'));
$this->line('Copying app/Models...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Models', app_path('Models'));
$this->line('Copying app/Services...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/app/Services', app_path('Services'));
$this->line('Copying database...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/database', base_path('database'));
$this->line('Copying resources/views...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/resources/views', base_path('resources/views'));
$this->line('Copying tests...');
$this->copyPreparedFiles(getcwd().'/vendor/grafite/builder/src/Packages/Starter/tests', base_path('tests'));
$this->fileManager();
$this->info('Publishing theme');
Artisan::call('theme:publish', [
'name' => 'default',
'--forced' => true,
]);
$dbReady = $this->confirm('Please confirm that you have a database set and configured in your .env file.');
if ($dbReady) {
$this->info('Migrating database');
Artisan::call('migrate:refresh', [
'--force' => true,
]);
$this->info('Setting roles');
if (!Role::where('name', 'member')->first()) {
Role::create([
'name' => 'member',
'label' => 'Member',
]);
Role::create([
'name' => 'admin',
'label' => 'Admin',
]);
}
$this->info('Creating default account');
$service = app(UserService::class);
if (!User::where('name', 'admin')->first()) {
$user = User::create([
'name' => 'Admin',
'email' => 'admin@example.com',
'password' => bcrypt('admin'),
]);
}
$service->create($user, 'admin', 'admin', false);
$this->info('Finished setting up your site with Grafite CMS!');
$this->line('You can now login with the following username and password:');
$this->comment('admin@example.com');
$this->comment('admin');
}
$this->info('Please add to your app.scss:');
$this->comment("@import '../../themes/default/assets/sass/_theme.scss';");
$this->info('Please run:');
$this->comment('npm install');
$this->info('and:');
$this->comment('npm run dev');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"Artisan",
"::",
"call",
"(",
"'vendor:publish'",
",",
"[",
"'--provider'",
"=>",
"'Grafite\\Cms\\GrafiteCmsProvider'",
",",
"'--force'",
"=>",
"true",
",",
"]",
")",
";",
"Artisan",
"::",
"call",
"(",
"'vendor:pu... | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/Setup.php#L37-L138 |
GrafiteInc/CMS | src/Console/Setup.php | Setup.fileManager | public function fileManager()
{
$files = [
base_path('config/auth.php'),
base_path('config/services.php'),
];
foreach ($files as $file) {
$contents = file_get_contents($file);
$contents = str_replace('App\User::class', 'App\Models\User::class', $contents);
file_put_contents($file, $contents);
}
// Route setup
$routeContents = file_get_contents(app_path('Providers/RouteServiceProvider.php'));
$routeContents = str_replace("->group(base_path('routes/web.php'));", "->group(function() { \n\t\t\trequire base_path('routes/web.php');\n\t\t\trequire base_path('routes/cms.php'); });", $routeContents);
file_put_contents(app_path('Providers/RouteServiceProvider.php'), $routeContents);
$routeToDashboardContents = file_get_contents(base_path('routes/web.php'));
$routeToDashboardContents = str_replace("Route::get('/dashboard', 'PagesController@dashboard');", "Route::get('/dashboard', function(){ return Redirect::to('cms/dashboard'); });", $routeToDashboardContents);
file_put_contents(base_path('routes/web.php'), $routeToDashboardContents);
// Kernel setup
$routeContents = file_get_contents(app_path('Http/Kernel.php'));
$routeContents = str_replace("'auth' => \App\Http\Middleware\Authenticate::class,", "'auth' => \App\Http\Middleware\Authenticate::class,\n\t\t'cms' => \App\Http\Middleware\GrafiteCms::class,\n\t\t'cms-api' => \App\Http\Middleware\GrafiteCmsApi::class,\n\t\t'cms-analytics' => \Grafite\Cms\Middleware\GrafiteCmsAnalytics::class,\n\t\t'cms-language' => \App\Http\Middleware\GrafiteCmsLanguage::class,\n\t\t'admin' => \App\Http\Middleware\Admin::class,\n\t\t'active' => \App\Http\Middleware\Active::class,", $routeContents);
file_put_contents(app_path('Http/Kernel.php'), $routeContents);
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(__DIR__.'/../PublishedAssets/Setup');
foreach ($files as $file) {
$newFileName = str_replace(__DIR__.'/../PublishedAssets/Setup', '', $file);
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
// AuthProviders
$authProviderContents = file_get_contents(app_path('Providers/AuthServiceProvider.php'));
$authProviderContents = str_replace('$this->registerPolicies();', "\$this->registerPolicies();\n\t\t\Gate::define('cms', function (\$user) {\n\t\t\treturn (\$user->roles->first()->name === 'admin');\n\t\t});\n\t\t\Gate::define('admin', function (\$user) {\n\t\t\treturn (\$user->roles->first()->name === 'admin');\n\t\t});", $authProviderContents);
file_put_contents(app_path('Providers/AuthServiceProvider.php'), $authProviderContents);
// Remove the teams
$this->dropDeadFiles();
/*
* --------------------------------------------------------------------------
* Drop the team routes and the active middleware
* --------------------------------------------------------------------------
*/
$mainRoutes = file_get_contents(base_path('routes/web.php'));
$mainRoutes = str_replace("/*
|--------------------------------------------------------------------------
| Team Routes
|--------------------------------------------------------------------------
*/
Route::get('team/{name}', 'TeamController@showByName');
Route::resource('teams', 'TeamController', ['except' => ['show']]);
Route::post('teams/search', 'TeamController@search');
Route::post('teams/{id}/invite', 'TeamController@inviteMember');
Route::get('teams/{id}/remove/{userId}', 'TeamController@removeMember');", '', $mainRoutes);
$mainRoutes = str_replace("['auth', 'active']", "['auth']", $mainRoutes);
file_put_contents(base_path('routes/web.php'), $mainRoutes);
/*
* --------------------------------------------------------------------------
* Drop the activate by email notification
* --------------------------------------------------------------------------
*/
$activateUserEmail = file_get_contents(app_path('Notifications/ActivateUserEmail.php'));
$activateUserEmail = str_replace("'mail'", '', $activateUserEmail);
file_put_contents(app_path('Notifications/ActivateUserEmail.php'), $activateUserEmail);
/*
* --------------------------------------------------------------------------
* Clean up the user model
* --------------------------------------------------------------------------
*/
$userModel = file_get_contents(app_path('Models/User.php'));
$userModel = str_replace("/**
* Teams
*
* @return Relationship
*/
public function teams()
{
return \$this->belongsToMany(Team::class);
}
/**
* Team member
*
* @return boolean
*/
public function isTeamMember(\$id)
{
\$teams = array_column(\$this->teams->toArray(), 'id');
return array_search(\$id, \$teams) > -1;
}
/**
* Team admin
*
* @return boolean
*/
public function isTeamAdmin(\$id)
{
\$team = \$this->teams->find(\$id);
return (int)\$team->user_id === (int)\$this->id;
}", '', $userModel);
$userModel = str_replace("use App\Models\Team;", '', $userModel);
file_put_contents(app_path('Models/User.php'), $userModel);
$userService = file_get_contents(app_path('Services/UserService.php'));
$userService = str_replace('/*
|--------------------------------------------------------------------------
| Teams
|--------------------------------------------------------------------------
*/
public function joinTeam($teamId, $userId)
{
$team = $this->team->find($teamId);
$user = $this->model->find($userId);
$user->teams()->attach($team);
}
public function leaveTeam($teamId, $userId)
{
$team = $this->team->find($teamId);
$user = $this->model->find($userId);
$user->teams()->detach($team);
}
public function leaveAllTeams($userId)
{
$user = $this->model->find($userId);
$user->teams()->detach();
}', '', $userService);
$userService = str_replace('use App\Models\Team;', '', $userService);
$userService = str_replace('Team $team,', '', $userService);
$userService = str_replace('$this->team = $team;', '', $userService);
$userService = str_replace('$this->leaveAllTeams($id);', '', $userService);
file_put_contents(app_path('Services/UserService.php'), $userService);
$seed = file_get_contents(base_path('database/seeds/DatabaseSeeder.php'));
$seed = str_replace('$this->call(TeamTableSeeder::class);', '', $seed);
file_put_contents(base_path('database/seeds/DatabaseSeeder.php'), $seed);
$css = file_get_contents(base_path('resources/sass/app.scss'));
$css = str_replace('@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";', '@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";'."\n".'@import "resources/themes/default/assets/sass/_theme.scss";', $css);
file_put_contents(base_path('resources/sass/app.scss'), $css);
$composer = file_get_contents(base_path('composer.json'));
$composer = str_replace('"App\\": "app/",', '"App\\": "app/",'."\n".'"Cms\\Modules\\": "cms/Modules/",', $composer);
file_put_contents(base_path('composer.json'), $composer);
} | php | public function fileManager()
{
$files = [
base_path('config/auth.php'),
base_path('config/services.php'),
];
foreach ($files as $file) {
$contents = file_get_contents($file);
$contents = str_replace('App\User::class', 'App\Models\User::class', $contents);
file_put_contents($file, $contents);
}
// Route setup
$routeContents = file_get_contents(app_path('Providers/RouteServiceProvider.php'));
$routeContents = str_replace("->group(base_path('routes/web.php'));", "->group(function() { \n\t\t\trequire base_path('routes/web.php');\n\t\t\trequire base_path('routes/cms.php'); });", $routeContents);
file_put_contents(app_path('Providers/RouteServiceProvider.php'), $routeContents);
$routeToDashboardContents = file_get_contents(base_path('routes/web.php'));
$routeToDashboardContents = str_replace("Route::get('/dashboard', 'PagesController@dashboard');", "Route::get('/dashboard', function(){ return Redirect::to('cms/dashboard'); });", $routeToDashboardContents);
file_put_contents(base_path('routes/web.php'), $routeToDashboardContents);
// Kernel setup
$routeContents = file_get_contents(app_path('Http/Kernel.php'));
$routeContents = str_replace("'auth' => \App\Http\Middleware\Authenticate::class,", "'auth' => \App\Http\Middleware\Authenticate::class,\n\t\t'cms' => \App\Http\Middleware\GrafiteCms::class,\n\t\t'cms-api' => \App\Http\Middleware\GrafiteCmsApi::class,\n\t\t'cms-analytics' => \Grafite\Cms\Middleware\GrafiteCmsAnalytics::class,\n\t\t'cms-language' => \App\Http\Middleware\GrafiteCmsLanguage::class,\n\t\t'admin' => \App\Http\Middleware\Admin::class,\n\t\t'active' => \App\Http\Middleware\Active::class,", $routeContents);
file_put_contents(app_path('Http/Kernel.php'), $routeContents);
$fileSystem = new Filesystem();
$files = $fileSystem->allFiles(__DIR__.'/../PublishedAssets/Setup');
foreach ($files as $file) {
$newFileName = str_replace(__DIR__.'/../PublishedAssets/Setup', '', $file);
if (is_dir($file)) {
$fileSystem->copyDirectory($file, base_path($newFileName));
} else {
@mkdir(base_path(str_replace(basename($newFileName), '', $newFileName)), 0755, true);
$fileSystem->copy($file, base_path($newFileName));
}
}
// AuthProviders
$authProviderContents = file_get_contents(app_path('Providers/AuthServiceProvider.php'));
$authProviderContents = str_replace('$this->registerPolicies();', "\$this->registerPolicies();\n\t\t\Gate::define('cms', function (\$user) {\n\t\t\treturn (\$user->roles->first()->name === 'admin');\n\t\t});\n\t\t\Gate::define('admin', function (\$user) {\n\t\t\treturn (\$user->roles->first()->name === 'admin');\n\t\t});", $authProviderContents);
file_put_contents(app_path('Providers/AuthServiceProvider.php'), $authProviderContents);
// Remove the teams
$this->dropDeadFiles();
/*
* --------------------------------------------------------------------------
* Drop the team routes and the active middleware
* --------------------------------------------------------------------------
*/
$mainRoutes = file_get_contents(base_path('routes/web.php'));
$mainRoutes = str_replace("/*
|--------------------------------------------------------------------------
| Team Routes
|--------------------------------------------------------------------------
*/
Route::get('team/{name}', 'TeamController@showByName');
Route::resource('teams', 'TeamController', ['except' => ['show']]);
Route::post('teams/search', 'TeamController@search');
Route::post('teams/{id}/invite', 'TeamController@inviteMember');
Route::get('teams/{id}/remove/{userId}', 'TeamController@removeMember');", '', $mainRoutes);
$mainRoutes = str_replace("['auth', 'active']", "['auth']", $mainRoutes);
file_put_contents(base_path('routes/web.php'), $mainRoutes);
/*
* --------------------------------------------------------------------------
* Drop the activate by email notification
* --------------------------------------------------------------------------
*/
$activateUserEmail = file_get_contents(app_path('Notifications/ActivateUserEmail.php'));
$activateUserEmail = str_replace("'mail'", '', $activateUserEmail);
file_put_contents(app_path('Notifications/ActivateUserEmail.php'), $activateUserEmail);
/*
* --------------------------------------------------------------------------
* Clean up the user model
* --------------------------------------------------------------------------
*/
$userModel = file_get_contents(app_path('Models/User.php'));
$userModel = str_replace("/**
* Teams
*
* @return Relationship
*/
public function teams()
{
return \$this->belongsToMany(Team::class);
}
/**
* Team member
*
* @return boolean
*/
public function isTeamMember(\$id)
{
\$teams = array_column(\$this->teams->toArray(), 'id');
return array_search(\$id, \$teams) > -1;
}
/**
* Team admin
*
* @return boolean
*/
public function isTeamAdmin(\$id)
{
\$team = \$this->teams->find(\$id);
return (int)\$team->user_id === (int)\$this->id;
}", '', $userModel);
$userModel = str_replace("use App\Models\Team;", '', $userModel);
file_put_contents(app_path('Models/User.php'), $userModel);
$userService = file_get_contents(app_path('Services/UserService.php'));
$userService = str_replace('/*
|--------------------------------------------------------------------------
| Teams
|--------------------------------------------------------------------------
*/
public function joinTeam($teamId, $userId)
{
$team = $this->team->find($teamId);
$user = $this->model->find($userId);
$user->teams()->attach($team);
}
public function leaveTeam($teamId, $userId)
{
$team = $this->team->find($teamId);
$user = $this->model->find($userId);
$user->teams()->detach($team);
}
public function leaveAllTeams($userId)
{
$user = $this->model->find($userId);
$user->teams()->detach();
}', '', $userService);
$userService = str_replace('use App\Models\Team;', '', $userService);
$userService = str_replace('Team $team,', '', $userService);
$userService = str_replace('$this->team = $team;', '', $userService);
$userService = str_replace('$this->leaveAllTeams($id);', '', $userService);
file_put_contents(app_path('Services/UserService.php'), $userService);
$seed = file_get_contents(base_path('database/seeds/DatabaseSeeder.php'));
$seed = str_replace('$this->call(TeamTableSeeder::class);', '', $seed);
file_put_contents(base_path('database/seeds/DatabaseSeeder.php'), $seed);
$css = file_get_contents(base_path('resources/sass/app.scss'));
$css = str_replace('@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";', '@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";'."\n".'@import "resources/themes/default/assets/sass/_theme.scss";', $css);
file_put_contents(base_path('resources/sass/app.scss'), $css);
$composer = file_get_contents(base_path('composer.json'));
$composer = str_replace('"App\\": "app/",', '"App\\": "app/",'."\n".'"Cms\\Modules\\": "cms/Modules/",', $composer);
file_put_contents(base_path('composer.json'), $composer);
} | [
"public",
"function",
"fileManager",
"(",
")",
"{",
"$",
"files",
"=",
"[",
"base_path",
"(",
"'config/auth.php'",
")",
",",
"base_path",
"(",
"'config/services.php'",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
... | Clean up files from the install of Laracogs etc. | [
"Clean",
"up",
"files",
"from",
"the",
"install",
"of",
"Laracogs",
"etc",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/Setup.php#L143-L309 |
GrafiteInc/CMS | src/Console/Setup.php | Setup.dropDeadFiles | public function dropDeadFiles()
{
@unlink(app_path('Http/Controllers/PagesController.php'));
@unlink(app_path('Http/Controllers/TeamController.php'));
@unlink(app_path('Http/Requests/TeamCreateRequest.php'));
@unlink(app_path('Http/Requests/TeamUpdateRequest.php'));
@unlink(app_path('Models/Team.php'));
@unlink(app_path('Services/TeamService.php'));
@unlink(base_path('resources/views/dashboard.blade.php'));
@unlink(base_path('resources/views/dashboard/main.blade.php'));
@unlink(base_path('resources/views/dashboard/panel.blade.php'));
@unlink(base_path('resources/views/partials/navigation.blade.php'));
@unlink(base_path('resources/views/team/create.blade.php'));
@unlink(base_path('resources/views/team/edit.blade.php'));
@unlink(base_path('resources/views/team/show.blade.php'));
@unlink(base_path('resources/views/team/index.blade.php'));
@rmdir(base_path('resources/views/team'));
@rmdir(base_path('resources/views/dashboard'));
} | php | public function dropDeadFiles()
{
@unlink(app_path('Http/Controllers/PagesController.php'));
@unlink(app_path('Http/Controllers/TeamController.php'));
@unlink(app_path('Http/Requests/TeamCreateRequest.php'));
@unlink(app_path('Http/Requests/TeamUpdateRequest.php'));
@unlink(app_path('Models/Team.php'));
@unlink(app_path('Services/TeamService.php'));
@unlink(base_path('resources/views/dashboard.blade.php'));
@unlink(base_path('resources/views/dashboard/main.blade.php'));
@unlink(base_path('resources/views/dashboard/panel.blade.php'));
@unlink(base_path('resources/views/partials/navigation.blade.php'));
@unlink(base_path('resources/views/team/create.blade.php'));
@unlink(base_path('resources/views/team/edit.blade.php'));
@unlink(base_path('resources/views/team/show.blade.php'));
@unlink(base_path('resources/views/team/index.blade.php'));
@rmdir(base_path('resources/views/team'));
@rmdir(base_path('resources/views/dashboard'));
} | [
"public",
"function",
"dropDeadFiles",
"(",
")",
"{",
"@",
"unlink",
"(",
"app_path",
"(",
"'Http/Controllers/PagesController.php'",
")",
")",
";",
"@",
"unlink",
"(",
"app_path",
"(",
"'Http/Controllers/TeamController.php'",
")",
")",
";",
"@",
"unlink",
"(",
"... | Clean up dead files. | [
"Clean",
"up",
"dead",
"files",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/Setup.php#L314-L332 |
GrafiteInc/CMS | src/Migrations/2017_12_14_045216_add_hero_images.php | AddHeroImages.up | public function up()
{
Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) {
$table->string('hero_image')->nullable();
});
Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) {
$table->string('hero_image')->nullable();
});
} | php | public function up()
{
Schema::table(config('cms.db-prefix', '').'blogs', function (Blueprint $table) {
$table->string('hero_image')->nullable();
});
Schema::table(config('cms.db-prefix', '').'pages', function (Blueprint $table) {
$table->string('hero_image')->nullable();
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"table",
"(",
"config",
"(",
"'cms.db-prefix'",
",",
"''",
")",
".",
"'blogs'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"string",
"(",
"'hero_image'",
")"... | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2017_12_14_045216_add_hero_images.php#L14-L23 |
GrafiteInc/CMS | src/Migrations/2017_12_14_045216_add_hero_images.php | AddHeroImages.down | public function down()
{
Schema::table(config('cms.db-prefix', '').'blogs', function ($table) {
$table->dropColumn('hero_image');
});
Schema::table(config('cms.db-prefix', '').'pages', function ($table) {
$table->dropColumn('hero_image');
});
} | php | public function down()
{
Schema::table(config('cms.db-prefix', '').'blogs', function ($table) {
$table->dropColumn('hero_image');
});
Schema::table(config('cms.db-prefix', '').'pages', function ($table) {
$table->dropColumn('hero_image');
});
} | [
"public",
"function",
"down",
"(",
")",
"{",
"Schema",
"::",
"table",
"(",
"config",
"(",
"'cms.db-prefix'",
",",
"''",
")",
".",
"'blogs'",
",",
"function",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"dropColumn",
"(",
"'hero_image'",
")",
";",
... | Reverse the migrations.
@return void | [
"Reverse",
"the",
"migrations",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Migrations/2017_12_14_045216_add_hero_images.php#L30-L39 |
GrafiteInc/CMS | src/Repositories/FileRepository.php | FileRepository.store | public function store($payload)
{
$result = false;
foreach ($payload['location'] as $file) {
$filePayload = $payload;
$filePayload['name'] = $file['original'];
$filePayload['location'] = CryptoService::decrypt($file['name']);
$filePayload['mime'] = $file['mime'];
$filePayload['size'] = $file['size'];
$filePayload['order'] = 0;
$filePayload['user'] = (isset($payload['user'])) ? $payload['user'] : Auth::id();
$filePayload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$result = $this->model->create($filePayload);
}
return $result;
} | php | public function store($payload)
{
$result = false;
foreach ($payload['location'] as $file) {
$filePayload = $payload;
$filePayload['name'] = $file['original'];
$filePayload['location'] = CryptoService::decrypt($file['name']);
$filePayload['mime'] = $file['mime'];
$filePayload['size'] = $file['size'];
$filePayload['order'] = 0;
$filePayload['user'] = (isset($payload['user'])) ? $payload['user'] : Auth::id();
$filePayload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
$result = $this->model->create($filePayload);
}
return $result;
} | [
"public",
"function",
"store",
"(",
"$",
"payload",
")",
"{",
"$",
"result",
"=",
"false",
";",
"foreach",
"(",
"$",
"payload",
"[",
"'location'",
"]",
"as",
"$",
"file",
")",
"{",
"$",
"filePayload",
"=",
"$",
"payload",
";",
"$",
"filePayload",
"["... | Stores Files into database.
@param array $input
@return Files | [
"Stores",
"Files",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/FileRepository.php#L32-L49 |
GrafiteInc/CMS | src/Repositories/FileRepository.php | FileRepository.update | public function update($files, $payload)
{
if (isset($payload['location'])) {
$savedFile = app(FileService::class)->saveFile($payload['location'], 'files/');
$_file = $payload['location'];
$filePayload = $payload;
$filePayload['name'] = $savedFile['original'];
$filePayload['location'] = $savedFile['name'];
$filePayload['mime'] = $_file->getClientMimeType();
$filePayload['size'] = $_file->getClientSize();
} else {
$filePayload = $payload;
}
$filePayload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
return $files->update($filePayload);
} | php | public function update($files, $payload)
{
if (isset($payload['location'])) {
$savedFile = app(FileService::class)->saveFile($payload['location'], 'files/');
$_file = $payload['location'];
$filePayload = $payload;
$filePayload['name'] = $savedFile['original'];
$filePayload['location'] = $savedFile['name'];
$filePayload['mime'] = $_file->getClientMimeType();
$filePayload['size'] = $_file->getClientSize();
} else {
$filePayload = $payload;
}
$filePayload['is_published'] = (isset($payload['is_published'])) ? (bool) $payload['is_published'] : 0;
return $files->update($filePayload);
} | [
"public",
"function",
"update",
"(",
"$",
"files",
",",
"$",
"payload",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"payload",
"[",
"'location'",
"]",
")",
")",
"{",
"$",
"savedFile",
"=",
"app",
"(",
"FileService",
"::",
"class",
")",
"->",
"saveFile",
... | Updates Files into database.
@param Files $files
@param array $payload
@return Files | [
"Updates",
"Files",
"into",
"database",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/FileRepository.php#L59-L77 |
GrafiteInc/CMS | src/Repositories/FileRepository.php | FileRepository.apiPrepared | public function apiPrepared()
{
$files = File::orderBy('created_at', 'desc')->where('is_published', 1)->get();
$allFiles = [];
foreach ($files as $file) {
array_push($allFiles, [
'file_identifier' => CryptoService::url_encode($file->name).'/'.CryptoService::url_encode($file->location),
'file_name' => $file->name,
'file_date' => $file->created_at->format('F jS, Y'),
]);
}
return $allFiles;
} | php | public function apiPrepared()
{
$files = File::orderBy('created_at', 'desc')->where('is_published', 1)->get();
$allFiles = [];
foreach ($files as $file) {
array_push($allFiles, [
'file_identifier' => CryptoService::url_encode($file->name).'/'.CryptoService::url_encode($file->location),
'file_name' => $file->name,
'file_date' => $file->created_at->format('F jS, Y'),
]);
}
return $allFiles;
} | [
"public",
"function",
"apiPrepared",
"(",
")",
"{",
"$",
"files",
"=",
"File",
"::",
"orderBy",
"(",
"'created_at'",
",",
"'desc'",
")",
"->",
"where",
"(",
"'is_published'",
",",
"1",
")",
"->",
"get",
"(",
")",
";",
"$",
"allFiles",
"=",
"[",
"]",
... | Files output for API calls
@return array | [
"Files",
"output",
"for",
"API",
"calls"
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Repositories/FileRepository.php#L84-L98 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/PagesController.php | PagesController.home | public function home()
{
$page = $this->repository->findPagesByURL('home');
$view = view('cms-frontend::pages.home');
if (is_null($page)) {
return $view;
}
return $view->with('page', $page);
} | php | public function home()
{
$page = $this->repository->findPagesByURL('home');
$view = view('cms-frontend::pages.home');
if (is_null($page)) {
return $view;
}
return $view->with('page', $page);
} | [
"public",
"function",
"home",
"(",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"repository",
"->",
"findPagesByURL",
"(",
"'home'",
")",
";",
"$",
"view",
"=",
"view",
"(",
"'cms-frontend::pages.home'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"pag... | Homepage.
@param string $url
@return Response | [
"Homepage",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/PagesController.php#L24-L35 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/PagesController.php | PagesController.all | public function all()
{
$pages = $this->repository->published();
if (empty($pages)) {
abort(404);
}
return view('cms-frontend::pages.all')->with('pages', $pages);
} | php | public function all()
{
$pages = $this->repository->published();
if (empty($pages)) {
abort(404);
}
return view('cms-frontend::pages.all')->with('pages', $pages);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"pages",
"=",
"$",
"this",
"->",
"repository",
"->",
"published",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"pages",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"return",
"view",
"(",
"... | Display page list.
@return Response | [
"Display",
"page",
"list",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/PagesController.php#L42-L51 |
GrafiteInc/CMS | src/PublishedAssets/Controllers/PagesController.php | PagesController.show | public function show($url)
{
$page = $this->repository->findPagesByURL($url);
if (empty($page)) {
abort(404);
}
return view('cms-frontend::pages.'.$page->template)->with('page', $page);
} | php | public function show($url)
{
$page = $this->repository->findPagesByURL($url);
if (empty($page)) {
abort(404);
}
return view('cms-frontend::pages.'.$page->template)->with('page', $page);
} | [
"public",
"function",
"show",
"(",
"$",
"url",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"repository",
"->",
"findPagesByURL",
"(",
"$",
"url",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"page",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"... | Display the specified Page.
@param string $url
@return Response | [
"Display",
"the",
"specified",
"Page",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/PublishedAssets/Controllers/PagesController.php#L60-L69 |
GrafiteInc/CMS | src/Console/ModuleCrud.php | ModuleCrud.handle | public function handle()
{
$this->filesystem = new Filesystem();
$crudGenerator = new CrudGenerator();
$this->table = ucfirst(str_singular(strtolower($this->argument('table'))));
$moduleDirectory = base_path('cms/Modules/'.ucfirst(str_plural($this->table)));
$this->directorySetup();
if (!is_dir($moduleDirectory)) {
mkdir($moduleDirectory);
mkdir($moduleDirectory.'/Assets', 0777, true);
mkdir($moduleDirectory.'/Publishes', 0777, true);
mkdir($moduleDirectory.'/Publishes/database', 0777, true);
mkdir($moduleDirectory.'/Publishes/app/Http', 0777, true);
mkdir($moduleDirectory.'/Publishes/routes', 0777, true);
mkdir($moduleDirectory.'/Publishes/app/Http/Controllers/Cms', 0777, true);
mkdir($moduleDirectory.'/Publishes/resources/themes/default', 0777, true);
mkdir($moduleDirectory.'/Migrations', 0777, true);
mkdir($moduleDirectory.'/Controllers', 0777, true);
mkdir($moduleDirectory.'/Services', 0777, true);
mkdir($moduleDirectory.'/Models', 0777, true);
mkdir($moduleDirectory.'/Routes', 0777, true);
mkdir($moduleDirectory.'/Views', 0777, true);
mkdir($moduleDirectory.'/Tests', 0777, true);
mkdir($moduleDirectory.'/Tests/Feature', 0777, true);
mkdir($moduleDirectory.'/Tests/Unit', 0777, true);
}
file_put_contents($moduleDirectory.'/config.php', "<?php \n\n\n return [ 'asset_path' => __DIR__.'/Assets', 'url' => '".strtolower(str_plural($this->table))."', ];");
file_put_contents($moduleDirectory.'/Views/menu.blade.php', "<li class=\"nav-item @if (Request::is(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."') || Request::is(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."/*')) active @endif\"><a class=\"nav-link\" href=\"{{ url(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."') }}\"><span class=\"fa fa-fw fa-file\"></span> ".ucfirst(str_plural($this->table)).'</a></li>');
$config = [
'bootstrap' => false,
'semantic' => false,
'_path_facade_' => $moduleDirectory.'/Facades',
'_path_service_' => $moduleDirectory.'/Services',
'_path_model_' => $moduleDirectory.'/Models',
'_path_model_' => $moduleDirectory.'/Models',
'_path_controller_' => $moduleDirectory.'/Controllers',
'_path_views_' => $moduleDirectory.'/Views',
'_path_tests_' => $moduleDirectory.'/Tests',
'_path_request_' => $moduleDirectory.'/Requests',
'_path_routes_' => $moduleDirectory.'/Routes/web.php',
'routes_prefix' => "<?php \n\nRoute::group(['namespace' => 'Cms\Modules\\".ucfirst(str_plural($this->table))."\Controllers', 'prefix' => config('cms.backend-route-prefix', 'cms'), 'middleware' => ['web', 'auth', 'cms']], function () { \n\n",
'routes_suffix' => "\n\n});",
'_app_namespace_' => app()->getInstance()->getNamespace(),
'_namespace_services_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Services',
'_namespace_facade_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Facades',
'_namespace_model_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Models',
'_namespace_controller_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Controllers',
'_namespace_request_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Requests',
'_table_name_' => str_plural(strtolower($this->table)),
'_lower_case_' => strtolower($this->table),
'_lower_casePlural_' => str_plural(strtolower($this->table)),
'_camel_case_' => ucfirst(camel_case($this->table)),
'_camel_casePlural_' => ucfirst(str_plural(camel_case($this->table))),
'_ucCamel_casePlural_' => ucfirst(str_plural(camel_case($this->table))),
'template_source' => __DIR__.'/../Templates/CRUD/',
'tests_generated' => 'integration,service,repository',
];
$this->makeTheProvider($config, $moduleDirectory, $this->table);
$appConfig = $config;
$appConfig['template_source'] = __DIR__.'/../Templates/AppCRUD';
$appConfig['_path_controller_'] = $moduleDirectory.'/Publishes/app/Http/Controllers/Cms';
$appConfig['_path_views_'] = $moduleDirectory.'/Publishes/resources/themes/default';
$appConfig['_path_routes_'] = $moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php';
$appConfig['_namespace_controller_'] = $config['_app_namespace_'].'Http\Controllers\Cms';
$appConfig['routes_prefix'] = "<?php \n\nRoute::group(['namespace' => 'Cms', 'middleware' => ['web']], function () {\n\n";
$appConfig['routes_suffix'] = "\n\n});";
try {
$this->info('Building the admin side...');
$this->line('Building controller...');
$crudGenerator->createController($config);
$this->line('Building model...');
$crudGenerator->createModel($config);
$this->line('Building request...');
$crudGenerator->createRequest($config);
$this->line('Building service...');
$crudGenerator->createService($config);
$this->line('Building views...');
$crudGenerator->createViews($config);
$this->line('Building routes...');
$crudGenerator->createRoutes($config);
$this->line('Building tests...');
$crudGenerator->createTests($config, false);
$this->info('Building the theme side...');
$this->line('Building controller...');
$crudGenerator->createController($appConfig);
$this->line('Building views...');
$crudGenerator->createViews($appConfig);
$this->line('Building routes...');
@file_put_contents($moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php', '');
$crudGenerator->createRoutes($appConfig, false);
$this->line('You will need to publish your module to make it available to your vistors:');
$this->comment('php artisan module:publish '.str_plural($this->table));
$this->line('');
$this->info('Add this to your `app/Providers/RouteServiceProver.php` in the `mapWebRoutes` method:');
$this->comment("\nrequire base_path('routes/".$config['_lower_casePlural_']."-web.php');\n");
} catch (Exception $e) {
throw new Exception('Unable to generate your Module', 1);
}
Artisan::call('make:migration', [
'name' => 'create_'.str_plural(strtolower($this->table)).'_table',
'--path' => 'cms/Modules/'.ucfirst(str_plural($this->table)).'/Migrations',
'--table' => str_plural(strtolower($this->table)),
'--create' => true,
]);
$this->setSchema();
$this->line('You may wish to add this as your testing database');
$this->line("'testing' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '' ],");
$this->info('Module for '.$this->table.' is done.');
} | php | public function handle()
{
$this->filesystem = new Filesystem();
$crudGenerator = new CrudGenerator();
$this->table = ucfirst(str_singular(strtolower($this->argument('table'))));
$moduleDirectory = base_path('cms/Modules/'.ucfirst(str_plural($this->table)));
$this->directorySetup();
if (!is_dir($moduleDirectory)) {
mkdir($moduleDirectory);
mkdir($moduleDirectory.'/Assets', 0777, true);
mkdir($moduleDirectory.'/Publishes', 0777, true);
mkdir($moduleDirectory.'/Publishes/database', 0777, true);
mkdir($moduleDirectory.'/Publishes/app/Http', 0777, true);
mkdir($moduleDirectory.'/Publishes/routes', 0777, true);
mkdir($moduleDirectory.'/Publishes/app/Http/Controllers/Cms', 0777, true);
mkdir($moduleDirectory.'/Publishes/resources/themes/default', 0777, true);
mkdir($moduleDirectory.'/Migrations', 0777, true);
mkdir($moduleDirectory.'/Controllers', 0777, true);
mkdir($moduleDirectory.'/Services', 0777, true);
mkdir($moduleDirectory.'/Models', 0777, true);
mkdir($moduleDirectory.'/Routes', 0777, true);
mkdir($moduleDirectory.'/Views', 0777, true);
mkdir($moduleDirectory.'/Tests', 0777, true);
mkdir($moduleDirectory.'/Tests/Feature', 0777, true);
mkdir($moduleDirectory.'/Tests/Unit', 0777, true);
}
file_put_contents($moduleDirectory.'/config.php', "<?php \n\n\n return [ 'asset_path' => __DIR__.'/Assets', 'url' => '".strtolower(str_plural($this->table))."', ];");
file_put_contents($moduleDirectory.'/Views/menu.blade.php', "<li class=\"nav-item @if (Request::is(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."') || Request::is(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."/*')) active @endif\"><a class=\"nav-link\" href=\"{{ url(config('cms.backend-route-prefix', 'cms').'/".strtolower(str_plural($this->table))."') }}\"><span class=\"fa fa-fw fa-file\"></span> ".ucfirst(str_plural($this->table)).'</a></li>');
$config = [
'bootstrap' => false,
'semantic' => false,
'_path_facade_' => $moduleDirectory.'/Facades',
'_path_service_' => $moduleDirectory.'/Services',
'_path_model_' => $moduleDirectory.'/Models',
'_path_model_' => $moduleDirectory.'/Models',
'_path_controller_' => $moduleDirectory.'/Controllers',
'_path_views_' => $moduleDirectory.'/Views',
'_path_tests_' => $moduleDirectory.'/Tests',
'_path_request_' => $moduleDirectory.'/Requests',
'_path_routes_' => $moduleDirectory.'/Routes/web.php',
'routes_prefix' => "<?php \n\nRoute::group(['namespace' => 'Cms\Modules\\".ucfirst(str_plural($this->table))."\Controllers', 'prefix' => config('cms.backend-route-prefix', 'cms'), 'middleware' => ['web', 'auth', 'cms']], function () { \n\n",
'routes_suffix' => "\n\n});",
'_app_namespace_' => app()->getInstance()->getNamespace(),
'_namespace_services_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Services',
'_namespace_facade_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Facades',
'_namespace_model_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Models',
'_namespace_controller_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Controllers',
'_namespace_request_' => 'Cms\Modules\\'.ucfirst(str_plural($this->table)).'\Requests',
'_table_name_' => str_plural(strtolower($this->table)),
'_lower_case_' => strtolower($this->table),
'_lower_casePlural_' => str_plural(strtolower($this->table)),
'_camel_case_' => ucfirst(camel_case($this->table)),
'_camel_casePlural_' => ucfirst(str_plural(camel_case($this->table))),
'_ucCamel_casePlural_' => ucfirst(str_plural(camel_case($this->table))),
'template_source' => __DIR__.'/../Templates/CRUD/',
'tests_generated' => 'integration,service,repository',
];
$this->makeTheProvider($config, $moduleDirectory, $this->table);
$appConfig = $config;
$appConfig['template_source'] = __DIR__.'/../Templates/AppCRUD';
$appConfig['_path_controller_'] = $moduleDirectory.'/Publishes/app/Http/Controllers/Cms';
$appConfig['_path_views_'] = $moduleDirectory.'/Publishes/resources/themes/default';
$appConfig['_path_routes_'] = $moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php';
$appConfig['_namespace_controller_'] = $config['_app_namespace_'].'Http\Controllers\Cms';
$appConfig['routes_prefix'] = "<?php \n\nRoute::group(['namespace' => 'Cms', 'middleware' => ['web']], function () {\n\n";
$appConfig['routes_suffix'] = "\n\n});";
try {
$this->info('Building the admin side...');
$this->line('Building controller...');
$crudGenerator->createController($config);
$this->line('Building model...');
$crudGenerator->createModel($config);
$this->line('Building request...');
$crudGenerator->createRequest($config);
$this->line('Building service...');
$crudGenerator->createService($config);
$this->line('Building views...');
$crudGenerator->createViews($config);
$this->line('Building routes...');
$crudGenerator->createRoutes($config);
$this->line('Building tests...');
$crudGenerator->createTests($config, false);
$this->info('Building the theme side...');
$this->line('Building controller...');
$crudGenerator->createController($appConfig);
$this->line('Building views...');
$crudGenerator->createViews($appConfig);
$this->line('Building routes...');
@file_put_contents($moduleDirectory.'/Publishes/routes/'.$config['_lower_casePlural_'].'-web.php', '');
$crudGenerator->createRoutes($appConfig, false);
$this->line('You will need to publish your module to make it available to your vistors:');
$this->comment('php artisan module:publish '.str_plural($this->table));
$this->line('');
$this->info('Add this to your `app/Providers/RouteServiceProver.php` in the `mapWebRoutes` method:');
$this->comment("\nrequire base_path('routes/".$config['_lower_casePlural_']."-web.php');\n");
} catch (Exception $e) {
throw new Exception('Unable to generate your Module', 1);
}
Artisan::call('make:migration', [
'name' => 'create_'.str_plural(strtolower($this->table)).'_table',
'--path' => 'cms/Modules/'.ucfirst(str_plural($this->table)).'/Migrations',
'--table' => str_plural(strtolower($this->table)),
'--create' => true,
]);
$this->setSchema();
$this->line('You may wish to add this as your testing database');
$this->line("'testing' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '' ],");
$this->info('Module for '.$this->table.' is done.');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"this",
"->",
"filesystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"$",
"crudGenerator",
"=",
"new",
"CrudGenerator",
"(",
")",
";",
"$",
"this",
"->",
"table",
"=",
"ucfirst",
"(",
"str_singular",
... | Generate a CRUD stack.
@return mixed | [
"Generate",
"a",
"CRUD",
"stack",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ModuleCrud.php#L36-L168 |
GrafiteInc/CMS | src/Console/ModuleCrud.php | ModuleCrud.makeTheProvider | public function makeTheProvider($config, $moduleDirectory, $table)
{
$provider = file_get_contents(__DIR__.'/../Templates/CRUD/Provider.txt');
foreach ($config as $key => $value) {
$provider = str_replace($key, $value, $provider);
}
return file_put_contents($moduleDirectory.'/'.ucfirst(str_plural($table)).'ModuleProvider.php', $provider);
} | php | public function makeTheProvider($config, $moduleDirectory, $table)
{
$provider = file_get_contents(__DIR__.'/../Templates/CRUD/Provider.txt');
foreach ($config as $key => $value) {
$provider = str_replace($key, $value, $provider);
}
return file_put_contents($moduleDirectory.'/'.ucfirst(str_plural($table)).'ModuleProvider.php', $provider);
} | [
"public",
"function",
"makeTheProvider",
"(",
"$",
"config",
",",
"$",
"moduleDirectory",
",",
"$",
"table",
")",
"{",
"$",
"provider",
"=",
"file_get_contents",
"(",
"__DIR__",
".",
"'/../Templates/CRUD/Provider.txt'",
")",
";",
"foreach",
"(",
"$",
"config",
... | Generate the provider file.
@param array $config
@return bool | [
"Generate",
"the",
"provider",
"file",
"."
] | train | https://github.com/GrafiteInc/CMS/blob/d3cefadc0ff50dbd968050e7bddb592b141a9b5d/src/Console/ModuleCrud.php#L177-L186 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.