mirror of
https://github.com/danpros/htmly.git
synced 2026-04-19 20:16:22 +05:30
$_REQUEST ready
This commit is contained in:
parent
0316cf0602
commit
4a7c57503e
3 changed files with 100 additions and 64 deletions
|
|
@ -39,14 +39,18 @@ function remove_accent($str) {
|
|||
}
|
||||
|
||||
// Edit blog posts
|
||||
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) {
|
||||
|
||||
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null) {
|
||||
$oldurl = explode('_', $oldfile);
|
||||
|
||||
$post_title = $title;
|
||||
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
|
||||
if ($description !== null) {
|
||||
$post_description = "<!--d " . $description . " d-->";
|
||||
} else {
|
||||
$post_description = "";
|
||||
}
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
|
||||
|
||||
if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
|
|
@ -85,13 +89,17 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
|
|||
}
|
||||
|
||||
// Edit static page
|
||||
function edit_page($title, $url, $content, $oldfile, $destination = null) {
|
||||
|
||||
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null) {
|
||||
$dir = substr($oldfile, 0, strrpos($oldfile, '/'));
|
||||
|
||||
$post_title = $title;
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
|
||||
if ($description !== null) {
|
||||
$post_description = "\n<!--d " . $description . " d-->";
|
||||
} else {
|
||||
$post_description = '';
|
||||
}
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
|
||||
|
||||
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
|
|
@ -119,13 +127,18 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) {
|
|||
}
|
||||
|
||||
// Add blog post
|
||||
function add_post($title, $tag, $url, $content, $user) {
|
||||
function add_post($title, $tag, $url, $content, $user, $desciption = null) {
|
||||
|
||||
$post_date = date('Y-m-d-H-i-s');
|
||||
$post_title = $title;
|
||||
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
|
||||
if ($description !== null) {
|
||||
$post_description = "<!--d " . $description . " d-->";
|
||||
} else {
|
||||
$post_description = "";
|
||||
}
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
|
||||
|
||||
if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
|
|
@ -148,11 +161,16 @@ function add_post($title, $tag, $url, $content, $user) {
|
|||
}
|
||||
|
||||
// Add static page
|
||||
function add_page($title, $url, $content) {
|
||||
function add_page($title, $url, $content, $description = null) {
|
||||
|
||||
$post_title = $title;
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
|
||||
if ($description !== null) {
|
||||
$post_description = "<!--d " . $description . " d-->";
|
||||
} else {
|
||||
$post_description = "";
|
||||
}
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
|
||||
|
||||
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
|
|
@ -175,11 +193,16 @@ function add_page($title, $url, $content) {
|
|||
}
|
||||
|
||||
// Add static sub page
|
||||
function add_sub_page($title, $url, $content, $static) {
|
||||
function add_sub_page($title, $url, $content, $static, $description = null) {
|
||||
|
||||
$post_title = $title;
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
|
||||
if ($description !== null) {
|
||||
$post_description = "<!--d " . $description . " d-->";
|
||||
} else {
|
||||
$post_description = "";
|
||||
}
|
||||
$post_content = '<!--t ' . $post_title . ' t-->' . $post_description . "\n\n" . $content;
|
||||
|
||||
if (!empty($post_title) && !empty($post_url) && !empty($post_content)) {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,8 @@ get("/:static/:sub/edit", function($static, $sub) {
|
|||
post("/:static/:sub/edit", function($static,$sub) {
|
||||
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
|
||||
|
||||
if (!login()) {
|
||||
if(!login())
|
||||
{
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
|
|
@ -154,15 +155,17 @@ post("/:static/:sub/edit", function($static, $sub) {
|
|||
$content = from($_REQUEST, 'content');
|
||||
$oldfile = from($_REQUEST, 'oldfile');
|
||||
$destination = from($_GET, 'destination');
|
||||
if ($destination === null) {
|
||||
$description = from($_REQUEST, 'description');
|
||||
if($destination === null)
|
||||
{
|
||||
$destination = $static . "/" . $sub;
|
||||
}
|
||||
if ($proper && !empty($title) && !empty($content)) {
|
||||
if (!empty($url)) {
|
||||
edit_page($title, $url, $content, $oldfile, $destination);
|
||||
edit_page($title, $url, $content, $oldfile, $destination, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
edit_page($title, $url, $content, $oldfile, $destination);
|
||||
edit_page($title, $url, $content, $oldfile, $destination, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -236,7 +239,8 @@ post("/:static/:sub/delete", function() {
|
|||
// The blog post page
|
||||
get('/:year/:month/:name', function($year, $month, $name) {
|
||||
|
||||
if (config("views.counter") != "true") {
|
||||
if(config("views.counter") != "true")
|
||||
{
|
||||
if (!login()) {
|
||||
file_cache($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
|
@ -250,7 +254,8 @@ get('/:year/:month/:name', function($year, $month, $name) {
|
|||
not_found();
|
||||
}
|
||||
|
||||
if (config("views.counter") == "true") {
|
||||
if(config("views.counter") == "true")
|
||||
{
|
||||
add_view($current->file);
|
||||
|
||||
if (!login()) {
|
||||
|
|
@ -279,7 +284,7 @@ get('/:year/:month/:name', function($year, $month, $name) {
|
|||
}
|
||||
|
||||
render('post', array(
|
||||
'head_contents' => head_contents($current->title . ' - ' . blog_title(), $current->description, $current->url),
|
||||
'head_contents' => head_contents($current->title . ' - ' . blog_title(), $description = get_description($current->body), $current->url),
|
||||
'p' => $current,
|
||||
'authorinfo' => authorinfo($bio->title, $bio->body),
|
||||
'bodyclass' => 'inpost',
|
||||
|
|
@ -339,12 +344,13 @@ post('/:year/:month/:name/edit', function() {
|
|||
$content = from($_REQUEST, 'content');
|
||||
$oldfile = from($_REQUEST, 'oldfile');
|
||||
$destination = from($_GET, 'destination');
|
||||
$description = from($_REQUEST, 'description');
|
||||
if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
|
||||
if (!empty($url)) {
|
||||
edit_post($title, $tag, $url, $content, $oldfile, $destination);
|
||||
edit_post($title, $tag, $url, $content, $oldfile, $destination, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
edit_post($title, $tag, $url, $content, $oldfile, $destination);
|
||||
edit_post($title, $tag, $url, $content, $oldfile, $destination, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -448,11 +454,9 @@ get('/author/:profile', function($profile) {
|
|||
$bio = default_profile($profile);
|
||||
}
|
||||
|
||||
$description = 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.';
|
||||
|
||||
if (empty($posts) || $page < 1) {
|
||||
render('profile', array(
|
||||
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), $description, site_url() . 'author/' . $profile),
|
||||
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.', site_url() . 'author/' . $profile),
|
||||
'page' => $page,
|
||||
'posts' => null,
|
||||
'bio' => $bio->body,
|
||||
|
|
@ -465,7 +469,7 @@ get('/author/:profile', function($profile) {
|
|||
}
|
||||
|
||||
render('profile', array(
|
||||
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), $description, site_url() . 'author/' . $profile),
|
||||
'head_contents' => head_contents('Profile for: ' . $bio->title . ' - ' . blog_title(), 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.', site_url() . 'author/' . $profile),
|
||||
'page' => $page,
|
||||
'posts' => $posts,
|
||||
'bio' => $bio->body,
|
||||
|
|
@ -501,8 +505,9 @@ post('/edit/profile', function() {
|
|||
$user = $_SESSION[config("site.url")]['user'];
|
||||
$title = from($_REQUEST, 'title');
|
||||
$content = from($_REQUEST, 'content');
|
||||
$description = from($_REQUEST, 'description');
|
||||
if ($proper && !empty($title) && !empty($content)) {
|
||||
edit_profile($title, $content, $user);
|
||||
edit_profile($title, $content, $user, $description);
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
if (empty($title)) {
|
||||
|
|
@ -703,7 +708,8 @@ get('/:static', function($static) {
|
|||
die;
|
||||
} else {
|
||||
|
||||
if (config("views.counter") != "true") {
|
||||
if( config("views.counter") != "true")
|
||||
{
|
||||
if (!login()) {
|
||||
file_cache($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
|
|
@ -717,7 +723,8 @@ get('/:static', function($static) {
|
|||
|
||||
$post = $post[0];
|
||||
|
||||
if (config("views.counter") == "true") {
|
||||
if(config("views.counter") == "true")
|
||||
{
|
||||
add_view($post->file);
|
||||
if (!login()) {
|
||||
file_cache($_SERVER['REQUEST_URI']);
|
||||
|
|
@ -725,7 +732,7 @@ get('/:static', function($static) {
|
|||
}
|
||||
|
||||
render('static', array(
|
||||
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $post->description, $post->url),
|
||||
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url),
|
||||
'bodyclass' => 'inpage',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » ' . $post->title,
|
||||
'p' => $post,
|
||||
|
|
@ -765,7 +772,8 @@ get('/:static/edit', function($static) {
|
|||
post('/:static/edit', function() {
|
||||
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
|
||||
|
||||
if (!login()) {
|
||||
if(!login())
|
||||
{
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
|
|
@ -775,12 +783,13 @@ post('/:static/edit', function() {
|
|||
$content = from($_REQUEST, 'content');
|
||||
$oldfile = from($_REQUEST, 'oldfile');
|
||||
$destination = from($_GET, 'destination');
|
||||
$description = from($_REQUEST, 'description');
|
||||
if ($proper && !empty($title) && !empty($content)) {
|
||||
if (!empty($url)) {
|
||||
edit_page($title, $url, $content, $oldfile, $destination);
|
||||
edit_page($title, $url, $content, $oldfile, $destination, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
edit_page($title, $url, $content, $oldfile, $destination);
|
||||
edit_page($title, $url, $content, $oldfile, $destination, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -873,13 +882,14 @@ post('/add/post', function() {
|
|||
$tag = from($_REQUEST, 'tag');
|
||||
$url = from($_REQUEST, 'url');
|
||||
$content = from($_REQUEST, 'content');
|
||||
$description = from($_REQUEST, 'description');
|
||||
$user = $_SESSION[config("site.url")]['user'];
|
||||
if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
|
||||
if (!empty($url)) {
|
||||
add_post($title, $tag, $url, $content, $user);
|
||||
add_post($title, $tag, $url, $content, $user, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
add_post($title, $tag, $url, $content, $user);
|
||||
add_post($title, $tag, $url, $content, $user, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -935,12 +945,13 @@ post('/add/page', function() {
|
|||
$title = from($_REQUEST, 'title');
|
||||
$url = from($_REQUEST, 'url');
|
||||
$content = from($_REQUEST, 'content');
|
||||
$description = from($_REQUEST, 'description');
|
||||
if ($proper && !empty($title) && !empty($content) && login()) {
|
||||
if (!empty($url)) {
|
||||
add_page($title, $url, $content);
|
||||
add_page($title, $url, $content, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
add_page($title, $url, $content);
|
||||
add_page($title, $url, $content, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -1234,7 +1245,8 @@ get('/:static/add', function($static) {
|
|||
|
||||
$post = get_static_post($static);
|
||||
|
||||
if (!$post) {
|
||||
if(! $post)
|
||||
{
|
||||
not_found();
|
||||
}
|
||||
|
||||
|
|
@ -1257,12 +1269,13 @@ post('/:static/add', function($static) {
|
|||
$title = from($_REQUEST, 'title');
|
||||
$url = from($_REQUEST, 'url');
|
||||
$content = from($_REQUEST, 'content');
|
||||
$description = from($_REQUEST, 'description');
|
||||
if ($proper && !empty($title) && !empty($content) && login()) {
|
||||
if (!empty($url)) {
|
||||
add_sub_page($title, $url, $content, $static);
|
||||
add_sub_page($title, $url, $content, $static, $description);
|
||||
} else {
|
||||
$url = $title;
|
||||
add_sub_page($title, $url, $content, $static);
|
||||
add_sub_page($title, $url, $content, $static, $description);
|
||||
}
|
||||
} else {
|
||||
$message['error'] = '';
|
||||
|
|
@ -1300,7 +1313,8 @@ get('/:static/:sub', function($static, $sub) {
|
|||
}
|
||||
$post = $post[0];
|
||||
|
||||
if (config("views.counter") == "true") {
|
||||
if(config("views.counter") == "true")
|
||||
{
|
||||
add_view($post->file);
|
||||
}
|
||||
|
||||
|
|
@ -1309,7 +1323,7 @@ get('/:static/:sub', function($static, $sub) {
|
|||
}
|
||||
|
||||
render('static', array(
|
||||
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $post->description, $post->url),
|
||||
'head_contents' => head_contents($post->title . ' - ' . blog_title(), $description = get_description($post->body), $post->url),
|
||||
'bodyclass' => 'inpage',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » <a href="' . $father_post[0]->url . '">' . $father_post[0]->title . '</a> » ' . $post->title,
|
||||
'p' => $post,
|
||||
|
|
|
|||
|
|
@ -1686,6 +1686,5 @@ function get_content_tag($tag, $string, $alt = null) {
|
|||
}
|
||||
|
||||
function remove_html_comments($content) {
|
||||
//return $content;
|
||||
return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue