Constants

SNIPPET_TITLE_LENGTH

SNIPPET_TITLE_LENGTH

MAX_SNIPPET_TITLE_LENGTH

MAX_SNIPPET_TITLE_LENGTH

SNIPPET_LENGTH_LEFT

SNIPPET_LENGTH_LEFT

SNIPPET_LENGTH_RIGHT

SNIPPET_LENGTH_RIGHT

MIN_SNIPPET_LENGTH

MIN_SNIPPET_LENGTH

DEFAULT_DESCRIPTION_LENGTH

DEFAULT_DESCRIPTION_LENGTH

Default maximum character length of a search summary

Properties

$db

$db : object

Reference to a DatasourceManager

Type

object

$db_name

$db_name : string

Name of the search engine database

Type

string

$private_db

$private_db : object

Reference to a private DatasourceManager

Type

object

$private_db_name

$private_db_name : string

Name of the private search engine database

Type

string

$edited_page_summaries

$edited_page_summaries : array

Associative array of page summaries which might be used to override default page summaries if set.

Type

array

$any_fields

$any_fields : array

These fields if present in $search_array (used by @see getRows() ), but with value "-1", will be skipped as part of the where clause but will be used for order by clause

Type

array

$search_table_column_map

$search_table_column_map : array

Associations of the form name of field for web forms => database column names/abbreviations In this case, things will in general map to the LOCALES tables in the Yioop database

Type

array

$web_site

$web_site : object

Reference to a WebSite object in use to serve pages (if any)

Type

object

$cache

$cache : object

Cache object to be used if we are doing caching

Type

object

$configure

$configure : array

Used to store ini file data of the current locale

Type

array

$default_configure

$default_configure : array

Used to store ini file data of the default locale (will use if no translation current locale)

Type

array

$locale_tag

$locale_tag : string

IANA tag name of current locale

Type

string

$locale_name

$locale_name : string

Locale name as a string it locale name's language

Type

string

$writing_mode

$writing_mode : string

Combination of text direction and block progression as a string. Has one of four values: lr-tb, rl-tb, tb-lr, tb-rl. Other possible values for things like Arabic block quoted in Mongolian not supported

Type

string

$extract_dirs

$extract_dirs : array

Directories to try to extract translatable identifier strings from

Type

array

$extensions

$extensions : array

File extensions of files to try to extract translatable strings from

Type

array

$current_locale

$current_locale : object

Holds global locale object currently in use for the session

Type

object

Methods

__construct()

__construct(string  $db_name = \seekquarry\yioop\configs\DB_NAME, boolean  $connect = true,   $web_site = null) 

Sets up the database manager that will be used and name of the search engine database

Parameters

string $db_name

the name of the database for the search engine

boolean $connect

whether to connect to the database by default after making the datasource class

$web_site

fileGetContents()

fileGetContents(string  $filename, boolean  $force_read = false) : string

Either a wrapper for file_get_contents, or if a WebSite object is being used to serve pages, it reads it in using blocking I/O file_get_contents() and caches it before return its string contents.

Note this function assumes that only the web server is performing I/O with this file. filemtime() can be used to see if a file on disk has been changed and then you can use $force_read = true below to force re- reading the file into the cache

Parameters

string $filename

name of file to get contents of

boolean $force_read

whether to force the file to be read from presistent storage rather than the cache

Returns

string —

contents of the file given by $filename

filePutContents()

filePutContents(string  $filename, string  $data) 

Either a wrapper for file_put_contents, or if a WebSite object is being used to serve pages, writes $data to the persistent file with name $filename. Saves a copy in the RAM cache if there is a copy already there.

Parameters

string $filename

name of file to write to persistent storages

string $data

string of data to store in file

createIfNecessaryDirectory()

createIfNecessaryDirectory(string  $directory) : integer

Creates a directory and sets it to world permission if it doesn't aleady exist

Parameters

string $directory

name of directory to create

Returns

integer —

-1 on failure, 0 if already existed, 1 if created

formatSinglePageResult()

formatSinglePageResult(array  $page, array  $words = null, integer  $description_length = self::DEFAULT_DESCRIPTION_LENGTH) : array

Given a page summary, extracts snippets which are related to a set of search words. For each snippet, bold faces the search terms, and then creates a new summary array.

Parameters

array $page

a single search result summary

array $words

keywords (typically what was searched on)

integer $description_length

length of the description

Returns

array —

$page which has been snippified and bold faced

getSnippets()

getSnippets(string  $text, array  $words, string  $description_length) : string

Given a string, extracts a snippets of text related to a given set of key words. For a given word a snippet is a window of characters to its left and right that is less than a maximum total number of characters.

There is also a rule that a snippet should avoid ending in the middle of a word

Parameters

string $text

haystack to extract snippet from

array $words

keywords used to make look in haystack

string $description_length

length of the description desired

Returns

string —

a concatenation of the extracted snippets of each word

boldKeywords()

boldKeywords(string  $text, array  $words) : string

Given a string, wraps in bold html tags a set of key words it contains.

Parameters

string $text

haystack string to look for the key words

array $words

an array of words to bold face

Returns

string —

the resulting string after boldfacing has been applied

getDbmsList()

getDbmsList() : array

Gets a list of all DBMS that work with the search engine

Returns

array —

Names of available data sources

loginDbms()

loginDbms(string  $dbms) : boolean

Returns whether the provided dbms needs a login and password or not (sqlite or sqlite3)

Parameters

string $dbms

the name of a database management system

Returns

boolean —

true if needs a login and password; false otherwise

isSingleLocalhost()

isSingleLocalhost(array  $machine_urls, string  $index_timestamp = -1) : boolean

Used to determine if an action involves just one yioop instance on the current local machine or not

Parameters

array $machine_urls

urls of yioop instances to which the action applies

string $index_timestamp

if timestamp exists checks if the index has declared itself to be a no network index.

Returns

boolean —

whether it involves a single local yioop instance (true) or not (false)

translateDb()

translateDb(string  $string_id, string  $locale_tag) : mixed

Used to get the translation of a string_id stored in the database to the given locale.

Parameters

string $string_id

id to translate

string $locale_tag

to translate to

Returns

mixed —

translation if found, $string_id, otherwise

getUserId()

getUserId(string  $username) : string

Get the user_id associated with a given username (In base class as used as an internal method in both signin and user models)

Parameters

string $username

the username to look up

Returns

string —

the corresponding userid

searchArrayToWhereOrderClauses()

searchArrayToWhereOrderClauses(array  $search_array, array  $any_fields = array('status')) : array

Creates the WHERE and ORDER BY clauses for a query of a Yioop table such as USERS, ROLE, GROUP, which have associated search web forms. Searches are case insensitive

Parameters

array $search_array

each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by

array $any_fields

these fields if present in search array but with value "-1" will be skipped as part of the where clause but will be used for order by clause

Returns

array —

string for where clause, string for order by clause

getRows()

getRows(integer  $limit, integer  $num, \seekquarry\yioop\models\int&  $total, array  $search_array = array(), array  $args = null) : array

Gets a range of rows which match the provided search criteria from $th provided table

Parameters

integer $limit

starting row from the potential results to return

integer $num

number of rows after start row to return

\seekquarry\yioop\models\int& $total

gets set with the total number of rows that can be returned by the given database query

array $search_array

each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by

array $args

additional values which may be used to get rows (what these are will typically depend on the subclass implementation)

Returns

array

selectCallback()

selectCallback(mixed  $args = null) : string

Controls which columns and the names of those columns from the tables underlying the given model should be return from a getRows call.

This defaults to *, but in general will be overriden in subclasses of Model

Parameters

mixed $args

any additional arguments which should be used to determine the columns

Returns

string —

a comma separated list of columns suitable for a SQL query

fromCallback()

fromCallback(mixed  $args = null) : string

Controls which tables and the names of tables underlie the given model and should be used in a getRows call This defaults to the single table whose name is whatever is before Model in the name of the model. For example, by default on FooModel this method would return "FOO". If a different behavior, this can be overriden in subclasses of Model

Parameters

mixed $args

any additional arguments which should be used to determine these tables

Returns

string —

a comma separated list of tables suitable for a SQL query

whereCallback()

whereCallback(mixed  $args = null) : string

Controls the WHERE clause of the SQL query that underlies the given model and should be used in a getRows call.

This defaults to an empty WHERE clause.

Parameters

mixed $args

additional arguments that might be used to construct the WHERE clause.

Returns

string —

a SQL WHERE clause

rowCallback()

rowCallback(string  $locale, mixed  $args) : \seekquarry\yioop\models\$locale

This is called after each row is retrieved by getRows. This method Then reads in the corresponding statistics.txt file (or rebuilds it from the Configure.ini file if it is out of date) to add to the row percent translated info.

For example, in CrawlModel, after a row representing a crawl mix has been gotten, this is used to perform an additional query to marshal its components. By default this method just returns this row unchanged.

Parameters

string $locale

one getRows row corresponding to a given locale

mixed $args

additional arguments that might be used for this method (none used for this sub-class)

Returns

\seekquarry\yioop\models\$locale —

row with PERCENT_WITH_STRINGS field added

postQueryCallback()

postQueryCallback(array  $rows) : array

Called after getRows has retrieved all the rows that it would retrieve but before they are returned to give one last place where they could be further manipulated. For example, in MachineModel this callback is used to make parallel network calls to get the status of each machine returned by getRows. The default for this method is to leave the rows that would be returned unchanged

Parameters

array $rows

that have been calculated so far by getRows

Returns

array —

$rows after this final manipulation

initialize()

initialize(string  $locale_tag) 

Loads the provided locale's configure file (containing transalation) and calls setlocale to set up locale specific string formatting (to format numbers, etc.)

Parameters

string $locale_tag

the tag of the locale to use as the current locale

getLocaleList()

getLocaleList(boolean  $only_active = true, boolean  $only_db_info = true) : array

Returns information about available locales

Parameters

boolean $only_active

says whether to return info only about active locales (true) or about all locales (false);

boolean $only_db_info

only get database information about the locale, skip calculating percent translated

Returns

array —

rows of locale information

checkLocaleExists()

checkLocaleExists(string  $locale_tag) : boolean

Check if there is a locale with tag equal to $locale_tag

Parameters

string $locale_tag

to check for

Returns

boolean —

whether or not has exists

getLocaleInfo()

getLocaleInfo(string  $locale_tag) : string

Returns the locale name, tag, and writing mode for tag $locale_tag

Parameters

string $locale_tag

to get name for

Returns

string —

name of locale

getLocaleName()

getLocaleName(string  $locale_tag) : string

Returns the name of the locale for tag $locale_tag

Parameters

string $locale_tag

to get name for

Returns

string —

name of locale

addLocale()

addLocale(string  $locale_name, string  $locale_tag, string  $writing_mode, integer  $active = 1) 

Adds information concerning a new locale to the database

Parameters

string $locale_name

the name of the locale in the locale's language

string $locale_tag

the IANA langauge tag for the locale

string $writing_mode

a combination of the horizontal and vertical text direction used for writing in the locale

integer $active

whether the locale is current active (>0) or not used (== 0)

deleteLocale()

deleteLocale(string  $locale_tag) 

Remove a locale from the database

Parameters

string $locale_tag

the IANA language tag for the locale to remove

updateLocaleInfo()

updateLocaleInfo(array  $locale_info) 

Used to update the fields stored in a LOCALE row according to an array holding new values

Parameters

array $locale_info

updated values for a LOCALE row

getStringData()

getStringData(string  $locale_tag) : array

For each translatable identifier string (either static from a configure ini file, or dynamic from the db) return its name together with its translation into the given locale if such a translation exists.

Parameters

string $locale_tag

the IANA language tag to translate string into

Returns

array —

rows of identfier string - translation pairs

updateStringData()

updateStringData(string  $locale_tag, array  $new_strings) 

Updates the identifier_string-translation pairs (both static and dynamic) for a given locale

Parameters

string $locale_tag

the IANA language tag to update the strings of

array $new_strings

rows of identifier string - translation pairs

translate()

translate(array  $arr) : mixed

Translate an array consisting of an identifier string together with additional variable parameters into the current locale.

Suppose the identifier string was some_view_fraction_received and two additional arguments 5 and 10 were given. Suppose further that its translation into the current locale (say en_US) was "%s out of %s". Then the string returned by translate would be "5 out of 10".

Parameters

array $arr

an array consisting of an identifier string followed optionally by parameter values.

Returns

mixed —

the translation of the identifier string into the current locale where all %s have been replaced by the corresponding parameter values. Returns false if no translation

getLocaleTag()

getLocaleTag() : string

Get the current IANA language tag being used by the search engine

Returns

string —

an IANA language tag

getLocaleDirection()

getLocaleDirection() : string

The text direction of the current locale being used by the text engine

Returns

string —

either ltr (left-to-right) or rtl (right-to-left)

getBlockProgression()

getBlockProgression() : string

The direction that blocks (such as p or div tags) should be drawn in the current locale

Returns

string —

a direction which is one of tb -- top-bottom, rl -- right-to-left, or lr -- left-to-right

getWritingMode()

getWritingMode() : string

Get the writing mode of the current locale (text and block directions)

Returns

string —

the current writing mode

extractMergeLocales()

extractMergeLocales(array  $force_folders = array()) : array

Used to extract identifier strings from files with correct extensions, then these strings are merged with existing extracted strings for each locale as well as their translations (if an extract string has a translation the translation is untouched by this process).

Parameters

array $force_folders

which locale subfolders should be forced updated to the fallback dir's version

Returns

array —

a pair consisting of the data from the General.ini file together with an array of msg_ids msg_strings.

updateLocales()

updateLocales(array  $general_ini, array  $strings, array  $force_folders = array()) 

Cycles through locale subdirectories in LOCALE_DIR, for each locale it merges out the current general_ini and strings data.

It deletes identifiers that are not in strings, it adds new identifiers and it leaves existing identifier translation pairs untouched.

Parameters

array $general_ini

data that would typically come from the General.ini file

array $strings

lines from what is equivalent to an ini file of msg_id msg_string pairs these lines also have comments on the file that strings were extracted from

array $force_folders

which locale subfolders should be forced updated to the fallback dir's version

updateLocale()

updateLocale(array  $general_ini, array  $strings, string  $dir, string  $locale, array  $new_configure = null, array  $force_folders = array()) 

Updates the Configure.ini file and static pages for a particular locale.

The Configure.ini has general information (at this point not really being used) about all locales together with specific msg_id (identifiers to be translated) and msg_string (translation) data. updateLocale takes line data coming from the General.ini file, strings extracted from documents that might need to be translation, the old Configure.ini file (this might have existing translations), as well as new translation data that might come from a localizer via a web form and combines these to produce a new Configure.ini file

Parameters

array $general_ini

data from the General.ini file

array $strings

line array data extracted from files in directories that have strings in need of translation

string $dir

the directory of all the locales

string $locale

the particular locale in $dir to update

array $new_configure

translations of identifier strings from another source such as a localizer using a web form

array $force_folders

which locale subfolders should be forced updated to the fallback dir's version

updateTranslation()

updateTranslation(array  $new_configure, array  $old_configure, array  $fallback_configure, string  $string_id, string  $default_value = "") : string

Computes a string of the form string_id = 'translation' for a string_id from among translation array data in $new_configure (most preferred, probably come from recent web form data), $old_configure (probably from work dir), and $fallback_configure (probably from base dir of Yioop instance, least preferred).

Parameters

array $new_configure

string_id => translation pairs

array $old_configure

string_id => translation pairs

array $fallback_configure

string_id => translation pairs

string $string_id

an id to translate

string $default_value

value to use if no configuration has a translation for a string_id

Returns

string —

translation in format describe above

lookupTranslation()

lookupTranslation(array  $new_configure, array  $old_configure, array  $fallback_configure, string  $string_id, string  $default_value = "") : string

Translates a string_id from among translation array data in $new_configure (most preferred, probably come from recent web form data), $old_configure (probably from work dir), and $fallback_configure (probably from base dir of Yioop instance, least preferred).

Parameters

array $new_configure

string_id => translation pairs

array $old_configure

string_id => translation pairs

array $fallback_configure

string_id => translation pairs

string $string_id

an id to translate

string $default_value

value to use if no configuration has a translation for a string_id

Returns

string —

translation of string id

isTranslated()

isTranslated(string  $string_id, array  $translations = false) : boolean

Checks if the given string_id has a translation in translations

Parameters

string $string_id

what to check if translated

array $translations

of form string_id => translation defaults to current configuration

Returns

boolean —

whether a translation of nonzero length exists

updateLocaleSubFolder()

updateLocaleSubFolder(string  $locale_pages_path, string  $fallback_pages_path, array  $file_extensions) 

Copies over subfolder items of the correct file extensions which exists in a fallback directory, but not in the actual directory of a locale.

Parameters

string $locale_pages_path

static page directory to which will copy

string $fallback_pages_path

static page directory from which will copy

array $file_extensions

an array of strings names of file extensions for example: .txt.gz .thtml .php ,etc

getTranslateStrings()

getTranslateStrings(array  $extract_dirs, array  $extensions) : array

Searches the directories provided looking for files matching the extensions provided. When such a file is found it is loaded and scanned for tl() function calls. The identifier string in this function call is then extracted and added to a line array of strings to be translated.

This line array is formatted so that each line looks like a line that might occur in an PHP ini file. To understand this format one can look at the parse_ini_string function in the PHP manual or look at the Configure.ini files in the locale directory

Parameters

array $extract_dirs

directories to start looking for files with strings to be translated

array $extensions

file extensions of files which might contain such strings

Returns

array —

of lines for any ini file of msg_id msg_string pairs

traverseExtractRecursive()

traverseExtractRecursive(string  $dir, array  $extensions) : array

Traverses a directory and its subdirectories looking for files whose extensions come from the extensions array. As the traversal is done a strings array is created. Each time a file is found of any identifiers of strings that need to be translated are added to the strings array. In addition, ini style comments are added givne the line file and line number of the item to be translated

Parameters

string $dir

current directory to start looking for files with strings to be translated

array $extensions

file extensions of files which might contain such strings

Returns

array —

of lines for any ini file of msg_id msg_string pairs