From 90850390f195231b7355716f7e5bcf85edc5a93d Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Mon, 3 Sep 2012 16:25:18 -0700 Subject: [PATCH] getting tags working. --- content/log/islands | 1 + content/log/overlords | 1 + content/log/temple | 1 + content/log/water_is_life | 2 +- content/projects/mask | 1 + content/projects/prism | 1 + data/content/data.json | 1 + data/content/log/data.json | 1 + data/content/log/tags.json | 1 + data/content/projects/data.json | 1 + data/content/projects/tags.json | 1 + data/content/tags.json | 1 + data/tags.json | 1 + lib/config.ini | 1 + lib/data.php | 54 ++++++++++++++++++++++++++++++++- lib/init.php | 1 + lib/test/data_test.php | 14 +++++++-- pages/tag | 30 ++++++++++++++++++ 18 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 data/content/data.json create mode 100644 data/content/log/data.json create mode 100644 data/content/log/tags.json create mode 100644 data/content/projects/data.json create mode 100644 data/content/projects/tags.json create mode 100644 data/content/tags.json create mode 100644 data/tags.json create mode 100644 pages/tag diff --git a/content/log/islands b/content/log/islands index e3fd573..93288d1 100644 --- a/content/log/islands +++ b/content/log/islands @@ -1,5 +1,6 @@ title = islands date = Oct 05 2011, 03:53:55 PM +tags = writing quote -- > Imagine that every man's mind is an island, surrounded by ocean. Each seems isolated, yet in reality all are linked by the bedrock from which they spring. If the ocean were to vanish, that would be the end of the islands. They would all be part of one continent, but their individuality would be gone. diff --git a/content/log/overlords b/content/log/overlords index a8a052c..e949c3d 100644 --- a/content/log/overlords +++ b/content/log/overlords @@ -1,5 +1,6 @@ title = childhoods end date = Oct 05 2011, 03:17:57 PM +tags = india quote -- > The case of India is particularly instructive. The main difference between us and the British in India was that they had no real motives for going there—no conscious objectives, that is, except such trivial and temporary ones as trade or hostility to other European powers. They found themselves possessors of an empire before they knew what to do with it, and were never really happy until they had got rid of it again. diff --git a/content/log/temple b/content/log/temple index 915bef5..e56d25a 100644 --- a/content/log/temple +++ b/content/log/temple @@ -1,5 +1,6 @@ date = feb 20 2012 title = temple +tags = photo -- diff --git a/content/log/water_is_life b/content/log/water_is_life index 8249c81..b04bcc7 100644 --- a/content/log/water_is_life +++ b/content/log/water_is_life @@ -1,6 +1,6 @@ title = Water Is Life date = Oct 23 2011 06:04:38 PM -draft = 1 +tags = water photo -- diff --git a/content/projects/mask b/content/projects/mask index d72fb40..5a5a98b 100644 --- a/content/projects/mask +++ b/content/projects/mask @@ -1,6 +1,7 @@ title = mask date = 2007-07-02 thumb = http://portfolio.quilime.com/2008/mask/thumb.png +tags = mask painting -- diff --git a/content/projects/prism b/content/projects/prism index ea834a3..ae5806a 100644 --- a/content/projects/prism +++ b/content/projects/prism @@ -1,6 +1,7 @@ title = prism date = 2007-08-23 thumb = http://portfolio.quilime.com/2008/prism/thumb.png +tags = prism painting -- diff --git a/data/content/data.json b/data/content/data.json new file mode 100644 index 0000000..8ca625c --- /dev/null +++ b/data/content/data.json @@ -0,0 +1 @@ +{"entries":[{"config":{"date":"feb 20 2012","title":"temple","tags":"photo"},"title":"temple","filename":"temple","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/temple","fileInfo":{},"timestamp":"1329724800","tags":["photo"],"content":"

\n \n<\/a><\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/temple\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"og","url":"log\/"},"media":"media\/\/og\/temple\/","thumb":"media\/\/og\/temple\/thumb.png","url":"\/og\/temple"},{"config":{"title":"Water Is Life","date":"Oct 23 2011 06:04:38 PM","tags":"water photo"},"title":"Water Is Life","filename":"water_is_life","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/water_is_life","fileInfo":{},"timestamp":"1319418278","tags":["water","photo"],"content":"

<\/a><\/p>\n\n

near Quotar Minar in Dadabari.<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/water_is_life\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"og","url":"log\/"},"media":"media\/\/og\/water_is_life\/","thumb":"media\/\/og\/water_is_life\/thumb.png","url":"\/og\/water_is_life"},{"config":{"title":"islands","date":"Oct 05 2011, 03:53:55 PM","tags":"writing quote"},"title":"islands","filename":"islands","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/islands","fileInfo":{},"timestamp":"1317855235","tags":["writing","quote"],"content":"

\n

Imagine that every man's mind is an island, surrounded by ocean. Each seems isolated, yet in reality all are linked by the bedrock from which they spring. If the ocean were to vanish, that would be the end of the islands. They would all be part of one continent, but their individuality would be gone.<\/p>\n \n

—\"The Inspector\" Overlord. Childhoods End<\/u>, Arthur C. Clark. p.176<\/p>\n<\/blockquote>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/islands\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"og","url":"log\/"},"media":"media\/\/og\/islands\/","thumb":"media\/\/og\/islands\/thumb.png","url":"\/og\/islands"},{"config":{"title":"childhoods end","date":"Oct 05 2011, 03:17:57 PM","tags":"india quote"},"title":"childhoods end","filename":"overlords","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/overlords","fileInfo":{},"timestamp":"1317853077","tags":["india","quote"],"content":"

\n

The case of India is particularly instructive. The main difference between us and the British in India was that they had no real motives for going there—no conscious objectives, that is, except such trivial and temporary ones as trade or hostility to other European powers. They found themselves possessors of an empire before they knew what to do with it, and were never really happy until they had got rid of it again.<\/p>\n \n

—\"The Inspector\" Overlord. Childhoods End<\/u>, Arthur C. Clark. p.161<\/p>\n<\/blockquote>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/overlords\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"og","url":"log\/"},"media":"media\/\/og\/overlords\/","thumb":"media\/\/og\/overlords\/thumb.png","url":"\/og\/overlords"},{"config":{"title":"prism","date":"2007-08-23","thumb":"http:\/\/portfolio.quilime.com\/2008\/prism\/thumb.png","tags":"prism painting"},"title":"prism","filename":"prism","path":"\/Users\/gdunne\/_code\/plog\/content\/projects\/prism","fileInfo":{},"timestamp":"1187852400","tags":["prism","painting"],"content":"

<\/p>\n\n

oil on canvas. 4' x 3'<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/projects\/prism\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"rojects","url":"projects\/"},"media":"media\/\/rojects\/prism\/","thumb":"http:\/\/portfolio.quilime.com\/2008\/prism\/thumb.png","url":"\/rojects\/prism"},{"config":{"title":"mask","date":"2007-07-02","thumb":"http:\/\/portfolio.quilime.com\/2008\/mask\/thumb.png","tags":"mask painting"},"title":"mask","filename":"mask","path":"\/Users\/gdunne\/_code\/plog\/content\/projects\/mask","fileInfo":{},"timestamp":"1183359600","tags":["mask","painting"],"content":"

<\/p>\n\n

graphite on plywood. 12\" x 12\"<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/projects\/mask\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"rojects","url":"projects\/"},"media":"media\/\/rojects\/mask\/","thumb":"http:\/\/portfolio.quilime.com\/2008\/mask\/thumb.png","url":"\/rojects\/mask"}]} \ No newline at end of file diff --git a/data/content/log/data.json b/data/content/log/data.json new file mode 100644 index 0000000..dacb6fe --- /dev/null +++ b/data/content/log/data.json @@ -0,0 +1 @@ +{"entries":[{"config":{"date":"feb 20 2012","title":"temple","tags":"photo"},"title":"temple","filename":"temple","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/temple","fileInfo":{},"timestamp":"1329724800","tags":["photo"],"content":"

\n \n<\/a><\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/temple\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"log","url":"\/log\/"},"media":"media\/\/log\/temple\/","thumb":"media\/\/log\/temple\/thumb.png","url":"\/log\/temple"},{"config":{"title":"Water Is Life","date":"Oct 23 2011 06:04:38 PM","tags":"water photo"},"title":"Water Is Life","filename":"water_is_life","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/water_is_life","fileInfo":{},"timestamp":"1319418278","tags":["water","photo"],"content":"

<\/a><\/p>\n\n

near Quotar Minar in Dadabari.<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/water_is_life\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"log","url":"\/log\/"},"media":"media\/\/log\/water_is_life\/","thumb":"media\/\/log\/water_is_life\/thumb.png","url":"\/log\/water_is_life"},{"config":{"title":"islands","date":"Oct 05 2011, 03:53:55 PM","tags":"writing quote"},"title":"islands","filename":"islands","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/islands","fileInfo":{},"timestamp":"1317855235","tags":["writing","quote"],"content":"

\n

Imagine that every man's mind is an island, surrounded by ocean. Each seems isolated, yet in reality all are linked by the bedrock from which they spring. If the ocean were to vanish, that would be the end of the islands. They would all be part of one continent, but their individuality would be gone.<\/p>\n \n

—\"The Inspector\" Overlord. Childhoods End<\/u>, Arthur C. Clark. p.176<\/p>\n<\/blockquote>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/islands\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"log","url":"\/log\/"},"media":"media\/\/log\/islands\/","thumb":"media\/\/log\/islands\/thumb.png","url":"\/log\/islands"},{"config":{"title":"childhoods end","date":"Oct 05 2011, 03:17:57 PM","tags":"india quote"},"title":"childhoods end","filename":"overlords","path":"\/Users\/gdunne\/_code\/plog\/content\/log\/overlords","fileInfo":{},"timestamp":"1317853077","tags":["india","quote"],"content":"

\n

The case of India is particularly instructive. The main difference between us and the British in India was that they had no real motives for going there—no conscious objectives, that is, except such trivial and temporary ones as trade or hostility to other European powers. They found themselves possessors of an empire before they knew what to do with it, and were never really happy until they had got rid of it again.<\/p>\n \n

—\"The Inspector\" Overlord. Childhoods End<\/u>, Arthur C. Clark. p.161<\/p>\n<\/blockquote>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/log\/overlords\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"log","url":"\/log\/"},"media":"media\/\/log\/overlords\/","thumb":"media\/\/log\/overlords\/thumb.png","url":"\/log\/overlords"}]} \ No newline at end of file diff --git a/data/content/log/tags.json b/data/content/log/tags.json new file mode 100644 index 0000000..da87f8a --- /dev/null +++ b/data/content/log/tags.json @@ -0,0 +1 @@ +{"tags":{"photo":2,"water":1,"writing":1,"quote":2,"india":1}} \ No newline at end of file diff --git a/data/content/projects/data.json b/data/content/projects/data.json new file mode 100644 index 0000000..acde96c --- /dev/null +++ b/data/content/projects/data.json @@ -0,0 +1 @@ +{"entries":[{"config":{"title":"prism","date":"2007-08-23","thumb":"http:\/\/portfolio.quilime.com\/2008\/prism\/thumb.png","tags":"prism painting"},"title":"prism","filename":"prism","path":"\/Users\/gdunne\/_code\/plog\/content\/projects\/prism","fileInfo":{},"timestamp":"1187852400","tags":["prism","painting"],"content":"

<\/p>\n\n

oil on canvas. 4' x 3'<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/projects\/prism\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"projects","url":"\/projects\/"},"media":"media\/\/projects\/prism\/","thumb":"http:\/\/portfolio.quilime.com\/2008\/prism\/thumb.png","url":"\/projects\/prism"},{"config":{"title":"mask","date":"2007-07-02","thumb":"http:\/\/portfolio.quilime.com\/2008\/mask\/thumb.png","tags":"mask painting"},"title":"mask","filename":"mask","path":"\/Users\/gdunne\/_code\/plog\/content\/projects\/mask","fileInfo":{},"timestamp":"1183359600","tags":["mask","painting"],"content":"

<\/p>\n\n

graphite on plywood. 12\" x 12\"<\/p>\n","comments_enabled":false,"comments":{"comments":[],"comments_loc":"\/Users\/gdunne\/_code\/plogcomments\/\/Users\/gdunne\/_code\/plog\/content\/projects\/mask\/","fileInfo":{},"_recaptcha_resp":null,"_recaptcha_error":null,"_comment_error":null},"cat":{"name":"projects","url":"\/projects\/"},"media":"media\/\/projects\/mask\/","thumb":"http:\/\/portfolio.quilime.com\/2008\/mask\/thumb.png","url":"\/projects\/mask"}]} \ No newline at end of file diff --git a/data/content/projects/tags.json b/data/content/projects/tags.json new file mode 100644 index 0000000..7a2a5ff --- /dev/null +++ b/data/content/projects/tags.json @@ -0,0 +1 @@ +{"tags":{"prism":1,"painting":2,"mask":1}} \ No newline at end of file diff --git a/data/content/tags.json b/data/content/tags.json new file mode 100644 index 0000000..1d66e51 --- /dev/null +++ b/data/content/tags.json @@ -0,0 +1 @@ +{"tags":{"photo":2,"water":1,"writing":1,"quote":2,"india":1,"prism":1,"painting":2,"mask":1}} \ No newline at end of file diff --git a/data/tags.json b/data/tags.json new file mode 100644 index 0000000..1d66e51 --- /dev/null +++ b/data/tags.json @@ -0,0 +1 @@ +{"tags":{"photo":2,"water":1,"writing":1,"quote":2,"india":1,"prism":1,"painting":2,"mask":1}} \ No newline at end of file diff --git a/lib/config.ini b/lib/config.ini index 0e5b84a..919a806 100644 --- a/lib/config.ini +++ b/lib/config.ini @@ -19,6 +19,7 @@ media = media/ config_file = config data_file = data.json +tags_file = tags.json diff --git a/lib/data.php b/lib/data.php index 87fb90a..1888d80 100644 --- a/lib/data.php +++ b/lib/data.php @@ -74,7 +74,7 @@ function get_entries( $path = "", $args = array() ) fwrite($fp, json_encode(array( 'entries' => $entries ))); fclose($fp); if (!file_exists( $data_file )) { - throw new Exception('Error creating tags json. Permissions?'); + throw new Exception('Error creating data json. Permissions?'); } } } @@ -146,6 +146,58 @@ function get_pages() } +/** + * get tags + */ +function get_tags($path = "", $args = array() ) +{ + + $data_path = rtrim(LOCAL_ROOT . '/' . DATA_DIR . '/' . CONTENT_DIR . '/' . $path, '/'); + $data_file = rtrim($data_path . '/' . TAGS_FILE, '/'); + + if (DEV || !file_exists($data_file)) { + + $create_datafile = true; + + $entries = get_entries($path, $args); + $tags = array(); + + foreach($entries as $entry) { + $entry_tags = isset($entry->tags) && is_array($entry->tags) ? $entry->tags : array(); + $tags = array_merge($tags, $entry_tags); + } + + $tags = array_count_values($tags); + + + if ($create_datafile) { + if (!is_dir($data_path)) { + if (!mkdir($data_path, 0777, true)) { + throw new Exception('Error making data folder in get_tags(). Permissions?'); + } + } + $fp = fopen( $data_file, 'w'); + fwrite($fp, json_encode(array( 'tags' => $tags ))); + fclose($fp); + if (!file_exists( $data_file )) { + throw new Exception('Error creating tags json in get_tags(). Permissions?'); + } + } + + + // $fp = fopen( $data_file, 'w'); + // fwrite($fp, json_encode(array( 'tags' => $tags ))); + // fclose($fp); + // if (!file_exists( $data_file)) { + // throw new Exception('Error creating tags.json. Permissions?'); + // } + } + + $json = json_decode(file_get_contents($data_file)); + return (array) $json->tags; +} + + /** * @param splFileInfo SPLFileInfo Object * @param page default is false diff --git a/lib/init.php b/lib/init.php index 7533d56..74f228f 100644 --- a/lib/init.php +++ b/lib/init.php @@ -36,6 +36,7 @@ define ('COMMENTS_DIR', $_cfg['comments']); define ('DATA_DIR', $_cfg['data']); define ('MEDIA_DIR', $_cfg['media']); define ('DATA_FILE', $_cfg['data_file']); +define ('TAGS_FILE', $_cfg['tags_file']); define ('TEMPLATE_DIR', $_cfg['templates']); define ('PAGE_DIR', $_cfg['pages']); define ('CONFIG_DELIMITER', $_cfg['config_delim']); diff --git a/lib/test/data_test.php b/lib/test/data_test.php index 5053ee6..9bc1b00 100644 --- a/lib/test/data_test.php +++ b/lib/test/data_test.php @@ -5,9 +5,6 @@ class DataTest extends UnitTestCase { function test_GettingEntriesArray() { $entries = get_entries('/'); $this->assertTrue(is_array($entries)); - } - - function test_EntryFolderNotExist() { $this->expectException( new Exception("Directory does not exist") ); get_entries('sdfs'); } @@ -22,6 +19,17 @@ class DataTest extends UnitTestCase { $this->assertTrue(is_array($dirs)); } + function test_GettingTagsArray() { + $tags = get_tags(); + $this->assertTrue(is_array($tags)); + $tags = get_tags('log/'); + $this->assertTrue(is_array($tags)); + $tags = get_tags('projects/'); + $this->assertTrue(is_array($tags)); + $this->expectException( new Exception("Directory does not exist") ); + $tags = get_tags('asdf/'); + } + function test_getEntryIsFileObj() { $this->assertIsA(get_entry('/projects/prism'), 'stdClass'); } diff --git a/pages/tag b/pages/tag new file mode 100644 index 0000000..ef0c764 --- /dev/null +++ b/pages/tag @@ -0,0 +1,30 @@ +title = tag +-- + + + + $tag)); ?> + +content_short)) +$entry->content = $entry->content_short . +'
more →

'; +?> + +

+include_template('entry.html.tpl', array('entry' => $entry)); ?> +
+ + + + + + +
    + + $count) : ?> +
  • ×
  • + +
+ + -- 2.34.1