PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/core/core.php

http://snowcms.googlecode.com/
PHP | 246 lines | 156 code | 19 blank | 71 comment | 21 complexity | 7976598d0568c7242c4a9fbddd118403 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////
  3. // SnowCMS v2.0 //
  4. // By the SnowCMS Team //
  5. // www.snowcms.com //
  6. // Released under the Microsoft Reciprocal License //
  7. // www.opensource.org/licenses/ms-rl.html //
  8. ////////////////////////////////////////////////////////////////////////////
  9. // //
  10. // SnowCMS originally pawned by soren121 started in early 2008 //
  11. // //
  12. ////////////////////////////////////////////////////////////////////////////
  13. // //
  14. // SnowCMS v2.0 began in November 2009 //
  15. // //
  16. ////////////////////////////////////////////////////////////////////////////
  17. // File version: SnowCMS 2.0 //
  18. ////////////////////////////////////////////////////////////////////////////
  19. if(!defined('INSNOW'))
  20. {
  21. die('Nice try...');
  22. }
  23. /*
  24. Title: Core actions
  25. Function: init_core
  26. Registers actions which are default "features", such as logging in/out,
  27. registration, and other such operations. Plus a couple other things ;)
  28. Parameters:
  29. none
  30. Returns:
  31. void - Nothing is returned by this function.
  32. Note:
  33. All the actions registered in this function can be overloaded, simply
  34. by registering the actions before init_core is called, but also, all
  35. the functions which are used are overloadable as well.
  36. */
  37. function init_core()
  38. {
  39. // We have a couple default actions of our own :) (Remember, you can
  40. // register these actions before they are registered here! :) But also
  41. //all these functions are overloadable, so simply define them before
  42. // this too!!!).
  43. reset($_GET);
  44. // Why don't we speed up this process a bit? Sounds like a good idea, no?
  45. if(key($_GET) == 'action')
  46. {
  47. // I mean, we don't need to load all of these if we don't need to, right?
  48. if(current($_GET) == 'activate')
  49. {
  50. api()->add_event('action=activate', 'activate_view', coredir. '/activate.php');
  51. }
  52. elseif(current($_GET) == 'admin')
  53. {
  54. api()->add_event('action=admin', 'admin_home', coredir. '/admin/admin_home.php');
  55. api()->add_event('action=admin&sa=about', 'admin_about', coredir. '/admin/admin_home.php');
  56. api()->add_event('action=admin&sa=update&apply=*', 'admin_update_apply', coredir. '/admin/admin_update.php');
  57. api()->add_event('action=admin&sa=error_log', 'admin_error_log', coredir. '/admin/admin_error_log.php');
  58. api()->add_event('action=admin&sa=error_log&id=*', 'admin_error_log_view', coredir. '/admin/admin_error_log.php');
  59. api()->add_event('action=admin&sa=members_add', 'admin_members_add', coredir. '/admin/admin_members_add.php');
  60. api()->add_event('action=admin&sa=members_manage', 'admin_members_manage', coredir. '/admin/admin_members_manage.php');
  61. api()->add_event('action=admin&sa=members_permissions', 'admin_members_manage_permissions', coredir. '/admin/admin_members_permissions.php');
  62. api()->add_event('action=admin&sa=members_permissions&grp=*', 'admin_members_manage_group_permissions', coredir. '/admin/admin_members_permissions.php');
  63. api()->add_event('action=admin&sa=members_settings', 'admin_members_settings', coredir. '/admin/admin_members_settings.php');
  64. api()->add_event('action=admin&sa=plugins_add', 'admin_plugins_add', coredir. '/admin/admin_plugins_add.php');
  65. api()->add_event('action=admin&sa=plugins_add&install=*', 'admin_plugins_install', coredir. '/admin/admin_plugins_add.php');
  66. api()->add_event('action=admin&sa=plugins_manage', 'admin_plugins_manage', coredir. '/admin/admin_plugins_manage.php');
  67. api()->add_event('action=admin&sa=plugins_manage&update=*', 'admin_plugins_update', coredir. '/admin/admin_plugins_manage.php');
  68. api()->add_event('action=admin&sa=plugins_settings', 'admin_plugins_settings', coredir. '/admin/admin_plugins_settings.php');
  69. api()->add_event('action=admin&sa=settings', 'admin_settings', coredir. '/admin/admin_settings.php');
  70. api()->add_event('action=admin&sa=themes&section=manage', 'admin_themes_manage', coredir. '/admin/admin_themes_manage.php');
  71. api()->add_event('action=admin&sa=themes&section=install', 'admin_themes_install', coredir. '/admin/admin_themes_install.php');
  72. api()->add_event('action=admin&sa=themes&section=widgets', 'admin_themes_widgets', coredir. '/admin/admin_themes_widgets.php');
  73. api()->add_event('action=admin&sa=themes&install=*', 'admin_themes_perform_install', coredir. '/admin/admin_themes_install.php');
  74. api()->add_event('action=admin&sa=themes&update=*', 'admin_themes_update', coredir. '/admin/admin_themes_manage.php');
  75. api()->add_event('action=admin&sa=update', 'admin_update', coredir. '/admin/admin_update.php');
  76. // Yup, we will want to call on the admin_prepend function.
  77. $start_admin_prepend = true;
  78. }
  79. elseif(current($_GET) == 'checkcookie')
  80. {
  81. api()->add_event('action=checkcookie', 'checkcookie_verify', coredir. '/checkcookie.php');
  82. }
  83. elseif(substr(current($_GET), 0, 3) == 'log')
  84. {
  85. api()->add_event('action=login', 'login_view', coredir. '/login.php');
  86. api()->add_event('action=login2', 'login_view2', coredir. '/login.php');
  87. api()->add_event('action=logout', 'logout_process', coredir. '/logout.php');
  88. }
  89. elseif(current($_GET) == 'profile')
  90. {
  91. api()->add_event('action=profile', 'profile_view', coredir. '/profile.php');
  92. api()->add_event('action=profile&id=*', 'profile_view', coredir. '/profile.php');
  93. }
  94. elseif(substr(current($_GET), 0, 2) == 're')
  95. {
  96. api()->add_event('action=register', 'register_view', coredir. '/register.php');
  97. api()->add_event('action=register2', 'register_process', coredir. '/register.php');
  98. api()->add_event('action=resend', 'resend_view', coredir. '/resend.php');
  99. api()->add_event('action=resource', 'api_handle_resource');
  100. }
  101. elseif(substr(current($_GET), 0, 6) == 'forgot')
  102. {
  103. api()->add_event('action=forgotpw', 'forgotpw_view', coredir. '/forgotpw.php');
  104. api()->add_event('action=forgotpw2', 'forgotpw_view2', coredir. '/forgotpw.php');
  105. }
  106. elseif(current($_GET) == 'tasks')
  107. {
  108. api()->add_event('action=tasks', 'tasks_run', coredir. '/tasks.class.php');
  109. }
  110. elseif(current($_GET) == 'popup')
  111. {
  112. api()->add_event('action=popup', 'core_popup');
  113. }
  114. elseif(current($_GET) == 'verify')
  115. {
  116. api()->add_event('action=verify', 'verify_email', coredir. '/verify.php');
  117. }
  118. }
  119. // Stop output buffering which was started in the <load_api> function.
  120. ob_end_clean();
  121. // Start output buffering.
  122. ob_start(api()->apply_filters('output_callback', null));
  123. // Do we need to load up admin_prepend?
  124. if(!empty($start_admin_prepend))
  125. {
  126. require_once(coredir. '/admin.php');
  127. admin_prepend();
  128. }
  129. api()->add_menu_category('main', 'Main Menu');
  130. // Let's add a few default links to allow some basic navigation throughout
  131. // the website.
  132. api()->add_menu_item('main', array(
  133. 'href' => baseurl(),
  134. 'content' => l('Home'),
  135. ));
  136. // We won't need to show logged in members links to registering, now do
  137. // we?
  138. if(member()->is_guest())
  139. {
  140. api()->add_menu_item('main', array(
  141. 'href' => baseurl('index.php?action=register'),
  142. 'content' => l('Register'),
  143. ));
  144. api()->add_menu_item('main', array(
  145. 'href' => baseurl('index.php?action=login'),
  146. 'content' => l('Log In'),
  147. ));
  148. }
  149. else
  150. {
  151. api()->add_menu_item('main', array(
  152. 'href' => baseurl('index.php?action=profile'),
  153. 'content' => l('My Profile'),
  154. ));
  155. if(member()->can('access_admin_cp'))
  156. {
  157. api()->add_menu_item('main', array(
  158. 'href' => baseurl('index.php?action=admin'),
  159. 'content' => l('Control Panel'),
  160. ));
  161. }
  162. api()->add_menu_item('main', array(
  163. 'href' => baseurl('index.php?action=logout&amp;sc='. member()->session_id()),
  164. 'content' => l('Log Out'),
  165. ));
  166. }
  167. }
  168. if(!function_exists('core_popup'))
  169. {
  170. /*
  171. Function: core_popup
  172. Displays the popup dialog content of the specified popup.
  173. Parameters:
  174. none
  175. Returns:
  176. void - Nothing is returned by this function.
  177. Note:
  178. To make a popup, simply apply a filter to popup_{ID_HERE}, for
  179. example if the popup identifier is timeformat, apply a filter to
  180. popup_timeformat. Be sure that if the popup information should only
  181. be available to a certain member group, check using the
  182. <Member::is_a> method before applying the filter.
  183. */
  184. function core_popup()
  185. {
  186. global $func;
  187. if(empty($_GET['id']))
  188. {
  189. die(l('No popup identifier supplied.'));
  190. }
  191. // Collect the popup information.
  192. $popup = api()->apply_filters('popup_'. $_GET['id'], array(
  193. 'title' => false,
  194. 'content' => false,
  195. ));
  196. // We need title and content for the popup.
  197. if(empty($popup['title']) || empty($popup['content']))
  198. {
  199. die(l('Invalid popup identifier'));
  200. }
  201. // Now simply output the popup.
  202. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  203. <html xmlns="http://www.w3.org/1999/xhtml">
  204. <head>
  205. <title>', $func['htmlspecialchars']($popup['title']), '</title>
  206. <style type="text/css">
  207. ', api()->apply_filters('core_popup_css', 'body { background: #FFFFFF; font-family: Tahoma, Arial, sans-serif; font-size: 90%; }
  208. h1 { font-size: 115%; color: #3465A7; margin-top: 15px; }'), '
  209. </style>
  210. </head>
  211. <body>
  212. <h1>', $func['htmlspecialchars']($popup['title']), '</h1>
  213. ', $popup['content'], '
  214. </body>
  215. </html>';
  216. }
  217. }
  218. ?>