Альтернативная ''Шапка'' для JohnCMS - 6.x.x (6)
gi8ri7
#1
Endi "saytda kim bor" sahifasidan foydalanuvchi qaysi sahifada ekanligini ko'rsatish uchun places.lng faylini qo'lda taxrirlashning hojati yo'q deya bizga ДоХтор JohnCMS saytida birqancha kodlarni taqdim etdi .
incfiles/classes/functions.php uchun
  1. /**
  2.  * Автозапись в файл places.lng местоположения пользователя
  3.  *
  4.  * @param string $file Локальный путь к файлу
  5.  * @param string $headmod Название папки с файлом(файлами)
  6.  * @param string $textl Название заголовка страницы
  7.  * @param string $uri GET-параметры (если они есть)
  8.  */
  9. public static function headmod($file, $headmod, $textl, $uri = '')
  10. {
  11. $writeToFile = function ($path, $arr, $fname, $uri) {
  12. file_put_contents($path, $arr);
  13. header('Location: '. $fname . $uri);
  14. };
  15.  
  16. $length = 30 - strlen($headmod);
  17. $spase = html_entity_decode(' ');
  18.  
  19. $fname = basename($file);
  20. $url = $headmod .'/'. $fname . $uri;
  21.  
  22. $repeat = str_repeat($spase, 3);
  23. $href = '='. $repeat .'"<a href=\'#home#/'. $url .'\'>'. $textl .'</a>"';
  24.  
  25. $places = ROOTPATH .'incfiles/languages/ru/places.lng';
  26. $arrPls = file($places);
  27.  
  28. $array_result = array_filter(
  29. $arrPls,
  30. function ($item) use ($headmod) {
  31. return strstr($item, $headmod);
  32. }
  33. );
  34.  
  35. $arrPls[] = "\r\n". $headmod . str_repeat($spase, $length) . $href;
  36.  
  37. if (empty($array_result)) {
  38. $writeToFile($places, $arrPls, $fname, $uri);
  39. } else {
  40. $arrUri = array_map(
  41. function ($item) {
  42. preg_match('~(<a[^>]*>).*</a>~ui', $item, $matches);
  43. $pattern = '~<a href=\'#home#/[\w\d]+/?([\w\d-]+\.php?.*)\'>~';
  44. return preg_replace($pattern, '$1', $matches[1]);
  45. },
  46. $array_result
  47. );
  48.  
  49. in_array($fname . $uri, $arrUri) ?: $writeToFile($places, $arrPls, $fname, $uri);
  50. }
  51. }
]incfiles/classes/functions.php uchun

head.php uchun
  1. <?php
  2.  
  3. const _IN_JOHNCMS = 1;
  4. $dir = explode(DIRECTORY_SEPARATOR, __DIR__);
  5. $headmod = end($dir); # автоопределение папки
  6. $textl = 'Моя страница';
  7. require_once '../incfiles/core.php';
  8. require_once '../incfiles/head.php';
  9. functions::headmod(__FILE__, $headmod, $textl);
  10.  
  11. /*
  12.   Тут код вашей странички
  13. */
  14.  
  15. require_once '../incfiles/end.php';
  16. ?>
  17.  
  18. Yoki (agar siz parametrlarni kiritishingiz kerak bo'lsa)
  19.  
  20. <?php
  21.  
  22. const _IN_JOHNCMS = 1;
  23. $dir = explode(DIRECTORY_SEPARATOR, __DIR__);
  24. $headmod = end($dir); # автоопределение папки
  25. $textl = 'Моя страница с параметрами';
  26. require_once '../incfiles/core.php';
  27. require_once '../incfiles/head.php';
  28. functions::headmod(__FILE__, $headmod, $textl, '?var=value');
  29.  
  30. /*
  31.   Sahifa kodlari
  32. */
  33.  
  34. require_once '../incfiles/end.php'
KooL
#2
Buni til paketdan qanday farqi bor? Nabarot ko'p vaqt ketsa kerak bu usulni tanlasak
Сирожиддин
#3
Ajalbek, # Ajalbek (01.02.2019 / 18:21)
Buni til paketdan qanday farqi bor? Nabarot ko'p vaqt ketsa kerak bu usulni tanlasak
Автозапись в файл places.lng местоположения пользователя.

headmod va textl ni o'zi yozib boradi.
XuSha
#4
functions.phpga kerakli kodni yozdim endi headga shu kodlarni qoysa boldimi boshqa kod kerak emasmi?
gi8ri7
#5
XuSha, # XuSha (04.02.2019 / 12:02)
functions.phpga kerakli kodni yozdim endi headga shu kodlarni qoysa boldimi boshqa kod kerak emasmi?
Har bir sahifaning https://uzfor.uz/view.php?act=file&id=1692 kodlari o'rniga

  1. <?php
  2.  
  3. const _IN_JOHNCMS = 1;
  4. $dir = explode(DIRECTORY_SEPARATOR, __DIR__);
  5. $headmod = end($dir); # автоопределение папки
  6. $textl = 'Моя страница';
  7. require_once '../incfiles/core.php';
  8. require_once '../incfiles/head.php';
  9. functions::headmod(__FILE__, $headmod, $textl);
Biriktirilgan fayllar [1]:
 20190204_220425.png (368.02 KB) (151 ↴)
Akbarali
#6
буни ўрнатишга мени ақлим бир оз сустлик қилди ? Балки қунт билан қарамаганим сабаблидур.


Кимдур ишлатиб кўрдими ?

Kunduzi: 28°C

19 Apr 2024 yil
Joylashuv aniqlanmadi