Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.38 KB | None | 0 0
  1. <?php
  2. $dbArray = include(dirname(dirname(dirname(__FILE__))) . "/typo3conf/LocalConfiguration.php"); // das holt natürlich nicht die richtigen DB-Einstellungen aus AdditionalConfiguration!!!
  3. include(dirname(dirname(dirname(__FILE__))) . "/typo3conf/AdditionalConfiguration.php");
  4. $dbhost = $dbArray['DB']['host'];
  5. $dbuser = $dbArray['DB']['username'];
  6. $dbpassword = $dbArray['DB']['password'];
  7. $dbname = $dbArray['DB']['database'];
  8. // get AdditionalConfiguration if applicable:
  9. if (isset($GLOBALS['TYPO3_CONF_VARS']['DB']['username'])) {
  10.   $dbhost = $GLOBALS['TYPO3_CONF_VARS']['DB']['host'];
  11.   $dbuser = $GLOBALS['TYPO3_CONF_VARS']['DB']['username'];
  12.   $dbpassword = $GLOBALS['TYPO3_CONF_VARS']['DB']['password'];
  13.   $dbname = $GLOBALS['TYPO3_CONF_VARS']['DB']['database'];
  14. }
  15. $mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbname);
  16. $mysqli->query('set names utf8');
  17. $code = $mysqli->real_escape_string($_GET['code']);
  18. $host = 'http://' . filter_input(INPUT_SERVER, 'HTTP_HOST');
  19.  
  20. function redirect($alsoRetrieveOldOnes=false) {
  21.   global $mysqli, $code, $host;
  22.   $betweenFilter = 'and pid BETWEEN 833 AND 847';
  23.   if ($alsoRetrieveOldOnes) {
  24.     $betweenFilter = '';
  25.   }
  26.     $res = $mysqli->query("SELECT realurl_headline FROM tx_davtravel_domain_model_travel where hidden=0 and deleted=0 ".$betweenFilter." and bookingcode='$code' limit 0,1");
  27.     $row = $res->fetch_assoc();
  28.     if(!is_null($row)) {
  29.         $url = $host . '/reisedetails/detail/' . $row['realurl_headline'] . '.html';
  30.         header('Location:' . $url, 301);
  31.         exit;
  32.     }
  33. }
  34.  
  35. redirect();
  36. // Look if there is an archived version that we may want to display:
  37. redirect(true);
  38.  
  39. function slugify($text, $substitutes = null) {
  40.  
  41.     $invalid = array();
  42.  
  43.     // use default substitutes if none were given
  44.     if ($substitutes == null || !is_array($substitutes))
  45.       $invalid = array(
  46.           'Ä' => 'ae', 'Ü' => 'ue', 'Ö' => 'oe',
  47.           'ä' => 'ae', 'ü' => 'ue', 'ö' => 'oe',
  48.       );
  49.     else
  50.       $invalid = $substitutes;
  51.  
  52.     // substitute umlauts
  53.     $text = str_replace(array_keys($invalid), array_values($invalid), $text);
  54.  
  55.     // lowercase
  56.     $text = strtolower($text);
  57.  
  58.     // replace non letter or digits by -
  59.     $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  60.  
  61.     // trim
  62.     $text = trim($text, '-');
  63.  
  64.     // transliterate
  65.     if (function_exists('iconv')) {
  66.       $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  67.     }
  68.  
  69.     // remove unwanted characters
  70.     $text = preg_replace('~[^-\w]+~', '', $text);
  71.  
  72.     if (empty($text))
  73.       return 'n-a';
  74.  
  75.     return $text;
  76.   }
  77.  
  78. // Look if we can unarchive an old one and fetch it:
  79. $res = $mysqli->query("SELECT * FROM tx_davtravel_domain_model_travel where bookingcode='$code' order by crdate desc limit 0,1");
  80. while($row = $res->fetch_assoc()) {
  81.   $correctRealUrl = '';
  82.   if ($row['realurl_headline'] == '') {
  83.     $headline = $row['headline'];
  84.     if ($headline == '') {
  85.       $headline = $row['reise_titel'];
  86.     }
  87.     $correctRealUrl = ', realurl_headline="'.slugify($headline).'"';
  88.   }
  89.   $mysqli->query("UPDATE tx_davtravel_domain_model_travel SET hidden=0 $correctRealUrl WHERE uid=".$row['uid']);
  90. //  $url = $host . '/reisedetails/detail/' . $row['realurl_headline'] . '.html';
  91. //  header('Location:' . $url, 301);
  92. //  exit;
  93. }
  94.  
  95. //try again:
  96. redirect(true);
  97.  
  98. header('Location:' . $host, 301);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement