/** * Used to get default path related configuration * * It returns configuration containing path information * * @since 1.0.0 * @param array $configuration the default configuration * @param array $user_configuration the user configuration * @throws * @return array $configuration the default configuration information */ private function GetPathConfig($configuration, $user_configuration) { /** The document root of the application is set */ $configuration['path']['document_root'] = $_SERVER['DOCUMENT_ROOT']; /** The base folder path is set. All the application files including the framework are in this folder */ $configuration['path']['base_path'] = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . ".."); /** If the application template name is not set then the default template basicsite is used */ if (!isset($user_configuration['general']['template'])) { $user_configuration['general']['template'] = "basicsite"; } /** The application folder name is derived from the application name */ if (isset($user_configuration['general']['application_name']) && !isset($user_configuration['path']['application_folder'])) { $user_configuration['path']['application_folder'] = strtolower(\Framework\Utilities\UtilitiesFramework::Factory("string")->CamelCase($user_configuration['general']['application_name'])); } /** The application domain name is set */ if (isset($parameters['web_domain'])) { $user_configuration['path']['web_domain'] = $parameters['web_domain']; } else { if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['HTTPS_HOST'])) { $user_configuration['path']['web_domain'] = isset($_SERVER['HTTPS_HOST']) ? "https://" . $_SERVER['HTTPS_HOST'] : "http://" . $_SERVER['HTTP_HOST']; } else { $user_configuration['path']['web_domain'] = "http://example.com"; } } /** The web path to the framework */ if (!isset($user_configuration['path']['relative_web_domain'])) { $user_configuration['path']['relative_web_domain'] = trim(str_replace($configuration['path']['document_root'], "", $configuration['path']['base_path']), "/"); } /** The framework url is set */ $user_configuration['path']['framework_url'] = $user_configuration['path']['web_domain'] . "/" . $user_configuration['path']['relative_web_domain'] . "/index.php"; /** The web path to the application */ if (!isset($user_configuration['path']['application_folder_url'])) { /** The web path to the application */ $user_configuration['path']['application_folder_url'] = $user_configuration['path']['web_domain'] . "/" . $user_configuration['path']['relative_web_domain'] . "/" . $user_configuration['path']['application_folder']; } /** The url to the framework's template folder */ if (!isset($user_configuration['path']['framework_template_url'])) { $user_configuration['path']['framework_template_url'] = $user_configuration['path']['web_domain'] . "/" . $user_configuration['path']['relative_web_domain'] . "/framework/templates/" . $user_configuration['general']['template']; } /** The url to the application's template folder */ if (!isset($user_configuration['path']['application_template_folder'])) { $user_configuration['path']['application_template_folder'] = "templates"; } $user_configuration['path']['application_template_url'] = $user_configuration['path']['web_domain'] . "/" . $user_configuration['path']['relative_web_domain'] . "/" . $user_configuration['path']['application_folder'] . "/" . $user_configuration['path']['application_template_folder']; /** The web path to the application's vendors folder */ if (!isset($user_configuration['path']['web_vendor_path'])) { $user_configuration['path']['web_vendor_path'] = $user_configuration['path']['application_folder_url'] . "/vendors"; } else { $user_configuration['path']['web_vendor_path'] = $user_configuration['path']['web_domain'] . "/" . $user_configuration['path']['relative_web_domain'] . "/" . $user_configuration['path']['web_vendor_path']; } /** The path to the framework folder */ $configuration['path']['framework_path'] = $configuration['path']['base_path'] . DIRECTORY_SEPARATOR . "framework"; /** The path to the application folder */ $configuration['path']['application_path'] = $configuration['path']['base_path'] . DIRECTORY_SEPARATOR . $user_configuration['path']['application_folder']; /** The path to the framework templates html folder */ $configuration['path']['template_path'] = $configuration['path']['framework_path'] . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $user_configuration['general']['template'] . DIRECTORY_SEPARATOR . "html"; /** The path to the application templates folder */ $configuration['path']['application_template_path'] = $configuration['path']['application_path'] . DIRECTORY_SEPARATOR . $user_configuration['path']['application_template_folder']; /** The path to the application tmp folder */ $configuration['path']['tmp_folder_path'] = $configuration['path']['application_path'] . DIRECTORY_SEPARATOR . 'tmp'; /** The path to the vendor folder */ $configuration['path']['vendor_folder_path'] = $configuration['path']['application_path'] . DIRECTORY_SEPARATOR . 'vendors'; /** The path to the pear folder */ $configuration['path']['pear_folder_path'] = DIRECTORY_SEPARATOR . "usr" . DIRECTORY_SEPARATOR . "share" . DIRECTORY_SEPARATOR . "pear"; /** Indicates the files that need to be included for all application requests */ $configuration['path']['include_files'] = array(); /** The path to the application data folder is set in user configuration */ if (isset($user_configuration['path']['data_folder'])) { $user_configuration['path']['data_folder'] = $configuration['path']['application_path'] . DIRECTORY_SEPARATOR . $user_configuration['path']['data_folder']; } /** The folder path to the application's vendors folder */ if (!isset($user_configuration['path']['vendor_folder_path'])) { $user_configuration['path']['vendor_folder_path'] = $configuration['path']['application_path'] . DIRECTORY_SEPARATOR . 'vendors'; } else { $user_configuration['path']['vendor_folder_path'] = $configuration['path']['base_path'] . DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR . $user_configuration['path']['vendor_folder_path']; } /** User configuration is merged */ if (isset($user_configuration['path'])) { $configuration['path'] = array_replace_recursive($configuration['path'], $user_configuration['path']); } return $configuration; }
/** * Used to authenticate the user using http authentication * * It displays an error to the user if http authentication fails * */ public function HttpAuthentication() { /** The http authentication parameters are fetched **/ $http_authentication = $this->GetConfig('http_auth'); /** The http authentication method is called **/ $is_valid_user = \Framework\Utilities\UtilitiesFramework::Factory("authentication")->AuthenticateUser($http_authentication['credentials'], $http_authentication['realm']); /** If the authentication method returns an error then an error is shown to the user in browser and script execution ends **/ if (!$is_valid_user) { die("Please enter a valid user name and password"); } }
/** * Used to get css and javascript tag values * * It returns css and javascript file tags for the given css and javascript files * * @since 1.0.0 * @param array $parameters the parameters used to render the css and javascript tags. It is an array with following keys: * file_type=> the type of file to render. i.e css or javascript * file_list=> an array where each element is an absolute path of a css file * * @return string $script_tags_html html string containing the css or javascript tags */ private function RenderCssJsFileTags($parameters) { /** The path to the application template folder is fetched */ $template_folder_path = $this->GetConfig("path", "template_path"); $file_list = $parameters['file_list']; $tag_arr = array(); for ($count = 0; $count < count($file_list); $count++) { $file_name = $file_list[$count]; $tag_arr[$count]["url"] = $file_name; } /** If the file type is css then the css template file is rendered */ if ($parameters['file_type'] == 'css') { $script_tags_html = \Framework\Utilities\UtilitiesFramework::Factory("template")->RenderTemplateFile($template_folder_path . DIRECTORY_SEPARATOR . "css_tags.html", $tag_arr); } else { if ($parameters['file_type'] == 'javascript') { $script_tags_html = \Framework\Utilities\UtilitiesFramework::Factory("template")->RenderTemplateFile($template_folder_path . DIRECTORY_SEPARATOR . "javascript_tags.html", $tag_arr); } else { throw new \Exception("Invalid file type given to RenderCssJsFileTags"); } } return $script_tags_html; }
/** * Used to download and parse the given file * * It downloads the file from the given url * It then converts the file contents into an array * Each line is parsed and the field values are extracted * CSV and TXT files are supported * Field names in csv files must be enclosed with "" and separated with , * Fi * @since 1.0.2 * @param string $file_url the url of the file * * @return array $data the contents of the file. each array element contains the data for a line */ public function DownloadAndParseFile($file_url, $local_file_path, $line_parsing_callback) { /** The parsed contents of the file */ $data = array(); /** The file data containing file name and extension */ $file_details = \Framework\Utilities\UtilitiesFramework::Factory("string")->GetFileNameAndExtension($file_url); /** The file name */ $file_name = $file_details['file_name']; /** The file name is url decoded */ $file_name = urldecode($file_name); /** The file extension */ $file_extension = $file_details['file_extension']; /** The absolute path to the downloaded file */ $file_path = $local_file_path . DIRECTORY_SEPARATOR . $file_name; /** If the file exists locally then it is read */ if (is_file($file_path)) { $file_contents = $this->ReadLocalFile($file_path); } else { $file_contents = $this->GetFileContent($file_url); /** The file contents are saved locally */ $this->WriteLocalFile($file_contents, $file_path); } /** The file contents are converted to array */ $file_contents = explode("\n", $file_contents); /** The components of each meta data item is extracted using regular expression */ for ($count = 0; $count < count($file_contents); $count++) { /** The line string */ $line = trim($file_contents[$count]); /** If the line is empty or it starts with a # then it is ignored */ if ($line == '' || strpos($line, '#') !== false) { break; } /** The parametes for the callback function */ $parameters[0] = $file_extension; $parameters[1] = $line; /** The parsed lined. It is generated by the line parsing callback function */ $parsed_line = call_user_func_array($line_parsing_callback, $parameters); /** The parsed line is appended to the data */ $data[] = $parsed_line; } return $data; }