From 656c39ec736441543698c7aa7fec7b2bca75779b Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Mon, 11 Jul 2016 22:21:24 -0400 Subject: [PATCH] add faq categories, fix up a few faqs --- controller/action/ContentActions.class.php | 22 +++++++++- model/Post.class.php | 47 +++++++++++++--------- posts/faq/api-help.md | 23 ++++++++--- posts/faq/how-to-check-mining-balance.md | 4 +- view/template/content/_postNav.php | 26 ++++++++++++ view/template/content/faq.php | 11 +++-- view/template/content/post.php | 39 +++--------------- 7 files changed, 109 insertions(+), 63 deletions(-) create mode 100644 view/template/content/_postNav.php diff --git a/controller/action/ContentActions.class.php b/controller/action/ContentActions.class.php index 458aa38d..e29e41bd 100644 --- a/controller/action/ContentActions.class.php +++ b/controller/action/ContentActions.class.php @@ -24,8 +24,28 @@ class ContentActions extends Actions public static function executeFaq() { $posts = Post::find(static::VIEW_FOLDER_FAQ); + + $groupNames = [ + 'getstarted' => 'Getting Started', + 'install' => 'Installing LBRY', + 'running' => 'Running LBRY', + 'wallet' => 'The LBRY Wallet', + 'hosting' => 'Hosting Content', + 'mining' => 'Mining LBC', + 'developer' => 'Developers', + 'other' => 'Other Questions', + ]; + + $groups = array_fill_keys(array_keys($groupNames), []); + + foreach($posts as $post) + { + $groups[isset($groupNames[$post->getCategory()]) ? $post->getCategory() : 'other'][] = $post; + } + return ['content/faq', [ - 'posts' => $posts + 'groupNames' => $groupNames, + 'postGroups' => $groups ]]; } diff --git a/model/Post.class.php b/model/Post.class.php index 4601c539..41f64d95 100644 --- a/model/Post.class.php +++ b/model/Post.class.php @@ -5,7 +5,7 @@ class Post const SORT_DATE_DESC = 'sort_date_desc'; protected static $slugMap = []; - protected $slug, $title, $author, $date, $markdown, $contentText, $contentHtml, $cover, $category; + protected $slug, $title, $author, $date, $markdown, $contentText, $contentHtml, $cover, $postType, $category; protected $isCoverLight = false; public static function load($relativeOrAbsolutePath) @@ -15,7 +15,7 @@ class Post { throw new LogicException('Cannot load a post without a path.'); } - $category = $pathTokens[count($pathTokens) - 2]; + $postType = $pathTokens[count($pathTokens) - 2]; $filename = $pathTokens[count($pathTokens) - 1]; $isRelative = $relativeOrAbsolutePath[0] != '/'; $slug = strpos($filename, '.md') !== false ? static::getSlugFromFilename($filename) : $filename; @@ -27,7 +27,7 @@ class Post { if ($isRelative) { - $slugMap = static::getSlugMap($category); + $slugMap = static::getSlugMap($postType); if (isset($slugMap[$slug])) { return static::load($slugMap[$slug]); @@ -37,12 +37,12 @@ class Post } list($ignored, $frontMatter, $content) = explode('---', file_get_contents($path), 3); - return new static($category, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content)); + return new static($postType, $slug, Spyc::YAMLLoadString(trim($frontMatter)), trim($content)); } - public function __construct($category, $slug, $frontMatter, $markdown) + public function __construct($postType, $slug, $frontMatter, $markdown) { - $this->category = $category; + $this->postType = $postType; $this->slug = $slug; $this->markdown = $markdown; $this->title = isset($frontMatter['title']) ? $frontMatter['title'] : null; @@ -50,6 +50,7 @@ class Post $this->date = isset($frontMatter['date']) ? new DateTime($frontMatter['date']) : null; $this->cover = isset($frontMatter['cover']) ? $frontMatter['cover'] : null; $this->isCoverLight = isset($frontMatter['cover-light']) && $frontMatter['cover-light'] == 'true'; + $this->category = isset($frontMatter['category']) ? $frontMatter['category'] : null; } public static function find($folder, $sort = null) @@ -75,7 +76,7 @@ class Post public function getRelativeUrl() { - return $this->category . '/' . $this->slug; + return $this->postType . '/' . $this->slug; } public function getSlug() @@ -108,6 +109,11 @@ class Post return $this->isCoverLight; } + public function getCategory() + { + return $this->category; + } + public function getContentText($wordLimit = null, $appendEllipsis = false) { if ($this->markdown && !$this->contentText) @@ -130,21 +136,21 @@ class Post public function getPostNum() { - return array_search($this->getSlug(), array_keys(static::getSlugMap($this->category))); + return array_search($this->getSlug(), array_keys(static::getSlugMap($this->postType))); } public function getPrevPost() { - $slugs = array_keys(Post::getSlugMap($this->category)); + $slugs = array_keys(Post::getSlugMap($this->postType)); $postNum = $this->getPostNum(); - return $postNum === false || $postNum === 0 ? null : Post::load($this->category . '/' . $slugs[$postNum-1]); + return $postNum === false || $postNum === 0 ? null : Post::load($this->postType . '/' . $slugs[$postNum-1]); } public function getNextPost() { - $slugs = array_keys(Post::getSlugMap($this->category)); + $slugs = array_keys(Post::getSlugMap($this->postType)); $postNum = $this->getPostNum(); - return $postNum === false || $postNum >= count($slugs)-1 ? null : Post::load($this->category . '/' . $slugs[$postNum+1]); + return $postNum === false || $postNum >= count($slugs)-1 ? null : Post::load($this->postType . '/' . $slugs[$postNum+1]); } public function hasAuthor() @@ -157,6 +163,11 @@ class Post return $this->date !== null; } + public function hasPrevNext() + { + return $this->postType == 'post'; + } + public function getAuthorName() { switch(strtolower($this->author)) @@ -298,16 +309,16 @@ class Post return strtolower(preg_replace('#^\d+\-#', '', basename(trim($filename), '.md'))); } - public static function getSlugMap($category) + public static function getSlugMap($postType) { - if (!isset(static::$slugMap[$category])) + if (!isset(static::$slugMap[$postType])) { - static::$slugMap[$category] = []; - foreach(glob(ROOT_DIR . '/posts/' . $category . '/*.md') as $file) + static::$slugMap[$postType] = []; + foreach(glob(ROOT_DIR . '/posts/' . $postType . '/*.md') as $file) { - static::$slugMap[$category][static::getSlugFromFilename($file)] = $file; + static::$slugMap[$postType][static::getSlugFromFilename($file)] = $file; } } - return static::$slugMap[$category]; + return static::$slugMap[$postType]; } } \ No newline at end of file diff --git a/posts/faq/api-help.md b/posts/faq/api-help.md index 7302776d..a11f5160 100644 --- a/posts/faq/api-help.md +++ b/posts/faq/api-help.md @@ -3,17 +3,30 @@ title: How do I see the list of API functions I can call, and how do I call them category: developer --- -Here is an example script to get the documentation for the various API calls. To use any of the functions displayed, just provide any specified arguments in a dictionary. Many (though not all) of the calls are the same as those for bitcoin core, which are documented [here](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list). +Ensure that `lbrycrd` is running with the `-server` flag, which enables the JSON-RPC API. Then use one of the following methods to make API calls. -If for some reason you can't get lbrycrd-cli working to make these calls, make sure you passed -server when starting lbrycrd. If it still doesn't work, you can use this command: +Many (though not all) of the calls are the same as those for bitcoin core, which are +documented [here](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list). To see the full list of API calls, use the `help` API call. - curl --user USER:PASSWORD --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "COMMAND", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:9245/ +## lbrycrd-cli -USER and PASSWORD can be found in your lbrycrd.conf file, COMMAND can be any of the supported methods like getbalance or getnewaddress. 9245 is the default port used, but if you chose a custom port for the server, you'll need to use that instead. If the command accepts parameters, they can be passed inside the params array []. + lbrycrd-cli help + +## curl + + curl --user USER:PASSWORD --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "help", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:9245/ + +- `USER` and `PASSWORD` can be found in your lbrycrd.conf file. +- The `method` field can be any of the supported methods like `getbalance` or `getnewaddress`. +- `9245` is the default port used, but if you chose a custom port for the server, you'll need to use that instead. +- If the command accepts parameters, they can be passed inside the `params` array. See Also: [important directories](https://lbry.io/faq/lbry-directories). -Note: the LBRY API can only be used while either the app or lbrynet-daemon is running. +## Python + +Here is an example script to get the documentation for the various API calls. +To use any of the functions displayed, just provide any specified arguments in a dictionary. import sys from jsonrpc.proxy import JSONRPCProxy diff --git a/posts/faq/how-to-check-mining-balance.md b/posts/faq/how-to-check-mining-balance.md index 077e7842..102869f5 100644 --- a/posts/faq/how-to-check-mining-balance.md +++ b/posts/faq/how-to-check-mining-balance.md @@ -3,4 +3,6 @@ title: How do I check my mining balance? category: mining --- -You can use `lbrycrd-cli getbalance`, or `lbrycrd-cli getwalletinfo` for more detailed information. It takes 100 confirmed blocks (roughly a bit over 4 hours) for mined LBC to show up in your confirmed balance, but you can see these credits in your immature balance in getwalletinfo. +You can use `lbrycrd-cli getbalance`, or `lbrycrd-cli getwalletinfo` for more detailed information. +It takes 100 confirmed blocks (roughly a bit over 4 hours) for mined LBC to show up in your confirmed balance, +but you can see these credits in your immature balance in getwalletinfo. diff --git a/view/template/content/_postNav.php b/view/template/content/_postNav.php new file mode 100644 index 00000000..eca06397 --- /dev/null +++ b/view/template/content/_postNav.php @@ -0,0 +1,26 @@ + diff --git a/view/template/content/faq.php b/view/template/content/faq.php index 5627f661..c649e740 100644 --- a/view/template/content/faq.php +++ b/view/template/content/faq.php @@ -3,10 +3,13 @@

Frequently Asked Questions

- - + $posts): ?> +

+ + +
diff --git a/view/template/content/post.php b/view/template/content/post.php index b31746c3..b73e9a55 100644 --- a/view/template/content/post.php +++ b/view/template/content/post.php @@ -19,45 +19,16 @@
-
-
- getContentHtml() ?> -
+ getContentHtml() ?>
- - + hasPrevNext()): ?> + $post]) ?> +
hasAuthor()): ?> - $post - ]) ?> + $post]) ?>