Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit e6353877da66ed8ebd678f53a1cffa81c091c088 1 parent 5b6795a
anantgarg authored
Showing with 31,933 additions and 0 deletions.
  1. +6 −0 .htaccess
  2. +47 −0 .svn/all-wcprops
  3. +287 −0 .svn/entries
  4. +6 −0 .svn/text-base/.htaccess.svn-base
  5. +76 −0 .svn/text-base/LICENSE.TXT.svn-base
  6. +12 −0 .svn/text-base/README.TXT.svn-base
  7. +1 −0  .svn/text-base/VERSION.TXT.svn-base
  8. +32 −0 .svn/text-base/config.default.php.svn-base
  9. +56 −0 .svn/text-base/index.php.svn-base
  10. +202 −0 .svn/text-base/install.php.svn-base
  11. +41 −0 controllers/.svn/all-wcprops
  12. +232 −0 controllers/.svn/entries
  13. +202 −0 controllers/.svn/text-base/answers.php.svn-base
  14. +98 −0 controllers/.svn/text-base/comments.php.svn-base
  15. +15 −0 controllers/.svn/text-base/helpers.php.svn-base
  16. +954 −0 controllers/.svn/text-base/questions.php.svn-base
  17. +23 −0 controllers/.svn/text-base/tags.php.svn-base
  18. +131 −0 controllers/.svn/text-base/users.php.svn-base
  19. +202 −0 controllers/answers.php
  20. +98 −0 controllers/comments.php
  21. +15 −0 controllers/helpers.php
  22. +954 −0 controllers/questions.php
  23. +23 −0 controllers/tags.php
  24. +131 −0 controllers/users.php
  25. +29 −0 css/.svn/all-wcprops
  26. +164 −0 css/.svn/entries
  27. +745 −0 css/.svn/text-base/main.css.svn-base
  28. +27 −0 css/.svn/text-base/prettify.css.svn-base
  29. +43 −0 css/.svn/text-base/tagscomplete.css.svn-base
  30. +139 −0 css/.svn/text-base/wmd.css.svn-base
  31. +745 −0 css/main.css
  32. +27 −0 css/prettify.css
  33. +43 −0 css/tagscomplete.css
  34. +139 −0 css/wmd.css
  35. +23 −0 db/.svn/all-wcprops
  36. +130 −0 db/.svn/entries
  37. +195 −0 db/.svn/text-base/1.txt.svn-base
  38. +8 −0 db/.svn/text-base/2.txt.svn-base
  39. +21 −0 db/.svn/text-base/3.txt.svn-base
  40. +195 −0 db/1.txt
  41. +8 −0 db/2.txt
  42. +21 −0 db/3.txt
  43. +29 −0 img/.svn/all-wcprops
  44. +164 −0 img/.svn/entries
  45. +5 −0 img/.svn/prop-base/close.gif.svn-base
  46. +5 −0 img/.svn/prop-base/loading.gif.svn-base
  47. +5 −0 img/.svn/prop-base/logo.gif.svn-base
  48. +5 −0 img/.svn/prop-base/wmd-buttons.png.svn-base
  49. BIN  img/.svn/text-base/close.gif.svn-base
  50. BIN  img/.svn/text-base/loading.gif.svn-base
  51. BIN  img/.svn/text-base/logo.gif.svn-base
  52. BIN  img/.svn/text-base/wmd-buttons.png.svn-base
  53. BIN  img/close.gif
  54. BIN  img/loading.gif
  55. BIN  img/logo.gif
  56. BIN  img/wmd-buttons.png
  57. +35 −0 js/.svn/all-wcprops
  58. +201 −0 js/.svn/entries
  59. +52 −0 js/.svn/text-base/fancyalert.js.svn-base
  60. +19 −0 js/.svn/text-base/jquery.js.svn-base
  61. +1,306 −0 js/.svn/text-base/showdown.js.svn-base
  62. +661 −0 js/.svn/text-base/tagscomplete.js.svn-base
  63. +2,378 −0 js/.svn/text-base/wmd.js.svn-base
  64. +52 −0 js/fancyalert.js
  65. +19 −0 js/jquery.js
  66. +65 −0 js/prettify/.svn/all-wcprops
  67. +368 −0 js/prettify/.svn/entries
  68. +2 −0  js/prettify/.svn/text-base/lang-css.js.svn-base
  69. +2 −0  js/prettify/.svn/text-base/lang-hs.js.svn-base
  70. +3 −0  js/prettify/.svn/text-base/lang-lisp.js.svn-base
  71. +2 −0  js/prettify/.svn/text-base/lang-lua.js.svn-base
  72. +2 −0  js/prettify/.svn/text-base/lang-ml.js.svn-base
  73. +1 −0  js/prettify/.svn/text-base/lang-proto.js.svn-base
  74. +2 −0  js/prettify/.svn/text-base/lang-sql.js.svn-base
  75. +2 −0  js/prettify/.svn/text-base/lang-vb.js.svn-base
  76. +2 −0  js/prettify/.svn/text-base/lang-wiki.js.svn-base
  77. +33 −0 js/prettify/.svn/text-base/prettify.js.svn-base
  78. +2 −0  js/prettify/lang-css.js
  79. +2 −0  js/prettify/lang-hs.js
  80. +3 −0  js/prettify/lang-lisp.js
  81. +2 −0  js/prettify/lang-lua.js
  82. +2 −0  js/prettify/lang-ml.js
  83. +1 −0  js/prettify/lang-proto.js
  84. +2 −0  js/prettify/lang-sql.js
  85. +2 −0  js/prettify/lang-vb.js
  86. +2 −0  js/prettify/lang-wiki.js
  87. +33 −0 js/prettify/prettify.js
  88. +1,306 −0 js/showdown.js
  89. +661 −0 js/tagscomplete.js
  90. +2,378 −0 js/wmd.js
  91. +47 −0 libraries/.svn/all-wcprops
  92. +269 −0 libraries/.svn/entries
  93. +50 −0 libraries/.svn/text-base/helper.class.php.svn-base
  94. +1,710 −0 libraries/.svn/text-base/markdown.php.svn-base
  95. +97 −0 libraries/.svn/text-base/pagination.class.php.svn-base
  96. +104 −0 libraries/.svn/text-base/score.php.svn-base
  97. +209 −0 libraries/.svn/text-base/shared.php.svn-base
  98. +56 −0 libraries/.svn/text-base/template.class.php.svn-base
  99. +261 −0 libraries/.svn/text-base/timeago.php.svn-base
  100. +50 −0 libraries/helper.class.php
  101. +1,710 −0 libraries/markdown.php
  102. +97 −0 libraries/pagination.class.php
  103. +53 −0 libraries/purifier/.svn/all-wcprops
  104. +303 −0 libraries/purifier/.svn/entries
  105. +11 −0 libraries/purifier/.svn/text-base/HTMLPurifier.auto.php.svn-base
  106. +21 −0 libraries/purifier/.svn/text-base/HTMLPurifier.autoload.php.svn-base
  107. +23 −0 libraries/purifier/.svn/text-base/HTMLPurifier.func.php.svn-base
  108. +208 −0 libraries/purifier/.svn/text-base/HTMLPurifier.includes.php.svn-base
  109. +30 −0 libraries/purifier/.svn/text-base/HTMLPurifier.kses.php.svn-base
  110. +11 −0 libraries/purifier/.svn/text-base/HTMLPurifier.path.php.svn-base
  111. +237 −0 libraries/purifier/.svn/text-base/HTMLPurifier.php.svn-base
  112. +202 −0 libraries/purifier/.svn/text-base/HTMLPurifier.safe-includes.php.svn-base
  113. +11 −0 libraries/purifier/HTMLPurifier.auto.php
  114. +21 −0 libraries/purifier/HTMLPurifier.autoload.php
  115. +23 −0 libraries/purifier/HTMLPurifier.func.php
  116. +208 −0 libraries/purifier/HTMLPurifier.includes.php
  117. +30 −0 libraries/purifier/HTMLPurifier.kses.php
  118. +11 −0 libraries/purifier/HTMLPurifier.path.php
  119. +237 −0 libraries/purifier/HTMLPurifier.php
  120. +202 −0 libraries/purifier/HTMLPurifier.safe-includes.php
  121. +329 −0 libraries/purifier/HTMLPurifier/.svn/all-wcprops
  122. +1,918 −0 libraries/purifier/HTMLPurifier/.svn/entries
  123. +128 −0 libraries/purifier/HTMLPurifier/.svn/text-base/AttrCollections.php.svn-base
  124. +87 −0 libraries/purifier/HTMLPurifier/.svn/text-base/AttrDef.php.svn-base
  125. +56 −0 libraries/purifier/HTMLPurifier/.svn/text-base/AttrTransform.php.svn-base
  126. +77 −0 libraries/purifier/HTMLPurifier/.svn/text-base/AttrTypes.php.svn-base
  127. +162 −0 libraries/purifier/HTMLPurifier/.svn/text-base/AttrValidator.php.svn-base
  128. +98 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Bootstrap.php.svn-base
  129. +292 −0 libraries/purifier/HTMLPurifier/.svn/text-base/CSSDefinition.php.svn-base
  130. +48 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ChildDef.php.svn-base
  131. +580 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Config.php.svn-base
  132. +158 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ConfigSchema.php.svn-base
  133. +155 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ContentSets.php.svn-base
  134. +82 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Context.php.svn-base
  135. +39 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Definition.php.svn-base
  136. +108 −0 libraries/purifier/HTMLPurifier/.svn/text-base/DefinitionCache.php.svn-base
  137. +91 −0 libraries/purifier/HTMLPurifier/.svn/text-base/DefinitionCacheFactory.php.svn-base
  138. +60 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Doctype.php.svn-base
  139. +103 −0 libraries/purifier/HTMLPurifier/.svn/text-base/DoctypeRegistry.php.svn-base
  140. +176 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ElementDef.php.svn-base
  141. +426 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Encoder.php.svn-base
  142. +44 −0 libraries/purifier/HTMLPurifier/.svn/text-base/EntityLookup.php.svn-base
  143. +144 −0 libraries/purifier/HTMLPurifier/.svn/text-base/EntityParser.php.svn-base
  144. +209 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ErrorCollector.php.svn-base
  145. +60 −0 libraries/purifier/HTMLPurifier/.svn/text-base/ErrorStruct.php.svn-base
  146. +12 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Exception.php.svn-base
  147. +46 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Filter.php.svn-base
  148. +183 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Generator.php.svn-base
  149. +420 −0 libraries/purifier/HTMLPurifier/.svn/text-base/HTMLDefinition.php.svn-base
  150. +244 −0 libraries/purifier/HTMLPurifier/.svn/text-base/HTMLModule.php.svn-base
  151. +403 −0 libraries/purifier/HTMLPurifier/.svn/text-base/HTMLModuleManager.php.svn-base
  152. +53 −0 libraries/purifier/HTMLPurifier/.svn/text-base/IDAccumulator.php.svn-base
  153. +239 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Injector.php.svn-base
  154. +163 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Language.php.svn-base
  155. +198 −0 libraries/purifier/HTMLPurifier/.svn/text-base/LanguageFactory.php.svn-base
  156. +115 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Length.php.svn-base
  157. +298 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Lexer.php.svn-base
  158. +98 −0 libraries/purifier/HTMLPurifier/.svn/text-base/PercentEncoder.php.svn-base
  159. +176 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Printer.php.svn-base
  160. +86 −0 libraries/purifier/HTMLPurifier/.svn/text-base/PropertyList.php.svn-base
  161. +32 −0 libraries/purifier/HTMLPurifier/.svn/text-base/PropertyListIterator.php.svn-base
  162. +26 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Strategy.php.svn-base
  163. +39 −0 libraries/purifier/HTMLPurifier/.svn/text-base/StringHash.php.svn-base
  164. +110 −0 libraries/purifier/HTMLPurifier/.svn/text-base/StringHashParser.php.svn-base
  165. +36 −0 libraries/purifier/HTMLPurifier/.svn/text-base/TagTransform.php.svn-base
  166. +57 −0 libraries/purifier/HTMLPurifier/.svn/text-base/Token.php.svn-base
  167. +94 −0 libraries/purifier/HTMLPurifier/.svn/text-base/TokenFactory.php.svn-base
  168. +173 −0 libraries/purifier/HTMLPurifier/.svn/text-base/URI.php.svn-base
  169. +93 −0 libraries/purifier/HTMLPurifier/.svn/text-base/URIDefinition.php.svn-base
  170. +45 −0 libraries/purifier/HTMLPurifier/.svn/text-base/URIFilter.php.svn-base
Sorry, we could not display the entire diff because too many files (869) changed.
6 .htaccess
View
@@ -0,0 +1,6 @@
+<IfModule mod_rewrite.c>
+ RewriteEngine On
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteRule ^(.*)$ index.php/$1 [QSA,L]
+</IfModule>
47 .svn/all-wcprops
View
@@ -0,0 +1,47 @@
+K 25
+svn:wc:ra_dav:version-url
+V 29
+/svn/qwench/!svn/ver/30/trunk
+END
+LICENSE.TXT
+K 25
+svn:wc:ra_dav:version-url
+V 41
+/svn/qwench/!svn/ver/27/trunk/LICENSE.TXT
+END
+VERSION.TXT
+K 25
+svn:wc:ra_dav:version-url
+V 41
+/svn/qwench/!svn/ver/27/trunk/VERSION.TXT
+END
+.htaccess
+K 25
+svn:wc:ra_dav:version-url
+V 39
+/svn/qwench/!svn/ver/27/trunk/.htaccess
+END
+README.TXT
+K 25
+svn:wc:ra_dav:version-url
+V 40
+/svn/qwench/!svn/ver/28/trunk/README.TXT
+END
+install.php
+K 25
+svn:wc:ra_dav:version-url
+V 41
+/svn/qwench/!svn/ver/29/trunk/install.php
+END
+index.php
+K 25
+svn:wc:ra_dav:version-url
+V 39
+/svn/qwench/!svn/ver/26/trunk/index.php
+END
+config.default.php
+K 25
+svn:wc:ra_dav:version-url
+V 48
+/svn/qwench/!svn/ver/29/trunk/config.default.php
+END
287 .svn/entries
View
@@ -0,0 +1,287 @@
+10
+
+dir
+30
+http://k.i/svn/qwench/trunk
+http://k.i/svn/qwench
+
+
+
+2009-12-09T09:24:55.428545Z
+30
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2c2bcabb-f85b-4f93-8145-bce7f95e6b2a
+
+LICENSE.TXT
+file
+
+
+
+
+2009-12-16T10:39:00.474200Z
+ce145d3370c795e757fd96cbd6808036
+2009-12-09T08:22:25.001934Z
+27
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+4107
+
+VERSION.TXT
+file
+
+
+
+
+2009-12-16T10:39:00.477200Z
+e4c2e8edac362acab7123654b9e73432
+2009-12-09T08:22:25.001934Z
+27
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3
+
+db
+dir
+
+controllers
+dir
+
+css
+dir
+
+.htaccess
+file
+
+
+
+
+2009-12-16T10:39:00.480200Z
+44ee2a895e6a9269e2a548875bbafa37
+2009-12-09T08:22:25.001934Z
+27
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+186
+
+README.TXT
+file
+
+
+
+
+2009-12-16T10:39:00.483200Z
+7517fe638de70cbe769f2b109bec1430
+2009-12-09T08:23:34.071587Z
+28
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+316
+
+img
+dir
+
+js
+dir
+
+libraries
+dir
+
+install.php
+file
+
+
+
+
+2009-12-16T10:39:00.486200Z
+64b8165a401a05bf1b536d2f4735fc40
+2009-12-09T09:19:09.872791Z
+29
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+6536
+
+views
+dir
+
+index.php
+file
+
+
+
+
+2009-12-16T10:39:00.497200Z
+5ae389bc9ed3650f5cc3f0f8fa2ed0a6
+2009-09-22T06:04:16.186489Z
+26
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1507
+
+config.default.php
+file
+
+
+
+
+2009-12-16T10:39:00.502200Z
+ce3ce43efb5fca2ba5c4bba28e4cf768
+2009-12-09T09:19:09.872791Z
+29
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+918
+
6 .svn/text-base/.htaccess.svn-base
View
@@ -0,0 +1,6 @@
+<IfModule mod_rewrite.c>
+ RewriteEngine On
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteRule ^(.*)$ index.php/$1 [QSA,L]
+</IfModule>
76 .svn/text-base/LICENSE.TXT.svn-base
View
@@ -0,0 +1,76 @@
+Qwench
+Copyright (c) 2009-2010 Inscripts
+
+Qwench ('the Software') is a copyrighted work of authorship. Inscripts
+retains ownership of the Software and any copies of it, regardless of the
+form in which the copies may exist.
+
+By installing and using Qwench on your server, you agree to the following
+terms and conditions.
+
+A Modification, or a Mod, is defined as instructions, to be performed
+manually or in an automated manner, that alter any part of this Package.
+A Modified Package is defined as this Package or a derivative of it with
+one or more Modification applied to it. Distribution is defined as allowing
+one or more other people to in any way download or receive a copy of this
+Package, a Modified Package, or a derivative of this Package.
+
+Such agreement is either on your own behalf or on behalf
+of any corporate entity which employs you or which you represent
+('Corporate Licensee'). In this Agreement, 'you' includes both the reader
+and any Corporate Licensee and 'Inscripts' means Inscripts (I) Private Limited:
+
+1. Permission is hereby granted to use, copy, modify and/or distribute this
+Package, provided that:
+
+a. All copyright notices within source files and as generated by the Software
+as output are retained, unchanged.
+b. Any Distribution of this Package, whether as a Modified Package or not,
+includes this license and is released under the terms of this Agreement. This
+clause is not dependant upon any measure of changes made to this Package.
+c. This Package, Modified Packages, and derivative works may not be sold or
+released under any paid license. Copying fees for the transport of this Package,
+support fees for installation or other services, and hosting fees for hosting
+the Software may, however, be imposed.
+d. Any Distribution of this Package, whether as a Modified Package or not,
+requires express written consent from Inscripts.
+
+2.You may make Modifications to this Package or a derivative of it, and
+distribute your Modifications in a form that is separate from the Package,
+such as patches. The following restrictions apply to Modifications:
+
+a. A Modification must not alter or remove any copyright notices in the
+Software or Package, generated or otherwise.
+b. When a Modification to the Package is released, a non-exclusive
+royalty-free right is granted to Inscripts to distribute the Modification in
+future versions of the Package provided such versions remain available under
+the terms of this Agreement in addition to any other license(s) of the initial
+developer.
+c. Any Distribution of a Modified Package or derivative requires express
+written consent from Inscripts.
+
+3.Permission is hereby also granted to distribute programs which depend on
+this Package, provided that you do not distribute any Modified Package
+without express written consent.
+
+All Software copyright notices within the scripts must remain unchanged (and visible).
+
+The Software may not be used for anything that would represent or is associated
+with an Intellectual Property violation, including, but not limited to,
+engaging in any activity that infringes or misappropriates the intellectual property
+rights of others, including copyrights, trademarks, service marks, trade secrets,
+software piracy, and patents held by individuals, corporations, or other entities.
+
+If any of the terms of this Agreement are violated, Inscripts reserves the right
+to revoke the Software license at any time.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
12 .svn/text-base/README.TXT.svn-base
View
@@ -0,0 +1,12 @@
+Qwench
+Copyright (c) 2009-2010 Inscripts
+
+Installation Instructions
+-----------------------------------------------
+
+1. Modify config.php as per your site
+2. Run install.php (using your browser)
+3. Done! (Delete install.php)
+4. Register on your new site :)
+
+-----------------------------------------------
1  .svn/text-base/VERSION.TXT.svn-base
View
@@ -0,0 +1 @@
+1.0
32 .svn/text-base/config.default.php.svn-base
View
@@ -0,0 +1,32 @@
+<?php
+
+// Database Details
+define('SERVERNAME','localhost');
+define('SERVERPORT','3306');
+define('DBUSERNAME','root');
+define('DBPASSWORD','yourpassword');
+define('DBNAME','qwench');
+
+Define('ANSWERS_PER_PAGE','10');
+define('QUESTIONS_PER_PAGE','10');
+
+// If you want only logged in users to view the site
+define('ALLOW_VISITORS','1');
+
+// Do not change salt after users have registered
+define('SALT','yoursecurestringoverhere');
+
+// Set default timezone if you want or comment the line below
+date_default_timezone_set("Asia/Calcutta");
+
+// No trailing slash
+// Path to the Qwench folder
+// If you have installed Qwench in your
+// root folder then set
+// define('BASE_DIR','');
+define('BASE_DIR','/qwench');
+
+// If URL-Rewriting does not work then set
+// define('BASE_PATH',BASE_DIR.'/index.php');
+// If URL-Rewriting works, then leave the line below as is
+define('BASE_PATH',BASE_DIR);
56 .svn/text-base/index.php.svn-base
View
@@ -0,0 +1,56 @@
+<?php
+
+/* Start Session */
+
+session_name("qwench");
+session_start();
+
+/* Define */
+
+define('ROOT',DIRNAME(__FILE__));
+define('DS',DIRECTORY_SEPARATOR);
+
+/* Get Basic Details */
+
+$path = explode("/", substr($_SERVER['PATH_INFO'],1));
+
+$controller = 'questions';
+$action = 'index';
+if (empty($_GET['type'])) { $_GET['type'] = "active"; }
+$norender = false;
+$noheader = false;
+
+if (!empty($path[0])) { $controller = $path[0]; if ($_GET['type'] == "active") { $_GET['type'] = ""; } }
+if (!empty($path[1])) { $action = $path[1]; if ($_GET['type'] == "active") { $_GET['type'] = ""; } }
+
+/* Include Libraries */
+
+include_once ROOT.DS.'config.php';
+include_once ROOT.DS.'libraries'.DS.'template.class.php';
+include_once ROOT.DS.'libraries'.DS.'helper.class.php';
+
+$template = new Template($controller,$action);
+$helper = new Helper();
+
+include_once ROOT.DS.'libraries'.DS.'shared.php';
+include_once ROOT.DS.'libraries'.DS.'markdown.php';
+include_once ROOT.DS.'libraries'.DS.'timeago.php';
+include_once ROOT.DS.'libraries'.DS.'score.php';
+include_once ROOT.DS.'libraries'.DS.'pagination.class.php';
+include_once ROOT.DS.'controllers'.DS.'helpers.php';
+/* Debug Mode */
+
+error_reporting(E_ALL);
+ini_set('display_errors','On');
+
+/* Basic Bootstrapping */
+
+include ROOT.DS.'controllers'.DS.$controller.'.php';
+if (function_exists($action)) {
+ call_user_func($action);
+} else {
+ call_user_func('index');
+}
+if ($norender == false) {
+ $template->render($noheader);
+}
202 .svn/text-base/install.php.svn-base
View
@@ -0,0 +1,202 @@
+<?php
+
+include (dirname(__FILE__))."/config.php";
+include (dirname(__FILE__))."/libraries/shared.php";
+
+db();
+
+$body = '';
+$path = '';
+
+$rollback = 0;
+$errors = '';
+
+ $content = <<<EOD
+
+DROP TABLE IF EXISTS `activities`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `activities` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `userid` int(10) unsigned NOT NULL,
+ `activity` varchar(255) NOT NULL default '',
+ `points` int(11) NOT NULL,
+ `created` datetime NOT NULL,
+ `activityid` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `answers`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `answers` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `questionid` int(10) unsigned NOT NULL,
+ `description` text character set latin1 NOT NULL,
+ `created` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `updated` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `userid` int(10) unsigned NOT NULL,
+ `accepted` int(10) unsigned NOT NULL,
+ `votes` int(11) NOT NULL default '0',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `answers_votes`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `answers_votes` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `answerid` int(10) unsigned NOT NULL,
+ `userid` int(10) unsigned NOT NULL,
+ `vote` int(11) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `comments`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `comments` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `type` int(10) unsigned NOT NULL,
+ `comment` text character set latin1 NOT NULL,
+ `votes` int(10) unsigned NOT NULL default '0',
+ `created` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `userid` int(10) unsigned NOT NULL,
+ `typeid` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `comments_votes`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `comments_votes` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `commentid` int(10) unsigned NOT NULL,
+ `userid` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `favorites`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `favorites` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `questionid` int(10) unsigned NOT NULL,
+ `userid` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+
+DROP TABLE IF EXISTS `questions`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `questions` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `title` text character set latin1 NOT NULL,
+ `description` text character set latin1 NOT NULL,
+ `created` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `updated` timestamp NOT NULL default '0000-00-00 00:00:00',
+ `link` text character set latin1 NOT NULL,
+ `userid` int(10) unsigned NOT NULL,
+ `linkcache` longtext character set latin1 NOT NULL,
+ `votes` int(11) NOT NULL default '0',
+ `accepted` int(10) unsigned NOT NULL default '0',
+ `answers` int(10) unsigned NOT NULL default '0',
+ `kb` int(10) unsigned NOT NULL default '0',
+ `slug` text NOT NULL,
+ PRIMARY KEY (`id`),
+ FULLTEXT KEY `title` (`title`,`description`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
+
+
+DROP TABLE IF EXISTS `questions_votes`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `questions_votes` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `questionid` int(10) unsigned NOT NULL,
+ `userid` int(10) unsigned NOT NULL,
+ `vote` int(11) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+
+DROP TABLE IF EXISTS `tags`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `tags` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `tag` varchar(255) character set latin1 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `tags_questions`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `tags_questions` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `tagid` int(10) unsigned NOT NULL,
+ `questionid` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+DROP TABLE IF EXISTS `users`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `users` (
+ `id` int(10) unsigned NOT NULL auto_increment,
+ `password` varchar(255) character set latin1 NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `email` varchar(255) NOT NULL,
+ `points` int(11) NOT NULL default '0',
+ `moderator` int(10) unsigned NOT NULL,
+ `created` datetime NOT NULL,
+ `lastactivity` datetime NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
+SET character_set_client = @saved_cs_client;
+
+EOD;
+
+ $q = preg_split('/;[\r\n]+/',$content);
+
+ foreach ($q as $query) {
+ if (strlen($query) > 4) {
+ $result = mysql_query($query);
+ if (!$result) {
+ $rollback = 1;
+ $errors .= mysql_error()."<br/>\n";
+ }
+ }
+ }
+
+?>
+<html>
+<head>
+<title>Install</title>
+<style>
+body {
+padding:0;
+margin:0;
+font-family: "Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif;
+font-size: 14px;
+color: #333333;
+
+}
+</style>
+</head>
+<body>
+<div class="setup">Database import completed.
+</div>
+</body>
+</html>
41 controllers/.svn/all-wcprops
View
@@ -0,0 +1,41 @@
+K 25
+svn:wc:ra_dav:version-url
+V 41
+/svn/qwench/!svn/ver/27/trunk/controllers
+END
+questions.php
+K 25
+svn:wc:ra_dav:version-url
+V 55
+/svn/qwench/!svn/ver/25/trunk/controllers/questions.php
+END
+tags.php
+K 25
+svn:wc:ra_dav:version-url
+V 49
+/svn/qwench/!svn/ver/8/trunk/controllers/tags.php
+END
+users.php
+K 25
+svn:wc:ra_dav:version-url
+V 51
+/svn/qwench/!svn/ver/27/trunk/controllers/users.php
+END
+answers.php
+K 25
+svn:wc:ra_dav:version-url
+V 53
+/svn/qwench/!svn/ver/22/trunk/controllers/answers.php
+END
+helpers.php
+K 25
+svn:wc:ra_dav:version-url
+V 53
+/svn/qwench/!svn/ver/16/trunk/controllers/helpers.php
+END
+comments.php
+K 25
+svn:wc:ra_dav:version-url
+V 54
+/svn/qwench/!svn/ver/23/trunk/controllers/comments.php
+END
232 controllers/.svn/entries
View
@@ -0,0 +1,232 @@
+10
+
+dir
+30
+http://k.i/svn/qwench/trunk/controllers
+http://k.i/svn/qwench
+
+
+
+2009-12-09T08:22:25.001934Z
+27
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2c2bcabb-f85b-4f93-8145-bce7f95e6b2a
+
+questions.php
+file
+
+
+
+
+2009-12-16T10:38:50.824200Z
+94a672971dcb53c3ec65d32518f16ddb
+2009-09-17T09:15:21.029206Z
+25
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+27140
+
+tags.php
+file
+
+
+
+
+2009-12-16T10:38:50.863200Z
+afa4b561e234ceb445c1a66d0254120a
+2009-09-09T16:52:39.757853Z
+8
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+632
+
+users.php
+file
+
+
+
+
+2009-12-16T10:38:50.885200Z
+8c9e654118649499874b48205c84b395
+2009-12-09T08:22:25.001934Z
+27
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+3362
+
+answers.php
+file
+
+
+
+
+2009-12-16T10:38:50.893200Z
+7956eec16501b68321b7e364de53f9b9
+2009-09-12T14:26:28.944142Z
+22
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+6575
+
+helpers.php
+file
+
+
+
+
+2009-12-16T10:38:50.905200Z
+8bfcce8d7ee1b97303ccf0571fb63b64
+2009-09-11T14:03:52.509349Z
+16
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+284
+
+comments.php
+file
+
+
+
+
+2009-12-16T10:38:50.908200Z
+af25700bab70f81edf8495769c23eb0d
+2009-09-12T15:19:45.588259Z
+23
+anantgarg
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+2603
+
202 controllers/.svn/text-base/answers.php.svn-base
View
@@ -0,0 +1,202 @@
+<?php
+
+function edit() {
+ authenticate(1);
+
+ global $path;
+ global $template;
+ $answerid = sanitize($path[2],"int");
+
+ $basePath = basePath();
+ $basePathNS = basePathNS();
+
+ $js = <<<EOD
+
+<script src="$basePathNS/js/showdown.js"></script>
+<script src="$basePathNS/js/wmd.js"></script>
+<link href="$basePathNS/css/wmd.css" type="text/css" rel="stylesheet" />
+
+EOD;
+
+ $template->set('js',$js);
+
+ $sql = ("select * from answers where id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('description',$result['description']);
+ $template->set('answerid',$result['id']);
+}
+
+function post() {
+ authenticate(1);
+ $basePath = basePath();
+
+ $description = sanitize($_POST['description'],"markdown");
+ $questionid = sanitize($_POST['questionid'],"int");
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if (strlen($description) < 15 || $result['id'] == '' || $result['id'] == 0) {
+ header("Location: $basePath/questions/view/$questionid/{$result['slug']}");
+ exit;
+ }
+
+ $sql = ("insert into answers (questionid,description,created,updated,userid,accepted,votes) values ('".escape($questionid)."','".escape($description)."',NOW(),NOW(),'".escape($_SESSION['userid'])."','0','0')");
+ $query = mysql_query($sql);
+
+ $sql = ("update questions set updated = NOW(), answers=answers+1 where id = '".escape($result['id'])."'");
+ $query = mysql_query($sql);
+
+ header("Location: $basePath/questions/view/$questionid/{$result['slug']}");
+}
+
+function update() {
+ authenticate(1);
+
+ $answerid = sanitize($_POST['id'],"int");
+ $description = sanitize($_POST['description'],"markdown");
+
+ $sql = ("select * from answers where id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $sql = ("select * from questions where id = '".escape($result['questionid'])."'");
+ $query = mysql_query($sql);
+ $qresult = mysql_fetch_array($query);
+
+ if ($qresult['userid'] != $_SESSION['userid']) {
+ $basePath = basePath();
+ header("Location: $basePath/questions/view/{$qresult['id']}/{$qresult['slug']}");
+ }
+
+ $sql = ("update answers set description = '".escape($description)."', updated = NOW() where userid = '".escape($_SESSION['userid'])."' and id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+
+ $sql = ("update questions set updated = NOW() where id = '".escape($result['questionid'])."'");
+ $query = mysql_query($sql);
+
+ $basePath = basePath();
+
+ header("Location: $basePath/questions/view/{$qresult['id']}/{$qresult['slug']}");
+}
+
+function vote() {
+ if ($_SESSION['userid'] == '') {
+ echo "0Please login to vote";
+ exit;
+ }
+
+ $id = sanitize($_POST['id'],"int");
+ $vote = sanitize($_POST['vote'],"string");
+
+ if ($vote == 'plus') {
+ $vote = '+1';
+ } else {
+ $vote = '-1';
+ }
+
+ $sql = ("select answers.userid,answers_votes.id qvid,answers_votes.vote qvvote from answers left join answers_votes on (answers.id = answers_votes.answerid and answers_votes.userid = '".escape($_SESSION['userid'])."') where answers.id = '".escape($id)."'");
+ $query = mysql_query($sql);
+
+ $answer = mysql_fetch_array($query);
+
+ if ($answer['userid'] == $_SESSION['userid']) {
+ echo "0"."You cannot up/down vote your own answer";
+ exit;
+ }
+
+ if ($answer['qvid'] > 0) {
+
+ if ($answer['qvvote'] == 1 && $vote == '+1') {
+ $vote = "-1";
+ score('a_upvoted_removed',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == 1 && $vote == '-1') {
+ $vote = "-2";
+ score('a_upvoted_removed',$id,$answer['userid']);
+ score('a_downvoter',$id);
+ score('a_downvoted',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == -1 && $vote == '-1') {
+ $vote = "+1";
+ score('a_downvoter_removed',$id);
+ score('a_downvoted_removed',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == -1 && $vote == '+1') {
+ $vote = "+2";
+ score('a_downvoter_removed',$id);
+ score('a_downvoted_removed',$id,$answer['userid']);
+ score('a_upvoted',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == 0) {
+ if ($vote == 1) {
+ score('a_upvoted',$id,$answer['userid']);
+ } else {
+ score('a_downvoter',$id);
+ score('a_downvoted',$id,$answer['userid']);
+ }
+ }
+
+ $sql = ("update answers_votes set vote = vote".escape($vote)." where id = '".$answer['qvid']."'");
+ $query = mysql_query($sql);
+
+ } else {
+ $sql = ("insert into answers_votes (answerid,userid,vote) values ('".escape($id)."','".escape($_SESSION['userid'])."','".escape($vote)."')");
+ $query = mysql_query($sql);
+
+ if ($vote == 1) {
+ score('a_upvoted',$id,$answer['userid']);
+ } else {
+ score('a_downvoter',$id);
+ score('a_downvoted',$id,$answer['userid']);
+ }
+
+ }
+
+ $sql_nest = ("update answers set votes = votes".escape($vote)." where id = '".escape($id)."'");
+ $query_nest = mysql_query($sql_nest);
+
+ echo "1Thankyou for voting";
+ exit;
+
+}
+
+function accept() {
+ authenticate(1);
+
+ $answerid = sanitize($_GET['id'],"int");
+
+ $sql = ("select questionid,userid from answers where id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $answer = mysql_fetch_array($query);
+
+ $sql = ("select questions.*,answers.id answerid, answers.userid answeruserid from questions left join answers on (questions.id = answers.questionid and answers.accepted = 1) where questions.id = '".escape($answer['questionid'])."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if ($result['kb'] == 1) {
+ header("Location: $basePath/questions/view/{$result['id']}/{$result['slug']}");
+ exit;
+ }
+
+ if ($result['answerid'] > 0) {
+ score('a_accepted_removed',$answerid,$result['answeruserid']);
+ } else {
+ score('a_accepter',$answerid);
+ }
+
+ if ($result['userid'] == $_SESSION['userid']) {
+ $sql = ("update answers set accepted = '0' where questionid = '".escape($result['id'])."'");
+ $query = mysql_query($sql);
+ $sql = ("update answers set accepted = '1' where questionid = '".escape($result['id'])."' and id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $sql = ("update questions set accepted = '1' where id = '".escape($result['id'])."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+
+ score('a_accepted',$answerid,$answer['userid']);
+
+ }
+
+ $basePath = basePath();
+
+ header("Location: $basePath/questions/view/{$result['id']}/{$result['slug']}");
+}
98 controllers/.svn/text-base/comments.php.svn-base
View
@@ -0,0 +1,98 @@
+<?php
+
+function post() {
+ if ($_SESSION['userid'] == '') {
+ echo "0";
+ exit;
+ }
+
+ global $template;
+ global $noheader;
+ $noheader = true;
+
+ $id = sanitize($_POST['id'],"string");
+ $type = substr($id,0,1);
+ $typeid = substr($id,1);
+ if ($type == 'q') {
+ $type = 0;
+ } else {
+ $type = 1;
+ }
+
+ $comment = sanitize($_POST['comment'],"comment");
+
+ if (strlen($comment) < 10 || strlen($comment) > 600) {
+ echo "0An error has occurred. Please try again later";
+ exit;
+ }
+
+ $sql = ("insert into comments (type,comment,votes,created,userid,typeid) values ('".escape($type)."','".escape($comment)."','0',NOW(),'".escape($_SESSION['userid'])."','".escape($typeid)."')");
+ $query = mysql_query($sql);
+
+ $template->set('comment',$comment);
+
+ $firstname = $_SESSION['name'];
+ $pos = strpos($_SESSION['name'],' ');
+ if ($pos > 0) {
+ $firstname = substr($_SESSION['name'],0,$pos);
+ }
+
+ $template->set('username',$firstname);
+ $template->set('userid',$_SESSION['userid']);
+
+}
+
+function vote() {
+ if ($_SESSION['userid'] == '') {
+ echo "0Please login to vote";
+ exit;
+ }
+
+ $id = sanitize($_POST['id'],"int");
+
+ $sql = ("select userid from comments where id = '".escape($id)."'");
+ $query = mysql_query($sql);
+ $comment = mysql_fetch_array($query);
+
+ if ($comment['userid'] == $_SESSION['userid']) {
+ echo "0You cannot upvote your own comment";
+ exit;
+ }
+
+ $sql = ("select * from comments_votes where commentid = '".escape($id)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+
+ if ($result['id'] > 0) {
+
+ $sql = ("delete from comments_votes where commentid = '".escape($id)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $sql_nest = ("update comments set votes = votes-1 where id = '".escape($id)."'");
+ $query_nest = mysql_query($sql_nest);
+ score('c_upvoted_removed',$id,$comment['userid']);
+
+ } else {
+ $sql = ("insert into comments_votes (commentid,userid) values ('".escape($id)."','".escape($_SESSION['userid'])."')");
+ $query = mysql_query($sql);
+ $sql_nest = ("update comments set votes = votes+1 where id = '".escape($id)."'");
+ $query_nest = mysql_query($sql_nest);
+ score('c_upvoted',$id,$comment['userid']);
+ }
+
+ echo "1";
+ exit;
+
+}
+
+function del() {
+
+ $id = sanitize($_POST['id'],"int");
+
+ $sql = ("delete from comments where id = '".escape($id)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+
+ echo "1Comment successfully deleted";
+ exit;
+
+}
15 controllers/.svn/text-base/helpers.php.svn-base
View
@@ -0,0 +1,15 @@
+<?php
+
+function getUser($id) {
+ global $helper;
+
+ $id = sanitize($id,"int");
+ $sql = ("select * from users where id = '".escape($id)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $helper->set('user',$result);
+ return $helper->render();
+}
+
+
954 controllers/.svn/text-base/questions.php.svn-base
View
@@ -0,0 +1,954 @@
+<?php
+
+function ask() {
+ authenticate(1);
+
+ global $template;
+
+ $basePath = basePath();
+ $basePathNS = basePathNS();
+
+ $js = <<<EOD
+
+<script src="$basePathNS/js/showdown.js"></script>
+<script src="$basePathNS/js/wmd.js"></script>
+<link href="$basePathNS/css/wmd.css" type="text/css" rel="stylesheet" />
+
+<script>
+
+
+$(document).ready(function() {
+ $("#tags").fcbkcomplete({
+ json_url: "$basePath/questions/fetchtags",
+ json_cache: true,
+ filter_case: true,
+ filter_hide: true,
+ newel: true
+ });
+
+
+
+});
+</script>
+
+EOD;
+
+ $template->set('js',$js);
+
+
+}
+
+function edit() {
+ authenticate(1);
+
+ global $path;
+ global $template;
+
+ $basePath = basePath();
+ $basePathNS = basePathNS();
+
+ $questionid = sanitize($path[2],"int");
+
+ $js = <<<EOD
+
+<script src="$basePathNS/js/showdown.js"></script>
+<script src="$basePathNS/js/wmd.js"></script>
+<link href="$basePathNS/css/wmd.css" type="text/css" rel="stylesheet" />
+
+<script>
+
+
+$(document).ready(function() {
+ $("#tags").fcbkcomplete({
+ json_url: "$basePath/questions/fetchtags",
+ json_cache: true,
+ filter_case: true,
+ filter_hide: true,
+ newel: true
+ });
+
+
+
+});
+</script>
+
+EOD;
+
+ $template->set('js',$js);
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('title',$result['title']);
+ $template->set('description',$result['description']);
+ $template->set('link',$result['link']);
+ $template->set('kb',$result['kb']);
+
+ $sql = ("select tag from tags_questions, tags where questionid = '".escape($questionid)."' and tags.id = tags_questions.tagid order by tag");
+ $query = mysql_query($sql);
+
+ $tags = array();
+
+ while ($result = mysql_fetch_array($query)) {
+ $tags[] = $result['tag'];
+ }
+
+ $template->set('tags',$tags);
+ $template->set('questionid',$questionid);
+
+
+}
+
+function post() {
+ authenticate(1);
+ $basePath = basePath();
+
+ $title = sanitize($_POST['title'],"string");
+ $description = sanitize($_POST['description'],"markdown");
+ $link = sanitize($_POST['link'],"url");
+ $slug = createSlug($title);
+
+ $kb = 0;
+
+ if (!empty($_POST['answercheck'])) {
+ $kb = sanitize($_POST['answercheck'],"int");
+ }
+
+ $cache = '';
+ if (!empty($link)) {
+ $cache = fetchURL($link);
+ }
+
+ if (strlen($title) < 15 || strlen($description)<15) {
+ header("Location: $basePath/questions/ask");
+ exit;
+ }
+
+ $sql = ("insert into questions (title,description,created,updated,link,userid,slug,linkcache,votes,accepted,answers,kb) values ('".escape($title)."','".escape($description)."',NOW(),NOW(),'".escape($link)."','".escape($_SESSION['userid'])."','".escape($slug)."','".escape($cache)."','0','0','0','".escape($kb)."')");
+ $query = mysql_query($sql);
+
+ $questionid = mysql_insert_id();
+
+ if (!empty($_POST['tags'])) {
+ foreach ($_POST['tags'] as $tag) {
+ $tag = createSlug($tag);
+
+ $sql = ("select * from tags where tag = '".escape($tag)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if ($result['id'] > 0) {
+ $sql = ("insert into tags_questions (tagid,questionid) values ('".escape($result['id'])."','".escape($questionid)."')");
+ $query = mysql_query($sql);
+ } else {
+
+ $sql = ("insert into tags (tag) values ('".escape($tag)."')");
+ $query = mysql_query($sql);
+ $tagid = mysql_insert_id();
+
+ $sql = ("insert into tags_questions (tagid,questionid) values ('".escape($tagid)."','".escape($questionid)."')");
+ $query = mysql_query($sql);
+ }
+ }
+ }
+
+ if (!empty($_POST['answer'])) {
+ $description = sanitize($_POST['answer'],"markdown");
+ $sql = ("insert into answers (questionid,description,created,updated,userid,accepted,votes) values ('".escape($questionid)."','".escape($description)."',NOW(),NOW(),'".escape($_SESSION['userid'])."','1','0')");
+ $query = mysql_query($sql);
+ }
+
+ if ($kb == 1) {
+ score('kb_posted',$questionid);
+ }
+
+ header("Location: $basePath/questions/view/$questionid/$slug");
+}
+
+
+function update() {
+ authenticate(1);
+
+ $questionid = sanitize($_POST['id'],"int");
+ $title = sanitize($_POST['title'],"string");
+ $description = sanitize($_POST['description'],"markdown");
+ $link = sanitize($_POST['link'],"url");
+
+ $slug = createSlug($title);
+
+ $kb = 0;
+
+ if (!empty($_POST['answercheck'])) {
+ $kb = sanitize($_POST['answercheck'],"int");
+ }
+
+ $cache = '';
+ if (!empty($link)) {
+ $cache = fetchURL($link);
+ }
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+
+ $result = mysql_fetch_array($query);
+
+ if ($result['userid'] != $_SESSION['userid']) {
+ $basePath = basePath();
+ header("Location: $basePath/questions/view/{$result['id']}/{$result['slug']}");
+ }
+
+ $cacheup = '';
+
+ if ($result['link'] != $link) {
+ $cacheup = ",linkcache = '".escape($cache)."'";
+ }
+
+ if ($result['kb'] == 1 && $kb == 0) {
+ score('kb_posted_removed',$questionid);
+ } else if ($result['kb'] == 0 && $kb == 1) {
+ score('kb_posted',$questionid);
+ }
+
+ $sql = ("update questions set title = '".escape($title)."', kb = '".escape($kb)."', description = '".escape($description)."' , updated = NOW(), link = '".escape($link)."', slug = '".escape($slug)."' $cacheup where userid = '".escape($_SESSION['userid'])."' and id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ echo mysql_error();
+
+
+ $sql = ("delete from tags_questions where questionid = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+
+
+ if (!empty($_POST['tags'])) {
+ foreach ($_POST['tags'] as $tag) {
+ $tag = createSlug($tag);
+
+ $sql = ("select * from tags where tag = '".escape($tag)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if ($result['id'] > 0) {
+ $sql = ("insert into tags_questions (tagid,questionid) values ('".escape($result['id'])."','".escape($questionid)."')");
+ $query = mysql_query($sql);
+ } else {
+
+ $sql = ("insert into tags (tag) values ('".escape($tag)."')");
+ $query = mysql_query($sql);
+ $tagid = mysql_insert_id();
+
+ $sql = ("insert into tags_questions (tagid,questionid) values ('".escape($tagid)."','".escape($questionid)."')");
+ $query = mysql_query($sql);
+ }
+ }
+ }
+
+
+
+ $basePath = basePath();
+ header("Location: $basePath/questions/view/$questionid/$slug");
+}
+
+function fetchtags() {
+ noRender();
+
+ $tag = createSlug($_GET['tag']);
+
+ header('Content-type: application/json; charset=utf-8');
+ $sql = ("select * from tags where tag LIKE '%".escape($tag)."%'");
+ $query = mysql_query($sql);
+
+ $resultSet = array();
+ while ($result = mysql_fetch_array($query)) {
+ $resultSet[] = array("caption" => $result['tag'], "value" => $result['tag']);
+ }
+ echo json_encode($resultSet);
+ exit();
+}
+
+
+function view() {
+ global $path;
+ global $template;
+
+ $questionid = sanitize($path[2],"int");
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('id',$result['id']);
+ $template->set('userid',$result['userid']);
+ $template->set('title',$result['title']);
+ $template->set('created',$result['created']);
+ $template->set('description',Markdown($result['description']));
+ $template->set('kb',$result['kb']);
+
+ $template->set('link',$result['link']);
+
+ $cache = 0;
+ if (!empty($result['linkcache'])) {
+ $cache = 1;
+ }
+
+ $template->set('cache',$cache);
+
+ $sql = ("select tag from tags_questions, tags where questionid = '".escape($questionid)."' and tags.id = tags_questions.tagid order by tag");
+ $query = mysql_query($sql);
+
+ $tags = array();
+ while ($result = mysql_fetch_array($query)) {
+ $tags[] = $result['tag'];
+ }
+
+ $template->set('tags',$tags);
+
+
+ $sql = ("select * from favorites where questionid = '".escape($questionid)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $fave = 0;
+ if ($result['id'] > 0) { $fave = 1; }
+
+ $template->set('fave',$fave);
+
+
+ $sql = ("select sum(vote) count from questions_votes where questionid = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $votes = $result['count'];
+ if ($votes == '') { $votes = 0; }
+
+ $template->set('votes',$votes);
+
+ $sql = ("select vote from questions_votes where questionid = '".escape($questionid)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $nvote = 0;
+ $pvote = 0;
+
+ if ($result['vote'] == -1) {
+ $nvote = 1;
+ }
+
+ if ($result['vote'] == 1) {
+ $pvote = 1;
+ }
+
+ $template->set('nvote',$nvote);
+ $template->set('pvote',$pvote);
+
+
+
+ $sql = ("select comments.id,comment,comments.userid,users.name username, comments_votes.id voted, comments.votes from comments left join users on comments.userid = users.id left join comments_votes on (comments_votes.commentid = comments.id and comments_votes.userid = '".escape($_SESSION['userid'])."') where type = '0' and typeid = '".escape($questionid)."' order by comments.created asc");
+ $query = mysql_query($sql);
+
+ $comments = array();
+
+ while ($result = mysql_fetch_array($query)) {
+ $pos = strpos($result['username'],' ');
+ if ($pos > 0) {
+ $result['username'] = substr($result['username'],0,$pos);
+ }
+
+ $comments[] = array("id" => $result['id'], "comment" => $result['comment'], "userid" => $result['userid'], "username" => $result['username'], "voted" => $result['voted'], "votes" => $result['votes']);
+ }
+
+ $template->set('comments',$comments);
+
+ $sql = ("select count(id) count from answers where questionid = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('answerscount',$result['count']);
+
+ $order = "votes desc";
+ $orderby = "votes";
+ $page = 1;
+
+ if (!empty($_GET['order'])) {
+ if ($_GET['order'] == "newest") {
+ $order = "created desc";
+ $orderby = "newest";
+ } else if ($_GET['order'] == "oldest") {
+ $order = "created asc";
+ $orderby = "oldest";
+ }
+ }
+
+ if (!empty($_GET['page'])) {
+ $page = $_GET['page'];
+ }
+
+ $offset = ($page-1)*ANSWERS_PER_PAGE;
+
+ $paging = new Pagination();
+ $paging->set('urlscheme','?order='.$orderby.'&page=%page%');
+ $paging->set('perpage',ANSWERS_PER_PAGE);
+ $paging->set('page',$page);
+ $paging->set('total',$result['count']);
+ $paging->set('order',$orderby);
+
+ $template->set('pagination',$paging->display());
+
+ $paging->set('urlscheme','?order=%label%&page=1');
+ $template->set('orderOptions',$paging->displayOptions());
+
+ $sqlanswer = '';
+
+ if ($page == 1) {
+ $sqlanswer = "(select answers.*,users.name username from answers,users where questionid = '".escape($questionid)."' and answers.userid = users.id and answers.accepted = '1') UNION ";
+ }
+
+ $sql = ("$sqlanswer (select answers.*,users.name username from answers,users where questionid = '".escape($questionid)."' and answers.userid = users.id and answers.accepted = '0' order by $order, created desc LIMIT ".ANSWERS_PER_PAGE." OFFSET $offset)");
+ $query = mysql_query($sql);
+
+
+ $answers = array();
+ while ($result = mysql_fetch_array($query)) {
+
+ $sql_nest = ("select sum(vote) count from answers_votes where answerid = '".escape($result['id'])."'");
+ $query_nest = mysql_query($sql_nest);
+ $result_nest = mysql_fetch_array($query_nest);
+
+ $votes = $result_nest['count'];
+
+ if ($votes == '') { $votes = 0; }
+
+ $sql_nest = ("select vote from answers_votes where answerid = '".escape($result['id'])."' and userid = '".escape($_SESSION['userid'])."'");
+ $query_nest = mysql_query($sql_nest);
+ $result_nest = mysql_fetch_array($query_nest);
+
+ $nvote = 0;
+ $pvote = 0;
+
+ if ($result_nest['vote'] == -1) {
+ $nvote = 1;
+ }
+
+ if ($result_nest['vote'] == 1) {
+ $pvote = 1;
+ }
+
+
+
+ $sql_nest = ("select comments.id,comment,comments.userid,users.name username, comments_votes.id voted, comments.votes from comments left join users on comments.userid = users.id left join comments_votes on (comments_votes.commentid = comments.id and comments_votes.userid = '".escape($_SESSION['userid'])."') where type = '1' and typeid = '".escape($result['id'])."' order by comments.created asc");
+ $query_nest = mysql_query($sql_nest);
+
+
+ $comments = array();
+
+ while ($result_nest = mysql_fetch_array($query_nest)) {
+ $pos = strpos($result['username'],' ');
+ if ($pos > 0) {
+ $result['username'] = substr($result['username'],0,$pos);
+ }
+ $comments[] = array("id" => $result_nest['id'], "comment" => $result_nest['comment'], "userid" => $result_nest['userid'], "username" => $result['username'], "voted" => $result_nest['voted'], "votes" => $result_nest['votes']);
+ }
+
+ $answers[] = array ("description" => Markdown($result['description']), "created" => $result['created'], "updated" => $result['updated'], "userid" => $result['userid'], "username" => $result['username'], "pvote" => $pvote, "nvote" => $nvote, "votes" => $votes, "id" => $result['id'], "accepted"=> $result['accepted'], "comments" => $comments );
+ }
+
+ $template->set('answers',$answers);
+
+ $basePathNS = basePathNS();
+
+ $js = '';
+
+ if ($_SESSION['userid'] != '') {
+ $js = <<<EOD
+
+ <script src="$basePathNS/js/showdown.js"></script>
+ <script src="$basePathNS/js/wmd.js"></script>
+ <link href="$basePathNS/css/wmd.css" type="text/css" rel="stylesheet" />
+
+EOD;
+
+ }
+
+ $js .= <<<EOD
+
+
+
+<script>
+
+ var basePath = "/qwench/index.php";
+
+
+ function vote(elem,type,voted) {
+ \$this = $(elem);
+ var id = \$this.parent().parent().parent().attr('id');
+
+ var add = 1;
+ var minus = -1;
+ var up = 'up';
+ var down = 'down';
+ if (voted == 'minus') { add = -1; minus = 1; up = 'down'; down = 'up'; }
+
+ $.post(basePath+"/"+type+"/vote", { id: id, vote: voted },
+ function(data) {
+ var result = data.substr(0,1);
+ var message = data.substr(1);
+
+ if (result == 1) {
+
+ if (!$("#"+id+" .questionsview_"+up+"").hasClass("voteselected")) {
+
+ $("#"+id+" .questionsview_vote").html(parseInt($("#"+id+" .questionsview_vote").html())+add);
+
+ if ($("#"+id+" .questionsview_"+down+"").hasClass("voteselected")) {
+ $("#"+id+" .questionsview_vote").html(parseInt($("#"+id+" .questionsview_vote").html())+add);
+ $("#"+id+" .questionsview_"+down+"").removeClass("voteselected");
+ }
+
+ } else {
+ $("#"+id+" .questionsview_vote").html(parseInt($("#"+id+" .questionsview_vote").html())+minus);
+ }
+
+ \$this.toggleClass("voteselected");
+ }
+
+ if (message != '') {
+ $.fancyalert(message);
+ }
+
+ });
+ }
+
+ $(document).ready(function() {
+
+ $(".questionsview_answer .questionsview_up").click(function() {
+ vote(this,'answers','plus');
+ });
+
+ $(".questionsview_answer .questionsview_down").click(function() {
+ vote(this,'answers','minus');
+ });
+
+ $(".questionsview_question .questionsview_up").click(function() {
+ vote(this,'questions','plus');
+ });
+
+ $(".questionsview_question .questionsview_down").click(function() {
+ vote(this,'questions','minus');
+ });
+
+ $(".questionsview_question .questionsview_fave").click(function() {
+ \$this = $(this);
+ var id = \$this.parent().parent().parent().attr('id');
+ $.post(basePath+"/questions/fave", { id: id },
+ function(data) {
+ var result = data.substr(0,1);
+ var message = data.substr(1);
+
+ if (result == 1) {
+ \$this.toggleClass("voteselected");
+ }
+
+ $.fancyalert(message);
+
+ });
+ });
+
+
+ $(".commentfave").click(function() {
+
+ var id = $(this).attr('id');
+ \$this = $(this);
+
+ $.post(basePath+"/comments/vote", { id: id },
+ function(data) {
+
+ var result = data.substr(0,1);
+ var message = data.substr(1);
+
+ if (result == "1") {
+ if (\$this.next('div').html() == '') {
+ \$this.next('div').html('0');
+ }
+
+ if (!\$this.hasClass("voteselected")) {
+ \$this.next('div').html(parseInt(\$this.next('div').html())+1);
+ } else {
+ \$this.next('div').html(parseInt(\$this.next('div').html())-1);
+ }
+
+ \$this.toggleClass("voteselected");
+ }
+
+ if (message != '') {
+ $.fancyalert(message);
+ }
+
+ });
+
+
+ });
+
+ $(".commentdel").click(function() {
+
+ var answer = confirm("Delete this comment?")
+ if (answer){
+ var id = $(this).attr('id');
+ \$this = $(this);
+ $.post(basePath+"/comments/del", { id: id },
+ function(data) {
+
+ var result = data.substr(0,1);
+ var message = data.substr(1);
+
+ if (result == "1") {
+ \$this.parent().fadeOut(2000);
+ }
+
+ if (message != '') {
+ $.fancyalert(message);
+ }
+
+ });
+ }
+
+
+ });
+
+ var comments = $(".comments");
+ $.each(comments, function() {
+ var elements = ( $('.comment:gt(4)',$(this)).size());
+
+ if (elements > 0) {
+ $('.viewallcomments',$(this)).css('display','block');
+ $('.viewallcomments a',$(this)).html('View all comments ('+elements+' more)');
+ }
+
+ allComments = $(".comment",$(this)).get();
+ allComments.sort(function(a,b) {
+ a = $(".commentfavevotes",a).html();
+ b = $(".commentfavevotes",b).html();;
+
+ if (a == '') a = 0;
+ if (b == '') b = 0;
+
+ if (a > b) {
+ return -1;
+ } else if (a < b) {
+ return 1;
+ } else {
+ return 0;
+ }
+ });
+ $(allComments.slice(5)).hide();
+
+
+
+ });
+
+});
+
+function comment(id) {
+ $("#comment_"+id).html("<textarea class=\"commenttextarea\" id='commenttext_"+id+"'></textarea><input class=\"smallbutton\" type=\"submit\" value=\"Add Comment\" onclick=\"addcomment('"+id+"')\"/>");
+}
+
+function addcomment(id) {
+
+ var comment = $("#commenttext_"+id).val();
+
+ if (comment.length < 10) {
+ $.fancyalert('Your comment must be atleast 10 characters in length');
+ return;
+ }
+
+ if (comment.length > 600) {
+ $.fancyalert('Your comment is too long, please reduce it to 600 characters');
+ return;
+ }
+
+ $("#commenttext_"+id).val('');
+
+ $.post(basePath+"/comments/post", { id: id, comment: comment },
+ function(data) {
+ if (data == 0) {
+ $("#commenttext_"+id).val(comment);
+ $.fancyalert('Please login to post a comment');
+ } else {
+ $("#comments_"+id).append(data);
+ }
+ });
+}
+
+
+function viewallcomments(id){
+ $('#comments_'+id+' .comment').fadeIn(1000);
+ $('#comment_'+id+' .viewallcomments').css('display','none');
+}
+
+</script>
+
+EOD;
+
+ $template->set('js',$js);
+}
+
+function cache() {
+ global $path;
+ global $template;
+ global $noheader;
+
+ $noheader = true;
+ $questionid = sanitize($path[2],"int");
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('cachelink',$result['link']);
+ $template->set('cache',$result['linkcache']);
+}
+
+function vote() {
+ if ($_SESSION['userid'] == '') {
+ echo "0Please login to vote";
+ exit;
+ }
+
+ $id = sanitize($_POST['id'],"int");
+ $vote = sanitize($_POST['vote'],"string");
+
+ if ($vote == 'plus') {
+ $vote = '+1';
+ } else {
+ $vote = '-1';
+ }
+
+ $sql = ("select questions.userid,questions_votes.id qvid,questions_votes.vote qvvote from questions left join questions_votes on (questions.id = questions_votes.questionid and questions_votes.userid = '".escape($_SESSION['userid'])."') where questions.id = '".escape($id)."'");
+ $query = mysql_query($sql);
+
+ $question = mysql_fetch_array($query);
+
+ if ($question['userid'] == $_SESSION['userid']) {
+ echo "0"."You cannot up/down vote your own question";
+ exit;
+ }
+
+ if ($question['qvid'] > 0) {
+
+ if ($question['qvvote'] == 1 && $vote == '+1') {
+ $vote = "-1";
+ score('q_upvoted_removed',$id,$question['userid']);
+ } else if ($question['qvvote'] == 1 && $vote == '-1') {
+ $vote = "-2";
+ score('q_upvoted_removed',$id,$question['userid']);
+ score('q_downvoter',$id);
+ score('q_downvoted',$id,$question['userid']);
+ } else if ($question['qvvote'] == -1 && $vote == '-1') {
+ $vote = "+1";
+ score('q_downvoter_removed',$id);
+ score('q_downvoted_removed',$id,$question['userid']);
+ } else if ($question['qvvote'] == -1 && $vote == '+1') {
+ $vote = "+2";
+ score('q_downvoter_removed',$id);
+ score('q_downvoted_removed',$id,$question['userid']);
+ score('q_upvoted',$id,$question['userid']);
+ } else if ($question['qvvote'] == 0) {
+ if ($vote == 1) {
+ score('q_upvoted',$id,$question['userid']);
+ } else {
+ score('q_downvoter',$id);
+ score('q_downvoted',$id,$question['userid']);
+ }
+ }
+
+ $sql = ("update questions_votes set vote = vote".escape($vote)." where id = '".$question['qvid']."'");
+ $query = mysql_query($sql);
+
+ } else {
+ $sql = ("insert into questions_votes (questionid,userid,vote) values ('".escape($id)."','".escape($_SESSION['userid'])."','".escape($vote)."')");
+ $query = mysql_query($sql);
+
+ if ($vote == 1) {
+ score('q_upvoted',$id,$question['userid']);
+ } else {
+ score('q_downvoter',$id);
+ score('q_downvoted',$id,$question['userid']);
+ }
+
+ }
+
+ $sql_nest = ("update questions set votes = votes".escape($vote)." where id = '".escape($id)."'");
+ $query_nest = mysql_query($sql_nest);
+
+ echo "1Thankyou for voting";
+ exit;
+
+}
+
+function fave() {
+
+ if ($_SESSION['userid'] == '') {
+ echo "0Please login to add a question to your favorites";
+ exit;
+ }
+
+ $id = sanitize($_POST['id'],"int");
+
+ $sql = ("select * from favorites where questionid = '".escape($id)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if ($result['id'] > 0) {
+ $sql = ("delete from favorites where questionid = '".escape($id)."' and userid = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ echo "1Question removed from your favorites";
+
+ } else {
+ $sql = ("insert into favorites (questionid,userid) values ('".escape($id)."','".escape($_SESSION['userid'])."')");
+ $query = mysql_query($sql);
+ echo "1Question added to your favorites";
+ }
+
+
+ exit;
+
+}
+
+function index() {
+ global $path;
+ global $template;
+
+ $conditionspre = '';
+ $conditionspost = '';
+ $conditionsselect = '';
+ $extratitle = '';
+
+
+ $orderby = 'newest';
+ $order = 'created desc';
+ $defaultorder = 1;
+ $nopagination = 0;
+ $page = 1;
+
+ $searchstringoriginal = '';
+
+ if (!empty($_GET['search'])) { $searchstringoriginal = sanitize($_GET['search'],"string"); }
+
+ if (!empty($_GET['order'])) {
+ if ($_GET['order'] == "votes") {
+ $order = "votes desc";
+ $orderby = "votes";
+ $defaultorder = 0;
+ } else if ($_GET['order'] == "oldest") {
+ $order = "created asc";
+ $orderby = "oldest";
+ $defaultorder = 0;
+ } else if ($_GET['order'] == "relevance") {
+ $order = "score desc";
+ $orderby = "relevance";
+ $defaultorder = 0;
+ } else if ($_GET['order'] == "newest") {
+ $defaultorder = 0;
+ }
+ }
+
+ if (!empty($_GET['page'])) {
+ $page = sanitize($_GET['page'],"int");
+ }
+
+ $type = '';
+
+
+ if (!empty($_GET['type'])) {
+
+ $type = "&type=".sanitize($_GET['type'],"string");
+
+ if (sanitize($_GET['type'],"string") == "unanswered") {
+ // $conditionspost .= " questions.id NOT IN (select questions.id from questions,answers where questions.id = answers.questionid and answers.accepted = 1) and ";
+ $conditionspost .= " questions.accepted = 0 and questions.kb = 0 and ";
+ $extratitle = " not yet answered";
+
+ } else {
+ $extratitle = " active";
+ $order = " updated desc ";
+ $nopagination = 1;
+ }
+ }
+
+ $template->set('nopagination',$nopagination);
+
+ $search = '';
+ $searchstring = urldecode($searchstringoriginal);
+
+ if (!empty($searchstringoriginal)) {
+ $search = "&search=".urlencode($searchstring);
+ $conditionspost .= " MATCH(title, description) AGAINST ('".escape($searchstring)."') and ";
+ $conditionsselect .= ",MATCH(title, description) AGAINST ('".escape($searchstring)."') AS score ";
+ $extratitle = " showing ".$searchstring;
+ if ($defaultorder == 1) {
+ $orderby = 'relevance';
+ $order = 'score desc';
+ }
+ }
+
+ $template->set('searchstring',$searchstring);
+
+ $tag = '';
+
+ if (!empty($_GET['tag'])) {
+ $tag = "&tag=".createSlug($_GET['tag']);
+ $conditionspre .= ",tags_questions, tags";
+ $conditionspost .= " tags_questions.questionid = questions.id and tags.id = tags_questions.tagid and tags.tag LIKE '".escape(createSlug($_GET['tag']))."' and ";
+ $extratitle = " tagged ".createSlug($_GET['tag']);
+ }
+
+ $offset = ($page-1)*QUESTIONS_PER_PAGE;
+
+ $sql = ("select count(questions.id) count from questions $conditionspre WHERE $conditionspost 1");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('questionscount',$result['count']);
+
+ $paging = new Pagination();
+ $paging->set('urlscheme','?order='.$orderby.$tag.$type.$search.'&page=%page%');
+ $paging->set('perpage',QUESTIONS_PER_PAGE);
+ $paging->set('page',$page);
+ $paging->set('total',$result['count']);
+ $paging->set('order',$orderby);
+ $paging->set('search',$search);
+
+ $template->set('pagination',$paging->display());
+
+ $paging->set('urlscheme','?order=%label%'.$tag.$type.$search.'&page=1');
+ $template->set('orderOptions',$paging->displayOptions());
+
+ $template->set('extratitle',$extratitle);
+
+ $sql = ("select questions.* $conditionsselect from questions $conditionspre WHERE $conditionspost 1 order by $order, created desc LIMIT ".QUESTIONS_PER_PAGE." OFFSET $offset");
+ $query = mysql_query($sql);
+
+ $questions = array();
+
+ while ($result = mysql_fetch_array($query)) {
+
+ $sql_nest = ("select tag from tags_questions, tags where questionid = '".escape($result['id'])."' and tags.id = tags_questions.tagid order by tag");
+ $query_nest = mysql_query($sql_nest);
+
+ $tags = array();
+ while ($result_nest = mysql_fetch_array($query_nest)) {
+ $tags[] = $result_nest['tag'];
+ }
+
+ $description = truncate(trim(sanitize(Markdown($result['description']),"string")));
+
+ if (!empty($searchstring)) {
+ $description = highlight(excerpt((trim(sanitize(Markdown($result['description']),"string"))),$searchstring),$searchstring);
+ $result['title'] = highlight($result['title'],$searchstring);
+ }
+
+ $questions[] = array ("title" => $result['title'], "created" => $result['created'], "updated" => $result['updated'], "userid" => $result['userid'], "link" => $result['link'], "slug" => $result['slug'], "answers" => $result['answers'], "accepted" => $result['accepted'], "kb" => $result['kb'], "votes" => $result['votes'], "id" => $result['id'], "tags" => $tags, "description" => $description);
+
+ }
+
+ $template->set('questions',$questions);
+
+}
23 controllers/.svn/text-base/tags.php.svn-base
View
@@ -0,0 +1,23 @@
+<?php
+
+function index() {
+ global $template;
+
+ $sql = ("select count(id) count from tags");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+ $template->set('count',$result['count']);
+
+ $sql = ("select tag, count(tags_questions.questionid) tagcount from tags, tags_questions where tags.id = tags_questions.tagid group by tagid order by tagcount desc");
+ $query = mysql_query($sql);
+
+ $tags = array();
+
+ while ($result = mysql_fetch_array($query)) {
+ $tags[] = array ("tag" => $result['tag'], "count" => $result['tagcount']);
+ }
+
+ $template->set('tags',$tags);
+
+ /* Add Pagination Later */
+}
131 controllers/.svn/text-base/users.php.svn-base
View
@@ -0,0 +1,131 @@
+<?php
+
+function login() {
+ global $template;
+ $template->set('loginpage','1');
+}
+
+function view() {
+
+ global $path;
+ global $template;
+
+ $userid = sanitize($path[2],"int");
+
+ $sql = ("select * from users where id = '".escape($userid)."'");
+ $query = mysql_query($sql);
+ $user = mysql_fetch_array($query);
+
+ $basePath = basePath();
+
+ $template->set('user',$user);
+}
+
+function edit() {
+ authenticate(1);
+ global $template;
+ $sql = ("select * from users where id = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ $user = mysql_fetch_array($query);
+ $basePath = basePath();
+ $template->set('user',$user);
+}
+
+function update() {
+ authenticate(1);
+ global $template;
+
+ $name = sanitize($_POST['name'],"string");
+ $email = sanitize($_POST['email'],"email");
+ $password = sanitize($_POST['password'],"string");
+ $password = sha1(SALT.$password.$email);
+
+ if (!empty($_POST['password'])) {
+ $sql = ("update users set password = '".escape($password)."' where id = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+ }
+
+ $sql = ("update users set name = '".escape($name)."', email = '".escape($email)."' where id = '".escape($_SESSION['userid'])."'");
+ $query = mysql_query($sql);
+
+ $slug = createslug($name);
+
+ $basePath = basePath();
+ header("Location: $basePath/users/view/{$_SESSION['userid']}/$slug");
+}
+
+function validate() {
+ $email = sanitize($_POST['email'],"email");
+ $password = sanitize($_POST['password'],"string");
+ $password = sha1(SALT.$password.$email);
+
+ $sql = ("select * from users where email = '".escape($email)."' and password = '".escape($password)."'");
+ $query = mysql_query($sql);
+ $user = mysql_fetch_array($query);
+
+ $basePath = basePath();
+
+ if ($user['id'] > 0) {
+ $_SESSION['userid'] = $user['id'];
+ $_SESSION['name'] = $user['name'];
+ $_SESSION['email'] = $user['email'];
+ $_SESSION['password'] = $user['password'];
+ $_SESSION['points'] = $user['points'];
+
+ if (!empty($_POST['returnurl'])) {
+ $url = sanitize($_POST['returnurl'],"url");
+ header("Location: {$url}");
+ } else {
+
+ header("Location: $basePath");
+ }
+ } else {
+ header("Location: $basePath/users/login");
+ }
+}
+
+function register() {
+
+}
+
+function create() {
+ $name = sanitize($_POST['name'],"string");
+ $email = sanitize($_POST['email'],"email");
+ $password = sanitize($_POST['password'],"string");
+ $password = sha1(SALT.$password.$email);
+
+ $sql = ("insert into users (name,email,password,points,moderator,created,lastactivity) values ('".escape($name)."','".escape($email)."','".escape($password)."','1','0',NOW(),NOW())");
+ $query = mysql_query($sql);
+
+ validate();
+
+}
+
+function logout() {
+ session_destroy();
+ session_start();
+ $_SESSION['userid'] = '';
+
+}
+
+function index() {
+ global $template;
+
+ $sql = ("select count(id) count from users");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+ $template->set('count',$result['count']);
+
+ $sql = ("select * from users order by points desc, name asc");
+ $query = mysql_query($sql);
+
+ $users = array();
+
+ while ($result = mysql_fetch_array($query)) {
+ $users[] = array ("id" => $result['id'], "name" => $result['name'], "points" => $result['points']);
+ }
+
+ $template->set('users',$users);
+
+ /* Add Pagination Later */
+}
202 controllers/answers.php
View
@@ -0,0 +1,202 @@
+<?php
+
+function edit() {
+ authenticate(1);
+
+ global $path;
+ global $template;
+ $answerid = sanitize($path[2],"int");
+
+ $basePath = basePath();
+ $basePathNS = basePathNS();
+
+ $js = <<<EOD
+
+<script src="$basePathNS/js/showdown.js"></script>
+<script src="$basePathNS/js/wmd.js"></script>
+<link href="$basePathNS/css/wmd.css" type="text/css" rel="stylesheet" />
+
+EOD;
+
+ $template->set('js',$js);
+
+ $sql = ("select * from answers where id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $template->set('description',$result['description']);
+ $template->set('answerid',$result['id']);
+}
+
+function post() {
+ authenticate(1);
+ $basePath = basePath();
+
+ $description = sanitize($_POST['description'],"markdown");
+ $questionid = sanitize($_POST['questionid'],"int");
+
+ $sql = ("select * from questions where id = '".escape($questionid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ if (strlen($description) < 15 || $result['id'] == '' || $result['id'] == 0) {
+ header("Location: $basePath/questions/view/$questionid/{$result['slug']}");
+ exit;
+ }
+
+ $sql = ("insert into answers (questionid,description,created,updated,userid,accepted,votes) values ('".escape($questionid)."','".escape($description)."',NOW(),NOW(),'".escape($_SESSION['userid'])."','0','0')");
+ $query = mysql_query($sql);
+
+ $sql = ("update questions set updated = NOW(), answers=answers+1 where id = '".escape($result['id'])."'");
+ $query = mysql_query($sql);
+
+ header("Location: $basePath/questions/view/$questionid/{$result['slug']}");
+}
+
+function update() {
+ authenticate(1);
+
+ $answerid = sanitize($_POST['id'],"int");
+ $description = sanitize($_POST['description'],"markdown");
+
+ $sql = ("select * from answers where id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+ $result = mysql_fetch_array($query);
+
+ $sql = ("select * from questions where id = '".escape($result['questionid'])."'");
+ $query = mysql_query($sql);
+ $qresult = mysql_fetch_array($query);
+
+ if ($qresult['userid'] != $_SESSION['userid']) {
+ $basePath = basePath();
+ header("Location: $basePath/questions/view/{$qresult['id']}/{$qresult['slug']}");
+ }
+
+ $sql = ("update answers set description = '".escape($description)."', updated = NOW() where userid = '".escape($_SESSION['userid'])."' and id = '".escape($answerid)."'");
+ $query = mysql_query($sql);
+
+ $sql = ("update questions set updated = NOW() where id = '".escape($result['questionid'])."'");
+ $query = mysql_query($sql);
+
+ $basePath = basePath();
+
+ header("Location: $basePath/questions/view/{$qresult['id']}/{$qresult['slug']}");
+}
+
+function vote() {
+ if ($_SESSION['userid'] == '') {
+ echo "0Please login to vote";
+ exit;
+ }
+
+ $id = sanitize($_POST['id'],"int");
+ $vote = sanitize($_POST['vote'],"string");
+
+ if ($vote == 'plus') {
+ $vote = '+1';
+ } else {
+ $vote = '-1';
+ }
+
+ $sql = ("select answers.userid,answers_votes.id qvid,answers_votes.vote qvvote from answers left join answers_votes on (answers.id = answers_votes.answerid and answers_votes.userid = '".escape($_SESSION['userid'])."') where answers.id = '".escape($id)."'");
+ $query = mysql_query($sql);
+
+ $answer = mysql_fetch_array($query);
+
+ if ($answer['userid'] == $_SESSION['userid']) {
+ echo "0"."You cannot up/down vote your own answer";
+ exit;
+ }
+
+ if ($answer['qvid'] > 0) {
+
+ if ($answer['qvvote'] == 1 && $vote == '+1') {
+ $vote = "-1";
+ score('a_upvoted_removed',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == 1 && $vote == '-1') {
+ $vote = "-2";
+ score('a_upvoted_removed',$id,$answer['userid']);
+ score('a_downvoter',$id);
+ score('a_downvoted',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == -1 && $vote == '-1') {
+ $vote = "+1";
+ score('a_downvoter_removed',$id);
+ score('a_downvoted_removed',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == -1 && $vote == '+1') {
+ $vote = "+2";
+ score('a_downvoter_removed',$id);
+ score('a_downvoted_removed',$id,$answer['userid']);
+ score('a_upvoted',$id,$answer['userid']);
+ } else if ($answer['qvvote'] == 0) {
+ if ($vote == 1) {
+ score('a_upvoted',$id,$answer['userid']);
+ } else {