Yioop_V9.5_Source_Code_Documentation

ProfileModel extends Model
in package

This is class is used to handle getting and saving the Profile.php of the current search engine instance

Tags
author

Chris Pollett

Table of Contents

DEFAULT_DESCRIPTION_LENGTH  = 150
Default maximum character length of a search summary
MAX_SNIPPET_TITLE_LENGTH  = 20
MIN_SNIPPET_LENGTH  = 100
SNIPPET_LENGTH_LEFT  = 20
SNIPPET_LENGTH_RIGHT  = 40
SNIPPET_TITLE_LENGTH  = 20
$any_fields  : array<string|int, mixed>
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
$cache  : object
Cache object to be used if we are doing caching
$create_statements  : array<string|int, mixed>
Associative array (table_name => SQL statement to create that table for the pubblic database) List is alphabetical and contains all Yioop tables. List is only initialized after an @see initializeSql call.
$db  : object
Reference to a DatasourceManager
$db_name  : string
Name of the search engine database
$edited_page_summaries  : array<string|int, mixed>
Associative array of page summaries which might be used to override default page summaries if set.
$file_fields  : array<string|int, mixed>
Profile fields which are stored in wiki or in a flat file
$private_create_statements  : array<string|int, mixed>
Associative array (table_name => SQL statement to create that table for the private database) List is alphabetical and contains all Yioop tables. List is only initialized after an @see initializeSql call.
$private_db  : object
Reference to a private DatasourceManager
$private_db_name  : string
Name of the private search engine database
$profile_fields  : array<string|int, mixed>
These are fields whose values might be set in a Yioop instance Profile.php file
$search_table_column_map  : array<string|int, mixed>
Associations of the form name of field for web forms => database column names/abbreviations
$web_site  : object
Reference to a WebSite object in use to serve pages (if any)
__construct()  : mixed
Sets up the database manager that will be used and name of the search engine database
boldKeywords()  : string
Given a string, wraps in bold html tags a set of key words it contains.
createDatabaseTables()  : bool
On a blank database this method create all the tables necessary for Yioop less those on a skip list
createDatabaseTablesPrivate()  : bool
On a blank database this method create all the tables necessary for private Yioop less those on a skip list
createIfNecessaryDirectory()  : int
Creates a directory and sets it to world permission if it doesn't already exist
deleteTheme()  : mixed
Deletes the CSS theme with the provided name
fileGetContents()  : 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.
filePutContents()  : mixed
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.
formatSinglePageResult()  : array<string|int, mixed>
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.
fromCallback()  : 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 overridden in subclasses of Model
getDbmsList()  : array<string|int, mixed>
Gets a list of all DBMS that work with the search engine
getProfile()  : array<string|int, mixed>
Reads a profile from a Profile.php file in the provided directory
getRows()  : array<string|int, mixed>
Gets a range of rows which match the provided search criteria from $th provided table
getSnippets()  : 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.
getThemeNames()  : array<string|int, mixed>
Get a list of auxliary stylesheets which can be applied in addition to the default stylesheet across the site and which can be used to control the styling of individual wiki pages.
getUserId()  : 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)
initializeSql()  : mixed
Used to construct $this->create_statements, the list of all SQL CREATE statements needed to build a Yioop database
initializeSqlPrivate()  : mixed
Used to construct $this->private_create_statements, the list of all SQL CREATE statements needed to build Yioop private database
isSingleLocalhost()  : bool
Used to determine if an action involves just one yioop instance on the current local machine or not
loginDbms()  : bool
Returns whether the provided dbms needs a login and password or not (sqlite or sqlite3)
makeWorkDirectory()  : mixed
Creates a folder to be used to maintain local information about this instance of the Yioop/SeekQuarry engine
matchDefine()  : string
Finds the first occurrence of define('$defined', something) in $string and returns something
migrateDatabaseIfNecessary()  : bool
Check if $dbinfo provided the connection details for a Yioop/SeekQuarry database. If it does provide a valid db connection but no data then try to recreate the database from the default copy stored in /data dir.
postQueryCallback()  : array<string|int, mixed>
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
rowCallback()  : array<string|int, mixed>
Called after as row is retrieved by getRows from the database to perform some manipulation that would be useful for this model.
searchArrayToWhereOrderClauses()  : array<string|int, mixed>
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
selectCallback()  : string
Controls which columns and the names of those columns from the tables underlying the given model should be return from a getRows call.
setWorkDirectoryConfigFile()  : mixed
Modifies the config.php file so the WORK_DIRECTORY define points at $directory
testDatabaseManager()  : mixed
Checks if $dbinfo provides info to connect to an working instance of app db.
translateDb()  : mixed
Used to get the translation of a string_id stored in the database to the given locale.
updateProfile()  : mixed
Outputs a Profile.php file in the given directory containing profile data based on new and old data sources
whereCallback()  : string
Controls the WHERE clause of the SQL query that underlies the given model and should be used in a getRows call.

Constants

DEFAULT_DESCRIPTION_LENGTH

Default maximum character length of a search summary

public mixed DEFAULT_DESCRIPTION_LENGTH = 150

MAX_SNIPPET_TITLE_LENGTH

public mixed MAX_SNIPPET_TITLE_LENGTH = 20

MIN_SNIPPET_LENGTH

public mixed MIN_SNIPPET_LENGTH = 100

SNIPPET_LENGTH_LEFT

public mixed SNIPPET_LENGTH_LEFT = 20

SNIPPET_LENGTH_RIGHT

public mixed SNIPPET_LENGTH_RIGHT = 40

SNIPPET_TITLE_LENGTH

public mixed SNIPPET_TITLE_LENGTH = 20

Properties

$any_fields

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

public array<string|int, mixed> $any_fields = []

$cache

Cache object to be used if we are doing caching

public static object $cache

$create_statements

Associative array (table_name => SQL statement to create that table for the pubblic database) List is alphabetical and contains all Yioop tables. List is only initialized after an @see initializeSql call.

public array<string|int, mixed> $create_statements

$db

Reference to a DatasourceManager

public object $db

$db_name

Name of the search engine database

public string $db_name

$edited_page_summaries

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

public array<string|int, mixed> $edited_page_summaries = null

$file_fields

Profile fields which are stored in wiki or in a flat file

public array<string|int, mixed> $file_fields = ["AUXILIARY_CSS", "ROBOT_DESCRIPTION"]

$private_create_statements

Associative array (table_name => SQL statement to create that table for the private database) List is alphabetical and contains all Yioop tables. List is only initialized after an @see initializeSql call.

public array<string|int, mixed> $private_create_statements

$private_db

Reference to a private DatasourceManager

public object $private_db

$private_db_name

Name of the private search engine database

public string $private_db_name

$profile_fields

These are fields whose values might be set in a Yioop instance Profile.php file

public array<string|int, mixed> $profile_fields = ['AD_LOCATION', 'API_ACCESS', 'AUTH_KEY', 'AUTOLOGOUT', 'AUXILIARY_CSS', 'AUXILIARY_CSS_NAME', 'BACKGROUND_COLOR', 'BACKGROUND_IMAGE', 'CACHE_LINK', 'CAPTCHA_MODE', 'CLD_URL_BONUS', 'CONFIGURE_BOT', 'COOKIE_LIFETIME', 'CSRF_TOKEN', 'DEBUG_LEVEL', 'DEFAULT_CONTINUOUS_SCROLL', 'DB_HOST', 'DBMS', 'DB_NAME', 'DB_PASSWORD', 'DB_USER', 'DEFAULT_LOCALE', 'DIFFERENTIAL_PRIVACY', 'FAVICON', 'FOREGROUND_COLOR', 'GLOBAL_ADSCRIPT', 'GROUP_ITEM', 'GROUP_ANALYTICS_MODE', 'HOST_KEYWORD_BONUS', 'HOST_URL_BONUS', 'IN_LINK', 'IP_LINK', 'LANDING_PAGE', 'LOGO_SMALL', 'LOGO_MEDIUM', 'LOGO_LARGE', 'MAIL_PASSWORD', 'MAIL_SECURITY', 'MAIL_SENDER', 'MAIL_SERVER', 'MAIL_SERVERPORT', 'MAIL_USERNAME', 'MIN_RESULTS_TO_GROUP', 'MONETIZATION_TYPE', 'MORE_RESULT', 'MEDIA_MODE', 'NAME_SERVER', 'NUM_SLASHES_BONUS', 'PATH_KEYWORD_BONUS', 'PRIVATE_DB_NAME', 'PRIVATE_DB_HOST', 'PRIVATE_DBMS', 'PRIVATE_DB_PASSWORD', 'PRIVATE_DB_USER', 'PROXY_SERVERS', 'PROXIMITY_BONUS', 'RECOVERY_MODE', 'REGISTRATION_TYPE', 'RESULT_SCORE', 'ROBOT_INSTANCE', 'RSS_ACCESS', 'SEARCH_ANALYTICS_MODE', 'SEARCHBAR_PATH', 'SEND_MAIL_MEDIA_UPDATER', 'SERP_FAVICONS', 'SESSION_NAME', 'SIDE_ADSCRIPT', 'SIDEBAR_COLOR', 'SIGNIN_LINK', 'SIMILAR_LINK', 'SUBSEARCH_LINK', 'TITLE_BONUS', 'TIMEZONE', 'TOPBAR_COLOR', 'TOP_ADSCRIPT', 'TOR_PROXY', 'USE_FILECACHE', 'USE_MAIL_PHP', 'USE_PROXY', 'USER_AGENT_SHORT', 'USER_RANK_BONUS', 'WEB_URI', 'WEB_ACCESS', 'WIKI_BONUS', 'WORD_CLOUD', 'WORD_SUGGEST']

$search_table_column_map

Associations of the form name of field for web forms => database column names/abbreviations

public array<string|int, mixed> $search_table_column_map = []

$web_site

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

public object $web_site

Methods

__construct()

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

public __construct([string $db_name = CDB_NAME ][, bool $connect = true ]) : mixed
Parameters
$db_name : string = CDB_NAME

the name of the database for the search engine

$connect : bool = true

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

Return values
mixed

boldKeywords()

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

public boldKeywords(string $text, array<string|int, mixed> $words) : string
Parameters
$text : string

haystack string to look for the key words

$words : array<string|int, mixed>

an array of words to bold face

Return values
string

the resulting string after boldfacing has been applied

createDatabaseTables()

On a blank database this method create all the tables necessary for Yioop less those on a skip list

public createDatabaseTables(object $dbm, array<string|int, mixed> $dbinfo[, array<string|int, mixed> $skip_list = [] ]) : bool
Parameters
$dbm : object

a DatabaseManager open to some DBMS and with a blank database selected

$dbinfo : array<string|int, mixed>

name of database, host, user, and password

$skip_list : array<string|int, mixed> = []

an array of table or index names not to bother creating

Return values
bool

whether all of the creates were successful or not

createDatabaseTablesPrivate()

On a blank database this method create all the tables necessary for private Yioop less those on a skip list

public createDatabaseTablesPrivate(object $dbm, array<string|int, mixed> $dbinfo[, array<string|int, mixed> $skip_list = [] ]) : bool
Parameters
$dbm : object

a DatabaseManager open to some DBMS and with a blank database selected

$dbinfo : array<string|int, mixed>

name of database, host, user, and password

$skip_list : array<string|int, mixed> = []

an array of table or index names not to bother creating

Return values
bool

whether all of the creates were successful or not

createIfNecessaryDirectory()

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

public createIfNecessaryDirectory(string $directory) : int
Parameters
$directory : string

name of directory to create

Return values
int

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

deleteTheme()

Deletes the CSS theme with the provided name

public deleteTheme(string $theme_name) : mixed
Parameters
$theme_name : string

name of the theme to delete

Return values
mixed

fileGetContents()

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.

public fileGetContents(string $filename[, bool $force_read = false ]) : string

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
$filename : string

name of file to get contents of

$force_read : bool = false

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

Return values
string

contents of the file given by $filename

filePutContents()

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.

public filePutContents(string $filename, string $data) : mixed
Parameters
$filename : string

name of file to write to persistent storages

$data : string

string of data to store in file

Return values
mixed

formatSinglePageResult()

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.

public formatSinglePageResult(array<string|int, mixed> $page[, array<string|int, mixed> $words = null ][, int $description_length = self::DEFAULT_DESCRIPTION_LENGTH ]) : array<string|int, mixed>
Parameters
$page : array<string|int, mixed>

a single search result summary

$words : array<string|int, mixed> = null

keywords (typically what was searched on)

$description_length : int = self::DEFAULT_DESCRIPTION_LENGTH

length of the description

Return values
array<string|int, mixed>

$page which has been snippified and bold faced

fromCallback()

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 overridden in subclasses of Model

public fromCallback([mixed $args = null ]) : string
Parameters
$args : mixed = null

any additional arguments which should be used to determine these tables

Return values
string

a comma separated list of tables suitable for a SQL query

getDbmsList()

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

public getDbmsList() : array<string|int, mixed>
Return values
array<string|int, mixed>

Names of available data sources

getProfile()

Reads a profile from a Profile.php file in the provided directory

public getProfile(string $work_directory) : array<string|int, mixed>
Parameters
$work_directory : string

directory to look for profile in

Return values
array<string|int, mixed>

associate array of the profile fields and their values

getRows()

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

public getRows(int $limit, int $num, int &$total[, array<string|int, mixed> $search_array = [] ][, array<string|int, mixed> $args = null ]) : array<string|int, mixed>
Parameters
$limit : int

starting row from the potential results to return

$num : int

number of rows after start row to return

$total : int

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

$search_array : array<string|int, mixed> = []

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

$args : array<string|int, mixed> = null

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

Return values
array<string|int, mixed>

getSnippets()

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.

public getSnippets(string $text, array<string|int, mixed> $words, string $description_length) : string

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

Parameters
$text : string

haystack to extract snippet from

$words : array<string|int, mixed>

keywords used to make look in haystack

$description_length : string

length of the description desired

Return values
string

a concatenation of the extracted snippets of each word

getThemeNames()

Get a list of auxliary stylesheets which can be applied in addition to the default stylesheet across the site and which can be used to control the styling of individual wiki pages.

public getThemeNames() : array<string|int, mixed>
Return values
array<string|int, mixed>

list of the available css themes

getUserId()

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

public getUserId(string $username) : string
Parameters
$username : string

the username to look up

Return values
string

the corresponding userid

initializeSql()

Used to construct $this->create_statements, the list of all SQL CREATE statements needed to build a Yioop database

public initializeSql(object $dbm, array<string|int, mixed> $dbinfo) : mixed
Parameters
$dbm : object

a datasource_manager object used to get strings for autoincrement and serial types for a given db

$dbinfo : array<string|int, mixed>

connect info for the database, also used in getting autoincrement and serial types

Return values
mixed

initializeSqlPrivate()

Used to construct $this->private_create_statements, the list of all SQL CREATE statements needed to build Yioop private database

public initializeSqlPrivate(object $dbm, array<string|int, mixed> $dbinfo) : mixed
Parameters
$dbm : object

a datasource_manager object used to get strings for autoincrement and serial types for a given db

$dbinfo : array<string|int, mixed>

connect info for the database, also used in getting autoincrement and serial types

Return values
mixed

isSingleLocalhost()

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

public isSingleLocalhost(array<string|int, mixed> $machine_urls[, string $index_timestamp = -1 ]) : bool
Parameters
$machine_urls : array<string|int, mixed>

urls of yioop instances to which the action applies

$index_timestamp : string = -1

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

Return values
bool

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

loginDbms()

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

public loginDbms(string $dbms) : bool
Parameters
$dbms : string

the name of a database management system

Return values
bool

true if needs a login and password; false otherwise

makeWorkDirectory()

Creates a folder to be used to maintain local information about this instance of the Yioop/SeekQuarry engine

public makeWorkDirectory(string $directory) : mixed

Creates the directory provides as well as subdirectories for crawls, locales, logging, and sqlite DBs.

Parameters
$directory : string

path and name of directory to create

Return values
mixed

matchDefine()

Finds the first occurrence of define('$defined', something) in $string and returns something

public matchDefine(string $defined, string $string) : string
Parameters
$defined : string

the constant being defined

$string : string

the haystack string to search in

Return values
string

matched value of define if exists; empty string otherwise

migrateDatabaseIfNecessary()

Check if $dbinfo provided the connection details for a Yioop/SeekQuarry database. If it does provide a valid db connection but no data then try to recreate the database from the default copy stored in /data dir.

public migrateDatabaseIfNecessary(array<string|int, mixed> $dbinfo[, array<string|int, mixed> $skip_list = [] ]) : bool
Parameters
$dbinfo : array<string|int, mixed>

has fields for DBMS, DB_USER, DB_PASSWORD, DB_HOST and DB_NAME

$skip_list : array<string|int, mixed> = []

an array of table or index names not to bother creating or copying

Return values
bool

returns true if can connect to/create a valid database; returns false otherwise

postQueryCallback()

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

public postQueryCallback(array<string|int, mixed> $rows) : array<string|int, mixed>
Parameters
$rows : array<string|int, mixed>

that have been calculated so far by getRows

Return values
array<string|int, mixed>

$rows after this final manipulation

rowCallback()

Called after as row is retrieved by getRows from the database to perform some manipulation that would be useful for this model.

public rowCallback(array<string|int, mixed> $row, mixed $args) : array<string|int, mixed>

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
$row : array<string|int, mixed>

row as retrieved from database query

$args : mixed

additional arguments that might be used by this callback

Return values
array<string|int, mixed>

$row after callback manipulation

searchArrayToWhereOrderClauses()

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

public searchArrayToWhereOrderClauses(array<string|int, mixed> $search_array[, array<string|int, mixed> $any_fields = ['status'] ]) : array<string|int, mixed>
Parameters
$search_array : array<string|int, mixed>

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

$any_fields : array<string|int, mixed> = ['status']

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

Return values
array<string|int, mixed>

string for where clause, string for order by clause

selectCallback()

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

public selectCallback([mixed $args = null ]) : string

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

Parameters
$args : mixed = null

any additional arguments which should be used to determine the columns

Return values
string

a comma separated list of columns suitable for a SQL query

setWorkDirectoryConfigFile()

Modifies the config.php file so the WORK_DIRECTORY define points at $directory

public setWorkDirectoryConfigFile(string $directory) : mixed
Parameters
$directory : string

folder that WORK_DIRECTORY should be defined to

Return values
mixed

testDatabaseManager()

Checks if $dbinfo provides info to connect to an working instance of app db.

public testDatabaseManager(array<string|int, mixed> $dbinfo) : mixed
Parameters
$dbinfo : array<string|int, mixed>

has field for DBMS, DB_USER, DB_PASSWORD, DB_HOST and DB_NAME

Return values
mixed

returns true if can connect to DBMS with username and password, can select the given database name and that database seems to be of Yioop/SeekQuarry type. If the connection works but database isn't there it attempts to create it. If the database is there but no data, then it returns a resource for the database. Otherwise, it returns false.

translateDb()

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

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

id to translate

$locale_tag : string

to translate to

Return values
mixed

translation if found, $string_id, otherwise

updateProfile()

Outputs a Profile.php file in the given directory containing profile data based on new and old data sources

public updateProfile(string $directory, array<string|int, mixed> $new_profile_data, array<string|int, mixed> $old_profile_data[, bool $reset = false ]) : mixed

This function creates a Profile.php file if it doesn't exist. A given field is output in the profile according to the precedence that a new value is preferred to an old value is preferred to the value that comes from a currently defined constant. It might be the case that a new value for a given field doesn't exist, etc.

Parameters
$directory : string

the work directory to output the Profile.php file

$new_profile_data : array<string|int, mixed>

fields and values containing at least some profile information (only $this->profile_fields fields of $new_profile_data will be considered).

$old_profile_data : array<string|int, mixed>

fields and values that come from presumably a previously existing profile

$reset : bool = false

whether the new profile data is coming from a reset to factory settings or not

Return values
mixed

whereCallback()

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

public whereCallback([mixed $args = null ]) : string

This defaults to an empty WHERE clause.

Parameters
$args : mixed = null

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

Return values
string

a SQL WHERE clause


        

Search results