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

Secure PHP Development- P88 ppsx

5 197 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

◆ 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 _loadFilemethod.. The _loadFileload

Trang 1

with the app=current_applicationquery parameter For example, if the application name is irm, then this link can be http://server/path/to/ help.php?app=irm The $tocLinkvalue is stored in $contentshash using $contents[‘toc_link’]

◆ A local variable called $prevSectionis 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 $searchis set up with a set of regular expression (RE) patterns that identifies embedded image sources in HTML contents Another local array variable called $replaceis 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=”imageswith 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

$searchpatterns with $replacein $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 $contentsassociative 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

Trang 2

◆ Then it finds the array index of the current section ($section) in the

$this->_SECTIONSarray 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->_SECTIONSarray 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->_SECTIONShash

◆ 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->_SECTIONShash

◆ A local variable called $indexis initialized to null

Trang 3

◆ 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 $indexvalue is returned

getTOCContents( )

This method returns the table of contents in a hash It works as follows:

◆ It sets a hash called $contentsto 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 $sectionswith 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 $contentshash

isLoaded( )

This method returns the value of object variable _LOADED, which indicates if the help map is loaded or not

isSection( )

This method returns TRUEif 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 $keywordListusing 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

Trang 4

◆ It initializes an array called $matchedSectionsto an empty list.

◆ It sets $keywordCountto the number of keywords in $keywordList

◆ For each keyword in the list, it runs through a whileloop 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 $matchedSectionslist If the

$matchedSectionsarray 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_RESULTand 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 TRUEor

FALSE

getSearchMatchCount( )

This method returns the number of matches found in a search The number of matches is stored in the _SEARCH_MATCH_COUNTobject variable

getSearchResults( )

This method returns the match results in a hash It works as follows:

◆ An associative array variable called $contentsis 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_RESULTto the getSectionHash()method

◆ A local variable called $linkPrefixis 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

$sectionLinksarray using the $linkPrefixand section ID information

Trang 5

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 $historyFilevariable

◆ The serialized contents of the history file, $historyFile, is loaded in

$serializedHistoryusing the _loadFile()method

◆ If the history is not empty, then the $asisparameter is checked to see how the data should be returned If $asisis set to FALSE, then the history data is unserialized in the $historyvariable and, using a loop, each his-tory element is parsed The key of each hishis-tory 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 $hashis populated with search keywords from the history, and the relative URL is stored as a value

◆ On the other hand, if $asisis 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:

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