jay 4 years ago
commit
b79f62d488
100 changed files with 22041 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 9 0
      .htaccess
  3. 6 0
      .idea/misc.xml
  4. 8 0
      .idea/modules.xml
  5. 6 0
      .idea/vcs.xml
  6. 319 0
      .idea/workspace.xml
  7. 189 0
      Application/Common/Common/function.php
  8. 1 0
      Application/Common/Common/index.html
  9. 4 0
      Application/Common/Conf/config.php
  10. 14 0
      Application/Common/Conf/debug.php
  11. 1 0
      Application/Common/Conf/index.html
  12. 1 0
      Application/Common/index.html
  13. 1 0
      Application/Home/Common/index.html
  14. 9 0
      Application/Home/Conf/config.php
  15. 1 0
      Application/Home/Conf/index.html
  16. 5 0
      Application/Home/Conf/tags.php
  17. 62 0
      Application/Home/Controller/AttornController.class.php
  18. 123 0
      Application/Home/Controller/BaseController.class.php
  19. 163 0
      Application/Home/Controller/CatalogController.class.php
  20. 32 0
      Application/Home/Controller/CommonController.class.php
  21. 30 0
      Application/Home/Controller/IndexController.class.php
  22. 392 0
      Application/Home/Controller/ItemController.class.php
  23. 99 0
      Application/Home/Controller/MemberController.class.php
  24. 300 0
      Application/Home/Controller/PageController.class.php
  25. 71 0
      Application/Home/Controller/TemplateController.class.php
  26. 495 0
      Application/Home/Controller/UpdateController.class.php
  27. 165 0
      Application/Home/Controller/UserController.class.php
  28. 1 0
      Application/Home/Controller/index.html
  29. 216 0
      Application/Home/Lang/en-us.php
  30. 220 0
      Application/Home/Lang/zh-cn.php
  31. 17 0
      Application/Home/Model/BaseModel.class.php
  32. 182 0
      Application/Home/Model/ItemModel.class.php
  33. 52 0
      Application/Home/Model/UserModel.class.php
  34. 34 0
      Application/Home/Model/UserTokenModel.class.php
  35. 1 0
      Application/Home/Model/index.html
  36. 44 0
      Application/Home/View/Attorn/index.html
  37. 77 0
      Application/Home/View/Catalog/edit.html
  38. 11 0
      Application/Home/View/Common/footer.html
  39. 23 0
      Application/Home/View/Common/header.html
  40. 38 0
      Application/Home/View/Common/message.html
  41. 132 0
      Application/Home/View/Index/index.html
  42. 122 0
      Application/Home/View/Item/add.html
  43. 38 0
      Application/Home/View/Item/delete.html
  44. 57 0
      Application/Home/View/Item/export.html
  45. 74 0
      Application/Home/View/Item/index.html
  46. 70 0
      Application/Home/View/Item/pwd.html
  47. 269 0
      Application/Home/View/Item/setting.html
  48. 176 0
      Application/Home/View/Item/show.html
  49. 187 0
      Application/Home/View/Item/show_regular.html
  50. 89 0
      Application/Home/View/Item/show_single_page.html
  51. 71 0
      Application/Home/View/Item/showbyuid.html
  52. 44 0
      Application/Home/View/MdTemplate/api-doc.en-us.html
  53. 45 0
      Application/Home/View/MdTemplate/api-doc.zh-cn.html
  54. 12 0
      Application/Home/View/MdTemplate/database.en-us.html
  55. 13 0
      Application/Home/View/MdTemplate/database.zh-cn.html
  56. 57 0
      Application/Home/View/Member/edit.html
  57. 89 0
      Application/Home/View/Page/diff.html
  58. 148 0
      Application/Home/View/Page/edit.html
  59. 47 0
      Application/Home/View/Page/history.html
  60. 22 0
      Application/Home/View/Page/index.html
  61. 152 0
      Application/Home/View/Page/single.html
  62. 67 0
      Application/Home/View/User/login.html
  63. 58 0
      Application/Home/View/User/register.html
  64. 19 0
      Application/Home/View/User/setting.html
  65. 1 0
      Application/Home/View/index.html
  66. 1 0
      Application/Home/index.html
  67. 1 0
      Application/README.md
  68. 1 0
      Application/index.html
  69. 16 0
      Dockerfile
  70. 31 0
      LICENSE.txt
  71. 1 0
      Public/README.md
  72. 1 0
      Public/Uploads/index.html
  73. 1109 0
      Public/bootstrap/css/bootstrap-responsive.css
  74. 9 0
      Public/bootstrap/css/bootstrap-responsive.min.css
  75. 6167 0
      Public/bootstrap/css/bootstrap.css
  76. 9 0
      Public/bootstrap/css/bootstrap.min.css
  77. BIN
      Public/bootstrap/img/glyphicons-halflings-white.png
  78. BIN
      Public/bootstrap/img/glyphicons-halflings.png
  79. 2280 0
      Public/bootstrap/js/bootstrap.js
  80. 11 0
      Public/bootstrap/js/bootstrap.min.js
  81. 38 0
      Public/css/index.css
  82. 51 0
      Public/css/item/index.css
  83. 171 0
      Public/css/item/show.css
  84. 83 0
      Public/css/item/show_single_page.css
  85. 182 0
      Public/css/jquery.fullPage.css
  86. 52 0
      Public/css/login.css
  87. 491 0
      Public/css/page/edit.css
  88. 46 0
      Public/css/page/index.css
  89. 35 0
      Public/css/showdoc.css
  90. 46 0
      Public/css/tab-tpl.css
  91. 411 0
      Public/diff/difflib.js
  92. 83 0
      Public/diff/diffview.css
  93. 198 0
      Public/diff/diffview.js
  94. 342 0
      Public/editor.md/Gulpfile.js
  95. 22 0
      Public/editor.md/LICENSE
  96. 119 0
      Public/editor.md/README.md
  97. 4450 0
      Public/editor.md/css/editormd.css
  98. 98 0
      Public/editor.md/css/editormd.logo.css
  99. 2 0
      Public/editor.md/css/editormd.logo.min.css
  100. 0 0
      Public/editor.md/css/editormd.min.css

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+Application/Runtime/
+server/Application/Runtime/
+

+ 9 - 0
.htaccess

@@ -0,0 +1,9 @@
+<IfModule mod_rewrite.c>
+  Options +FollowSymlinks
+  RewriteEngine On
+
+  RewriteCond %{REQUEST_FILENAME} !-d
+  RewriteCond %{REQUEST_FILENAME} !-f
+  RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
+  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
+</IfModule>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" project-jdk-name="Go 1.6.2" project-jdk-type="Go SDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/showdoc.iml" filepath="$PROJECT_DIR$/showdoc.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>

+ 319 - 0
.idea/workspace.xml

@@ -0,0 +1,319 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ChangeListManager">
+    <list default="true" id="e564c34b-bc50-4861-a43a-d038c6967781" name="Default" comment="">
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Controller/BaseController.class.php" afterPath="$PROJECT_DIR$/Application/Home/Controller/BaseController.class.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Controller/CommonController.class.php" afterPath="$PROJECT_DIR$/Application/Home/Controller/CommonController.class.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Controller/IndexController.class.php" afterPath="$PROJECT_DIR$/Application/Home/Controller/IndexController.class.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Controller/ItemController.class.php" afterPath="$PROJECT_DIR$/Application/Home/Controller/ItemController.class.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Controller/UpdateController.class.php" afterPath="$PROJECT_DIR$/Application/Home/Controller/UpdateController.class.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/Lang/zh-cn.php" afterPath="$PROJECT_DIR$/Application/Home/Lang/zh-cn.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Item/add.html" afterPath="$PROJECT_DIR$/Application/Home/View/Item/add.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Item/setting.html" afterPath="$PROJECT_DIR$/Application/Home/View/Item/setting.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Item/show.html" afterPath="$PROJECT_DIR$/Application/Home/View/Item/show.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Item/show_regular.html" afterPath="$PROJECT_DIR$/Application/Home/View/Item/show_regular.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Item/show_single_page.html" afterPath="$PROJECT_DIR$/Application/Home/View/Item/show_single_page.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Application/Home/View/Page/single.html" afterPath="$PROJECT_DIR$/Application/Home/View/Page/single.html" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/Public/js/dialog.js" afterPath="$PROJECT_DIR$/Public/js/dialog.js" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/install/ajax.php" afterPath="$PROJECT_DIR$/install/ajax.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/install/database.php" afterPath="$PROJECT_DIR$/install/database.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/install/lang.en.php" afterPath="$PROJECT_DIR$/install/lang.en.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/install/lang.zh.php" afterPath="$PROJECT_DIR$/install/lang.zh.php" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/server/Application/Common/Conf/config.php" afterPath="$PROJECT_DIR$/server/Application/Common/Conf/config.php" />
+    </list>
+    <ignored path="$PROJECT_DIR$/out/" />
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
+    <option name="TRACKING_ENABLED" value="true" />
+    <option name="SHOW_DIALOG" value="false" />
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+    <option name="LAST_RESOLUTION" value="IGNORE" />
+  </component>
+  <component name="FileEditorManager">
+    <leaf>
+      <file leaf-file-name="ajax.php" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/install/ajax.php">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="277">
+              <caret line="53" column="28" lean-forward="true" selection-start-line="53" selection-start-column="28" selection-end-line="53" selection-end-column="28" />
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file leaf-file-name="BaseController.class.php" pinned="false" current-in-tab="true">
+        <entry file="file://$PROJECT_DIR$/Application/Home/Controller/BaseController.class.php">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="321">
+              <caret line="19" column="32" lean-forward="true" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="32" />
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+    </leaf>
+  </component>
+  <component name="FindInProjectRecents">
+    <findStrings>
+      <find>http://www.showdoc.cc</find>
+      <find>https://www.showdoc.cc</find>
+    </findStrings>
+    <replaceStrings>
+      <replace>http://api.pkbigdata.com</replace>
+    </replaceStrings>
+    <dirStrings>
+      <dir>D:\D\workspace\intellijidea\showdoc</dir>
+    </dirStrings>
+  </component>
+  <component name="Git.Settings">
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
+  </component>
+  <component name="GradleLocalSettings">
+    <option name="modificationStamps">
+      <map>
+        <entry key="$PROJECT_DIR$/../common" value="2977917943151" />
+      </map>
+    </option>
+    <option name="externalProjectsViewState">
+      <projects_view />
+    </option>
+  </component>
+  <component name="IdeDocumentHistory">
+    <option name="CHANGED_PATHS">
+      <list>
+        <option value="$PROJECT_DIR$/install/ajax.php" />
+        <option value="$PROJECT_DIR$/Application/Home/Controller/BaseController.class.php" />
+      </list>
+    </option>
+  </component>
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
+  <component name="JsGulpfileManager">
+    <detection-done>true</detection-done>
+    <sorting>DEFINITION_ORDER</sorting>
+  </component>
+  <component name="ProjectView">
+    <navigator currentView="ProjectPane" proportions="" version="1">
+      <flattenPackages />
+      <showMembers />
+      <showModules />
+      <showLibraryContents />
+      <hideEmptyPackages />
+      <abbreviatePackageNames />
+      <autoscrollToSource />
+      <autoscrollFromSource />
+      <sortByType />
+      <manualOrder />
+      <foldersAlwaysOnTop value="true" />
+    </navigator>
+    <panes>
+      <pane id="Scratches" />
+      <pane id="ProjectPane">
+        <subPane>
+          <expand>
+            <path>
+              <item name="showdoc" type="b2602c69:ProjectViewProjectNode" />
+              <item name="showdoc" type="462c0819:PsiDirectoryNode" />
+            </path>
+          </expand>
+          <select />
+        </subPane>
+      </pane>
+      <pane id="Scope" />
+      <pane id="PackagesPane" />
+    </panes>
+  </component>
+  <component name="PropertiesComponent">
+    <property name="settings.editor.selected.configurable" value="com.zeroturnaround.javarebel.idea.plugin.settings.startup.StartupConfigurable" />
+    <property name="last_opened_file_path" value="D:/nodejs/node.exe" />
+    <property name="WebServerToolWindowFactoryState" value="false" />
+    <property name="aspect.path.notification.shown" value="true" />
+  </component>
+  <component name="RunDashboard">
+    <option name="ruleStates">
+      <list>
+        <RuleState>
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
+        </RuleState>
+        <RuleState>
+          <option name="name" value="StatusDashboardGroupingRule" />
+        </RuleState>
+      </list>
+    </option>
+  </component>
+  <component name="RunManager">
+    <configuration default="true" type="Applet" factoryName="Applet">
+      <option name="WIDTH" value="400" />
+      <option name="HEIGHT" value="300" />
+      <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
+      <module />
+    </configuration>
+    <configuration default="true" type="Application" factoryName="Application">
+      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+      <option name="MAIN_CLASS_NAME" />
+      <option name="VM_PARAMETERS" />
+      <option name="PROGRAM_PARAMETERS" />
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+      <option name="ENABLE_SWING_INSPECTOR" value="false" />
+      <option name="ENV_VARIABLES" />
+      <option name="PASS_PARENT_ENVS" value="true" />
+      <module name="" />
+      <envs />
+    </configuration>
+    <configuration default="true" type="JUnit" factoryName="JUnit">
+      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+      <module name="" />
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+      <option name="PACKAGE_NAME" />
+      <option name="MAIN_CLASS_NAME" />
+      <option name="METHOD_NAME" />
+      <option name="TEST_OBJECT" value="class" />
+      <option name="VM_PARAMETERS" value="-ea" />
+      <option name="PARAMETERS" />
+      <option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
+      <option name="ENV_VARIABLES" />
+      <option name="PASS_PARENT_ENVS" value="true" />
+      <option name="TEST_SEARCH_SCOPE">
+        <value defaultName="singleModule" />
+      </option>
+      <envs />
+      <patterns />
+    </configuration>
+    <configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin">
+      <module name="" />
+      <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
+      <option name="PROGRAM_PARAMETERS" />
+      <predefined_log_file id="idea.log" enabled="true" />
+    </configuration>
+    <configuration default="true" type="Remote" factoryName="Remote">
+      <option name="USE_SOCKET_TRANSPORT" value="true" />
+      <option name="SERVER_MODE" value="false" />
+      <option name="SHMEM_ADDRESS" value="javadebug" />
+      <option name="HOST" value="localhost" />
+      <option name="PORT" value="5005" />
+    </configuration>
+    <configuration default="true" type="TestNG" factoryName="TestNG">
+      <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+      <module name="" />
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+      <option name="ALTERNATIVE_JRE_PATH" />
+      <option name="SUITE_NAME" />
+      <option name="PACKAGE_NAME" />
+      <option name="MAIN_CLASS_NAME" />
+      <option name="METHOD_NAME" />
+      <option name="GROUP_NAME" />
+      <option name="TEST_OBJECT" value="CLASS" />
+      <option name="VM_PARAMETERS" value="-ea" />
+      <option name="PARAMETERS" />
+      <option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
+      <option name="OUTPUT_DIRECTORY" />
+      <option name="ANNOTATION_TYPE" />
+      <option name="ENV_VARIABLES" />
+      <option name="PASS_PARENT_ENVS" value="true" />
+      <option name="TEST_SEARCH_SCOPE">
+        <value defaultName="singleModule" />
+      </option>
+      <option name="USE_DEFAULT_REPORTERS" value="false" />
+      <option name="PROPERTIES_FILE" />
+      <envs />
+      <properties />
+      <listeners />
+    </configuration>
+  </component>
+  <component name="ShelveChangesManager" show_recycled="false">
+    <option name="remove_strategy" value="false" />
+  </component>
+  <component name="TaskManager">
+    <task active="true" id="Default" summary="Default task">
+      <changelist id="e564c34b-bc50-4861-a43a-d038c6967781" name="Default" comment="" />
+      <created>1513655746446</created>
+      <option name="number" value="Default" />
+      <option name="presentableId" value="Default" />
+      <updated>1513655746446</updated>
+      <workItem from="1513655749280" duration="235000" />
+    </task>
+    <servers />
+  </component>
+  <component name="TimeTrackingManager">
+    <option name="totallyTimeSpent" value="235000" />
+  </component>
+  <component name="ToolWindowManager">
+    <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
+    <editor active="true" />
+    <layout>
+      <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
+      <window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+      <window_info id="JRebel Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+      <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="JRebel Executor" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
+      <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24973147" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
+      <window_info id="JRebel" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+      <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32998884" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+      <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+      <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+      <window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
+      <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+      <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
+      <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
+      <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+      <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+      <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
+    </layout>
+  </component>
+  <component name="TypeScriptGeneratedFilesManager">
+    <option name="version" value="1" />
+  </component>
+  <component name="VcsContentAnnotationSettings">
+    <option name="myLimit" value="2678400000" />
+  </component>
+  <component name="XDebuggerManager">
+    <breakpoint-manager />
+    <watches-manager />
+  </component>
+  <component name="editorHistoryManager">
+    <entry file="file://$PROJECT_DIR$/install/ajax.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="277">
+          <caret line="53" column="28" lean-forward="true" selection-start-line="53" selection-start-column="28" selection-end-line="53" selection-end-column="28" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/Application/Home/Controller/BaseController.class.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="321">
+          <caret line="19" column="32" lean-forward="true" selection-start-line="19" selection-start-column="32" selection-end-line="19" selection-end-column="32" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+  </component>
+  <component name="masterDetails">
+    <states>
+      <state key="ProjectJDKs.UI">
+        <settings>
+          <last-edited>1.8</last-edited>
+          <splitter-proportions>
+            <option name="proportions">
+              <list>
+                <option value="0.2" />
+              </list>
+            </option>
+          </splitter-proportions>
+        </settings>
+      </state>
+    </states>
+  </component>
+</project>

+ 189 - 0
Application/Common/Common/function.php

@@ -0,0 +1,189 @@
+<?php
+
+
+/**
+ * 获得当前的域名
+ *
+ * @return  string
+ */
+function get_domain()
+{
+    /* 协议 */
+    $protocol = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
+
+    /* 域名或IP地址 */
+    if (isset($_SERVER['HTTP_X_FORWARDED_HOST']))
+    {
+        $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
+    }
+    elseif (isset($_SERVER['HTTP_HOST']))
+    {
+        $host = $_SERVER['HTTP_HOST'];
+    }
+    else
+    {
+        /* 端口 */
+        if (isset($_SERVER['SERVER_PORT']))
+        {
+            $port = ':' . $_SERVER['SERVER_PORT'];
+
+            if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol))
+            {
+                $port = '';
+            }
+        }
+        else
+        {
+            $port = '';
+        }
+
+        if (isset($_SERVER['SERVER_NAME']))
+        {
+            $host = $_SERVER['SERVER_NAME'] . $port;
+        }
+        elseif (isset($_SERVER['SERVER_ADDR']))
+        {
+            $host = $_SERVER['SERVER_ADDR'] . $port;
+        }
+    }
+
+    return $protocol . $host;
+}
+
+/**
+ * 获得网站的URL地址
+ *
+ * @return  string
+ */
+function site_url()
+{
+    return get_domain() . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
+}
+
+
+//导出称word
+function output_word($data,$fileName=''){
+
+    if(empty($data)) return '';
+
+    $data = '
+        <html xmlns:v="urn:schemas-microsoft-com:vml"
+        xmlns:o="urn:schemas-microsoft-com:office:office"
+        xmlns:w="urn:schemas-microsoft-com:office:word"
+        xmlns="http://www.w3.org/TR/REC-html40">
+        <head><meta http-equiv=Content-Type content="text/html;  
+        charset=utf-8">
+		<style type="text/css">
+			table  
+			{  
+				border-collapse: collapse;
+				border: none;  
+				width: 100%;  
+			}  
+			td  
+			{  
+				border: solid #CCC 1px;  
+			}  
+			.codestyle{
+				word-break: break-all;
+				background:silver;mso-highlight:silver;
+			}
+		</style>
+        <meta name=ProgId content=Word.Document>
+        <meta name=Generator content="Microsoft Word 11">
+        <meta name=Originator content="Microsoft Word 11">
+        <xml><w:WordDocument><w:View>Print</w:View></xml></head>
+        <body>'.$data.'</body></html>';
+    
+    $filepath = tmpfile();
+	$data = str_replace("<thead>\n<tr>","<thead><tr style='background-color: rgb(0, 136, 204); color: rgb(255, 255, 255);'>",$data);
+	$data = str_replace("<pre><code>","<table width='100%' class='codestyle'><pre><code>",$data);
+	$data = str_replace("</code></pre>","</code></pre></table>",$data);
+    $len = strlen($data);
+    fwrite($filepath, $data);
+    header("Content-type: application/octet-stream");
+    header("Content-Disposition: attachment; filename={$fileName}.doc");
+    header('Content-Description: File Transfer');
+    header('Content-Type: application/octet-stream');
+    header('Content-Disposition: attachment; filename='.$fileName.'.doc');
+    header('Content-Transfer-Encoding: binary');
+    header('Expires: 0');
+    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+    header('Pragma: public');
+    header('Content-Length: ' . $len);
+    rewind($filepath);
+    echo fread($filepath,$len);
+}
+
+
+function clear_runtime($path = RUNTIME_PATH){  
+    //给定的目录不是一个文件夹  
+    if(!is_dir($path)){  
+        return null;  
+    }  
+  
+    $fh = opendir($path);  
+    while(($row = readdir($fh)) !== false){  
+        //过滤掉虚拟目录  
+        if($row == '.' || $row == '..'|| $row == 'index.html'){  
+            continue;  
+        }  
+  
+        if(!is_dir($path.'/'.$row)){
+            unlink($path.'/'.$row);  
+        }  
+        clear_runtime($path.'/'.$row);  
+          
+    }  
+    //关闭目录句柄,否则出Permission denied  
+    closedir($fh);    
+    return true;  
+}
+
+//获取ip
+function getIPaddress(){
+    $IPaddress='';
+    if (isset($_SERVER)){
+        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
+            $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
+        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
+            $IPaddress = $_SERVER["HTTP_CLIENT_IP"];
+        } else {
+            $IPaddress = $_SERVER["REMOTE_ADDR"];
+        }
+    } else {
+        if (getenv("HTTP_X_FORWARDED_FOR")){
+            $IPaddress = getenv("HTTP_X_FORWARDED_FOR");
+        } else if (getenv("HTTP_CLIENT_IP")) {
+            $IPaddress = getenv("HTTP_CLIENT_IP");
+        } else {
+            $IPaddress = getenv("REMOTE_ADDR");
+        }
+    }
+    return $IPaddress;
+
+}
+
+function http_post($url, $param) {
+    $oCurl = curl_init ();
+    if (stripos ( $url, "https://" ) !== FALSE) {
+        curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYPEER, FALSE );
+        curl_setopt ( $oCurl, CURLOPT_SSL_VERIFYHOST, false );
+    }
+    if (is_string ( $param )) {
+        $strPOST = $param;
+    } else {
+        $aPOST = array ();
+        foreach ( $param as $key => $val ) {
+            $aPOST [] = $key . "=" . urlencode ( $val );
+        }
+        $strPOST = join ( "&", $aPOST );
+    }
+    curl_setopt ( $oCurl, CURLOPT_URL, $url );
+    curl_setopt ( $oCurl, CURLOPT_RETURNTRANSFER, 1 );
+    curl_setopt ( $oCurl, CURLOPT_POST, true );
+    curl_setopt ( $oCurl, CURLOPT_POSTFIELDS, $strPOST );
+    $sContent = curl_exec ( $oCurl );
+    curl_close ( $oCurl );
+    return $sContent;
+}

+ 1 - 0
Application/Common/Common/index.html

@@ -0,0 +1 @@
+ 

+ 4 - 0
Application/Common/Conf/config.php

@@ -0,0 +1,4 @@
+<?php
+//showdoc not install 
+//
+//

+ 14 - 0
Application/Common/Conf/debug.php

@@ -0,0 +1,14 @@
+<?php
+
+// 调试模式下面默认设置 可以在应用配置目录下重新定义 debug.php 覆盖
+return  array(
+    'LOG_RECORD'            =>  false,  // 进行日志记录
+    'LOG_EXCEPTION_RECORD'  =>  false,    // 是否记录异常信息日志
+    'LOG_LEVEL'             =>  'ERR',  // 允许记录的日志级别
+    'DB_FIELDS_CACHE'       =>  false, // 字段缓存信息
+    'DB_DEBUG'				=>  false, // 开启调试模式 记录SQL日志
+    'TMPL_CACHE_ON'         =>  false,        // 是否开启模板编译缓存,设为false则每次都会重新编译
+    'TMPL_STRIP_SPACE'      =>  false,       // 是否去除模板文件里面的html空格与换行
+    'SHOW_ERROR_MSG'        =>  true,    // 显示错误信息
+    'URL_CASE_INSENSITIVE'  =>  false,  // URL区分大小写
+);

+ 1 - 0
Application/Common/Conf/index.html

@@ -0,0 +1 @@
+ 

+ 1 - 0
Application/Common/index.html

@@ -0,0 +1 @@
+ 

+ 1 - 0
Application/Home/Common/index.html

@@ -0,0 +1 @@
+ 

+ 9 - 0
Application/Home/Conf/config.php

@@ -0,0 +1,9 @@
+<?php 
+return array(
+	//'配置项'=>'配置值'
+    'LANG_SWITCH_ON' => true,   // 开启语言包功能
+    'LANG_AUTO_DETECT' => false, // 自动侦测语言 开启多语言功能后有效
+    'DEFAULT_LANG' => 'zh-cn', // 默认语言
+    'LANG_LIST'        => 'zh-cn,en-us', // 允许切换的语言列表 用逗号分隔
+    'VAR_LANGUAGE'     => 'l', // 默认语言切换变量
+);

+ 1 - 0
Application/Home/Conf/index.html

@@ -0,0 +1 @@
+ 

+ 5 - 0
Application/Home/Conf/tags.php

@@ -0,0 +1,5 @@
+<?php
+return array(
+    // 添加下面一行定义即可
+    'app_begin' => array('Behavior\CheckLangBehavior'),
+);

+ 62 - 0
Application/Home/Controller/AttornController.class.php

@@ -0,0 +1,62 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class AttornController extends BaseController {
+
+    //转让页面
+    public function index(){
+        $item_id =  I("item_id");
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        $this->assign("item_id" , $item_id);
+
+        $this->display();        
+    }
+
+    //保存
+    public function save(){
+        $login_user = $this->checkLogin();
+
+        $username = I("username");
+        $item_id = I("item_id/d");
+        $password = I("password");
+
+        $item  = D("Item")->where("item_id = '$item_id' ")->find();
+
+        if(! D("User")-> checkLogin($item['username'],$password)){
+            $return['error_code'] = 10102 ;
+            $return['error_message'] = L('incorrect_password') ;
+            $this->sendResult($return);
+            return ;
+        }
+
+        $member = D("User")->where(" username = '%s' ",array($username))->find();
+
+        if (!$member) {
+            $return['error_code'] = 10201 ;
+            $return['error_message'] = L('user_does_not_exist') ;
+            $this->sendResult($return);
+            return ;
+        }
+
+        $data['username'] = $member['username'] ;
+        $data['uid'] = $member['uid'] ;
+        
+
+        $id = D("Item")->where(" item_id = '$item_id' ")->save($data);
+
+        $return = D("Item")->where("item_id = '$item_id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+}

+ 123 - 0
Application/Home/Controller/BaseController.class.php

@@ -0,0 +1,123 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class BaseController extends Controller {
+
+	public function message($msg , $redirect = ''){
+		$this->assign("msg" , $msg);
+		$this->assign("redirect" , $redirect);
+		$this->display ("Common/message");
+	}
+
+	public function checkLogin($redirect = true){
+    	if (strtolower(C("DB_TYPE")) == 'mysql' ) {
+            echo 'ShowDoc does not support mysql any more . http://api.pkbigdata.com/help?page_id=31990 ';
+            clear_runtime();
+            exit();
+    	}
+		if ( ! session("login_user")) {
+			$cookie_token = cookie('cookie_token');
+			if ($cookie_token) {
+				$ret = D("UserToken")->getToken($cookie_token);
+				if ($ret && $ret['token_expire'] > time() ) {
+					$login_user = D("User")->where("uid = $ret[uid]")->find();
+					unset($ret['password']);
+					session("login_user" , $login_user);
+					return $login_user ;
+				}
+			}
+			if ($redirect) {
+				$this->message("你尚未登录!",U('Home/User/login'));
+				exit();
+			}
+		}else{
+			return  session("login_user") ;
+		}
+	}
+
+	/**
+	 * 返回json数据
+	 */
+	public function sendResult($array){
+		if (isset($array['error_code'])) {
+			$result['error_code'] = $array['error_code'] ;
+			$result['error_message'] = $array['error_message'] ;
+		}
+		else{
+			$result['error_code'] = 0 ;
+			$result['data'] = $array ;
+		}
+		echo json_encode($result);
+	}
+
+	//判断某用户是否有项目管理权限(项目成员member_group_id为1,以及 项目创建者)
+	protected function checkItemPermn($uid , $item_id){
+
+		if (!$uid) {
+			return false;
+		}
+
+		if (session("mamage_item_".$item_id)) {
+			return true;
+		}
+
+		$item = D("Item")->where("item_id = '%d' ",array($item_id))->find();
+		if ($item['uid'] && $item['uid'] == $uid) {
+			session("mamage_item_".$item_id , 1 );
+			return true;
+		}
+		$ItemMember = D("ItemMember")->where("item_id = '%d' and uid = '%d' and member_group_id = 1 ",array($item_id,$uid))->find();
+		if ($ItemMember) {
+			session("mamage_item_".$item_id , 1 );
+			return true;
+		}
+		return false;
+	}
+
+	//判断某用户是否为项目创建者
+	protected function checkItemCreator($uid , $item_id){
+		if (!$uid) {
+			return false;
+		}
+		if (session("creat_item_".$item_id)) {
+			return true;
+		}
+
+		$item = D("Item")->where("item_id = '%d' ",array($item_id))->find();
+		if ($item['uid'] && $item['uid'] == $uid) {
+			session("creat_item_".$item_id , 1 );
+			return true;
+		}
+		return false;
+	}
+
+	//判断某用户是否有项目访问权限(公开项目的话所有人可访问,私有项目则项目成员、项目创建者和访问密码输入者可访问)
+	protected function checkItemVisit($uid , $item_id, $refer_url= ''){
+		if (session("visit_item_".$item_id)) {
+			return true;
+		}
+
+		if ($this->checkItemCreator($uid , $item_id)) {
+			session("visit_item_".$item_id , 1 );
+			return true;
+		}
+
+		$ItemMember = D("ItemMember")->where("item_id = '%d' and uid = '%d'  ",array($item_id,$uid))->find();
+		if ($ItemMember) {
+			session("visit_item_".$item_id , 1 );
+			return true;
+		}
+
+		$item = D("Item")->where("item_id = '%d' ",array($item_id))->find();
+		if ($item['password']) {
+			//跳转到输入访问密码框
+			header("location:".U("Home/item/pwd",array("item_id"=>$item_id,"refer_url"=>base64_encode($refer_url))));
+		}else{
+			session("visit_item_".$item_id , 1 );
+			return true;
+		}
+
+	}
+
+
+}

+ 163 - 0
Application/Home/Controller/CatalogController.class.php

@@ -0,0 +1,163 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class CatalogController extends BaseController {
+
+    //编辑页面
+    public function edit(){
+
+        $cat_id = I("cat_id/d");
+
+        $Catalog = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
+
+        if ($Catalog) {
+            $this->assign("Catalog" , $Catalog);
+        }
+
+        if ($Catalog['parent_cat_id']) {
+            $this->assign("default_parent_cat_id" , $Catalog['parent_cat_id']);
+        }
+        
+        $item_id = $Catalog['item_id'] ? $Catalog['item_id'] : I("item_id");
+
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $this->assign("item_id" , $item_id);
+
+        $this->display();        
+    }
+
+    //保存目录
+    public function save(){
+        $cat_name = I("cat_name");
+        $s_number = I("s_number/d") ? I("s_number/d") : 99 ;
+        $cat_id = I("cat_id/d")? I("cat_id/d") : 0;
+        $parent_cat_id = I("parent_cat_id/d")? I("parent_cat_id/d") : 0;
+        $item_id =  I("item_id/d");
+
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        //禁止空目录的生成
+        if (!$cat_name) {
+            return;
+        }
+        
+        $data['cat_name'] = $cat_name ;
+        $data['s_number'] = $s_number ;
+        $data['item_id'] = $item_id ;
+        $data['parent_cat_id'] = $parent_cat_id ;
+        if ($parent_cat_id > 0 ) {
+           $data['level'] = 3;
+        }else{
+            $data['level'] = 2;
+        }
+
+        if ($cat_id > 0 ) {
+            
+            $ret = D("Catalog")->where(" cat_id = '$cat_id' ")->save($data);
+            $return = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
+
+        }else{
+            $data['addtime'] = time();
+            $cat_id = D("Catalog")->add($data);
+            $return = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
+            
+        }
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+        $this->sendResult($return);
+        
+    }
+
+    //获取目录列表
+    public function catList(){
+        $item_id = I("item_id/d");
+        if ($item_id > 0 ) {
+            $ret = D("Catalog")->where(" item_id = '$item_id' ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //获取二级目录列表
+    public function secondCatList(){
+        $item_id = I("item_id/d");
+        if ($item_id > 0 ) {
+            $ret = D("Catalog")->where(" item_id = '$item_id' and level =2  ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //获取一个目录的子目录列表(如果存在的话)
+    public function childCatList(){
+        $cat_id = I("cat_id/d");
+        if ($cat_id > 0 ) {
+            $ret = D("Catalog")->where(" parent_cat_id = '$cat_id' ")->order(" 's_number', addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }      
+    }
+    //删除目录
+    public function delete(){
+        $cat_id = I("cat_id/d")? I("cat_id/d") : 0;
+        $cat = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
+        $item_id = $cat['item_id'];
+        
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $return['error_code'] = -1 ;
+            $return['error_message'] = L('no_permissions');
+            $this->sendResult($return);
+            return;
+        }
+
+        if (D("Page")->where(" cat_id = '$cat_id' ")->find() || D("Catalog")->where(" parent_cat_id = '$cat_id' ")->find()) {
+            $return['error_code'] = -1 ;
+            $return['error_message'] = L('no_delete_empty_catalog') ;
+            $this->sendResult($return);
+            return;
+        }
+
+        if ($cat_id > 0 ) {
+            
+            $ret = D("Catalog")->where(" cat_id = '$cat_id' ")->delete();
+
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = -1 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 32 - 0
Application/Home/Controller/CommonController.class.php

@@ -0,0 +1,32 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class CommonController extends BaseController {
+
+
+    //保存
+    public function qrcode(){
+        Vendor('Phpqrcode.phpqrcode');
+        $url = I("url");
+        $url = urldecode($url) ? urldecode($url) : $url;
+        $size = I("size") ? I("size") : 6;
+        $object = new \QRcode();
+        $object->png($url, false, 3 , $size, 2);             
+    }
+
+    public function checkForUpdate(){
+    	$option_data = D("Options")->where("option_name='version' ")->find();
+    	$post_data = array(
+    		"version" => $option_data['option_value'] ,
+    		);
+    	$version = $option_data['option_value'];
+        // TODO 此功能是留着检测更新用的。未完成。代码有空再写吧
+    	//$url = "http://api.pkbigdata.com/";
+    	//$result = http_post($url , $post_data);
+    	//$version_num = str_replace("v", '', $num);
+    	//$result = version_compare($version_num, "2.1.5",'<');
+    	//echo $result;
+
+    }
+
+}

+ 30 - 0
Application/Home/Controller/IndexController.class.php

@@ -0,0 +1,30 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class IndexController extends BaseController {
+    public function index(){
+        $tmp = @file_get_contents('./Application/Common/Conf/config.php');
+        if (strstr($tmp, "showdoc not install")) {
+            header("location:./install");
+            exit();
+        }
+    	$this->checkLogin(false);
+    	$login_user = session("login_user");
+    	$this->assign("login_user" ,$login_user);
+    	if (LANG_SET == 'en-us') {
+    		$demo_url = "http://api.pkbigdata.com/demo-en";
+    		$help_url = "http://api.pkbigdata.com/help-en";
+    		$creator_url = "https://github.com/star7th";
+    	}
+    	else{
+    		$demo_url = "http://api.pkbigdata.com/demo";
+    		$help_url = "http://api.pkbigdata.com/help";
+    		$creator_url = "https://blog.star7th.com/";
+    	}
+    	$this->assign("demo_url" ,$demo_url);
+    	$this->assign("help_url" ,$help_url);
+    	$this->assign("creator_url" ,$creator_url);
+
+        $this->display();
+    }
+}

+ 392 - 0
Application/Home/Controller/ItemController.class.php

@@ -0,0 +1,392 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class ItemController extends BaseController {
+    //项目列表页
+    public function index(){
+        $login_user = $this->checkLogin();        
+        $items  = D("Item")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->select();
+        //读取需要置顶的项目
+        $top_items = D("ItemTop")->where("uid = '$login_user[uid]'")->select();
+        if ($top_items) {
+            $top_item_ids = array() ;
+            foreach ($top_items as $key => $value) {
+                $top_item_ids[] = $value['item_id'];
+            }
+            foreach ($items as $key => $value) {
+                $items[$key]['top'] = 0 ;
+                if (in_array($value['item_id'], $top_item_ids) ) {
+                    $items[$key]['top'] = 1 ;
+                    $tmp = $items[$key] ;
+                    unset($items[$key]);
+                    array_unshift($items,$tmp) ;
+                }
+            }
+
+            $items = array_values($items);
+        }
+        
+        $share_url = get_domain().__APP__.'/uid/'.$login_user['uid'];
+
+        $this->assign("items" , $items);
+        $this->assign("login_user" , $login_user);
+    	$this->assign("share_url" , $share_url);
+        $this->display();
+    }
+    //我公开的项目列表
+    public function showByUid(){
+        $login_user = $this->checkLogin(false); //如果用户有登录,则赋值给$login_user
+        $uid = I("uid/d");
+        $show_user = D("User")->where(" uid = '$uid' ")->find();
+        if ($show_user) {
+            $items  = D("Item")->where(" password = '' and  ( uid = '$show_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$show_user[uid]' ) ) ")->select();
+            $this->assign("items" , $items);
+            $this->assign("show_user" , $show_user);
+            $this->assign("login_user" , $login_user);
+            
+        }
+        if (LANG_SET == 'en-us') {
+            $help_url = "http://api.pkbigdata.com/help-en";
+        }
+        else{
+            $help_url = "http://api.pkbigdata.com/help";
+        }
+
+        $this->assign("help_url" , $help_url);
+        $this->display();
+
+    }
+
+    //新建项目
+    public function add(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");
+        if (!IS_POST) {
+          $item = D("Item")->where("item_id = '$item_id' ")->find();
+          $this->assign("item" , $item);
+          $this->display ();
+
+        }else{
+            $item_name = I("item_name");
+            $item_domain = I("item_domain") ? I("item_domain") : '';
+            $copy_item_id = I("copy_item_id");
+            $password = I("password");
+            $item_description = I("item_description");
+            $item_type = I("item_type");
+
+            if ($item_domain) {
+                $item = D("Item")->where("item_domain = '%s' and item_id !='%s' ",array($item_domain,$item_id))->find();
+                if ($item) {
+                    //个性域名已经存在
+                    $this->message(L('domain_already_exists'));
+                    return false;
+                }
+                if(!ctype_alnum($item_domain) ||  is_numeric($item_domain) ){
+                    //echo '个性域名只能是字母或数字的组合';exit;
+                    $this->message(L('item_domain_illegal'));
+                    return false;
+                }
+            }
+            
+            //如果是复制项目
+            if ($copy_item_id > 0) {
+                if (!$this->checkItemPermn($login_user['uid'] , $copy_item_id)) {
+                    $this->message(L('no_permissions'));
+                    return;
+                }
+                $ret = D("Item")->copy($copy_item_id,$login_user['uid'],$item_name,$item_description,$password,$item_domain);
+                if ($ret) {
+                    $this->message(L('operation_succeeded'),U('Home/Item/index'));              
+                }else{
+                    $this->message(L('operation_failed'),U('Home/Item/index'));
+                }
+                return ;
+            }
+            if ($item_id > 0 ) {
+                $data = array(
+                    "item_name" => $item_name ,
+                    "item_domain" => $item_domain ,
+                    "password" => $password ,
+                    "item_description" => $item_description ,
+                    );
+                $ret = D("Item")->where("item_id = '$item_id' ")->save($data);
+            }else{
+                $insert = array(
+                    "uid" => $login_user['uid'] ,
+                    "username" => $login_user['username'] ,
+                    "item_name" => $item_name ,
+                    "password" => $password ,
+                    "item_description" => $item_description ,
+                    "item_domain" => $item_domain ,
+                    "item_type" => $item_type ,
+                    "addtime" =>time()
+                    );
+                $item_id = D("Item")->add($insert);
+            }
+
+            if ($item_id) {
+                //如果是单页应用,则新建一个默认页
+                if ($item_type == 2 ) {
+                    $insert = array(
+                        'author_uid' => $login_user['uid'] ,
+                        'author_username' => $login_user['username'],
+                        "page_title" => $item_name ,
+                        "item_id" => $item_id ,
+                        "cat_id" => 0 ,
+                        "page_content" => '欢迎使用showdoc。点击右上方的编辑按钮进行编辑吧!' ,
+                        "addtime" =>time()
+                        );
+                    D("Page")->add($insert);
+                }
+                $this->message(L('operation_succeeded'),U('Home/Item/index'));              
+            }else{
+                $this->message(L('operation_failed'),U('Home/Item/index'));
+            }
+        }
+    }
+
+    //根据项目类型展示项目
+    public function show(){
+        $this->checkLogin(false);
+        $item_id = I("item_id/d");
+        $item_domain = I("item_domain/s");
+        $current_page_id = I("page_id/d");
+        //判断个性域名
+        if ($item_domain) {
+            $item = D("Item")->where("item_domain = '%s'",array($item_domain))->find();
+            if ($item['item_id']) {
+                $item_id = $item['item_id'] ;
+            }
+        }
+        $login_user = session("login_user");
+        $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
+            
+        $this->checkItemVisit($uid , $item_id);
+
+
+        $item = D("Item")->where("item_id = '$item_id' ")->find();
+        if ($item['item_type'] == 1 ) {
+            $this->_show_regular_item($item);
+        }
+        elseif ($item['item_type'] == 2 ) {
+            $this->_show_single_page_item($item);
+        }else{
+           $this->_show_regular_item($item); 
+        }
+        
+
+    }
+
+    //展示常规项目
+    private function _show_regular_item($item){
+        $item_id = $item['item_id'];
+
+        $current_page_id = I("page_id/d");
+        $keyword = I("keyword");
+
+        $login_user = session("login_user");
+        $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
+            
+        //是否有搜索词
+        if ($keyword) {
+            $keyword = \SQLite3::escapeString($keyword) ;
+            $pages = D("Page")->where("item_id = '$item_id' and ( page_title like '%{$keyword}%' or page_content like '%{$keyword}%' ) ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
+        
+        }else{
+            //获取所有父目录id为0的页面
+            $pages = D("Page")->where("cat_id = '0' and item_id = '$item_id' ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
+            //获取所有二级目录
+            $catalogs = D("Catalog")->where("item_id = '$item_id' and level = 2  ")->order(" `s_number` asc  ")->select();
+            if ($catalogs) {
+                foreach ($catalogs as $key => &$catalog) {
+                    //该二级目录下的所有子页面
+                    $temp = D("Page")->where("cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
+                    $catalog['pages'] = $temp ? $temp: array();
+
+                    //该二级目录下的所有子目录
+                    $temp = D("catalog")->where("parent_cat_id = '$catalog[cat_id]' ")->order(" `s_number` asc  ")->select();
+                    $catalog['catalogs'] = $temp ? $temp: array();
+                    if($catalog['catalogs']){
+                        //获取所有三级目录的子页面
+                        foreach ($catalog['catalogs'] as $key3 => &$catalog3) {
+                            //该二级目录下的所有子页面
+                            $temp = D("Page")->where("cat_id = '$catalog3[cat_id]' ")->order(" `s_number` asc  ")->field("page_id,author_uid,cat_id,page_title,addtime")->select();
+                            $catalog3['pages'] = $temp ? $temp: array();
+                        }                        
+                    }               
+                }
+            }
+        }
+
+        $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
+        $share_url = get_domain().__APP__.'/'.$domain;
+
+        $ItemPermn = $this->checkItemPermn($uid , $item_id) ;
+
+        $ItemCreator = $this->checkItemCreator($uid , $item_id);
+
+        if (LANG_SET == 'en-us') {
+            $help_url = "http://api.pkbigdata.com/help-en";
+        }
+        else{
+            $help_url = "http://api.pkbigdata.com/help";
+        }
+        
+        $this->assign("help_url" , $help_url);
+        $this->assign("current_page_id" , $current_page_id);
+        $this->assign("keyword" , $keyword);
+        $this->assign("ItemPermn" , $ItemPermn);
+        $this->assign("ItemCreator" , $ItemCreator);
+        $this->assign("share_url" , $share_url);
+        $this->assign("catalogs" , $catalogs);
+        $this->assign("pages" , $pages);
+        $this->assign("item" , $item);
+        $this->assign("login_user" , $login_user);
+        $this->display("show_regular");
+    }
+
+    //展示单页项目
+    private function _show_single_page_item($item){
+        $item_id = $item['item_id'];
+
+        $current_page_id = I("page_id/d");
+
+        $login_user = session("login_user");
+        $uid = $login_user['uid'] ? $login_user['uid'] : 0 ;
+
+        //获取页面
+        $page = D("Page")->where(" item_id = '$item_id' ")->find();
+
+        $domain = $item['item_domain'] ? $item['item_domain'] : $item['item_id'];
+        $share_url = get_domain().__APP__.'/'.$domain;
+
+        $ItemPermn = $this->checkItemPermn($uid , $item_id) ;
+
+        $ItemCreator = $this->checkItemCreator($uid , $item_id);
+
+        $this->assign("current_page_id" , $current_page_id);
+        $this->assign("ItemPermn" , $ItemPermn);
+        $this->assign("ItemCreator" , $ItemCreator);
+        $this->assign("share_url" , $share_url);
+        $this->assign("catalogs" , $catalogs);
+        $this->assign("page" , $page);
+        $this->assign("item" , $item);
+        $this->assign("login_user" , $login_user);
+        $this->display("show_single_page");
+    }
+    //删除项目
+    public function delete(){
+        $item_id =  I("item_id");
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        $this->assign("item_id" , $item_id);
+        $this->display(); 
+    }
+
+    //删除项目
+    public function ajaxDelete(){
+        $login_user = $this->checkLogin();
+
+        $item_id = I("item_id/d");
+        $password = I("password");
+
+        $item  = D("Item")->where("item_id = '$item_id' ")->find();
+
+        if(! D("User")-> checkLogin($item['username'],$password)){
+            $return['error_code'] = 10102 ;
+            $return['error_message'] = L('incorrect_password') ;
+            $this->sendResult($return);
+            return ;
+        }
+
+
+        D("Page")->where("item_id = '$item_id' ")->delete();
+        D("Catalog")->where("item_id = '$item_id' ")->delete();
+        D("PageHistory")->where("item_id = '$item_id' ")->delete();
+        D("ItemMember")->where("item_id = '$item_id' ")->delete();
+        $return = D("Item")->where("item_id = '$item_id' ")->delete();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+    }
+
+    //输入访问密码
+    public function pwd(){
+        $item_id = I("item_id/d");
+        $CloseVerify = C('CloseVerify');
+        $refer_url = I('refer_url');
+        //var_dump(urldecode($refer_url));
+        $this->assign('CloseVerify',$CloseVerify);
+        $this->assign('refer_url',$refer_url);
+        if (!IS_POST) {
+          $this->assign("item_id" , $item_id);
+          $this->display ();
+
+        }else{
+          $password = I("password");
+          $v_code = I("v_code");
+          if ( $CloseVerify ||  ( $v_code && $v_code == session('v_code') )) {
+            $item = D("Item")->where("item_id = '$item_id' ")->find();
+            if ($item['password'] == $password) {
+                session("visit_item_".$item_id , 1 );
+                if ($refer_url) {
+                    header("location:".base64_decode($refer_url));
+                }else{
+                    header("location:".U("Home/Item/show").'&item_id='.$item_id);
+                }
+                
+            }else{
+                
+                $this->message(L('access_password_are_incorrect'));
+            }
+
+          }else{
+            $this->message(L('verification_code_are_incorrect'));
+          }
+
+        }
+    }
+
+    //导出word
+    public function export(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");  
+        $uid = $login_user['uid'] ;
+        $this->checkItemPermn($uid , $item_id) ; 
+
+        $item = D("Item")->where("item_id = '$item_id' ")->find();
+
+        //对于单页项目,直接导出。对于普通项目,则让其选择目录
+        if ($item['item_type'] == 2 ) {
+            $url = 'server/index.php?s=/api/export/word&item_id='.$item_id ;
+            header("location:{$url}");
+        }else{
+            $this->assign("item_id",$item_id);
+            $this->display();
+        }
+    }
+
+    public function itemList(){
+        $login_user = $this->checkLogin();        
+        $items  = D("Item")->where("uid = '$login_user[uid]' ")->select();
+        $items = $items ? $items : array();
+        $this->sendResult($items);
+    }
+
+    public function setting(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d");  
+        $uid = $login_user['uid'] ;
+        $this->checkItemPermn($uid , $item_id) ; 
+        $this->assign("item_id",$item_id);
+        $this->display();
+    }
+
+}

+ 99 - 0
Application/Home/Controller/MemberController.class.php

@@ -0,0 +1,99 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class MemberController extends BaseController {
+
+    //编辑页面
+    public function edit(){
+        $item_id =  I("item_id");
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        $this->assign("item_id" , $item_id);
+
+        $this->display();        
+    }
+
+    //保存
+    public function save(){
+        $item_id =  I("item_id/d");
+        $member_group_id =  I("member_group_id/d");
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        $username = I("username");
+        $member = D("User")->where(" username = '%s' ",array($username))->find();
+
+        if (!$member) {
+            $return['error_code'] = 10201 ;
+            $return['error_message'] =L('user_does_not_exist') ;
+            $this->sendResult($return);
+            return ;
+        }
+
+        $data['username'] = $member['username'] ;
+        $data['uid'] = $member['uid'] ;
+        $data['item_id'] = $item_id ;
+        $data['member_group_id'] = $member_group_id ;
+        $data['addtime'] = time() ;
+        
+
+        $id = D("ItemMember")->add($data);
+        $return = D("ItemMember")->where(" item_member_id = '$id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取成员列表
+    public function getList(){
+        $item_id = I("item_id/d");
+        if ($item_id > 0 ) {
+            $ret = D("ItemMember")->where(" item_id = '$item_id' ")->order(" addtime asc  ")->select();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //删除成员
+    public function delete(){
+        $item_id = I("item_id/d")? I("item_id/d") : 0;
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+        $username = I("username")? I("username") : 0;
+
+        if ($username) {
+            
+            $ret = D("ItemMember")->where(" item_id = '%d' and username = '%s'  ",array($item_id,$username))->delete();
+
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 300 - 0
Application/Home/Controller/PageController.class.php

@@ -0,0 +1,300 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class PageController extends BaseController {
+
+    //展示某个项目的单个页面
+    public function index(){
+        import("Vendor.Parsedown.Parsedown");
+        $page_id = I("page_id/d");
+        $page = D("Page")->where(" page_id = '$page_id' ")->find();
+        $login_user = $this->checkLogin(false);
+        if (!$this->checkItemVisit($login_user['uid'] , $page['item_id'])) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $ItemPermn = $this->checkItemPermn($login_user['uid'] , $page['item_id']) ;
+        $ItemCreator = $this->checkItemCreator($login_user['uid'],$page['item_id']);
+		$page['page_md_content'] = $page['page_content'];
+
+        //$Parsedown = new \Parsedown();
+        //$page['page_content'] = $Parsedown->text(htmlspecialchars_decode($page['page_content']));
+        $this->assign("page" , $page);
+        $this->display();
+    }
+
+    //展示单个页面
+    public function single(){
+        import("Vendor.Parsedown.Parsedown");
+        $page_id = I("page_id/d");
+        $page = D("Page")->where(" page_id = '$page_id' ")->find();
+        $login_user = $this->checkLogin(false);
+        if (!$this->checkItemVisit($login_user['uid'] , $page['item_id'],$_SERVER['REQUEST_URI'])) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $ItemPermn = $this->checkItemPermn($login_user['uid'] , $page['item_id']) ;
+        $ItemCreator = $this->checkItemCreator($login_user['uid'],$page['item_id']);
+
+        $page['page_md_content'] = $page['page_content'];
+        //$page['page_html_content'] = $Parsedown->text(htmlspecialchars_decode($page['page_content']));
+        $this->assign("page" , $page);
+        $this->assign("login_user" , $login_user);
+        $this->display();
+    }
+
+    //返回单个页面的源markdown代码
+    public function md(){
+        $page_id = I("page_id/d");
+        $page = D("Page")->where(" page_id = '$page_id' ")->find();
+        echo $page['page_content'];
+    }
+
+    //编辑页面
+    public function edit(){
+        $login_user = $this->checkLogin();
+        $page_id = I("page_id/d");
+        $item_id = I("item_id/d");
+
+        $page_history_id = I("page_history_id/d");
+        $copy_page_id = I("copy_page_id/d");
+
+        if ($page_id > 0 ) {
+            if ($page_history_id) {
+                $page = D("PageHistory")->where(" page_history_id = '$page_history_id' ")->find();
+                $page_content = gzuncompress(base64_decode($page['page_content'])); 
+                $page['page_content'] = $page_content ? $page_content : $page['page_content'] ;
+            }else{
+                $page = D("Page")->where(" page_id = '$page_id' ")->find();
+            }
+            $default_cat_id = $page['cat_id'];
+        }
+        //如果是复制接口
+        elseif ($copy_page_id) {
+            $copy_page = D("Page")->where(" page_id = '$copy_page_id' ")->find();
+            $page['page_title'] = $copy_page['page_title']."-copy";
+            $page['page_content'] = $copy_page['page_content'];
+            $page['item_id'] = $copy_page['item_id'];
+            $default_cat_id = $copy_page['cat_id'];
+
+        }else{
+            //查找用户上一次设置的目录
+            $last_page = D("Page")->where(" author_uid ='$login_user[uid]' and $item_id = '$item_id' ")->order(" addtime desc ")->limit(1)->find();
+            $default_cat_id = $last_page['cat_id'];
+
+
+        }
+
+        $item_id = $page['item_id'] ?$page['item_id'] :$item_id;
+
+        
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $Catalog = D("Catalog")->where(" cat_id = '$default_cat_id' ")->find();
+        if ($Catalog['parent_cat_id']) {
+            $default_second_cat_id = $Catalog['parent_cat_id'];
+            $default_child_cat_id = $default_cat_id;
+
+        }else{
+            $default_second_cat_id = $default_cat_id;
+        }
+        $this->assign("api_doc_templ" , 'MdTemplate/api-doc.'.LANG_SET);
+        $this->assign("database_doc_templ" , 'MdTemplate/database.'.LANG_SET);
+        $this->assign("page" , $page);
+        $this->assign("item_id" , $item_id);
+        $this->assign("default_second_cat_id" , $default_second_cat_id);
+        $this->assign("default_child_cat_id" , $default_child_cat_id);
+
+
+        $this->display();        
+    }
+
+    //保存
+    public function save(){
+        $login_user = $this->checkLogin();
+        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
+        $page_title = I("page_title") ?I("page_title") : L("default_title");
+        $page_comments = I("page_comments") ?I("page_comments") :'';
+        $page_content = I("page_content");
+        $cat_id = I("cat_id/d")? I("cat_id/d") : 0;
+        $item_id = I("item_id/d")? I("item_id/d") : 0;
+        $s_number = I("s_number/d")? I("s_number/d") : 99;
+
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $data['page_title'] = $page_title ;
+        $data['page_content'] = $page_content ;
+        $data['page_comments'] = $page_comments ;
+        $data['s_number'] = $s_number ;
+        $data['item_id'] = $item_id ;
+        $data['cat_id'] = $cat_id ;
+        $data['addtime'] = time();
+        $data['author_uid'] = $login_user['uid'] ;
+        $data['author_username'] = $login_user['username'];
+
+        if ($page_id > 0 ) {
+            
+            //在保存前先把当前页面的版本存档
+            $page = D("Page")->where(" page_id = '$page_id' ")->find();
+            $insert_history = array(
+                'page_id'=>$page['page_id'],
+                'item_id'=>$page['item_id'],
+                'cat_id'=>$page['cat_id'],
+                'page_title'=>$page['page_title'],
+                'page_comments'=>$page['page_comments'],
+                'page_content'=>base64_encode( gzcompress($page['page_content'], 9)),
+                's_number'=>$page['s_number'],
+                'addtime'=>$page['addtime'],
+                'author_uid'=>$page['author_uid'],
+                'author_username'=>$page['author_username'],
+                );
+             D("PageHistory")->add($insert_history);
+
+            $ret = D("Page")->where(" page_id = '$page_id' ")->save($data);
+
+            //统计该page_id有多少历史版本了
+            $Count = D("PageHistory")->where(" page_id = '$page_id' ")->Count();
+            if ($Count > 20 ) {
+               //每个单页面只保留最多20个历史版本
+               $ret = D("PageHistory")->where(" page_id = '$page_id' ")->limit("20")->order("page_history_id desc")->select();
+               D("PageHistory")->where(" page_id = '$page_id' and page_history_id < ".$ret[19]['page_history_id'] )->delete();
+            }
+
+            //如果是单页项目,则将页面标题设置为项目名
+            $item_array = D("Item")->where(" item_id = '$item_id' ")->find();
+            if ($item_array['item_type'] == 2 ) {
+                D("Item")->where(" item_id = '$item_id' ")->save(array("last_update_time"=>time(),"item_name"=>$page_title));
+            }else{
+                D("Item")->where(" item_id = '$item_id' ")->save(array("last_update_time"=>time()));
+            }
+
+            $return = D("Page")->where(" page_id = '$page_id' ")->find();
+        }else{
+            
+            $page_id = D("Page")->add($data);
+
+            //更新项目时间
+            D("Item")->where(" item_id = '$item_id' ")->save(array("last_update_time"=>time()));
+
+            $return = D("Page")->where(" page_id = '$page_id' ")->find();
+        }
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+        $this->sendResult($return);
+        
+    }
+
+    //删除页面
+    public function delete(){
+        $page_id = I("page_id/d")? I("page_id/d") : 0;
+        $page = D("Page")->where(" page_id = '$page_id' ")->find();
+
+        $login_user = $this->checkLogin();
+        if (!$this->checkItemCreator($login_user['uid'] , $page['item_id']) && $login_user['uid'] != $page['author_uid']) {
+            $this->message(L('no_permissions_to_delete_page',array("author_username"=>$page['author_username'])));
+            return;
+        }
+
+        if ($page) {
+            
+            $ret = D("Page")->where(" page_id = '$page_id' ")->delete();
+            //更新项目时间
+            D("Item")->where(" item_id = '$page[item_id]' ")->save(array("last_update_time"=>time()));
+
+        }
+        if ($ret) {
+           $this->message(L('delete_succeeded'),U("Home/item/show?item_id={$page['item_id']}"));
+        }else{
+           $this->message(L('delete_failed'),U("Home/item/show?item_id={$page['item_id']}"));
+        }
+    }
+
+    //历史版本
+    public function history(){
+        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
+        $this->assign("page_id" , $page_id);
+
+        $PageHistory = D("PageHistory")->where("page_id = '$page_id' ")->order(" addtime desc")->limit(10)->select();
+
+        if ($PageHistory) {
+            foreach ($PageHistory as $key => &$value) {
+                $page_content = gzuncompress(base64_decode($value['page_content'])); 
+                $value['page_content'] = $page_content ? $page_content : $value['page_content'] ;
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+            }
+        }
+
+        $this->assign("PageHistory" , $PageHistory);
+
+        $this->display();        
+
+    }
+
+    //上传图片
+    public function uploadImg(){
+        $qiniu_config = C('UPLOAD_SITEIMG_QINIU') ;
+        if ($_FILES['editormd-image-file']['name'] == 'blob') {
+            $_FILES['editormd-image-file']['name'] .= '.jpg';
+        }
+        if (strstr(strtolower($_FILES['editormd-image-file']['name']), ".php") ) {
+            return false;
+        }
+        if (!empty($qiniu_config['driverConfig']['secrectKey'])) {
+          //上传到七牛
+          $Upload = new \Think\Upload(C('UPLOAD_SITEIMG_QINIU'));
+          $info = $Upload->upload($_FILES);
+          $url = $info['editormd-image-file']['url'] ;
+          echo json_encode(array("url"=>$url,"success"=>1));
+        }else{
+            $upload = new \Think\Upload();// 实例化上传类
+            $upload->maxSize  = 3145728 ;// 设置附件上传大小
+            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
+            $upload->rootPath = './Public/Uploads/';// 设置附件上传目录
+            $upload->savePath = '';// 设置附件上传子目录
+            $info = $upload->upload() ;
+            if(!$info) {// 上传错误提示错误信息
+              $this->error($upload->getError());
+              return;
+            }else{// 上传成功 获取上传文件信息
+              $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['editormd-image-file']['savepath'].$info['editormd-image-file']['savename'] ;
+              echo json_encode(array("url"=>$url,"success"=>1));
+            }
+        }
+
+    }
+
+    public function diff(){
+        $login_user = $this->checkLogin();
+        $page_history_id = I("page_history_id/d");
+        $page_id = I("page_id/d");
+
+        $page = D("Page")->where(" page_id = '$page_id' ")->find();
+        $cur_page_content = $page['page_content'];
+
+        $item_id = $page['item_id'] ?$page['item_id'] :$item_id;
+
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->message(L('no_permissions'));
+            return;
+        }
+
+        $page = D("PageHistory")->where(" page_history_id = '$page_history_id' ")->find();
+        $page_content = gzuncompress(base64_decode($page['page_content'])); 
+        $history_page_content = $page_content ? $page_content : $page['page_content'] ;
+        
+        $this->assign("cur_page_content" , $cur_page_content);
+        $this->assign("history_page_content" , $history_page_content);
+        $this->display(); 
+    }
+}

+ 71 - 0
Application/Home/Controller/TemplateController.class.php

@@ -0,0 +1,71 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class TemplateController extends BaseController {
+
+
+    //保存
+    public function save(){
+        $login_user = $this->checkLogin();
+
+        $template_title = I("template_title");
+        $template_content = I("template_content");
+
+        $data['username'] = $login_user['username'] ;
+        $data['uid'] = $login_user['uid'] ;
+        $data['template_title'] = $template_title ;
+        $data['template_content'] = $template_content ;
+        $data['addtime'] = time() ;
+        
+
+        $id = D("Template")->add($data);
+        $return = D("Template")->where(" id = '$id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取我的模板列表
+    public function getList(){
+        $login_user = $this->checkLogin();
+        if ($login_user['uid'] > 0 ) {
+            $ret = D("Template")->where(" uid = '$login_user[uid]' ")->order(" addtime desc  ")->select();
+        }
+        if ($ret) {
+            foreach ($ret as $key => &$value) {
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+                $value['template_content'] = htmlspecialchars_decode($value['template_content']);
+            }
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+    //删除目录
+    public function delete(){
+        $id = I("id/d")? I("id/d") : 0;
+        $login_user = $this->checkLogin();
+        if ($id && $login_user['uid']) {
+            $ret = D("Template")->where(" id = '$id' and uid = '$login_user[uid]'")->delete();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 495 - 0
Application/Home/Controller/UpdateController.class.php

@@ -0,0 +1,495 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class UpdateController extends BaseController {
+    
+ 	//升级数据库
+    public function db(){
+        $this->_clear_runtime();
+    	if (strtolower(C("DB_TYPE")) == 'mysql' ) {
+    		//$this->mysql();
+            echo 'ShowDoc does not support mysql any more . http://api.pkbigdata.com/help?page_id=31990 ';
+    	}
+        elseif (strtolower(C("DB_TYPE")) == 'sqlite' ) {
+            $this->sqlite();
+        }
+    	$this->_clear_runtime();
+    }
+    public function sqlite(){
+        //catalog表增加parent_cat_id字段
+        $columns = M("catalog")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'parent_cat_id') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' ;";
+                D("catalog")->execute($sql);
+            }
+        }
+
+        //catalog表增加level字段
+        $columns = M("catalog")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'level') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2'  ;";
+                D("catalog")->execute($sql);
+            }
+        }
+
+        //item表增加item_domain字段
+        $columns = M("item")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'item_domain') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain text NOT NULL DEFAULT '';";
+                D("item")->execute($sql);
+            }
+        }
+        //创建user_token表
+        $sql = "CREATE TABLE IF NOT EXISTS `user_token` (
+        `id`  INTEGER PRIMARY KEY ,
+        `uid` int(10) NOT NULL DEFAULT '0',
+        `token` CHAR(200) NOT NULL DEFAULT '',
+        `token_expire` int(11) NOT NULL DEFAULT '0' ,
+        `ip` CHAR(200) NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0'
+        )";
+        D("UserToken")->execute($sql);
+
+        //创建template表
+        $sql = "CREATE TABLE IF NOT EXISTS `template` (
+        `id`  INTEGER PRIMARY KEY ,
+        `uid` int(10) NOT NULL DEFAULT '0',
+        `username` CHAR(200) NOT NULL DEFAULT '',
+        `template_title` CHAR(200) NOT NULL DEFAULT '' ,
+        `template_content` text NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0'
+        )";
+        D("UserToken")->execute($sql);
+
+        //page表增加page_comments字段
+        $columns = D("Page")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'page_comments') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments text NOT NULL DEFAULT ''  ;";
+                D("Page")->execute($sql);
+            }
+        }
+
+        //page_history 表增加page_comments字段
+        $columns = D("PageHistory")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'page_comments') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments text NOT NULL DEFAULT '';";
+                D("PageHistory")->execute($sql);
+            }
+        }
+
+        //item_member表增加member_group_id字段
+        $columns = M("ItemMember")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'member_group_id') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item_member ADD member_group_id INT( 1 ) NOT NULL DEFAULT '1'  ;";
+                D("ItemMember")->execute($sql);
+            }
+        }
+
+        //item表增加item_type字段
+        $columns = M("Item")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'item_type') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_type INT( 1 ) NOT NULL DEFAULT '1'  ;";
+                D("Item")->execute($sql);
+            }
+        }
+
+        //创建options表
+        $sql = "CREATE TABLE IF NOT EXISTS `options` (
+        `option_id`  INTEGER PRIMARY KEY ,
+        `option_name` CHAR(200) NOT NULL UNIQUE ,
+        `option_value` CHAR(200) NOT NULL 
+        )";
+        D("UserToken")->execute($sql);
+
+        //创建item_token表
+        $sql = "CREATE TABLE IF NOT EXISTS `item_token` (
+        `id`  INTEGER PRIMARY KEY ,
+        `item_id` int(11) NOT NULL DEFAULT '0' ,
+        `api_key` CHAR(200) NOT NULL UNIQUE ,
+        `api_token` CHAR(200) NOT NULL ,
+        `addtime` int(11) NOT NULL DEFAULT '0' ,
+        `last_check_time` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("UserToken")->execute($sql);
+
+        //创建item_top表
+        $sql = "CREATE TABLE IF NOT EXISTS `item_top` (
+        `id`  INTEGER PRIMARY KEY ,
+        `item_id` int(11) NOT NULL DEFAULT '0' ,
+        `uid` int(11) NOT NULL DEFAULT '0' ,
+        `addtime` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("UserToken")->execute($sql);
+
+        //item表增加is_archived字段
+        $columns = M("Item")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'is_archived') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD is_archived INT( 1 ) NOT NULL DEFAULT '0'  ;";
+                D("Item")->execute($sql);
+            }
+        }
+
+
+        echo 'OK!';
+    }
+
+    private function _clear_runtime($path = RUNTIME_PATH){  
+        //给定的目录不是一个文件夹  
+        if(!is_dir($path)){  
+            return null;  
+        }  
+      
+        $fh = opendir($path);  
+        while(($row = readdir($fh)) !== false){  
+            //过滤掉虚拟目录  
+            if($row == '.' || $row == '..'|| $row == 'index.html'){  
+                continue;  
+            }  
+      
+            if(!is_dir($path.'/'.$row)){
+                unlink($path.'/'.$row);  
+            }  
+            $this->_clear_runtime($path.'/'.$row);  
+              
+        }  
+        //关闭目录句柄,否则出Permission denied  
+        closedir($fh);    
+        return true;  
+    }
+
+    //转移mysql的数据到sqlite
+    public function toSqlite(){
+        $this->_clear_runtime();
+        if (strtolower(C("DB_TYPE")) == 'mysql' ) {
+            $this->mysql();
+            $this->_moveTable("catalog");
+            $this->_moveTable("item");
+            $this->_moveTable("item_member");
+            $this->_moveTable("page");
+            $this->_moveTable("page_history");
+            $this->_moveTable("template");
+            $this->_moveTable("user");
+            $this->_moveTable("user_token");
+            $db_config = array(
+                'DB_TYPE'   => 'Sqlite', 
+                'DB_NAME'   => 'Sqlite/showdoc.db.php', 
+                );
+            $array = M("item")->db(2,$db_config)->select();
+            if ($array) {
+                echo "ok";
+            }else{
+                echo 'fail';
+            }
+            
+        }
+        else{
+            echo "mysql not found";
+        }
+        $this->_clear_runtime();
+    }
+
+    //升级mysql数据库  
+    public function mysql(){
+
+        //user表的username字段增大了长度,防止长邮箱的用户名注册不了
+        $sql = "alter table ".C('DB_PREFIX')."user modify column username varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '' ";
+        M("Catalog")->execute($sql);
+
+        //item表增加last_update_time字段
+        $columns = M("item")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'last_update_time') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD last_update_time INT( 11 ) NOT NULL DEFAULT '0' COMMENT '最后更新时间';";
+                D("Item")->execute($sql);
+            }
+        }
+        
+
+        //更改catalog表的order字段名为s_number
+        $columns = M("Catalog")->getDbFields();
+        if ($columns) {
+            foreach ($columns as $key => $value) {
+                if ($value == 'order') {
+                    $sql = "ALTER TABLE  `".C('DB_PREFIX')."catalog` CHANGE  `order`  `s_number` INT( 10 ) NOT NULL DEFAULT  '99' COMMENT  '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
+                    M("Catalog")->execute($sql);
+                }
+            }
+        }
+
+        //更改page表的order字段名为s_number
+        $columns = M("Page")->getDbFields();
+        if ($columns) {
+            foreach ($columns as $key => $value) {
+                if ($value == 'order') {
+                    $sql = "ALTER TABLE  `".C('DB_PREFIX')."page` CHANGE  `order`  `s_number` INT( 10 ) NOT NULL DEFAULT  '99' COMMENT  '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
+                    M("Page")->execute($sql);
+                }
+            }
+        }
+
+        //更改page_history表的order字段名为s_number
+        $columns = M("PageHistory")->getDbFields();
+        if ($columns) {
+            foreach ($columns as $key => $value) {
+                if ($value == 'order') {
+                    $sql = "ALTER TABLE  `".C('DB_PREFIX')."page_history` CHANGE  `order`  `s_number` INT( 10 ) NOT NULL DEFAULT  '99' COMMENT  '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
+                    M("PageHistory")->execute($sql);
+                }
+            }
+        }
+
+        //为catalog表增加addtime索引
+        $indexs = M("Catalog")->query(" show index from ".C('DB_PREFIX')."catalog");
+        if ($indexs) {
+            $has_it = 0 ;//是否存在该索引
+            foreach ($indexs as $key => $value) {
+                if ($value['column_name'] =='addtime') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0 ) {
+                M("Catalog")->execute("ALTER TABLE ".C('DB_PREFIX')."catalog ADD INDEX ( `addtime` ) ;");
+            }
+        }
+
+        //为item表增加addtime索引
+        $indexs = M("Item")->query(" show index from ".C('DB_PREFIX')."item");
+        if ($indexs) {
+            $has_it = 0 ;//是否存在该索引
+            foreach ($indexs as $key => $value) {
+                if ($value['column_name'] =='addtime') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0 ) {
+                M("Item")->execute("ALTER TABLE ".C('DB_PREFIX')."item ADD INDEX ( `addtime` ) ;");
+            }
+        }
+
+        //为page表增加addtime索引
+        $indexs = M("Page")->query(" show index from ".C('DB_PREFIX')."page");
+        if ($indexs) {
+            $has_it = 0 ;//是否存在该索引
+            foreach ($indexs as $key => $value) {
+                if ($value['column_name'] =='addtime') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0 ) {
+                M("page")->execute("ALTER TABLE ".C('DB_PREFIX')."page ADD INDEX ( `addtime` ) ;");
+            }
+        }
+
+        //为page_history表增加addtime索引
+        $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
+        if ($indexs) {
+            $has_it = 0 ;//是否存在该索引
+            foreach ($indexs as $key => $value) {
+                if ($value['column_name'] =='addtime') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0 ) {
+                M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `addtime` ) ;");
+            }
+        }
+
+        //为page_history表增加page_id索引
+        $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
+        if ($indexs) {
+            $has_it = 0 ;//是否存在该索引
+            foreach ($indexs as $key => $value) {
+                if ($value['column_name'] =='page_id') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0 ) {
+                M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `page_id` ) ;");
+            }
+        }
+
+
+        //catalog表增加parent_cat_id字段
+        $columns = M("catalog")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'parent_cat_id') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' COMMENT '上一级目录的id';";
+                D("catalog")->execute($sql);
+            }
+        }
+
+        //catalog表增加level字段
+        $columns = M("catalog")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'level') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2' COMMENT '2为二级目录,3为三级目录';";
+                D("catalog")->execute($sql);
+            }
+        }
+        //item表增加item_domain字段
+        $columns = M("item")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'item_domain') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain varchar( 50 ) NOT NULL DEFAULT '' COMMENT 'item的个性域名';";
+                D("item")->execute($sql);
+            }
+        }
+
+        $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."user_token` (
+        `id` int(10) NOT NULL AUTO_INCREMENT,
+        `uid` int(10) NOT NULL DEFAULT '0',
+        `token` varchar(200) NOT NULL DEFAULT '',
+        `token_expire` int(11) NOT NULL DEFAULT '0' ,
+        `ip` varchar(200) NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0',
+        PRIMARY KEY (`id`),
+        KEY `token` (`token`)
+        ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1 ";
+        D("User")->execute($sql);
+
+        //创建template表
+        $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."template` (
+        `id` int(10) NOT NULL AUTO_INCREMENT,
+        `uid` int(10) NOT NULL DEFAULT '0',
+        `username` varchar(200) NOT NULL DEFAULT '',
+        `template_title` varchar(200) NOT NULL DEFAULT '' ,
+        `template_content` text NOT NULL ,
+        `addtime` int(11) NOT NULL DEFAULT '0',
+        PRIMARY KEY (`id`),
+        KEY `uid` (`uid`)
+        )ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1";
+        D("UserToken")->execute($sql);
+
+        //page表增加page_comments字段
+        $columns = M("Page")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'page_comments') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
+                D("Page")->execute($sql);
+            }
+        }
+        //page_history表增加page_comments字段
+        $columns = M("PageHistory")->getDbFields();
+        if ($columns) {
+            $has_it = 0 ;//是否存在该字段
+            foreach ($columns as $key => $value) {
+                if ($value == 'page_comments') {
+                    $has_it = 1 ;
+                }
+            }
+            if ($has_it === 0) {
+                $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
+                D("PageHistory")->execute($sql);
+            }
+        }
+
+        if(D("User")->where("uid = 1 ")->find()){
+        $db_config = array(
+            'DB_TYPE'   => 'Sqlite', 
+            'DB_NAME'   => 'Sqlite/showdoc.db.php', 
+            );
+            M("User")->db(2,$db_config)->where("uid = 1 ")->delete();    
+        }
+    }
+
+    private function _moveTable($table){
+        $db_config = array(
+            'DB_TYPE'   => 'Sqlite', 
+            'DB_NAME'   => 'Sqlite/showdoc.db.php', 
+            );
+        $array = M($table)->select();
+        if ($array) {
+            foreach ($array as $key => $value) {
+               M($table)->db(2,$db_config)->add($value);
+            }
+        }
+    }
+
+
+}

+ 165 - 0
Application/Home/Controller/UserController.class.php

@@ -0,0 +1,165 @@
+<?php
+namespace Home\Controller;
+use Think\Controller;
+class UserController extends BaseController {
+
+
+	//注册
+	public function register(){
+		if (!IS_POST) {
+			  $this->assign('CloseVerify',C('CloseVerify'));
+			  $this->display ();
+			}else{
+			  $username = I("username");
+			  $password = I("password");
+			  $confirm_password = I("confirm_password");
+			  $v_code = I("v_code");
+			  if (C('CloseVerify') || $v_code && $v_code == session('v_code') ) {
+		  		if ( $password != '' && $password == $confirm_password) {
+
+			  		if ( ! D("User")->isExist($username) ) {
+						$ret = D("User")->register($username,$password);
+						if ($ret) {
+					      $this->message(L('register_succeeded'),U('Home/User/login'));					    
+						}else{
+						  $this->message('register fail');
+						}
+			  		}else{
+			  			$this->message(L('username_exists'));
+			  		}
+
+			  	}else{
+			  		$this->message(L('code_much_the_same'));
+			  	}
+			  }else{
+				    $this->message(L('verification_code_are_incorrect'));
+			  }
+			  
+
+			}
+	}
+
+
+
+	//登录
+	public function login()
+	{
+		if (!IS_POST) {
+			//如果有cookie记录,则自动登录
+			$cookie_token = cookie('cookie_token');
+			if ($cookie_token) {
+				$ret = D("UserToken")->getToken($cookie_token);
+				if ($ret && $ret['token_expire'] > time() ) {
+					D("User")->setLastTime($ret['uid']);
+					$login_user = D("User")->where(array('uid' => $ret['uid']))->field('password', true)->find();
+					session("login_user" , $login_user);
+					$this->message(L('auto_login_succeeded'),U('Home/Item/index'));
+					exit();
+				}
+			}
+			$this->assign('CloseVerify',C('CloseVerify'));
+		  	$this->display ();
+
+		}else{
+		  $username = I("username");
+		  $password = I("password");
+		  $v_code = I("v_code");
+		  if (C('CloseVerify')) { //如果关闭验证码
+		  	$ret = D("User")->checkLogin($username,$password);
+		    if ($ret) {
+		      session("login_user" , $ret );
+		      D("User")->setLastTime($ret['uid']);
+		      $token = D("UserToken")->createToken($ret['uid']);
+	          cookie('cookie_token',$token,60*60*24*90);//此处由服务端控制token是否过期,所以cookies过期时间设置多久都无所谓
+		      unset($ret['password']);
+	          $this->message(L('login_succeeded'),U('Home/Item/index'));		        
+		    }else{
+		      $this->message(L('username_or_password_incorrect'));
+		    }
+		  }else{
+			  if ($v_code && $v_code == session('v_code')) {
+			    $ret = D("User")->checkLogin($username,$password);
+			    if ($ret) {
+			      session("login_user" , $ret );
+			  D("User")->setLastTime($ret['uid']);
+		      	  $token = D("UserToken")->createToken($ret['uid']);
+          		  cookie('cookie_token',$token,60*60*24*90);//此处由服务端控制token是否过期,所以cookies过期时间设置多久都无所谓
+			      unset($ret['password']);
+
+		          $this->message(L('login_succeeded'),U('Home/Item/index'));		        
+			    }else{
+			      $this->message(L('username_or_password_incorrect'));
+			    }
+
+			  }else{
+			    $this->message(L('verification_code_are_incorrect'));
+			  }	
+		  }
+		  
+
+		}
+	}
+
+	//生成验证码
+	public function verify(){
+	  //生成验证码图片
+	  Header("Content-type: image/PNG");
+	  $im = imagecreate(44,18); // 画一张指定宽高的图片
+	  $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
+	  imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
+	  $vcodes = "";
+	  srand((double)microtime()*1000000);
+	  //生成4位数字
+	  for($i=0;$i<4;$i++){
+	  $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
+	  $authnum=rand(1,9);
+	  $vcodes.=$authnum;
+	  imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
+	  }
+	  $_SESSION['v_code'] = $vcodes;
+
+	  for($i=0;$i<200;$i++) //加入干扰象素
+	  {
+	    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
+	    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
+	  }
+	  ImagePNG($im);
+	  ImageDestroy($im);
+	}
+
+	public function setting(){
+		$user = $this->checkLogin();
+		if (!IS_POST) {
+		  $this->assign("user",$user);
+		  $this->display ();
+
+		}else{
+			$username = $user['username'];
+			$password = I("password");
+			$new_password = I("new_password");
+			$ret = D("User")->checkLogin($username,$password);
+			if ($ret) {
+					$ret = D("User")->updatePwd($user['uid'],$new_password);
+					if ($ret) {
+						$this->message(L('modify_succeeded'),U("Home/Item/index"));
+					}else{
+						$this->message(L('modify_faild'));
+
+					}
+
+				}else{	
+					$this->message(L('old_password_incorrect'));
+				}
+
+		}
+	}
+
+	//退出登录
+	public function exist(){
+		$login_user = $this->checkLogin();
+		session("login_user" , NULL);
+		cookie('cookie_token',NULL);
+		session(null);
+		$this->message(L('logout_succeeded'),U('Home/index/index'));
+	}
+}

+ 1 - 0
Application/Home/Controller/index.html

@@ -0,0 +1 @@
+ 

+ 216 - 0
Application/Home/Lang/en-us.php

@@ -0,0 +1,216 @@
+<?php
+return array(
+
+    //Attorn
+    'attorn_item'=>'Attorn item',
+    'username'=>'Username',
+    'receiver_name'=>"Receiver's username",
+    'verify_identity'=>'Verify identity',
+    'your_password'=>'Your password',
+    'attorn'=>'Attorn',
+    'close'=>'close',
+
+    //Catalog
+    'new_or_edit_catalog' => 'New/Edit catalog',
+    'catalog_name' => 'Catalog name',
+    's_number' => 'Order',
+    's_number_explain' => 'Optional: order number',
+    'last_catalog' => 'Parent catalog',
+    'save' => 'Sava',
+    'delete_catalog' => 'Delete catalog',
+    'catalog_list' => 'Catalog list',
+    'click_to_edit' => 'Click to edit',
+
+
+    //index
+    'help' => 'Help',
+    'demo' => 'Demo',
+    'index_login_or_register' => 'Login / Register',
+    'my_item' => 'My items',
+    'section_title1' => 'ShowDoc',
+    'section_description1' => ' A tool greatly applicable for an IT team',
+    'section_title2' => 'API Document',
+    'section_description2' => 'ShowDoc can compile exquisite API documents <br>in a very fast and convenient way',
+    'section_title3' => 'Data Dictionary',
+    'section_description3' => 'A good Data Dictionary can easily exhibit database structure to other people<br>ShowDoc can compile exquisite Data Dictionary',
+    'section_title4' => 'Explanation Document',
+    'section_description4' => 'You can absolutely use ShowDoc to compile the explanation documents for some tools',
+    'section_title5' => 'Team Work',
+    'section_description5' => 'Your team will work with ShowDoc together very well ',
+    'section_title6' => 'Open Source',
+    'section_description6' => 'ShowDoc is a free, open source tool that <br>you can deploy it to your own server',
+    'section_title7' => 'Hosted online',
+    'section_description7' => 'Www.showdoc.cc provide security and stability of the document hosting service',
+    'section_title8' => 'Try it now',
+    'section_description8' => 'Over 6000+ IT team is using ShowDoc',
+
+
+    //Common message
+    'redirect_message' => 'If your browser does not automatically jump, please click on this link.',
+    'click_to_goback' => 'Click to goback',
+    'home' => 'Home',
+    
+
+    //item/add
+    'item_name' => "Item's name",
+    'item_description' => "Item's description",
+    'item_domain' => '(Optional)domain hack',
+    'item_domain_illegal' => 'Domain hack must be a combination of letters and numbers',
+    'domain_already_exists' => 'Domain already exists',
+    'visit_password_placeholder' => 'Access password(Optional: private project required)',
+    'submit' => 'Submit',
+    'goback' => 'Goback',
+    //item/delete
+    'delete_item' => 'Delete item',
+    'verify_your_identity' => 'Verify your identity',
+    'creator_password' => "creator's password",
+    'delete' => 'Delete',
+    'close' => 'Close',
+    //item/index
+    'personal_setting'=>'Personal setting',
+    'share_home'=>'Share home',
+    'web_home'=>'Website home',
+    'logout'=>'Logout',
+    'add_an_item'=>'Add an item',
+    'new_item'=>'New item',
+    'share_my_home'=>'Share my home',
+    'feedback' => "feedback",
+    'home_address'=>'Home address',
+    'home_address_description'=>'The others will be able to see all of your public items When he visits your home page.You can copy the address to your friends.',
+    //item/pwd
+    'input_visit_password'=>'Please enter the access password',
+    'password'=>'Passwod',
+    'verification_code'=>'Verification code',
+    'submit'=>'Submit',
+    'login_or_register'=>'Login/Register',
+    //item/show
+    'item'=>'Item',
+    'share'=>'Share',
+    'export'=>'Export',
+    'update_info'=>'Modify',
+    'manage_members'=>'Members',
+    'attorn'=>'Attorn',
+    'delete'=>'Delete',
+    'more_item'=>'More items',
+    'login_or_register'=>'Login/Register',
+    'about_showdoc'=>'About ShowDoc',
+    'my_item'=>'My items',
+    'new_page'=>'New page',
+    'new_catalog'=>'New catalog',
+    'share_address_to_your_friends'=>'Share address to your friends',
+    'share'=>'Share',
+    'copy_interface_to_new'=>'Copy page  to new ',
+    'copy'=>'Copy',
+    'edit_interface'=>'Edit page',
+    'edit'=>'Edit',
+    'delete_interface'=>'Delete page',
+    'comfirm_delete'=>'Are you sure that you want to delete it?',
+    'delete'=>'Delete',
+    'share'=>'Share',
+    'item_address'=>'Item address',
+    'copy_address_to_your_friends'=>'You can copy the address to your friend.',
+    'share_page'=>'Share page',
+    'page_address'=>'Page address',
+    'copy_address_to_your_friends'=>'You can copy the address to your friend.',
+    //item/showbyuid
+    'more'=>'More',
+    'my_item'=>'My items',
+    'login_or_register'=>'Login/Register',
+    'about_showdoc'=>'About ShowDoc',
+    'all_pubilc_item'=>"'s all public items",
+
+    //member
+    'new_member'=>'New member',
+    'username'=>'Username',
+    'save'=>'Save',
+    'member_list'=>'member list',
+    'click_to_delete'=>'Click to delete',
+    'close'=>'Close',
+    "member_group_id" => "Read-only(can read item ,but not edit or delete )",
+    //page
+    'input_page_title'=>'Please enter a page title',
+    'level_2_directory'=>'Second-level catalog',
+    'level_3_directory'=>'Third-level catalog',
+    's_number_explain'=>'Optional: order number',
+    'history_version'=>'History version',
+    'save'=>'Save',
+    'cancel'=>'Cancel',
+    'inser_apidoc_template'=>'Insert apidoc template',
+    'inser_database_doc_template'=>'Insert db-doc template',
+    'json_tools'=>'Json tools',
+    'json_to_table'=>'Json to table',
+    'beautify_json'=>'Beautify Json',