Esempio n. 1
0
 /**
  * Check if has some of the three styles applied
  * 
  * Checks too:
  * - if the keyword is inside a tag
  * - if the keyword is inside a shortcode
  * 
  * @param	string	$content
  * @param	string	$keyword
  * @param	array	$keyword_arr
  * @return 	bool
  * @static 
  */
 static function if_some_style_or_in_tag_attribute($content, $keyword_arr, $key_pos = 1)
 {
     $pieces = WSW_Keywords::get_pieces_by_keyword($keyword_arr, $content);
     $before_key_pos = $key_pos - 1;
     if (count($pieces) > $key_pos) {
         $some_style = self::if_some_style_in_pieces($pieces, $before_key_pos, array(), $keyword_arr);
         if ($some_style) {
             // If true, so some style is applied
             return $some_style;
         } else {
             $in_tag = self::keyword_in_tag_attribute($pieces, $before_key_pos);
             if ($in_tag) {
                 return array(TRUE, 'in_tag');
             } else {
                 $in_shortcode = self::keyword_in_shortcode($pieces, $before_key_pos);
                 if ($in_shortcode) {
                     return array(TRUE, 'in_shortcode');
                 }
             }
         }
     }
     return FALSE;
 }
Esempio n. 2
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;
 }