Skip to content

Commit

Permalink
Changes to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Nov 19, 2020
1 parent 625c54e commit aa4f79b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 101 deletions.
34 changes: 10 additions & 24 deletions app/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function getArticles($category, $limit=10, $skip=0, $template="article.tw
$articles = $articles->orderBy("published_date desc")->asObject();

foreach ($articles as $id => $article) {
$articles[$id]->url = "/content/article/{$article->slug}";
$articles[$id]->content = $this->parseContent($article->content);
if (!file_exists("./cache/article-".md5($article->image).".png")) {
if ($article->image) {
Expand Down Expand Up @@ -250,40 +251,25 @@ public function getCategories($articleId=0, $parentId="") {
* @param int $level
* @return string
*/
public function getMenu($parentId="", $liClass="", $aClass="", $level=0) {

$html = "";
public function getMenu($parentId="", $level=0) {
if (!empty($parentId)) {
$filter = "where parent_id = {$parentId} and is_active = 1 and is_menu = 1 ";
} else {
$filter = "where parent_id = 0 and is_active = 1 and is_menu = 1 ";
}
$sql = "select a.*,(select count(id) from article_category where parent_id = a.id) as has_children from article_category a {$filter} order by display_order asc";
$categories = $this->DBA->fetch($sql, 1000)->asArray();
$menus = $this->DBA->fetch($sql, 1000)->asObject();

$lis = [];
foreach ($categories as $id => $category) {
if ($category["hasChildren"] > 0) {
$childrenMenus = $this->getMenu($category["id"], "", "dropdown-item", $level+=1);
$children = _ul(["class" => "dropdown-menu"], $childrenMenus );
if ($level > 1) {
$lis[] = _li(["class" => trim($liClass . " dropdown-submenu")], _a(["class" => $aClass . " dropdown-toggle", "href" => "#", "data-toggle" => "dropdown"], $category["name"]), $children);
} else {
$lis[] = _li(["class" => trim($liClass . " dropdown")], _a(["class" => $aClass . " dropdown-toggle", "href" => "#", "data-toggle" => "dropdown"], $category["name"]), $children);
}
} else {
if ($category["slug"] !== "") {
$url = "/content/".$this->getSlug($category["slug"]);
} else {
$url = "/content/".$this->getSlug($category["name"]);
}
$lis[] = _li(["class" => $liClass], _a(["class" => $aClass, "href" => $url], $category["name"]));
foreach ($menus as $id => $menu) {
if ($menu->hasChildren > 0) {
$childrenMenus = $this->getMenu($menu->id, $level+=1);
$menu->children = $childrenMenus;
}
}
$menu->url = "/content/{$menu->slug}";

$html .= _shape($lis);
}

return $html;
return $menus;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions templates/api/admin/articles/form.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<form id="articleForm" enctype="multipart/form-data" xmlns="http://www.w3.org/1999/html">
<div class="row">
<div class="form-group col-md-4">
<div class="form-group col-md-6">
<label for="title">Title</label>
<input class="form-control" type="text" name="title" placeholder="Title" value="{{ data.title }}">
</div>
<div class="form-group col-md-8">
<div class="form-group col-md-6">
<label for="description">Description</label>
<input class="form-control" type="text" name="description" placeholder="Description" value="{{ data.description }}">
</div>
Expand All @@ -16,7 +16,7 @@
<input class="form-control" type="file" name="image" placeholder="Image" value="">
</div>
{% if session.user.id %}
<div class="form-group col-md-3">
<div class="form-group col-md-6">
<label for="author">Author</label>
<input class="form-control" type="text" name="author" readonly placeholder="Author" value="{{ session.user.firstName }} {{ session.user.lastName }}">
<input type="hidden" name="userId" value="{{ session.user.id }}">
Expand Down
17 changes: 7 additions & 10 deletions templates/api/admin/pages/form.twig
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<form id="pageForm" enctype="multipart/form-data" xmlns="http://www.w3.org/1999/html">
<div class="row">
<div class="form-group col-md-4">
<label for="id">Id</label>
<input class="form-control" type="text" readonly name="id" placeholder="Id" value="{{ data.id }}">
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-6">
<label for="title">Name</label>
<input class="form-control" type="text" name="name" placeholder="Name" value="{{ data.name }}">
</div>
<div class="form-group col-md-4">
<div class="form-group col-md-6">
<label for="title">Title</label>
<input class="form-control" type="text" name="title" placeholder="Title" value="{{ data.title }}">
</div>
<div class="form-group col-md-12">
<label for="description">Description</label>
<input class="form-control" type="text" name="description" placeholder="Description" value="{{ data.description }}">
</div>
<div class="form-group col-md-2">
<img class="img-thumbnail" src="data:image/png;base64,{{ data.image }}">
</div>
<div class="form-group col-md-4">
<label for="image">Image</label>
<input class="form-control" type="file" name="image" placeholder="Image" value="">
</div>
<div class="form-group col-md-6">
<label for="description">Description</label>
<input class="form-control" type="text" name="description" placeholder="Description" value="{{ data.description }}">
</div>

<div class="form-group col-md-12">
<label for="content">Content</label>
<textarea id="contentEditor" class="form-control" name="content">{{ data.content }}</textarea>
Expand Down
7 changes: 2 additions & 5 deletions templates/article.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

{% set keywords = article.keywords|split(',') %}

<a class="badge badge-primary m-1 p-2" href="#">TAGS</a>
<a href="#">TAGS</a>
{% for keyword in keywords %}
<a class="badge badge-secondary m-1 p-2" href="/content/tags/{{ keyword | getSlug }}">{{ keyword }}</a>
<a href="/content/tags/{{ keyword | getSlug }}">{{ keyword }}</a>
{% endfor %}




<a href="/content/article/{{ article.relatedArticles[0].slug }}">Previous Article<br>
{{ article.relatedArticles[0].title }}
</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/navigation.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav>
{% set menus = Content.getMenu("") %}
<ul>
{{ menus | raw }}
</ul>
{% for menu in menus %}
<a href="{{ menu.url }}">{{ menu.name }} {% for menu in menu.children %} <a href="{{ menu.url }}">{{ menu.name }}</a> {% endfor %} </a>
{% endfor %}
</div>
</nav>
21 changes: 5 additions & 16 deletions templates/snippets/large.twig
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@

<div class="row">
<div class="col-sm-10 col-lg-9">
<h1 class="mb-3"><span>Featured Article</span></h1>
<div class="large text-center" onclick="document.location.href = '/content/article/{{ article.slug }}';">
<a class="title" href="/content/article/{{ article.slug }}">{{ article.title }}</a>
<div class="text-muted text-right">{{ article.author }} / {{ article.publishedDate }}</div>
<img src="{{ article.image }}" />
<p>{{ article.description | raw }}</p>
</div>
</div>
<div class="col-sm-2 col-lg-3 pt-2">
{{ magazine | raw }}
{% include "snippets/mailchimp.twig" %}
</div>
</div>
<h3>{{ article.title }}<br> <sub>{{ article.publishedDate }} by {{ article.author }} </sub></h3>
<a href="{{ article.url }}">
<img src="{{ article.image }}"/>
</a>
<p> {{ article.content | raw }}</p>
19 changes: 5 additions & 14 deletions templates/snippets/med-large.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@

<ul class="medium" >

<li style="list-style-type: none;">
<div class="aligncenter">
<img src="{{ article.image }}">
<h3 class="widget-title"><a href="https://dev.dartsworld.com/exclusive-bunting-wants-double-celebration/">Exclusive: Bunting Wants Double Celebration.</a></h3>
<h5>tags / author / date </h5>
</div>
</li>
<li>
<p>some text from snippet here</p>
</li>
</ul>
<h3>{{ article.title }}<br> <sub>{{ article.publishedDate }} by {{ article.author }} </sub></h3>
<a href="{{ article.url }}">
<img src="{{ article.image }}"/>
</a>
<p> {{ article.description | raw }}</p>
13 changes: 5 additions & 8 deletions templates/snippets/medium.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<div class="col-sm-3 col-lg-3">
<div class="medium" onclick="document.location.href = '/content/article/{{ article.slug }}';">
<img src="{{ article.image }}"/>
<a class="title" href="/content/article/{{ article.slug }}">{{ article.title }}</a>
<span class="d-flex flex-row justify-content-between"><strong>{{ article.author }}</strong> &nbsp;<small>{{ article.publishedDate }}</small></span>
<p>{{ article.description | raw }}</p>
</div>
</div>
<h3>{{ article.title }}<br> <sub>{{ article.publishedDate }} by {{ article.author }} </sub></h3>
<a href="{{ article.url }}">
<img src="{{ article.image }}"/>
</a>
<p> {{ article.description | raw }}</p>
14 changes: 5 additions & 9 deletions templates/snippets/mini.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<div class="col-sm-3 col-lg-3">
<div class="mini row" onclick="document.location.href = '/content/article/{{ article.slug }}';">
<div class="col text-right"><img src="{{ article.image }}" /></div>
<div class="col flex-column">
<h5><a href="/content/article/{{ article.slug }}">{{ article.title }}</a></h5>
<cite class="text-muted"><small>{{ article.publishedDate }}</small></cite>
</div>
</div>
</div>
<h3>{{ article.title }}<br> <sub>{{ article.publishedDate }} by {{ article.author }} </sub></h3>
<a href="{{ article.url }}">
<img src="{{ article.image }}"/>
</a>
<p> {{ article.description | raw }}</p>
17 changes: 8 additions & 9 deletions templates/snippets/small.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<div class="col-sm-6 col-lg-6">
<div class="small" onclick="document.location.href = '/content/article/{{ article.slug }}';">
<img src="{{ article.image }}" />
<div class="px-2">
<a class="title" href="/content/article/{{ article.slug }}">{{ article.title }}</a>
<p><span class="d-block"><strong>{{ article.publishedDate }}</strong></span>{{ article.description | raw }}</p>
</div>
</div>
</div>
<h3>{{ article.title }}<br> <sub>{{ article.publishedDate }} by {{ article.author }} </sub></h3>
<a href="{{ article.url }}">
<img src="{{ article.image }}"/>
</a>
<p> {{ article.description | raw }}</p>



0 comments on commit aa4f79b

Please sign in to comment.