macgyver17

Wp Zend Model

May 19th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 41.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Retrieve translated string with gettext context.
  4.  *
  5.  * Quite a few times, there will be collisions with similar translatable text
  6.  * found in more than two places, but with different translated context.
  7.  *
  8.  * By including the context in the pot file, translators can translate the two
  9.  * strings differently.
  10.  *
  11.  * @since 2.8.0
  12.  *
  13.  * @param string $text    Text to translate.
  14.  * @param string $context Context information for the translators.
  15.  * @param string $domain  Optional. Text domain. Unique identifier for retrieving translated strings.
  16.  *                        Default 'default'.
  17.  * @return string Translated context string without pipe.
  18.  */
  19. function _x( $text, $context, $domain = 'default' ) {
  20.     return $text;
  21. }
  22.  
  23. /**
  24.  * Retrieve the combined regular expression for HTML and shortcodes.
  25.  *
  26.  * @access private
  27.  * @ignore
  28.  * @internal This function will be removed in 4.5.0 per Shortcode API Roadmap.
  29.  * @since 4.4.0
  30.  *
  31.  * @param string $shortcode_regex The result from _get_wptexturize_shortcode_regex().  Optional.
  32.  * @return string The regular expression
  33.  */
  34. function _get_wptexturize_split_regex( $shortcode_regex = '' ) {
  35.     static $html_regex;
  36.  
  37.     if ( ! isset( $html_regex ) ) {
  38.         $comment_regex =
  39.               '!'           // Start of comment, after the <.
  40.             . '(?:'         // Unroll the loop: Consume everything until --> is found.
  41.             .     '-(?!->)' // Dash not followed by end of comment.
  42.             .     '[^\-]*+' // Consume non-dashes.
  43.             . ')*+'         // Loop possessively.
  44.             . '(?:-->)?';   // End of comment. If not found, match all input.
  45.  
  46.         $html_regex =            // Needs replaced with wp_html_split() per Shortcode API Roadmap.
  47.               '<'                // Find start of element.
  48.             . '(?(?=!--)'        // Is this a comment?
  49.             .     $comment_regex // Find end of comment.
  50.             . '|'
  51.             .     '[^>]*>?'      // Find end of element. If not found, match all input.
  52.             . ')';
  53.     }
  54.  
  55.     if ( empty( $shortcode_regex ) ) {
  56.         $regex = '/(' . $html_regex . ')/';
  57.     } else {
  58.         $regex = '/(' . $html_regex . '|' . $shortcode_regex . ')/';
  59.     }
  60.  
  61.     return $regex;
  62. }
  63.  
  64. /**
  65.  * Search for disabled element tags. Push element to stack on tag open and pop
  66.  * on tag close.
  67.  *
  68.  * Assumes first char of $text is tag opening and last char is tag closing.
  69.  * Assumes second char of $text is optionally '/' to indicate closing as in </html>.
  70.  *
  71.  * @since 2.9.0
  72.  * @access private
  73.  *
  74.  * @param string $text Text to check. Must be a tag like `<html>` or `[shortcode]`.
  75.  * @param array  $stack List of open tag elements.
  76.  * @param array  $disabled_elements The tag names to match against. Spaces are not allowed in tag names.
  77.  */
  78. function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) {
  79.     // Is it an opening tag or closing tag?
  80.     if ( '/' !== $text[1] ) {
  81.         $opening_tag = true;
  82.         $name_offset = 1;
  83.     } elseif ( 0 == count( $stack ) ) {
  84.         // Stack is empty. Just stop.
  85.         return;
  86.     } else {
  87.         $opening_tag = false;
  88.         $name_offset = 2;
  89.     }
  90.  
  91.     // Parse out the tag name.
  92.     $space = strpos( $text, ' ' );
  93.     if ( false === $space ) {
  94.         $space = -1;
  95.     } else {
  96.         $space -= $name_offset;
  97.     }
  98.     $tag = substr( $text, $name_offset, $space );
  99.  
  100.     // Handle disabled tags.
  101.     if ( in_array( $tag, $disabled_elements ) ) {
  102.         if ( $opening_tag ) {
  103.             /*
  104.              * This disables texturize until we find a closing tag of our type
  105.              * (e.g. <pre>) even if there was invalid nesting before that
  106.              *
  107.              * Example: in the case <pre>sadsadasd</code>"baba"</pre>
  108.              *          "baba" won't be texturize
  109.              */
  110.  
  111.             array_push( $stack, $tag );
  112.         } elseif ( end( $stack ) == $tag ) {
  113.             array_pop( $stack );
  114.         }
  115.     }
  116. }
  117.  
  118. /**
  119.  * Newline preservation help function for wpautop
  120.  *
  121.  * @since 3.1.0
  122.  * @access private
  123.  *
  124.  * @param array $matches preg_replace_callback matches array
  125.  * @return string
  126.  */
  127. function _autop_newline_preservation_helper( $matches ) {
  128.     return str_replace( "\n", "<WPPreserveNewline />", $matches[0] );
  129. }
  130.  
  131. /**
  132.  * Replaces common plain text characters into formatted entities
  133.  *
  134.  * As an example,
  135.  *
  136.  *     'cause today's effort makes it worth tomorrow's "holiday" ...
  137.  *
  138.  * Becomes:
  139.  *
  140.  *     &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221; &#8230;
  141.  *
  142.  * Code within certain html blocks are skipped.
  143.  *
  144.  * Do not use this function before the 'init' action hook; everything will break.
  145.  *
  146.  * @since 0.71
  147.  *
  148.  * @global array $wp_cockneyreplace Array of formatted entities for certain common phrases
  149.  * @global array $shortcode_tags
  150.  * @staticvar array $static_characters
  151.  * @staticvar array $static_replacements
  152.  * @staticvar array $dynamic_characters
  153.  * @staticvar array $dynamic_replacements
  154.  * @staticvar array $default_no_texturize_tags
  155.  * @staticvar array $default_no_texturize_shortcodes
  156.  * @staticvar bool  $run_texturize
  157.  *
  158.  * @param string $text The text to be formatted
  159.  * @param bool   $reset Set to true for unit testing. Translated patterns will reset.
  160.  * @return string The string replaced with html entities
  161.  */
  162. function wptexturize( $text, $reset = false ) {
  163.     global $wp_cockneyreplace, $shortcode_tags;
  164.     static $static_characters = null,
  165.         $static_replacements = null,
  166.         $dynamic_characters = null,
  167.         $dynamic_replacements = null,
  168.         $default_no_texturize_tags = null,
  169.         $default_no_texturize_shortcodes = null,
  170.         $run_texturize = true,
  171.         $apos = null,
  172.         $prime = null,
  173.         $double_prime = null,
  174.         $opening_quote = null,
  175.         $closing_quote = null,
  176.         $opening_single_quote = null,
  177.         $closing_single_quote = null,
  178.         $open_q_flag = '<!--oq-->',
  179.         $open_sq_flag = '<!--osq-->',
  180.         $apos_flag = '<!--apos-->';
  181.  
  182.     // If there's nothing to do, just stop.
  183.     if ( empty( $text ) || false === $run_texturize ) {
  184.         return $text;
  185.     }
  186.  
  187.     // Set up static variables. Run once only.
  188.     if ( $reset || ! isset( $static_characters ) ) {
  189.         /**
  190.          * Filter whether to skip running wptexturize().
  191.          *
  192.          * Passing false to the filter will effectively short-circuit wptexturize().
  193.          * returning the original text passed to the function instead.
  194.          *
  195.          * The filter runs only once, the first time wptexturize() is called.
  196.          *
  197.          * @since 4.0.0
  198.          *
  199.          * @see wptexturize()
  200.          *
  201.          * @param bool $run_texturize Whether to short-circuit wptexturize().
  202.          */
  203.         $run_texturize = apply_filters( 'run_wptexturize', $run_texturize );
  204.         if ( false === $run_texturize ) {
  205.             return $text;
  206.         }
  207.  
  208.         /* translators: opening curly double quote */
  209.         $opening_quote = _x( '&#8220;', 'opening curly double quote' );
  210.         /* translators: closing curly double quote */
  211.         $closing_quote = _x( '&#8221;', 'closing curly double quote' );
  212.  
  213.         /* translators: apostrophe, for example in 'cause or can't */
  214.         $apos = _x( '&#8217;', 'apostrophe' );
  215.  
  216.         /* translators: prime, for example in 9' (nine feet) */
  217.         $prime = _x( '&#8242;', 'prime' );
  218.         /* translators: double prime, for example in 9" (nine inches) */
  219.         $double_prime = _x( '&#8243;', 'double prime' );
  220.  
  221.         /* translators: opening curly single quote */
  222.         $opening_single_quote = _x( '&#8216;', 'opening curly single quote' );
  223.         /* translators: closing curly single quote */
  224.         $closing_single_quote = _x( '&#8217;', 'closing curly single quote' );
  225.  
  226.         /* translators: en dash */
  227.         $en_dash = _x( '&#8211;', 'en dash' );
  228.         /* translators: em dash */
  229.         $em_dash = _x( '&#8212;', 'em dash' );
  230.  
  231.         $default_no_texturize_tags = array('pre', 'code', 'kbd', 'style', 'script', 'tt');
  232.         $default_no_texturize_shortcodes = array('code');
  233.  
  234.         // if a plugin has provided an autocorrect array, use it
  235.         if ( isset($wp_cockneyreplace) ) {
  236.             $cockney = array_keys( $wp_cockneyreplace );
  237.             $cockneyreplace = array_values( $wp_cockneyreplace );
  238.         } else {
  239.             /* translators: This is a comma-separated list of words that defy the syntax of quotations in normal use,
  240.              * for example...  'We do not have enough words yet' ... is a typical quoted phrase.  But when we write
  241.              * lines of code 'til we have enough of 'em, then we need to insert apostrophes instead of quotes.
  242.              */
  243.             $cockney = explode( ',', _x( "'tain't,'twere,'twas,'tis,'twill,'til,'bout,'nuff,'round,'cause,'em",
  244.                 'Comma-separated list of words to texturize in your language' ) );
  245.  
  246.             $cockneyreplace = explode( ',', _x( '&#8217;tain&#8217;t,&#8217;twere,&#8217;twas,&#8217;tis,&#8217;twill,&#8217;til,&#8217;bout,&#8217;nuff,&#8217;round,&#8217;cause,&#8217;em',
  247.                 'Comma-separated list of replacement words in your language' ) );
  248.         }
  249.  
  250.         $static_characters = array_merge( array( '...', '``', '\'\'', ' (tm)' ), $cockney );
  251.         $static_replacements = array_merge( array( '&#8230;', $opening_quote, $closing_quote, ' &#8482;' ), $cockneyreplace );
  252.  
  253.  
  254.         // Pattern-based replacements of characters.
  255.         // Sort the remaining patterns into several arrays for performance tuning.
  256.         $dynamic_characters = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
  257.         $dynamic_replacements = array( 'apos' => array(), 'quote' => array(), 'dash' => array() );
  258.         $dynamic = array();
  259.         $spaces = wp_spaces_regexp();
  260.  
  261.         // '99' and '99" are ambiguous among other patterns; assume it's an abbreviated year at the end of a quotation.
  262.         if ( "'" !== $apos || "'" !== $closing_single_quote ) {
  263.             $dynamic[ '/\'(\d\d)\'(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_single_quote;
  264.         }
  265.         if ( "'" !== $apos || '"' !== $closing_quote ) {
  266.             $dynamic[ '/\'(\d\d)"(?=\Z|[.,:;!?)}\-\]]|&gt;|' . $spaces . ')/' ] = $apos_flag . '$1' . $closing_quote;
  267.         }
  268.  
  269.         // '99 '99s '99's (apostrophe)  But never '9 or '99% or '999 or '99.0.
  270.         if ( "'" !== $apos ) {
  271.             $dynamic[ '/\'(?=\d\d(?:\Z|(?![%\d]|[.,]\d)))/' ] = $apos_flag;
  272.         }
  273.  
  274.         // Quoted Numbers like '0.42'
  275.         if ( "'" !== $opening_single_quote && "'" !== $closing_single_quote ) {
  276.             $dynamic[ '/(?<=\A|' . $spaces . ')\'(\d[.,\d]*)\'/' ] = $open_sq_flag . '$1' . $closing_single_quote;
  277.         }
  278.  
  279.         // Single quote at start, or preceded by (, {, <, [, ", -, or spaces.
  280.         if ( "'" !== $opening_single_quote ) {
  281.             $dynamic[ '/(?<=\A|[([{"\-]|&lt;|' . $spaces . ')\'/' ] = $open_sq_flag;
  282.         }
  283.  
  284.         // Apostrophe in a word.  No spaces, double apostrophes, or other punctuation.
  285.         if ( "'" !== $apos ) {
  286.             $dynamic[ '/(?<!' . $spaces . ')\'(?!\Z|[.,:;!?"\'(){}[\]\-]|&[lg]t;|' . $spaces . ')/' ] = $apos_flag;
  287.         }
  288.  
  289.         $dynamic_characters['apos'] = array_keys( $dynamic );
  290.         $dynamic_replacements['apos'] = array_values( $dynamic );
  291.         $dynamic = array();
  292.  
  293.         // Quoted Numbers like "42"
  294.         if ( '"' !== $opening_quote && '"' !== $closing_quote ) {
  295.             $dynamic[ '/(?<=\A|' . $spaces . ')"(\d[.,\d]*)"/' ] = $open_q_flag . '$1' . $closing_quote;
  296.         }
  297.  
  298.         // Double quote at start, or preceded by (, {, <, [, -, or spaces, and not followed by spaces.
  299.         if ( '"' !== $opening_quote ) {
  300.             $dynamic[ '/(?<=\A|[([{\-]|&lt;|' . $spaces . ')"(?!' . $spaces . ')/' ] = $open_q_flag;
  301.         }
  302.  
  303.         $dynamic_characters['quote'] = array_keys( $dynamic );
  304.         $dynamic_replacements['quote'] = array_values( $dynamic );
  305.         $dynamic = array();
  306.  
  307.         // Dashes and spaces
  308.         $dynamic[ '/---/' ] = $em_dash;
  309.         $dynamic[ '/(?<=^|' . $spaces . ')--(?=$|' . $spaces . ')/' ] = $em_dash;
  310.         $dynamic[ '/(?<!xn)--/' ] = $en_dash;
  311.         $dynamic[ '/(?<=^|' . $spaces . ')-(?=$|' . $spaces . ')/' ] = $en_dash;
  312.  
  313.         $dynamic_characters['dash'] = array_keys( $dynamic );
  314.         $dynamic_replacements['dash'] = array_values( $dynamic );
  315.     }
  316.  
  317.     // Must do this every time in case plugins use these filters in a context sensitive manner
  318.     /**
  319.      * Filter the list of HTML elements not to texturize.
  320.      *
  321.      * @since 2.8.0
  322.      *
  323.      * @param array $default_no_texturize_tags An array of HTML element names.
  324.      */
  325.     $no_texturize_tags = apply_filters( 'no_texturize_tags', $default_no_texturize_tags );
  326.     /**
  327.      * Filter the list of shortcodes not to texturize.
  328.      *
  329.      * @since 2.8.0
  330.      *
  331.      * @param array $default_no_texturize_shortcodes An array of shortcode names.
  332.      */
  333.     $no_texturize_shortcodes = apply_filters( 'no_texturize_shortcodes', $default_no_texturize_shortcodes );
  334.  
  335.     $no_texturize_tags_stack = array();
  336.     $no_texturize_shortcodes_stack = array();
  337.  
  338.     // Look for shortcodes and HTML elements.
  339.  
  340.     preg_match_all( '@\[/?([^<>&/\[\]\x00-\x20=]++)@', $text, $matches );
  341.     $tagnames = $shortcode_tags ? array_intersect( array_keys( $shortcode_tags ), $matches[1] ) : array();
  342.     $found_shortcodes = ! empty( $tagnames );
  343.     $shortcode_regex = $found_shortcodes ? _get_wptexturize_shortcode_regex( $tagnames ) : '';
  344.     $regex = _get_wptexturize_split_regex( $shortcode_regex );
  345.  
  346.     $textarr = preg_split( $regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
  347.  
  348.     foreach ( $textarr as &$curl ) {
  349.         // Only call _wptexturize_pushpop_element if $curl is a delimiter.
  350.         $first = $curl[0];
  351.         if ( '<' === $first ) {
  352.             if ( '<!--' === substr( $curl, 0, 4 ) ) {
  353.                 // This is an HTML comment delimiter.
  354.                 continue;
  355.             } else {
  356.                 // This is an HTML element delimiter.
  357.  
  358.                 // Replace each & with &#038; unless it already looks like an entity.
  359.                 $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&#038;', $curl );
  360.  
  361.                 _wptexturize_pushpop_element( $curl, $no_texturize_tags_stack, $no_texturize_tags );
  362.             }
  363.  
  364.         } elseif ( '' === trim( $curl ) ) {
  365.             // This is a newline between delimiters.  Performance improves when we check this.
  366.             continue;
  367.  
  368.         } elseif ( '[' === $first && $found_shortcodes && 1 === preg_match( '/^' . $shortcode_regex . '$/', $curl ) ) {
  369.             // This is a shortcode delimiter.
  370.  
  371.             if ( '[[' !== substr( $curl, 0, 2 ) && ']]' !== substr( $curl, -2 ) ) {
  372.                 // Looks like a normal shortcode.
  373.                 _wptexturize_pushpop_element( $curl, $no_texturize_shortcodes_stack, $no_texturize_shortcodes );
  374.             } else {
  375.                 // Looks like an escaped shortcode.
  376.                 continue;
  377.             }
  378.  
  379.         } elseif ( empty( $no_texturize_shortcodes_stack ) && empty( $no_texturize_tags_stack ) ) {
  380.             // This is neither a delimiter, nor is this content inside of no_texturize pairs.  Do texturize.
  381.  
  382.             $curl = str_replace( $static_characters, $static_replacements, $curl );
  383.  
  384.             if ( false !== strpos( $curl, "'" ) ) {
  385.                 $curl = preg_replace( $dynamic_characters['apos'], $dynamic_replacements['apos'], $curl );
  386.                 $curl = wptexturize_primes( $curl, "'", $prime, $open_sq_flag, $closing_single_quote );
  387.                 $curl = str_replace( $apos_flag, $apos, $curl );
  388.                 $curl = str_replace( $open_sq_flag, $opening_single_quote, $curl );
  389.             }
  390.             if ( false !== strpos( $curl, '"' ) ) {
  391.                 $curl = preg_replace( $dynamic_characters['quote'], $dynamic_replacements['quote'], $curl );
  392.                 $curl = wptexturize_primes( $curl, '"', $double_prime, $open_q_flag, $closing_quote );
  393.                 $curl = str_replace( $open_q_flag, $opening_quote, $curl );
  394.             }
  395.             if ( false !== strpos( $curl, '-' ) ) {
  396.                 $curl = preg_replace( $dynamic_characters['dash'], $dynamic_replacements['dash'], $curl );
  397.             }
  398.  
  399.             // 9x9 (times), but never 0x9999
  400.             if ( 1 === preg_match( '/(?<=\d)x\d/', $curl ) ) {
  401.                 // Searching for a digit is 10 times more expensive than for the x, so we avoid doing this one!
  402.                 $curl = preg_replace( '/\b(\d(?(?<=0)[\d\.,]+|[\d\.,]*))x(\d[\d\.,]*)\b/', '$1&#215;$2', $curl );
  403.             }
  404.  
  405.             // Replace each & with &#038; unless it already looks like an entity.
  406.             $curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&#038;', $curl );
  407.         }
  408.     }
  409.  
  410.     return implode( '', $textarr );
  411. }
  412.  
  413. /**
  414.  * Separate HTML elements and comments from the text.
  415.  *
  416.  * @since 4.2.4
  417.  *
  418.  * @param string $input The text which has to be formatted.
  419.  * @return array The formatted text.
  420.  */
  421. function wp_html_split( $input ) {
  422.     return preg_split( get_html_split_regex(), $input, -1, PREG_SPLIT_DELIM_CAPTURE );
  423. }
  424.  
  425. /**
  426.  * Replace characters or phrases within HTML elements only.
  427.  *
  428.  * @since 4.2.3
  429.  *
  430.  * @param string $haystack The text which has to be formatted.
  431.  * @param array $replace_pairs In the form array('from' => 'to', ...).
  432.  * @return string The formatted text.
  433.  */
  434. function wp_replace_in_html_tags( $haystack, $replace_pairs ) {
  435.     // Find all elements.
  436.     $textarr = wp_html_split( $haystack );
  437.     $changed = false;
  438.  
  439.     // Optimize when searching for one item.
  440.     if ( 1 === count( $replace_pairs ) ) {
  441.         // Extract $needle and $replace.
  442.         foreach ( $replace_pairs as $needle => $replace );
  443.  
  444.         // Loop through delimiters (elements) only.
  445.         for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
  446.             if ( false !== strpos( $textarr[$i], $needle ) ) {
  447.                 $textarr[$i] = str_replace( $needle, $replace, $textarr[$i] );
  448.                 $changed = true;
  449.             }
  450.         }
  451.     } else {
  452.         // Extract all $needles.
  453.         $needles = array_keys( $replace_pairs );
  454.  
  455.         // Loop through delimiters (elements) only.
  456.         for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) {
  457.             foreach ( $needles as $needle ) {
  458.                 if ( false !== strpos( $textarr[$i], $needle ) ) {
  459.                     $textarr[$i] = strtr( $textarr[$i], $replace_pairs );
  460.                     $changed = true;
  461.                     // After one strtr() break out of the foreach loop and look at next element.
  462.                     break;
  463.                 }
  464.             }
  465.         }
  466.     }
  467.  
  468.     if ( $changed ) {
  469.         $haystack = implode( $textarr );
  470.     }
  471.  
  472.     return $haystack;
  473. }
  474.  
  475. /**
  476.  * Replaces double line-breaks with paragraph elements.
  477.  *
  478.  * A group of regex replaces used to identify text formatted with newlines and
  479.  * replace double line-breaks with HTML paragraph tags. The remaining line-breaks
  480.  * after conversion become <<br />> tags, unless $br is set to '0' or 'false'.
  481.  *
  482.  * @since 0.71
  483.  *
  484.  * @param string $pee The text which has to be formatted.
  485.  * @param bool   $br  Optional. If set, this will convert all remaining line-breaks
  486.  *                    after paragraphing. Default true.
  487.  * @return string Text which has been converted into correct paragraph tags.
  488.  */
  489. function wpautop( $pee, $br = true ) {
  490.     $pre_tags = array();
  491.  
  492.     if ( trim($pee) === '' )
  493.         return '';
  494.  
  495.     // Just to make things a little easier, pad the end.
  496.     $pee = $pee . "\n";
  497.  
  498.     /*
  499.      * Pre tags shouldn't be touched by autop.
  500.      * Replace pre tags with placeholders and bring them back after autop.
  501.      */
  502.     if ( strpos($pee, '<pre') !== false ) {
  503.         $pee_parts = explode( '</pre>', $pee );
  504.         $last_pee = array_pop($pee_parts);
  505.         $pee = '';
  506.         $i = 0;
  507.  
  508.         foreach ( $pee_parts as $pee_part ) {
  509.             $start = strpos($pee_part, '<pre');
  510.  
  511.             // Malformed html?
  512.             if ( $start === false ) {
  513.                 $pee .= $pee_part;
  514.                 continue;
  515.             }
  516.  
  517.             $name = "<pre wp-pre-tag-$i></pre>";
  518.             $pre_tags[$name] = substr( $pee_part, $start ) . '</pre>';
  519.  
  520.             $pee .= substr( $pee_part, 0, $start ) . $name;
  521.             $i++;
  522.         }
  523.  
  524.         $pee .= $last_pee;
  525.     }
  526.     // Change multiple <br>s into two line breaks, which will turn into paragraphs.
  527.     $pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
  528.  
  529.     $allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
  530.  
  531.     // Add a single line break above block-level opening tags.
  532.     $pee = preg_replace('!(<' . $allblocks . '[\s/>])!', "\n$1", $pee);
  533.  
  534.     // Add a double line break below block-level closing tags.
  535.     $pee = preg_replace('!(</' . $allblocks . '>)!', "$1\n\n", $pee);
  536.  
  537.     // Standardize newline characters to "\n".
  538.     $pee = str_replace(array("\r\n", "\r"), "\n", $pee);
  539.  
  540.     // Find newlines in all elements and add placeholders.
  541.     $pee = wp_replace_in_html_tags( $pee, array( "\n" => " <!-- wpnl --> " ) );
  542.  
  543.     // Collapse line breaks before and after <option> elements so they don't get autop'd.
  544.     if ( strpos( $pee, '<option' ) !== false ) {
  545.         $pee = preg_replace( '|\s*<option|', '<option', $pee );
  546.         $pee = preg_replace( '|</option>\s*|', '</option>', $pee );
  547.     }
  548.  
  549.     /*
  550.      * Collapse line breaks inside <object> elements, before <param> and <embed> elements
  551.      * so they don't get autop'd.
  552.      */
  553.     if ( strpos( $pee, '</object>' ) !== false ) {
  554.         $pee = preg_replace( '|(<object[^>]*>)\s*|', '$1', $pee );
  555.         $pee = preg_replace( '|\s*</object>|', '</object>', $pee );
  556.         $pee = preg_replace( '%\s*(</?(?:param|embed)[^>]*>)\s*%', '$1', $pee );
  557.     }
  558.  
  559.     /*
  560.      * Collapse line breaks inside <audio> and <video> elements,
  561.      * before and after <source> and <track> elements.
  562.      */
  563.     if ( strpos( $pee, '<source' ) !== false || strpos( $pee, '<track' ) !== false ) {
  564.         $pee = preg_replace( '%([<\[](?:audio|video)[^>\]]*[>\]])\s*%', '$1', $pee );
  565.         $pee = preg_replace( '%\s*([<\[]/(?:audio|video)[>\]])%', '$1', $pee );
  566.         $pee = preg_replace( '%\s*(<(?:source|track)[^>]*>)\s*%', '$1', $pee );
  567.     }
  568.  
  569.     // Remove more than two contiguous line breaks.
  570.     $pee = preg_replace("/\n\n+/", "\n\n", $pee);
  571.  
  572.     // Split up the contents into an array of strings, separated by double line breaks.
  573.     $pees = preg_split('/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY);
  574.  
  575.     // Reset $pee prior to rebuilding.
  576.     $pee = '';
  577.  
  578.     // Rebuild the content as a string, wrapping every bit with a <p>.
  579.     foreach ( $pees as $tinkle ) {
  580.         $pee .= '<p>' . trim($tinkle, "\n") . "</p>\n";
  581.     }
  582.  
  583.     // Under certain strange conditions it could create a P of entirely whitespace.
  584.     $pee = preg_replace('|<p>\s*</p>|', '', $pee);
  585.  
  586.     // Add a closing <p> inside <div>, <address>, or <form> tag if missing.
  587.     $pee = preg_replace('!<p>([^<]+)</(div|address|form)>!', "<p>$1</p></$2>", $pee);
  588.  
  589.     // If an opening or closing block element tag is wrapped in a <p>, unwrap it.
  590.     $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
  591.  
  592.     // In some cases <li> may get wrapped in <p>, fix them.
  593.     $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee);
  594.  
  595.     // If a <blockquote> is wrapped with a <p>, move it inside the <blockquote>.
  596.     $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee);
  597.     $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee);
  598.  
  599.     // If an opening or closing block element tag is preceded by an opening <p> tag, remove it.
  600.     $pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
  601.  
  602.     // If an opening or closing block element tag is followed by a closing <p> tag, remove it.
  603.     $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
  604.  
  605.     // Optionally insert line breaks.
  606.     if ( $br ) {
  607.         // Replace newlines that shouldn't be touched with a placeholder.
  608.         $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
  609.  
  610.         // Normalize <br>
  611.         $pee = str_replace( array( '<br>', '<br/>' ), '<br />', $pee );
  612.  
  613.         // Replace any new line characters that aren't preceded by a <br /> with a <br />.
  614.         $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee);
  615.  
  616.         // Replace newline placeholders with newlines.
  617.         $pee = str_replace('<WPPreserveNewline />', "\n", $pee);
  618.     }
  619.  
  620.     // If a <br /> tag is after an opening or closing block tag, remove it.
  621.     $pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee);
  622.  
  623.     // If a <br /> tag is before a subset of opening or closing block tags, remove it.
  624.     $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
  625.     $pee = preg_replace( "|\n</p>$|", '</p>', $pee );
  626.  
  627.     // Replace placeholder <pre> tags with their original content.
  628.     if ( !empty($pre_tags) )
  629.         $pee = str_replace(array_keys($pre_tags), array_values($pre_tags), $pee);
  630.  
  631.     // Restore newlines in all elements.
  632.     if ( false !== strpos( $pee, '<!-- wpnl -->' ) ) {
  633.         $pee = str_replace( array( ' <!-- wpnl --> ', '<!-- wpnl -->' ), "\n", $pee );
  634.     }
  635.  
  636.     return $pee;
  637. }
  638.  
  639. /**
  640.  * Returns the regexp for common whitespace characters.
  641.  *
  642.  * By default, spaces include new lines, tabs, nbsp entities, and the UTF-8 nbsp.
  643.  * This is designed to replace the PCRE \s sequence.  In ticket #22692, that
  644.  * sequence was found to be unreliable due to random inclusion of the A0 byte.
  645.  *
  646.  * @since 4.0.0
  647.  *
  648.  * @staticvar string $spaces
  649.  *
  650.  * @return string The spaces regexp.
  651.  */
  652. function wp_spaces_regexp() {
  653.     static $spaces = '';
  654.  
  655.     if ( empty( $spaces ) ) {
  656.         /**
  657.          * Filter the regexp for common whitespace characters.
  658.          *
  659.          * This string is substituted for the \s sequence as needed in regular
  660.          * expressions. For websites not written in English, different characters
  661.          * may represent whitespace. For websites not encoded in UTF-8, the 0xC2 0xA0
  662.          * sequence may not be in use.
  663.          *
  664.          * @since 4.0.0
  665.          *
  666.          * @param string $spaces Regexp pattern for matching common whitespace characters.
  667.          */
  668.         $spaces = apply_filters( 'wp_spaces_regexp', '[\r\n\t ]|\xC2\xA0|&nbsp;' );
  669.     }
  670.  
  671.     return $spaces;
  672. }
  673.  
  674. /**
  675.  * Implements a logic tree to determine whether or not "7'." represents seven feet,
  676.  * then converts the special char into either a prime char or a closing quote char.
  677.  *
  678.  * @since 4.3.0
  679.  *
  680.  * @param string $haystack    The plain text to be searched.
  681.  * @param string $needle      The character to search for such as ' or ".
  682.  * @param string $prime       The prime char to use for replacement.
  683.  * @param string $open_quote  The opening quote char. Opening quote replacement must be
  684.  *                            accomplished already.
  685.  * @param string $close_quote The closing quote char to use for replacement.
  686.  * @return string The $haystack value after primes and quotes replacements.
  687.  */
  688. function wptexturize_primes( $haystack, $needle, $prime, $open_quote, $close_quote ) {
  689.     $spaces = wp_spaces_regexp();
  690.     $flag = '<!--wp-prime-or-quote-->';
  691.     $quote_pattern = "/$needle(?=\\Z|[.,:;!?)}\\-\\]]|&gt;|" . $spaces . ")/";
  692.     $prime_pattern    = "/(?<=\\d)$needle/";
  693.     $flag_after_digit = "/(?<=\\d)$flag/";
  694.     $flag_no_digit    = "/(?<!\\d)$flag/";
  695.  
  696.     $sentences = explode( $open_quote, $haystack );
  697.  
  698.     foreach ( $sentences as $key => &$sentence ) {
  699.         if ( false === strpos( $sentence, $needle ) ) {
  700.             continue;
  701.         } elseif ( 0 !== $key && 0 === substr_count( $sentence, $close_quote ) ) {
  702.             $sentence = preg_replace( $quote_pattern, $flag, $sentence, -1, $count );
  703.             if ( $count > 1 ) {
  704.                 // This sentence appears to have multiple closing quotes.  Attempt Vulcan logic.
  705.                 $sentence = preg_replace( $flag_no_digit, $close_quote, $sentence, -1, $count2 );
  706.                 if ( 0 === $count2 ) {
  707.                     // Try looking for a quote followed by a period.
  708.                     $count2 = substr_count( $sentence, "$flag." );
  709.                     if ( $count2 > 0 ) {
  710.                         // Assume the rightmost quote-period match is the end of quotation.
  711.                         $pos = strrpos( $sentence, "$flag." );
  712.                     } else {
  713.                         // When all else fails, make the rightmost candidate a closing quote.
  714.                         // This is most likely to be problematic in the context of bug #18549.
  715.                         $pos = strrpos( $sentence, $flag );
  716.                     }
  717.                     $sentence = substr_replace( $sentence, $close_quote, $pos, strlen( $flag ) );
  718.                 }
  719.                 // Use conventional replacement on any remaining primes and quotes.
  720.                 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
  721.                 $sentence = preg_replace( $flag_after_digit, $prime, $sentence );
  722.                 $sentence = str_replace( $flag, $close_quote, $sentence );
  723.             } elseif ( 1 == $count ) {
  724.                 // Found only one closing quote candidate, so give it priority over primes.
  725.                 $sentence = str_replace( $flag, $close_quote, $sentence );
  726.                 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
  727.             } else {
  728.                 // No closing quotes found.  Just run primes pattern.
  729.                 $sentence = preg_replace( $prime_pattern, $prime, $sentence );
  730.             }
  731.         } else {
  732.             $sentence = preg_replace( $prime_pattern, $prime, $sentence );
  733.             $sentence = preg_replace( $quote_pattern, $close_quote, $sentence );
  734.         }
  735.         if ( '"' == $needle && false !== strpos( $sentence, '"' ) ) {
  736.             $sentence = str_replace( '"', $close_quote, $sentence );
  737.         }
  738.     }
  739.  
  740.     return implode( $open_quote, $sentences );
  741. }
  742.  
  743. /**
  744.  * Retrieve the name of the current filter or action.
  745.  *
  746.  * @since 2.5.0
  747.  *
  748.  * @global array $wp_current_filter Stores the list of current filters with the current one last
  749.  *
  750.  * @return string Hook name of the current filter or action.
  751.  */
  752. function current_filter() {
  753.     return "the_content";
  754. }
  755.  
  756. /**
  757.  * Convert text equivalent of smilies to images.
  758.  *
  759.  * Will only convert smilies if the option 'use_smilies' is true and the global
  760.  * used in the function isn't empty.
  761.  *
  762.  * @since 0.71
  763.  *
  764.  * @global string|array $wp_smiliessearch
  765.  *
  766.  * @param string $text Content to convert smilies from text.
  767.  * @return string Converted content with text smilies replaced with images.
  768.  */
  769. function convert_smilies( $text ) {
  770.     return $text;
  771. }
  772.  
  773. /**
  774.  * Retrieve the regular expression for an HTML element.
  775.  *
  776.  * @since 4.4.0
  777.  *
  778.  * @return string The regular expression
  779.  */
  780. function get_html_split_regex() {
  781.     static $regex;
  782.  
  783.     if ( ! isset( $regex ) ) {
  784.         $comments =
  785.               '!'           // Start of comment, after the <.
  786.             . '(?:'         // Unroll the loop: Consume everything until --> is found.
  787.             .     '-(?!->)' // Dash not followed by end of comment.
  788.             .     '[^\-]*+' // Consume non-dashes.
  789.             . ')*+'         // Loop possessively.
  790.             . '(?:-->)?';   // End of comment. If not found, match all input.
  791.  
  792.         $cdata =
  793.               '!\[CDATA\['  // Start of comment, after the <.
  794.             . '[^\]]*+'     // Consume non-].
  795.             . '(?:'         // Unroll the loop: Consume everything until ]]> is found.
  796.             .     '](?!]>)' // One ] not followed by end of comment.
  797.             .     '[^\]]*+' // Consume non-].
  798.             . ')*+'         // Loop possessively.
  799.             . '(?:]]>)?';   // End of comment. If not found, match all input.
  800.  
  801.         $escaped =
  802.               '(?='           // Is the element escaped?
  803.             .    '!--'
  804.             . '|'
  805.             .    '!\[CDATA\['
  806.             . ')'
  807.             . '(?(?=!-)'      // If yes, which type?
  808.             .     $comments
  809.             . '|'
  810.             .     $cdata
  811.             . ')';
  812.  
  813.         $regex =
  814.               '/('              // Capture the entire match.
  815.             .     '<'           // Find start of element.
  816.             .     '(?'          // Conditional expression follows.
  817.             .         $escaped  // Find end of escaped element.
  818.             .     '|'           // ... else ...
  819.             .         '[^>]*>?' // Find end of normal element.
  820.             .     ')'
  821.             . ')/';
  822.     }
  823.  
  824.     return $regex;
  825. }
  826.  
  827. /**
  828.  * Don't auto-p wrap shortcodes that stand alone
  829.  *
  830.  * Ensures that shortcodes are not wrapped in `<p>...</p>`.
  831.  *
  832.  * @since 2.9.0
  833.  *
  834.  * @global array $shortcode_tags
  835.  *
  836.  * @param string $pee The content.
  837.  * @return string The filtered content.
  838.  */
  839. function shortcode_unautop( $pee ) {
  840.     global $shortcode_tags;
  841.  
  842.     if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) {
  843.         return $pee;
  844.     }
  845.  
  846.     $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
  847.     $spaces = wp_spaces_regexp();
  848.  
  849.     $pattern =
  850.           '/'
  851.         . '<p>'                              // Opening paragraph
  852.         . '(?:' . $spaces . ')*+'            // Optional leading whitespace
  853.         . '('                                // 1: The shortcode
  854.         .     '\\['                          // Opening bracket
  855.         .     "($tagregexp)"                 // 2: Shortcode name
  856.         .     '(?![\\w-])'                   // Not followed by word character or hyphen
  857.                                              // Unroll the loop: Inside the opening shortcode tag
  858.         .     '[^\\]\\/]*'                   // Not a closing bracket or forward slash
  859.         .     '(?:'
  860.         .         '\\/(?!\\])'               // A forward slash not followed by a closing bracket
  861.         .         '[^\\]\\/]*'               // Not a closing bracket or forward slash
  862.         .     ')*?'
  863.         .     '(?:'
  864.         .         '\\/\\]'                   // Self closing tag and closing bracket
  865.         .     '|'
  866.         .         '\\]'                      // Closing bracket
  867.         .         '(?:'                      // Unroll the loop: Optionally, anything between the opening and closing shortcode tags
  868.         .             '[^\\[]*+'             // Not an opening bracket
  869.         .             '(?:'
  870.         .                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
  871.         .                 '[^\\[]*+'         // Not an opening bracket
  872.         .             ')*+'
  873.         .             '\\[\\/\\2\\]'         // Closing shortcode tag
  874.         .         ')?'
  875.         .     ')'
  876.         . ')'
  877.         . '(?:' . $spaces . ')*+'            // optional trailing whitespace
  878.         . '<\\/p>'                           // closing paragraph
  879.         . '/';
  880.  
  881.     return preg_replace( $pattern, '$1', $pee );
  882. }
  883.  
  884.  
  885. /**
  886.  * Forever eliminate "Wordpress" from the planet (or at least the little bit we can influence).
  887.  *
  888.  * Violating our coding standards for a good function name.
  889.  *
  890.  * @since 3.0.0
  891.  *
  892.  * @staticvar string|false $dblq
  893.  */
  894. function capital_P_dangit( $text ) {
  895.     // Simple replacement for titles
  896.     $current_filter = current_filter();
  897.     if ( 'the_title' === $current_filter || 'wp_title' === $current_filter )
  898.         return str_replace( 'Wordpress', 'WordPress', $text );
  899.     // Still here? Use the more judicious replacement
  900.     static $dblq = false;
  901.     if ( false === $dblq ) {
  902.         $dblq = _x( '&#8220;', 'opening curly double quote' );
  903.     }
  904.     return str_replace(
  905.         array( ' Wordpress', '&#8216;Wordpress', $dblq . 'Wordpress', '>Wordpress', '(Wordpress' ),
  906.         array( ' WordPress', '&#8216;WordPress', $dblq . 'WordPress', '>WordPress', '(WordPress' ),
  907.     $text );
  908. }
  909.  
  910. /**
  911.  * Call the functions added to a filter hook.
  912.  *
  913.  * The callback functions attached to filter hook $tag are invoked by calling
  914.  * this function. This function can be used to create a new filter hook by
  915.  * simply calling this function with the name of the new hook specified using
  916.  * the $tag parameter.
  917.  *
  918.  * The function allows for additional arguments to be added and passed to hooks.
  919.  *
  920.  *     // Our filter callback function
  921.  *     function example_callback( $string, $arg1, $arg2 ) {
  922.  *         // (maybe) modify $string
  923.  *         return $string;
  924.  *     }
  925.  *     add_filter( 'example_filter', 'example_callback', 10, 3 );
  926.  *
  927.  *     /*
  928.  *      * Apply the filters by calling the 'example_callback' function we
  929.  *      * "hooked" to 'example_filter' using the add_filter() function above.
  930.  *      * - 'example_filter' is the filter hook $tag
  931.  *      * - 'filter me' is the value being filtered
  932.  *      * - $arg1 and $arg2 are the additional arguments passed to the callback.
  933.  *     $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
  934.  *
  935.  * @since 0.71
  936.  *
  937.  * @global array $wp_filter         Stores all of the filters.
  938.  * @global array $merged_filters    Merges the filter hooks using this function.
  939.  * @global array $wp_current_filter Stores the list of current filters with the current one last.
  940.  *
  941.  * @param string $tag   The name of the filter hook.
  942.  * @param mixed  $value The value on which the filters hooked to `$tag` are applied on.
  943.  * @param mixed  $var   Additional variables passed to the functions hooked to `$tag`.
  944.  * @return mixed The filtered value after all hooked functions are applied to it.
  945.  */
  946. function apply_filters( $tag, $value ) {
  947.     if ( $tag == 'the_content' ) {
  948.         $value = wptexturize( $value, true );
  949.         $value = convert_smilies( $value );
  950.         $value = wpautop( $value );
  951.         $value = shortcode_unautop( $value );
  952.         //$value = prepend_attachment( $value );
  953.         //$value = wp_make_content_images_responsive( $value );
  954.         $value = capital_P_dangit( $value );
  955.         //$value = do_shortcode( $value );
  956.         //$value = qtranxf_useCurrentLanguageIfNotFoundShowAvailable( $value );
  957.     }
  958.     return $value;
  959. }
  960.  
  961. /**
  962.  * 新着情報
  963.  */
  964. class Dao_WpNewsPosts extends Dao_Base {
  965.     protected $_name    = 'wp_news_posts';
  966.     protected $_primary = 'ID';
  967.  
  968.     /**
  969.      * 言語振り分け
  970.      */
  971.     private function splitText($str) {
  972.         $titles = explode("[:jp]", $str);
  973.         if (strlen($str)) {
  974.             if (count($titles) == 2) {
  975.                 $txt_id = preg_replace("/^\[:id\]/","",$titles[0]);
  976.                 $txt_jp = preg_replace("/\[:\]$/","",$titles[1]);
  977.             } else {
  978.                 $txt_id = preg_replace("/\[:\]$/","",preg_replace("/^\[:id\]/","",$titles[0]));
  979.                 $txt_jp = '';
  980.             }
  981.             return array('id' => $txt_id, 'jp' => $txt_jp);
  982.          } else {
  983.             return array('id' => '', 'jp' => '');
  984.          }
  985.     }
  986.  
  987.     /**
  988.      * カテゴリ取得
  989.      */
  990.     public function getCategory($post_id) {
  991.         return $this->db()->fetchOne(
  992.             "SELECT term_taxonomy_id FROM wp_news_term_relationships WHERE object_id = ? LIMIT 1", $post_id
  993.         );
  994.     }
  995.  
  996.     /**
  997.      * サムネイル画像取得
  998.      */
  999.     public function getThumbnail($post_id) {
  1000.         return $this->db()->fetchOne(
  1001.             "SELECT guid FROM wp_news_posts WHERE id = ".
  1002.             "(SELECT meta_value FROM wp_news_postmeta WHERE post_id = ? AND meta_key = '_thumbnail_id')", $post_id
  1003.         );
  1004.     }
  1005.  
  1006.     /**
  1007.      * Wordpressから既存データ形式への変換
  1008.      */
  1009.     public function convertWPtoModel($news) {
  1010.         if (!$news) {
  1011.             return null;
  1012.         }
  1013.  
  1014.         $model = array();
  1015.  
  1016.         $model['id'] = $news['ID'];
  1017.  
  1018.         // カテゴリ取得
  1019.         $model['category'] = $this->getCategory($news['ID']);
  1020.  
  1021.         // 件名の言語別データ取得
  1022.         $title = $this->splitText($news['post_title']);
  1023.         $model['title_id'] = $title['id'];
  1024.         $model['title_jp'] = $title['jp'];
  1025.  
  1026.         // 未使用(dtb_newsとの互換用)
  1027.         $model['prefix_id'] = '';
  1028.         $model['prefix_jp'] = '';
  1029.  
  1030.         // 本文の言語別データ取得
  1031.         $content = $this->splitText($news['post_content']);
  1032.         $model['content_id'] = $content['id'];
  1033.         $model['content_jp'] = $content['jp'];
  1034.  
  1035.         // CDNパス
  1036.         $base_cdn = 'https://jkt48.com';
  1037.  
  1038.         // サムネイル画像取得
  1039.         $thumbnail = $this->getThumbnail($news['ID']);
  1040.         if ($thumbnail) {
  1041.             $model['image_url'] = $thumbnail;
  1042.            
  1043.             // GIFのときはそのまま表示。それ以外のときはクリッピングして表示
  1044.             if (preg_match("/\.gif$/", $thumbnail)) {
  1045.                 $model['thumb_url'] = $thumbnail;
  1046.             } else {
  1047.                 $model['thumb_url'] = "$base_cdn/thumbnail.php?w=270&h=270&wh=1&u=".$thumbnail;
  1048.             }
  1049.         } else {
  1050.             if ( preg_match("/src=\"(.*?)\"/", $model['content_id'], $matches) ) {
  1051.                 // サムネイル画像が設定されていないときは本文から取得
  1052.                 $url = $matches[1];
  1053.                 if (!preg_match("/^http/", $url)) {
  1054.                     $url = $base_cdn . $url;
  1055.                 }
  1056.                 $model['image_url'] = $url;
  1057.                 $model['thumb_url'] = "$base_cdn/thumbnail.php?w=270&h=270&wh=1&u=".$url;
  1058.             } else {
  1059.                 // 本文にも画像がないときはデフォルト画像を使う
  1060.                 $model['image_url'] = "$base_cdn/new3/img/jkt48logo.jpg";
  1061.                 $model['thumb_url'] = "$base_cdn/new3/img/jkt48logo.jpg";
  1062.             }
  1063.         }
  1064.  
  1065.         // 表示用日付(Y-m-d)取得
  1066.         $model['disp_date'] = substr($news['post_date'],0,10);
  1067.  
  1068.         return $model;
  1069.     }
  1070.  
  1071.     /**
  1072.      * 新着情報1件取得
  1073.      */
  1074.     public function findById($post_id) {
  1075.         $news = $this->db()->fetchRow(
  1076.             "SELECT * FROM `wp_news_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish' AND `ID` = ?", $post_id
  1077.         );
  1078.         $model = $this->convertWPtoModel($news);
  1079.         $model['content_id'] = apply_filters('the_content', str_replace("<BR>","<br/>", $model['content_id']));
  1080.         $model['content_jp'] = apply_filters('the_content', str_replace("<BR>","<br/>", $model['content_jp']));
  1081.         return $model;
  1082.     }
  1083.  
  1084.     /**
  1085.      * [旧サイドメニュー用] 新着情報5件
  1086.      */
  1087.     public function getSideNews($language = 'id') {
  1088.         if ($language == 'jp') {
  1089.             $news_list = $this->db()->fetchAll("SELECT * FROM `wp_news_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish' AND `post_title` LIKE '%[:jp]%' AND `post_title` NOT LIKE '%[:jp][:]' ORDER BY `post_date` DESC, `ID` DESC LIMIT 5");
  1090.         } else {
  1091.             $news_list = $this->db()->fetchAll("SELECT * FROM `wp_news_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish' AND (wp_news_posts.post_status = 'publish') AND (wp_news_posts.post_content='' OR wp_news_posts.post_content LIKE '%![:id!]%' ESCAPE '!' OR wp_news_posts.post_content LIKE '%<!--:id-->%' OR (wp_news_posts.post_content NOT LIKE '%![:!]%' ESCAPE '!' AND wp_news_posts.post_content NOT LIKE '%<!--:-->%')) ORDER BY `post_date` DESC, `ID` DESC LIMIT 5");
  1092.         }
  1093.  
  1094.         $models = array();
  1095.         foreach ($news_list as $news) {
  1096.             $models[] = $this->convertWPtoModel($news);
  1097.         }
  1098.  
  1099.         return $models;
  1100.     }
  1101.  
  1102.     /**
  1103.      * [新トップ用] グッズ4件
  1104.      */
  1105.     public function getGoods($language = 'id') {
  1106.         if ($language == 'jp') {
  1107.             $news_list = $this->db()->fetchAll("SELECT * FROM `wp_news_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish' AND `post_title` LIKE '%[:jp]%' AND `post_title` NOT LIKE '%[:jp][:]' AND ID IN (SELECT object_id FROM wp_news_term_relationships WHERE term_taxonomy_id = 6) ORDER BY `post_date` DESC, `ID` DESC LIMIT 4");
  1108.         } else {
  1109.             $news_list = $this->db()->fetchAll("SELECT * FROM `wp_news_posts` WHERE `post_type` = 'post' AND `post_status` = 'publish' AND (wp_news_posts.post_status = 'publish') AND (wp_news_posts.post_content='' OR wp_news_posts.post_content LIKE '%![:id!]%' ESCAPE '!' OR wp_news_posts.post_content LIKE '%<!--:id-->%' OR (wp_news_posts.post_content NOT LIKE '%![:!]%' ESCAPE '!' AND wp_news_posts.post_content NOT LIKE '%<!--:-->%')) AND ID IN (SELECT object_id FROM wp_news_term_relationships WHERE term_taxonomy_id = 6) ORDER BY `post_date` DESC, `ID` DESC LIMIT 4");
  1110.         }
  1111.  
  1112.         $models = array();
  1113.         foreach ($news_list as $news) {
  1114.             $models[] = $this->convertWPtoModel($news);
  1115.         }
  1116.  
  1117.         return $models;
  1118.     }
  1119. }
Add Comment
Please, Sign In to add comment