<?
/*
Plugin Name: DoInf-table
Description: Плагин преобразует в таблицу третий маркированный список в статье.
Plugin URI: http://doinf.ru/plugin4.html
Version: 0.1 (17-09-2018)
Author: DoInf
Author URI: http://DoInf.ru/
*/



//ini_set('display_errors', '1');
//ini_set('error_reporting', E_ALL);


// Stop direct call
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }

if (!class_exists('DoInfTable')) {
 class DoInfTable {
 
	## Хранение внутренних данных
	public $data = array();
	
	## Конструктор объекта
	## Инициализация основных переменных
	function DoInfTable()
	{
		global $wpdb;
		
		## Объявляем константу инициализации нашего плагина
		DEFINE('DoInfTable', true);
		
		## Название файла нашего плагина 
		$this->plugin_name = plugin_basename(__FILE__);
		
		## URL адресс для нашего плагина
		$this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
		
		 
		## Функция которая исполняется при активации плагина
		register_activation_hook( $this->plugin_name, array(&$this, 'activate') );
		
		## Функция которая исполняется при деактивации плагина
		register_deactivation_hook( $this->plugin_name, array(&$this, 'deactivate') );
		
		##  Функция которая исполняется удалении плагина
		register_uninstall_hook( $this->plugin_name, array(&$this, 'uninstall') );
		
 	}
	
  
	/**
	 * Активация плагина
	 */
	function activate() 
	{
		return true;
	}
	
	function deactivate() 
	{
		return true;
	}
	
	/**
	 * Удаление плагина
	 */
	function uninstall() 
	{
		return true;
	}
	

	

 }
}

global $reviews;
$reviews = new DoInfTable();

 
	
/*************************************************************/

// получаем позицию Нного вхождения
function strposX($haystack, $needle, $number)
{
    preg_match_all("/$needle/", $haystack, $matches, PREG_OFFSET_CAPTURE);
    return $matches[0][$number-1][1];
}

// список в таблицу делаем
function getContents($str, $startDelimiter, $endDelimiter) {
  $contents = array();
  $startDelimiterLength = strlen($startDelimiter);
  $endDelimiterLength = strlen($endDelimiter);
  $startFrom = $contentStart = $contentEnd = 0;
  while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
    $contentStart += $startDelimiterLength;
    $contentEnd = strpos($str, $endDelimiter, $contentStart);
    if (false === $contentEnd) {
      break;
    }
    $contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
    $startFrom = $contentEnd + $endDelimiterLength;
  }

  return $contents;
}

function ul_to_table($content) {
	$text=$content;
	$n=3;$i=0;
	// get position 
	$pos1 = strposX($text, '<ul>', $n);
	$pos2 = strposX($text, '<\/ul>', $n)+5;
	while($pos1>$pos2){ $i++; $pos2 = strposX($text, '<\/ul>', ($n+$i))+5;}
	//echo"$pos1 - $pos2";
	if($pos1>5){
		$spisok=substr($text, $pos1, ($pos2-$pos1));
		$text=str_replace($spisok,'**********',$text);

		$massive=getContents($spisok, '<li>', '</li>');
		 
		$tt=0;
		$text_table='<table width="100%" border="1" cellpadding="5" cellspacing="0"> <tr> <th scope="col" width="20">№</th> <th scope="col">Полезная информация</th></tr>';
		foreach($massive as $val){
			$tt++;
			$text_table.=' <tr>  <td>'.$tt.'</td> <td>'.substr($val,0,-1).'</td></tr>';
		}
		 $text_table.='</tr></table>';

		$text=str_replace('**********',$text_table,$text);
		 
	}
	return $text;
}
add_filter('the_content', 'ul_to_table');

?><?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://opuholi.org/post-sitemap.xml</loc>
		<lastmod>2026-10-09T17:34:59+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://opuholi.org/page-sitemap.xml</loc>
		<lastmod>2018-05-10T13:02:27+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://opuholi.org/autors-sitemap.xml</loc>
		<lastmod>2018-09-10T10:33:23+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://opuholi.org/category-sitemap.xml</loc>
		<lastmod>2026-10-09T17:34:59+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://opuholi.org/post_tag-sitemap.xml</loc>
		<lastmod>2019-06-12T20:09:05+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->