diff --git a/Controller/WikiController.php b/Controller/WikiController.php index 7d4013f..6d34d11 100755 --- a/Controller/WikiController.php +++ b/Controller/WikiController.php @@ -33,28 +33,51 @@ class WikiController extends Controller{ /** * @Route( - * "/{wikiId}", - * requirements={"wikiId" = "\d+"}, + * "/{wikiId}.{_format}", + * defaults={"_format":"html"}, + * requirements={"wikiId" = "\d+", "_format":"html|pdf"}, * name="icap_wiki_view" * ) * @ParamConverter("wiki", class="IcapWikiBundle:Wiki", options={"id" = "wikiId"}) - * @Template() */ - public function viewAction(Wiki $wiki) + public function viewAction(Wiki $wiki, Request $request) { $this->checkAccess("OPEN", $wiki); $isAdmin = $this->isUserGranted("EDIT", $wiki); $user = $this->getLoggedUser(); $sectionRepository = $this->get('icap.wiki.section_repository'); $tree = $sectionRepository->buildSectionTree($wiki, $isAdmin); - - return array( + $format = $request->get('_format'); + $response = new Response(); + $this->render(sprintf('IcapWikiBundle:Wiki:view.%s.twig', $format), array( '_resource' => $wiki, 'tree' => $tree, 'workspace' => $wiki->getResourceNode()->getWorkspace(), 'isAdmin' => $isAdmin, 'user' => $user - ); + ), $response); + if ($format == "pdf") { + return new Response( + $this->get('knp_snappy.pdf')->getOutputFromHtml( + $response->getContent(), + array( + 'outline' => true, + 'footer-right' => '[page]/[toPage]', + 'footer-spacing' => 3, + 'footer-font-size' => 8 + ), + true + ), + 200, + array( + 'Content-Type' => 'application/pdf', + 'Content-Disposition' => 'inline; filename="'.$wiki->getResourceNode()->getName() + ) + ); + + } + + return $response; } /** diff --git a/Entity/Contribution.php b/Entity/Contribution.php index 204f001..aeffa49 100755 --- a/Entity/Contribution.php +++ b/Entity/Contribution.php @@ -35,6 +35,8 @@ class Contribution */ protected $text; + protected $textForPdf; + /** * @ORM\Column(type="datetime", name="creation_date") * @Gedmo\Timestampable(on="create") @@ -91,6 +93,15 @@ public function getText() return $this->text; } + public function getTextForPdf() + { + $tmpText = $this->text; + str_replace(" ", " ", $tmpText); + preg_replace('/alt=["\'][a-zA-Z]*["\']/g', "", $tmpText); + + return $tmpText; + } + /** * @param mixed $text */ diff --git a/Listener/WikiListener.php b/Listener/WikiListener.php index 8fdfa01..d3b9fcf 100755 --- a/Listener/WikiListener.php +++ b/Listener/WikiListener.php @@ -72,7 +72,7 @@ public function onOpen(OpenResourceEvent $event) public function onDelete(DeleteResourceEvent $event) { - $em = $this->container->get('doctrine.orm.entity_manager'); + $em = $this->container->get('claroline.persistence.object_manager'); $em->remove($event->getResource()); $em->flush(); $event->stopPropagation(); @@ -88,4 +88,4 @@ public function onCopy(CopyResourceEvent $event) $event->setCopy($newWiki); $event->stopPropagation(); } -} \ No newline at end of file +} diff --git a/Resources/public/css/pdf.css b/Resources/public/css/pdf.css new file mode 100644 index 0000000..66ea0d8 --- /dev/null +++ b/Resources/public/css/pdf.css @@ -0,0 +1 @@ +html,body{font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;font-size:12px}h1,h2,h3,h4,h5,h6{margin:10px 0;font-weight:500}h1{font-size:20px}h2{font-size:16px}h3{font-size:14px}h4{font-size:12px}a{color:#2a6496}ul{display:block;margin-left:0px;padding-left:0px}ul ul{margin-left:10px}table{border-color:#ccc;border-width:0 0 1px 1px;border-style:solid;border-spacing:0px;border-collapse:separate}table td,table th{border-width:1px 1px 0 0;border-style:solid;margin:0;padding:4px;border-color:#ccc}div.pdf-contents div.pdf-contents-inner{float:left;border:1px solid #e3e3e3;padding:10px;min-width:200px}ul.no-bullet-list{list-style:none}.page-header{border-bottom:1px solid #eeeeee}.subsection-header{border-bottom:1px dashed #eeeeee}.clearfix,.clearfix::after{clear:both} \ No newline at end of file diff --git a/Resources/views/Section/deleteModal.html.twig b/Resources/views/Section/deleteModal.html.twig index 8d0f2eb..ea19d05 100755 --- a/Resources/views/Section/deleteModal.html.twig +++ b/Resources/views/Section/deleteModal.html.twig @@ -21,7 +21,7 @@ $('form[id="deleteSection-form-{{ section.id }}"] > input[type="submit"]').hide(); $('form[id="deleteSection-form-{{ section.id }}"] > a.cancel-btn').hide(); - $('#deleteSectionModal-submit-{{ section.id }}').on('click', function () { + $('#deleteSectionModal-submit-{{ section.id }}').on('click', function (event) { event.preventDefault(); //I do the "click" on submit button for keep html5 warning $('form[id="deleteSection-form-{{ section.id }}"] > input[type="submit"]').trigger('click'); diff --git a/Resources/views/Wiki/view.html.twig b/Resources/views/Wiki/view.html.twig index 39f30d2..963e39c 100755 --- a/Resources/views/Wiki/view.html.twig +++ b/Resources/views/Wiki/view.html.twig @@ -5,15 +5,22 @@ {% block title %}{{ _resource.resourceNode.name }}{% endblock %} {% block wiki_buttons %} - {% if user is not empty and (isAdmin or _resource.mode is not sameas(2)) %} -
- - {{ 'create_new_section'|trans({}, 'icap_wiki') }} - - {% if isAdmin %} - {{'options'|trans({},'icap_wiki')}} + {% if user is not empty or config.getParameter('is_pdf_export_active') == true %} +
+ {% if user is not empty %} + {% if isAdmin or _resource.mode is not sameas(2)%} + + {{ 'create_new_section'|trans({}, 'icap_wiki') }} + + {% endif %} + {% if isAdmin %} + {{'options'|trans({},'icap_wiki')}} + {% endif %} + {% render controller('IcapNotificationBundle:FollowerResource:renderForm', {'resourceId': _resource.resourceNode.id, 'resourceClass': _resource.resourceNode.class}) %} + {% endif %} + {% if config.getParameter('is_pdf_export_active') == true %} + {{ 'pdf_export'|trans({}, 'platform') }} {% endif %} - {% render controller('IcapNotificationBundle:FollowerResource:renderForm', {'resourceId': _resource.resourceNode.id, 'resourceClass': _resource.resourceNode.class}) %}
{% endif %} {% endblock %} diff --git a/Resources/views/Wiki/view.pdf.twig b/Resources/views/Wiki/view.pdf.twig new file mode 100644 index 0000000..6cd7ec0 --- /dev/null +++ b/Resources/views/Wiki/view.pdf.twig @@ -0,0 +1,37 @@ + + + + + {{ _resource.resourceNode.name ~ '.pdf' }} + {% stylesheets debug=false filter='lessphp' output='bundles/icapwiki/css/pdf.css' + "@IcapWikiBundle/Resources/views/less/pdf.less" + %} + + {% endstylesheets %} + + + + {% if tree is not empty and tree[0] is not empty and tree[0].activeContribution.text is not empty%} +
+ {{ tree[0].activeContribution.text|raw }} +
+ {% endif %} + + {% if tree is not empty and tree[0] is not empty and tree[0].__children is not empty %} +
+
+
+ {{ 'wiki_contents'|trans({},'icap_wiki') }} +
+ {% include "IcapWikiBundle:Wiki:wikiContents.pdf.twig" with {'sections' : tree[0].__children, 'isAdmin' : isAdmin, 'delimeter' : '.', 'rootId' : tree[0].id } %} +
+
+
+
+ {% include "IcapWikiBundle:Wiki:wikiSections.pdf.twig" with {'sections' : tree[0].__children, 'wikiId' : _resource.id, 'isAdmin' : isAdmin, 'wikiMode' : _resource.mode, 'user' : user } %} +
+ {% endif %} + + \ No newline at end of file diff --git a/Resources/views/Wiki/wikiContents.pdf.twig b/Resources/views/Wiki/wikiContents.pdf.twig new file mode 100644 index 0000000..bc87789 --- /dev/null +++ b/Resources/views/Wiki/wikiContents.pdf.twig @@ -0,0 +1,20 @@ +{% macro wiki_contents_pdf(sections, isAdmin, delimeter, prefix) %} + {% for section in sections %} + {% if section.visible %} +
  • + + {{prefix ~ loop.index}} {{ section.activeContribution.title }} + + +
  • + {% endif %} + {% endfor %} +{% endmacro %} + + \ No newline at end of file diff --git a/Resources/views/Wiki/wikiSections.pdf.twig b/Resources/views/Wiki/wikiSections.pdf.twig new file mode 100644 index 0000000..abad69c --- /dev/null +++ b/Resources/views/Wiki/wikiSections.pdf.twig @@ -0,0 +1,26 @@ +{% macro wiki_sections_pdf(sections, isAdmin, wikiId, wikiMode, user) %} + {% for section in sections %} + {% if section.deleted is empty and section.visible %} + {% set level = section.level + 1 %} + {% set fontsize = 0 %} + {% if level > 4 %} + {% set level = 4 %} + {% endif %} +
  • +
    + {{section.activeContribution.title}} +
    +
    {{section.activeContribution.text|preg_replace("/src=\"\\/\\//","src=\"http://")|preg_replace("/src=\"\\//","src=\""~app.request.getSchemeAndHttpHost()~"/")|raw}}
    + {% if section.__children is not empty %} + + {% endif %} +
  • + {% endif %} + {% endfor %} +{% endmacro %} + + diff --git a/Resources/views/less/pdf.less b/Resources/views/less/pdf.less new file mode 100644 index 0000000..9cbcf3b --- /dev/null +++ b/Resources/views/less/pdf.less @@ -0,0 +1,69 @@ +html, body{ + font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; + font-size: 12px; +} +h1, h2, h3, h4, h5, h6{margin: 10px 0; font-weight: 500;} +h1{ + font-size: 20px; +} + +h2{ + font-size: 16px; +} + +h3{ + font-size: 14px; +} + +h4{ + font-size: 12px; +} + +a{ + color: #2a6496; +} + +ul{ + ul{margin-left: 10px;} + display: block; + margin-left: 0px; + padding-left: 0px; +} + +table{ + border-color: #ccc; + border-width: 0 0 1px 1px; + border-style: solid; + border-spacing: 0px; + border-collapse: separate; + td, th{ + border-width: 1px 1px 0 0; + border-style: solid; + margin: 0; + padding: 4px; + border-color: #ccc; + } +} + +div.pdf-contents{ + div.pdf-contents-inner{ + float:left; + border: 1px solid #e3e3e3; + padding: 10px; + min-width: 200px; + } +} + +ul.no-bullet-list{ + list-style: none; +} + +.page-header{ + border-bottom: 1px solid #eeeeee; +} + +.subsection-header{ + border-bottom: 1px dashed #eeeeee; +} + +.clearfix, .clearfix::after{clear:both;} \ No newline at end of file