aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/model/HTMLExtract.php64
-rw-r--r--app/views/index.view.php66
2 files changed, 92 insertions, 38 deletions
diff --git a/app/model/HTMLExtract.php b/app/model/HTMLExtract.php
new file mode 100644
index 0000000..5c3f727
--- /dev/null
+++ b/app/model/HTMLExtract.php
@@ -0,0 +1,64 @@
+<?php
+
+class DOMExtract extends DOMDocument
+{
+ private $source;
+ private $document;
+
+ public function __construct()
+ {
+ libxml_use_internal_errors(true);
+ $this->preserveWhiteSpace = false;
+ $this->strictErrorChecking = false;
+ $this->formatOutput = true;
+ }
+
+ public function setSource($source)
+ {
+ $this->source = file_get_contents($source);
+ return $this;
+ }
+
+ public function getInnerHTML($tag, $id=null, $nodeValue = false)
+ {
+ if (empty($this->source)) {
+ throw new Exception('Error: Missing $this->source, use setSource() first');
+ }
+
+ $html = null;
+ $this->loadHTML($this->source);
+ $element = $this->getElementsByTagName($tag);
+
+ foreach ($element as $tags) {
+ if ($id !== null) {
+ $attr = explode('=', $id);
+ if ($tags->getAttribute($attr[0]) == $attr[1]) {
+ if ($nodeValue == true) {
+ $html .= trim($tags->nodeValue);
+ } else {
+ $html .= $this->innerHTML($tags);
+ }
+ }
+ } else {
+ if ($nodeValue == true) {
+ $html .= trim($tags->nodeValue);
+ } else {
+ $html .= $this->innerHTML($tags);
+ }
+ }
+ }
+ return $html;
+ }
+
+ protected function innerHTML($document)
+ {
+ $html = "";
+ foreach ($document->childNodes as $v) {
+ $tmp = new DOMDocument();
+ $tmp->appendChild($tmp->importNode($v, true));
+ $html .= trim($tmp->saveHTML());
+ }
+ return $html;
+ }
+
+}
diff --git a/app/views/index.view.php b/app/views/index.view.php
index bff5b9c..6c6fb59 100644
--- a/app/views/index.view.php
+++ b/app/views/index.view.php
@@ -40,53 +40,43 @@
</div>
- <div class="columns">
+ <div class="recent__article">
- <div class="column has-text-centered has-text-left-mobile">
- <div class="front__textbox has-text-left is-inline-block">
+ <h1 class="title has-text-weight-normal">Recent Posts</h1>
- <h3 class="has-text-dark is-marginless is-size-5">
- Recent Posts
- </h3>
+ <?php
+ $recentPosts = new DOMExtract();
+ $recentPosts->setSource($_SERVER['DOCUMENT_ROOT'] . '/post/index.html');
+ echo $recentPosts->getInnerHTML('recent-article');
+ ?>
- <?php
- $recent_posts = file($_SERVER['DOCUMENT_ROOT'] . '/post/index.html');
- foreach (range(count($recent_posts) - 32, count($recent_posts) - 24) as $line) {
- echo $recent_posts[$line];
- }
- ?>
+ <a href="/post/"
+ class="front__more is-block has-text-right has-text-centered-mobile">
+ See All Posts
+ <?php echo file_get_contents($_SERVER['DOCUMENT_ROOT']
+ . '/..' . '/public/css/fonts/feather-icons/chevron-right.svg') ?>
+ </a>
- <br>
- <br>
-
- <a class="front__frame is-inline-block" href="post/">More posts <span class="icon">➤</span></a>
-
- </div>
- </div>
-
- <div class="column has-text-centered has-text-left-mobile">
- <div class="front__textbox has-text-left is-inline-block">
-
- <h3 class="has-text-dark is-marginless is-size-5">
- Recent Projects
- </h3>
+ <br>
- <?php
- $recent_projects = file($_SERVER['DOCUMENT_ROOT'] . '/post/index.html');
- foreach (range(count($recent_projects) - 15, count($recent_projects) - 7) as $line) {
- echo $recent_projects[$line];
- }
- ?>
+ <h1 class="title has-text-weight-normal">Recent Projects</h1>
- <br>
- <br>
+ <?php
+ $recentProjects = new DOMExtract();
+ $recentProjects->setSource($_SERVER['DOCUMENT_ROOT'] . '/project/index.html');
+ echo $recentProjects->getInnerHTML('recent-article');
+ ?>
+ </div>
- <a class="front__frame is-inline-block" href="project/">More projects <span class="icon">➤</span></a>
+ <a href="/project/"
+ class="front__more is-block has-text-right has-text-centered-mobile">
+ See All Projects
+ <?php echo file_get_contents($_SERVER['DOCUMENT_ROOT']
+ . '/..' . '/public/css/fonts/feather-icons/chevron-right.svg') ?>
+ </a>
- </div>
- </div>
+ <br>
- </div>
</div>
</div>
</div>