SNIPPET_TITLE_LENGTH
SNIPPET_TITLE_LENGTH
Used to encapsulate information about a locale (data about a language in a given region).
__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
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(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
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 |
contents of the file given by $filename
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.
string | $filename | name of file to write to persistent storages |
string | $data | string of data to store in file |
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.
array | $page | a single search result summary |
array | $words | keywords (typically what was searched on) |
integer | $description_length | length of the description |
$page which has been snippified and bold faced
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
string | $text | haystack to extract snippet from |
array | $words | keywords used to make look in haystack |
string | $description_length | length of the description desired |
a concatenation of the extracted snippets of each word
boldKeywords(string $text, array $words) : string
Given a string, wraps in bold html tags a set of key words it contains.
string | $text | haystack string to look for the key words |
array | $words | an array of words to bold face |
the resulting string after boldfacing has been applied
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
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. |
whether it involves a single local yioop instance (true) or not (false)
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
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 |
string for where clause, string for order by clause
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
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) |
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
mixed | $args | any additional arguments which should be used to determine the columns |
a comma separated list of columns suitable for a SQL query
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
mixed | $args | any additional arguments which should be used to determine these tables |
a comma separated list of tables suitable for a SQL query
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.
mixed | $args | additional arguments that might be used to construct the WHERE clause. |
a SQL WHERE clause
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.
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) |
row with PERCENT_WITH_STRINGS field added
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
array | $rows | that have been calculated so far by getRows |
$rows after this final manipulation
getLocaleList(boolean $only_active = true, boolean $only_db_info = true) : array
Returns information about available locales
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 |
rows of locale information
addLocale(string $locale_name, string $locale_tag, string $writing_mode, integer $active = 1)
Adds information concerning a new locale to the database
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) |
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.
string | $locale_tag | the IANA language tag to translate string into |
rows of identfier string - translation pairs
updateStringData(string $locale_tag, array $new_strings)
Updates the identifier_string-translation pairs (both static and dynamic) for a given locale
string | $locale_tag | the IANA language tag to update the strings of |
array | $new_strings | rows of identifier string - translation pairs |
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".
array | $arr | an array consisting of an identifier string followed optionally by parameter values. |
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
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).
array | $force_folders | which locale subfolders should be forced updated to the fallback dir's version |
a pair consisting of the data from the General.ini file together with an array of msg_ids msg_strings.
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.
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(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
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(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).
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 |
translation in format describe above
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).
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 |
translation of string id
isTranslated(string $string_id, array $translations = false) : boolean
Checks if the given string_id has a translation in translations
string | $string_id | what to check if translated |
array | $translations | of form string_id => translation defaults to current configuration |
whether a translation of nonzero length exists
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.
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(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
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 |
of lines for any ini file of msg_id msg_string pairs
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
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 |
of lines for any ini file of msg_id msg_string pairs