Example #1
0
 /**
  * PPI Mail Sending Functioin
  * @param array $p_aOptions The options for sending to the mail library
  * @uses $p_aOptions[subject, body, toaddr] are all mandatory.
  * @uses Options available are toname
  * @return boolean The result of the mail sending process
  */
 static function sendMail(array $p_aOptions)
 {
     $oConfig = PPI_Helper::getConfig();
     $oEmail = new PPI_Model_Email_Advanced();
     if (!isset($p_aOptions['subject'], $p_aOptions['body'], $p_aOptions['toaddr'])) {
         throw new PPI_Exception('Invalid parameters to sendMail');
     }
     $oEmail->Subject = $p_sSubject;
     if (isset($p_aOptions['fromaddr'], $p_aOptions['fromname'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr'], $p_aOptions['fromname']);
     } elseif (isset($p_aOptions['fromaddr'])) {
         $oEmail->SetFrom($p_aOptions['fromaddr']);
     } else {
         $oEmail->SetFrom($oConfig->system->adminEmail, $oConfig->system->adminName);
     }
     if (isset($p_aOptions['toaddr'], $p_aOptions['toname'])) {
         $oEmail->AddAddress($p_aOptions['toaddr'], $p_aOptions['toname']);
     } elseif (isset($p_aOptions['toaddr'])) {
         $oEmail->AddAddress($p_aOptions['toaddr']);
     }
     if (isset($p_aOptions['altbody'])) {
         $oEmail->AltBody = $p_sMessage;
     }
     $oEmail->MsgHTML($p_aOptions['body']);
     // If the email sent successfully,
     return $oEmail->Send();
     // @todo - Log the email sending process.
 }
Example #2
0
 /**
  * The function used to initially set the instance
  *
  * @param PPI_Helper $instance
  * @throws PPI_Exception
  * @return void
  */
 static function setInstance(PPI_Helper $instance)
 {
     if (self::$_instance !== null) {
         throw new PPI_Exception('PPI_Helper is already initialised');
     }
     self::$_instance = $instance;
 }
Example #3
0
 function __construct(PDOStatement $statement)
 {
     // Config override for fetchmode. If it's a valid fetchmode then we override
     $oConfig = PPI_Helper::getConfig();
     if (isset($oConfig->db->fetchmode) && $oConfig->db->fetchmode != '' && array_key_exists($oConfig->db->fetchmode, $this->_fetchModes)) {
         $this->_fetchMode = $oConfig->db->fetchmode;
     }
     $this->_statement = $statement;
 }
Example #4
0
 /**
  * Get the URI segments after the base url
  *
  * @return array
  */
 function getURISegments()
 {
     if ($this->_router !== null) {
         $url = $this->_router->getMatchedRoute();
     } else {
         $url = str_replace($this->_config->system->base_url, '', $this->_fullUrl);
     }
     PPI_Helper::getRegistry()->set('PPI::Request_URI', $url);
     return explode('/', trim($url, '/'));
 }
Example #5
0
 function putRecord(array $aData)
 {
     $oConfig = PPI_Helper::getConfig();
     // If its an insert
     if (!array_key_exists($this->_iTableIndex, $aData)) {
         $plainPass = $aData['password'];
         if (!array_key_exists($oConfig->system->usernameField, $aData)) {
             throw new PPI_Exception('Unable to locate username field when creating user');
         }
         $aData['active'] = isset($oConfig->system->defaultUserActive) && $oConfig->system->defaultUserActive != false ? 1 : 0;
         $aData['created'] = time();
         $aData['activation_code'] = base64_encode(time());
         // ----- Password Stuff ----
         if (isset($aData['salt'])) {
             $sSalt = $aData['salt'];
             unset($aData['salt']);
             // If no salt has been set then we get it from the config.
         } else {
             $sSalt = $oConfig->system->userAuthSalt;
         }
         if (empty($sSalt)) {
             throw new PPI_Exception('No salt found when trying to register user');
         }
         $aData['password'] = $this->encryptPassword($sSalt, $aData['password']);
         // If no role_id has been set, lets set it from the config.
         if (!isset($aData['role_id'])) {
             if (!isset($oConfig->system->defaultUserRole)) {
                 throw new PPI_Exception('Missing config value system.defaultUserRole');
             }
             $aData['role_id'] = PPI_Model_Helper::getRoleIDFromName($oConfig->system->defaultUserRole);
         }
     } else {
         //if password is being passed in for re-set, we need to encrypt it
         if (isset($aData['password'], $aData['salt'])) {
             $aData['password'] = $this->encryptPassword($aData['salt'], $aData['password']);
             unset($aData[$oConfig->system->usernameField]);
             unset($aData['salt']);
         }
     }
     return parent::putRecord($aData);
     // set the system log here
     // send acitvation email here
     //$oEmail = new PPI_Model_Email();
     /*$oEmail->setTemplate('User Registration', array(
     			'site_name' => $oConfig->site_name,
     			'username' 	=> $aData[$oConfig->usernameField],
     			'password' 	=> $plainPass
     		))->sendMail();*/
 }
Example #6
0
 /**
  * Returns an array of role_id => role_type of all the roles defined
  *
  * @return array
  */
 static function getRoles()
 {
     $oConfig = PPI_Helper::getConfig();
     if (isset($oConfig->user->roleMappingService) && $oConfig->user->roleMappingService == 'database') {
         $oUser = new APP_Model_User_Role();
         $aRoles = $oUser->getList()->fetchAll();
         $aRetRoles = array();
         foreach ($aRoles as $aRole) {
             $aRetRoles[$aRole['name']] = $aRole['id'];
         }
         return $aRetRoles;
     } else {
         return $oConfig->system->roleMapping->toArray();
     }
 }
Example #7
0
 /**
  * Initialise the config object
  *
  * Will check the file extension of your config filename and load up a specific parser
  * @param string $p_sConfigFile The config filename
  * @param array $p_aOptions The options
  * 
  * @return void
  */
 function __construct($p_sConfigFile, $p_aOptions = array())
 {
     if (!file_exists(CONFIGPATH . $p_sConfigFile)) {
         die('Unable to find <b>' . CONFIGPATH . $p_sConfigFile . '</b> file, please check your application configuration');
     }
     $ext = PPI_Helper::getFileExtension($p_sConfigFile);
     $block = isset($p_aOptions['block']) ? $p_aOptions['block'] : 'development';
     switch ($ext) {
         case 'ini':
             $this->_oConfig = new PPI_Config_Ini(parse_ini_file(CONFIGPATH . $p_sConfigFile, true), $block);
             break;
         case 'xml':
             die('Trying to load a xml config file but no parser yet created.');
             break;
         case 'php':
             die('Trying to load a php config file but no parser yet created.');
             break;
     }
 }
Example #8
0
 /**
  * Get the routes, either from the cache or newly from disk
  *
  * @return array
  */
 function getRoute()
 {
     $this->routes = file_get_contents(APPFOLDER . 'Config/routes.php');
     ppi_dump($this->routes, true);
     // Loop through the route array looking for wild-cards
     foreach ($this->routes as $key => $val) {
         // Convert wild-cards to RegEx
         $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
         // Does the RegEx match?
         if (preg_match('#^' . $key . '$#', $uri)) {
             // Do we have a back-reference?
             if (strpos($val, '$') !== FALSE and strpos($key, '(') !== FALSE) {
                 $val = preg_replace('#^' . $key . '$#', $val, $uri);
             }
             $this->_set_request(explode('/', $val));
             return;
         }
     }
     PPI_Helper::getRegistry()->set();
     return self::$_routes;
 }
Example #9
0
 /**
  * Initialise the router and start grabbing routes
  *
  * @return void
  */
 function init()
 {
     include_once $this->getRoutingFile();
     $uri = str_replace(PPI_Helper::getConfig()->system->base_url, '/', PPI_Helper::getFullUrl());
     $route = $uri;
     // Loop through the route array looking for wild-cards
     foreach ($routes as $key => $val) {
         // Convert wild-cards to RegEx
         $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key);
         // Does the RegEx match?
         if (preg_match('#^' . $key . '$#', $uri)) {
             // Do we have a back-reference?
             if (strpos($val, '$') !== false && strpos($key, '(') !== false) {
                 $val = preg_replace('#^' . $key . '$#', $val, $uri);
             }
             $route = $val;
             break;
         }
     }
     $this->setMatchedRoute($route);
 }
Example #10
0
 /**
  * Read the config file, only ini type implemented
  *
  * @todo Implement XML and PHP config files
  * @return void
  */
 function readConfig()
 {
     global $siteTypes;
     if (!file_exists(CONFIGPATH . $this->_configFile)) {
         die('Unable to find ' . $this->_configFile . ' file, please check your application configuration');
     }
     $ext = PPI_Helper::getFileExtension($this->_configFile);
     $sHostname = getHTTPHostname();
     $siteType = array_key_exists($sHostname, $siteTypes) ? $siteTypes[$sHostname] : 'development';
     switch ($ext) {
         case 'ini':
             $this->_oConfig = new PPI_Config_Ini(parse_ini_file(CONFIGPATH . $this->_configFile, true), $siteType);
             break;
         case 'xml':
             die('Trying to load a xml config file but no parser yet created.');
             break;
         case 'php':
             die('Trying to load a php config file but no parser yet created.');
             break;
     }
 }
Example #11
0
function writeErrorToLog($message)
{
    if (ini_get('log_errors') !== 'On') {
        return false;
    }
    $oConfig = PPI_Helper::getConfig();
    if (($sErrorLog = ini_get('error_log')) == 'syslog') {
        syslog(LOG_ALERT, "\n{$message}\n");
    } elseif ($sErrorLog !== '' && is_writable($sErrorLog)) {
        file_put_contents($sErrorLog, "\n{$message}\n", FILE_APPEND);
    }
}
Example #12
0
 /**
  * PPI_Input::clearFlashMessage()
  * Wipe the flash message from the session
  * @return void
  */
 static function clearFlashMessage()
 {
     PPI_Helper::getSession()->remove('ppi_flash_message');
 }
Example #13
0
 function getTemplateExtension()
 {
     $oConfig = PPI_Helper::getConfig();
     return !empty($oConfig->layout->rendererExt) ? $oConfig->layout->rendererExt : '.html';
 }
Example #14
0
 /**
  * Get a plugin by name.
  *
  * @param string $p_sPluginName
  * @return
  */
 protected function getPlugin($p_sPluginName)
 {
     return PPI_Helper::getPlugin()->getPlugin($p_sPluginName);
 }
Example #15
0
 /**
  * Convert the role ID by specifying the role name
  *
  * @static
  * @throws PPI_Exception
  * @param  string $p_sRoleName The role name
  * @return integer
  */
 static function getRoleIDFromName($p_sRoleName)
 {
     $oConfig = PPI_Helper::getConfig();
     $aRoles = $oConfig->system->roleMapping->toArray();
     if (array_key_exists($p_sRoleName, $aRoles)) {
         return $aRoles[$p_sRoleName];
     }
     throw new PPI_Exception('Unknown Role Type: ' . $p_sRoleName);
 }
Example #16
0
 /**
  * The constructor
  */
 function __construct()
 {
     $this->_config = PPI_Helper::getConfig();
     $this->_input = PPI_Helper::getInput();
     $this->_fullUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI'];
 }
Example #17
0
 /**
  * Get the CSRF token from the session
  * @return string
  */
 static function getCSRF()
 {
     return PPI_Helper::getSession()->get('PPI_Security::csrfToken');
 }
Example #18
0
 /**
  * Same as show error but return the content as a param
  *
  * @param array $p_aError
  * @return string The HTML contents
  */
 function getErrorForEmail($p_aError = "")
 {
     $oConfig = PPI_Helper::getConfig();
     $heading = "PHP Error";
     $baseUrl = $oConfig->system->base_url;
     require SYSTEMPATH . 'View/code_error.php';
     return $html;
 }
Example #19
0
function roleIDToName($p_iID)
{
    if (!isset(PPI_Helper::getConfig()->system->roleMapping)) {
        throw new PPI_Exception('Trying to perform roleIDToName when no roleMapping information was found.');
    }
}
Example #20
0
 /**
  * Obtain the list of default view variables
  *
  * @todo review making var names not HNC prefixed.
  * @param array $options
  * @return array
  */
 function getDefaultRenderValues(array $options, $p_oConfig)
 {
     $authData = PPI_Helper::getSession()->getAuthData();
     $oDispatch = PPI_Helper::getDispatcher();
     $request = array('controller' => $oDispatch->getControllerName(), 'method' => $oDispatch->getMethodName());
     return array('isLoggedIn' => !empty($authData), 'config' => $p_oConfig, 'request' => $request, 'input' => PPI_Helper::getInput(), 'authData' => $authData, 'baseUrl' => $p_oConfig->system->base_url, 'fullUrl' => PPI_Helper::getFullUrl(), 'currUrl' => PPI_Helper::getCurrUrl(), 'viewDir' => $options['viewDir'], 'actionFile' => $options['actionFile'], 'responseCode' => PPI_Helper::getRegistry()->get('PPI_View::httpResponseCode', 200), 'stylesheetFiles' => PPI_View_Helper::getStylesheets(), 'javascriptFiles' => PPI_View_Helper::getJavascripts(), 'authInfo' => $authData, 'aAuthInfo' => $authData, 'bIsLoggedIn' => !empty($authData), 'oConfig' => $p_oConfig);
 }
Example #21
0
 /**
  * Get the session object
  *
  * @return object
  */
 function getSession()
 {
     return PPI_Helper::getSession();
 }
Example #22
0
 /**
  * Retrieve information passed via the $_POST array.
  * Can specify a key and return that, else return the whole $_POST array
  *
  * @param string [$p_sIndex] Specific $_POST key
  * @param mixed [$p_sDefaultValue] null if not specified, mixed otherwise
  * @return string|array Depending if you passed in a value for $p_sIndex
  */
 function post($p_sIndex = null, $p_sDefaultValue = null, $p_aOptions = null)
 {
     if ($p_sIndex === null) {
         return PPI_Helper::getInstance()->arrayTrim($_POST);
     } else {
         return PPI_Helper::getInstance()->arrayTrim(isset($_POST[$p_sIndex]) ? $_POST[$p_sIndex] : $p_sDefaultValue);
     }
 }
Example #23
0
 /**
  * This gets the submitted values from the form.
  * If $fields is submitted then it only returns the fields specified. Otherwise gets all fields
  *
  * @param array [$fields] Key => Value result of the form
  * @return array
  */
 function getSubmitValues($fields = array())
 {
     // we can only return the fields specified by $fields or we can return all fields
     if (!empty($fields)) {
         foreach ($fields as $field) {
             if (array_key_exists($field, $this->_formFields)) {
                 $submitFields[$field] = $this->_formFields[$field];
             }
         }
         // We get all the fields by default
     } else {
         foreach ($this->_formFields as $fieldName => $fieldVal) {
             if (array_key_exists($fieldName, $this->_formFields)) {
                 $submitFields[$fieldName] = $this->_formFields[$fieldName];
             }
         }
     }
     // Remove all captcha fields from the retreived submit values.
     foreach ($this->_captchaFields as $val) {
         if (array_key_exists($val, $submitFields) === true) {
             unset($submitFields[$val]);
             unset($submitFields['recaptcha_challenge_field']);
             unset($submitFields['recaptcha_response_field']);
         }
     }
     // remove our submit button !
     if (array_key_exists('submit', $submitFields) === true) {
         unset($submitFields['submit']);
     }
     // Pass these fields to the hooker to clean up and get rid of anything we don't want
     $submitFields = $this->oHooker->preRetreival($submitFields);
     // Clean the inputs
     $submitFields = PPI_Helper::getInstance()->arrayTrim($submitFields);
     return $submitFields;
 }