public function link() { if (empty($_GET['lid'])) { $c = '<h1>Create new CoolUri</h1>'; $new = true; } else { $c = '<h1>Update this CoolUri</h1>'; $new = false; $id = (int) $_GET['lid']; } if (!$new) { $q = $this->db->query('SELECT * FROM ' . $this->table . 'cache WHERE id=' . $id); $data = $this->db->fetch($q); $data['params'] = str_replace('&', '&', $this->serializedArrayToQueryString($data['params'])); } if (!empty($_POST)) { $data = $_POST; $data = array_map('trim', $data); if (empty($data['url']) || empty($data['params'])) { $c .= '<div class="error"><p>You must fill all inputs.</p></div>'; } else { $params = \Bednarik\Cooluri\Core\Functions::convertQuerystringToArray($data['params']); $cp = \Bednarik\Cooluri\Core\Functions::prepareParamsForCache($params); $ok = true; $olq = $this->db->query('SELECT COUNT(*) FROM ' . $this->table . 'cache WHERE params=' . $cp . ($new ? '' : ' AND id<>' . $id)); $num = $this->db->fetch_row($olq); if ($num[0] > 0) { $c .= '<div class="error"><p>A different link with such parameters exists already.</p></div>'; $ok = false; } $temp = preg_replace('~/$~', '', $data['url']); if ($temp == $data['url']) { $temp .= '/'; } $olq = $this->db->query('SELECT COUNT(*) FROM ' . $this->table . 'cache WHERE (url=' . $this->db->escape($temp) . ' OR url=' . $this->db->escape($data['url']) . ')' . ($new ? '' : ' AND id<>' . $id)); $num = $this->db->fetch_row($olq); if ($num[0] > 0) { $c .= '<div class="error"><p>A different link with such URI exists already.</p></div>'; $ok = false; } if ($new && $ok) { $q = $this->db->query('INSERT INTO ' . $this->table . 'cache(url,params,sticky,crdatetime) VALUES(' . $this->db->escape($data['url']) . ', ' . $cp . ', ' . (!empty($data['sticky']) && $data['sticky'] == 1 ? 1 : 0) . ', NOW())'); $this->db->query('DELETE FROM ' . $this->table . 'oldlinks WHERE url=' . $this->db->escape($data['url'])); if ($q) { $c .= '<div class="succes"><p>The new link was saved successfully.</p></div>'; $c .= '<p class="center"><a href="' . $this->file . 'mod=cache&l=' . htmlspecialchars($data['url']) . '">Show >></a></p>'; $data = array(); } else { $c .= '<div class="error"><p>Could not save the link.</p></div>'; } } elseif (!empty($id) && $ok) { $oldq = $this->db->query('SELECT * FROM ' . $this->table . 'cache WHERE id=' . $id); $old = $this->db->fetch($oldq); if ($data['url'] != $old['url']) { $q = $this->db->query('INSERT INTO ' . $this->table . 'oldlinks(link_id,url) VALUES(' . $id . ', \'' . $old['url'] . '\')'); } $qq = $this->db->query('UPDATE ' . $this->table . 'cache SET url=' . $this->db->escape($data['url']) . ', params=' . $cp . ', sticky=' . (!empty($data['sticky']) && $data['sticky'] == 1 ? 1 : 0) . ' WHERE id=' . $id . ' LIMIT 1 '); $this->db->query('DELETE FROM ' . $this->table . 'oldlinks WHERE url=' . $this->db->escape($data['url'])); if ($qq) { $c .= '<div class="succes"><p>The link was updated successfully.</p></div>'; $c .= '<p class="center"><a href="' . $this->file . 'mod=cache&l=' . htmlspecialchars($data['url']) . '">Show >></a></p>'; } else { $c .= '<div class="error"><p>Could not update the link.</p></div>'; } } } } $c .= '<form method="post" action="' . $this->file . 'mod=link' . ($new ? '' : '&lid=' . $id) . '"> <fieldset> <legend>URI details</legend> <label for="url">URI:</label><br /> <input type="text" name="url" id="url" value="' . (empty($data['url']) ? '' : htmlspecialchars($data['url'])) . '" /><br /> <label for="params">Parameters (query string: id=1&type=2):</label><br /> <input type="text" name="params" id="params" value="' . (empty($data['params']) ? '' : htmlspecialchars($data['params'])) . '" /><br /> <label for="sticky">Sticky (won\'t be updated):</label><br /> <input type="checkbox" class="check" name="sticky" id="sticky" value="1" ' . (empty($data['sticky']) ? '' : ' checked="checked"') . ' /> </fieldset> <input type="submit" value=" ' . ($new ? 'Save new URI' : 'Update this URI') . ' " class="submit" /> </form> '; return $c; }
public static function goForRedirect($params, $ref) { if (empty($_GET['eID']) && empty($_GET['ADMCMD_prev']) && empty($_GET['ADMCMD_cooluri']) && $GLOBALS['TSFE']->config['config']['tx_cooluri_enable'] == 1 && $GLOBALS['TSFE']->config['config']['redirectOldLinksToNew'] == 1 && \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') && (substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 1, 9) == 'index.php' || substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), 1, 1) == '?')) { $ourl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'); $ss = explode('?', $ourl); if ($ss[1]) { $ss[1] = strtr($ss[1], array('%5B' => '[', '%5D' => ']')); $pars = \Bednarik\Cooluri\Core\Functions::convertQuerystringToArray($ss[1]); } $pageid = $pars['id']; if (is_null($pageid)) { // No page id given, so no need to redirect return; } else { if (!ctype_digit($pageid)) { $pageid = $GLOBALS['TYPO3_DB']->fullQuoteStr($pageid, 'pages'); $q = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'alias=' . $pageid); $page = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($q); $pars['id'] = (int) $page['uid']; } else { $q = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid=' . (int) $pageid); $page = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($q); $pars['id'] = (int) $page['uid']; } } // if a page is hidden, there won't be any redirect, because it would // redirect to the root if (!$page || $page['hidden'] == 1 || $page['deleted'] == 1) { return; } if ($pars) { $lt = self::getTranslateInstance(); if (!$lt) { return; } if (self::$confArray['MULTIDOMAIN']) { if (empty(\Bednarik\Cooluri\Core\Translate::$conf->cache->prefix)) { self::simplexml_addChild(\Bednarik\Cooluri\Core\Translate::$conf->cache, 'prefix', self::getDomain((int) $pars['id']) . '@'); } else { \Bednarik\Cooluri\Core\Translate::$conf->cache->prefix = self::getDomain((int) $pars['id']) . '@'; } } $url = $lt->params2coolForRedirect($pars); $parts = explode('?', $url); if (empty($parts[0])) { return; } if (self::$confArray['MULTIDOMAIN'] || \Bednarik\Cooluri\Core\Translate::$conf->domainlanguages) { $url = explode('@', $url); $url = 'http://' . $url[0] . '/' . $url[1]; } \Bednarik\Cooluri\Core\Functions::redirect($url, 301); } } }