2024-08-15 22:53:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function sanitize_post_path($post_path) {
|
|
|
|
$post_path = chop($post_path, '/');
|
|
|
|
|
|
|
|
if($post_path == "") {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!preg_match('/^(?:\/[\w-]+)+(?:\.[\w-]+)*$/', $post_path)) {
|
|
|
|
echo "Post path match against " . $post_path . " failed!";
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $post_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
function escape_tag($tag) {
|
|
|
|
return preg_replace_callback('/[\WZ]/', function($match) {
|
|
|
|
return "Z" . ord($match[0]);
|
|
|
|
}, strtolower($tag));
|
|
|
|
}
|
|
|
|
|
|
|
|
function escape_search_tag($tag) {
|
|
|
|
preg_match("/^([\+\-]?)(.*?)(\*?)$/", $tag, $matches);
|
|
|
|
|
|
|
|
if(!isset($matches[1])) {
|
|
|
|
echo "Problem with tag!";
|
|
|
|
var_dump($tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $matches[1] . $this->escape_tag($matches[2]) . $matches[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PostdataInterface {
|
|
|
|
/* Postdata format:
|
|
|
|
*
|
|
|
|
* The Postdata array is a simple intermediate data format
|
|
|
|
* for the Post content and metadata.
|
|
|
|
* It is slightly abstracted from the SQL format itself but will
|
|
|
|
* only reformat keys, *not* do any alteration of the data itself.
|
|
|
|
*
|
|
|
|
* Any supported fields will be integrated into the database.
|
|
|
|
* Other fields will be saved in a JSON structure, and will
|
|
|
|
* be restored afterward.
|
|
|
|
*
|
|
|
|
* The following fields are mandatory for *writing*
|
|
|
|
* - path: String, must be sanitized to consist of just alphanumeric
|
|
|
|
* characters, `_-./`
|
|
|
|
* used to identify the post itself
|
|
|
|
*
|
|
|
|
* The following fields may be returned by the database:
|
|
|
|
* - id
|
|
|
|
* - created_at
|
|
|
|
* - updated_at
|
|
|
|
* - view_count
|
|
|
|
*
|
|
|
|
* The following fields may be supported by the database:
|
|
|
|
* - markdown: String, markdown of the post. May be
|
|
|
|
* stored separately and won't be returned by default!
|
|
|
|
* - type: String, defining the type of the post
|
|
|
|
* - title: String, self-explanatory
|
|
|
|
* - tags: Array of strings
|
|
|
|
* - settings: Hash, recursively merged settings (calculated by DB!)
|
|
|
|
*
|
|
|
|
* The following fields are *recommended*, but nothing more:
|
|
|
|
* - icon: String, optionally defining
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function stub_postdata($path);
|
|
|
|
public function stub_postdata_tree($path);
|
|
|
|
|
|
|
|
public function set_postdata($data);
|
|
|
|
public function set_post_markdown($id, $markdown);
|
|
|
|
|
|
|
|
public function get_postdata($path);
|
|
|
|
// Returns a key-value pair of child paths => child data
|
|
|
|
public function get_post_children($path,
|
|
|
|
$limit = 50, $depth_start = 1, $depth_end = 1,
|
|
|
|
$order_by = 'path');
|
|
|
|
|
|
|
|
public function get_post_markdown($id);
|
2024-12-09 10:50:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Returns an array of PostData information
|
|
|
|
// based on the tag search list
|
|
|
|
//
|
|
|
|
// Tag searchlist is comprised of space-separated
|
|
|
|
// tags. Each tag can have a weighting prefix,
|
|
|
|
// and some special tags exist (such as limit:N,
|
|
|
|
// order:S).
|
|
|
|
public function search_posts($taglist);
|
2024-08-15 22:53:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|