A QCodo powered CMS
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.

235 lines
7.5 KiB

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