Skip to content

Commit

Permalink
Updates for CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Nov 23, 2020
1 parent b5cb673 commit cf7b8b1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ composer require andrevanzuydam/tina4cms
php -S localhost:8080 index.php
```

Make the usual tina4 index.php file - we do need a database!

```
require_once "vendor/autoload.php";
global $DBA;
$DBA = new \Tina4\DataSQLite3("test.db","", "", "d/m/Y");
echo new \Tina4\Tina4Php();
```

Run the migrations

http://localhost:8080/migrate

Open up the CMS to setup the admin user

http://localhost:8080/cms/login -> will get you started

### Customization
Expand Down
32 changes: 21 additions & 11 deletions app/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public function getArticleMeta($slug) {
* @return string
* @throws \Twig\Error\LoaderError
*/
public function getSnippet($name) {
public function
getSnippet($name) {
$snippet = new Snippet();
$snippet->load("name = '{$name}'");

Expand Down Expand Up @@ -258,18 +259,23 @@ public function getMenu($parentId="", $level=0) {
$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";
$menus = $this->DBA->fetch($sql, 1000)->asObject();

foreach ($menus as $id => $menu) {
if ($menu->hasChildren > 0) {
$childrenMenus = $this->getMenu($menu->id, $level+=1);
$menu->children = $childrenMenus;
if ($this->DBA->tableExists("article_category")) {
$menus = $this->DBA->fetch($sql, 1000)->asObject();

foreach ($menus as $id => $menu) {
if ($menu->hasChildren > 0) {
$childrenMenus = $this->getMenu($menu->id, $level += 1);
$menu->children = $childrenMenus;
}
$menu->url = "/content/{$menu->slug}";

}
$menu->url = "/content/{$menu->slug}";

return $menus;
} else {
return [];
}

return $menus;
}

/**
Expand Down Expand Up @@ -332,8 +338,12 @@ public function parseContent ($content) {
* @return string|string[]
*/
public function getSnippets() {
$snippets = (new Snippet())->select("*", 1000)->AsObject();
return $snippets;
$snippets = (new Snippet())->select("*", 1000);
if (!empty($snippets)) {
return $snippets->asObject();
} else {
return [];
}
}

public function getArticlesByTag($category, $limit=1, $skip=0) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
]
},
"require": {
"andrevanzuydam/tina4php": "^v0.1.41"
"andrevanzuydam/tina4php": "^1.42"
}
}
10 changes: 6 additions & 4 deletions routes/admin.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

\Tina4\Get::add("/cms/login", function (\Tina4\Response $response) {
$users = (new Users())->select("count(id) as number")->asObject()[0];
if ($users->number === 0) {
$users = (new Users())->select("count(id) as number");

if (empty($users)) {
return (\Tina4\renderTemplate("@tina4cms/admin/setup.twig"));
} else {
return (\Tina4\renderTemplate("@tina4cms/admin/login.twig"));
Expand All @@ -19,8 +20,9 @@
});

\Tina4\Get::add("/cms/dashboard", function (\Tina4\Response $response) {
$users = (new Users())->select("count(id) as number")->asObject()[0];
if ($users->number === 0) {
$users = (new Users())->select("count(id) as number");

if (empty($users)) {
return (\Tina4\renderTemplate("@tina4cms/admin/setup.twig"));
} else {
return (\Tina4\renderTemplate("@tina4cms/admin/dashboard.twig"));
Expand Down
2 changes: 1 addition & 1 deletion templates/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>{{ title }}</title>

<meta prefix="og: https://ogp.me/ns#" property="og:title" content="Darts Group - {{ title }}"/>
<meta prefix="og: https://ogp.me/ns#" property="og:title" content="{{ title }}"/>
<meta prefix="og: https://ogp.me/ns#" property="og:type" content="website"/>
<meta prefix="og: https://ogp.me/ns#" property="og:url" content="{{ url }}"/>
<meta prefix="og: https://ogp.me/ns#" property="og:image" content="{{ image }}"/>
Expand Down

0 comments on commit cf7b8b1

Please sign in to comment.