Strip Tags from URL #1588

Open
opened 2026-10-05 00:49:14 +02:00 by adam · 0 comments
Owner

This is an improvement that could be made to improve functionality with the Extended Descriptions plugin.

The Extended Description plugin adds the ability to use hidden HTML tags inside of title and description blocks. The addition of a <!--hidden--> tag in the title will make the album not appear on the parent album or index listing. This works really great for making custom pages that link to the albums in other ways.

The issue comes when the URL for the page is generated by the system. While the regular expressions work correctly to strip out the tag brackets, it will leave the rest of the HTML code behind.

So for example an album with this title: <!--hidden-->My Secret Album will generate a URL that says: #_hidden_my_secret_album.

function str2url($str)
{
  $str = $safe = pwg_transliterate($str);
  $str = preg_replace('/[^\x80-\xffa-z0-9_\s\'\:\/\[\],-]/','',$str);
  $str = preg_replace('/[\s\'\:\/\[\],-]+/',' ',trim($str));
  $res = str_replace(' ','_',$str);

  if (empty($res))
  {
    $res = str_replace(' ','_', $safe);
  }

  return $res;
}

Add the strip_tags function at the start of the code.

function str2url($str)
{
  $str = strip_tags($str);
  $str = $safe = pwg_transliterate($str);
  $str = preg_replace('/[^\x80-\xffa-z0-9_\s\'\:\/\[\],-]/','',$str);
  $str = preg_replace('/[\s\'\:\/\[\],-]+/',' ',trim($str));
  $res = str_replace(' ','_',$str);

  if (empty($res))
  {
    $res = str_replace(' ','_', $safe);
  }

  return $res;
}

This will generate a tag correctly.

This title: <!--hidden-->My Secret Album will generate a URL that says: #_my_secret_album.

The other alternative is creating permalinks for each and every album, but that would not help with picture URLs which also can use the tags in their titles.

This is an improvement that could be made to improve functionality with the [Extended Descriptions](https://piwigo.org/ext/extension_view.php?eid=175) plugin. The Extended Description plugin adds the ability to use hidden HTML tags inside of title and description blocks. The addition of a ```<!--hidden-->``` tag in the title will make the album not appear on the parent album or index listing. This works really great for making custom pages that link to the albums in other ways. The issue comes when the URL for the page is generated by the system. While the regular expressions work correctly to strip out the tag brackets, it will leave the rest of the HTML code behind. So for example an album with this title: ````<!--hidden-->My Secret Album```` will generate a URL that says: ````#_hidden_my_secret_album````. ```` function str2url($str) { $str = $safe = pwg_transliterate($str); $str = preg_replace('/[^\x80-\xffa-z0-9_\s\'\:\/\[\],-]/','',$str); $str = preg_replace('/[\s\'\:\/\[\],-]+/',' ',trim($str)); $res = str_replace(' ','_',$str); if (empty($res)) { $res = str_replace(' ','_', $safe); } return $res; } ```` Add the strip_tags function at the start of the code. ```` function str2url($str) { $str = strip_tags($str); $str = $safe = pwg_transliterate($str); $str = preg_replace('/[^\x80-\xffa-z0-9_\s\'\:\/\[\],-]/','',$str); $str = preg_replace('/[\s\'\:\/\[\],-]+/',' ',trim($str)); $res = str_replace(' ','_',$str); if (empty($res)) { $res = str_replace(' ','_', $safe); } return $res; } ```` This will generate a tag correctly. This title: ````<!--hidden-->My Secret Album```` will generate a URL that says: ````#_my_secret_album````. The other alternative is creating permalinks for each and every album, but that would not help with picture URLs which also can use the <!--hidden--> tags in their titles. <!-- github-sync-id:1473420346 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1588