| 1 | == API functions == |
| 2 | |
| 3 | |
| 4 | API function means all functions that you can use for your XML Server application work. These are all functions from "'''modules/global/inc/apiFunctions.inc.php'''" and "'''modules/global/inc/customFunctions.inc.php'''" files. |
| 5 | |
| 6 | "'''apiFunctions.inc.php'''" file contains unchangeable functions, and "'''customFunctions.inc.php'''" contains functions that depend on script structure (integrational functions). By default these functions are configured for "Dolphin" script. |
| 7 | |
| 8 | |
| 9 | "'''apiFunctions.inc.php'''" file functions: |
| 10 | |
| 11 | 1. '''parseXml''' |
| 12 | |
| 13 | {{{ |
| 14 | /** |
| 15 | * Parse XML template using specified information. |
| 16 | * @param aXmlTemplates - array with XML templates grouped by type. |
| 17 | * @param ... - variable amount of incoming parameters with information to be used in the process of |
| 18 | parsing. |
| 19 | * @return $sContent - XML entry |
| 20 | */ |
| 21 | function parseXml($aXmlTemplates){ ... } |
| 22 | }}} |
| 23 | |
| 24 | This function accepts the XML entry template, inserts the given values and returns the resulting XML entry: |
| 25 | |
| 26 | {{{ |
| 27 | $aXmlTemplates = array ( |
| 28 | "result" => array ( |
| 29 | 1 => "<result value=\"#1#\" />", |
| 30 | 2 => "<result value=\"#1#\" status=\"#2#\" />" |
| 31 | ) |
| 32 | ); |
| 33 | $sContents = parseXml($aXmlTemplates["result"], "some_value", "success"); |
| 34 | echo $sContents; |
| 35 | /////////////////// |
| 36 | <result value="some_value" status="success" /> |
| 37 | }}} |
| 38 | |
| 39 | 2. '''makeGroup''' |
| 40 | |
| 41 | {{{ |
| 42 | /** |
| 43 | * Group specified content. |
| 44 | * @param sXmlContent - content to be grouped. |
| 45 | * @param sXmlGroup - group name. |
| 46 | */ |
| 47 | function makeGroup($sXmlContent, $sXmlGroup = "ray"){ ... } |
| 48 | }}} |
| 49 | |
| 50 | This function accepts some XML content that should be grouped, group name and returns the grouped XML entries: |
| 51 | |
| 52 | {{{ |
| 53 | $sEntries = "<item value=\"some_value\" /><item value=\"another_value\" />"; |
| 54 | $sContents = makeGroup($sEntries,"items"); |
| 55 | echo $sContents; |
| 56 | /////////////////// |
| 57 | <items><item value="some_value" /><item value="another_value" /></items> |
| 58 | }}} |
| 59 | |
| 60 | 3. '''setSettingValue''' |
| 61 | |
| 62 | {{{ |
| 63 | /** |
| 64 | * Saves the setting value in the config.xml file of the specified widget. |
| 65 | * @param sWidget - widget's name. |
| 66 | * @param sSettingKey - setting's key. |
| 67 | * @param sSettingValue - new value for specified setting. |
| 68 | */ |
| 69 | function setSettingValue($sWidget, $sSettingKey, $sSettingValue){ ... } |
| 70 | }}} |
| 71 | |
| 72 | This function sets the value of a given key setting in a given widget configuration file |
| 73 | |
| 74 | {{{ |
| 75 | ([widget_name]/xml/config.xml): |
| 76 | [some_widget]/xml/config.xml before: |
| 77 | <items><item key="some_key"><![CDATA[some_value]]></item></items> |
| 78 | setSettingValue("some_widget", "some_key", "another_value"); |
| 79 | [some_widget]/xml/config.xml after: |
| 80 | <items><item key="some_key"><![CDATA[another_value]]></item></items> |
| 81 | }}} |
| 82 | |
| 83 | 4. '''getSettingValue''' |
| 84 | |
| 85 | {{{ |
| 86 | /** |
| 87 | * Gets the setting value from config.xml file. |
| 88 | * @param sWidget - widget's name. |
| 89 | * @param $sSettingKey - setting's name. |
| 90 | */ |
| 91 | function getSettingValue($sWidget, $sSettingKey, $bFullReturn = false){ ... } |
| 92 | }}} |
| 93 | |
| 94 | This function gets the value of a given key setting from a given widget configuration file |
| 95 | |
| 96 | {{{ |
| 97 | ([widget_name]/xml/config.xml): |
| 98 | [some_widget]/xml/config.xml: |
| 99 | <items><item key="some_key"><![CDATA[some_value]]></item></items> |
| 100 | $sValue = getSettingValue("some_widget", "some_key"); |
| 101 | $aValue = getSettingValue("some_widget", "some_key", true); |
| 102 | echo $sValue; |
| 103 | print_r($aValue); |
| 104 | ///////////////////// |
| 105 | some_value |
| 106 | Array('value' => "some_value", 'status' => "success") |
| 107 | }}} |
| 108 | |
| 109 | 5. '''getRMSUrl''' |
| 110 | |
| 111 | {{{ |
| 112 | /** |
| 113 | * returns the RMS Url to the given application |
| 114 | * @param sApplication - application name. |
| 115 | * @return sRMSUrl - RMS Url. |
| 116 | */ |
| 117 | function getRMSUrl($sApplication){ ... } |
| 118 | }}} |
| 119 | |
| 120 | This function returns the full url to the RMS application by given server application name: |
| 121 | |
| 122 | {{{ |
| 123 | $sRMSUrl = getRMSUrl("chat"); |
| 124 | echo $sRMSUrl; |
| 125 | ///////////////////// |
| 126 | rtmp://195.132.156.124:1935/chat/ |
| 127 | }}} |
| 128 | |
| 129 | 6. '''updateOnline''' |
| 130 | |
| 131 | {{{ |
| 132 | /** |
| 133 | * Update online users |
| 134 | * Clear TrackUsers table if it is necessary. |
| 135 | * @param sId - user ID to update status |
| 136 | * @param sStatus - user new status |
| 137 | */ |
| 138 | function updateOnline($sId = "", $sStatus = ""){ ... } |
| 139 | }}} |
| 140 | |
| 141 | This function updates online status for a user with a given ID and resets his online status, if there is one. Status can be "offline"/"online". It also deletes all tracks for users that exceed the delete timeout. |
| 142 | |
| 143 | |
| 144 | 7. '''getOnline''' |
| 145 | |
| 146 | {{{ |
| 147 | /** |
| 148 | * get online users |
| 149 | * @param aRange - users IDs range to select from |
| 150 | * @param $bInRange - get users that in(not in) range |
| 151 | */ |
| 152 | function getOnline($aRange = array(), $bInRange = true) { ... } |
| 153 | }}} |
| 154 | |
| 155 | This function retrieves the currently online members array. If $aRange variable is not empty this function retrieves the currently online members from the given list ($bInRange is true) or excludes this list ($bInRange is false). |
| 156 | |
| 157 | |
| 158 | 8. '''getUserStatus''' |
| 159 | |
| 160 | {{{ |
| 161 | /** |
| 162 | * get user status |
| 163 | * @param sId - user id |
| 164 | * @return sStatus - user status |
| 165 | */ |
| 166 | function getUserStatus ($sId){ ... } |
| 167 | }}} |
| 168 | |
| 169 | This function retrieves the online status for a user with a given ID. The possible result values so far: "offline", "online". |
| 170 | |
| 171 | |
| 172 | 9. '''getExtraFiles''' |
| 173 | |
| 174 | {{{ |
| 175 | /** |
| 176 | * get extra files list for given module |
| 177 | * @param $sModule - module name |
| 178 | * @param $sFolder - folder name for where to look for files |
| 179 | * @param $bGetUserFile - get current user file (true) or default file (false) |
| 180 | * @param $bGetDate - get dates of files |
| 181 | * @return $aResult - files array without extension and/or current file and extension separately |
| 182 | */ |
| 183 | function getExtraFiles($sModule, $sFolder = "langs", $bGetUserFile = true, $bGetDate = false) { ... } |
| 184 | }}} |
| 185 | |
| 186 | This function retrieves files(cuts the last 4 characters from filename as extension) from a given folder and/or current user/default file of the given widget (skins or languages). This is mainly for language and skins lists generating: |
| 187 | |
| 188 | {{{ |
| 189 | $aSkins = getExtraFiles("chat", "skins"); |
| 190 | print_r($aSkins); |
| 191 | ///////////////////// |
| 192 | Array("files" => Array(0 => "default", 1 => "heaven"), "current" =>"default", "extension" => "swf") |
| 193 | }}} |
| 194 | |
| 195 | 10. '''setCurrentFile''' |
| 196 | |
| 197 | {{{ |
| 198 | /** |
| 199 | * set current file for module to cookie |
| 200 | * @param $sModule - module name |
| 201 | * @param $sFile - file value |
| 202 | * @param $sFolder - folder name for which value is set |
| 203 | */ |
| 204 | function setCurrentFile($sModule, $sFile, $sFolder = "langs") { ... } |
| 205 | }}} |
| 206 | |
| 207 | This function saves current file (language or skin) as a cookie in the browser. |
| 208 | |
| 209 | |
| 210 | 11. '''printFiles''' |
| 211 | |
| 212 | {{{ |
| 213 | /** |
| 214 | * get extra files for module in XML format |
| 215 | * @param $sModule - module name |
| 216 | * @param $sFolder - folder name for which value is set |
| 217 | * @param $bGetDate - get dates of files |
| 218 | * @return $sContents - XML formatted result |
| 219 | */ |
| 220 | function printFiles($sModule, $sFolder = "langs", $bGetDate = false) { ... } |
| 221 | }}} |
| 222 | |
| 223 | This function returns extra files information (languages or skins) for the given widget in XML format: |
| 224 | |
| 225 | {{{ |
| 226 | $sSkins = printFiles ("chat", "skins"); |
| 227 | echo $sSkins; |
| 228 | ///////////////////// |
| 229 | <files> |
| 230 | <file name="default" /> |
| 231 | <file name="heaven" /> |
| 232 | </files> |
| 233 | <current name="heaven" url="http://[your_site]/ray/modules/chat/skins/heaven.swf" /> |
| 234 | }}} |
| 235 | |
| 236 | 12. '''getSiteName''' |
| 237 | |
| 238 | {{{ |
| 239 | /** |
| 240 | * return Site Name set by web-master |
| 241 | * @return sSiteName - Site Name |
| 242 | */ |
| 243 | function getSiteName (){ ... } |
| 244 | }}} |
| 245 | |
| 246 | This function returns site name set by web-master. |
| 247 | |
| 248 | {{{ |
| 249 | $sSiteName = getSiteName(); |
| 250 | echo $sSiteName; |
| 251 | ///////////////////// |
| 252 | Dolphin Site |
| 253 | }}} |
| 254 | |
| 255 | |
| 256 | "'''customFunctions.inc.php'''" file functions: |
| 257 | |
| 258 | |
| 259 | 1. '''loginUser''' |
| 260 | |
| 261 | {{{ |
| 262 | /** |
| 263 | * Authorize user by specified ID and Password or Login and Password. |
| 264 | * @param $sName - user login/ID * @param $sPassword - user password |
| 265 | * @param $bLogin - search for login (true) or ID (false) * @return true/false |
| 266 | */ |
| 267 | function loginUser($sName, $sPassword, $bLogin = false) { ... } |
| 268 | }}} |
| 269 | |
| 270 | This function authorizes user by ID and password or by nick and password: |
| 271 | |
| 272 | {{{ |
| 273 | $sResult = loginUser("1", "12345"); |
| 274 | echo $sResult; |
| 275 | $sResult = loginUser("nick", "12345"); |
| 276 | echo $sResult; |
| 277 | ///////////////////// |
| 278 | true false |
| 279 | }}} |
| 280 | |
| 281 | 2. '''loginAdmin''' |
| 282 | |
| 283 | {{{ |
| 284 | /**= o ns = "urn:schemas-microsoft-com:office:office" /> |
| 285 | * Authorize administrator by specified Login and Password. |
| 286 | * @param $sLogin - administrator login |
| 287 | * @param $sPassword - administrator password |
| 288 | * @return true/false |
| 289 | */ |
| 290 | function loginAdmin($sLogin, $sPassword) { ... } |
| 291 | }}} |
| 292 | |
| 293 | This function authorizes admin by nick and password: |
| 294 | |
| 295 | {{{ |
| 296 | $sResult = loginAdmin("admin", "dolphin"); |
| 297 | echo $sResult; |
| 298 | ///////////////////// |
| 299 | true |
| 300 | }}} |
| 301 | |
| 302 | 3. '''getUserInfo''' |
| 303 | |
| 304 | {{{ |
| 305 | /** |
| 306 | * Gets user's information from database by user's id |
| 307 | * @param $sId - user ID |
| 308 | * @return $aInfo - user info |
| 309 | */ |
| 310 | function getUserInfo($sId) { ... } |
| 311 | }}} |
| 312 | |
| 313 | This function retrieves user info by given ID: |
| 314 | |
| 315 | {{{ |
| 316 | $aInfo = getUserInfo("1"); |
| 317 | print_r($aInfo); |
| 318 | ///////////////////// |
| 319 | Array("nick" => "Macho", "sex" => "Male", "age" => 25, "desc" => "some description goes here", |
| 320 | "photo" => "http://[your_site]/[images_folder]/1.pg", "profile" => "http://[your_site]/profile.php?ID=1") |
| 321 | }}} |
| 322 | |
| 323 | 4. '''searchUser''' |
| 324 | |
| 325 | {{{ |
| 326 | /** |
| 327 | * Searches for user by field $sField with value $sValue |
| 328 | * @param $sValue - value to search for |
| 329 | * @param $sField - field to search |
| 330 | * @return $sId - found user ID |
| 331 | */ |
| 332 | function searchUser($sValue, $sField = "ID") { ... } |
| 333 | Searches user by $sField field ("ID" by default) for $sValue value and returns user ID: |
| 334 | $sId = searchUser("Macho", "Nick"); |
| 335 | echo $sId; |
| 336 | ///////////////////// |
| 337 | 1 |
| 338 | }}} |