/** * @param string $sConfigVar Specify the variable in the INI file where module options. Default module.setting * @param string $sConfigPath Specify the path of INI file configuration WITHOUT "config.ini". The default value is the current configuration file module. Default NULL * @return void */ public static function display($sConfigVar = 'module.setting', $sConfigPath = null) { $sConfigFile = 'config.ini'; $sIniFile = empty($sConfigPath) ? Registry::getInstance()->path_module_config . $sConfigFile : $sConfigPath . $sConfigFile; $aData = parse_ini_file($sIniFile, true); $rData = file_get_contents($sIniFile); if (isset($_POST['submit_config'])) { if (\PFBC\Form::isValid($_POST['submit_config'])) { new ConfigFileCoreFormProcess($sConfigVar, $sIniFile); } Framework\Url\Header::redirect(); } $oForm = new \PFBC\Form('form_config', 600); $oForm->configure(array('action' => '')); $oForm->addElement(new \PFBC\Element\Hidden('submit_config', 'form_config')); $oForm->addElement(new \PFBC\Element\Token('config')); foreach ($aData[$sConfigVar] as $sKey => $sVal) { $sLabel = str_replace(array('.', '_'), ' ', $sKey); $sLabel = (new Str())->upperFirstWords($sLabel); if (false !== strpos($sKey, 'enable')) { $oForm->addElement(new \PFBC\Element\Select($sLabel, 'config[' . $sKey . ']', array(1 => t('Enable'), 0 => t('Disable')), array('value' => $sVal))); } elseif (false !== strpos($sKey, 'email')) { $oForm->addElement(new \PFBC\Element\Email($sLabel, 'config[' . $sKey . ']', array('value' => $sVal))); } elseif (ctype_digit($sVal)) { $oForm->addElement(new \PFBC\Element\Number($sLabel, 'config[' . $sKey . ']', array('step' => 'any', 'value' => $sVal))); } else { $oForm->addElement(new \PFBC\Element\Textbox($sLabel, 'config[' . $sKey . ']', array('value' => $sVal))); } } $oForm->addElement(new \PFBC\Element\Button()); $oForm->render(); }
/** * Gets Ads with ORDER BY RAND() SQL aggregate function. * With caching, advertising changes every hour. * * @param integer $iWidth * @param integer $iHeight * @param boolean $bOnlyActive Default TRUE * @return object Query */ public function ad($iWidth, $iHeight, $bOnlyActive = true) { if (!PH7_VALID_LICENSE) { return false; } $this->_oCache->start(self::CACHE_STATIC_GROUP, 'ads' . $iWidth . $iHeight . $bOnlyActive, static::CACHE_TIME); if (!($oData = $this->_oCache->get())) { $sSqlActive = $bOnlyActive ? ' AND (active=\'1\') ' : ' '; $rStmt = Db::getInstance()->prepare('SELECT * FROM ' . Db::prefix('Ads') . 'WHERE (width=:width) AND (height=:height)' . $sSqlActive . 'ORDER BY RAND() LIMIT 1'); $rStmt->bindValue(':width', $iWidth, \PDO::PARAM_INT); $rStmt->bindValue(':height', $iHeight, \PDO::PARAM_INT); $rStmt->execute(); $oData = $rStmt->fetch(\PDO::FETCH_OBJ); Db::free($rStmt); $this->_oCache->put($oData); } /** * Don't display ads on the admin panel. */ if (!(Registry::getInstance()->module === PH7_ADMIN_MOD) && $oData) { echo '<div class="inline" onclick="$(\'#ad_' . $oData->adsId . '\').attr(\'src\',\'' . PH7_URL_ROOT . '?' . \PH7\Framework\Ads\Ads::PARAM_URL . '=' . $oData->adsId . '\');return true;">'; echo \PH7\Framework\Ads\Ads::output($oData); echo '<img src="' . PH7_URL_STATIC . PH7_IMG . 'useful/blank.gif" style="border:0;width:0px;height:0px;" alt="" id="ad_' . $oData->adsId . '" /></div>'; } unset($oData); }
/** * Parser for the System variables. * * @param string $sVar * @return The new parsed text */ public function parse($sVar) { /*** Not to parse a text ***/ if (preg_match('/#!.+!#/', $sVar)) { $sVar = str_replace(array('#!', '!#'), '', $sVar); return $sVar; } /***** Site Variables *****/ $oRegistry = Registry::getInstance(); $sVar = str_replace('%site_name%', $oRegistry->site_name, $sVar); $sVar = str_replace('%url_relative%', PH7_RELATIVE, $sVar); $sVar = str_replace(array('%site_url%', '%url_root%'), $oRegistry->site_url, $sVar); $sVar = str_replace('%url_static%', PH7_URL_STATIC, $sVar); $sVar = str_replace('%page_ext%', PH7_PAGE_EXT, $sVar); unset($oRegistry); /***** Affiliate Variables *****/ $oSession = new Session(); $sAffUsername = $oSession->exists('affiliate_username') ? $oSession->get('affiliate_username') : 'aid'; $sVar = str_replace('%affiliate_url%', Uri::get('affiliate', 'router', 'refer', $sAffUsername), $sVar); unset($oSession); /***** Global Variables *****/ $sVar = str_replace('%ip%', Ip::get(), $sVar); /***** Kernel Variables *****/ $sVar = str_replace('%software_name%', Kernel::SOFTWARE_NAME, $sVar); $sVar = str_replace('%software_company%', Kernel::SOFTWARE_COMPANY, $sVar); $sVar = str_replace('%software_author%', 'Pierre-Henry Soria', $sVar); $sVar = str_replace('%software_version_name%', Kernel::SOFTWARE_VERSION_NAME, $sVar); $sVar = str_replace('%software_version%', Kernel::SOFTWARE_VERSION, $sVar); $sVar = str_replace('%software_build%', Kernel::SOFTWARE_BUILD, $sVar); $sVar = str_replace('%software_email%', Kernel::SOFTWARE_EMAIL, $sVar); $sVar = str_replace('%software_website%', Kernel::SOFTWARE_WEBSITE, $sVar); // Output return $sVar; }
public static function display() { $oUserModel = new UserCoreModel(); $iProfileId = (int) (new Session())->get('member_id'); if (isset($_POST['submit_privacy_account'])) { if (\PFBC\Form::isValid($_POST['submit_privacy_account'])) { new PrivacyFormProcess($iProfileId, $oUserModel); } Framework\Url\Header::redirect(); } $oPrivacy = $oUserModel->getPrivacySetting($iProfileId); $oForm = new \PFBC\Form('form_privacy_account', 500); $oForm->configure(array('action' => '')); $oForm->addElement(new \PFBC\Element\Hidden('submit_privacy_account', 'form_privacy_account')); $oForm->addElement(new \PFBC\Element\Token('privacy_account')); $oForm->addElement(new \PFBC\Element\HTMLExternal('<h3><u>' . t('Profile:') . '</u></h3>')); $oForm->addElement(new \PFBC\Element\Radio(t('Who can view your profile?'), 'privacy_profile', array('all' => t('Everyone (including people who are not %0% members).', Registry::getInstance()->site_name), 'only_members' => t('Only %0% members who are logged in.', Registry::getInstance()->site_name), 'only_me' => t('Only me.')), array('value' => $oPrivacy->privacyProfile, 'required' => 1))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<h3><u>' . t('Web search engine:') . '</u></h3>')); $oForm->addElement(new \PFBC\Element\Radio(t('Do you want to be included in search results?'), 'search_profile', array('yes' => t("Yes, include my profile in search results (%site_name%'s search, Google, Bing, Yahoo, etc.)."), 'no' => t('No, do not include my profile in search results.')), array('value' => $oPrivacy->searchProfile, 'required' => 1))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<h3><u>' . t('Show profile visitors:') . '</u></h3>')); $oForm->addElement(new \PFBC\Element\Radio(t('Do you want display members who viewed your profile?'), 'user_save_views', array('yes' => t('Yes, display members who viewed my profile (Selecting this option will allow other members to see that you visited their profile).'), 'no' => t('No, don\'t display members who viewed my profile. (Selecting this option will prevent you from seeing who visited your profile).')), array('value' => $oPrivacy->userSaveViews, 'required' => 1))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<h3><u>' . t('Presence:') . '</u></h3>')); $oForm->addElement(new \PFBC\Element\Select(t('Your status'), 'user_status', array('1' => t('Online'), '2' => t('Busy'), '3' => t('Away'), '0' => 'Offline'), array('id' => 'status', 'onchange' => 'init_status()', 'value' => $oUserModel->getUserStatus($iProfileId), 'required' => 1))); $oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="user_status right" id="status_div"></div>')); $oForm->addElement(new \PFBC\Element\HTMLExternal('<script>$(function(){ init_status() });</script>')); $oForm->addElement(new \PFBC\Element\Button()); $oForm->render(); }
/** * Sub Header HTML with the site logo. * * @return string HTML Contents. */ public function subHeader() { /** * @internal Because we sometimes work with this class in Ajax (e.g. FriendAjax.php of the User Module), the constant "PH7_TPL_NAME" is not yet defined. * So we use the constant "PH7_DEFAULT_THEME" is already defined. */ return '<table> <tr><td> <div id="sub_container"> <h1 class="logo"><a href="' . Registry::getInstance()->site_url . '">' . Registry::getInstance()->site_name . '</a></h1>'; }
public function __construct() { $this->config = Config::getInstance(); $this->str = new Str(); $this->file = new File(); $this->httpRequest = new Http(); $this->browser = new Browser(); $this->registry = Registry::getInstance(); /** * @internal The "_checkLicense" method cannot be declare more than one time. The "Kernel.class.php" file is included many times in the software, so we need to check that with a constant. */ if (!defined('PH7_CHECKED_LIC')) { define('PH7_CHECKED_LIC', 1); // OK, now we have checked the license key $this->_checkLicense(); } //** Temporary code. In the near future, pH7CMS will be usable without mod_rewrite if (!Server::isRewriteMod()) { $sModRewriteMsg = t('<span style="font-weight:bold;color:red"><a href="%0%">pH7CMS</a> requires Apache "mod_rewrite".</span><br /> Please install it so that pH7CMS can works.<br /> Click <a href="%1%" target="_blank">here</a> if you want to get more information on how to install the rewrite module.<br /><br /> After doing this, please <a href="%2%">retry</a>.', self::SOFTWARE_WEBSITE, 'http://software.hizup.com/doc/en/how-to-install-rewrite-module', PH7_URL_ROOT); Page::message($sModRewriteMsg); } //*/ }
/** * Autoload Forms. * * @param string $sClass * @return void */ private function _loadForm($sClass) { $sClass = $this->_removeNamespace($sClass); // For the Core Forms if (is_file(PH7_PATH_SYS . 'core/' . PH7_FORMS . $sClass . '.php')) { require_once PH7_PATH_SYS . 'core/' . PH7_FORMS . $sClass . '.php'; } if (is_file(PH7_PATH_SYS . 'core/' . PH7_FORMS . 'processing/' . $sClass . '.php')) { require_once PH7_PATH_SYS . 'core/' . PH7_FORMS . 'processing/' . $sClass . '.php'; } // For the Forms of the modules if (is_file(Registry::getInstance()->path_module_forms . $sClass . '.php')) { require_once Registry::getInstance()->path_module_forms . $sClass . '.php'; } if (is_file(Registry::getInstance()->path_module_forms . 'processing/' . $sClass . '.php')) { require_once Registry::getInstance()->path_module_forms . 'processing/' . $sClass . '.php'; } }
//*/ // Enable client browser cache (new Browser())->cache(); // Starting zlib-compressed output /* This "zlib output compression" compressthe pages. This allows you to save your bandwidth and faster download of your pages. WARNING: this function consumes CPU resources on your server. So you can if you want to remove this function. */ //ini_set('zlib.output_compression', 2048); //ini_set('zlib.output_compression_level', 6); ob_start(); new Server(); // Start Server Registry::getInstance()->start_time = microtime(true); /** * Initialize the FrontController, we are asking the front controller to process the HTTP request */ FrontController::getInstance()->runRouter(); } catch (Except\UserException $oE) { echo $oE->getMessage(); // Simple User Error with Exception } catch (Except\PH7Exception $oE) { Except\PH7Exception::launch($oE); } catch (\Exception $oE) { Except\PH7Exception::launch($oE); } finally { if ('' !== session_id()) { session_write_close(); }
/** * For download file. * * @param string $sFile file in download. * @param string $sName if file in download. * @param string $sMimeType Optional, default value is NULL. * @return void */ public function download($sFile, $sName, $sMimeType = null) { /* This function takes a path to a file to output ($sFile), the filename that the browser will see ($sName) and the MIME type of the file ($sMimeType, optional). If you want to do something on download abort/finish, register_shutdown_function('function_name'); */ //if (!is_readable($sFile)) exit('File not found or inaccessible!'); $sName = \PH7\Framework\Url\Url::decode($sName); // Clean the name file /* Figure out the MIME type (if not specified) */ if (empty($sMimeType)) { $sFileExtension = $this->getFileExt($sFile); $mGetMimeType = $this->getMimeType($sFileExtension); if (!empty($mGetMimeType)) { $sMimeType = $mGetMimeType; } else { $sMimeType = 'application/force-download'; } } @ob_end_clean(); // Turn off output buffering to decrease CPU usage (new \PH7\Framework\Navigation\Browser())->nocache(); // No cache $sPrefix = \PH7\Framework\Registry\Registry::getInstance()->site_name . '_'; // the prefix header('Content-Type: ' . $sMimeType); header('Content-Disposition: attachment; filename=' . \PH7\Framework\Parse\Url::clean($sPrefix) . $sName); header('Content-Transfer-Encoding: binary'); header('Accept-Ranges: bytes'); header('Content-Length: ' . $this->size($sFile)); readfile($sFile); }
/** * Load the language file. * * @param string $sFileName The language path. * @param string $sPath If you want to change the default path (the path to the current module), you can specify the path. Default NULL * @return void */ public function load($sFileName, $sPath = null) { textdomain($sFileName); bindtextdomain($sFileName, empty($sPath) ? \PH7\Framework\Registry\Registry::getInstance()->path_module_lang : $sPath); bind_textdomain_codeset($sFileName, PH7_ENCODING); }
/** * @return string The name of the current controller. */ public function currentController() { return str_replace('controller', '', strtolower(\PH7\Framework\Registry\Registry::getInstance()->controller)); }
/** * Generate a Report Link. * * @param integer $iId * @param string $sUsername * @param string $sFirstName * @param string $sSex * @internal We do not use \PH7\Framework\Url\Url::httpBuildQuery() method for the first condition otherwise the URL is distorted and it does not work. * @return void */ public function report($iId, $sUsername, $sFirstName, $sSex) { $sReportLink = \PH7\UserCore::auth() ? Uri::get('report', 'main', 'abuse', '?spammer=' . $iId . '&url=' . $this->oHttpRequest->currentUrl() . '&type=' . Registry::getInstance()->module, false) . '" data-popup="block-page' : Uri::get('user', 'signup', 'step1', '?' . Url::httpBuildQuery(array('msg' => t('You must register to report this person.'), 'ref' => 'profile', 'a' => 'report', 'u' => $sUsername, 'f_n' => $sFirstName, 's' => $sSex)), false); echo '<a rel="nofollow" href="', $sReportLink, '" title="', t('Report Abuse'), '">', t('Report'), '</a>'; }
/** * Useful HTML Header. * * @param array $aMeta Default NULL * @param boolean $bLogo Default FALSE * @return void */ public final function usefulHtmlHeader(array $aMeta = null, $bLogo = false) { $this->bIsDiv = true; // DO NOT REMOVE THE COPYRIGHT CODE BELOW! Thank you! echo '<html><head><meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <title>', !empty($aMeta['title']) ? $aMeta['title'] : '', '</title>'; if (!empty($aMeta['description'])) { echo '<meta name="description" content="', $aMeta['description'], '" />'; } if (!empty($aMeta['keywords'])) { echo '<meta name="keywords" content="', $aMeta['keywords'], '" />'; } echo '<meta name="author" content="', Kernel::SOFTWARE_COMPANY, '" /> <meta name="copyright" content="', Kernel::SOFTWARE_COPYRIGHT, '" /> <meta name="creator" content="', Kernel::SOFTWARE_NAME, '" /> <meta name="designer" content="', Kernel::SOFTWARE_NAME, '" /> <meta name="generator" content="', Kernel::SOFTWARE_NAME, ' ', Kernel::SOFTWARE_VERSION_NAME, ' ', Kernel::SOFTWARE_VERSION, ', Build ', Kernel::SOFTWARE_BUILD, '" />'; $this->externalCssFile(PH7_URL_STATIC . PH7_CSS . 'js/jquery/smoothness/jquery-ui.css'); $this->staticFiles('css', PH7_LAYOUT . PH7_TPL . PH7_DEFAULT_THEME . PH7_SH . PH7_CSS, 'common.css,style.css,form.css'); $this->externalJsFile(PH7_URL_STATIC . PH7_JS . 'jquery/jquery.js'); $this->externalJsFile(PH7_URL_STATIC . PH7_JS . 'jquery/jquery-ui.js'); echo '<script>var pH7Url={base:\'', PH7_URL_ROOT, '\'}</script></head><body>'; if ($bLogo) { // Website's name $sSiteName = Registry::getInstance()->site_name; // Check if the website's name exists, otherwise we displayed the software's name $sName = !empty($sSiteName) ? $sSiteName : Kernel::SOFTWARE_NAME; echo '<header> <div id="logo"><h1><a href="', PH7_URL_ROOT, '" title="', $sName, ' — ', Kernel::SOFTWARE_NAME, ', ', Kernel::SOFTWARE_COMPANY, '">', $sName, '</a></h1></div> </header>'; } echo $this->flashMsg(), '<div class="msg"></div><div class="m_marg">'; }
/** * Routing controllers. * * @access private */ private function __construct() { /** Objects are created for the functioning of the class. * */ $this->oConfig = Config::getInstance(); $this->oRegistry = Registry::getInstance(); $this->oHttpRequest = new Http(); $this->oUri = Uri::getInstance(); $this->indexFileRouter(); if ($this->oUri->fragment(0) === 'asset' && $this->oUri->fragment(1) === 'gzip') { // Loading and compress CSS and JavaScript files $this->gzipRouter(); exit; } /** * @internal We initialize the database after compression of static files (\PH7\Framework\Mvc\Router\FrontController::gzipRouter() method), * so we can always display static files even if there are problems with the database. */ $this->_databaseInitialize(); /** * @internal This method must be declared before the rest of the code, because it initializes essential language constants for the rest of the code. */ $this->_languageInitialize(); // For the resources of the assets folders if ($this->oUri->fragment(0) === 'asset') { switch ($this->oUri->fragment(1)) { case 'ajax': // Loading Asynchronous Ajax files $this->ajaxRouter(); break; case 'file': // Loading files $this->fileRouter(); break; case 'cron': // Loading Cron Jobs files $this->cronRouter(); break; case 'css': // Loading Style sheet files $this->cssRouter(); break; case 'js': // Loading JavaScript files $this->jsRouter(); break; default: $this->notFound('Not found Asset file!', 1); } exit; } $oUrl = UriRoute::loadFile(new \DomDocument()); foreach ($oUrl->getElementsByTagName('route') as $oRoute) { if (preg_match('`^' . $oRoute->getAttribute('url') . '/?(?:\\?[^/]+\\=[^/]+)?$`', $this->oHttpRequest->requestUri(), $aMatches)) { $this->bRouterRewriting = true; $sPathModule = $oRoute->getAttribute('path') . PH7_SH; // Get module $this->oRegistry->module = $oRoute->getAttribute('module'); // Check if file exist if (!$this->oConfig->load(PH7_PATH_APP . $sPathModule . $this->oRegistry->module . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE)) { $this->notFound('The <b>' . $this->oRegistry->module . '</b> system module is not found.<br />File: <b>' . PH7_PATH_APP . $sPathModule . $this->oRegistry->module . PH7_DS . '</b><br /> or the <b>' . PH7_CONFIG_FILE . '</b> file is not found.<br />File: <b>' . PH7_PATH_APP . $sPathModule . $this->oRegistry->module . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE . '</b>'); // It reloads the config.ini file for the new module "error" $this->oConfig->load(PH7_PATH_MOD . $this->oRegistry->module . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE); } /***** PATH THE MODULE *****/ $this->oRegistry->path_module = PH7_PATH_APP . $sPathModule . $this->oRegistry->module . PH7_DS; /***** URL THE MODULE *****/ $this->oRegistry->url_module = PH7_URL_ROOT . $this->oRegistry->module . PH7_SH; /***** PATH THE TEMPLATE *****/ $this->oRegistry->path_themes_module = PH7_PATH_ROOT . PH7_LAYOUT . $sPathModule . $this->oRegistry->module . PH7_DS . PH7_TPL; /***** URL THE TEMPLATE *****/ $this->oRegistry->url_themes_module = PH7_RELATIVE . PH7_LAYOUT . $sPathModule . $this->oRegistry->module . PH7_SH . PH7_TPL; // Get the default controller $this->oRegistry->controller = ucfirst($oRoute->getAttribute('controller')) . 'Controller'; // Get the default action $this->oRegistry->action = $oRoute->getAttribute('action'); if ($oRoute->hasAttribute('vars')) { $aVars = explode(',', $oRoute->getAttribute('vars')); $iOffset = count($aVars); foreach ($aMatches as $sKey => $sMatch) { if ($sKey !== 0) { $this->oHttpRequest->setGet($aVars[$sKey - 1], $sMatch); /** Request Parameter for the Router Rewriting mode. * */ $this->aRequestParameter = $this->oUri->segments($this->oUri->totalFragment() - $iOffset); } } } break; } } unset($oUrl); if (empty($this->bRouterRewriting)) { if ($this->oUri->fragment(0) === 'm') { $this->simpleModuleRouter(); } else { $this->simpleRouter(); } } }
/** * Get Profile Link with the link to the registration form if the user is not connected. * * @param string $sUsername * @param string $sFirstName * @param string $sSex * @return string The link */ public function getProfileSignupLink($sUsername, $sFirstName, $sSex) { if (!self::auth() && !AdminCore::auth()) { $aHttpParams = ['ref' => (new Framework\Mvc\Request\Http())->currentController(), 'a' => Framework\Registry\Registry::getInstance()->action, 'u' => $sUsername, 'f_n' => $sFirstName, 's' => $sSex]; $sLink = Uri::get('user', 'signup', 'step1', '?' . Framework\Url\Url::httpBuildQuery($aHttpParams), false); } else { $sLink = $this->getProfileLink($sUsername); } return $sLink; }
/** * @return object $this * @throws \PH7\Framework\Layout\Exception If the template module file is not found. */ public function modTpl() { $oRegistry = \PH7\Framework\Registry\Registry::getInstance(); if ($this->_oConfig->load($oRegistry->path_module_views . $this->_sUserTpl . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE)) { $this->_sModTplName = $this->_sUserTpl; } else { if ($this->_oConfig->load($oRegistry->path_module_views . $this->_sDefaultTpl . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE)) { $this->_sModTplName = $this->_sDefaultTpl; } else { if ($this->_oConfig->load($oRegistry->path_module_views . PH7_DEFAULT_TPL_MOD . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE)) { $this->_sModTplName = PH7_DEFAULT_TPL_MOD; } else { throw new Exception('Template module file not found! File: \'' . $oRegistry->path_module_views . PH7_DEFAULT_TPL_MOD . PH7_DS . PH7_CONFIG . PH7_CONFIG_FILE . '\' doesn\'t exist.'); } } } unset($oRegistry); return $this; }