Example #1
0
 /**
  * Remove the image tags in the article text.
  *
  * @param int $p_imageId
  * @param int $p_articleNumber
  * @param int $p_templateId
  * @return void
  */
 public static function RemoveImageTagsFromArticleText($p_articleNumber, $p_templateId)
 {
     // Get all the articles
     $articles = Article::getTranslations($p_articleNumber);
     // The REGEX
     $altAttr = '(alt\\s*=\\s*("[^"]*"|[^\\s]*))';
     $alignAttr = '(align\\s*=\\s*("[^"]*"|[^\\s]*))';
     $subAttr = '(sub\\s*=\\s*("[^"]*"|[^\\s]*))';
     $otherAttr = '(\\w+\\s*=\\s*("[^"]*"|[^\\s]*))*';
     $matchString = "/<!\\*\\*\\s*Image\\s*{$p_templateId}\\s*(({$altAttr}|{$alignAttr}|{$subAttr}|{$otherAttr})\\s*)*>/i";
     // Replace the article tag in each one with the empty string
     foreach ($articles as $article) {
         $articleData = $article->getArticleData();
         $dbColumns = $articleData->getUserDefinedColumns();
         foreach ($dbColumns as $dbColumn) {
             $originalText = $articleData->getProperty($dbColumn->getName());
             $newText = preg_replace($matchString, '', $originalText);
             if ($originalText != $newText) {
                 $articleData->setProperty($dbColumn->getName(), $newText);
             }
         }
     }
 }