marisalaspe

Script Ebooks PHP

May 27th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.61 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('xdebug.var_display_max_depth', -1);
  4. ini_set('xdebug.var_display_max_children', -1);
  5. ini_set('xdebug.var_display_max_data', -1);
  6.  
  7. function bbc_run(){
  8.     global $inserted;
  9.     global $tried;
  10.     global $bbc_cron;
  11.  
  12.     $isbn = (isset($_REQUEST['bbc_isbn']) ? $_REQUEST['bbc_isbn'] : false);
  13.  
  14.  
  15.     if($isbn)
  16.         $isbn = explode(',', $isbn);
  17.  
  18.     $amazon_api_key = get_field('bbc_api_amazon_access_key', 'options');
  19.     $amazon_api_secret = get_field('bbc_api_amazon_secret_key', 'options');
  20.     $amazon_api_tag = get_field('bbc_api_amazon_tag', 'options');
  21.     $amazon_api_sort = get_field('bbc_sort', 'options');
  22.     $amazon_api_nodes = get_field('bbc_ids_de_categorias', 'options');
  23.     $amazon_tops = get_field('bbc_bestseller_id', 'options');
  24.  
  25.     $url_servidor_proxy = get_field('bbc_proxy_url', 'options');
  26.  
  27.   do {
  28.       if( empty($url_servidor_proxy) ) break;
  29.  
  30.       $urls_servidor_proxy = explode(",", $url_servidor_proxy);
  31.  
  32.       if( !is_array($urls_servidor_proxy) ) break;
  33.  
  34.       $k = array_rand($urls_servidor_proxy);
  35.  
  36.       $url_servidor_proxy = $urls_servidor_proxy[$k];
  37.  
  38.   } while(0);
  39.  
  40.     $news_max = get_field('bbc_import_max', 'options');
  41.     $tops_max = 20;
  42.  
  43.     if(!$news_max)
  44.         $news_max = 99999;
  45.     if(!$tops_max)
  46.         $tops_max = 99999;
  47.  
  48.     $max_page = 10;
  49.  
  50.     $nodes = explode(',', $amazon_api_nodes);
  51.  
  52.     $c_node = next_node($nodes);
  53.  
  54.     if (isset($url_servidor_proxy) && empty($url_servidor_proxy)) $url_servidor_proxy = "";
  55.  
  56.  
  57.     if($isbn && $isbn[0] != ''){
  58.  
  59.         foreach($isbn as $i){
  60.  
  61.             $xml_answer = bbc_amazon($amazon_api_key, $amazon_api_secret, $amazon_api_tag, $amazon_api_sort, 1, $i, $nodes[0], $url_servidor_proxy);
  62.             $xml = $xml_answer->Items;
  63.  
  64.             foreach($xml->Item as $item){
  65.  
  66.                 bbc_parse_item($item);
  67.             }
  68.         }
  69.     }else{
  70.  
  71.         delete_post_meta_by_key( 'bbc_tops' );
  72.         // delete_post_meta_by_key( 'bbc_news' );
  73.         global $meta;
  74.         $meta = array('tops' => 0, 'news' => 0);
  75.  
  76.         $p = 1;
  77.         if(!$bbc_cron)
  78.             echo '<p>TOPS: </p>';
  79.  
  80.         while($p <= $max_page){
  81.             $xml_answer = bbc_amazon($amazon_api_key, $amazon_api_secret, $amazon_api_tag, $amazon_api_sort, $p, '', $amazon_tops, $url_servidor_proxy);
  82.             $xml = $xml_answer->Items;
  83.             if($p == 1)
  84.                 $totalPages = (int)$xml->TotalPages;
  85.             foreach($xml->Item as $item){
  86.                 $r = bbc_parse_item($item, 'tops');
  87.                 $tops_max--;
  88.                 if($tops_max == 0)
  89.                     break;
  90.             }
  91.             $p++;
  92.             if($p >= $totalPages)
  93.                 break;
  94.             if($tops_max == 0)
  95.                 break;
  96.         }
  97.  
  98.         //// foreach($nodes as $node){
  99.  
  100.             $node = $nodes[$c_node];
  101.             $p = 1;
  102.             $xml_answer = bbc_amazon($amazon_api_key, $amazon_api_secret, $amazon_api_tag, $amazon_api_sort, $p, '', $amazon_tops, $url_servidor_proxy);
  103.             $xml = $xml_answer->Items;
  104.             $new_books_max = $news_max;
  105.  
  106.             while($p <= $max_page){
  107.                 $xml_answer = bbc_amazon($amazon_api_key, $amazon_api_secret, $amazon_api_tag, $amazon_api_sort, $p, '', $node, $url_servidor_proxy);
  108.                 $xml = $xml_answer->Items;
  109.                 if($p == 1)
  110.                     $totalPages = (int)$xml->TotalPages;
  111.                 foreach($xml->Item as $item){
  112.                     $r = bbc_parse_item($item);
  113.                     if($r == 'new')
  114.                         $new_books_max--;
  115.                     if($new_books_max == 0)
  116.                         break;
  117.                 }
  118.                 $p++;
  119.                 if($p >= $totalPages)
  120.                     break;
  121.                 if($new_books_max == 0)
  122.                     break;
  123.             }
  124.  
  125.         //// }
  126.     }
  127.  
  128.     if(!$bbc_cron){
  129.         echo '<br>'.$tried.' Libros fueron encontrados';
  130.         echo ($inserted ? '<br>'.$inserted.' Libros nuevos fueron insertados' : 'Ningun libro nuevo fue insertado');
  131.     }
  132. }
  133.  
  134. function next_node($node){
  135.     $c_node = get_option('current_node');
  136.     if($c_node === false){
  137.         update_option('current_node', 0);
  138.         $c_node = get_option('current_node');
  139.     }else{
  140.         $c_node++;
  141.         if(!isset($node[$c_node]))
  142.             $c_node = 0;
  143.         update_option('current_node', $c_node);
  144.     }
  145.  
  146.     return $c_node;
  147. }
  148.  
  149. function bbc_parse_item($item, $m = ''){
  150.     global $inserted;
  151.     global $tried;
  152.     global $meta;
  153.     global $bbc_cron;
  154.     if($m){
  155.         $meta[$m]++;
  156.     }
  157.  
  158.     $tried++;
  159.     $att = $item->ItemAttributes;
  160.  
  161.     $titulo = trim(preg_replace('/[\(\)\?!].*/', '', (string)$att->Title));
  162.     $isbn = (string)$att->ISBN;
  163.     if(!$isbn)
  164.         $isbn = (string)$att->EISBN;
  165.     if(!$isbn)
  166.         $isbn = (string)$item->ASIN;
  167.  
  168.     if($post = get_page_by_title($titulo, OBJECT, 'libro')){
  169.  
  170.         if($m && !metadata_exists('post', $post->ID, 'bbc_'.$m)){
  171.             update_post_meta($post->ID, 'bbc_'.$m, $meta[$m]);
  172.         }
  173.         if(!$bbc_cron)
  174.             echo '<br>' . $titulo . __(' Ya existe el titulo con ISBN: ', 'books_theme') . $isbn;
  175.         return 'old';
  176.     }
  177.  
  178.     $args = array(
  179.         'post_type'       => 'libro',
  180.         'meta_key'   => 'isbn',
  181.         'meta_value' => $isbn,
  182.     );
  183.     $post = get_posts($args);
  184.  
  185.     if($post && !is_wp_error($post)){
  186.         if($m && !metadata_exists('post', $post[0]->ID, 'bbc_'.$m)){
  187.             update_post_meta($post[0]->ID, 'bbc_'.$m, $meta[$m]);
  188.         }
  189.         if(!$bbc_cron)
  190.             echo '<br>' . $titulo . __(' Ya existe, ISBN: ', 'books_theme') . $isbn;
  191.         return 'old';
  192.     }
  193.  
  194.     $isbn13 = (string)$att->EAN;
  195.  
  196.     $autor = false;
  197.     $autor_slug = '';
  198.     if($att->Author) {
  199.         if(count($att->Author)==1){
  200.             $autor = (string)$att->Author;
  201.         }else if(count($att->Author)>1){
  202.             $autor = (string)$att->Author[0];
  203.         }
  204.     }
  205.  
  206.     if($autor){
  207.         $autor_slug = bbc_slug($autor);
  208.         if(!get_term_by('slug', $autor_slug, 'autor')){
  209.             $autor_term = wp_insert_term($autor, 'autor', array('slug' => $autor_slug))['term_id'];
  210.         }else{
  211.             $autor_term = get_term_by('slug', $autor_slug, 'autor')->term_id;
  212.         }
  213.     }else{
  214.         if($att->Creator) {
  215.             if(count($att->Creator)==1){
  216.                 $autor = (string)$att->Creator;
  217.             }else if(count($att->Creator)>1){
  218.                 $autor = (string)$att->Creator[0];
  219.             }
  220.         }
  221.         if($autor){
  222.             $autor_slug = bbc_slug($autor);
  223.             if(!get_term_by('slug', $autor_slug, 'autor')){
  224.                 $autor_term = wp_insert_term($autor, 'autor', array('slug' => $autor_slug))['term_id'];
  225.             }else{
  226.                 $autor_term = get_term_by('slug', $autor_slug, 'autor')->term_id;
  227.             }
  228.         }
  229.     }
  230.  
  231.     $editorial = (string)$att->Publisher;
  232.     if($editorial){
  233.         $editorial_slug = bbc_slug($editorial);
  234.         if(!get_term_by('slug', $editorial_slug, 'editorial')){
  235.             $editorial_term = wp_insert_term($editorial, 'editorial', array('slug' => $editorial_slug))['term_id'];
  236.         }else{
  237.             $editorial_term = get_term_by('slug', $editorial_slug, 'editorial')->term_id;
  238.         }
  239.     }else{
  240.         $editorial_term = false;
  241.     }
  242.  
  243.     $genre = $subgenre = false;
  244.  
  245.     $limit = 9;
  246.  
  247.     while($limit>1){
  248.         $limit--;
  249.         if(!$genre){
  250.             $node = $item->BrowseNodes;
  251.         }else{
  252.             $node = $browseNode->Ancestors;
  253.         }
  254.         if(count($node)==1){
  255.             $browseNode = $node->BrowseNode;
  256.         }else if(count($node)>1){
  257.             $browseNode = $node->BrowseNode[0];
  258.         }
  259.         if(!$browseNode)
  260.             break;
  261.  
  262.         if($browseNode->IsCategoryRoot)
  263.             break;
  264.  
  265.         // if($genre){
  266.             // $subgenre = $genre;
  267.         // }
  268.         $genre = (string)$browseNode->Name;
  269.     }
  270.  
  271.     if($genre){
  272.         $genre_slug = bbc_slug($genre);
  273.         if(!get_term_by('slug', $genre_slug, 'genre')){
  274.             $genre_term = wp_insert_term($genre, 'genre', array('slug' => $genre_slug))['term_id'];
  275.         }else{
  276.             $genre_term = get_term_by('slug', $genre_slug, 'genre')->term_id;
  277.         }
  278.     }
  279.  
  280.     $imagen = (string)$item->LargeImage->URL;
  281.  
  282.     $fecha = (string)$att->PublicationDate;
  283.  
  284.     if($fecha){
  285.         $f = explode('-', $fecha);
  286.         if(count($f) == 3)
  287.             $fecha = $f[2] . '/' . $f[1] . '/' . $f[0];
  288.         if(count($f) == 2)
  289.             $fecha = '01/' . $f[1] . '/' . $f[0];
  290.     }
  291.  
  292.     $paginas = (int)$att->NumberOfPages;
  293.     if(!$paginas || $paginas <= 1)
  294.         $paginas = rand(100,200);
  295.     $rating = (4 + (rand(0, 9) / 10)) + (rand(0, 1) / 10);
  296.  
  297.     $views = rand(19000, 21000);
  298.  
  299.     $opiniones = rand(1000, 2000);
  300.  
  301.     $t = (string)$item->EditorialReviews->EditorialReview->Content;
  302.  
  303.     $content = bbc_Yandexize($t);
  304.     $excerpt = bbc_get_words($content, 100);
  305.  
  306.     if($excerpt != $content)
  307.         $excerpt .= ' ...';
  308.  
  309.     $post_name = sanitize_title($titulo);
  310.     // $post_name .= '-'.$autor_slug.'-epub-pdf-mobi';
  311.     $id = wp_insert_post(
  312.         array(
  313.             'post_title'=>$titulo,
  314.             'post_name' => $post_name,
  315.             'post_excerpt' => $excerpt,
  316.             'post_content' => $content,
  317.             'post_type'=>'libro',
  318.             'post_status' => 'publish',
  319.         )
  320.     );
  321.     if($m && !metadata_exists('post', $id, 'bbc_'.$m))
  322.         update_post_meta($id, 'bbc_'.$m, $meta[$m]);
  323.     if($autor_term){
  324.         wp_set_post_terms( $id, $autor, 'autor');
  325.         update_field('autor', (int)$autor_term, $id);
  326.     }else{
  327.         $autor = get_term(get_field('autor_default', 'options'));
  328.         if(!is_wp_error($autor)){
  329.             wp_set_post_terms( $id, $autor->name, 'autor');
  330.             update_field('autor', get_field('autor_default', 'options'), $id);
  331.         }
  332.     }
  333.  
  334.     if($editorial_term){
  335.         wp_set_post_terms( $id, $editorial, 'editorial');
  336.         update_field('editorial', (int)$editorial_term, $id);
  337.     }else{
  338.         $editorial = get_term(get_field('editorial_default', 'options'));
  339.         if(!is_wp_error($editorial)){
  340.             wp_set_post_terms( $id, $editorial->name, 'editorial');
  341.             update_field('editorial', get_field('editorial_default', 'options'), $id);
  342.         }
  343.     }
  344.  
  345.     if($genre_term){
  346.         wp_set_post_terms( $id, $genre_term, 'genre');
  347.     }else{
  348.         $genre = get_term(get_field('genre_default', 'options'));
  349.         if(!is_wp_error($genre)){
  350.             wp_set_post_terms( $id, $genre->name, 'genre');
  351.         }
  352.     }
  353.  
  354.     if($t)
  355.         update_field('original_content', $t, $id);
  356.     if($imagen)
  357.         update_field('imagen', $imagen, $id);
  358.     if($fecha)
  359.         update_field('fecha_de_publicacion', $fecha, $id);
  360.     if($isbn)
  361.         update_field('isbn', $isbn, $id);
  362.     if($isbn13)
  363.         update_field('isbn13', $isbn13, $id);
  364.     if($paginas)
  365.         update_field('paginas', $paginas, $id);
  366.     if($rating)
  367.         update_field('valoracion', (int)$rating, $id);
  368.     if($views)
  369.         update_post_meta($id, 'views', $views);
  370.     if($opiniones)
  371.         update_field('opiniones', (int)$opiniones, $id);
  372.  
  373.     if(!$bbc_cron)
  374.         echo __('<br>Nuevo libro: ', 'books_theme') . $titulo;
  375.     $inserted++;
  376.     return 'new';
  377. }
  378.  
  379. function bbc_GetAPIYandex($string) {
  380.     $apis = explode(",", $string);
  381.     $cantidad = count($apis);
  382.     if (get_option('bbc_yandex_api_actual') == false) {
  383.         update_option('bbc_yandex_api_actual', $apis[mt_rand(0, $cantidad - 1)]);
  384.     } else {
  385.         $yandex_actual = get_option('bbc_yandex_api_actual');
  386.         $continuar = false;
  387.         while ($continuar == false) {
  388.             $randtemporal = $apis[mt_rand(0, $cantidad - 1)];
  389.             if ($yandex_actual != $randtemporal) {
  390.                 update_option('bbc_yandex_api_actual', $randtemporal);
  391.                 $continuar = true;
  392.             }
  393.         }
  394.     }
  395.     return get_option('bbc_yandex_api_actual');
  396. }
  397.  
  398.  
  399. function bbc_YandexTraslate($contenido, $lenguaje) {
  400.     if(!$contenido)
  401.         return '';
  402.     $apis = get_field('bbc_api_yandex_key', 'options');
  403.     $YandexAPI = bbc_GetAPIYandex($apis);
  404.     $resultado = json_decode(@file_get_contents("https://translate.yandex.net/api/v1.5/tr.json/translate?key=" . $YandexAPI . "&text=" . urlencode($contenido) . "&lang=" . $lenguaje . "&format=html"));
  405.     if ($resultado->code == 200) {
  406.         $contenido = $resultado->text['0'];
  407.     }
  408.     return $contenido;
  409. }
  410.  
  411. function bbc_Yandexize($c){
  412.     $c = bbc_YandexTraslate($c, "es-fr");
  413.     $c = bbc_YandexTraslate($c, "fr-es");
  414.     return $c;
  415. }
  416.  
  417.  
  418. function bbc_amazon($aws_access_key_id, $amazon_api_secret, $amazon_api_tag, $amazon_api_sort, $itemPage, $books_isbn, $browseNode, $url_servidor_proxy) {
  419.     sleep(1);
  420.     try {
  421.  
  422.         $endpoint = "webservices.amazon.es";
  423.  
  424.         $uri = "/onca/xml";
  425.  
  426.         if ($books_isbn == "") {
  427.             $params = array(
  428.                 "Service" => "AWSECommerceService",
  429.                 "Operation" => "ItemSearch",
  430.                 "AWSAccessKeyId" => $aws_access_key_id,
  431.                 "AssociateTag" => $amazon_api_tag,
  432.                 "SearchIndex" => "Books",
  433.                 "Keywords" => "Book",
  434.                 "BrowseNode" => $browseNode,
  435.                 "ResponseGroup" => "BrowseNodes,EditorialReview,Images,ItemAttributes,ItemIds,SalesRank,AlternateVersions",
  436.                 "ItemPage" => $itemPage,
  437.                 "Version" => "2015-10-01",
  438.                 "Sort" => $amazon_api_sort
  439.             );
  440.         } else {
  441.             $params = array(
  442.                 "Service" => "AWSECommerceService",
  443.                 "Operation" => "ItemLookup",
  444.                 "ResponseGroup" => "BrowseNodes,EditorialReview,Images,ItemAttributes,ItemIds,SalesRank,AlternateVersions",
  445.                 "IdType" => "ASIN",
  446.                 "ItemId" => $books_isbn,
  447.                 "AWSAccessKeyId" => $aws_access_key_id,
  448.                 "AssociateTag" => $amazon_api_tag,
  449.                 "Version" => "2015-10-01",
  450.             );
  451.         }
  452.  
  453.         $params["Timestamp"] = gmdate('Y-m-d\TH:i:s\Z');
  454.  
  455.         ksort($params);
  456.  
  457.         $pairs = array();
  458.  
  459.         foreach ($params as $key => $value) {
  460.             array_push($pairs, rawurlencode($key) . "=" . rawurlencode($value));
  461.         }
  462.  
  463.         $canonical_query_string = join("&", $pairs);
  464.  
  465.         $string_to_sign = "GET\n" . $endpoint . "\n" . $uri . "\n" . $canonical_query_string;
  466.  
  467.         $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $amazon_api_secret, true));
  468.  
  469.         $request_url = 'https://' . $endpoint . $uri . '?' . $canonical_query_string . '&Signature=' . rawurlencode($signature);
  470.  
  471.         if (isset($url_servidor_proxy) && !empty($url_servidor_proxy)) $response = getDataProxy($request_url,$url_servidor_proxy);
  472.             else $response = file_get_contents($request_url);
  473.  
  474.         $parsed_xml = simplexml_load_string($response);
  475.         return $parsed_xml;
  476.     } catch (Exception $e) {
  477.  
  478.         var_dump($e->getMessage());
  479.  
  480.         return false;
  481.     }
  482. }
  483.  
  484. function getDataProxy($url, $proxy){
  485.  
  486.     $ch = curl_init();
  487.     curl_setopt($ch, CURLOPT_URL, $url);
  488.     curl_setopt($ch, CURLOPT_HEADER, 0);
  489.      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  490.      curl_setopt($ch, CURLOPT_PROXY, $proxy);
  491.  
  492.  
  493.      $user_pass = get_field('bbc_proxy_user_pass', 'options');
  494.   if( !empty($user_pass) ) {
  495.     curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user_pass);
  496.   }
  497.  
  498.     $resultado = curl_exec($ch);
  499.  
  500.     curl_close($ch);
  501.  
  502.     return $resultado;
  503.  
  504. }
  505.  
  506. function bbc_slug($string){
  507.     return sanitize_title(preg_replace("/[^A-Za-z0-9 ]/", '-', trim(strtolower(bbc_corrector($string)))));
  508. }
  509.  
  510. function bbc_corrector($txt) {
  511.     $transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' => 'h', 'Ħ' => 'H', 'í' => 'i', 'Í' => 'I', 'ì' => 'i', 'Ì' => 'I', 'î' => 'i', 'Î' => 'I', 'ï' => 'i', 'Ï' => 'I', 'ĩ' => 'i', 'Ĩ' => 'I', 'į' => 'i', 'Į' => 'I', 'ī' => 'i', 'Ī' => 'I', 'ĵ' => 'j', 'Ĵ' => 'J', 'ķ' => 'k', 'Ķ' => 'K', 'ĺ' => 'l', 'Ĺ' => 'L', 'ľ' => 'l', 'Ľ' => 'L', 'ļ' => 'l', 'Ļ' => 'L', 'ł' => 'l', 'Ł' => 'L', 'ṁ' => 'm', 'Ṁ' => 'M', 'ń' => 'n', 'Ń' => 'N', 'ň' => 'n', 'Ň' => 'N', 'ñ' => 'n', 'Ñ' => 'N', 'ņ' => 'n', 'Ņ' => 'N', 'ó' => 'o', 'Ó' => 'O', 'ò' => 'o', 'Ò' => 'O', 'ô' => 'o', 'Ô' => 'O', 'ő' => 'o', 'Ő' => 'O', 'õ' => 'o', 'Õ' => 'O', 'ø' => 'oe', 'Ø' => 'OE', 'ō' => 'o', 'Ō' => 'O', 'ơ' => 'o', 'Ơ' => 'O', 'ö' => 'oe', 'Ö' => 'OE', 'ṗ' => 'p', 'Ṗ' => 'P', 'ŕ' => 'r', 'Ŕ' => 'R', 'ř' => 'r', 'Ř' => 'R', 'ŗ' => 'r', 'Ŗ' => 'R', 'ś' => 's', 'Ś' => 'S', 'ŝ' => 's', 'Ŝ' => 'S', 'š' => 's', 'Š' => 'S', 'ṡ' => 's', 'Ṡ' => 'S', 'ş' => 's', 'Ş' => 'S', 'ș' => 's', 'Ș' => 'S', 'ß' => 'SS', 'ť' => 't', 'Ť' => 'T', 'ṫ' => 't', 'Ṫ' => 'T', 'ţ' => 't', 'Ţ' => 'T', 'ț' => 't', 'Ț' => 'T', 'ŧ' => 't', 'Ŧ' => 'T', 'ú' => 'u', 'Ú' => 'U', 'ù' => 'u', 'Ù' => 'U', 'ŭ' => 'u', 'Ŭ' => 'U', 'û' => 'u', 'Û' => 'U', 'ů' => 'u', 'Ů' => 'U', 'ű' => 'u', 'Ű' => 'U', 'ũ' => 'u', 'Ũ' => 'U', 'ų' => 'u', 'Ų' => 'U', 'ū' => 'u', 'Ū' => 'U', 'ư' => 'u', 'Ư' => 'U', 'ü' => 'ue', 'Ü' => 'UE', 'ẃ' => 'w', 'Ẃ' => 'W', 'ẁ' => 'w', 'Ẁ' => 'W', 'ŵ' => 'w', 'Ŵ' => 'W', 'ẅ' => 'w', 'Ẅ' => 'W', 'ý' => 'y', 'Ý' => 'Y', 'ỳ' => 'y', 'Ỳ' => 'Y', 'ŷ' => 'y', 'Ŷ' => 'Y', 'ÿ' => 'y', 'Ÿ' => 'Y', 'ź' => 'z', 'Ź' => 'Z', 'ž' => 'z', 'Ž' => 'Z', 'ż' => 'z', 'Ż' => 'Z', 'þ' => 'th', 'Þ' => 'Th', 'µ' => 'u', 'а' => 'a', 'А' => 'a', 'б' => 'b', 'Б' => 'b', 'в' => 'v', 'В' => 'v', 'г' => 'g', 'Г' => 'g', 'д' => 'd', 'Д' => 'd', 'е' => 'e', 'Е' => 'E', 'ё' => 'e', 'Ё' => 'E', 'ж' => 'zh', 'Ж' => 'zh', 'з' => 'z', 'З' => 'z', 'и' => 'i', 'И' => 'i', 'й' => 'j', 'Й' => 'j', 'к' => 'k', 'К' => 'k', 'л' => 'l', 'Л' => 'l', 'м' => 'm', 'М' => 'm', 'н' => 'n', 'Н' => 'n', 'о' => 'o', 'О' => 'o', 'п' => 'p', 'П' => 'p', 'р' => 'r', 'Р' => 'r', 'с' => 's', 'С' => 's', 'т' => 't', 'Т' => 't', 'у' => 'u', 'У' => 'u', 'ф' => 'f', 'Ф' => 'f', 'х' => 'h', 'Х' => 'h', 'ц' => 'c', 'Ц' => 'c', 'ч' => 'ch', 'Ч' => 'ch', 'ш' => 'sh', 'Ш' => 'sh', 'щ' => 'sch', 'Щ' => 'sch', 'ъ' => '', 'Ъ' => '', 'ы' => 'y', 'Ы' => 'y', 'ь' => '', 'Ь' => '', 'э' => 'e', 'Э' => 'e', 'ю' => 'ju', 'Ю' => 'ju', 'я' => 'ja', 'Я' => 'ja');
  512.     return str_replace(array_keys($transliterationTable), array_values($transliterationTable), $txt);
  513. }
  514.  
  515. function bbc_get_words($sentence, $count = 10) {
  516.   preg_match("/(?:\S+(?:\W+|$)){0,$count}/", $sentence, $matches);
  517.   return $matches[0];
  518. }
Add Comment
Please, Sign In to add comment