PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/phpmyfaq/admin/ajax.config_list.php

https://github.com/cyrke/phpMyFAQ
PHP | 266 lines | 211 code | 32 blank | 23 comment | 34 complexity | 1b5d67dc838e4c24cf3d25f1ba6a8033 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * AJAX: lists the complete configuration items as text/html
  4. *
  5. * PHP 5.2
  6. *
  7. * This Source Code Form is subject to the terms of the Mozilla Public License,
  8. * v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. * obtain one at http://mozilla.org/MPL/2.0/.
  10. *
  11. * @category phpMyFAQ
  12. * @package Administration
  13. * @author Thorsten Rinne <thorsten@phpmyfaq.de>
  14. * @author Thomas Zeithaml <tom@annatom.de>
  15. * @copyright 2005-2012 phpMyFAQ Team
  16. * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
  17. * @link http://www.phpmyfaq.de
  18. * @since 2005-12-26
  19. */
  20. if (!defined('IS_VALID_PHPMYFAQ')) {
  21. header('Location: http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
  22. exit();
  23. }
  24. require PMF_ROOT_DIR . '/inc/libs/twitteroauth/twitteroauth.php';
  25. if (!empty($_SESSION['access_token'])) {
  26. $connection = new TwitterOAuth(
  27. $faqConfig->get('socialnetworks.twitterConsumerKey'),
  28. $faqConfig->get('socialnetworks.twitterConsumerSecret'),
  29. $_SESSION['access_token']['oauth_token'],
  30. $_SESSION['access_token']['oauth_token_secret']
  31. );
  32. $content = $connection->get('account/verify_credentials');
  33. }
  34. $configMode = PMF_Filter::filterInput(INPUT_GET, 'conf', FILTER_SANITIZE_STRING, 'main');
  35. $availableConfigModes = array(
  36. 'main' => 1,
  37. 'records' => 1,
  38. 'spam' => 1,
  39. 'search' => 1,
  40. 'social' => 1
  41. );
  42. /**
  43. * @param $key
  44. * @param $type
  45. * @return void
  46. */
  47. function printInputFieldByType($key, $type)
  48. {
  49. global $PMF_LANG, $faqConfig;
  50. switch ($type) {
  51. case 'area':
  52. printf('<textarea name="edit[%s]" cols="60" rows="6" class="input-xxlarge">%s</textarea>',
  53. $key,
  54. str_replace('<', '&lt;', str_replace('>', '&gt;', $faqConfig->get($key))));
  55. printf("</div>\n");
  56. break;
  57. case 'input':
  58. if ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenKey' == $key &&
  59. isset($_SESSION['access_token'])) {
  60. $value = $_SESSION['access_token']['oauth_token'];
  61. } elseif ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenSecret' == $key &&
  62. isset($_SESSION['access_token'])) {
  63. $value = $_SESSION['access_token']['oauth_token_secret'];
  64. } else {
  65. $value = str_replace('"', '&quot;', $faqConfig->get($key));
  66. }
  67. printf(
  68. '<input class="%s" type="%s" name="edit[%s]" size="75" value="%s" />',
  69. is_numeric($value) ? 'input-small' : 'input-xxlarge',
  70. is_numeric($value) ? 'number' : 'text',
  71. $key,
  72. $value
  73. );
  74. echo "</div>\n";
  75. break;
  76. case 'select':
  77. printf('<select name="edit[%s]" size="1" class="input-xlarge">', $key);
  78. switch ($key) {
  79. case 'main.language':
  80. $languages = PMF_Language::getAvailableLanguages();
  81. if (count($languages) > 0) {
  82. print PMF_Language::languageOptions(
  83. str_replace(
  84. array(
  85. 'language_',
  86. '.php'
  87. ),
  88. '',
  89. $faqConfig->get('main.language')
  90. ),
  91. false,
  92. true
  93. );
  94. } else {
  95. print '<option value="language_en.php">English</option>';
  96. }
  97. break;
  98. case 'records.orderby':
  99. print PMF_Configuration::sortingOptions($faqConfig->get($key));
  100. break;
  101. case 'records.sortby':
  102. printf('<option value="DESC"%s>%s</option>',
  103. ('DESC' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  104. $PMF_LANG['ad_conf_desc']);
  105. printf('<option value="ASC"%s>%s</option>',
  106. ('ASC' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  107. $PMF_LANG['ad_conf_asc']);
  108. break;
  109. case 'security.permLevel':
  110. print PMF_Perm::permOptions($faqConfig->get($key));
  111. break;
  112. case 'main.templateSet':
  113. $faqSystem = new PMF_System();
  114. $templates = $faqSystem->getAvailableTemplates();
  115. foreach ($templates as $template => $selected) {
  116. printf ("<option%s>%s</option>",
  117. ($selected === true ? ' selected="selected"' : ''),
  118. $template
  119. );
  120. }
  121. break;
  122. case "records.attachmentsStorageType":
  123. foreach($PMF_LANG['att_storage_type'] as $i => $item) {
  124. $selected = $faqConfig->get($key) == $i
  125. ? ' selected="selected"'
  126. : '';
  127. printf('<option value="%d"%s>%s</option>',
  128. $i, $selected, $item);
  129. }
  130. break;
  131. case "records.orderingPopularFaqs":
  132. printf('<option value="visits"%s>%s</option>',
  133. ('visits' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  134. $PMF_LANG['records.orderingPopularFaqs.visits']);
  135. printf('<option value="voting"%s>%s</option>',
  136. ('voting' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  137. $PMF_LANG['records.orderingPopularFaqs.voting']);
  138. break;
  139. case "search.relevance":
  140. printf('<option value="thema,content,keywords"%s>%s</option>',
  141. ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  142. $PMF_LANG['search.relevance.thema-content-keywords']);
  143. printf('<option value="thema,keywords,content"%s>%s</option>',
  144. ('thema,keywords,content' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  145. $PMF_LANG['search.relevance.thema-keywords-content']);
  146. printf('<option value="content,thema,keywords"%s>%s</option>',
  147. ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  148. $PMF_LANG['search.relevance.content-thema-keywords']);
  149. printf('<option value="content,keywords,thema"%s>%s</option>',
  150. ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  151. $PMF_LANG['search.relevance.content-keywords-thema']);
  152. printf('<option value="keywords,content,thema"%s>%s</option>',
  153. ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  154. $PMF_LANG['search.relevance.keywords-content-thema']);
  155. printf('<option value="keywords,thema,content"%s>%s</option>',
  156. ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected="selected"' : '',
  157. $PMF_LANG['search.relevance.keywords-thema-content']);
  158. break;
  159. }
  160. print "</select>\n</p>\n";
  161. break;
  162. case 'checkbox':
  163. printf('<input type="checkbox" name="edit[%s]" value="true"', $key);
  164. if ($faqConfig->get($key)) {
  165. print ' checked="checked"';
  166. }
  167. print " /></div>\n";
  168. break;
  169. case 'print':
  170. printf('<input type="hidden" name="edit[%s]" size="80" value="%s" />%s</div>',
  171. $key,
  172. str_replace('"', '&quot;', $faqConfig->get($key)),
  173. $faqConfig->get($key));
  174. break;
  175. }
  176. }
  177. header("Content-type: text/html; charset=utf-8");
  178. foreach ($LANG_CONF as $key => $value) {
  179. if (strpos($key, $configMode) === 0) {
  180. if ('socialnetworks.twitterConsumerKey' == $key) {
  181. print '<p>';
  182. if ('' == $faqConfig->get('socialnetworks.twitterConsumerKey') ||
  183. '' == $faqConfig->get('socialnetworks.twitterConsumerSecret')) {
  184. print '<a target="_blank" href="https://dev.twitter.com/apps/new">Create Twitter APP for your site</a>';
  185. print "<br />\n";
  186. print "Your Callback URL is: " .$faqConfig->get('main.referenceURL') . "/services/twitter/callback.php";
  187. }
  188. if (!isset($content)) {
  189. print '<a target="_blank" href="../services/twitter/redirect.php">';
  190. print '<img src="../assets/img/twitter.signin.png" alt="Sign in with Twitter"/></a>';
  191. print "<br />\n<br />\n";
  192. } elseif (isset($content)) {
  193. print $content->screen_name . "<br />\n";
  194. print "<img src='" . $content->profile_image_url_https . "'><br />\n";
  195. print "Follower: " . $content->followers_count . "<br />\n";
  196. print "Status Count: " . $content->statuses_count . "<br />\n";
  197. print "Status: " . $content->status->text . "<br />\n";
  198. print "<br />\n";
  199. }
  200. print '</div>';
  201. }
  202. ?>
  203. <div class="control-group">
  204. <label class="control-label admin-config-label">
  205. <?php
  206. switch ($key) {
  207. case 'records.maxAttachmentSize':
  208. printf($value[1], ini_get('upload_max_filesize'));
  209. break;
  210. case 'main.googleTranslationKey':
  211. printf(
  212. '<a target="_blank" href="http://code.google.com/apis/loader/signup.html">%s</a>',
  213. $value[1]
  214. );
  215. break;
  216. case 'main.dateFormat':
  217. printf(
  218. '<a target="_blank" href="http://www.php.net/manual/%s/function.date.php">%s</a>',
  219. $LANGCODE,
  220. $value[1]
  221. );
  222. break;
  223. default:
  224. print $value[1];
  225. break;
  226. }
  227. ?>
  228. </label>
  229. <div class="controls admin-config-control">
  230. <?php printInputFieldByType($key, $value[0]); ?>
  231. </div>
  232. <?php
  233. }
  234. }