示例#1
0
 static function apply_biu_to_content($content, $keyword)
 {
     $settings = WSW_Main::$settings;
     $new_content = $content;
     if ($settings['chk_keyword_decorate_bold'] === 1 || $settings['chk_keyword_decorate_bold'] === '1') {
         $already_apply_bold = FALSE;
     } else {
         $already_apply_bold = TRUE;
     }
     if ($settings['chk_keyword_decorate_italic'] === 1 || $settings['chk_keyword_decorate_italic'] === '1') {
         $already_apply_italic = FALSE;
     } else {
         $already_apply_italic = TRUE;
     }
     if ($settings['chk_keyword_decorate_underline'] === 1 || $settings['chk_keyword_decorate_underline'] === '1') {
         $already_apply_underline = FALSE;
     } else {
         $already_apply_underline = TRUE;
     }
     // Pass through all keyword until ends or until are applied all designs
     $how_many_keys = WSW_Keywords::how_many_keywords(array($keyword), $new_content);
     // To avoid make the request for each keyword: Get pieces by keyword for determine if some has the design applied
     $pieces_by_keyword = WSW_Keywords::get_pieces_by_keyword(array($keyword), $new_content, TRUE);
     $pieces_by_keyword_matches = $pieces_by_keyword[1];
     $pieces_by_keyword = $pieces_by_keyword[0];
     // First, only check for designs already applied
     for ($i = 1; $i <= $how_many_keys; $i++) {
         // Stop if are already all the design applied
         if ($already_apply_bold && $already_apply_italic && $already_apply_underline) {
             break;
         }
         // Getting the position
         $key_pos = WSW_Keywords::strpos_offset($keyword, $new_content, $i, $pieces_by_keyword, $pieces_by_keyword_matches);
         if ($key_pos !== FALSE) {
             $already_style = WSW_HtmlStyles::if_some_style_or_in_tag_attribute($new_content, array($keyword), $i);
             if ($already_style) {
                 if ($already_style[1] == 'bold') {
                     $already_apply_bold = TRUE;
                 } elseif ($already_style[1] == 'italic') {
                     $already_apply_italic = TRUE;
                 } elseif ($already_style[1] == 'underline') {
                     $already_apply_underline = TRUE;
                 }
             }
         }
     }
     // Apply designs pendings to apply
     for ($i = 1; $i <= $how_many_keys; $i++) {
         // Stop if are already all the design applied
         if ($already_apply_bold && $already_apply_italic && $already_apply_underline) {
             break;
         }
         // Getting the position. Here can't be calculate one time ($pieces_by_keyword) and rehuse it because the content changes
         $key_pos = WSW_Keywords::strpos_offset($keyword, $new_content, $i);
         $pieces_by_keyword_matches_item = $pieces_by_keyword_matches[$i - 1];
         if ($key_pos !== FALSE) {
             $already_style = WSW_HtmlStyles::if_some_style_or_in_tag_attribute($new_content, array($keyword), $i);
             if ($already_style) {
                 if ($already_style[1] == 'bold') {
                     $already_apply_bold = TRUE;
                 } elseif ($already_style[1] == 'italic') {
                     $already_apply_italic = TRUE;
                 } elseif ($already_style[1] == 'underline') {
                     $already_apply_underline = TRUE;
                 }
             } else {
                 if (!$already_apply_bold) {
                     $keyword_with_style = WSW_HtmlStyles::apply_bold_styles($pieces_by_keyword_matches_item);
                     $already_apply_bold = TRUE;
                 } elseif (!$already_apply_italic) {
                     $keyword_with_style = WSW_HtmlStyles::apply_italic_styles($pieces_by_keyword_matches_item);
                     $already_apply_italic = TRUE;
                 } elseif (!$already_apply_underline) {
                     $keyword_with_style = WSW_HtmlStyles::apply_underline_styles($pieces_by_keyword_matches_item);
                     $already_apply_underline = TRUE;
                 }
                 $new_content = substr_replace($new_content, $keyword_with_style, $key_pos, strlen($pieces_by_keyword_matches_item));
                 // Calculate how many keyword, because in case the keyword is, for example "b" this value will change
                 $how_many_keys = WSW_Keywords::how_many_keywords(array($keyword), $new_content);
             }
         }
     }
     return $new_content;
 }