/** * Execute the search for the given SearchCommand * * @param SearchCommand $search * @return SearchResult */ public function fire(SearchCommand $search) { $search_result = new SearchResult(); $fields = array('filename', 'title'); $s = \rex_sql::factory(); $s->setQuery('SELECT * FROM ' . Watson::getTable('file') . ' LIMIT 0'); $fieldnames = $s->getFieldnames(); foreach ($fieldnames as $fieldname) { if (substr($fieldname, 0, 4) == 'med_') { $fields[] = $fieldname; } } $sql_query = ' SELECT filename, title FROM ' . Watson::getTable('file') . ' WHERE ' . $search->getSqlWhere($fields) . ' ORDER BY filename'; $results = $this->getDatabaseResults($sql_query); if (count($results)) { foreach ($results as $result) { $title = $result['title'] != '' ? ' (' . Watson::translate('watson_media_title') . ': ' . $result['title'] . ')' : ''; $entry = new SearchResultEntry(); $entry->setValue($result['filename']); $entry->setDescription(Watson::translate('watson_open_media') . $title); $entry->setIcon('icon_media.png'); $entry->setUrl('javascript:newPoolWindow(\'' . Watson::getUrl(array('page' => 'mediapool', 'subpage' => 'detail', 'file_name' => $result['filename'])) . '\')'); $m = \OOMedia::getMediaByFileName($result['filename']); if ($m instanceof \OOMedia) { if ($m->isImage()) { $entry->setQuickLookUrl(Watson::getUrl(array('rex_img_type' => 'rex_mediapool_maximized', 'rex_img_file' => $result['filename']))); } } $search_result->addEntry($entry); } } return $search_result; }
/** * @access public */ function getMediaByName($filename) { return OOMedia::getMediaByFileName($filename); }
rex_deleteCacheMedia($file_name); } else { $warning = $I18N->msg('pool_selectedmedia_error'); } } } else { $warning = $I18N->msg('pool_selectedmedia_error'); } } if ($PERMALL && $media_method == 'delete_selectedmedia') { $selectedmedia = rex_post("selectedmedia", "array"); if (count($selectedmedia) != 0) { $warning = array(); $info = array(); foreach ($selectedmedia as $file_name) { $media = OOMedia::getMediaByFileName($file_name); if ($media) { if ($PERMALL || $REX['USER']->hasPerm('media[' . $media->getCategoryId() . ']')) { $uses = $media->isInUse(); if ($uses === false) { if ($media->delete() !== FALSE) { $info[] = $I18N->msg('pool_file_deleted'); } else { $warning[] = $I18N->msg('pool_file_delete_error_1', $file_name); } $subpage = ""; } else { $tmp = '<strong>' . $I18N->msg('pool_file_delete_error_1', $file_name) . ' ' . $I18N->msg('pool_file_delete_error_2') . '</strong><br />'; foreach ($uses as $use) { $tmp .= '<br />' . $use; }
/** * @access public */ function getMedia() { global $REX; if ($this->_files === null) { $this->_files = array(); $id = $this->getId(); $list_path = $REX['INCLUDE_PATH'] . '/generated/files/' . $id . '.mlist'; if (!file_exists($list_path)) { require_once $REX['INCLUDE_PATH'] . '/functions/function_rex_generate.inc.php'; rex_generateMediaList($id); } if (file_exists($list_path)) { require_once $list_path; if (isset($REX['MEDIA']['MEDIA_CAT_ID'][$id]) && is_array($REX['MEDIA']['MEDIA_CAT_ID'][$id])) { foreach ($REX['MEDIA']['MEDIA_CAT_ID'][$id] as $filename) { $this->_files[] =& OOMedia::getMediaByFileName($filename); } } } } return $this->_files; }
public static function getImagesHTML() { global $REX; $return = []; /** * prepare images from MetaInfo */ if (self::$curArticle->getValue('art_open_graph_images')) { $images = explode(',', self::$curArticle->getValue('art_open_graph_images')); foreach ($images as $image) { $ogImage = new Image(); $image = \OOMedia::getMediaByFileName($image); if (false && \rex_addon::isActivated('seo42')) { $ogImage->setUrl(\seo42::getMediaUrl($image)); } else { $ogImage->setUrl($REX['SERVER'] . $REX['MEDIA_DIR'] . '/' . $image->getFileName()); } $ogImage->setType($image->getType()); $ogImage->setWidth($image->getWidth()); $ogImage->setHeigt($image->getHeight()); self::addImage($ogImage); } } /** @var Image $image */ foreach (self::$images as $image) { $return[] = '<meta property="og:image" content="' . $image->getUrl() . '">'; if ($image->getSecureUrl() || $REX['ADDON']['open_graph']['settings']['https']) { if (!$image->getSecureUrl()) { if (strpos($image->getUrl(), $REX['SERVER']) == 0) { $image->setSecureUrl(str_replace('http://', 'https://', $image->getUrl())); } } if ($image->getSecureUrl()) { $return[] = '<meta property="og:image:secure_url" content="' . $image->getSecureUrl() . '">'; } } if ($image->getWidth()) { $return[] = '<meta property="og:image:width" content="' . $image->getWidth() . '">'; } if ($image->getHeigt()) { $return[] = '<meta property="og:image:height" content="' . $image->getHeigt() . '">'; } if ($image->getType()) { $return[] = '<meta property="og:image:type" content="' . $image->getType() . '">'; } } return implode("\n\t", $return) . "\n\t"; }
function getFileMedia() { return OOMedia::getMediaByFileName($this->_file); }
/** * @access public * @return Returns <code>true</code> on success or <code>false</code> on error */ function delete($filename = null) { global $REX; if ($filename != null) { $OOMed = OOMedia::getMediaByFileName($filename); if ($OOMed) { return $OOMed->delete(); } } else { $qry = 'DELETE FROM ' . $this->_getTableName() . ' WHERE file_id = ' . $this->getId() . ' LIMIT 1'; $sql = new rex_sql(); $sql->setQuery($qry); if ($this->fileExists()) { unlink($REX['MEDIAFOLDER'] . DIRECTORY_SEPARATOR . $this->getFileName()); } return $sql->getError(); } return false; }
/** * @access public * @see #getMediaByFileName */ function &searchMediaByFileName($name) { return OOMedia::getMediaByFileName($name); }
/** * Accessor Method: * returns the name of the article * @deprecated 17.09.2007 */ function getFileMedia() { return OOMedia::getMediaByFileName($this->getValue('art_file')); }
public static function getImageTag($imageFile, $imageType = '', $width = 0, $height = 0) { $media = OOMedia::getMediaByFileName($imageFile); // make sure media object is valid if (OOMedia::isValid($media)) { $mediaWidth = $media->getWidth(); $mediaHeight = $media->getHeight(); $altAttribute = $media->getTitle(); } else { $mediaWidth = ''; $mediaHeight = ''; $altAttribute = ''; } // image width if ($width == 0) { $imgWidth = $mediaWidth; } else { $imgWidth = $width; } // image height if ($height == 0) { $imgHeight = $mediaHeight; } else { $imgHeight = $height; } // get url if ($imageType == '') { $url = self::getMediaFile($imageFile); } else { $url = self::getImageManagerFile($imageFile, $imageType); } return '<img src="' . $url . '" width="' . $imgWidth . '" height="' . $imgHeight . '" alt="' . $altAttribute . '" />'; }
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 ========================================'); }
<?php $file = htmlspecialchars(rex_request('file', 'string')); if ($file) { $ooPic = OOMedia::getMediaByFileName($file); if (is_object($ooPic)) { print_r($ooPic); } }
/** * @access public * @deprecated 20.02.2010 * Stattdessen getMediaByFileName() nutzen */ function getMediaById($id) { global $REX; $id = (int) $id; if ($id == 0) { return null; } $sql = rex_sql::factory(); // $sql->debugsql = true; $sql->setQuery('SELECT filename FROM ' . OOMedia::_getTableName() . ' WHERE file_id=' . $id); if ($sql->getRows() == 1) { return OOMedia::getMediaByFileName($sql->getValue('filename')); } return NULL; }
/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $replaceOldFile = FALSE) { global $REX; 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' => OOMedia::getMediaByFileName($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'); } }