1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P88 ppsx

5 197 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 86,07 KB

Nội dung

with the app=current_application query parameter. For example, if the application name is irm, then this link can be http://server/path/to/ help.php?app=irm . The $tocLink value is stored in $contents hash using $contents[‘toc_link’]. ◆ A local variable called $prevSection is used to store the previous section of the $section. The previous section number is retrieved by calling the getPreviousSection() method. If the previous section is available, then a URL is created to point to the previous section and the URL is stored in $contents[‘previous_section’]. Otherwise, the $contents[‘previous_ section’] is set to null. Similarly, a URL is created for the next section by calling the getNextSection() method and the value is stored in $contents[‘next_section’]. ◆ The body of the help contents for the current section is stored in $contents [‘next_section’] , which is populated using the contents returned by the _loadFile() method. The _loadFile() loads the help contents for the current section when it is given a fully qualified help file name using the $this->getFQPNofSection($section)) method. ◆ A local array variable called $search is set up with a set of regular expression (RE) patterns that identifies embedded image sources in HTML contents. Another local array variable called $replace is set up with a set of path replacements for RE patterns stored in $search. The idea is to replace image sources with relative paths such as src=images, src=”images, background=images, background=”images with the proper relative path generated using the getRelHelpDir() method. When the help contents are displayed by the help application, the relative paths of the HTML image sources must be modified this way to ensure that images are visible. The built-in preg_replace() function is used replace all $search patterns with $replace in $contents[‘body’]. ◆ The template path for the current section is set to $contents[‘template’] using the getSectionTemplate() method. ◆ Similarly, the base URL path for the current section is set to $contents [‘base_url’] using the getBaseURL() method. ◆ Finally, the method returns the $contents associative array. getPreviousSection() This method returns the previous section number for a given section. It works as follows: ◆ First it stores the total number of sections, $totalSections, in the current help map by counting the entries in $this->_SECTIONS, which is the list of sections. 406 Part II: Developing Intranet Solutions 15 549669 ch12.qxd 4/4/03 9:26 AM Page 406 ◆ Then it finds the array index of the current section ($section) in the $this->_SECTIONS array using the _indexOfSection() method. This array index is stored in $thisSectionIndex. ◆ If the current section’s array index, $thisSectionIndex, is greater than zero, which means the current section is not the first section, than the method returns the previous section number by subtracting 1 from the current section’s array index and calling the getSectionAtIndex() method to return the section number at this index. ◆ If the current section is the first section, the method returns null. getNextSection() This method returns the next section number for a given section. It works as follows: ◆ First it stores the total number of sections, $totalSections, in the current help map by counting the entries in $this->_SECTIONS, which is the list of sections. ◆ Then it finds the array index of the current section ($section) in the $this->_SECTIONS array using the _indexOfSection() method. This array index is stored in $thisSectionIndex. ◆ If the current section’s array index, $thisSectionIndex, is less than the total index count, which means the current section is not the last section, then the method returns the next section number by adding 1 to the current section’s array index and calling the getSectionAtIndex() method to return the section number at this index. ◆ If the current section is the last section, the method returns null. getSectionAtIndex() This method returns the section number from the $this->_SECTIONS hash for a given section array index. It works as follows: ◆ First it creates a list called $list, which stores the section names from the $this->_SECTIONS hash. ◆ If the given array index number, $index, is within the range of the $list array, it returns the section number at the index; otherwise, it returns null. _indexOfSection() This method returns the array index of a given section number. It works as follows: ◆ First it creates a list called $list, which stores the section names from the $this->_SECTIONS hash. ◆ A local variable called $index is initialized to null. Chapter 12: Online Help System 407 15 549669 ch12.qxd 4/4/03 9:26 AM Page 407 ◆ Then it loops through the list of sections and checks whether the given section number matches with one in the list. If a match is found, the loop is stopped and the index of the matched section is stored in $index. ◆ The $index value is returned. getTOCContents() This method returns the table of contents in a hash. It works as follows: ◆ It sets a hash called $contents to an empty array. ◆ The $contents[‘output’] is set to show_toc, which indicates to the help display application (help.php) that it needs to show the table of contents. ◆ It creates a hash called $sections with the list of sections using getSectionHash. If there are no sections, the method returns the empty $contents. Otherwise, the section hash is stored in $contents[‘sections’]. ◆ For each section of the help contents, it creates a URL and stores the URL in $sectionLinks, which is later stored in $contents[‘section_links’]. ◆ Then it gets the template for the table of contents using the getTOCTempalte() method and stores the template path in $contents[‘template’]. ◆ Similarly, the base URL path for the current section is set to $contents[‘base_url’] using the getBaseURL() method. ◆ Finally, the method returns the $contents hash. isLoaded() This method returns the value of object variable _LOADED, which indicates if the help map is loaded or not. isSection() This method returns TRUE if a given section name belongs to the current section list. search() This method performs a keyword search using the help index. It receives keywords as a parameter. It works as follows: ◆ It creates a keyword list called $keywordList using the getKeywordList() method. Note that the given keyword parameter, $kwords, might contain duplicates; the getKeywordList() method removes these duplicates and also removes the OR operator, because whenever multiple words are searched, the default operation is logical OR. ◆ It creates a list of sections, $allSections, using the getSectionList() method. 408 Part II: Developing Intranet Solutions 15 549669 ch12.qxd 4/4/03 9:26 AM Page 408 ◆ It initializes an array called $matchedSections to an empty list. ◆ It sets $keywordCount to the number of keywords in $keywordList. ◆ For each keyword in the list, it runs through a while loop to find matching sections. When looping through the list of keywords, each keyword is com- pared with ‘and’ (for an AND operation). If the current keyword is ‘and’, the next keyword is searched only in the section list of already matched sections for all previous keywords. If the keyword is not ‘and’, then the keyword is searched in all sections ($allSections). This effectively creates the AND operation. ◆ All found matches are consolidated in the $matchedSections list. If the $matchedSections array has a size greater than zero, that indicates that a match for the given keywords was found. In such a case, the matched sections are stored in an object variable called _SEARCH_RESULT and the match count is stored in another object variable called _SEARCH_MATCH_COUNT. ◆ Based on whether a match was found or not, the method returns TRUE or FALSE. getSearchMatchCount() This method returns the number of matches found in a search. The number of matches is stored in the _SEARCH_MATCH_COUNT object variable. getSearchResults() This method returns the match results in a hash. It works as follows: ◆ An associative array variable called $contents is initialized to an empty array. ◆ The $contents[‘output’] is set to search_result, which indicates to the help display application (help.php) that it needs to show the search results. ◆ A string version of the keyword array is stored in $contents[‘keyword_string’]. ◆ The $contents[‘sections’] is assigned to a hash that represents the matching sections stored in $this->_SEARCH_RESULT. This hash is created by passing $this->_SEARCH_RESULT to the getSectionHash() method. ◆ A local variable called $linkPrefix is set to the URL prefix needed to access the help for the current application. This URL has a syntax such as http://server/path/to/help.php?app=current_application. ◆ For each matching section in the search result, a link is created in the $sectionLinks array using the $linkPrefix and section ID information Chapter 12: Online Help System 409 15 549669 ch12.qxd 4/4/03 9:26 AM Page 409 so that the URL has a syntax of http://server/path/to/help. php?app=current_application&section=section_number . ◆ The list of matched section links is stored in $contents[‘section_links’]. The total match count is stored in $contents[‘match_count’]. ◆ The template for showing the results is retrieved by the getSearchResultTempalte() method and stored in $contents [‘template’] . ◆ The base URL path for the current section is set to $contents[‘base_url’] using the getBaseURL() method. ◆ The most recent search history hash is retrieved using the getRecentSearchList() method and stored in $contents [‘recent_search’] . ◆ Finally, the updateRecentSearchList() method is used to update the recent search history using the current keyword string returned by the getKeywordString() method. getRecentSearchList() This method returns a hash with recent search history. It works as follows: ◆ It creates an empty hash called $hash. ◆ The fully qualified history file name for the current help content is retrieved using the getFQPNSearchHistoryFile() method and stored in the $historyFile variable. ◆ The serialized contents of the history file, $historyFile, is loaded in $serializedHistory using the _loadFile() method. ◆ If the history is not empty, then the $asis parameter is checked to see how the data should be returned. If $asis is set to FALSE, then the history data is unserialized in the $history variable and, using a loop, each his- tory element is parsed. The key of each history hash element is the search keyword; the value consists of a time stamp and relative URL link that can be used to search for the keyword. The $hash is populated with search keywords from the history, and the relative URL is stored as a value. ◆ On the other hand, if $asis is TRUE, then the unserialized history hash is returned as is. updateRecentSearchList() This method adds the given keywords to the recent search history if they aren’t already in the history. It works as follows: 410 Part II: Developing Intranet Solutions 15 549669 ch12.qxd 4/4/03 9:26 AM Page 410 . For example, if the application name is irm, then this link can be http://server/path/to/ help .php? app=irm . The $tocLink value is stored in $contents hash using $contents[‘toc_link’]. ◆ A local. array. ◆ The $contents[‘output’] is set to show_toc, which indicates to the help display application (help .php) that it needs to show the table of contents. ◆ It creates a hash called $sections with the. $contents[‘output’] is set to search_result, which indicates to the help display application (help .php) that it needs to show the search results. ◆ A string version of the keyword array is stored

Ngày đăng: 07/07/2014, 07:20

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN