SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/ajax/document_import.php

  1. <?php
  2. /*
  3.  * kate: tab-width 4; indent-width 4; space-indent on; word-wrap off; word-wrap-column 120;
  4.  * :tabSize=4:indentSize=4:noTabs=true:wrap=false:maxLineLen=120:mode=php:
  5.  *
  6.  * Copyright (C) 2015 Karmabunny Pty Ltd.
  7.  *
  8.  * This file is a part of SproutCMS.
  9.  *
  10.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  11.  * of the GNU General Public License as published by the Free Software Foundation, either
  12.  * version 3 of the License, or (at your option) any later version.
  13.  *
  14.  * For more information, visit <http://getsproutcms.com>.
  15.  */
  16. ?>
  17.  
  18. <script>
  19. var docImport = {'selector' : '#<?php echo $elemid; ?>'};
  20. </script>
  21.  
  22.  
  23. <h2>Import content into the editor</h2>
  24.  
  25. <form action="SITE/admin_ajax/richtext_import_iframe" method="post" enctype="multipart/form-data" id="doc-import-form" target="doc-import-iframe">
  26. <input type="file" name="import" id="doc-import-upload">
  27. </form>
  28. <iframe id="doc-import-iframe" name="doc-import-iframe" width="1" height="1" style="border-style: none;"></iframe>
  29.  
  30.  
  31. <!-- TODO: externalise -->
  32. <style>
  33. #doc-import-upload {
  34. padding: 20px;
  35. width: 400px;
  36. background: #eee;
  37. border-radius: 3px;
  38. margin: 20px auto;
  39. }
  40. </style>
  41. <script>
  42. $(document).ready(function() {
  43. $('#doc-import-upload').change(function() {
  44. $('#doc-import-form').submit();
  45. });
  46.  
  47. $('#doc-import-iframe').on("load", function() {
  48. var nfo = $(this).contents().find('div').text();
  49. if (nfo == '') return;
  50.  
  51. nfo = $.parseJSON(nfo);
  52. if (nfo.error) {
  53. alert(nfo.error);
  54. return;
  55. }
  56. if (nfo.html == '') return;
  57.  
  58. $(docImport.selector).trigger('richtext_insert', [nfo.html]);
  59. $(document).trigger('close.facebox');
  60. });
  61. });
  62. </script>
  63.