| [ PHPXref.com ] | [ Generated: Sun Jul 20 17:59:00 2008 ] | [ Glossword 1.7.0 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 if (!defined('IN_GW')) 3 { 4 die('<!-- $Id: func.browse.inc.php,v 1.26 2005/06/09 06:32:02 yrtimd Exp $ -->'); 5 } 6 /** 7 * Glossword - glossary compiler (http://glossword.info/dev/) 8 * © 2002-2005 Dmitry N. Shilnikov <dev at glossword.info> 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * (see `glossword/support/license.html' for details) 15 */ 16 // -------------------------------------------------------- 17 /** 18 * Math, SQL, HTML functions for browsing dictionary. 19 */ 20 // -------------------------------------------------------- 21 22 /* Create custom page */ 23 function gw_custom_page($id_page) 24 { 25 global $oSqlQ, $oDb, $oTpl, $oFunc, $oHtml; 26 global $gw_this, $sys, $oL, $str_current_section, $ar_tpl_construct, $arPost, $layout; 27 $id_lang = 0; 28 /* Check languages first */ 29 switch ($sys['pages_link_mode']) 30 { 31 case GW_PAGE_LINK_NAME: 32 $sql_id_page = 'gpph.page_title = "'.gw_text_sql(urlencode($id_page)).'"'; 33 break; 34 case GW_PAGE_LINK_URI: 35 $sql_id_page = 'gp.page_uri = "'.gw_text_sql(urlencode($id_page)).'"'; 36 break; 37 default: 38 $sql_id_page = 'gp.id_page = "'.$id_page.'"'; 39 break; 40 } 41 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-custompages-lang', $sql_id_page), 'page'); 42 for (; list($arK, $arV) = each($arSql);) 43 { 44 if ($arV['id_lang'] == $gw_this['vars'][GW_LANG_I].'-'.$gw_this['vars']['lang_enc']) 45 { 46 $id_lang = $arV['id_lang']; 47 break; 48 } 49 elseif ($arV['id_lang'] == $sys['locale_name']) 50 { 51 $id_lang = $arV['id_lang']; 52 break; 53 } 54 else 55 { 56 $id_lang = $arV['id_lang']; 57 } 58 } 59 $id_page_int = 0; 60 if ($id_lang) 61 { 62 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-custompages', $sql_id_page, $id_lang), 'page'); 63 for (; list($arK, $arV) = each($arSql);) 64 { 65 $id_page_int = $arV['id_page']; 66 $ar_tpl_construct[] = '../common/custom_page.html'; 67 /* Process text filters */ 68 while (!$sys['is_debug_output'] 69 && is_array($sys['filters_defn']) 70 && list($k, $v) = each($sys['filters_defn']) ) 71 { 72 $arV['page_content'] = $v($arV['page_content']); 73 } 74 /* Custom content */ 75 $oTpl->addVal( 'block:page_content', $arV['page_content']); 76 $oTpl->addVal( 'block:page_descr', $arV['page_descr']); 77 /* Custom PHP-code */ 78 eval( $arV['page_php_1'] ); 79 $gw_this['arTitle'][] = $str_current_section = $arV['page_title']; 80 } 81 } 82 /* Create the list of subpages */ 83 $arSqlc = $oDb->sqlRun($oSqlQ->getQ('get-subpages-list'), 'page'); 84 $arSqlc = gw_rearrange_custompages($arSqlc); 85 $arSqlc = gw_create_tree_custompages($arSqlc); 86 $ar_page_titles = array(); 87 $ar_pages_p_uplevel = array(); 88 $ar_pages_p_level = isset($arSqlc[$id_page_int]) ? $arSqlc[$id_page_int] : array(); 89 90 $arQ['subpages_cnt'] = 0; 91 $arQ['subpages_tpl'] = ''; 92 $arQ['subpages_ul'] = ''; 93 /* The list pages, 1 level up. */ 94 $ar_parents = isset($arSqlc[$id_page_int]['p']) ? $arSqlc[$arSqlc[$id_page_int]['p']]['ch'] : array(); 95 for (; list($page_k, $ar_page_v) = each($ar_parents);) 96 { 97 if (($arSqlc[$page_k]['p'] == 0) && ($layout != 'title')) { continue; } 98 switch ($sys['pages_link_mode']) 99 { 100 case GW_PAGE_LINK_NAME: 101 $str_page_id = urlencode($arSqlc[$page_k]['page_title']); 102 break; 103 case GW_PAGE_LINK_URI: 104 $str_page_id = urlencode($arSqlc[$page_k]['page_uri']); 105 break; 106 default: 107 $str_page_id = $arSqlc[$page_k]['id']; 108 break; 109 } 110 # if ($arSqlc[$page_k]['p'] == 0) { continue; } 111 $ar_page_titles[] = $oHtml->a( $sys['page_index'] . 112 '?a='.GW_A_CUSTOMPAGE.'&id=' . $str_page_id, $arSqlc[$page_k]['page_title'] 113 ); 114 } 115 if (!empty($ar_page_titles)) 116 { 117 $arQ['subpages_ul_1'] = '<ul><li>' . implode('</li><li>', $ar_page_titles) . '</li></ul>'; 118 } 119 /* */ 120 if (isset($arSqlc[$id_page_int]['ch'])) 121 { 122 $arVarPage = array(); 123 $ar_page_titles = array(); 124 $subpages_cnt = 0; 125 /* The list subpages, current level. */ 126 $ar_subpages = $arSqlc[$id_page_int]['ch']; 127 for (; list($page_k, $ar_page_v) = each($ar_subpages);) 128 { 129 switch ($sys['pages_link_mode']) 130 { 131 case GW_PAGE_LINK_NAME: 132 $str_page_id = urlencode($arSqlc[$page_k]['page_title']); 133 break; 134 case GW_PAGE_LINK_URI: 135 $str_page_id = urlencode($arSqlc[$page_k]['page_uri']); 136 break; 137 default: 138 $str_page_id = $arSqlc[$page_k]['id']; 139 break; 140 } 141 $arVarPage[$page_k] = $arSqlc[$page_k]; 142 $arVarPage[$page_k]['url:page_title'] = $oHtml->a( $sys['page_index'] . 143 '?a='.GW_A_CUSTOMPAGE.'&id=' . $str_page_id, $arSqlc[$page_k]['page_title'] 144 ); 145 $ar_page_titles[] = $arVarPage[$page_k]['url:page_title']; 146 $subpages_cnt++; 147 if (isset($arVarPage[$page_k]['ch'])) 148 { 149 unset($arVarPage[$page_k]['ch']); 150 } 151 } 152 $arQ['subpages_ul'] = '<ul><li>' . implode('</li><li>', $ar_page_titles) . '</li></ul>'; 153 $oTplPage = new gwTemplate; 154 $oTplPage->setHandle( 0 , 'templates/common/tpl_pages_list.html' ); 155 $oTplPage->setBlock(0, 'page_list', $arVarPage); 156 $oTplPage->parse(); 157 $arQ['subpages_cnt'] = $subpages_cnt; 158 $arQ['subpages_tpl'] = $oTplPage->output(); 159 } 160 for (; list($k, $v) = each($arQ);) 161 { 162 $oTpl->addVal($k, $v); 163 } 164 $gw_this['id_page_int'] = $id_page_int; 165 $gw_this['ar_pages'] = $arSqlc; 166 } 167 168 /** 169 * Feedback form 170 * 171 * @param array $vars posted variables 172 * @param int $runtime is this form posted first time [ 0 - no | 1 - yes ] 173 * @param array $arBroken the names of broken fields (after post) 174 * @param array $arReq the names of required fields (after post) 175 * @return string complete HTML-code 176 * @see textcodetoform() 177 */ 178 function scrFeedback($vars, $runtime = 0, $arBroken = array(), $arReq = array()) 179 { 180 global $oL, $sys, $tmp, $gw_this; 181 $strForm = ""; 182 include_once( $sys['path_include'].'/class.forms.php' ); 183 184 $form = new gwForms(); 185 $form->action = $sys['server_dir'].'/index.php'; 186 $trClass = "t"; 187 $form->Set('submitok', $oL->m('3_send')); 188 $form->Set('submitcancel', $oL->m('3_cancel')); 189 $form->Set('formbgcolor', $GLOBALS['theme']['color_2']); 190 $form->Set('formbordercolor', $GLOBALS['theme']['color_4']); 191 $form->Set('formbordercolorL', $GLOBALS['theme']['color_1']); 192 $form->Set('formwidth', 450); 193 $form->Set('align_buttons', $sys['css_align_right']); 194 $form->Set('charset', $sys['internal_encoding']); 195 $form->arLtr = array('email', 'url'); 196 ## ---------------------------------------------------- 197 ## 198 199 /* reverse array keys <-- values; */ 200 $arReq = array_flip($arReq); 201 /* mark fields as "REQUIRED" and make error messages */ 202 while(is_array($vars) && list($key, $val) = each($vars) ) 203 { 204 $arReqMsg[$key] = $arBrokenMsg[$key] = ""; 205 if (isset($arReq[$key])) { $arReqMsg[$key] = ' <span style="color:#E30"><b>*</b></span>'; } 206 if (isset($arBroken[$key])) { $arBrokenMsg[$key] = ' <span style="color:#E30"><b>' . $oL->m('reason_9') . '</b></span><br/>'; } 207 } 208 ## 209 ## ---------------------------------------------------- 210 $strForm = ""; 211 $strForm .= '<table class="gw2TableFieldset" cellspacing="0" cellpadding="0" border="0" width="100%">'; 212 $strForm .= '<tr><td style="width:25%"></td><td></td></tr>'; 213 $strForm .= '<tr>'. 214 '<td class="td1">' .$oL->m('y_name') . ':' . $arReqMsg['name'] . '</td>'. 215 '<td class="td2">' . $arBrokenMsg['name'] . $form->field("input","name", textcodetoform($vars['name'])) . '</td>'. 216 '</tr>'; 217 $strForm .= '<tr>'. 218 '<td class="td1">' . $oL->m('y_email') . ':' . $arReqMsg['email'] . '</td>'. 219 '<td class="td2">' . $arBrokenMsg['email'] . $form->field("input", "email", textcodetoform($vars['email']) ) . '</td>'. 220 '</tr>'; 221 $strForm .= '<tr>'. 222 '<td class="td1">' . $oL->m('message') . ':' . $arReqMsg['message'] . '</td>'. 223 '<td class="td2">' . $arBrokenMsg['message'] . $form->field("textarea", "arPost[message]", textcodetoform($vars['message']), 10) . '</td>'. 224 '</tr>'; 225 $strForm .= '</table>'; 226 $strForm .= $form->field("hidden", GW_ACTION, GW_A_CUSTOMPAGE); 227 $strForm .= $form->field("hidden", 'id', $gw_this['vars']['id']); 228 $strForm .= $tmp['input_url_append']; 229 230 return $form->Output($strForm); 231 } 232 233 234 /** 235 * Top 10 236 * 237 * @param int $m [ R_DICT_AVERAGEHITS | R_DICT_EFFIC | 238 * R_DICT_NEWEST | R_TERM_NEWEST | 239 * R_DICT_UPDATED | R_POLL ] // todo ... 240 * @return string complete HTML-code 241 * @see htmlTagsA() 242 * @global $oL 243 */ 244 function getTop10($m, $amount = 10, $isItemOnly = 0) 245 { 246 global $oL, $sys, $gw_this; 247 global $oHtml, $oDb, $oSqlQ, $arDictParam; 248 global $oFunc, $oSess; 249 $str = ''; 250 $cnt = 0; 251 /* Current date in UNIX timestamp */ 252 $curDateMk = gmmktime(date("H,i,s,Y,m,d")); 253 $arThText = $arThWidth = array(); 254 $strData = $strTopicName = ''; 255 $m = strtolower(str_replace('R_', '', $m)); 256 $filename = $sys['path_include'] . '/top.' . $m . '.inc.' . $sys['phpEx']; 257 if (file_exists($filename)) 258 { 259 include_once( $filename ); 260 } 261 else 262 { 263 print("Can't find " . $filename); 264 } 265 266 $intRows = sizeof($arThWidth); 267 268 if (!empty($arThText) || !empty($arThWidth)) 269 { 270 $str .= '<table style="background:'.$GLOBALS['theme']['color_1'].'" width="100%" border="0" cellpadding="3" cellspacing="1">'; 271 $str .= '<col align="'.$sys['css_align_right'].'" width="1%"/>'; 272 for (reset($arThWidth); list ($kT, $vT)= each($arThWidth);) 273 { 274 $str .= '<col width="'.$vT.'" align="'.$arThAlign[$kT].'"/>'; 275 } 276 $str .= '<thead>'; 277 if ($strTopicName != '') 278 { 279 $str .= '<tr>' 280 . '<td style="background:'.$GLOBALS['theme']['color_4'].';text-align:'.$sys['css_align_left'].'" colspan="' . ($intRows + 1) . '" class="r">' 281 . ' ' . $strTopicName 282 . '</td>' 283 . '</tr>'; 284 } 285 if (!empty($arThText)) 286 { 287 $str .= '<tr class="a" style="color:'.$GLOBALS['theme']['color_white'].';background:'.$GLOBALS['theme']['color_6'].'">'; 288 $str .= '<th class="gw" style="text-align:center">N</th>'; 289 reset($arThText); 290 for (; list ($kT, $vT)= each($arThText);) 291 { 292 $str .= '<th class="gw">' . $vT . '</th>'; 293 } 294 $str .= '</tr>'; 295 } 296 $str .= '</thead>'; 297 $str .= '<tbody>'; 298 $str .= $strData; 299 $str .= '</tbody></table>'; 300 } 301 return $str; 302 } 303 304 /* */ 305 function getValidDictID() 306 { 307 global $oSqlQ, $oDb; 308 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-dict-valid'), 'st'); 309 return $arSql; 310 } 311 312 /* */ 313 function getStat() 314 { 315 global $oSqlQ, $oDb; 316 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-terms-total'), 'st'); 317 $arSql = isset($arSql[0]) ? $arSql[0] : array('num' => 0, 'sum' => 0); 318 $arSql['date'] = gmmktime(); 319 return $arSql; 320 } 321 322 /* */ 323 function getSettings() 324 { 325 global $oSqlQ, $oDb, $sys; 326 $strA = array(); 327 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-settings'), 'st'); 328 for (; list($k, $v) = each($arSql);) 329 { 330 $strA[$v['settings_key']] = $v['settings_val']; 331 } 332 /* No system settings found, run install */ 333 if (empty($strA)) 334 { 335 gwtk_header($sys['server_proto'].$sys['server_host'].$sys['server_dir'].'/gw_install/install.php?step=novar'); 336 } 337 return $strA; 338 } 339 340 341 342 /** 343 * Builds HTML-code for page navigation, like [ Pages: 1 .. 5 6 7 .. 11 ] 344 * 345 * @return string simple HTML-code, ready to put inside a table or else. 346 */ 347 function getNavToolbar($intSumPages, $page = 1, $url) 348 { 349 global $sys, $oHtml; 350 $strA = array(); 351 if ($intSumPages == 1) 352 { 353 return " "; 354 } 355 $sys['split_pagenums'] = isset($sys['split_pagenums']) ? $sys['split_pagenums'] : ' | '; 356 357 $isShowJump = 0; 358 $intVisible = 7; 359 $intJump = 10; 360 # [prev 10] [prev] 1 2 3 .. 11 [next] [next 10] 361 362 $strNext = $GLOBALS['oL']->m('1_nextpage').' >>'; 363 $strPrev = '<< '.$GLOBALS['oL']->m('1_prevpage'); 364 $strNextN = $GLOBALS['oL']->m('next_n %d'); 365 $strPrevN = $GLOBALS['oL']->m('prev_n %d'); 366 // 1 << 367 // 2 < 368 // 3 min 369 // 4 .. 370 // 5 n 371 // 6 .. 372 // 7 max 373 // 8 > 374 // 9 >> 375 // min & max values 376 $max = $page + $intJump; 377 if ($max > $intSumPages) { $max = $intSumPages; } 378 $min = $page - $intJump; 379 if ($min < 1) { $min = 1; } 380 // prev/next processing 381 if ( ($page - 1) != 0 ) { $linkPrev = $oHtml->a( append_url($url . ($page - 1)), $strPrev); } 382 else { $linkPrev = ''; } 383 if ( ($page + 1) <= $intSumPages ) 384 { 385 $linkNext = $oHtml->a( append_url($url . ($page + 1)), $strNext); 386 } 387 else { $linkNext = ''; } 388 // 389 if ($isShowJump) 390 { 391 $strA[] = (($page == 1) || ($page <= $intJump)) ? '' : $oHtml->a( append_url($url . $min), sprintf($strPrevN, $intJump)); 392 } 393 $strA[] = $linkPrev; 394 $strA[] = ($page == 1) ? '<b style="color:'.$GLOBALS['theme']['color_5'].';font:bold 110%">1</b>' : $oHtml->a( append_url($url . 1), '<b>1</b>'); 395 // 396 $p1 = ($page - intval($intVisible / 2)); 397 $p2 = ($p1 + $intVisible); 398 if ($p2 > $intSumPages) 399 { 400 $p2 = ($intSumPages - 1); 401 $p1 = ($p2 - $intVisible); 402 } 403 // $intVisible.. 404 if((($p2 - $intVisible) < 0) || ($p1 <= 1)) 405 { 406 $p1 = 2; 407 $p2 = $p1 + $intVisible; 408 } 409 if (($p1 - 1) > 1 ) { $strA[] = '..'; } 410 411 if ( (($intSumPages - $page) * 2) < $intVisible ) 412 { 413 $p2++; 414 } 415 if ($p2 > $intSumPages) { $p2 = $intSumPages; } 416 // visible part 417 for ($i = $p1; $i < $p2; $i++) 418 { 419 $strA[] = ($i == $page) ? '<b style="color:'.$GLOBALS['theme']['color_5'].';font:bold 110%">'.$i.'</b>' : $oHtml->a( append_url($url . $i), '<b>'.$i.'</b>'); 420 } 421 if (($intSumPages - $p2) >= 1) { $strA[] = '..'; } 422 $strA[] = ($page == $intSumPages) ? '<b style="color:'.$GLOBALS['theme']['color_5'].';font:bold 110%">'.$intSumPages.'</b>' : $oHtml->a( append_url($url . $intSumPages), '<b>'.$intSumPages.'</b>'); 423 424 $strA[] = $linkNext; 425 426 if ($isShowJump) 427 { 428 $strA[] = (($page == $intSumPages) || (($page + $intJump) > $intSumPages)) ? "" : $oHtml->a( append_url($url . $max), sprintf($strPrevN, $intJump)); 429 } 430 $str = implode($sys['split_pagenums'], $strA); 431 return $str; 432 } 433 434 435 436 /** 437 * Depreciated function 438 * 439 * Builds query "LIMIT n,n" for database 440 * 441 * @param int $total total number of items 442 * @param int $page current page number 443 * @param int $perpage items per page 444 * @return string part of database query 445 */ 446 function getSqlLimit($total, $page, $perpage) 447 { 448 $numpages = ceil($total / $perpage); 449 for ($i=1; $i <= $numpages; $i++) 450 { 451 $pos = ($i * $perpage); 452 if ($i == ($page - 1)) 453 { 454 return " LIMIT $pos, $perpage"; 455 } 456 } 457 return " LIMIT 0, $perpage"; 458 } 459 460 461 /** 462 * Get all dictionary parameters, such as: 463 * title, description, number of terms, sql-table name etc. 464 * 465 * @param int dictionary ID 466 * @return array dictionary name, description, total terms etc. 467 */ 468 function getDictParam($dict_id) 469 { 470 global $gw_this; 471 $ar = array(); 472 for (reset($gw_this['ar_dict_list']); list($kDict, $vDict) = each($gw_this['ar_dict_list']);) 473 { 474 if ($vDict['id'] == $dict_id) 475 { 476 $vDict['dict_settings'] = unserialize($vDict['dict_settings']); 477 if (is_array($vDict['dict_settings'])) 478 { 479 $vDict = array_merge($vDict, $vDict['dict_settings']); 480 } 481 unset($vDict['dict_settings']); 482 $ar = $vDict; 483 break; 484 } 485 } 486 return $ar; 487 } // end of getDictName 488 489 490 /** 491 * Get a random term from a random dictionary 492 * @param int dictionary ID 493 * @return array array with term and dictionary 494 */ 495 function getTermRandom() 496 { 497 global $gw_this, $oDb, $oSqlQ; 498 $arSqlD = $gw_this['ar_dict_list'][rand(0, sizeof($gw_this['ar_dict_list'])-1)]; 499 $sql = $oSqlQ->getQ('get-term-rand', $arSqlD['tablename']); 500 $arSql = $oDb->sqlExec($sql, '', 0); 501 $arSql = isset($arSql[0]) ? $arSql[0] : array(); 502 $arSql = array_merge($arSqlD, $arSql); 503 return $arSql; 504 } 505 506 507 /** 508 * Get term parameters: 509 * term id, term, definition 510 * 511 * @param int term ID 512 * @return array term id, defn id, name, definition(s), synonym(s) 513 */ 514 function getTermParam($tid = '', $name = '') 515 { 516 global $gw_this, $oL, $arDictParam, $oDb, $oSqlQ, $oSess; 517 518 $arFound = $arFoundInit = array('is_active' => '0', 'term' => '', 'term_1' => ' ', 'term_2' => ' ', 'defn' => '', 'tid' => ''); 519 if ($tid != '') 520 { 521 /* search by id (faster) */ 522 if (GW_IS_BROWSE_ADMIN) 523 { 524 $sql = $oSqlQ->getQ('get-term-by-id-adm', $arDictParam['tablename'], $tid); 525 } 526 else 527 { 528 $sql = $oSqlQ->getQ('get-term-by-id', $arDictParam['tablename'], $tid); 529 } 530 $arFound = $oDb->sqlExec($sql, sprintf("%05d", $gw_this['vars'][GW_ID_DICT]), 0); 531 $arFound = isset($arFound[0]) ? $arFound[0] : array(); 532 } 533 elseif ($name != '') 534 { 535 /* remove specials */ 536 $arKeywordsT = text2keywords( text_normalize( gw_stripslashes($name) ), 1); 537 $word_srch_sql = "'" . implode("', '", $arKeywordsT) . "'"; 538 if (GW_IS_BROWSE_ADMIN) 539 { 540 $sql = $oSqlQ->getQ('get-term-by-name-adm', TBL_WORDLIST, TBL_WORDMAP, $arDictParam['tablename'], $gw_this['vars'][GW_ID_DICT], $word_srch_sql); 541 } 542 else 543 { 544 $sql = $oSqlQ->getQ('get-term-by-name', TBL_WORDLIST, TBL_WORDMAP, $arDictParam['tablename'], $gw_this['vars'][GW_ID_DICT], $word_srch_sql); 545 } 546 $arSql = $oDb->sqlExec($sql, sprintf("%05d", $gw_this['vars'][GW_ID_DICT]), 0); 547 for (reset($arSql); list($arK, $arV) = each($arSql);) // compare founded values (Q) with imported (T) 548 { 549 $isTermExist = 0; 550 // first method, 08 july 2000 551 if (!$isTermExist && ($arV['term'] == $name)) 552 { 553 $isTermExist = 1; 554 $arFound = $arV; 555 # prn_r( $arV['term'].' = '.$name."\narsize=".sizeof($arSql) ); 556 break; // breaks at first loop, usually. 557 } 558 // do NOT remove specials 559 $arKeywordsQ = text2keywords( text_normalize($arV['term']), 1); // 1 - is the minimum length 560 $div1 = sizeof(gw_array_exclude($arKeywordsT, $arKeywordsQ)); 561 $div2 = sizeof(gw_array_exclude($arKeywordsQ, $arKeywordsT)); 562 $isTermNotMatched = ($div1 + $div2); 563 // if the sum of excluded arrays is 0, this term already exists 564 if (!$isTermNotMatched) // in english, double negative means positive. yeah. 565 { 566 $isTermExist = 1; 567 } 568 if ($isTermExist) 569 { 570 $arFound = $arV; 571 } 572 } // end of for each founded terms 573 } 574 if (empty($arFound)) 575 { 576 $arFound = $arFoundInit; 577 } 578 return $arFound; 579 } 580 581 582 583 584 585 ## -------------------------------------------------------- 586 ## Toolbar functions A-Z, 00-ZZ 587 588 /** 589 * === Toolbar functions. 590 * 1 of 2 functions to create alphabetic index. 591 * Get first letters from all terms in dictionary 592 * 593 * @param int $id_dict dictionary ID 594 * @param int $w second symbol (optional) // not in use since 1.3 595 * @return array initial letters 00-ZZ 596 */ 597 function getLettersArray($id_dict, $w = '') 598 { 599 global $oDb, $oSqlQ, $oFunc; 600 global $arDictParam; 601 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-az', $arDictParam['tablename']), sprintf("%05d", $id_dict)); 602 /* One array for both indexes (single and double) */ 603 $arL = array(); 604 for (; list($k, $v) = each($arSql);) 605 { 606 /* Must be mb_substr($v['L1'], 1, 3), but parameter (0, 3) 607 allows to override Unicode sorting order for diacritics. 608 Example (urlencoded): S%CC%8C overrides %C5%A0 */ 609 $arL[$oFunc->mb_substr($v['L1'], 0, 3)][$oFunc->mb_substr($v['L2'], 0, 6)] = $v['L2']; 610 } 611 /* Remove single character from double's index */ 612 for (; list($k, $v) = each($arL);) 613 { 614 if ( isset($v[$k]) ) /* is there any single character? */ 615 { 616 unset($arL[$v[$k]][$v[$k]]); 617 } 618 } 619 /* 1.7.1: Custom sorting order 620 $arLnew = array(); 621 $arSql = $oDb->sqlRun($oSqlQ->getQ('get-tb-by-char', 'gw_toolbar', $arDictParam['lang'], implode('","', array_keys($arL)))); 622 for (; list($k, $v) = each($arSql);) 623 { 624 $arLnew[$v['L1']] = $arL[$v['L1']]; 625 unset($arL[$v['L1']]); 626 } 627 $arL = array_merge($arLnew, $arL); 628 */ 629 return $arL; 630 } 631 632 /** 633 * === Toolbar functions. 634 * 2 of 2 functions to create alphabetic index. 635 * Get HTML-code for A-Z letters. Universal function. 636 * 637 * @param array $ar array[49][49] = 11; 638 * @param int $id_dict dictionary ID 639 * @param string $w1 single letter 640 * @param int $w2 double letter 641 * @return string HTML-code 642 * @return string HTML-code 643 */ 644 function getLetterHtml($ar, $id_dict, $w1 = '', $w2 = '') 645 { 646 global $oFunc, $oHtml, $sys; 647 648 /* Basic Multilingual Plane: */ 649 /* http://www.unicode.org/roadmaps/bmp/ */ 650 /* Break alphabetic toolbar per every set of characters */ 651 $arUnicodeMap = array( 652 array('20', 'Basic Latin Digits'), 653 array('41', 'Basic Latin'), 654 array('c280', 'Latin Extended'), 655 array('c990', 'IPA Extensions'), 656 array('cab0', 'Spacing Modifiers'), 657 array('cc80', 'Combining Diacritics'), 658 array('cdb0', 'Greek'), 659 array('d080', 'Cyrillic, Cyrillic Supplement'), 660 array('d4b0', 'Armenian') 661 ); 662 $int_cnt = 0; 663 $arS = array(); 664 $ar_tb_last = end($arUnicodeMap); 665 $int_tb_last = hexdec($ar_tb_last[0]); 666 /* links to letters */ 667 $arTmp['href'][GW_ACTION] = GW_A_LIST; 668 $arTmp['href'][GW_TARGET] = GW_T_DICT; 669 $arTmp['href'][GW_ID_DICT] = $id_dict; 670 671 # $arTmp['href'][$this->c('A_PAGENUM')] = 1; 672 # $arTmp['href'][$this->c('A_LANGUAGE')] = $this->gv['vars'][$this->c('A_LANGUAGE')]; 673 /* for each letter */ 674 for (reset($ar); list($k1, $v1) = each($ar);) 675 { 676 $int_cnt++; 677 $cnt1_str = (isset($sys['is_print_toolbar_num']) && $sys['is_print_toolbar_num'] == 1) ? $int_cnt : ''; 678 /* 0-Z */ 679 if (($w1 != '') && ($w2 == '')) 680 { 681 $oHtml->setTag('a', 'title', $cnt1_str); 682 $arTmp['href']['w1'] = urlencode($k1); 683 /* current letter */ 684 $int_utf2hex = ($oFunc->text_utf2hex($k1, 0)); 685 for (reset($arUnicodeMap); list($k2, $v2) = each($arUnicodeMap);) 686 { 687 /* next letter */ 688 if (!isset($arUnicodeMap[$k2+1])) 689 { 690 $int_utf2hex_tb_to = $int_tb_last; 691 } 692 else 693 { 694 $int_utf2hex_tb_to = ($arUnicodeMap[$k2+1][0]); 695 } 696 /* start letter */ 697 $int_utf2hex_tb_from = ($v2[0]); 698 /* start letter > current letter < next letter */ 699 if (($int_utf2hex >= $int_utf2hex_tb_from) && 700 ($int_utf2hex < $int_utf2hex_tb_to)) 701 { 702 $oHtml->setTag('a', 'class', ''); 703 if (strval($k1) == strval(trim($w1))) 704 { 705 $oHtml->setTag('a', 'class', 'on'); 706 } 707 $arS[$k2][] = $oHtml->a( $sys['page_index'].'?'. 708 $oHtml->paramValue($arTmp['href'], '&', ''), 709 htmlspecialchars($k1)); 710 } 711 } 712 $oHtml->setTag('a', 'title', ''); 713 } 714 else 715 { 716 /* 00-ZZ */ 717 if (strval($k1) == strval(trim($w1))) 718 { 719 for (reset($v1); list($k2, $v2) = each($v1);) 720 { 721 $oHtml->setTag('a', 'class', ''); 722 if (strval($k2) == strval(trim($w2))) 723 { 724 $oHtml->setTag('a', 'class', 'on'); 725 } 726 727 $arTmp['href']['w1'] = urlencode($k1); 728 $arTmp['href']['w2'] = urlencode($v2); 729 $arS['0z'][] = $oHtml->a($sys['page_index'].'?'. 730 $oHtml->paramValue($arTmp['href'], '&', ''), 731 htmlspecialchars($v2)); 732 } 733 } 734 } 735 } 736 unset($ar); 737 $oHtml->setTag('a', 'title', ''); 738 $oHtml->setTag('a', 'class', ''); 739 /* Build html-code */ 740 $str = ''; 741 for (reset($arS); list($k1, $v1) = each($arS);) 742 { 743 if ( is_array($v1) ) 744 { 745 $str .= implode(' ', $v1); 746 $str .= '<br />'; 747 } 748 } 749 return $str; 750 } 751 ## Toolbar functions A-Z, 00-ZZ 752 ## -------------------------------------------------------- 753 754 755 756 757 /** 758 * Parses XML-data and converts it into structured array. 759 * 760 * @param string $str XML-code, (from database) 761 * @return array Fields content structure 762 */ 763 function gw_Xml2Array($str) 764 { 765 global $arFields; 766 // 767 $xmlRoot = array(); 768 $xmlTags = array(); 769 $xmlAttr = array("link", "lang"); // possible attributes 770 // Get defined tags 771 for (reset($arFields); list($fk, $fv) = each($arFields);) 772 { 773 $fieldname = 'is_'.$fv[0]; 774 if (isset($fv[4]) && $fv[4]) // root 775 { 776 $xmlRoot[] = $fv[0]; 777 } 778 else // not root elements 779 { 780 $xmlTags[] = $fv[0]; 781 } 782 } 783 // go for each root element 784 for (reset($xmlRoot); list($kp, $vp) = each($xmlRoot);) 785 { 786 preg_match_all("/<$vp>(.+?)<\/$vp>/s", $str, $strDefnA); // root tags without attributes 787 if (isset($strDefnA[0]) && isset($strDefnA[0][0]) && !empty($strDefnA[0][0])) 788 { 789 $intDefnS = sizeof($strDefnA[0]); 790 for ($intDefnC = 0; $intDefnC < $intDefnS; $intDefnC++) // foreach <defn> 791 { 792 // value, 10 march 2003 793 $parsedAr[$vp][$intDefnC]['value'] = $strDefnA[1][$intDefnC]; 794 // 795 for (reset($xmlTags); list($kt, $vt) = each($xmlTags);) 796 { 797 for (reset($xmlAttr); list($ka, $va) = each($xmlAttr);) 798 { 799 preg_match_all("/<$vt( $va=\"(.*?)\")*\>(.*?)\<\/$vt\>/s", $strDefnA[1][$intDefnC], $strTmpA); 800 #prn_r($strTmpA); 801 if (isset($strTmpA[0]) && !empty($strTmpA[0])) 802 { 803 $intTmpS = sizeof($strTmpA[0]); 804 for ($intTmpC = 0; $intTmpC < $intTmpS; $intTmpC++) // foreach <trns> 805 { 806 $parsedAr[$vt][$intDefnC][$intTmpC]['value'] = $strTmpA[3][$intTmpC]; 807 $parsedAr[$vp][$intDefnC]['value'] = trim(str_replace($strTmpA[0][$intTmpC], '', $parsedAr[$vp][$intDefnC]['value'])); 808 // per-tag 809 if ($vt == 'syn') // collect data for syn 810 { 811 // 31 may 2002 - new attribute [text]: <syn link="" text=""> 812 $strSynText = ''; 813 if (preg_match("/\" text=\"/", $strTmpA[2][$intTmpC])) 814 { 815 $strSynText = preg_replace("'(.*)(\" text=\")(.*)'", "\\3", $strTmpA[2][$intTmpC]); 816 } 817 $strTmpA[2][$intTmpC] = preg_replace("'\" text=\"(.*)'", '', $strTmpA[2][$intTmpC]); 818 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['link'] = $strTmpA[2][$intTmpC]; 819 if ( ($strTmpA[2][$intTmpC] != '') && ($strTmpA[2][$intTmpC] != '--') ) 820 { 821 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['is_link'] = 1; 822 } 823 if ($strSynText != '') // text="" 824 { 825 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['text'] = ' [['.$strSynText.']]'; 826 } 827 $strSynText = ''; 828 } 829 elseif ($vt == 'see') // collect data for see 830 { 831 #prn_r( $strTmpA , __LINE__); 832 // 31 may 2002 - new attribute [text]: <see link="" text=""> 833 $strSeeText = ''; 834 if (preg_match("/\" text=\"/", $strTmpA[1][$intTmpC])) 835 { 836 $strSeeText = preg_replace("'(.*)(\" text=\")(.*)'", "\\3", $strTmpA[2][$intTmpC]); 837 } 838 $strTmpA[2][$intTmpC] = preg_replace("'\" text=\"(.*)'", '', $strTmpA[2][$intTmpC]); 839 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['link'] = $strTmpA[2][$intTmpC]; 840 if ( ($strTmpA[2][$intTmpC] != '') && ($strTmpA[2][$intTmpC] != '--') ) 841 { 842 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['is_link'] = 1; 843 } 844 if ($strSeeText != '') // text="" 845 { 846 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['text'] = ' [['.$strSeeText.']]'; 847 } 848 $strSeeText = ''; 849 } 850 elseif ($vt == 'abbr') // collect data for abbr 851 { 852 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['lang'] = $strTmpA[2][$intTmpC]; 853 } 854 elseif ($vt == 'trns') // collect data for trns 855 { 856 $parsedAr[$vt][$intDefnC][$intTmpC]['attributes']['lang'] = $strTmpA[2][$intTmpC]; 857 } 858 elseif ($vt == 'src') // collect data for src 859 { 860 if ( ($strTmpA[2][$intTmpC] != '') && ($strTmpA[2][$intTmpC] != '--') ) 861 { 862 $parsedAr['src'][$intDefnC][] = $strTmpA[1][$intTmpC]; 863 } 864 } 865 } 866 } 867 } // xmlAttr 868 } // xmlTags 869 } // foreach <defn> 870 } 871 } // end of $xmlPrnt 872 if (!isset($parsedAr)){ $parsedAr['defn'][0] = ""; } 873 return $parsedAr; 874 } // end of ParseFieldDbToInput() 875 876 /* end of file */ 877 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |