-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added post deletion, editing, comment deletion and dark mode su…
…pport.
- Loading branch information
Showing
27 changed files
with
510 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
class Formatting | ||
{ | ||
/** | ||
* Transform the body of the post. | ||
* | ||
* @param string $body | ||
* | ||
* @return string | ||
*/ | ||
public static function transformBody($text) | ||
{ | ||
$text = self::makeLinks($text); | ||
$text = self::wpautop($text); | ||
|
||
return $text; | ||
} | ||
|
||
/** | ||
* Makes links clickable in the given text. | ||
* | ||
* @param string $text The text to process. | ||
* @return string The processed text with clickable links. | ||
*/ | ||
public static function makeLinks($text) | ||
{ | ||
return preg_replace('/(http|https):\/\/[a-zA-Z0-9\.\-\/\?\&\=\_\%\#]+/', '<a href="$0" target="_blank">$0</a>', $text); | ||
} | ||
|
||
/** | ||
* Replaces double line breaks with paragraph elements. | ||
* | ||
* @param string $text The text to process. | ||
* @param bool $br Whether to add line breaks. | ||
* @return string The processed text with paragraph elements. | ||
*/ | ||
public static function wpautop($text, $br = true) | ||
{ | ||
if (trim($text) === '') { | ||
return ''; | ||
} | ||
|
||
// Just to make things a little easier, pad the end. | ||
$text = $text . "\n"; | ||
|
||
// Change multiple <br>'s into two line breaks, which will turn into paragraphs. | ||
$text = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $text); | ||
|
||
// Add a double line break after hr tags, which are self closing. | ||
$text = preg_replace('!(<hr\s*?/?>)!', "$1\n\n", $text); | ||
|
||
// Standardize newline characters to "\n". | ||
$text = str_replace(array( "\r\n", "\r" ), "\n", $text); | ||
|
||
// Remove more than two contiguous line breaks. | ||
$text = preg_replace("/\n\n+/", "\n\n", $text); | ||
|
||
// Split up the contents into an array of strings, separated by double line breaks. | ||
$paragraphs = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY); | ||
|
||
// Reset $text prior to rebuilding. | ||
$text = ''; | ||
|
||
// Rebuild the content as a string, wrapping every bit with a <p>. | ||
foreach ($paragraphs as $paragraph) { | ||
$text .= '<p class="mb-3">' . trim($paragraph, "\n") . "</p>\n"; | ||
} | ||
|
||
// Under certain strange conditions it could create a P of entirely whitespace. | ||
$text = preg_replace('|<p>\s*</p>|', '', $text); | ||
|
||
return $text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Comment; | ||
|
||
class CommentController extends Controller | ||
{ | ||
public function destroy(Comment $comment) | ||
{ | ||
$comment->delete(); | ||
|
||
return response()->json(['message' => 'Comment deleted']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.