$params = array(); $params['id'] = $articleId; $params['url_type'] = $newUrlType; if ($newUrlData['url_clone']) { foreach ($REX['CLANG'] as $theClang => $clang_name) { $params['clang'] = $theClang; rex_register_extension_point('SEO42_URL_UPDATE', '', $params); } } else { $params['clang'] = $clang; rex_register_extension_point('SEO42_URL_UPDATE', '', $params); } // generate stuff new rex_deleteCacheArticleContent($articleId, $clang); rex_generateArticle($articleId); seo42_generate_pathlist(array()); // extension point 2 rex_register_extension_point('SEO42_URL_UPDATED', '', $params); // this is for frontend link fix with js $dataUpdated = true; } else { // err msg if ($sql->getError() != '') { echo rex_warning($sql->getError()); } } } $sql = rex_sql::factory(); //$sql->debugsql = 1; $urlData = $sql->getArray('SELECT seo_custom_url FROM ' . $REX['TABLE_PREFIX'] . 'article WHERE id=' . $articleId . ' AND clang=' . $clang); $urlField = $urlData[0]['seo_custom_url'];
public static function syncRedirects() { global $REX, $SEO42_IDS, $SEO42_IDS_CLONE, $SEO42_URLS, $SEO42_URLS_CLONE; $newRedirects = array(); seo42_generate_pathlist(array()); // normal urls with existing article_id foreach ($SEO42_IDS as $id => $value) { if (isset($SEO42_IDS_CLONE[$id])) { foreach ($REX['CLANG'] as $clangId => $clangName) { $oldUrl = '/' . $SEO42_IDS_CLONE[$id][$clangId]['url']; $newUrl = '/' . $SEO42_IDS[$id][$clangId]['url']; if ($oldUrl !== $newUrl) { if ($oldUrl == '/' || $oldUrl == '' || $newUrl == '' || $oldUrl == $newUrl) { // do nothing } else { $article = OOArticle::getArticleById($id, $clangId); if (is_object($article)) { $onlyOnline = $REX['ADDON']['seo42']['settings']['sync_redirects_only_online']; if (!$onlyOnline || $onlyOnline && $article->isOnline()) { $newRedirects[$oldUrl] = $newUrl; } } } } } } } // userdef urls $userDefOldUrls = self::getUserDefUrls($SEO42_URLS_CLONE); if (isset($userDefOldUrls) && is_array($userDefOldUrls) && count($userDefOldUrls) > 0) { // include pathlist manually because at this point userdef urls are missing in $SEO42_URLS array if (file_exists(SEO42_PATHLIST)) { unset($SEO42_URLS); unset($SEO42_IDS); include SEO42_PATHLIST; } $userDefNewUrls = self::getUserDefUrls($SEO42_URLS); foreach ($userDefNewUrls as $id => $data) { if (isset($userDefOldUrls[$id])) { $oldUrl = '/' . $userDefOldUrls[$id]['url']; $newUrl = '/' . $userDefNewUrls[$id]['url']; if ($oldUrl !== $newUrl) { if ($oldUrl == '/' || $oldUrl == '' || $newUrl == '' || $oldUrl == $newUrl) { // do nothing } else { $article = OOArticle::getArticleById($data['article_id'], $data['clang']); if (is_object($article)) { $onlyOnline = $REX['ADDON']['seo42']['settings']['sync_redirects_only_online']; if (!isset($newRedirects[$oldUrl])) { if (!$onlyOnline || $onlyOnline && $article->isOnline()) { $newRedirects[$oldUrl] = $newUrl; } } } } } } } } if (count($newRedirects) > 0) { foreach ($newRedirects as $oldUrl => $newUrl) { // check for redirects loop $sql = rex_sql::factory(); $sql->setDebug(false); $sql->setQuery("SELECT * FROM `" . $REX['TABLE_PREFIX'] . "redirects` WHERE source_url LIKE '" . self::sqlLike($newUrl) . "' ESCAPE '|'"); if ($sql->getRows() > 0) { // delete existing redirect to avoid loop $sql2 = rex_sql::factory(); $sql2->setDebug(false); $sql2->setQuery("DELETE FROM `" . $REX['TABLE_PREFIX'] . "redirects` WHERE source_url LIKE '" . self::sqlLike($newUrl) . "' ESCAPE '|'"); } else { $maxAge = intval($REX['ADDON']['seo42']['settings']['redirects_max_age']); $createDate = self::getDate(); $expireDate = self::getDate($maxAge); if (!seo42_utils::redirectsDoExpire()) { $expireDate = 0; } // check if redirect already exists $sql2 = rex_sql::factory(); $sql2->setDebug(false); $sql2->setQuery("SELECT * FROM `" . $REX['TABLE_PREFIX'] . "redirects` WHERE source_url LIKE '" . self::sqlLike($oldUrl) . "' ESCAPE '|'"); if ($sql2->getRows() > 0) { // update existing redirect $sql3 = rex_sql::factory(); $sql3->setDebug(false); $sql3->setQuery('UPDATE `' . $REX['TABLE_PREFIX'] . 'redirects` SET source_url = "' . $oldUrl . '", target_url = "' . $newUrl . '", create_date = "' . $createDate . '", expire_date = "' . $expireDate . '" WHERE id = ' . $sql2->getValue('id')); } else { // add new redirect $sql3 = rex_sql::factory(); $sql3->setDebug(false); $sql3->setQuery('INSERT INTO `' . $REX['TABLE_PREFIX'] . 'redirects` (source_url, target_url, create_date, expire_date) VALUES ("' . $oldUrl . '", "' . $newUrl . '", "' . $createDate . '", "' . $expireDate . '")'); } } } // update cached redirects self::updateRedirectsFile(false); } }
} // reset inherit_from_clang to default if rewrite_mode not changed foreach ($REX['CLANG'] as $clangId => $clangName) { if (isset($langSettings[$clangId])) { if (isset($langSettings[$clangId]['rewrite_mode']) && $langSettings[$clangId]['rewrite_mode'] != SEO42_REWRITEMODE_INHERIT) { $langSettings[$clangId]['inherit_from_clang'] = 0; } } } // replace lang settings unset($REX['ADDON']['seo42']['settings']['lang']); $REX['ADDON']['seo42']['settings']['lang'] = $langSettings; // update settings file seo42_utils::updateSettingsFile(); // update pathlist seo42_generate_pathlist(''); } // url ending select box $url_ending_select = new rex_select(); $url_ending_select->setSize(1); $url_ending_select->setName('settings[url_ending]'); $url_ending_select->addOption('.html', '.html'); $url_ending_select->addOption('/', '/'); $url_ending_select->addOption($I18N->msg('seo42_settings_url_ending_without'), ''); $url_ending_select->setAttribute('style', 'width:70px;'); $url_ending_select->setSelected($REX['ADDON'][$myself]['settings']['url_ending']); // home url select box $ooa = OOArticle::getArticleById($REX['START_ARTICLE_ID']); if ($ooa) { $homename = strtolower($ooa->getName()); } else {
/** * RESOLVE() * * resolve url to ARTICLE_ID & CLANG, * resolve rewritten params back to GET/REQUEST */ function resolve() { global $REX, $SEO42_URLS, $SEO42_IDS; if (!file_exists(SEO42_PATHLIST)) { seo42_generate_pathlist(array()); } require_once SEO42_PATHLIST; if (!$REX['REDAXO']) { $article_id = -1; $clang = $REX['CUR_CLANG']; $start_id = $REX['START_ARTICLE_ID']; $notfound_id = $REX['NOTFOUND_ARTICLE_ID']; $install_subdir = seo42::getServerSubDir(); // 42 $homelang = $REX['ADDON']['seo42']['settings']['homelang']; // TRY IMMEDIATE MATCH OF REQUEST_URI AGAINST PATHLIST.. if (self::resolve_from_pathlist(ltrim($_SERVER['REQUEST_URI'], '/'))) { return; } // allow_article_id ? if ($REX['ADDON']['seo42']['settings']['allow_article_id'] && rex_get('article_id', 'int') > 0) { return self::setArticleId(rex_request('article_id', 'int'), rex_request('clang', 'int', $clang)); } // IF NON_REWRITTEN URLS ALLOWED -> USE ARTICLE_ID FROM REQUEST if ($REX['ADDON']['seo42']['settings']['auto_redirects'] != SEO42_AUTO_REDIRECT_NONE && rex_get('article_id', 'int') > 0) { if ($REX['ADDON']['seo42']['settings']['auto_redirects'] == SEO42_AUTO_REDIRECT_ARTICLE_ID) { $artId = rex_request('article_id', 'int'); $clangId = rex_request('clang', 'int', $clang); $article = OOArticle::getArticleById($artId, $clangId); if (OOArticle::isValid($article)) { $redirect = array('id' => $artId, 'clang' => $clangId, 'status' => 301); return self::redirect($redirect); /*todo: include params*/ } } } // GET PATH RELATIVE TO INTALL_SUBDIR ---------------> 42 $path = ltrim($_SERVER['REQUEST_URI'], '/'); if (seo42::isSubDirInstall()) { $path = substr($path, strlen($install_subdir)); $path = ltrim($path, '/'); } // TRIM STANDARD PARAMS if (($pos = strpos($path, '?')) !== false) { $path = substr($path, 0, $pos); } // TRIM ANCHORS if (($pos = strpos($path, '#')) !== false) { $path = substr($path, 0, $pos); } // RETRY RESOLVE VIA PATHLIST if (self::resolve_from_pathlist($path)) { return; } // smart redirects option if ($REX['ADDON']['seo42']['settings']['smart_redirects']) { $trimmedReuqestUri = trim($_SERVER['REQUEST_URI'], '/'); $trimmedReuqestUri = str_replace('.html', '', $trimmedReuqestUri); $requestUriWithCorrectUrlEnding = $trimmedReuqestUri . $REX['ADDON']['seo42']['settings']['url_ending']; if (isset($SEO42_URLS[$requestUriWithCorrectUrlEnding])) { $redirect = array('id' => $SEO42_URLS[$requestUriWithCorrectUrlEnding]['id'], 'clang' => $SEO42_URLS[$requestUriWithCorrectUrlEnding]['clang'], 'status' => 301); return self::redirect($redirect); } } // auto redirects if ($REX['ADDON']['seo42']['settings']['auto_redirects'] == SEO42_AUTO_REDIRECT_URL_REWRITE || $REX['ADDON']['seo42']['settings']['auto_redirects'] == SEO42_AUTO_REDIRECT_URL_REWRITE_R3) { // smart redirects for old fashioned standard redaxo rewrite methods if ($REX['ADDON']['seo42']['settings']['auto_redirects'] == SEO42_AUTO_REDIRECT_URL_REWRITE_R3) { preg_match('/\\/(.*(\\.))?((?P<clang>[0-9]+)(.*)\\-(?P<id>[0-9]+))((\\-|\\.).*)/', $_SERVER['REQUEST_URI'], $url_params); } else { preg_match('/\\/(.*(\\.))?((?P<id>[0-9]+)\\-(?P<clang>[0-9]+))((\\-|\\.).*)/', $_SERVER['REQUEST_URI'], $url_params); } if ($url_params !== false && isset($url_params['id']) && isset($url_params['clang'])) { $article = OOArticle::getArticleById($url_params['id'], $url_params['clang']); if (OOArticle::isValid($article)) { $redirect = array('id' => $url_params['id'], 'clang' => $url_params['clang'], 'status' => 301); return self::redirect($redirect); } } } // check for possible lang slug to load up correct language for 404 article $firstSlashPos = strpos($path, '/'); if ($firstSlashPos !== false) { $possibleLangSlug = substr($path, 0, $firstSlashPos); $langSlugs = array(); foreach ($REX['CLANG'] as $clangId => $clangName) { $langSlugs[$clangId] = seo42::getLangUrlSlug($clangId); } $clangId = array_search($possibleLangSlug, $langSlugs); if ($clangId !== false) { $clang = $clangId; $REX['CUR_CLANG'] = $clang; } } // GET ID FROM EXTENSION POINT $ep = rex_register_extension_point('SEO42_ARTICLE_ID_NOT_FOUND', ''); if (isset($ep['article_id']) && $ep['article_id'] > 0) { if (isset($ep['clang']) && $ep['clang'] > -1) { $clang = $ep['clang']; } return self::setArticleId($ep['article_id'], $clang); } // STILL NO MATCH -> 404 seo42::set404ResponseFlag(); self::setArticleId($notfound_id, $clang); } }
public static function syncData() { global $REX, $I18N; // error reporting if (HR4YOU_SYNC_DEBUG_MODE) { ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1); } else { ini_set('display_startup_errors', 0); ini_set('display_errors', 0); error_reporting(0); } // necessary stuff so mediapool function can work properly in frontend $REX['USER'] = new rex_fe_user(); $I18N = rex_create_lang($REX['LANG']); include_once $REX['INCLUDE_PATH'] . '/functions/function_rex_generate.inc.php'; include_once $REX['INCLUDE_PATH'] . '/functions/function_rex_mediapool.inc.php'; // init logger $logFile = HR4YOU_SYNC_LOG_FILE_PATH; $log = KLogger::instance($logFile, KLogger::INFO); $phpLogErrors = ini_get('log_errors'); $phperrorLog = ini_get('error_log'); ini_set('log_errors', 1); ini_set('error_log', $log->getLogFilePath()); $log->logInfo('======================================== START HR4YOU SYNC ========================================'); $context = stream_context_create(array('http' => array('header' => 'Accept: application/xml'))); $xmlUrl = $REX['ADDON']['hr4you_sync']['settings']['xml_url']; $defaultClangId = $REX['ADDON']['hr4you_sync']['settings']['default_clang_id']; $defaultArticleId = $REX['ADDON']['hr4you_sync']['settings']['default_article_id']; $defaultMediaCategoryId = $REX['ADDON']['hr4you_sync']['settings']['default_media_category_id']; $defaultJobCategoryId = $REX['ADDON']['hr4you_sync']['settings']['default_job_category_id']; $xmlString = file_get_contents($xmlUrl, false, $context); $jobs = new SimpleXMLElement($xmlString); // remove all previously synced jobs and media files $log->logInfo('>> [INF] remove all previously synced jobs and media files'); $sql = rex_sql::factory(); $sql->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql, "SELECT * FROM `" . $REX['TABLE_PREFIX'] . "d2u_stellenmarkt_stellen` WHERE hr4you_jobid > 0 ORDER BY stellen_id ASC"); for ($i = 0; $i < $sql->getRows(); $i++) { $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, 'DELETE FROM `' . $REX['TABLE_PREFIX'] . 'd2u_stellenmarkt_stellen` WHERE stellen_id = ' . $sql->getValue('stellen_id')); rex_hr4you_sync_utils::logQuery($log, $sql2, 'DELETE FROM `' . $REX['TABLE_PREFIX'] . 'd2u_stellenmarkt_stellen_lang` WHERE stellen_id = ' . $sql->getValue('stellen_id')); // delete media $log->logInfo('>> [INF] delete media: ' . $sql->getValue('bild')); $media = OOMedia::getMediaByFileName($sql->getValue('bild')); if (is_object($media)) { $mediaInUse = $media->isInUse(); if ($mediaInUse === false) { if ($media->delete() !== false) { // success $log->logInfo('>> [INF] media deleted'); } else { // failed $log->logError('>> [ERR] media not deleted'); } } else { $log->logInfo('>> [INF] media not deleted because still in use'); } } else { $log->logInfo('>> [INF] media does not exist anymore'); } $sql->next(); } // add jobs $log->logInfo('>> [INF] add jobs'); foreach ($jobs->entry as $job) { $sql = rex_sql::factory(); $sql->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql, "SELECT * FROM `" . $REX['TABLE_PREFIX'] . "d2u_stellenmarkt_stellen` WHERE hr4you_jobid = " . $job->jobid); if ($sql->getRows() < 1) { // for safety reasons: only addon new job if it does not already exist // copy media file $log->logInfo('>> [INF] copy media file'); $pathInfo = pathinfo($job->kopfgrafik_url); $originalFile = $pathInfo['basename']; $originalFileWithPath = $REX['MEDIAFOLDER'] . DIRECTORY_SEPARATOR . $originalFile; $mediaFile = self::rex_mediapool_filename_nosubindex($pathInfo['basename'], false); $mediaFileWithPath = $REX['MEDIAFOLDER'] . DIRECTORY_SEPARATOR . $mediaFile; if (!file_exists($mediaFileWithPath)) { if (copy($job->kopfgrafik_url, $mediaFileWithPath)) { $log->logInfo('>> [INF] media file sucessfully copied because it does not exist'); } if (chmod($mediaFileWithPath, $REX['FILEPERM'])) { $log->logInfo('>> [INF] media file chmod to: ' . $REX['FILEPERM']); } $mpSyncReturn = rex_mediapool_syncFile($mediaFile, $defaultMediaCategoryId, $job->kopfgrafik_name); $log->logInfo('>> [INF] media file synced width return value: ', $mpSyncReturn); } else { $log->logInfo('>> [INF] media file already exists'); } // retrieve id of contact by email address $log->logInfo('>> [INF] retrieve id of contact by email address'); $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, "SELECT kontakt_id FROM `" . $REX['TABLE_PREFIX'] . "d2u_stellenmarkt_kontakt` WHERE email LIKE '" . $job->ap_email . "'"); if ($sql2->getRows() > 0) { //contact found $contactId = $sql2->getValue('kontakt_id'); $log->logInfo('>> [INF] contact found! id:' . $contactId); } else { $log->logInfo('>> [INF] contact not found. adding new contact'); $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, 'INSERT INTO `' . $REX['TABLE_PREFIX'] . 'd2u_stellenmarkt_kontakt` (name, bild, telefon, email) VALUES ("' . $job->ap_vorname . ' ' . $job->ap_nachname . '","", "' . $job->ap_telefon . '", "' . $job->ap_email . '")'); $contactId = $sql2->getLastId(); $log->logInfo('>> [INF] contact id: ' . $contactId); } // checkout job category id as xml and addon ids are different $log->logInfo('>> [INF] checkout job category id as xml and addon ids are different'); $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, "SELECT kategorie_id FROM `" . $REX['TABLE_PREFIX'] . "d2u_stellenmarkt_kategorien` WHERE hr4you_berufskategorie_id LIKE '" . $job->berufskategorie_id . "'"); if ($sql2->getRows() > 0) { // job category found $log->logInfo('>> [INF] job category found!'); $jobCategoryId = $sql2->getValue('kategorie_id'); } else { $log->logInfo('>> [INF] job category not found! using default job category id'); $jobCategoryId = $defaultJobCategoryId; } // add new job $log->logInfo('>> [INF] add new job'); $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, 'INSERT INTO `' . $REX['TABLE_PREFIX'] . 'd2u_stellenmarkt_stellen` (hr4you_jobid, interne_bezeichnung, interne_nummer, datum, status, kontakt_id, artikel_id, kategorie_ids, bild, hr4you_url_application_form) VALUES (' . $job->jobid . ',"' . $job->titel . '", ' . $job->referenznummer . ', "' . $job->von_datum . '", "online", ' . $contactId . ', ' . $defaultArticleId . ', "|' . $jobCategoryId . '|", "' . $mediaFile . '", "' . $job->url_application_form . '")'); $theJobId = $sql2->getLastId(); // get blocks and headings $block1 = self::trimString($job->block1_html); $block2 = self::trimString($job->block2_html); $block3 = self::trimString($job->block3_html); $headline1 = self::getHeadline($block1); $headline2 = self::getHeadline($block2); $headline3 = self::getHeadline($block3); include_once $REX['INCLUDE_PATH'] . '/addons/xoutputfilter/classes/class.xoutputfilter.inc.php'; $xoutputFilter = new xoutputfilter(); if ($block1 != '') { if ($headline1 == '') { $headline1 = $xoutputFilter->get('###aufgaben_ueberschrift###', $defaultClangId); $log->logInfo('>> [INF] headline1 not found. using default: ' . $headline1); } else { $block1 = self::stripHeadline($block1); } } if ($block2 != '') { if ($headline2 == '') { $headline2 = $xoutputFilter->get('###profil_ueberschrift###', $defaultClangId); $log->logInfo('>> [INF] headline2 not found. using default: ' . $headline2); } else { $block2 = self::stripHeadline($block2); } } if ($block3 != '') { if ($headline3 == '') { $headline3 = $xoutputFilter->get('###angebot_ueberschrift###', $defaultClangId); $log->logInfo('>> [INF] headline3 not found. using default: ' . $headline3); } else { $block3 = self::stripHeadline($block3); } } // add lang specific stuff for new job $log->logInfo('>> [INF] add lang specific stuff for new job'); $sql2 = rex_sql::factory(); $sql2->setDebug(HR4YOU_SYNC_DEBUG_MODE); rex_hr4you_sync_utils::logQuery($log, $sql2, 'INSERT INTO `' . $REX['TABLE_PREFIX'] . 'd2u_stellenmarkt_stellen_lang` (stellen_id, clang_id, bezeichnung, aufgaben_ueberschrift, aufgaben_text, profil_ueberschrift, profil_text, angebot_ueberschrift, angebot_text, hr4you_einleitung) VALUES (' . $theJobId . ', ' . $defaultClangId . ', "' . $job->titel . '", "' . $headline1 . '", "' . htmlspecialchars($block1) . '", "' . $headline2 . '", "' . htmlspecialchars($block2) . '", "' . $headline3 . '", "' . htmlspecialchars($block3) . '", "' . $job->einleitung . '")'); } } // delete pathlist as ids of jobs have changed $log->logInfo('>> [INF] delete pathlist'); seo42_generate_pathlist(array()); // restore vars and settings unset($REX['USER']); unset($I18N); ini_set('log_errors', $phpLogErrors); ini_set('error_log', $phperrorLog); $log->logInfo('======================================== END HR4YOU SYNC ========================================'); }