Skip to content

Instantly share code, notes, and snippets.

@nmngt
Last active December 18, 2022 08:17
Show Gist options
  • Save nmngt/56c740ae72dea10f43e8936f71f99f55 to your computer and use it in GitHub Desktop.
Save nmngt/56c740ae72dea10f43e8936f71f99f55 to your computer and use it in GitHub Desktop.
GetContaoFilePathInWordPress
function get_imagepath_from_contao()
{
$wpdb_contao = new \wpdb('USER', 'PASSWORD', 'DBNAME', 'localhost');
$result = $wpdb_contao->get_col("
SELECT DISTINCT `product_imageSrc`
FROM `tl_zenner_products_language`
WHERE `id` = '1'
");
// get_col() liefert ein Array mit binaerem Inhalt zurück.
$binaer = $result[0];
// Contao arbeitet intern mit einem FileObject, welches pro Eintrag eine UUID vergibt und diese binaer speichert.
// Die Funktion zum umwandeln von binaer in die uuid habe ich mir im StringUtil von contao geborgt:
// https://github.com/contao/core-bundle/blob/4.x/src/Resources/contao/library/Contao/StringUtil.php
//
// Das aber nur zur Info.. Für den eigentlichen filepath benötigen wir die UUID nicht. Eventuell aber später.
$uuid = implode('-', unpack('H8time_low/H4time_mid/H4time_high/H4clock_seq/H12node', $binaer));
if(false !== $uuid)
{
$result = $wpdb_contao->get_col("
SELECT DISTINCT `path`
FROM `tl_files`
AND `uuid` = '".$binaer."'
");
var_dump($result);
die();
}
}
get_imagepath_from_contao();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment