'.$title.'

'); echo('
'.$previewImageAlt.'
'); if(!empty($previewPreface)) { echo('

'.$previewPreface.'

'); } if(!empty($previewText)) { echo('

'.$previewText.'
Click here

'); } else { echo('

Click here

'); } echo('
'); echo('

'); foreach($tags as &$tagValue) { echo('  #'.$tagValue.''); } echo('

'); } /* Defining globals and constants */ const BLOG_ACTION_NONE = "n"; const BLOG_ACTION_SEARCH_TAGS = "t"; const BLOG_ACTION_SEARCH_AUTHOR = "a"; const BLOG_ACTION_SEARCH_DATE = "d"; //const BLOG_ACTION_ERROR_SEARCH_TYPE_INVALID = "e"; const BLOG_PARAM_ACTION = "c"; const BLOG_PARAM_ARTICLE_PER_PAGE = "c"; const BLOG_PARAM_PAGE = "p"; const BLOG_PARAM_SEARCH_PARAM = "s"; $blog_action = BLOG_ACTION_NONE; $blog_search_parameter = ""; $current_page = 0; $article_per_page = 10; /* Parsing and verifying arguments */ if(count($_GET) > 0) { if(array_key_exists(BLOG_PARAM_ACTION, $_GET)) { $blog_action = $_GET[BLOG_PARAM_ACTION]; } if(array_key_exists(BLOG_PARAM_ARTICLE_PER_PAGE, $_GET)) { $article_per_page = $_GET[BLOG_PARAM_ARTICLE_PER_PAGE]; } if(array_key_exists(BLOG_PARAM_PAGE, $_GET)) { $current_page = $_GET[BLOG_PARAM_PAGE]; } if(array_key_exists(BLOG_PARAM_SEARCH_PARAM, $_GET)) { $blog_search_parameter = $_GET[BLOG_PARAM_SEARCH_PARAM]; } } if(!($blog_action == BLOG_ACTION_NONE || $blog_action == BLOG_ACTION_SEARCH_TAGS || $blog_action == BLOG_ACTION_SEARCH_AUTHOR || $blog_action == BLOG_ACTION_SEARCH_DATE)) { $blog_action = BLOG_ACTION_NONE; } if(!is_numeric($article_per_page)) { $article_per_page = 10; } if(!is_numeric($current_page)) { $current_page = 0; } /* Loading blog entries */ $jsonArticles = null; try { $jsonArticles = file_get_contents("articles.json"); $jsonArticles = json_decode($jsonArticles, true); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; $jsonArticles = null; } if($jsonArticles == null) { exit("An error occured during the JSON parsing process..."); } /* Printing the articles... */ $currentArticleId = 0; $articlesLeft = $article_per_page; //TODO: Max value is not right or checked yet ! for($currentArticleId = ($article_per_page * $current_page); $currentArticleId < count($jsonArticles); $currentArticleId++) { //echo($jsonArticles[$currentArticleId]["id"]."
"); printBlogPreviewCard( $jsonArticles[$currentArticleId]["id"], $jsonArticles[$currentArticleId]["title"], $jsonArticles[$currentArticleId]["preview"]["preface"], $jsonArticles[$currentArticleId]["preview"]["text"], $jsonArticles[$currentArticleId]["preview"]["image"], $jsonArticles[$currentArticleId]["preview"]["imageAlt"], $jsonArticles[$currentArticleId]["tags"], $jsonArticles[$currentArticleId]["preview"]["icon"]); } ?>