A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
9.6 KiB

13 years ago
  1. <?php
  2. if (!defined("QUASI.CLASS.PHP")){
  3. define("QUASI.CLASS.PHP",1);
  4. /**
  5. * Include Quasi configurations - this assumes that this config file is in the same directory, you
  6. * can adjust this here if you prefer to put either somewhere else.
  7. */
  8. require(dirname(__FILE__) . '/quasi_config.php');
  9. /**
  10. * Include QApplication, which will in turn pull in the QCodo framework and configuration
  11. */
  12. require(__QCODO_ROOT__ . '/includes/prepend.inc.php');
  13. /**
  14. * Define the autoloader for PHP here
  15. * NOTE: This overrides the QApplication definition, for this to work you must
  16. * put a define guard in qcodo.inc.php like this:
  17. *
  18. * if (!defined("QUASICMS")){
  19. * function __autoload($strClassName) {
  20. * QApplication::Autoload($strClassName);
  21. * }
  22. * }
  23. *
  24. * The Quasi autoloader looks in Quasi directories and then calls the QApplication autoloader.
  25. */
  26. function __autoload($strClassName) {
  27. Quasi::Autoload($strClassName);
  28. }
  29. /**
  30. * The Quasi class is an abstract class that statically provides global
  31. * information and global utilities for the entire CMS application. Since
  32. * it inherits QApplication, it also provides the connection to the QCodo
  33. * framework.
  34. *
  35. * Custom constants for Quasi CMS, as well as global variables and global
  36. * methods are declared statically here. Additional initializations for the CMS
  37. * should also be here - but remember, QApplication has already been initialized
  38. * in prepend.inc.php so do not use parent::
  39. *
  40. * This may also be used to override QApplication (eg. for BrowserType ..)
  41. *
  42. *@todo move things from IndexPage to here ..
  43. *@
  44. *@package Quasi
  45. * @subpackage Classes
  46. */
  47. abstract class Quasi extends QApplication
  48. {
  49. /**
  50. * @var string IsSsl true if $_SERVER['HTTPS'] is set, indicating the request was secure
  51. */
  52. public static $IsSsl = false;
  53. /**
  54. * @var string ServerName contains $_SERVER['SERVER_NAME']
  55. */
  56. public static $ServerName;
  57. /**
  58. * @var string ServerPort contains $_SERVER['SERVER_PORT'], the port webserver listens on
  59. */
  60. public static $ServerPort;
  61. /**
  62. * @var array QuasiClasses - a map array of classes to filenames used by the autoloader.
  63. */
  64. public static $QuasiClasses = array();
  65. /**
  66. * @var array QuasiIncludePaths - a map array of paths to be searched by the autoloader.
  67. */
  68. public static $QuasiIncludePaths = array(
  69. __QUASI_LOCAL_CLASSES__,
  70. __QUASI_LOCAL_MODULES__,
  71. __QUASI_LOCAL_ORM__,
  72. __QUASI_LOCAL_METAORM__,
  73. __QUASI_CONTRIB_CLASSES__,
  74. __QUASI_CONTRIB_MODULES__,
  75. __QUASI_CONTRIB_ORM__,
  76. __QUASI_CONTRIB_METAORM__,
  77. __QUASI_CORE_CLASSES__,
  78. __QUASI_CORE_MODULES__,
  79. __QUASI_CORE_ORM__,
  80. __QUASI_CORE_METAORM__,
  81. );
  82. public static $SupportEmailLink;
  83. /**
  84. * Initialize Quasi data, setting autoloader data, servername and other misc ..
  85. */
  86. public static function Init()
  87. {
  88. // set the Form state handler to use SESSION ..
  89. QForm::$FormStateHandler = 'QSessionFormStateHandler';
  90. Quasi::$ServerName = $_SERVER['SERVER_NAME'];
  91. Quasi::$ServerPort = $_SERVER['SERVER_PORT'];
  92. Quasi::$SupportEmailLink = ' <a href="mailto:' . STORE_EMAIL_ADDRESS . '">' . STORE_EMAIL_ADDRESS . '</a> ';
  93. $strSsl = array_key_exists( 'HTTPS', $_SERVER) ? $_SERVER['HTTPS'] : '';
  94. if(!empty($strSsl))
  95. Quasi::$IsSsl = true;
  96. ///@todo make me international ..
  97. setlocale(LC_MONETARY, 'en_US');
  98. //load an array of filenames for quick autoloading
  99. foreach( self::$QuasiIncludePaths as $strPath)
  100. {
  101. if (is_dir($strPath))
  102. {
  103. if ($dh = opendir($strPath))
  104. {
  105. while (($strFileName = readdir($dh)) !== false)
  106. {
  107. $pos = strrpos( $strFileName, '.class.php' );
  108. if(false === $pos || true == strpos( $strFileName , '~' ) )
  109. continue;
  110. $strClassName = substr( $strFileName, 0, $pos );
  111. if( ! array_key_exists(strtolower($strClassName), self::$QuasiClasses) )
  112. self::$QuasiClasses[strtolower($strClassName)] = $strPath . '/' . $strFileName;
  113. }
  114. closedir($dh);
  115. }
  116. }
  117. }
  118. }
  119. /**
  120. * This is called by the PHP5 Autoloader. This method overrides the
  121. * one in QApplication - if Quasi fails to load the class, we attempt
  122. * to load it from QApplication classes here
  123. * @return void
  124. */
  125. public static function Autoload($strClassName)
  126. {
  127. //some Qcodo generated QQ classes go in the same file as the ORM class ..
  128. $aryQcodoPrefixes = array(
  129. 'QQNode',
  130. );
  131. //work around for QCodo classes in same file ..
  132. foreach($aryQcodoPrefixes as $strPrefix)
  133. if( false !== strpos( $strClassName, $strPrefix ) )
  134. $strClassName = substr( $strClassName, strlen( $strPrefix ) );
  135. // first check Quasi directories ..
  136. if(array_key_exists(strtolower($strClassName), Quasi::$QuasiClasses) )
  137. {
  138. require_once(Quasi::$QuasiClasses[strtolower($strClassName)]);
  139. return true;
  140. }
  141. // Otherwise use the Qcodo Autoloader
  142. if (parent::Autoload($strClassName))
  143. return true;
  144. return false;
  145. }
  146. /**
  147. * This will redirect the user to a new web location. This can be a relative or absolute web path, or it
  148. * can be an entire URL. This overrides the QApplication::Redirect to work for offsite redirects and to
  149. * support browsers like Opera and Safari that do not accept document.location assigns.
  150. *
  151. * - any string starting with / is assumed to be local.
  152. * - any string with http:// or https:// is assumed to be offsite.
  153. *
  154. *@todo - support SEO friendly URLS .. and ssl (buggy, needs time ..)
  155. *
  156. *@param string strLocation - the URL to which the user is redirected
  157. * @return void
  158. */
  159. public static function Redirect($strLocation, $blnUseSsl=false)
  160. {
  161. ob_clean();
  162. $strProtocol = '';
  163. if($blnUseSsl)
  164. $strProtocol = 'https://';
  165. else
  166. $strProtocol = 'http://';
  167. if( false !== strpos( $strLocation, 'http://' ) || false !== strpos( $strLocation, 'https://' ) )
  168. {
  169. /* candidate:
  170. if (!headers_sent())
  171. {
  172. header('Location: '. $strLocation );
  173. } else {
  174. $strOutPut = '<script type="text/javascript">window.location.href="'. $strLocation . '";</script>';
  175. $strOutPut .= '<noscript><meta http-equiv="refresh" content="0;url=' . $strLocation . '" /></noscript>';
  176. _p($strOutPut);
  177. exit;
  178. }
  179. */
  180. ob_clean();
  181. header('Location: ' . $strLocation);
  182. if( Quasi::IsBrowser(QBrowserType::InternetExplorer ) )
  183. header('Connection: close');
  184. }//these two do not support document.location redirects ..??
  185. elseif( Quasi::IsBrowser( QBrowserType::Opera) || Quasi::IsBrowser( QBrowserType::Safari) )
  186. {
  187. ob_clean();
  188. // header('Location: ' . $strProtocol . Quasi::$ServerName . $strLocation);
  189. header('Location: ' . $strLocation);
  190. }
  191. else
  192. parent::Redirect($strLocation);
  193. exit;
  194. }
  195. /**
  196. * Quasi access control
  197. * Note: this is only a sketch of an idea, in the event of a real access control you will be notified ..
  198. * ie. THIS DOES NOTHING YET. And it will definitely change.
  199. *@todo implement access control
  200. */
  201. public static function CheckAccess($aryAllowGroups)
  202. {
  203. if(sizeof($aryAllowGroups) == 0)
  204. return true;
  205. $blnLoggedIn = false;
  206. $objAccount = null;
  207. $objPerson = null;
  208. $aryUsergroups = array();
  209. $blnAllow = false;
  210. if( isset($_SESSION) && isset($_SESSION['AccountLogin']) )
  211. {
  212. $objAccount = unserialize($_SESSION['AccountLogin']);
  213. if( $objAccount instanceof Account )
  214. {
  215. $blnLoggedIn = true;
  216. $objPerson = $objAccount->Person;
  217. }
  218. }
  219. if($blnLoggedIn && $objPerson)
  220. $aryUsergroups = $objPerson->GetUsergroupArray();
  221. foreach( $aryUsergroups as $objGroup )
  222. if(in_array($aryAllowGroups, $objGroup->Name ))
  223. $blnAllow = true;
  224. return $blnAllow;
  225. }
  226. }//end class
  227. //now initialize Quasi data
  228. Quasi::Init();
  229. }//end define
  230. ?>