diff --git a/src/book/src/Controller/Admin/ArticleController.php b/src/book/src/Controller/Admin/ArticleController.php index 5f9f97f..e026817 100644 --- a/src/book/src/Controller/Admin/ArticleController.php +++ b/src/book/src/Controller/Admin/ArticleController.php @@ -46,7 +46,6 @@ public function editAction() array( 'id' => $id, 'bid' => $this->params('bid'), - 'cdid' => $this->params('cdid'), 'title' => $row['title'], 'content' => $row['content'], )); diff --git a/src/book/src/Controller/Front/ArticleController.php b/src/book/src/Controller/Front/ArticleController.php index 5a1401c..06341e0 100644 --- a/src/book/src/Controller/Front/ArticleController.php +++ b/src/book/src/Controller/Front/ArticleController.php @@ -12,6 +12,7 @@ use \Zend\Db\Sql\Select; use Pi\Mvc\Controller\ActionController; +use Module\Book\XmlToHtml; /** * Article controller @@ -21,17 +22,16 @@ class ArticleController extends ActionController public function viewAction() { $bid = $this->params('bid'); - $cdid = $this->params('cdid'); - $id = $this->params('id'); $row = $this->getModel('article')->find($id); if ($row != null) { - $article = $row->toArray(); + $articleXml = $row->toArray(); + $converter = new XmlToHtml; + $articleHtml = $converter->parse($articleXml['content']); + $this->view()->assign('article', $articleHtml); } - $this->view()->assign('bid', $bid); - $this->view()->assign('cdid', $cdid); - $this->view()->assign('article', $article); + $this->view()->assign('bid', $bid); $this->view()->setTemplate('article-view'); } diff --git a/src/book/src/Controller/Front/IndexController.php b/src/book/src/Controller/Front/IndexController.php index 9bb4b6c..c007e70 100755 --- a/src/book/src/Controller/Front/IndexController.php +++ b/src/book/src/Controller/Front/IndexController.php @@ -25,6 +25,33 @@ public function indexAction() 'controller' => 'Book', 'action' => 'list' ) - ); + ); + } + + public function resetpasswordAction() + { + $request = $this->getRequest(); + + // Make sure that we are running in a console and the user has not tricked our + // application into running this action from a public web server. + if (!$request instanceof ConsoleRequest){ + throw new \RuntimeException('You can only use this action from a console!'); + } + + // Get user email from console and check if the user used --verbose or -v flag + $userEmail = $request->getParam('userEmail'); + $verbose = $request->getParam('verbose'); + + // reset new password + $newPassword = Rand::getString(16); + + // Fetch the user and change his password, then email him ... + // [...] + + if (!$verbose){ + return "Done! $userEmail has received an email with his new password.\n"; + }else{ + return "Done! New password for user $userEmail is '$newPassword'. It has also been emailed to him. \n"; + } } } diff --git a/src/book/src/Form/ArticleForm.php b/src/book/src/Form/ArticleForm.php index f786b11..fbb4f4d 100644 --- a/src/book/src/Form/ArticleForm.php +++ b/src/book/src/Form/ArticleForm.php @@ -25,19 +25,32 @@ public function init() { ), )); - $editorConfig = Pi::config()->load("module.article.ckeditor.php"); - $editorConfig['editor'] = 'html'; - $editorConfig['set'] = ''; - $this->add(array( 'name' => 'content', + 'options' => array( + 'label' => __('Content'), + ), 'attributes' => array( - 'type' => 'editor', - + 'type' => 'textarea', + 'placeholder' => __('Conent'), + 'class' => 'span12', + 'rows' => 20, ), - 'options' => $editorConfig, )); +// $editorConfig = Pi::config()->load("module.article.ckeditor.php"); +// $editorConfig['editor'] = 'html'; +// $editorConfig['set'] = ''; +// +// $this->add(array( +// 'name' => 'content', +// 'attributes' => array( +// 'type' => 'editor', +// +// ), +// 'options' => $editorConfig, +// )); + $this->add(array( 'name' => 'id', 'attributes' => array( diff --git a/src/book/src/XmlToHtml.php b/src/book/src/XmlToHtml.php new file mode 100644 index 0000000..0b1dd3c --- /dev/null +++ b/src/book/src/XmlToHtml.php @@ -0,0 +1,126 @@ +getRawData($string); + + if (isset($rawData['article'])) + { + return $this->parseArticle($rawData['article']); + } + + if (isset($rawData['qandasets'])) + { + return $this->parseQandA($rawData['qandasets']); + } + + if (isset($rawData['chapter'])) + { + return $this->parseChapter($rawData['chapter']); + } + + return 'xml parse error: ' . $string; + } + + private function parseChapter($array) + { + $article = array(); + $article['title'] = $array['title']; + + $content = false; + foreach ($array['abstract'] as $para) + { + $content = '

' . $para; + } + + $article['content'] = $content; + return $article; + } + + private function parseArticle($array) + { + $article = array(); + $article['title'] = $array['title']; + $content = '

' . $array['subtitle'] . '

'; + $content .= '
' . $array['abstract']['#text'] . ':'; + + $i = 0; + foreach ($array['para'] as $para) + { + if (++$i == 1) + { + $content .= $para . '
'; + } + else + { + $content .= '

' . $para; + } + + } + $article['content'] = $content; + return $article; + } + + private function parseQandA($array) + { + $article = array(); + $article['title'] = $array['title']; + + $content = ''; + foreach ($array['qandaentry'] as $qa) + { + $content .= $qa['question']['person'] . ' 发表于 ' . $qa['question']['time'] . ': ' . $qa['question']['para'] . '

'; + $content .= $qa['answer']['person'] . ' 发表于 ' . $qa['answer']['time'] . ': ' . $qa['answer']['para'] . '

'; + } + $article['content'] = $content; + + return $article; + } + + private function getRawData($string) + { + $dom = new DOMDocument(); + $dom->preserveWhiteSpace = false; + $dom->loadXML($string); + $dom->removeChild($dom->firstChild); // 去掉开始的元数据 + return $this->parseNode($dom); + } + + private function parseNode($node) + { + static $textNode = array('para', 'person', 'time', 'title', 'subtitle'); + + if (in_array($node->nodeName, $textNode) || !$node->hasChildNodes()) + { + return $node->nodeValue; + } + + $array = array(); + foreach ($node->childNodes as $childNode) + { + $array[$childNode->nodeName][] = $this->parseNode($childNode); + } + + foreach($array as $key => $value) + { + if (count($value) == 1) + $array[$key] = $value[0]; + } + return $array; + } +} diff --git a/src/book/template/admin/article-edit.phtml b/src/book/template/admin/article-edit.phtml index 7f15026..83dcfad 100644 --- a/src/book/template/admin/article-edit.phtml +++ b/src/book/template/admin/article-edit.phtml @@ -46,8 +46,6 @@ echo $this->formElement($element); $element = $form->get('bid'); echo $this->formElement($element); - $element = $form->get('cdid'); - echo $this->formElement($element); $element = $form->get('fake_id'); echo $this->formElement($element); ?> @@ -64,16 +62,7 @@ url('', array('controller' => 'catalogue', 'action' => 'edit', 'bid' => $form->get('bid')->getValue())); - $link = sprintf('%s', $url, __('Edit Catalogue'), __('Edit Catalogue')); - echo $link; - ?> - - -

- - url('', array('controller' => 'catalogue', 'action' => 'edit-item', 'bid' => $form->get('bid')->getValue(), 'cdid' => $form->get('cdid')->getValue())); - $link = sprintf('%s', $url, __('Edit Catalogue Item'), __('Edit Catalogue Item')); + $link = sprintf('%s', $url, __('Go to Catalogue'), __('Go to Catalogue')); echo $link; ?> diff --git a/src/book/template/admin/catalogue-edit.phtml b/src/book/template/admin/catalogue-edit.phtml index ad83b1c..fb0b2c1 100644 --- a/src/book/template/admin/catalogue-edit.phtml +++ b/src/book/template/admin/catalogue-edit.phtml @@ -12,13 +12,6 @@ -
- - - - - -
@@ -51,8 +44,7 @@ - - +
@@ -111,7 +103,7 @@ events: { 'click .js-toggle': 'toggle', 'click .js-delete': 'deleteItem', - 'click .js-manage': 'manageArticle', + 'click .js-view': 'viewArticle', 'click .tree-item-save': 'saveItem' }, initialize: function() { @@ -150,9 +142,9 @@ this.$('[name=url]').tooltip(); return this; }, - manageArticle: function() { - var cdid = this.model.get('id'); - window.location.href = "url('', array('controller' => 'catalogue', 'action' => 'editItem', 'bid' => $bid));?>" + '/cdid/' + cdid; + viewArticle: function() { + var id = this.model.get('id'); + window.location.href = "url('', array('controller' => 'article', 'action' => 'edit', 'bid' => $bid));?>" + '/id/' + id; } }); var MenuListItemView = Backbone.View.extend({ diff --git a/src/book/template/front/article-view.phtml b/src/book/template/front/article-view.phtml index 6944757..c0a42c4 100644 --- a/src/book/template/front/article-view.phtml +++ b/src/book/template/front/article-view.phtml @@ -18,16 +18,6 @@ $this->js(Pi::url('static/vendor/bootstrap/js/bootstrap.js'));
-
- - url('', array('controller' => 'article', 'action' => 'list', 'bid' => $bid, 'cdid' => $cdid)); - $link = sprintf('%s', $url, __('Back to Catalogue Article list'), __('Back to Catalogue Article list')); - echo $link; - ?> - -
-
js(Pi::url('static/vendor/bootstrap/js/bootstrap.js')); ?>
url('', array('controller' => 'article', 'action' => 'list', 'bid' => $book['id'], 'cdid' => $item->id)); + $url = $this->url('', array('controller' => 'article', 'action' => 'view', 'bid' => $book['id'], 'id' => $item->id)); $link = sprintf('%s', $url, __('View catalogue'), $item->label); for ($i = 0; $i < $item->depth; $i++) echo '    '; - echo '|—' . $link; + echo '|—  ' . $link; ?>