PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/common/settings.php

http://dabr.googlecode.com/
PHP | 167 lines | 126 code | 27 blank | 14 comment | 16 complexity | e41d8a5dec48edcca3ba5984cd2971d2 MD5 | raw file
  1. <?php
  2. /*
  3. Syntax is
  4. 'Name|links,bodybg,bodyt,small,odd,even,replyodd,replyeven,menubg,menut,menua',
  5. Assembled in theme_css()
  6. */
  7. $GLOBALS['colour_schemes'] = array(
  8. 0 => 'Pretty In Pink|c06,fcd,623,c8a,fee,fde,ffa,dd9,c06,fee,fee',
  9. 1 => 'Ugly Orange|b50,ddd,111,555,fff,eee,ffa,dd9,e81,c40,fff',
  10. 2 => 'Touch Blue|138,ddd,111,555,fff,eee,ffa,dd9,138,fff,fff',
  11. 3 => 'Sickly Green|293C03,ccc,000,555,fff,eee,CCE691,ACC671,495C23,919C35,fff',
  12. 4 => 'Kris\' Purple|d5d,000,ddd,999,222,111,202,101,909,222,000,000',
  13. 5 => '#red|d12,ddd,111,555,fff,eee,ffa,dd9,c12,fff,fff',
  14. );
  15. menu_register(array(
  16. 'settings' => array(
  17. 'callback' => 'settings_page',
  18. ),
  19. 'reset' => array(
  20. 'hidden' => true,
  21. 'callback' => 'cookie_monster',
  22. ),
  23. ));
  24. function cookie_monster() {
  25. $cookies = array(
  26. 'browser',
  27. 'settings',
  28. 'utc_offset',
  29. 'search_favourite',
  30. 'perPage',
  31. 'USER_AUTH',
  32. );
  33. $duration = time() - 3600;
  34. foreach ($cookies as $cookie) {
  35. setcookie($cookie, NULL, $duration, '/');
  36. setcookie($cookie, NULL, $duration);
  37. }
  38. return theme('page', 'Cookie Monster', '<p>The cookie monster has logged you out and cleared all settings. Try logging in again now.</p>');
  39. }
  40. function setting_fetch($setting, $default = NULL) {
  41. $settings = (array) unserialize(base64_decode($_COOKIE['settings']));
  42. if (array_key_exists($setting, $settings)) {
  43. return $settings[$setting];
  44. } else {
  45. return $default;
  46. }
  47. }
  48. function setcookie_year($name, $value) {
  49. $duration = time() + (3600 * 24 * 365);
  50. setcookie($name, $value, $duration, '/');
  51. }
  52. function settings_page($args) {
  53. if ($args[1] == 'save') {
  54. $settings['browser'] = $_POST['browser'];
  55. $settings['perPage'] = $_POST['perPage'];
  56. $settings['gwt'] = $_POST['gwt'];
  57. $settings['colours'] = $_POST['colours'];
  58. $settings['reverse'] = $_POST['reverse'];
  59. $settings['timestamp'] = $_POST['timestamp'];
  60. $settings['hide_inline'] = $_POST['hide_inline'];
  61. $settings['utc_offset'] = (float)$_POST['utc_offset'];
  62. $settings['emoticons'] = $_POST['emoticons'];
  63. // Save a user's oauth details to a MySQL table
  64. if (MYSQL_USERS == 'ON' && $newpass = $_POST['newpassword']) {
  65. user_is_authenticated();
  66. list($key, $secret) = explode('|', $GLOBALS['user']['password']);
  67. $sql = sprintf("REPLACE INTO user (username, oauth_key, oauth_secret, password) VALUES ('%s', '%s', '%s', MD5('%s'))", mysql_escape_string(user_current_username()), mysql_escape_string($key), mysql_escape_string($secret), mysql_escape_string($newpass));
  68. mysql_query($sql);
  69. }
  70. setcookie_year('settings', base64_encode(serialize($settings)));
  71. twitter_refresh('');
  72. }
  73. $modes = array(
  74. 'mobile' => 'Normal phone',
  75. 'touch' => 'Touch Screen',
  76. 'bigtouch' => 'Touch Screen Big Icons',
  77. 'desktop' => 'PC/Laptop',
  78. 'text' => 'Text only',
  79. 'worksafe' => 'Work Safe',
  80. );
  81. $perPage = array(
  82. '5' => '5 Tweets Per Page',
  83. '10' => '10 Tweets Per Page',
  84. '20' => '20 Tweets Per Page',
  85. '30' => '30 Tweets Per Page',
  86. '40' => '40 Tweets Per Page',
  87. '50' => '50 Tweets Per Page',
  88. '100' => '100 Tweets Per Page',
  89. '150' => '150 Tweets Per Page',
  90. '200' => '200 Tweets Per Page',
  91. );
  92. $gwt = array(
  93. 'off' => 'direct',
  94. 'on' => 'via GWT',
  95. );
  96. $emoticons = array(
  97. 'on' => 'ON',
  98. 'off' => 'OFF',
  99. );
  100. $colour_schemes = array();
  101. foreach ($GLOBALS['colour_schemes'] as $id => $info) {
  102. list($name, $colours) = explode('|', $info);
  103. $colour_schemes[$id] = $name;
  104. }
  105. $utc_offset = setting_fetch('utc_offset', 0);
  106. /* returning 401 as it calls http://api.twitter.com/1/users/show.json?screen_name= (no username???)
  107. if (!$utc_offset) {
  108. $user = twitter_user_info();
  109. $utc_offset = $user->utc_offset;
  110. }
  111. */
  112. if ($utc_offset > 0) {
  113. $utc_offset = '+' . $utc_offset;
  114. }
  115. $content .= '<form action="settings/save" method="post"><p>Colour scheme:<br /><select name="colours">';
  116. $content .= theme('options', $colour_schemes, setting_fetch('colours', 0));
  117. $content .= '</select></p><p>Mode:<br /><select name="browser">';
  118. $content .= theme('options', $modes, $GLOBALS['current_theme']);
  119. $content .= '</select>';
  120. $content .= '<p>Tweets Per Page:<br /><select name="perPage">';
  121. $content .= theme('options', $perPage, setting_fetch('perPage', 20));
  122. $content .= '</select>';
  123. $content .= '<br/></p><p>Emoticons - show :-) as images<br /><select name="emoticons">';
  124. $content .= theme('options', $emoticons, setting_fetch('emoticons', $GLOBALS['current_theme'] == 'text' ? 'on' : 'off'));
  125. $content .= '</select></p><p>External links go:<br /><select name="gwt">';
  126. $content .= theme('options', $gwt, setting_fetch('gwt', $GLOBALS['current_theme'] == 'text' ? 'on' : 'off'));
  127. $content .= '</select><small><br />Google Web Transcoder (GWT) converts third-party sites into small, speedy pages suitable for older phones and people with less bandwidth.</small></p>';
  128. $content .= '<p><label><input type="checkbox" name="reverse" value="yes" '. (setting_fetch('reverse') == 'yes' ? ' checked="checked" ' : '') .' /> Attempt to reverse the conversation thread view.</label></p>';
  129. $content .= '<p><label><input type="checkbox" name="timestamp" value="yes" '. (setting_fetch('timestamp') == 'yes' ? ' checked="checked" ' : '') .' /> Show the timestamp ' . twitter_date('H:i') . ' instead of 25 sec ago</label></p>';
  130. $content .= '<p><label><input type="checkbox" name="hide_inline" value="yes" '. (setting_fetch('hide_inline') == 'yes' ? ' checked="checked" ' : '') .' /> Hide inline media (eg TwitPic thumbnails)</label></p>';
  131. $content .= '<p><label>The time in UTC is currently ' . gmdate('H:i') . ', by using an offset of <input type="text" name="utc_offset" value="'. $utc_offset .'" size="3" /> we display the time as ' . twitter_date('H:i') . '.<br />It is worth adjusting this value if the time appears to be wrong.</label></p>';
  132. // Allow users to choose a Dabr password if accounts are enabled
  133. if (MYSQL_USERS == 'ON' && user_is_authenticated()) {
  134. $content .= '<fieldset><legend>Dabr account</legend><small>If you want to sign in to Dabr without going via Twitter.com in the future, create a password and we\'ll remember you.</small></p><p>Change Dabr password<br /><input type="password" name="newpassword" /><br /><small>Leave blank if you don\'t want to change it</small></fieldset>';
  135. }
  136. $content .= '<p><input type="submit" value="Save" /></p></form>';
  137. $content .= '<hr /><p>Visit <a href="reset">Reset</a> if things go horribly wrong - it will log you out and clear all settings.</p>';
  138. return theme('page', 'Settings', $content);
  139. }