Exemplo n.º 1
0
 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('&amp;', '&', $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 &gt;&gt;</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 &gt;&gt;</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 ? '' : '&amp;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&amp;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;
 }
Exemplo n.º 2
0
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
/**
 * test.Functions.php
 */
include '../cooluri/link.Functions.php';
// test lookindb
$sql = 'SELECT title FROM tx_news_domain_model_news WHERE deleted=\'0\' AND hidden=\'0\' AND (uid=$1 OR l10n_parent=$1) AND sys_language_uid={L=0}';
$param = '70';
\Bednarik\Cooluri\Core\Functions::lookindb($sql, $param, new stdClass(), array('L' => '2'));
class DB
{
    public static function getInstance()
    {
        return new DB();
    }
    public static function query($sql)
    {
        echo $sql;
        return $sql;
    }
    public static function fetch_row($res)
    {
        return $res;
    }
Exemplo n.º 3
0
 public static function getPageTitleBE($conf, $value)
 {
     if ($GLOBALS['TSFE']->showHiddenPage || self::isBEUserLoggedIn()) {
         $enable = ' AND deleted=0';
     } else {
         $enable = ' AND deleted=0 AND hidden=0';
     }
     $db =& $GLOBALS['TYPO3_DB'];
     $id = (int) $value[(string) $conf->saveto];
     $confArray = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cooluri']);
     $langVar = $confArray['LANGID'];
     if (empty($langVar)) {
         $langVar = 'L';
     }
     $langId = isset($value[$langVar]) ? $value[$langVar] : $GLOBALS['TSFE']->config['config']['sys_language_uid'];
     $langId = (int) $langId;
     $pagepath = array();
     if (empty($conf->alias)) {
         $sel = (string) $conf->title;
     } else {
         $sel = (string) $conf->alias;
     }
     $sel = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $sel);
     $max = 15;
     while ($max > 0 && $id) {
         if (!is_numeric($id)) {
             $id = $GLOBALS['TSFE']->sys_page->getPageIdFromAlias($id);
         }
         $q = $db->exec_SELECTquery('*', 'pages', 'uid=' . $id . $enable);
         $page = $db->sql_fetch_assoc($q);
         $temp = $db->exec_SELECTquery('COUNT(*) as num', 'sys_template', 'deleted=0 AND hidden=0 AND pid=' . $id . ' AND root=1' . $enable);
         $count = $db->sql_fetch_assoc($temp);
         if ($count['num'] > 0 || $page['is_siteroot'] == 1) {
             return $pagepath;
         }
         if ($langId) {
             $q = $db->exec_SELECTquery('*', 'pages_language_overlay', 'pid=' . $id . ' AND sys_language_uid=' . $langId . $enable);
             $lo = $db->sql_fetch_assoc($q);
             if ($lo) {
                 unset($lo['uid']);
                 unset($lo['pid']);
                 $page = array_merge($page, $lo);
             }
         }
         if (!$page) {
             break;
         }
         if ($page['tx_cooluri_exclude'] == 1 && !empty($pagepath) || $page['tx_cooluri_excludealways']) {
             ++$max;
             $id = $page['pid'];
             continue;
         }
         foreach ($sel as $s) {
             $trimmed = trim($page[$s]);
             if (!empty($trimmed)) {
                 $title = $trimmed;
                 break;
             }
         }
         if (!empty($conf->sanitize) && $conf->sanitize == 1) {
             $pagepath[] = \Bednarik\Cooluri\Core\Functions::sanitize_title_with_dashes($title);
         } elseif (!empty($conf->t3conv) && $conf->t3conv == 1) {
             $pagepath[] = \Bednarik\Cooluri\Core\Functions::specCharsToASCII($title);
         } elseif (!isset($conf->urlize) || $conf->urlize != 0) {
             $pagepath[] = \Bednarik\Cooluri\Core\Functions::URLize($title);
         } else {
             $pagepath[] = urlencode($title);
         }
         $id = $page['pid'];
         --$max;
         if (!empty($conf->maxsegments) && count($pagepath) >= (int) $conf->maxsegments) {
             $max = 0;
         }
     }
     return $pagepath;
 }