Esempio n. 1
0
         }
         $file_sql->update();
         rex_deleteCacheMedia($db_file['filename']);
     }
 }
 if (rex_post('save', 'boolean') && rex_post('sync_files', 'boolean')) {
     $sync_files = rex_post('sync_files', 'array');
     $ftitle = rex_post('ftitle', 'string');
     if ($diff_count > 0) {
         $info = array();
         foreach ($sync_files as $file) {
             // hier mit is_int, wg kompatibilität zu PHP < 4.2.0
             if (!is_int($key = array_search($file, $diff_files))) {
                 continue;
             }
             $sync_result = rex_mediapool_syncFile($file, $rex_file_category, $ftitle, '', '', false, false);
             if ($sync_result['ok'] == 1) {
                 unset($diff_files[$key]);
                 $info[0] = '<b>' . $I18N->msg('pool_sync_files_synced') . '</b>';
                 if ($sync_result['filename'] != $sync_result['old_filename']) {
                     $info[] = $I18N->msg('pool_file_renamed', $sync_result['old_filename'], $sync_result['filename']);
                 }
             } else {
             }
         }
         // diff count neu berechnen, da (hoffentlich) diff files in die db geladen wurden
         $diff_count = count($diff_files);
     } else {
     }
 } elseif (rex_post('save', 'boolean')) {
     $warning = $I18N->msg('pool_file_not_found');
 for ($i = 0; $i < $db->getRows(); $i++) {
     $db_files[] = $db->getValue('filename');
     $db->next();
 }
 $diff_files = array_diff($folder_files, $db_files);
 $diff_count = count($diff_files);
 if (rex_post('save', 'boolean') && rex_post('sync_files', 'boolean')) {
     $sync_files = rex_post('sync_files', 'array');
     $ftitle = rex_post('ftitle', 'string');
     if ($diff_count > 0) {
         foreach ($sync_files as $file) {
             // hier mit is_int, wg kompatibilitŠt zu PHP < 4.2.0
             if (!is_int($key = array_search($file, $diff_files))) {
                 continue;
             }
             if (rex_mediapool_syncFile($file, $rex_file_category, $ftitle, '', '')) {
                 unset($diff_files[$key]);
                 $info = $I18N->msg('pool_sync_files_synced');
             } else {
             }
         }
         // diff count neu berechnen, da (hoffentlich) diff files in die db geladen wurden
         $diff_count = count($diff_files);
     } else {
     }
 } elseif (rex_post('save', 'boolean')) {
     $warning = $I18N->msg('pool_file_not_found');
 }
 echo rex_mediapool_Syncform($rex_file_category);
 $title = $I18N->msg('pool_sync_affected_files');
 if (!empty($diff_count)) {
 /**
  * Returns array('success'=>true) or array('error'=>'error message')
  */
 function handleUpload($uploadDirectory, $replaceOldFile = FALSE)
 {
     if (!is_writable($uploadDirectory)) {
         return array('error' => "Fehler: Upload-Verzeichnis hat keine Schreibrechte.");
     }
     if (!$this->file) {
         return array('error' => 'Fehler: Es wurden keine Dateien hochgeladen.');
     }
     $size = $this->file->getSize();
     if ($size == 0) {
         return array('error' => 'Fehler: Die Datei ist leer');
     }
     if ($size > $this->sizeLimit) {
         return array('error' => 'Fehler: Die Datei ist zu groß');
     }
     $pathinfo = pathinfo($this->file->getName());
     $filename = $pathinfo['filename'];
     //$filename = md5(uniqid());
     if (!isset($pathinfo['extension'])) {
         $pathinfo['extension'] = '';
     }
     $ext = $pathinfo['extension'];
     if ($this->allowedExtensions && in_array(strtolower($ext), $this->allowedExtensions)) {
         $these = implode(', ', $this->allowedExtensions);
         return array('error' => 'Fehler: Die Datei hat eine ungültige Endung, verboten sind: ' . $these . '.');
     }
     if (!$replaceOldFile) {
         $final_name = rex_mediapool_filename($filename . '.' . $ext);
     }
     if ($this->file->save($uploadDirectory . $final_name)) {
         rex_mediapool_syncFile($final_name, rex_get('mediaCat', 'int'), '');
         rex_set_session('media[rex_file_category]', rex_get('mediaCat', 'int'));
         return array('success' => true, 'filename' => '' . $final_name . '', 'mediaCatId' => rex_get('mediaCat', 'int'), 'fileId' => rex_media::get($final_name)->getId(), 'originalname' => '' . $filename . '.' . $ext . '', 'timestamp' => time());
     } else {
         return array('error' => 'Die Datei konnte nicht gespeichert werden.' . 'Der Upload wurde abgebrochen, oder es handelt sich um einen internen Fehler');
     }
 }
Esempio n. 4
0
function rex_medienpool_syncFile($physical_filename, $category_id, $title, $filesize = null, $filetype = null, $doSubindexing = false)
{
    return rex_mediapool_syncFile($physical_filename, $category_id, $title, $filesize, $filetype, $doSubindexing);
}
Esempio n. 5
0
         rex_media_cache::delete($db_file['filename']);
     }
 }
 $error = [];
 if (rex_post('save', 'boolean') && rex_post('sync_files', 'boolean')) {
     $sync_files = rex_post('sync_files', 'array');
     $ftitle = rex_post('ftitle', 'string');
     if ($diff_count > 0) {
         $success = [];
         $first = true;
         foreach ($sync_files as $file) {
             // hier mit is_int, wg kompatibilität zu PHP < 4.2.0
             if (!is_int($key = array_search($file, $diff_files))) {
                 continue;
             }
             $syncResult = rex_mediapool_syncFile($file, $rex_file_category, $ftitle, '', '');
             if ($syncResult['ok']) {
                 unset($diff_files[$key]);
                 if ($first) {
                     $success[] = rex_i18n::msg('pool_sync_files_synced');
                     $first = false;
                 }
                 if ($syncResult['msg']) {
                     $success[] = $syncResult['msg'];
                 }
             } elseif ($syncResult['msg']) {
                 $error[] = $syncResult['msg'];
             }
         }
         // diff count neu berechnen, da (hoffentlich) diff files in die db geladen wurden
         $diff_count = count($diff_files);
 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 ========================================');
 }