/mambots/content/mosloadposition.php

https://github.com/Arkadiy-Sedelnikov/joostina-1.4 · PHP · 101 lines · 59 code · 20 blank · 22 comment · 8 complexity · 56b2cff891e61c3aeb5a3ea2e614b3ab MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joostina
  4. * @copyright Авторские права (C) 2008-2010 Joostina team. Все права защищены.
  5. * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
  6. * Joostina! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
  7. * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл help/copyright.php.
  8. */
  9. // запрет прямого доступа
  10. defined('_JLINDEX') or die();
  11. $_MAMBOTS->registerFunction('onPrepareContent', 'botMosLoadPosition');
  12. /**
  13. * Мамбот, загружающий модули в пределах содержимого
  14. */
  15. function botMosLoadPosition($published, &$row){
  16. $_MAMBOTS = mosMambotHandler::getInstance();
  17. $database = database::getInstance();
  18. // simple performance check to determine whether bot should process further
  19. if(strpos($row->text, 'mosloadposition') === false){
  20. return true;
  21. }
  22. // expression to search for
  23. $regex = '/{mosloadposition\s*.*?}/i';
  24. // check whether mambot has been unpublished
  25. if(!$published){
  26. $row->text = preg_replace($regex, '', $row->text);
  27. return true;
  28. }
  29. // найти все образцы мамбота и вставить в $matches
  30. preg_match_all($regex, $row->text, $matches);
  31. // Количество мамботов
  32. $count = count($matches[0]);
  33. // мамбот производит обработку если находит в тексте образцы мамбота
  34. if($count){
  35. // check if param query has previously been processed
  36. if(!isset($_MAMBOTS->_content_mambot_params['mosloadposition'])){
  37. // load mambot params info
  38. $query = "SELECT params FROM #__mambots WHERE element = 'mosloadposition' AND folder = 'content'";
  39. $database->setQuery($query);
  40. $database->loadObject($mambot);
  41. // save query to class variable
  42. $_MAMBOTS->_content_mambot_params['mosloadposition'] = $mambot;
  43. }
  44. // pull query data from class variable
  45. $mambot = $_MAMBOTS->_content_mambot_params['mosloadposition'];
  46. $botParams = new mosParameters($mambot->params);
  47. $style = $botParams->def('style', -2);
  48. processPositions($row, $matches, $count, $regex, $style);
  49. }
  50. }
  51. function processPositions(&$row, &$matches, $count, $regex, $style){
  52. $database = database::getInstance();
  53. $query = "SELECT position" . "\n FROM #__template_positions" . "\n ORDER BY position";
  54. $database->setQuery($query);
  55. $positions = $database->loadResultArray();
  56. for($i = 0; $i < $count; $i++){
  57. $load = str_replace('mosloadposition', '', $matches[0][$i]);
  58. $load = str_replace('{', '', $load);
  59. $load = str_replace('}', '', $load);
  60. $load = trim($load);
  61. foreach($positions as $position){
  62. if($position == @$load){
  63. $modules = loadPosition($load, $style);
  64. $row->text = str_replace($matches[0][$i], $modules, $row->text);
  65. break;
  66. }
  67. }
  68. }
  69. // удаление тэгов, не соответствующих позиции модуля
  70. $row->text = preg_replace($regex, '', $row->text);
  71. }
  72. function loadPosition($position, $style = -2){
  73. $modules = '';
  74. if(mosCountModules($position)){
  75. ob_start();
  76. mosLoadModules($position, $style);
  77. $modules = ob_get_contents();
  78. ob_end_clean();
  79. }
  80. return $modules;
  81. }