API

misc classes

Note

tbc

generalclass

This is the main wordpress plugin class and contains a range of important/necessary methods for the data handling, website content, and so far and so on. This class will be extended by both, the adminclass and userclass shown later.

class wetterturnier_generalclass

General-class which is used by the main class, the adminclass and the userclass. Contains a wide range of functions.

property $version
property $date_format
property $datetime_format
property $current_tournament
get_current_cityObj()

The current city is used in varous scripts and methods. Not to load the same information multiple times I am using this method to load the current city once from the database. The information (a @ref wetterturnier_cityObject object) will be stored on the private attribute current_cityObj. If the attribute is NULL load the information once. If not NULL return the object.

@return Returns a @ref wetterturnier_cityObject object with the active city.

init_options()

@details Initialize wordpress options. Loads a set of wetterturnier related options from the wordpress options database table and returns a stdClass object containing these options.

@return stdClass object containing all options as specified in the array $names inside this method.

plugins_url($pluginname = wp-wetterturnier)

Quick-access to the plugins url for the wp-wetterturnier plugin (returns the path to the plugin). Wrapper around the wordpress-function plugins_url.

@param $pluginname. String, default is wp-wetterturnier (name of the plugin). @return Returns (string) the path to the plugin.

load_current_tournament_once()

Save ‘next tournament’ once. Used in various positions, e.g., the widgets.

number_format($value, $decimals = 2)

An own number_format function to print well formatted numbers (integers and floating point numbers). The wetterturnier plugin offers some user defined options (See wetterturnier plugin backend settings) where the thousand separator and decimal separator can be specified. These specifications are stored.

@param $value. Numeric value which has to be formatted.

@param $decimals. Integer, default is 2. Number of decimal
values. Can also be 0.

@return Returns a string containing the formatted number.

register_css_files()

Adding css files (array) to the head of the wordpress theme. Uses the public attribute $version to add a version string to overcome browser caching issues.

register_js_files()

Adding js files (array) to the head of the wordpress. Uses the public attribute $version to add a version string to overcome browser caching issues.

register_js_file($file)

Adding js files to the head of the wordpress.

@param $file. Name of the javascript file without postfix!

include_js_script($name)

Including a js script file outside the wordpress header. Wont call wp_register_script, but includes the js file whereever you need. Using this for special jquery functions only needed for some special purposes, as e.g., the synopsymbols page. Benefit: the synopsymbols-jQuery code is not loaded globally whenever a wordpress page will be opened which reduces the response time. Drawback: only available where included. Therefore some js scripts (e.g., used for the navigation) will be registered in wordpress to make them available everywhere.

@param $file. Name of the javascript file without postfix!

get_user_language($value = slug)

Returns current language if pll (polylang plugin) is active. Else use en_US as default language.

@param $value. String, default is slug. If set to slug
the language slug will be returned (e.g., en or de). Can also be set to name. If set to name the language name will be returned (e.g., en_US, de_DE).

@todo Reto: if $vlaue is not slug or name: problem?

set_locale($locale = false)

Setting locale based on the active polylang slug

load_float_format()

Depending on the current language configuration (based on the polylang plugin if active) the floating point number format is specified here. Saves a stdClass object into the parent class called float_format. This is mainly used by the @ref number_format method.

@see number_format

@see load_date_format

@see load_datetime_format

load_date_format()

The wetterturnier plugins also allows to define language specific date formats. Based on the polylang plugin (if active) the date format will be loaded as set in the wetterturnier admin backend. If not found or polylang is inactive, the default format %Y-%m-%d will be used. Saves the date_format into the parent class and is used to create user-friendly date format output on the frontend.

@see load_float_format

@see load_datetime_format

load_datetime_format()

The wetterturnier plugins also allows to define language specific datetime formats. Based on the polylang plugin (if active) the date format will be loaded as set in the wetterturnier admin backend. If not found or polylang is inactive, the default format %Y-%m-%d %H:%M:%S will be used. Saves the datetime_format into the parent class and is used to create user-friendly datetime format output on the frontend.

@see load_float_format

@see load_date_format

convert_tdate($tdate, $fmt = %Y-%m-%d %H:%M:%S)

Converting $tdate (days sincd 1970-01-01) to the format specified. Can be used for specific date conversion like e.g., to print the day of the week or something.

@param $tdate. Integer representation of the date.

@param $fmt. String, format (see php date() manual). Default Return format is %Y-%m-%d %H:%M:%S

@return Returns string with the date in the format specified.

date_format($tdate, $fmt = NULL)

Small helper class to convert a tournament date into a string given a certain format.

@param $tdate. Integer, days since 1970-01-01.

@param $fmt. Format. Either a string (see php date manual page for more details) or NULL. If NULL the date_format will be used (@ref load_date_format).

@see datetime_format

@see number_format

datetime_format($tdate, $fmt = NULL)

Small helper class to convert a timestamp into a string given a certain format.

@param $tdate. Integer, seconds since 1970-01-01.

@param $fmt. Format. Either a string (see php date manual page for more details) or NULL. If NULL the datetime_format will be used (@ref load_datetime_format). @see datetime_format

@see number_format

Returns the web-link to the terms and conditions pages which can be defined via the wetterturnier plugin settings page in the admin backend.

insertonduplicate($table, $data, $updatecol = array(), $useprepare = True)

Small insert or update workaround for wordpress as a insert on duplicate update method is not yet implemented in the wordpress core.

@param $table. Name of the database table.

@param $data. Array which consists of key/value pairs where the key specifies the name of the column in the database while value defines the value which should be inserted.

next_tournament($row_offset, $check_access = true, $dayoffset, $backwards = false)
@details Checks which one is the next tournament date
dayoffset can be used to get ‘todays tournament’
@param $row_offset. Default is 0. Can be set to (any)
if set to 1 the function won’t return the next tournament but the one after. Please have a look to input $backwards. If backwards=true this $row_offset can be used to get the previous rather than the upcoming tournament.
@param $check_access. Boolean, default is true. Checks
whether the visitor has access to the data of this tournament. This is important as we don’t want the user to see the bets/forecasts of other competitors before the bet form is closed and the tournament has been started.

@param $dayoffset. Default 0.

@param $backwards. Boolean, default false. If false
we are looking forward in time if e.g., $row_offset is set. If true we are looking/searching backwards to e.g., get the last tournament date rather than the next.
@return Returns a stdClass object containing the requrested
tournament date and some more information (e.g., wheter the user has access to the data for the requested tournament date or the dates of the bet days where the forecasts will be placed and so far and so on.

@see next_tournament @see current_tournament @see latest_tournament @see older_tournament @see newer_tournament

current_tournament($row_offset, $check_access = true, $dayoffset = UnaryOp(u'-', 2), $backwards = false)

@details This method is based on @ref next_tournament and returns the current/last turnament. This is used to show current bets/observations. @param $row_offset. Positive integer, default 0 (no row offset)

@param $check_access. Boolean, default true.

@param $dayoffset. Integer, default -2. We are forecasting two days at the moment. $dayoffset-2 uses ‘today - 2 days’ to find the current tournament.

@see next_tournament @see latest_tournament @see older_tournament @see newer_tournament

@todo Reto should use the ‘number of bet days’ variable rather than this fixed number of -2.

latest_tournament($tdate)

This method is based on @ref next_tournament and returns the latest (last) tournament based on $tdate. Please check the next_tournament method to see what $tdate can be (either “day_offset” or explicit “tournament date”). @param Please check the @ref next_tournament method to see what $tdate

can be (either “day_offset” or explicit “tournament date”).

@see next_tournament @see current_tournament @see older_tournament @see newer_tournament

older_tournament($tdate)

This method is based on @ref next_tournament and returns the tournament before the one specified by input $tdate.

@param Please check the @ref next_tournament method to see what $tdate can be (either “day_offset” or explicit “tournament date”).

@see next_tournament @see current_tournament @see latest_tournament @see newer_tournament

newer_tournament($tdate)

This method is based on @ref next_tournament and returns the tournament after thie current one (so the next upcoming one) depending on the input $tdate.

@param Please check the @ref next_tournament method to see what $tdate can be (either “day_offset” or explicit “tournament date”).

@see next_tournament @see current_tournament @see latest_tournament @see older_tournament

check_bet_is_submitted($userID, $cityObj, $tdate)

We allow the user to enter and save the forecasts partially. As soon as all required fields are provided (all forecasts filled in and submitted) the wetterturnier plugin appends a row in the betstat database table. Note that this line will be deleted if the user decides to delete one or more values and stores them as empty. This function checks wheter the row in the betstat table exists or not. If it exists the function will return true, else false (not submitted or only partially submitted). @param $userID. Integer, numeric ID of the user. @param $cityObj. Object of class @wetterturnier_cityObject. @param $tdate. Integer, date of the tournament. @return Returns true if the user successfully submitted the forecast (all values) and false else.

check_user_is_in_group($userID, $groupName)

Checks whether the current user is in a specific group or not (is group member). @param $userID. Integer, numeric ID of the user. @param $groupName. Name of the group to check. @return Returns true if the user is a member of the group and false` else.

get_groups_for_user($userID)

Returns names of the groups the user is a member of.

@param $userID. Integer, numeric user ID.

@return Returns false if the user is not yet a member of
at least one group and a stdClass object containing the group ID and group names for all groups where the user is a member of.
get_user_by_ID($userID)

@details Returns a stdClass object with all information about a certain user specified by it’s numeric ID.

@param $userID. Integer, numeric user ID.

@return stdClass containing the detailed user information.

@see get_user_by_username

get_user_by_username($username)

@details Returns user details based on user login name. Not case sensitive.

@param $username. String containing the user login name.

@return stdClass containing the detailed user information.

@see get_user_by_ID

get_user_display_class_and_name($userID, $usr)

Sometimes I have to add a special userclass to some elements to display them as I want. Therefore there is a small method returning the userclass based on the uderID and the user_login name. The same yields for the username. We replace some special character strings with another string. e.g. GRP_ will be replaced but then we add [group] to the end.

@param $userID. Integer, numeric user ID.

@param $user_login. String containing the user_login name.

@return stdClass containing two strings. userclass contains the main class (automat, referenz, mitteltip, or Sleepy), username the modified username.

Returns the link to the profile page of the player. @param $usr. Wordpress user object. @return Returns <a href=…>…</a> tag with the link to the user profile (currently to bbpress /forum/users/<username>).

check_view_is_closed($tdate)

Function which checks if we can show the bet-form or not. If user is allowed to see the data, function returns true. Else return value is false and the function places some notes.

@param $tdate. Integer date value of a certain tournament.

@return Prints a message and returns true if the view is closed and we do not allow the user to retreive the data at the moment (maybe locked because the tournament has not been started yet). or false (not locked) if to grant access.

@see check_allowed_to_display_betdata

check_allowed_to_display_betdata($tdate, $showinfo = true)

Function which checks if we can show the placed bets/archive data If user is allowed to see the data, function returns true. Else return value is false and the function places some notes.

@param $tdate. Integer date value of a certain tournament.

@param $showinfo. Boolean, default true. If set to false the user-messages “sorry not access” are suppressed. This is used to not show the messages twice for two consecutive days.

@return Prints a message and returns true if the view is closed and we do not allow the user to retreive the data at the moment (maybe locked because the tournament has not been started yet). or false (not locked) if to grant access.

@see check_view_is_closed

get_param_by_ID($ID)

Returns parameter details from the database given a parameter ID.

@param $ID. Integer, numeric parameter ID. @return Returns stdClass object with all the information

in the corresponding row in the database or boolean false if the parameter cannot be found.
get_param_by_name($paramName)

Returns parameter details from the database given a parameter name (e.g., RR, Wn, Wv, …).

@return Returns stdClass object with all the information in the corresponding row in the database or boolean false if the parameter cannot be found.

get_param_ID($name)

Returns the numeric parameter ID given the parameter name as specified in the database.

@param $name. String, name of the parameter in the database.

@return Integer parameter ID or boolean false if the parameter cannot be found.

get_param_names()

Returns an array of objects containing all pairs of paramID and paramName (numeric parameter ID and name) as specified in the database. @return See description :).

tournament_date_status($tdate)

Returns status of a scheduled wetterturnier date.

@param $tdate. Integer representation of the tournament date. @return Returns boolean false if the date is not registered in the database (no status; neither ‘there will be a tournament’ nor ‘take care, there will be no tournament’). Else an integer will be returned: 1 = upcoming tournament, 2 = day without a tournament (or kind of a ‘no, there is defenitively no tournament!).

tournament_get_dates()

@details Loading all tournament dates from the database which have been specified explicitly. Status 1 means that there is or will be a tournament, 2 means that there will be no tournament (even if some would expect one). All others (not in database) are ‘no tournament’ as well, but not explicitly labeled as ‘no tournament’.

@return Array of stdClass objects containing tdate (numeric representation of the tournament date) and status.

get_param_data()

@details Returns the parameters and the parameter information from the database. The description depends on the current language.

@return Array of stdClass objects containing the necessary
information including parameter ID, name, number format, description, and unit.
@todo What happens if the user uses a language which is not
defined? This is not a very general way of storing this information …
get_current_city()

Returns city ID based on the city hash from the $_SESSIONS variable (is forced to be registered when loading the wetterturnier plugin - should exist all the time)

@param Returns object from @ref get_city_info of the current city based on the user session.

@see get_city_info

@see get_current_city_id

get_current_city_id()

Returns numeric cityID from the current city. Please note that—in contrast to @ref get_current_city—this function only returns the cityID.

@return Integer city ID of the active city.

@see get_city_info

@see get_current_city

get_all_cityObj($activeonly = true)

Returns an array containing @ref wetterturnier_cityObject objects. The input controls whether only active cities should be returned (typically used for user-frontend pages) or all (used for admin pages).

@param $activeonly. Boolean, default true. If set to true only active cities will be considered. If false inactive will be returned as well.

@see get_current_cityObj

get_city_info($input)

Returns city info based on the city hash from the city hash (e.g., IBK, BER, …) OR the ID of the city. If input is integer, select for ID, else for hash.

@param $input. Either numeric city ID or string. If string it has to be the city hash (e.g., IBK). Returns a stdClass object containing the city information.

get_all_stationObj($cityID = NULL)

@details Loading information of all active stations. An array will be returned containing a stationObject for each station. If cityID is given the stations of a specific city will be returned. If not given (NULL, default) all active stations will be returned.

@param $cityID. Integer city ID, default is NULL.

@return Returns NULL if no stations are found in the database.
Else an array of stationObjects will be returned.

@see wetterturnier_stationObject

get_station_wmo_for_city($cityID)

Returns the station numbers of the stations which are attached to this city.

@param $cityID. Integer city ID.

@return array of stdClass objects containing wmo only (the numeric WMO station number as specified in the database).

@see get_station_data_for_city

@see get_station_by_wmo

get_station_data_for_city($cityID)

Loading observation data for a given cityID (both stations)

@param $cityID. Integer city ID.

@return array of stdClass Objects containing the detailed station
information of all stations mapped to the city ($cityID).

@see get_station_wmo_for_city @see get_station_by_wmo

get_station_by_wmo($wmo)

Loading observation data for a given cityID (both stations)

@param $mo. Integer station number (WMO identifier).

@return Returns stdClass object containing the details of this
specific station.

@see get_station_wmo_for_city @see get_station_data_for_city

curPageURL($cut = False)

Getting current page url in a propper way.

@param $cut. Boolean, default is false. If set to true the POST arguments will be removed from the url.

@return Returns the current URL with or without POST args.

get_user_bets_from_db($cityObj, $userID, $next, $day, $detailed = false)

Loading allready stored data from the user from the database.

@param $cityObj. Object of class @ref wetterturnier_cityObject.

@param $userID. Numeric user ID.

@param $next. Object containing the tournament date information of the next (or upcoming) tournament.

@param $day. Integer which specifies for which day you want to load the forecast data. E.g., $day=1 would be the 1-day-ahead forecast leading to a bdate or ‘betdate’ of $next->tdate + 1.

@param $detailed. Boolean, default is false. If true additional elements will be returned such as parameter name and stuff.

@return A stdClass containing stdClassses identified by a combination of the parameter name and the forecast day. E.g., $result->RR_1 contians the information for RR day 1.

get_bet_values($city, $tdate, $betday, $points, $userID = NULL)

Loading bets from the database based on: cityID, tdate and betdate (integer, +1/+2) If input $pionts is true, loading points from database.

get_station_obs_from_db($stnObj, $next, $day, $detailed = false)

Loading allready stored observation values

@param $stnObj. Object of class @ref wetterturnier_stationObject.

get_obs_from_db($station, $tournament, $day)

Returns the observations in the same format as get_user_bets_from_db returns the bets. Need them for the edit forms when someone would like to change observation values.

get_obs_values($city, $betdate, $raw = false)

Loading observation data for a given cityID (both stations).

tournament_datepicker_widget()

Datepicker code for the widget

tournament_datepicker_ajax()
usersearch_ajax()

There is an ajax function call to save users which try to apply for a group membership. Returns json array. If user is allready an active member of this group, return value ‘got’ is ‘ismember’.

get_avatar_url($userID)

Getting avatar url instead of a full avatar imgi tag.

REQUEST_CHECK($name)

REQUEST_CHECK is checking if the requested variable is set or not. In case not, we will return ‘false’.

getobservations_ajax($statnr = Null)

Returns the latest observations for a given station. Called by wordpress ajax.

adminclass

The adminclass builds on generalclass (extends the generalclass) and provides a set of admin-specific functions and attributes. These are only for the wordpress admin-interface.

class wetterturnier_adminclass

The adminclass contains all the functions needed to offer the wordpress admin backend. Or at leas it is planned to put all the functions into this file :).

property $css_dir
property $css_files
property $js_files
property $options
__construct()

constructor method, loading admin menu items

enqueue_date_picker()

Enables the datepicker ui core plugin for the admin interface (to set up forms with date fields and a visual date selector).

disable_display_name_settings()

hide display name in profiles

add_admin_cap()

Adding capabilities to the administrator role

set_rerun_request()

If an admin changes either a bet or observation we have to recompute the points if the tournament date is not the current tournament date. If it is the cronjob will do it aniways.

tournament_datepicker_admin()

Datepicker for the admin interface

add_admin_menu()

adding the admin menus for the Wordpress Wetterturnier plugin

admin_show_plugin_info()
admin_show_settings()
admin_show_scheduler()
admin_show_deactivateusers()
admin_show_groups()
admin_show_groupusers()
admin_show_application()
admin_show_cities()
admin_show_stations()
admin_show_param()
admin_show_webcams()
admin_show_bets()
admin_show_obs()
admin_show_api()
admin_show_rerunrequests()
show_station_select($cityID, $number = false, $sel = false)

Add station select $sel is optional. If set it has to be a station ID means that this station is currently selected and should be shown as the selected option for this select box.

station_is_in_use($wmo)

Returns true or fals if a wmo station is in use of a city or not.

userclass

The userclass builds on generalclass (extends the generalclass) and provides a set of frontend-specific methods. This class is used for visitors (not logged in users), members (logged in users) and administrators as long as they browse on the frontend.

class wetterturnier_userclass

The userclass contains all the necessary functions for the frontend pages shown when visiting the wordpress page.

property $cities
property $css_dir
property $css_files
property $js_dir
property $js_files
property $options
__construct()

constructor method

wt_add_ajax_admin()
random_string($length = 10, $prefix)

Helper function to create a random string. @param $length int, default is 10. Length of the string to be returned. @param $prefix str, string prefix.

disable_display_name_settings()

Hide display name in profiles

wt_custom_user_options($user)

Adding special wetterturnier options to the user profile or settings page.

@param $user is a stdClass object containing the user Information.

wt_save_custom_user_options($user_id)

There is a @ref method called wt_custom_user_option which adds custom settings to the user profile page. This method saves the options to the database.

@param $user_id. Integer user ID of the active user.

check_is_admin()

Function which will be executed as soon as wordpress is loaded. Checks whether user is admin when logged in. Sets private attribute $this->is_admin to true.

is_admin()

Wrapper function for wordpress is_admin function.

@return Returns boolean attribute $this->is_admin.
wetterturnier_registration_form()

Append terms and conditions flag during registration

show_wetterturnier_user_profile()
add_cities_nav()

Load js script snippet, manipulate, return and add to header

wetterturnier_add_tooltip_js()

Loadaing wetterturnier.bet.tooltip.js and manipulate content. Add this (js) to the head of the wordpress.

initialize_cities_menu()

load defined cities

add_wetterturnier_bet_validate_js()

Load js script snippet, manipulate, return and add to header

city_check()

Check which city is choosen

logincheck()

workaround function, only call it after init! add_action(‘init’,’logincheck’). Returns bool value.

shortcode_wetterturnier_linkcollection()

In-page registration shortcode

shortcode_wetterturnier_register()

In-page registration shortcode

shortcode_wetterturnier_synopsymbols()

Wetterturnier synop symbol overview.

shortcode_wetterturnier_mapsforecasts()

Wetterturnier forecast and analysis map navigation

shortcode_wetterturnier_mapsanalysis()
shortcode_wetterturnier_archive()

Wetterturnier show archive list and values. Note: ob caches the “print output” of the functions in between ob_start and ob_end. We have to return the content to replace the [wetterturnier xxxx] shortcodes in the pages.

shortcode_wetterturnier_current($args)

Wetterturnier show current values (bet/obs), last tournament Note: ob caches the “print output” of the functions in between ob_start and ob_end. We have to return the content to replace the [wetterturnier xxxx] shortcodes in the pages.

shortcode_wetterturnier_groups()

Wetterturnier groups shows the groups and its users. Note: ob caches the “print output” of the functions in between ob_start and ob_end. We have to return the content to replace the [wetterturnier xxxx] shortcodes in the pages.

shortcode_wetterturnier_applygroup()

There is a special form where users can apply theirselves to get member of a group. An administrator has to check the promotion and approve or delete the promotion.

shortcode_wetterturnier_bet()

Wetterturnier groups shows the groups and its users. Note: ob caches the “print output” of the functions in between ob_start and ob_end. We have to return the content to replace the [wetterturnier xxxx] shortcodes in the pages.

shortcode_wetterturnier_ranking($args)

The wetterturnier has different ranking tables like daily rankings, seasonal ranking, total ranking, and some more. This is a function including differnt ranking types, and also offers a set of options (if the user would like to change what will be shown).

shortcode_wetterturnier_exportobslive()

Referer to the dataexport

shortcode_wetterturnier_exportobsarchive()
shortcode_wetterturnier_googlecharts()

Statistics interfaces. There are some based on R, others are purely php based.

shortcode_wetterturnier_obsimages()

Obs images

shortcode_wetterturnier_obstable()

Observation table

shortcode_wetterturnier_meteogram()

Show GEFS Meteograms and Meteogram data And the MOS forecasts

shortcode_wetterturnier_meteogramdata()
shortcode_wetterturnier_mosforecasts()
shortcode_wetterturnier_judgingform($args)

Forward to bbpress profile if we can find the user name. Note: ob caches the “print output” of the functions in between ob_start and ob_end. We have to return the content to replace the [wetterturnier xxxx] shortcodes in the pages.

shortcode_wtcode($args, $content)

Frontend

shortcode_wetterturnier_stationinfo()

List of cities/stations and the corresponding stations. Used in frontend (rules/spielregeln).

shortcode_wetterturnier_stationparamdisabled()

Frontend output to show which parameters of each station are neglected! Used in frontend (rules/spielregeln).

shortcode_include($file, $args = NULL)

Function used for the shortcodes - includes the file using buffering. Returns the content which should replace the shortcode in the pages.

scored_players_per_town($tdate)

Counting how many players already got points for a certain tournament date for each city. The method is used for some applications where the current leading players will be shown. If there are no points for any of the players, it does not make a lot of sense to show the “ranking of the ongoing tournament” bur rather show the “ranking of the last tournament”.

print_group_table($id, $group, $users, $inactive)

Used to display the group-lists

@details Prints the table of a certain group and its members. @param $inactive. Bool. If true this indicates that there are inactive users in the group.

archive_show_bet_data()

Loading all tournament dates stored in the db ever for this city (based on the bets, not on the obs. Should change that probably).

archive_show_colorlegend()

Displays the ‘color legend’ which shows the color mapping in the bet tables and allows the user to show/hide a certain type of players (e.g., mitteltips or automaten). Is a bit static, however, works.

archive_show_ranking_weekend()

Show total points for a given weekend with additional link to the archive to see the single parameter points if somewone is interested in that.

archive_show($type, $tdate, $points = false, $showday = False)

Show archive and/or current data If input $pionts is true, loading points from database.

show_bet_data_rows($data, $number, $type, $points = false, $editable = false, $tdate)

Show archive and/or current data

create_edit_button($type, $cityObj, $identifier, $tdate)

Function to add the ‘edit’ button to observations and bets if an admin is logged in.

get_average_points($cityID = False, $tdate = False)

Loading average points from database

get_sleepy_points($cityID = False, $tdate = False)

Loading current sleepy points

applygroup_ajax()

There is an ajax function call to save users which try to apply for a group membership. Returns json array. If user is allready an active member of this group, return value ‘got’ is ‘ismember’.

ranking_ajax()

There is an ajax function call to save users which try to apply for a group membership. Returns json array. If user is allready an active member of this group, return value ‘got’ is ‘ismember’.

judging_ajax()

This is a small ajax script I am using to call an Rscript on the prognose server. Used for different R-Calls WARNING: only integer values as arguments allowed.

wttable_show_details_ajax()

Used for the ranking-frontend: display details of a certain user. Dynamically loaded via an ajax call.

callRscript_ajax()

This is a small ajax script I am using to call an Rscript on the prognose server. Used for different R-Calls WARNING: only integer values as arguments allowed.

access_denied()

Some pages are restricted for logged in users only. Instead of using wordpress ‘private’ pages (which will result in a 404: page not found if the user is not logged in) we are using this small method. If a user is not logged in, an access denied message will be shown. Return value ‘true’ in this case. else the return value will be ‘false’, and nothing will be shown.

show_leading($city = NULL, $tdate = NULL, $number = 3, $style = NULL)

Shows the leading players of the current or ongoing tournament.

@param $city. If NULL (default) the current or active city will be used. Can also be a string (city hash) or numeric value (city ID). Details see

@ref wetterturnier_generalclass::get_current_cityObj

@param $tdate. Numeric representation of the tournament date. If NULL the current tournament will be used.

@param $number. Positive integer. Number of players which should be shown. Default is 3.

@param $style. Default NULL. Can be set to ‘wide’ for a landscape rather than a portrait representation.

obsdb_get_avaliable_stations($table = archive)

Loading available stations (and their dates) from the obs databases. Either ‘obs.live’ or ‘obs.archive’.

cityObject

Handling the different cities defined in the wetterturnier.

class wetterturnier_cityObject

A class to handle city information. Loads and stores information from the *_wetterturnier_cities database table. Whenever possible objects of this type will be called cityObj within the php code.

@param $init (mixed)
If numeric it will be interpreted as station ID, if the input is of type string the city `HASH and name of the city will be checked.

Please also check the two classes wetterturnier_stationObject and wetterturnier_paramObject.

__construct($init = NULL)
get($key)

Main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
name of the property you would like to get, e.g., ID or name.
@return Returns false if the value does not exist or the value of
the corresponding element if existing.
show()

Helper class for development. Print on standard out.

stations()

Returns the station information of this cityObject. Information loaded by _load_stations during the initialization of this object.

@return An array of wetterturnier_stationObject objects.

getParams()

Return parameter object array from first station, they are the same (except the ‘active’ flag which is killed in here) for all stations.

@return Returns an array of wetterturnier_paramObject.

stationObject

Handling single weather stations.

class wetterturnier_stationObject

A class to handle station information. Each city (see wetterturnier_cityObject) can have one or more stations attached to it. Should be called $stnObj whenever possible in the php code!

@param $init (numeric)
depending on the input argument by this is either the station ID or station wmo identification number.
@param $by (str)
default is ID, can also be set to wmo to initialize a new object via WMO station number.

Please also check the two classes wetterturnier_cityObject and wetterturnier_paramObject.

__construct($init, $by = ID)
showActiveParams($active = true)

Helper function, returns a string with all active parameters.

@param $active (bool)
Boolean, default true for showActiveParams. showInactiveParams (which is only a wrapper) uses $active=false to return inactive parameters, showInactiveParams.

@return Character string with active parameters.

showInactiveParams()

Helper function, returns a string with all inactive parameters. See also showActiveParams.

@return Character string with inactive parameters.

getParams()

Returns the parameter array containing paramObjects.

@return Array of @see wetterturnier_paramObjects.

showParamCheckboxes()

Helper function for the admin interface. Showas checkboxes for the parameters.

@return Html code for the checkboxes. Each parameter gets a box which
is either checked if active or not checked if inactive.
get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
ame of the property you would like to get, e.g., ID or name.

@return Returns false or the value of the element with the corresponding key.

show()

Helper class for development. Shows loaded key/value. Prints on stdout.

paramObject

Handling the different parameters (e.g., minimum temperature, or pressure at 12 UTC).

class wetterturnier_paramObject

A class to handle parameter information.

@param $init (numeric)
depending on input parameter $by this is either the parameter ID (numeric) r parameter shortname of the parameter (str).
@param $by (str)
default is ‘ID’. Allowed are ‘ID’ or ‘paramName’.
@param $tdate (int)
tournament date (days since 1970-01-01), default is NULL. if NULL the current date/time is used. If given the system is checking whether the parameter was active for $tdate or not. This changes the outcome of the isParameterActive method of this class.

Please also check the two classes wetterturnier_cityObject and wetterturnier_stationObject.

__construct($init, $by = ID, $tdate = NULL)
isParameterActive($stationID)

Checks if the parameter is active for a specific station.

@param $stationID (numeric)
station identifier ID.
@return Boolean True if parameter is active for station
$stationID and false else.
setActive($to)

Allows to overrule the ‘active’ flag in the object.

get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
name of the property you would like to get, e.g., ID or name.

@return Returns false or the value of the element with the corresponding key.

show()

Helper class for development. Shows loaded key/value. Print on stdout.

webcamObject

Small object to handle the webcams for the different cities (webcam image implementation).

class wetterturnier_webcamObject

A class to handle webcam information. Loads and stores information from the *_wetterturnier_webcams database table. Whenever possible objects of this type will be called $webcamObj within the php code.

@param $ID (int)
ID (as in the database) of the webcam to be loaded/prepared.
__construct($ID)
get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (string)
name of the property you would like to get, e.g., ID or uri.

@return Returns false or the value of the element with the corresponding key.

display_webcam()

Prints html to display the webcam image.

show()

Helper class for development purposes. Print on stdout.

groupsObject

Handling of groups. A group consists of several members/users and is used to generate the Mitteltipps (mean group bets).

class wetterturnier_groupsObject
This is a small class for group handling.
During initialization all groups will be loaded. The class contains some methods to load users (active/inactive) among the groups which is used to display e.g., the group tables.
__construct()
iteritems()

Returns all groups as array, often used in foreach loops to iterate over all available groups. Thus, this method is called iteritems.

@return Returns an array with all groups.

get_members($groupID)

For a given groupID the members will be returned.

@param $groupID (int)
ID (as in the database) of the group.
@return Returns boolean False if the group cannot be found.
Else a list of stdClass objects will be returned containing the required information about the user/users in the group.
show_frontend_tables()

Shows the frontend tables. No inputs, uses the object information loaded in the __construct method. Information on active/inactive status: active = 0: is inactive; active = 1: is active; active = 8: is active, but the user has an open ‘remove me from group’ request; active = 9: not yet in the group but a ‘add me to the group’ request open.

latestobsObject

Class to read observation data from the obs database table. Please note that database is hardcoded in the php code (database table called obs). The wordpress mysql user requires read permissions to be able to get these data. The objects can be returned as JSON arrays and are used for some wetterturnier jQuery plugins (observation tables and plots).

To grant the correct privileges to the wordpress user simply login to your database and give the correct user the following permissions:

GRANT SELECT ON obs.* TO 'wpwt'@'localhost';
FLUSH PRIVILEGES;
class wetterturnier_latestobsObject

A small class to load latest observations from the obs database. Loading data and description from the obs database table. Requires read access on the obs.* tables!

@param $stnObj (wetterturnier_stationObject)
object containing the station information for which the observation data should be loaded.
@param $from (Null or int)
Either Null (default) or a unix time stamp. Has to be numeric! Details see _load_latest_obs_from_db_.
@param $to (Null or int)
Either Null (default) or a unix time stamp. If set in combination with $from has to be larger than $from! Details _load_latest_obs_from_db_.
@param $limit (Null or int)
Either Null or a positiv numeric integer value. If set $limit rows will be loaded.
__construct($stnObj, $from = Null, $to = Null, $limit = Null)
_load_description_from_db()

Loading the bufrdescription information from the database. This contains the parameter description and it’s scaling/descaling values.

get_desc($param, $value = Null)

Returns parameter description for a given parameter $param. If parameter cannot be found or value is not available a None will be returned.

@param $param (str)
name of the observed parameter.
@param $value (misc)
Default Null, if Null the whole object for the $param will be returned. If set only this specific value will be returned if existing.
@return Returns parameter $value for $parmater if both inputs
are set or the object for $param if $value = Null. If not existing a Null will be returned.
get_value($param, $offset = Null, $format = Null)

Returns a value from the data set loaded. If offset is not given the first (newest) value will be returned.

@param $param (str)
String, name of the observed parameter.
@param $offset (Null or int)
Either Null or a positive integer. If e.g., set to $offset=1 the second last value will be returned if available.
@param $format (Null or str)
Default Null, if set the value will be converted and returned as string.

@return Returns observed value or Null if not available.

has_data()

Helper function, returns true if the object contains data and false if not.

@return Boolean true or false whether the object contains data or not.

nobs()

Helper function, returns number of loaded data sets.

@return Returns number (int) of loaded observations.

get_json($encode = true)

Create and return json array.

@param $encode (bool)
Default true, can be set to false, only for development purposes, du not use it in your code.
@return If $encode is set to false
the array will be returned which will be converted to a json array with the default input $encode = true.
get_json_d3($encode = true)

Create and return json array.

@param $encode. Default true, can be set to false, only for development purposes, du not use it in your code.

@return If $encode is set to false
the array will be returned which will be converted to a json array with the default input $encode = true.
show()

Helper function to show/print the content of this object. Mainly designed for development purposes. Prints output on stdout.

oldoutputformat

Note

This was a quick fix which not yet works (Jan 2018) we have the method Moses which relies of the forecasts of the latest few weeks. After moving our server the files are no more available in the same format. This class (in combination with the file oldarchive.php is mimiking the old ASCII format for the upper part of the data. Either Moses needs more, or he never downloads he new files as he cannot find the file listing on which he relies?

Called and only called from oldarchive.php. The server uses a .htaccess rewrite rule provide this mimiked files under the same old url. The rewrite condition is as follows:

RewriteBase /
RewriteRule ^archiv/wert_([a-z])/wert([0-9]{6})\.txt$ wp-content/plugins/wp-wetterturnier/oldarchive.php?city=$1&date=$2 [L,NC]
class wetterturnier_oldoutputObject

A helper class returning the ranking/points/bets from the last weekend. This file (only the upper part at the moment) looks exactely like the ASCII files before 2018 and can be accessed under the same URL’s using .htaccess redirects. The idea was that Moses comes back to life, however, the last two weeks this didn’t happen. This class is used solely by oldarchive.php in the same directory.

__construct($cityObj, $tdate, $days = 2)

Object constructor.

@param object $cityObj Object of class @ref wetterturnier_cityObject for which the data should be returned.

@param integer $tdate Tournament date as days since 1970-01-01 representation.

@param integer $days Number of days, default is 2, the current setting.

show()

This is the main function which proces the output. No extra inputs needed, all we need was already processed in the class __construct method. Note that I’ve removed two Umlaute (non utf-8 characters). They break my sphinx! And I am quite sure no one searches for non utf-8 to get the data position.