hasNext() public method

* Prueft ob das Resultset weitere Datensaetze enthaelt
public hasNext ( )
/**
 * rex_rewriter_generate_pathnames
 * generiert die Pathlist, abhŠngig von Aktion
 * @author markus.staab[at]redaxo[dot]de Markus Staab
 * @package redaxo4.2
 */
function rex_rewriter_generate_pathnames($params)
{
    global $REX, $REXPATH;
    if (file_exists(FULLNAMES_PATHLIST)) {
        require_once FULLNAMES_PATHLIST;
    }
    if (!isset($REXPATH)) {
        $REXPATH = array();
    }
    if (!isset($params['extension_point'])) {
        $params['extension_point'] = '';
    }
    $where = '';
    switch ($params['extension_point']) {
        // ------- sprachabhängig, einen artikel aktualisieren
        case 'CAT_DELETED':
        case 'ART_DELETED':
            unset($REXPATH[$params['id']]);
            break;
        case 'CAT_ADDED':
        case 'CAT_UPDATED':
        case 'ART_ADDED':
        case 'ART_UPDATED':
            $where = '(id=' . $params['id'] . ' AND clang=' . $params['clang'] . ') OR (path LIKE "%|' . $params['id'] . '|%" AND clang=' . $params['clang'] . ')';
            break;
            // ------- alles aktualisieren
        // ------- alles aktualisieren
        case 'ALL_GENERATED':
        default:
            $where = '1=1';
            break;
    }
    if ($where != '') {
        $db = new rex_sql();
        // $db->debugsql=true;
        $db->setQuery('SELECT id,clang,path,startpage FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE ' . $where . ' and revision=0');
        while ($db->hasNext()) {
            $clang = $db->getValue('clang');
            $pathname = '';
            if (count($REX['CLANG']) > 1) {
                $pathname = $REX['CLANG'][$clang] . '/';
            }
            // pfad über kategorien bauen
            $path = trim($db->getValue('path'), '|');
            if ($path != '') {
                $path = explode('|', $path);
                foreach ($path as $p) {
                    $ooc = OOCategory::getCategoryById($p, $clang);
                    $name = $ooc->getName();
                    unset($ooc);
                    // speicher freigeben
                    $pathname = rex_rewriter_appendToPath($pathname, $name);
                }
            }
            $ooa = OOArticle::getArticleById($db->getValue('id'), $clang);
            if ($ooa->isStartArticle()) {
                $ooc = $ooa->getCategory();
                $catname = $ooc->getName();
                unset($ooc);
                // speicher freigeben
                $pathname = rex_rewriter_appendToPath($pathname, $catname);
            }
            // eigentlicher artikel anhängen
            $name = $ooa->getName();
            unset($ooa);
            // speicher freigeben
            $pathname = rex_rewriter_appendToPath($pathname, $name);
            $pathname = substr($pathname, 0, strlen($pathname) - 1) . '.html';
            $REXPATH[$db->getValue('id')][$db->getValue('clang')] = $pathname;
            $db->next();
        }
    }
    rex_put_file_contents(FULLNAMES_PATHLIST, "<?php\n\$REXPATH = " . var_export($REXPATH, true) . ";\n");
}
/**
 * Löscht eine Kategorie und reorganisiert die Prioritäten verbleibender Geschwister-Kategorien
 * 
 * @param int $category_id Id der Kategorie die gelöscht werden soll
 * 
 * @return array Ein Array welches den status sowie eine Fehlermeldung beinhaltet
 */
function rex_deleteCategoryReorganized($category_id)
{
    global $REX, $I18N;
    $return = array();
    $return['state'] = FALSE;
    $return['message'] = '';
    $clang = 0;
    $thisCat = new rex_sql();
    $thisCat->setQuery('SELECT * FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE id=' . $category_id . ' and clang=' . $clang);
    // Prüfen ob die Kategorie existiert
    if ($thisCat->getRows() == 1) {
        $KAT = new rex_sql();
        $KAT->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article where re_id='{$category_id}' and clang='{$clang}' and startpage=1");
        // Prüfen ob die Kategorie noch Unterkategorien besitzt
        if ($KAT->getRows() == 0) {
            $KAT->setQuery("select * from " . $REX['TABLE_PREFIX'] . "article where re_id='{$category_id}' and clang='{$clang}' and startpage=0");
            // Prüfen ob die Kategorie noch Artikel besitzt (ausser dem Startartikel)
            if ($KAT->getRows() == 0) {
                $thisCat = new rex_sql();
                $thisCat->setQuery('SELECT * FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE id=' . $category_id);
                $re_id = $thisCat->getValue('re_id');
                $return = rex_deleteArticle($category_id);
                while ($thisCat->hasNext()) {
                    $_clang = $thisCat->getValue('clang');
                    // ----- PRIOR
                    rex_newCatPrio($re_id, $_clang, 0, 1);
                    // ----- EXTENSION POINT
                    $return = rex_register_extension_point('CAT_DELETED', $return, array('id' => $category_id, 're_id' => $re_id, 'clang' => $_clang, 'name' => $thisCat->getValue('catname'), 'prior' => $thisCat->getValue('catprior'), 'path' => $thisCat->getValue('path'), 'status' => $thisCat->getValue('status')));
                    $thisCat->next();
                }
            } else {
                $return['message'] = $I18N->msg('category_could_not_be_deleted') . ' ' . $I18N->msg('category_still_contains_articles');
            }
        } else {
            $return['message'] = $I18N->msg('category_could_not_be_deleted') . ' ' . $I18N->msg('category_still_contains_subcategories');
        }
    } else {
        $return['message'] = $I18N->msg('category_could_not_be_deleted');
    }
    return array($return['state'], $return['message']);
}
/**
* seo42_generate_pathlist()
*
* generiert die Pathlist, abhängig von Aktion
* @author markus.staab[at]redaxo[dot]de Markus Staab
* @package redaxo4.2
*/
function seo42_generate_pathlist($params)
{
    global $REX, $SEO42_IDS, $SEO42_URLS;
    // temporary community install workaround
    if (!isset($REX['ADDON']['seo42'])) {
        return;
    }
    // include pathlist file
    if (file_exists(SEO42_PATHLIST)) {
        require_once SEO42_PATHLIST;
    }
    // EXTENSION POINT "SEO42_PATHLIST_BEFORE_REBUILD"
    $subject = array('SEO42_IDS' => $SEO42_IDS, 'SEO42_URLS' => $SEO42_URLS);
    rex_register_extension_point('SEO42_PATHLIST_BEFORE_REBUILD', $subject);
    $SEO42_IDS = array();
    $SEO42_URLS = array();
    $REX['SEO42_URL_CLONE'] = array();
    $db = new rex_sql();
    // REVISION FIX
    $db->setQuery('UPDATE ' . $REX['TABLE_PREFIX'] . 'article SET revision = 0 WHERE revision IS NULL;');
    $db->setQuery('UPDATE ' . $REX['TABLE_PREFIX'] . 'article_slice SET revision = 0 WHERE revision IS NULL;');
    if ($REX['ADDON']['seo42']['settings']['ignore_root_cats']) {
        $sqlQuery = 'SELECT `id`, `clang`, `path`, `startpage`,`seo_custom_url` FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE re_id != 0 OR (re_id = 0 AND catname LIKE "") AND revision=0 OR revision IS NULL ORDER BY id';
    } else {
        $sqlQuery = 'SELECT `id`, `clang`, `path`, `startpage`,`seo_custom_url` FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE revision=0 OR revision IS NULL ORDER BY id';
    }
    $db->setQuery($sqlQuery);
    // redirects start articles withou slash: /xx to /xx/
    if (count($REX['CLANG']) > 1) {
        foreach ($REX['CLANG'] as $clangId => $clangName) {
            if ($REX['ADDON']['seo42']['settings']['url_ending'] == '') {
                $langSlug = seo42::getLangUrlSlug($clangId) . '/';
            } else {
                $langSlug = seo42::getLangUrlSlug($clangId);
            }
            if ($REX['ADDON']['seo42']['settings']['homelang'] != $clangId) {
                $SEO42_URLS[$langSlug] = array('id' => $REX['START_ARTICLE_ID'], 'clang' => $clangId, 'status' => 301);
            }
        }
    }
    while ($db->hasNext()) {
        $pathname = '';
        $id = $db->getValue('id');
        $clang = $db->getValue('clang');
        $path = $db->getValue('path');
        // LANG SLUG
        if (count($REX['CLANG']) > 1 && $clang != $REX['ADDON']['seo42']['settings']['hide_langslug']) {
            $pathname = '';
            $pathname = seo42_appendToPath($pathname, seo42::getLangUrlSlug($clang), $id, $clang);
        }
        // pfad über kategorien bauen
        $path = trim($path, '|');
        if ($path != '') {
            $path = explode('|', $path);
            foreach ($path as $p) {
                $ooc = OOCategory::getCategoryById($p, seo42_utils::getInheritedClang($clang));
                // PREVENT FATALS IN RARE CONDITIONS WHERE DB/CACHE ARE OUT OF SYNC
                if (!is_a($ooc, 'OOCategory')) {
                    continue;
                }
                // 42
                if ($REX['ADDON']['seo42']['settings']['ignore_root_cats'] && $ooc->getParentId() == 0) {
                    continue;
                }
                $name = $ooc->getName();
                unset($ooc);
                $pathname = seo42_appendToPath($pathname, $name, $id, $clang);
            }
        }
        $ooa = OOArticle::getArticleById($id, seo42_utils::getInheritedClang($clang));
        // PREVENT FATALS IN RARE CONDITIONS WHERE DB/CACHE ARE OUT OF SYNC
        if (!is_a($ooa, 'OOArticle')) {
            $db->next();
            continue;
        }
        if ($ooa->isStartArticle()) {
            $ooc = $ooa->getCategory();
            $catname = $ooc->getName();
            unset($ooc);
            $pathname = seo42_appendToPath($pathname, $catname, $id, $clang);
        }
        // url_schema: seo42
        if (!$ooa->isStartArticle()) {
            // eigentlicher artikel anhängen
            $name = $ooa->getName();
            unset($ooa);
            $pathname = seo42_appendToPath($pathname, $name, $id, $clang);
        }
        // ALLGEMEINE URL ENDUNG
        $pathname = substr($pathname, 0, strlen($pathname) - 1) . $REX['ADDON']['seo42']['settings']['url_ending'];
        // STARTSEITEN URL FORMAT
        if ($db->getValue('id') == $REX['START_ARTICLE_ID'] && $db->getValue('clang') == $REX['ADDON']['seo42']['settings']['homelang'] && ($REX['ADDON']['seo42']['settings']['homeurl'] == 1 || $REX['ADDON']['seo42']['settings']['homeurl'] == 2)) {
            $pathname = '';
        } elseif ($REX['ADDON']['seo42']['settings']['homeurl'] == 2 && $db->getValue('id') == $REX['START_ARTICLE_ID'] && count($REX['CLANG']) > 1) {
            if ($REX['ADDON']['seo42']['settings']['url_ending'] == '') {
                $langSlug = seo42::getLangUrlSlug($clang);
            } else {
                $langSlug = seo42::getLangUrlSlug($clang) . '/';
            }
            $pathname = $langSlug;
        }
        // UNSET OLD URL FROM $SEO42_URLS
        if (isset($SEO42_IDS[$id][$clang]['url']) && isset($SEO42_URLS[$SEO42_IDS[$id][$clang]['url']])) {
            unset($SEO42_URLS[$SEO42_IDS[$id][$clang]['url']]);
        }
        $SEO42_IDS[$id][$clang] = array('url' => $pathname);
        $SEO42_URLS[$pathname] = array('id' => (int) $id, 'clang' => (int) $clang);
        // get data from default lang if clone option is enabled for all other langs
        $jsonData = json_decode($db->getValue('seo_custom_url'), true);
        $articleId = $db->getValue('id');
        $clangId = $db->getValue('clang');
        if (isset($jsonData['url_clone']) && $jsonData['url_clone'] == true && $clangId == $REX['START_CLANG_ID']) {
            $REX['SEO42_URL_CLONE'][$articleId] = $jsonData;
        }
        $db->next();
    }
    // URL MANIPULATION BY SEO42
    // -----------------------------------------------------------------------------------------------------------
    $interReplaceIds = array();
    $db->reset();
    for ($i = 0; $i < $db->getRows(); $i++) {
        $urlField = $db->getValue('seo_custom_url');
        $articleId = $db->getValue('id');
        $clangId = $db->getValue('clang');
        if ($urlField != '' || isset($REX['SEO42_URL_CLONE'][$articleId])) {
            $urlData = seo42_utils::getUrlTypeData($urlField);
            $jsonData = json_decode($urlData, true);
            if (isset($REX['SEO42_URL_CLONE'][$articleId]) && !isset($jsonData['url_type'])) {
                $jsonData = $REX['SEO42_URL_CLONE'][$articleId];
            }
            switch ($jsonData['url_type']) {
                case SEO42_URL_TYPE_DEFAULT:
                    // do nothing
                    break;
                case SEO42_URL_TYPE_USERDEF_INTERN:
                    $customUrl = $jsonData['custom_url'];
                    if ($SEO42_IDS[$articleId][$clangId]['url'] != $customUrl) {
                        // only if custom url ist different then auto url
                        $SEO42_URLS[$customUrl] = $SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']];
                        unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    }
                    $SEO42_IDS[$articleId][$clangId] = array('url' => $customUrl);
                    break;
                case SEO42_URL_TYPE_USERDEF_EXTERN:
                    $customUrl = $jsonData['custom_url'];
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    $SEO42_IDS[$articleId][$clangId] = array('url' => $customUrl);
                    break;
                case SEO42_URL_TYPE_MEDIAPOOL:
                    $customUrl = $REX['MEDIA_DIR'] . '/' . $jsonData['file'];
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    $SEO42_IDS[$articleId][$clangId] = array('url' => $customUrl);
                    break;
                case SEO42_URL_TYPE_INTERN_REPLACE:
                    $customArticleId = $jsonData['article_id'];
                    $interReplaceIds[$clangId][$articleId] = array('id' => $customArticleId, 'clang' => $clangId);
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    if (isset($SEO42_IDS[$customArticleId][$clangId]['url'])) {
                        $SEO42_IDS[$articleId][$clangId] = array('url' => $SEO42_IDS[$customArticleId][$clangId]['url']);
                    } else {
                        $SEO42_IDS[$articleId][$clangId] = array('url' => '');
                    }
                    break;
                case SEO42_URL_TYPE_INTERN_REPLACE_CLANG:
                    $customArticleId = $jsonData['article_id'];
                    $customClangId = $jsonData['clang_id'];
                    $interReplaceIds[$clangId][$articleId] = array('id' => $customArticleId, 'clang' => $customClangId);
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    if (isset($SEO42_IDS[$customArticleId][$customClangId]['url'])) {
                        $SEO42_IDS[$articleId][$clangId] = array('url' => $SEO42_IDS[$customArticleId][$customClangId]['url']);
                    } else {
                        $SEO42_IDS[$articleId][$clangId] = array('url' => '');
                    }
                    break;
                case SEO42_URL_TYPE_REMOVE_ROOT_CAT:
                    $curUrl = $SEO42_IDS[$articleId][$clangId]['url'];
                    $newUrl = seo42_utils::removeRootCatFromUrl($curUrl, $clangId);
                    if ($newUrl != '') {
                        // same as SEO42_URL_TYPE_USERDEF_INTERN
                        $SEO42_URLS[$newUrl] = $SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']];
                        unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                        $SEO42_IDS[$articleId][$clangId] = array('url' => $newUrl);
                    }
                    break;
                case SEO42_URL_TYPE_CALL_FUNC:
                    if ($jsonData['no_url']) {
                        unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    }
                    break;
                case SEO42_URL_TYPE_LANGSWITCH:
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    break;
                case SEO42_URL_TYPE_NONE:
                    unset($SEO42_URLS[$SEO42_IDS[$articleId][$clangId]['url']]);
                    $SEO42_IDS[$articleId][$clangId] = array('url' => '');
                    break;
            }
            unset($jsonData);
        }
        $db->next();
    }
    // workaround for #177
    foreach ($interReplaceIds as $clangId => $value) {
        foreach ($value as $interReplaceId => $targetArticle) {
            if (isset($SEO42_IDS[$targetArticle['id']][$targetArticle['clang']]['url'])) {
                $SEO42_IDS[$interReplaceId][$clangId] = array('url' => $SEO42_IDS[$targetArticle['id']][$targetArticle['clang']]['url']);
            }
        }
    }
    // -----------------------------------------------------------------------------------------------------------
    // EXTENSION POINT "SEO42_PATHLIST_CREATED"
    $subject = array('SEO42_IDS' => $SEO42_IDS, 'SEO42_URLS' => $SEO42_URLS);
    $subject = rex_register_extension_point('SEO42_PATHLIST_CREATED', $subject);
    // EXTENSION POINT "SEO42_PATHLIST_FINAL" - READ ONLY
    rex_register_extension_point('SEO42_PATHLIST_FINAL', $subject);
    // ASSEMBLE, COMPRESS & WRITE PATHLIST TO FILE
    $pathlist_content = '$SEO42_IDS = ' . var_export($subject['SEO42_IDS'], true) . ';' . PHP_EOL . '$SEO42_URLS = ' . var_export($subject['SEO42_URLS'], true) . ';';
    $pathlist_content = seo42_compressPathlist($pathlist_content);
    rex_put_file_contents(SEO42_PATHLIST, '<?php' . PHP_EOL . $pathlist_content);
    // PURGE *.CONTENT CACHEFILES TO UPDATE INTERNAL LINKS CREATED BY replceLinks() in rex_article_base
    seo42_purgeCacheFiles();
}
/**
 * Schreibt Spracheigenschaften in die Datei include/clang.inc.php
 * 
 * @return TRUE bei Erfolg, sonst eine Fehlermeldung
 */
function rex_generateClang()
{
    global $REX;
    $lg = new rex_sql();
    $lg->setQuery("select * from " . $REX['TABLE_PREFIX'] . "clang order by id");
    $REX['CLANG'] = array();
    while ($lg->hasNext()) {
        $REX['CLANG'][$lg->getValue("id")] = $lg->getValue("name");
        $lg->next();
    }
    $file = $REX['INCLUDE_PATH'] . "/clang.inc.php";
    if (rex_replace_dynamic_contents($file, "\$REX['CLANG'] = " . var_export($REX['CLANG'], TRUE) . ";\n") === FALSE) {
        return 'Datei "' . $file . '" hat keine Schreibrechte';
    }
    return TRUE;
}