$REX['ADDON']['supportpage']['hr4you_sync'] = 'http://www.redaxo.org/de/forum/addons-f30/stellenmarkt-addon-mit-optionalem-hr4you-import-t20726.html'; // add lang file if ($REX['REDAXO']) { $I18N->appendFile($REX['INCLUDE_PATH'] . '/addons/d2u_stellenmarkt/plugins/hr4you_sync/lang/'); } // consts define('HR4YOU_SYNC_DEBUG_MODE', false); define('HR4YOU_SYNC_HTML_HEADLINE_TAG', 'h3'); define('HR4YOU_SYNC_LOG_FILE_PATH', $REX['INCLUDE_PATH'] . '/data/addons/d2u_stellenmarkt/hr4you_sync/'); define('HR4YOU_SYNC_LOG_FILE', 'log_' . date('Y') . '.txt'); // includes require $REX['INCLUDE_PATH'] . '/addons/d2u_stellenmarkt/plugins/hr4you_sync/classes/class.rex_hr4you_sync.inc.php'; require $REX['INCLUDE_PATH'] . '/addons/d2u_stellenmarkt/plugins/hr4you_sync/classes/class.rex_hr4you_sync_utils.inc.php'; // default settings (user settings are saved in data dir!) $REX['ADDON']['hr4you_sync']['settings'] = array('xml_url' => '', 'default_clang_id' => '1', 'default_article_id' => '1', 'default_media_category_id' => '1', 'default_job_category_id' => '1'); // overwrite default settings with user settings rex_hr4you_sync_utils::includeSettingsFile(); if (!$REX['REDAXO']) { if (!class_exists('KLogger')) { require $REX['INCLUDE_PATH'] . '/addons/d2u_stellenmarkt/plugins/hr4you_sync/classes/class.klogger.inc.php'; } if (!class_exists('rex_fe_user')) { require $REX['INCLUDE_PATH'] . '/addons/d2u_stellenmarkt/plugins/hr4you_sync/classes/class.rex_fe_user.inc.php'; } rex_register_extension('SEO42_INCLUDED', function () { if (rex_request('func') == 'hr4you_sync') { rex_hr4you_sync::syncData(); exit; } }); }
<?php echo rex_hr4you_sync_utils::getHtmlFromMDFile('help/help.md');
<?php $page = rex_request('page', 'string'); $subpage = rex_request('subpage', 'string'); $chapter = rex_request('chapter', 'string'); $func = rex_request('func', 'string'); // save settings if ($func == 'update') { $settings = (array) rex_post('settings', 'array', array()); rex_hr4you_sync_utils::replaceSettings($settings); rex_hr4you_sync_utils::updateSettingsFile(); } ?> <div class="rex-addon-output"> <div class="rex-form"> <h2 class="rex-hl2"><?php echo $I18N->msg('d2u_stellenmarkt_hr4you_sync_settings'); ?> </h2> <form action="index.php" method="post"> <fieldset class="rex-form-col-1"> <div class="rex-form-wrapper"> <input type="hidden" name="page" value="<?php echo $page; ?> " /> <input type="hidden" name="subpage" value="<?php echo $subpage; ?> " />
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 ========================================'); }