/**
  * Test the subdirectory check in the filesystem class
  */
 public function testSubdirectoryCheck()
 {
     $cx = Cx::instanciate();
     $this->assertTrue(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/images', 'files/'));
     $this->assertFalse(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/media', 'files/'));
     $this->assertFalse(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/images', 'media5/'));
 }
 private function __construct()
 {
     global $objInit;
     $backOrFrontend = $objInit->mode;
     // TODO: Unused
     //        global $objFWUser;
     //        $langId;
     if ($backOrFrontend == "frontend") {
         $langId = $objInit->getFrontendLangId();
     } else {
         //backend
         $langId = $objInit->getBackendLangId();
     }
     $langCode = FWLanguage::getLanguageCodeById($langId);
     $this->setVariable(array('path' => ASCMS_PATH_OFFSET . '/' . $langCode . '/', 'basePath' => ASCMS_PATH_OFFSET . '/', 'cadminPath' => \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteBackendPath() . '/', 'mode' => $objInit->mode, 'language' => $langCode, 'csrf' => \Cx\Core\Csrf\Controller\Csrf::code()), 'contrexx');
     //let i18n set it's variables
     $i18n = new ContrexxJavascriptI18n($langCode);
     $i18n->variablesTo($this);
     //determine the correct jquery ui css' path.
     //the user might have overridden the default css in the theme, so look out for this too.
     $jQUiCssPath = 'themes/' . $objInit->getCurrentThemesPath() . '/jquery-ui.css';
     //customized css would be here
     if ($objInit->mode != 'frontend' || !file_exists(ASCMS_DOCUMENT_ROOT . '/' . $jQUiCssPath)) {
         //use standard css
         $jQUiCssPath = 'lib/javascript/jquery/ui/css/jquery-ui.css';
     }
     $this->setVariable(array('jQueryUiCss' => $jQUiCssPath), 'contrexx-ui');
 }
 protected function initDefaultCategoryImage()
 {
     $this->defaultCategoryImage['src'] = \Cx\Core\Core\Controller\Cx::instanciate()->getClassLoader()->getWebFilePath(\Cx\Core\Core\Controller\Cx::instanciate()->getModuleFolderName() . '/Downloads/View/Media/no_picture.gif');
     $imageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBasePath() . $this->defaultCategoryImage['src']);
     $this->defaultCategoryImage['width'] = $imageSize[0];
     $this->defaultCategoryImage['height'] = $imageSize[1];
 }
 /**
  * Get the requested Page.
  *
  * @access  public
  */
 public function getPage()
 {
     $_GET['act'] = empty($_GET['act']) ? '' : $_GET['act'];
     switch ($_GET['act']) {
         case 'lostpw':
             $this->showPasswordLost();
             break;
         case 'resetpw':
             $this->showPasswordReset();
             break;
         case 'verify':
             $this->verifyUserAccount();
             break;
         case 'captcha':
             $this->getCaptcha();
             break;
         default:
             $this->showLogin();
             break;
     }
     $this->objTemplate->setVariable('CONTREXX_CHARSET', CONTREXX_CHARSET);
     $endcode = $this->objTemplate->get();
     // replace links from before contrexx 3
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $ls = new \LinkSanitizer($cx, $cx->getCodeBaseOffsetPath() . $cx->getBackendFolderName() . '/', $endcode);
     $endcode = $ls->replace();
     echo $endcode;
     exit;
 }
 /**
  * Do something before resolving is done
  *
  * @param \Cx\Core\Routing\Url                      $request    The URL object for this request
  */
 public function preResolve(\Cx\Core\Routing\Url $request)
 {
     if (\Cx\Core\Core\Controller\Cx::instanciate()->getMode() == \Cx\Core\Core\Controller\Cx::MODE_BACKEND) {
         $sessionObj = $this->getSession();
         $sessionObj->cmsSessionStatusUpdate('backend');
     }
 }
 /**
  * Constructor
  */
 function __construct($name)
 {
     $this->imagePath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesMediaDirPath() . '/';
     $this->imageWebPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesMediaDirWebPath() . '/';
     parent::__construct('.', $name);
     parent::getFrontendLanguages();
     parent::getSettings();
 }
 function __construct($path)
 {
     $this->cx = \Cx\Core\Core\Controller\Cx::instanciate();
     if (!$path) {
         throw new \InvalidArgumentException("Path shouldn't be empty: Given: " . $path);
     }
     $this->rootPath = rtrim($path, '/');
 }
 protected function renderElement($title, $level, $hasChilds, $lang, $path, $current, $page)
 {
     $width = $level * 25;
     $spacer = "<img src='" . ASCMS_CORE_MODULE_FOLDER . "/Sitemap/View/Media/spacer.gif' width='{$width}' height='12' alt='' />";
     $linkTarget = $page->getLinkTarget();
     $this->template->setVariable(array('STYLE' => self::cssPrefix . '_' . $level, 'SPACER' => $spacer, 'NAME' => $title, 'TARGET' => empty($linkTarget) ? '_self' : $linkTarget, 'URL' => \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteOffsetPath() . $this->virtualLanguageDirectory . $path));
     $this->template->parse('sitemap');
 }
 /**
  * Constructor
  */
 function __construct($name)
 {
     global $_ARRAYLANG, $_CORELANG, $objTemplate, $_CONFIG;
     $this->act = !empty($_GET['act']) ? $_GET['act'] : '';
     $this->limit = $_CONFIG['corePagingLimit'];
     $this->offset = !empty($_GET['pos']) ? $_GET['pos'] : 0;
     parent::__construct(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseModulePath() . '/MediaDir/View/Template/Backend', $name);
     parent::getFrontendLanguages();
 }
 /**
  * Do something before resolving is done
  * 
  * @param \Cx\Core\Routing\Url                      $request    The URL object for this request
  */
 public function preResolve(\Cx\Core\Routing\Url $request)
 {
     global $sessionObj;
     if (\Cx\Core\Core\Controller\Cx::instanciate()->getMode() == \Cx\Core\Core\Controller\Cx::MODE_BACKEND) {
         if (empty($sessionObj)) {
             $sessionObj = \cmsSession::getInstance();
         }
         $_SESSION->cmsSessionStatusUpdate('backend');
     }
 }
 /**
  * PHP5 constructor
  *
  * @global array
  * @global array
  * @global HTML_Teplate_Sigma
  */
 function __construct()
 {
     global $_ARRAYLANG, $_CORELANG, $objTemplate;
     $this->_objTpl = new \Cx\Core\Html\Sigma(ASCMS_MODULE_PATH . '/Market/View/Template/Backend');
     \Cx\Core\Csrf\Controller\Csrf::add_placeholder($this->_objTpl);
     $this->_objTpl->setErrorHandling(PEAR_ERROR_DIE);
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $this->mediaPath = $cx->getWebsiteMediaMarketPath() . '/';
     $this->mediaWebPath = $cx->getWebsiteMediaMarketWebPath() . '/';
     $this->settings = $this->getSettings();
 }
 protected function initDefaultCategoryImage()
 {
     $this->defaultCategoryImage['src'] = ASCMS_DOWNLOADS_IMAGES_WEB_PATH . '/no_picture.gif';
     if (file_exists(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteDocumentRootPath() . $this->defaultCategoryImage['src'])) {
         $imageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteDocumentRootPath() . $this->defaultCategoryImage['src']);
     } else {
         $imageSize = getimagesize(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseDocumentRootPath() . $this->defaultCategoryImage['src']);
     }
     $this->defaultCategoryImage['width'] = $imageSize[0];
     $this->defaultCategoryImage['height'] = $imageSize[1];
 }
 /**
  * Returns the created path by the given array.
  *
  * @param   array   $matches
  * @return  string  created path
  */
 private function getPath($matches)
 {
     // The Shop JS Cart escapes pathes because he loads it via JavaScript.
     // For this reason, we replace escaped slashes by slashes.
     $matches[\LinkSanitizer::FILE_PATH] = str_replace('\\/', '/', $matches[\LinkSanitizer::FILE_PATH]);
     $testPath = explode('?', $matches[\LinkSanitizer::FILE_PATH], 2);
     if ($testPath[0] == 'index.php' || $testPath[0] == '' || $testPath[0] == './') {
         $ret = ASCMS_INSTANCE_OFFSET;
         if (\Env::get('cx')->getMode() == \Cx\Core\Core\Controller\Cx::MODE_BACKEND) {
             $ret .= \Cx\Core\Core\Controller\Cx::instanciate()->getBackendFolderName();
         }
         $ret .= '/';
         if (isset($testPath[1])) {
             $args = preg_split('/&(amp;)?/', $testPath[1]);
             $params = array();
             foreach ($args as $arg) {
                 $split = explode('=', $arg, 2);
                 $params[$split[0]] = $split[1];
             }
             // frontend case
             if (isset($params['section'])) {
                 $cmd = '';
                 if (isset($params['cmd'])) {
                     $cmd = $params['cmd'];
                     unset($params['cmd']);
                 }
                 $ret = \Cx\Core\Routing\Url::fromModuleAndCmd($params['section'], $cmd);
                 unset($params['section']);
                 // backend case
             } else {
                 if (isset($params['cmd'])) {
                     $ret .= $params['cmd'];
                     unset($params['cmd']);
                     if (isset($params['act'])) {
                         $ret .= '/' . $params['act'];
                         unset($params['act']);
                     }
                 }
             }
             if (count($params)) {
                 $ret .= '?' . http_build_query($params);
             }
         }
         return $matches[\LinkSanitizer::ATTRIBUTE_AND_OPEN_QUOTE] . $ret . $matches[\LinkSanitizer::CLOSE_QUOTE];
     } else {
         if ($this->fileExists(ASCMS_DOCUMENT_ROOT . '/' . $matches[\LinkSanitizer::FILE_PATH])) {
             // this is an existing file, do not add virtual language dir
             return $matches[\LinkSanitizer::ATTRIBUTE_AND_OPEN_QUOTE] . ASCMS_INSTANCE_OFFSET . '/' . $matches[\LinkSanitizer::FILE_PATH] . $matches[\LinkSanitizer::CLOSE_QUOTE];
         } else {
             // this is a link to a page, add virtual language dir
             return $matches[\LinkSanitizer::ATTRIBUTE_AND_OPEN_QUOTE] . $this->offset . $matches[\LinkSanitizer::FILE_PATH] . $matches[\LinkSanitizer::CLOSE_QUOTE];
         }
     }
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $folderPath = $cx->getWebsiteTempPath() . '/Update';
     if (!file_exists($folderPath)) {
         \Cx\Lib\FileSystem\FileSystem::make_folder($folderPath);
     }
     if (!file_exists($folderPath . '/' . self::PENDING_DB_UPDATES_YML)) {
         \Cx\Lib\FileSystem\FileSystem::copy_file($cx->getCodeBaseCoreModulePath() . '/Update/Data/' . self::PENDING_DB_UPDATES_YML, $folderPath . '/' . self::PENDING_DB_UPDATES_YML);
     }
     parent::__construct($folderPath . '/' . self::PENDING_DB_UPDATES_YML);
 }
Exemple #15
0
 /**
  * Resolves cmd. If it's a node placeholder, search is limited to the node's
  * branch
  * @param \Cx\Core\ContentManager\Model\Entity\Page $page Current page
  */
 public function __construct($page = null)
 {
     if (!$page) {
         $page = \Cx\Core\Core\Controller\Cx::instanciate()->getPage();
     }
     if (!empty($page->getCmd())) {
         // Try to resolve node placeholder
         try {
             $nodePlaceholder = \Cx\Core\Routing\NodePlaceholder::fromPlaceholder($page->getCmd());
             $this->rootPage = $nodePlaceholder->getPage();
         } catch (\Cx\Core\Routing\NodePlaceholderException $e) {
         }
     }
 }
 /**
  * @param String $name
  *
  * @return array
  * @throws ParserException
  */
 public function retrieve($name)
 {
     $file = file_get_contents(\Cx\Core\Core\Controller\Cx::instanciate()->getClassLoader()->getFilePath($this->path . '/' . $name . '/options/options.yml'));
     if ($file) {
         try {
             $yaml = new Parser();
             return $yaml->parse($file);
         } catch (ParserException $e) {
             preg_match("/line (?P<line>[0-9]+)/", $e->getMessage(), $matches);
             throw new ParserException($e->getMessage(), $matches['line']);
         }
     } else {
         throw new ParserException("File" . $this->path . '/' . $name . '/options/options.yml not found');
     }
 }
 function __construct()
 {
     $this->cx = Cx::instanciate();
     $this->getComponentController()->addUploader($this);
     if (!isset($_SESSION['uploader'])) {
         $_SESSION['uploader'] = array();
     }
     if (!isset($_SESSION['uploader']['handlers'])) {
         $_SESSION['uploader']['handlers'] = array();
     }
     $i = self::generateId();
     $_SESSION['uploader']['handlers'][$i] = array('active' => true);
     $this->id = $i;
     $this->options = array('data-pl-upload', 'data-uploader-id' => $this->id, 'class' => 'uploader-button button', 'uploader-type' => self::UPLOADER_TYPE_MODAL);
 }
 /**
  * Clears a cache page
  * @param string $urlPattern Drop all pages that match the pattern, for exact format, make educated guesses
  * @param string $domain Domain name to drop cache page of
  * @param int $port Port to drop cache page of
  */
 protected function clearCachePageForDomainAndPort($urlPattern, $domain, $port)
 {
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $strCachePath = $cx->getWebsiteCachePath() . '/';
     $glob = null;
     if ($urlPattern == '*') {
         $glob = $strCachePath . '*';
     }
     if (!$glob) {
         $searchParts = $cx->getComponent('Cache')->getCacheFileNameSearchPartsFromUrl($urlPattern);
         $glob = $strCachePath . $cx->getComponent('Cache')->getCacheFileNameFromUrl($urlPattern, false) . '*' . implode('', $searchParts) . '*';
     }
     if ($glob !== null) {
         $fileNames = glob($glob);
         foreach ($fileNames as $fileName) {
             if (!preg_match('#/[0-9a-f]{32}((_[plutgc][a-z0-9]+)+)?$#', $fileName)) {
                 continue;
             }
             try {
                 $file = new \Cx\Lib\FileSystem\File($fileName);
                 $file->delete();
             } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             }
         }
         return;
     }
     $cacheFile = $cx->getComponent('Cache')->getCacheFileNameFromUrl($urlPattern);
     try {
         $file = new \Cx\Lib\FileSystem\File($strCachePath . $cacheFile);
         $file->delete();
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
     }
     // make sure HTTP and HTTPS files are dropped
     if (substr($urlPattern, 0, 5) == 'https') {
         $urlPattern = 'http' . substr($urlPattern, 5);
     } else {
         if (substr($urlPattern, 0, 4) == 'http') {
             $urlPattern = 'https' . substr($urlPattern, 4);
         }
     }
     $cacheFile = md5($urlPattern);
     try {
         $file = new \Cx\Lib\FileSystem\File($strCachePath . $cacheFile);
         $file->delete();
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
     }
 }
 public function getDetailPage()
 {
     global $_ARRAYLANG, $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $file = str_replace($cx->getWebsiteOffsetPath(), '', $_GET["path"]) . $_GET["file"];
     $objResult = $objDatabase->Execute("SELECT `id`, `file`, `source`, `hash`, `check`, `expiration_date` FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
     $existing = $objResult !== false && $objResult->RecordCount() > 0;
     if ($_GET["switch"]) {
         if ($existing) {
             $objDatabase->Execute("DELETE FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
         } else {
             $hash = FileSharingLib::createHash();
             $check = FileSharingLib::createCheck($hash);
             $source = str_replace($cx->getWebsiteOffsetPath(), '', $_GET["path"]) . $_GET["file"];
             $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `hash`, `check`) VALUES ('" . contrexx_raw2db($source) . "', '" . contrexx_raw2db($source) . "', '" . contrexx_raw2db($hash) . "', '" . contrexx_raw2db($check) . "')");
         }
         $existing = !$existing;
     }
     if ($existing) {
         $this->_objTpl->setVariable(array('FILE_STATUS' => $_ARRAYLANG["TXT_FILESHARING_SHARED"], 'FILE_STATUS_SWITCH' => $_ARRAYLANG["TXT_FILESHARING_STOP_SHARING"], 'FILE_STATUS_SWITCH_HREF' => 'index.php?cmd=Media&amp;archive=FileSharing&amp;act=filesharing&amp;path=' . $_GET["path"] . '&amp;file=' . $_GET["file"] . '&amp;switch=1'));
         $this->_objTpl->touchBlock('shared');
     } else {
         $this->_objTpl->setVariable(array('FILE_STATUS' => $_ARRAYLANG["TXT_FILESHARING_NOT_SHARED"], 'FILE_STATUS_SWITCH' => $_ARRAYLANG["TXT_FILESHARING_START_SHARING"], 'FILE_STATUS_SWITCH_HREF' => 'index.php?cmd=Media&amp;archive=FileSharing&amp;act=filesharing&amp;path=' . $_GET["path"] . '&amp;file=' . $_GET["file"] . '&amp;switch=1'));
         $this->_objTpl->hideBlock('shared');
     }
     if ($_POST["shareFiles"]) {
         $emails = array();
         foreach (preg_split('/[;,\\s]+/', $_POST["email"]) as $email) {
             if (\FWValidator::isEmail($email)) {
                 $emails[] = contrexx_input2raw($email);
             }
         }
         if (count($emails) > 0) {
             FileSharingLib::sendMail($objResult->fields["id"], $_POST["subject"], $emails, $_POST["message"]);
         }
     } elseif ($_POST["saveExpiration"]) {
         if ($_POST["expiration"]) {
             $objDatabase->Execute("UPDATE " . DBPREFIX . "module_filesharing SET `expiration_date` = NULL WHERE `id` = " . $objResult->fields["id"]);
         } else {
             $objDatabase->Execute("UPDATE " . DBPREFIX . "module_filesharing SET `expiration_date` = '" . date('Y-m-d H:i:s', strtotime($_POST["expirationDate"])) . "' WHERE `id` = " . $objResult->fields["id"]);
         }
     }
     $objResult = $objDatabase->Execute("SELECT `id`, `hash`, `check`, `expiration_date` FROM " . DBPREFIX . "module_filesharing WHERE `source` = '" . contrexx_raw2db($file) . "'");
     $this->_objTpl->setVariable(array('FORM_ACTION' => 'index.php?cmd=Media&amp;archive=FileSharing&amp;act=filesharing&amp;path=' . $_GET["path"] . '&amp;file=' . $_GET["file"], 'FORM_METHOD' => 'POST', 'FILESHARING_INFO' => $_ARRAYLANG['TXT_FILESHARING_INFO'], 'FILESHARING_LINK_BACK_HREF' => 'index.php?cmd=Media&amp;archive=FileSharing&amp;path=' . $_GET["path"], 'FILESHARING_LINK_BACK' => $_ARRAYLANG['TXT_FILESHARING_LINK_BACK'], 'FILESHARING_DOWNLOAD_LINK' => $_ARRAYLANG['TXT_FILESHARING_DOWNLOAD_LINK'], 'FILE_DOWNLOAD_LINK_HREF' => FileSharingLib::getDownloadLink($objResult->fields["id"]), 'FILE_DELETE_LINK_HREF' => FileSharingLib::getDeleteLink($objResult->fields["id"]), 'FILESHARING_DELETE_LINK' => $_ARRAYLANG['TXT_FILESHARING_DELETE_LINK'], 'FILESHARING_STATUS' => $_ARRAYLANG['TXT_FILESHARING_STATUS'], 'FILESHARING_EXPIRATION' => $_ARRAYLANG['TXT_FILESHARING_EXPIRATION'], 'FILESHARING_NEVER' => $_ARRAYLANG['TXT_FILESHARING_NEVER'], 'FILESHARING_EXPIRATION_CHECKED' => htmlentities($objResult->fields["expiration_date"] == NULL ? 'checked="checked"' : '', ENT_QUOTES, CONTREXX_CHARSET), 'FILESHARING_EXPIRATION_DATE' => htmlentities($objResult->fields["expiration_date"] != NULL ? date('d.m.Y H:i', strtotime($objResult->fields["expiration_date"])) : date('d.m.Y H:i', time() + 3600 * 24 * 7), ENT_QUOTES, CONTREXX_CHARSET), 'FILESHARING_SEND_MAIL' => $_ARRAYLANG['TXT_FILESHARING_SEND_MAIL'], 'FILESHARING_EMAIL' => $_ARRAYLANG["TXT_FILESHARING_EMAIL"], 'FILESHARING_EMAIL_INFO' => $_ARRAYLANG["TXT_FILESHARING_EMAIL_INFO"], 'FILESHARING_SUBJECT' => $_ARRAYLANG["TXT_FILESHARING_SUBJECT"], 'FILESHARING_SUBJECT_INFO' => $_ARRAYLANG["TXT_FILESHARING_SUBJECT_INFO"], 'FILESHARING_MESSAGE' => $_ARRAYLANG["TXT_FILESHARING_MESSAGE"], 'FILESHARING_MESSAGE_INFO' => $_ARRAYLANG["TXT_FILESHARING_MESSAGE_INFO"], 'FILESHARING_SEND' => $_ARRAYLANG["TXT_FILESHARING_SEND"], 'FILESHARING_SAVE' => $_ARRAYLANG["TXT_FILESHARING_SAVE"], 'TXT_CORE_MAILTEMPLATE_NOTE_TO' => $_ARRAYLANG['TXT_CORE_MAILTEMPLATE_NOTE_TO']));
 }
Exemple #20
0
 public static function get($prop)
 {
     switch ($prop) {
         case 'em':
             return \Cx\Core\Core\Controller\Cx::instanciate()->getDb()->getEntityManager();
             break;
         case 'cx':
             if (!isset(self::$props[$prop]) && class_exists('\\Cx\\Core\\Core\\Controller\\Cx')) {
                 return \Cx\Core\Core\Controller\Cx::instanciate();
             }
         default:
             if (isset(self::$props[$prop])) {
                 return self::$props[$prop];
             }
             break;
     }
     return null;
 }
Exemple #21
0
 private function __construct($config)
 {
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $sessionObj = $cx->getComponent('Session')->getSession();
     // TODO: move to basic configuration screen (/cadmin/index.php?cmd=settings)
     $captchaConfig = array('ReCaptcha' => array('domains' => array('localhost' => array('public_key' => '6LeiusgSAAAAACPI2stz_Qh2fVC1reRUxJuqzf7h', 'private_key' => '6LeiusgSAAAAAABv3CW65svwgRMqFfTiC5NTOzOh'))));
     $config['coreCaptchaLib'] = '';
     $config['coreCaptchaLibConfig'] = json_encode($captchaConfig);
     switch ($config['coreCaptchaLib']) {
         case 'ReCaptcha':
             $this->objCaptcha = new ReCaptcha($config);
             break;
         case 'contrexx':
         default:
             $this->objCaptcha = new ContrexxCaptcha($config);
             break;
     }
 }
 /**
  * PHP5 constructor
  *
  * @global     object    $objTemplate
  * @global    array    $_ARRAYLANG
  */
 function __construct()
 {
     global $objTemplate, $_ARRAYLANG, $objInit;
     $this->objTpl = new \Cx\Core\Html\Sigma(ASCMS_CORE_MODULE_PATH . '/Cache/View/Template/Backend');
     $langData = $objInit->loadLanguageData('Cache');
     \Cx\Core\Csrf\Controller\Csrf::add_placeholder($this->objTpl);
     $this->objTpl->setErrorHandling(PEAR_ERROR_DIE);
     $this->arrSettings = $this->getSettings();
     $this->objSettings = new \Cx\Core\Config\Controller\Config();
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     if (is_dir($cx->getWebsiteCachePath())) {
         if (is_writable($cx->getWebsiteCachePath())) {
             $this->strCachePath = $cx->getWebsiteCachePath() . '/';
         } else {
             $objTemplate->SetVariable('CONTENT_STATUS_MESSAGE', $_ARRAYLANG['TXT_CACHE_ERR_NOTWRITABLE'] . $cx->getWebsiteCachePath());
         }
     } else {
         $objTemplate->SetVariable('CONTENT_STATUS_MESSAGE', $_ARRAYLANG['TXT_CACHE_ERR_NOTEXIST'] . $cx->getWebsiteCachePath());
     }
     parent::__construct();
 }
 public function postUpdate($eventArgs)
 {
     $this->writeXmlSitemap($eventArgs);
     // drop complete cache if active or visible flag changed
     // or if navigation title, navigation CSS name or slug changed:
     if ($this->lastPreUpdateChangeset && (isset($this->lastPreUpdateChangeset['active']) || isset($this->lastPreUpdateChangeset['display']) || isset($this->lastPreUpdateChangeset['slug']) || isset($this->lastPreUpdateChangeset['cssNavName']) || isset($this->lastPreUpdateChangeset['title']))) {
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         $cx->getComponent('Cache')->clearCache();
     }
 }
 /**
  * notify the staffs regarding the account modification of a contact
  *
  * @param Integer $customerId    customer id
  * @param String  $first_name customer first name
  * @param String  $last_name customer last name
  *
  * @access public
  * @global object $objTemplate
  * @global array  $_ARRAYLANG
  *
  * @return null
  */
 public function notifyStaffOnContactAccModification($customerId = 0, $first_name = '', $last_name = '', $gender = 0)
 {
     global $objDatabase, $_ARRAYLANG;
     if (empty($customerId)) {
         return false;
     }
     $objFWUser = \FWUser::getFWUserObject();
     $settings = $this->getSettings();
     $resources = $this->getResources($settings['emp_default_user_group']);
     $customer_name = $first_name . " " . $last_name;
     $contact_gender = $gender == 1 ? "gender_female" : ($gender == 2 ? "gender_male" : 'gender_undefined');
     $emailIds = array();
     foreach ($resources as $key => $value) {
         $emailIds[] = $value['email'];
     }
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     foreach ($emailIds as $emails) {
         if (!empty($emails)) {
             $objUsers = $objFWUser->objUser->getUsers($filter = array('email' => addslashes($emails)));
             $info['substitution'] = array('CRM_ASSIGNED_USER_NAME' => contrexx_raw2xhtml(\FWUser::getParsedUserTitle($objUsers->getId())), 'CRM_ASSIGNED_USER_EMAIL' => $emails, 'CRM_CONTACT_FIRSTNAME' => contrexx_raw2xhtml($first_name), 'CRM_CONTACT_LASTNAME' => contrexx_raw2xhtml($last_name), 'CRM_CONTACT_GENDER' => contrexx_raw2xhtml($contact_gender), 'CRM_DOMAIN' => ASCMS_PROTOCOL . "://{$_SERVER['HTTP_HOST']}" . $cx->getCodeBaseOffsetPath(), 'CRM_CONTACT_DETAILS_URL' => ASCMS_PROTOCOL . "://{$_SERVER['HTTP_HOST']}" . $cx->getCodeBaseOffsetPath() . $cx->getBackendFolderName() . "/index.php?cmd=" . $this->moduleName . "&act=customers&tpl=showcustdetail&id={$customerId}", 'CRM_CONTACT_DETAILS_LINK' => "<a href='" . ASCMS_PROTOCOL . "://{$_SERVER['HTTP_HOST']}" . $cx->getCodeBaseOffsetPath() . $cx->getBackendFolderName() . "/index.php?cmd=" . $this->moduleName . "&act=customers&tpl=showcustdetail&id={$customerId}'>" . $customer_name . "</a>");
             //setting email template lang id
             $availableMailTempLangAry = $this->getActiveEmailTemLangId('Crm', CRM_EVENT_ON_ACCOUNT_UPDATED);
             $availableLangId = $this->getEmailTempLang($availableMailTempLangAry, $emails);
             $info['lang_id'] = $availableLangId;
             $dispatcher = CrmEventDispatcher::getInstance();
             $dispatcher->triggerEvent(CRM_EVENT_ON_ACCOUNT_UPDATED, null, $info);
         }
     }
 }
Exemple #25
0
/**
 * Adds slashes to the given raw string or array thereof for insertion
 * into the database.
 * @param   mixed     $raw      The raw string or array
 * @return  mixed               The slashed string or array
 */
function contrexx_raw2db($raw)
{
    if (is_array($raw)) {
        $arr = array();
        foreach ($raw as $i => $_raw) {
            $arr[$i] = contrexx_raw2db($_raw);
        }
        return $arr;
    }
    $cx = \Cx\Core\Core\Controller\Cx::instanciate();
    $db = $cx->getDb();
    if (!isset($db)) {
        throw new \Cx\Core\Model\DbException('Database not yet initialized!');
    }
    $pdo = $db->getPdoConnection();
    $rawQuoted = $pdo->quote($raw);
    //addslashes did not add quotes, but pdo:quote does
    //we remove the quotes so we do not have to change all the queries
    if (strpos($rawQuoted, '\'') === 0 && substr($rawQuoted, -1) === '\'') {
        $rawQuoted = substr($rawQuoted, 1, -1);
    }
    return $rawQuoted;
}
 /**
  * Overview Media Data
  *
  * @global     array     $_ARRAYLANG
  * @global     array     $_CONFIG
  * @global     array     $_CORELANG
  * @return    string    parsed content
  */
 function _overviewMedia()
 {
     global $_ARRAYLANG, $_CONFIG, $_CORELANG, $objDatabase;
     \JS::activate('shadowbox');
     $this->_objTpl->loadTemplateFile('module_media.html', true, true);
     switch ($this->archive) {
         case 'themes':
             $this->pageTitle = $_ARRAYLANG['TXT_MEDIA_LAYOUT'];
             break;
         case 'content':
             $this->pageTitle = $_ARRAYLANG['TXT_IMAGE_ADMINISTRATION'];
             break;
         case 'Contact':
             $this->pageTitle = $_ARRAYLANG['TXT_FILE_UPLOADS'];
             break;
         case 'attach':
         case 'Access':
         case 'Blog':
         case 'Calendar':
         case 'Downloads':
         case 'Gallery':
         case 'MediaDir':
         case 'Podcast':
         case 'Shop':
             $archives = array('attach' => 'TXT_FILE_UPLOADS', 'Shop' => 'TXT_IMAGE_SHOP', 'Gallery' => 'TXT_GALLERY_TITLE', 'Access' => 'TXT_USER_ADMINISTRATION', 'MediaDir' => 'TXT_MEDIADIR_MODULE', 'Downloads' => 'TXT_DOWNLOADS', 'Calendar' => 'TXT_CALENDAR', 'Podcast' => 'TXT_PODCAST', 'Blog' => 'TXT_BLOG_MODULE');
             $moduleMatchTable = array('attach' => 'core');
             $subnavigation = '
                 <div id="subnavbar_level2">
                     <ul>';
             $license = \Cx\Core_Modules\License\License::getCached($_CONFIG, $objDatabase);
             $license->check();
             foreach ($archives as $archive => $txtKey) {
                 $moduleName = $archive;
                 if (isset($moduleMatchTable[$archive])) {
                     $moduleName = $moduleMatchTable[$archive];
                 }
                 if (!$license->isInLegalComponents($moduleName)) {
                     \DBG::msg('Module "' . $archive . '" is deactivated');
                     continue;
                 }
                 $subnavigation .= '
                         <li><a href="index.php?cmd=Media&amp;archive=' . $archive . '" class="' . ($this->archive == $archive ? 'active' : '') . '">' . $_ARRAYLANG[$txtKey] . '</a></li>';
             }
             $subnavigation .= '
                     </ul>
                 </div>';
             $this->_objTpl->setVariable('CONTENT_SUBNAVIGATION', $subnavigation);
         default:
             $this->pageTitle = $_ARRAYLANG['TXT_MEDIA_OVERVIEW'];
             if ($this->archive == "FileSharing") {
                 \Cx\Modules\FileSharing\Controller\FileSharingLib::cleanUp();
             }
             break;
     }
     // cut, copy and paste session
     if (isset($_SESSION['mediaCutFile'])) {
         $tmpArray = array();
         foreach ($_SESSION['mediaCutFile'][2] as $tmp) {
             if (file_exists($_SESSION['mediaCutFile'][0] . $tmp)) {
                 $tmpArray[] = $tmp;
             }
         }
         if (count($tmpArray) > 0) {
             $_SESSION['mediaCutFile'][0] = $_SESSION['mediaCutFile'][0];
             $_SESSION['mediaCutFile'][1] = $_SESSION['mediaCutFile'][1];
             $_SESSION['mediaCutFile'][2] = $tmpArray;
         } else {
             unset($_SESSION['mediaCutFile']);
         }
     }
     if (isset($_SESSION['mediaCopyFile'])) {
         $tmpArray = array();
         foreach ($_SESSION['mediaCopyFile'][2] as $tmp) {
             if (file_exists($_SESSION['mediaCopyFile'][0] . $tmp)) {
                 $tmpArray[] = $tmp;
             }
         }
         if (count($tmpArray) > 0) {
             $_SESSION['mediaCopyFile'][0] = $_SESSION['mediaCopyFile'][0];
             $_SESSION['mediaCopyFile'][1] = $_SESSION['mediaCopyFile'][1];
             $_SESSION['mediaCopyFile'][2] = $tmpArray;
         } else {
             unset($_SESSION['mediaCopyFile']);
         }
     }
     // tree navigation
     $tmp = $this->arrWebPaths[$this->archive];
     if (substr($this->webPath, 0, strlen($tmp)) == $tmp) {
         $this->_objTpl->setVariable(array('MEDIA_TREE_NAV_MAIN' => 'http://' . $_SERVER['HTTP_HOST'] . $this->arrWebPaths[$this->archive], 'MEDIA_TREE_NAV_MAIN_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->arrWebPaths[$this->archive]));
         if (strlen($this->webPath) != strlen($tmp)) {
             $tmpPath = substr($this->webPath, -(strlen($this->webPath) - strlen($tmp)));
             $tmpPath = explode('/', $tmpPath);
             $tmpLink = '';
             foreach ($tmpPath as $path) {
                 if (!empty($path)) {
                     $tmpLink .= $path . '/';
                     $this->_objTpl->setVariable(array('MEDIA_TREE_NAV_DIR' => $path, 'MEDIA_TREE_NAV_DIR_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->arrWebPaths[$this->archive] . $tmpLink));
                     $this->_objTpl->parse('mediaTreeNavigation');
                 }
             }
         }
     }
     //data we want to remember for handling the uploaded files
     $data = array('path' => $this->path, 'webPath' => $this->webPath);
     $uploader = new \Cx\Core_Modules\Uploader\Model\Entity\Uploader();
     $uploader->setCallback('mediaCallbackJs');
     $uploader->setFinishedCallback(array(ASCMS_CORE_MODULE_PATH . '/Media/Controller/MediaLibrary.class.php', '\\Cx\\Core_modules\\Media\\Controller\\MediaLibrary', 'uploadFinished'));
     $uploader->setOptions(array('id' => 'media_browse_button', 'type' => 'button'));
     $uploader->setData($data);
     $this->_objTpl->setVariable('MEDIA_UPLOADER_BUTTON', $uploader->getXHtml($_ARRAYLANG['TXT_MEDIA_UPLOAD_FILES']));
     //end of uploader button handling
     //check if a finished upload caused reloading of the page.
     //if yes, we know the added files and want to highlight them
     if (!empty($_GET['highlightUploadId'])) {
         $key = 'media_upload_files_' . $_GET['highlightUploadId'];
         if (isset($_SESSION[$key])) {
             $sessionHighlightCandidates = $_SESSION[$key]->toArray();
             //an array with the filenames, set in mediaLib::uploadFinished
         }
         //clean up session; we do only highlight once
         unset($_SESSION[$key]);
         if (is_array($sessionHighlightCandidates)) {
             //make sure we don't cause any unexpected behaviour if we lost the session data
             $this->highlightName = $sessionHighlightCandidates;
         }
     }
     // Check if an image has been edited.
     // If yes, we know the edited file and want to highlight them.
     if (!empty($_GET['editedImage'])) {
         \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($this->path . $_GET['editedImage'], true);
         $this->highlightName[] = $_GET['editedImage'];
     }
     // media directory tree
     $i = 0;
     $dirTree = $this->_dirTree($this->path);
     $dirTree = $this->_sortDirTree($dirTree);
     foreach (array_keys($dirTree) as $key) {
         if (isset($dirTree[$key]['icon']) && is_array($dirTree[$key]['icon'])) {
             for ($x = 0; $x < count($dirTree[$key]['icon']); $x++) {
                 $fileName = $dirTree[$key]['name'][$x];
                 if (MediaLibrary::isIllegalFileName($fileName)) {
                     continue;
                 }
                 // colors
                 $class = $i % 2 ? 'row2' : 'row1';
                 if (in_array($fileName, $this->highlightName)) {
                     $class .= '" style="background-color: ' . $this->highlightColor . ';';
                 }
                 if (isset($_SESSION['mediaCutFile']) && !empty($_SESSION['mediaCutFile'])) {
                     if ($this->webPath == $_SESSION['mediaCutFile'][1] && in_array($fileName, $_SESSION['mediaCutFile'][2])) {
                         $class .= '" style="background-color: ' . $this->highlightCCColor . ';';
                     }
                 }
                 if (isset($_SESSION['mediaCopyFile']) && !empty($_SESSION['mediaCopyFile'])) {
                     if ($this->webPath == $_SESSION['mediaCopyFile'][1] && in_array($fileName, $_SESSION['mediaCopyFile'][2])) {
                         $class .= '" style="background-color: ' . $this->highlightCCColor . ';';
                     }
                 }
                 $this->_objTpl->setVariable(array('MEDIA_DIR_TREE_ROW' => $class, 'MEDIA_FILE_ICON' => $dirTree[$key]['icon'][$x], 'MEDIA_FILE_NAME' => $fileName, 'MEDIA_FILE_SIZE' => $this->_formatSize($dirTree[$key]['size'][$x]), 'MEDIA_FILE_TYPE' => $this->_formatType($dirTree[$key]['type'][$x]), 'MEDIA_FILE_DATE' => $this->_formatDate($dirTree[$key]['date'][$x]), 'MEDIA_FILE_PERM' => $this->_formatPerm($dirTree[$key]['perm'][$x], $key)));
                 // creates link
                 if ($key == 'dir') {
                     $tmpHref = 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->webPath . $fileName . '/';
                 } elseif ($key == 'file') {
                     if ($this->_isImage($this->path . $fileName)) {
                         $tmpHref = 'javascript:expandcontent(\'preview_' . $fileName . '\');';
                     } else {
                         $tmpHref = 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=download&amp;path=' . $this->webPath . '&amp;file=' . $fileName;
                     }
                 }
                 $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_HREF' => $tmpHref));
                 // show thumbnail
                 if ($this->_isImage($this->path . $fileName)) {
                     // make thumbnail if it doesn't exist
                     $tmpSize = @getimagesize($this->path . $fileName);
                     $thumbnails = \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($this->path . $fileName);
                     $thumb = $this->webPath . $thumbnails[0];
                     if (in_array($fileName, $this->highlightName)) {
                         $thumb .= '?lastAccess=' . fileatime($this->path . $fileName);
                     }
                     $this->_objTpl->setVariable(array('MEDIA_FILE_NAME_SIZE' => $tmpSize[0] . ' x ' . $tmpSize[1], 'MEDIA_FILE_NAME_PRE' => 'preview_' . $fileName, 'MEDIA_FILE_NAME_IMG_HREF' => $this->webPath . $fileName, 'MEDIA_FILE_NAME_IMG_SRC' => $thumb, 'MEDIA_FILE_NAME_IMG_SIZE' => $thumbnails[0]['size']));
                     $this->_objTpl->parse('mediaShowThumbnail');
                     $this->_objTpl->setVariable(array('MEDIA_FILE_EDIT_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=edit&amp;path=' . $this->webPath . '&amp;file=' . $fileName, 'MEDIA_EDIT' => $_ARRAYLANG['TXT_MEDIA_EDIT']));
                     $this->_objTpl->parse('mediaImageEdit');
                 }
                 $this->_objTpl->setVariable(array('MEDIA_FILE_RENAME_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=rename&amp;path=' . $this->webPath . '&amp;file=' . $fileName, 'MEDIA_RENAME' => $_ARRAYLANG['TXT_MEDIA_RENAME'], 'MEDIA_FILE_DELETE_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=delete&amp;path=' . $this->webPath . '&amp;file=' . $fileName, 'MEDIA_DELETE' => $_ARRAYLANG['TXT_MEDIA_DELETE'], 'MEDIA_FILE_FILESHARING_HREF' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=filesharing&amp;path=' . $this->webPath . '&amp;file=' . $fileName, 'MEDIA_FILESHARING' => $_ARRAYLANG['TXT_FILESHARING_MODULE'], 'MEDIA_FILESHARING_STATE' => \Cx\Modules\FileSharing\Controller\FileSharingLib::isShared(null, (isset($_GET['path']) ? $_GET['path'] : ASCMS_FILESHARING_WEB_PATH . '/') . $fileName) ? '_green' : '_red'));
                 if ($this->archive == "FileSharing" && !is_dir($this->path . $fileName)) {
                     $this->_objTpl->parse('mediaFilesharing');
                 } else {
                     $this->_objTpl->hideBlock('mediaFilesharing');
                 }
                 $this->_objTpl->parse('mediaDirectoryTree');
                 $i++;
             }
         }
     }
     // empty dir or php safe mode restriction
     if ($i == 0 || !@opendir($this->path)) {
         $tmpMessage = $_ARRAYLANG['TXT_MEDIA_DIR_EMPTY'];
         if (!@opendir($this->path)) {
             $tmpMessage = 'PHP Safe Mode Restriction!';
         }
         $this->_objTpl->setVariable(array('TXT_MEDIA_DIR_EMPTY' => $tmpMessage, 'MEDIA_SELECT_STATUS' => ' disabled'));
         $this->_objTpl->parse('mediaEmptyDirectory');
     } else {
         // not empty dir (select action)
         $this->_objTpl->setVariable(array('TXT_SELECT_ALL' => $_CORELANG['TXT_SELECT_ALL'], 'TXT_DESELECT_ALL' => $_CORELANG['TXT_DESELECT_ALL'], 'TXT_MEDIA_SELECT_ACTION' => $_ARRAYLANG['TXT_MEDIA_SELECT_ACTION'], 'TXT_MEDIA_CUT' => $_ARRAYLANG['TXT_MEDIA_CUT'], 'TXT_MEDIA_COPY' => $_ARRAYLANG['TXT_MEDIA_COPY'], 'TXT_MEDIA_DELETE' => $_ARRAYLANG['TXT_MEDIA_DELETE']));
         $this->_objTpl->parse('mediaSelectAction');
         $this->_objTpl->setVariable('MEDIA_ARCHIVE', $this->archive);
     }
     // paste media
     if (isset($_SESSION['mediaCutFile']) or isset($_SESSION['mediaCopyFile'])) {
         $this->_objTpl->setVariable(array('MEDIDA_PASTE_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=paste&amp;path=' . $this->webPath, 'TXT_MEDIA_PASTE' => $_ARRAYLANG['TXT_MEDIA_PASTE']));
         $this->_objTpl->parse('mediaActionPaste');
     }
     // parse variables
     $tmpHref = 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;path=' . $this->webPath;
     $tmpIcon = $this->_sortingIcons();
     $tmpClass = $this->_sortingClass();
     $this->_objTpl->setVariable(array('TXT_MEDIA_CHECK_NAME' => $_ARRAYLANG['TXT_MEDIA_CHECK_NAME'], 'TXT_MEDIA_CONFIRM_DELETE_2' => $_ARRAYLANG['TXT_MEDIA_CONFIRM_DELETE_2'], 'MEDIA_DO_ACTION_PATH' => $this->webPath, 'TXT_MEDIA_MAKE_SELECTION' => $_ARRAYLANG['TXT_MEDIA_MAKE_SELECTION'], 'TXT_MEDIA_SELECT_UPLOAD_FILE' => $_ARRAYLANG['TXT_MEDIA_SELECT_UPLOAD_FILE'], 'MEDIA_JAVA_SCRIPT_PREVIEW' => $this->_getJavaScriptCodePreview()));
     $this->_objTpl->setVariable(array('TXT_MEDIA_NEW_DIRECTORY' => $_ARRAYLANG['TXT_MEDIA_NEW_DIRECTORY'], 'MEDIA_CREATE_DIR_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=newDir&amp;path=' . $this->webPath, 'TXT_MEDIA_NAME' => $_ARRAYLANG['TXT_MEDIA_NAME'], 'TXT_MEDIA_CREATE' => $_ARRAYLANG['TXT_MEDIA_CREATE']));
     $this->_objTpl->setVariable(array('TXT_MEDIA_UPLOAD_FILES' => $_ARRAYLANG['TXT_MEDIA_UPLOAD_FILES'], 'MEDIA_UPLOAD_FILES_ACTION' => 'index.php?cmd=Media&amp;archive=' . $this->archive . '&amp;act=upload&amp;path=' . $this->webPath, 'TXT_MEDIA_UPLOAD' => $_ARRAYLANG['TXT_MEDIA_UPLOAD'], 'TXT_MEDIA_FORCE_OVERWRITE' => $_ARRAYLANG['TXT_MEDIA_FORCE_OVERWRITE']));
     $this->_objTpl->setVariable(array('MEDIA_NAME_HREF' => $tmpHref . '&amp;sort=name&amp;sort_desc=' . ($this->sortBy == 'name' && !$this->sortDesc), 'MEDIA_SIZE_HREF' => $tmpHref . '&amp;sort=size&amp;sort_desc=' . ($this->sortBy == 'size' && !$this->sortDesc), 'MEDIA_TYPE_HREF' => $tmpHref . '&amp;sort=type&amp;sort_desc=' . ($this->sortBy == 'type' && !$this->sortDesc), 'MEDIA_DATE_HREF' => $tmpHref . '&amp;sort=date&amp;sort_desc=' . ($this->sortBy == 'date' && !$this->sortDesc), 'MEDIA_PERM_HREF' => $tmpHref . '&amp;sort=perm&amp;sort_desc=' . ($this->sortBy == 'perm' && !$this->sortDesc), 'TXT_MEDIA_FILE_NAME' => $_ARRAYLANG['TXT_MEDIA_FILE_NAME'], 'TXT_MEDIA_FILE_SIZE' => $_ARRAYLANG['TXT_MEDIA_FILE_SIZE'], 'TXT_MEDIA_FILE_TYPE' => $_ARRAYLANG['TXT_MEDIA_FILE_TYPE'], 'TXT_MEDIA_FILE_DATE' => $_ARRAYLANG['TXT_MEDIA_FILE_DATE'], 'TXT_MEDIA_FILE_PERM' => $_ARRAYLANG['TXT_MEDIA_FILE_PERM'], 'TXT_MEDIA_FILE_FUNCTIONS' => $_ARRAYLANG['TXT_FUNCTIONS'], 'MEDIA_NAME_ICON' => isset($tmpIcon['name']) ? $tmpIcon['name'] : '', 'MEDIA_SIZE_ICON' => isset($tmpIcon['size']) ? $tmpIcon['size'] : '', 'MEDIA_TYPE_ICON' => isset($tmpIcon['type']) ? $tmpIcon['type'] : '', 'MEDIA_DATE_ICON' => isset($tmpIcon['date']) ? $tmpIcon['date'] : '', 'MEDIA_PERM_ICON' => isset($tmpIcon['perm']) ? $tmpIcon['perm'] : '', 'MEDIA_NAME_CLASS' => isset($tmpClass['name']) ? $tmpIcon['name'] : '', 'MEDIA_SIZE_CLASS' => isset($tmpClass['size']) ? $tmpIcon['size'] : '', 'MEDIA_TYPE_CLASS' => isset($tmpClass['type']) ? $tmpIcon['type'] : '', 'MEDIA_DATE_CLASS' => isset($tmpClass['date']) ? $tmpIcon['date'] : '', 'MEDIA_PERM_CLASS' => isset($tmpClass['perm']) ? $tmpIcon['perm'] : '', 'CSRF' => \Cx\Core\Csrf\Controller\Csrf::param()));
 }
 /**
  * This function is used to delete an entry
  *
  * @param string $entityWithNS class name including namespace
  * @access protected
  * @global array $_ARRAYLANG array containing the language variables
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  * @throws \Exception
  */
 protected function removeEntry($entityWithNS)
 {
     global $_ARRAYLANG;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $em = $cx->getDb()->getEntityManager();
     $deleteId = !empty($_GET['deleteid']) ? contrexx_input2raw($_GET['deleteid']) : '';
     $entityObject = $this->object->getEntry($deleteId);
     if (empty($entityObject)) {
         \Message::add($_ARRAYLANG['TXT_CORE_RECORD_NO_SUCH_ENTRY'], \Message::CLASS_ERROR);
         return;
     }
     $entityObj = $em->getClassMetadata($entityWithNS);
     $id = $entityObject[$entityObj->getSingleIdentifierFieldName()];
     //get primary key value
     // delete all n associated entries, because the are not longer used and we can delete the main entry only if we
     // have no more n associated entries
     $pageRepo = $em->getRepository($entityWithNS);
     $associationMappings = $entityObj->getAssociationMappings();
     foreach ($associationMappings as $mapping => $value) {
         // we only need to delete the n associated values, the single associated will be handled by doctrine itself
         if (!$entityObj->isCollectionValuedAssociation($mapping)) {
             continue;
         }
         $mainEntity = $pageRepo->find($id);
         $associatedEntities = $mainEntity->{'get' . preg_replace('/_([a-z])/', '\\1', ucfirst($mapping))}();
         foreach ($associatedEntities as $associatedEntity) {
             $em->remove($associatedEntity);
         }
     }
     if (!empty($id)) {
         $entityObj = $em->getRepository($entityWithNS)->find($id);
         if (!empty($entityObj)) {
             if ($entityObj instanceof \Cx\Core\Model\Model\Entity\YamlEntity) {
                 $ymlRepo = $em->getRepository($entityWithNS);
                 $ymlRepo->remove($entityObj);
                 $ymlRepo->flush();
             } else {
                 $em->remove($entityObj);
                 $em->flush();
             }
             \Message::add($_ARRAYLANG['TXT_CORE_RECORD_DELETED_SUCCESSFUL']);
         }
     }
     $actionUrl = clone $cx->getRequest()->getUrl();
     $actionUrl->setParam('deleteid', null);
     \Cx\Core\Csrf\Controller\Csrf::redirect($actionUrl);
 }
    function getJavascriptCheck()
    {
        $fieldName = $this->moduleNameLC . "Inputfield_";
        if (\Cx\Core\Core\Controller\Cx::instanciate()->getMode() == \Cx\Core\Core\Controller\Cx::MODE_BACKEND) {
            $hiddenField = "value_hidden = false";
        } else {
            $hiddenField = "value_hidden = document.getElementById('" . $fieldName . "' + field + '_0_hidden').value;";
        }
        $strJavascriptCheck = <<<EOF

            case 'file':
                value = document.getElementById('{$fieldName}' + field + '_0').value;
                {$hiddenField}
                if (value == "" && value_hidden == "" && isRequiredGlobal(inputFields[field][1], value)) {
                    isOk = false;
                    document.getElementById('{$fieldName}' + field + '_0').style.border = "#ff0000 1px solid";
                } else {
                    document.getElementById('{$fieldName}' + field + '_0').style.borderColor = '';
                }
                break;

EOF;
        return $strJavascriptCheck;
    }
 /**
  * Searches the content and returns an array that is built as needed by the search module.
  *
  * @param string $searchTerm
  *
  * @return array
  */
 public function searchResultsForSearchModule($searchTerm)
 {
     $em = \Env::get('cx')->getDb()->getEntityManager();
     $pageRepo = $em->getRepository('Cx\\Core\\ContentManager\\Model\\Entity\\Page');
     // only list results in case the associated page of the module is active
     $page = $pageRepo->findOneBy(array('module' => 'MediaDir', 'lang' => FRONTEND_LANG_ID, 'type' => \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION));
     //If page is not exists or page is inactive then return empty result
     if (!$page || !$page->isActive()) {
         return array();
     }
     //get the config site values
     \Cx\Core\Setting\Controller\Setting::init('Config', 'site', 'Yaml');
     $coreListProtectedPages = \Cx\Core\Setting\Controller\Setting::getValue('coreListProtectedPages', 'Config');
     $searchVisibleContentOnly = \Cx\Core\Setting\Controller\Setting::getValue('searchVisibleContentOnly', 'Config');
     //get the config otherConfigurations value
     \Cx\Core\Setting\Controller\Setting::init('Config', 'otherConfigurations', 'Yaml');
     $searchDescriptionLength = \Cx\Core\Setting\Controller\Setting::getValue('searchDescriptionLength', 'Config');
     $hasPageAccess = true;
     $isNotVisible = $searchVisibleContentOnly == 'on' && !$page->isVisible();
     if ($coreListProtectedPages == 'off' && $page->isFrontendProtected()) {
         $hasPageAccess = \Permission::checkAccess($page->getFrontendAccessId(), 'dynamic', true);
     }
     //If the page is invisible and frontend access is denied then return empty result
     if ($isNotVisible || !$hasPageAccess) {
         return array();
     }
     //get the media directory entry by the search term
     $entries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($this->moduleName);
     $entries->getEntries(null, null, null, $searchTerm);
     //if no entries found then return empty result
     if (empty($entries->arrEntries)) {
         return array();
     }
     $results = array();
     $formEntries = array();
     $defaultEntries = null;
     $objForm = new \Cx\Modules\MediaDir\Controller\MediaDirectoryForm(null, $this->moduleName);
     $numOfEntries = intval($entries->arrSettings['settingsPagingNumEntries']);
     foreach ($entries->arrEntries as $entry) {
         $pageUrlResult = null;
         $entryForm = $objForm->arrForms[$entry['entryFormId']];
         //Get the entry's link url
         //check the entry's form detail view exists if not,
         //check the entry's form overview exists if not,
         //check the default overview exists if not, dont show the corresponding entry in entry
         switch (true) {
             case $entries->checkPageCmd('detail' . $entry['entryFormId']):
                 $pageUrlResult = \Cx\Core\Routing\Url::fromModuleAndCmd($entries->moduleName, 'detail' . $entry['entryFormId'], FRONTEND_LANG_ID, array('eid' => $entry['entryId']));
                 break;
             case $pageCmdExists = $entries->checkPageCmd($entryForm['formCmd']):
             case $entries->checkPageCmd(''):
                 if ($pageCmdExists && !isset($formEntries[$entryForm['formCmd']])) {
                     $formEntries[$entryForm['formCmd']] = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($entries->moduleName);
                     $formEntries[$entryForm['formCmd']]->getEntries(null, null, null, null, null, null, 1, null, 'n', null, null, $entryForm['formId']);
                 }
                 if (!$pageCmdExists && !isset($defaultEntries)) {
                     $defaultEntries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry($entries->moduleName);
                     $defaultEntries->getEntries();
                 }
                 //get entry's form overview / default page paging position
                 $entriesPerPage = $numOfEntries;
                 if ($pageCmdExists) {
                     $entriesPerPage = !empty($entryForm['formEntriesPerPage']) ? $entryForm['formEntriesPerPage'] : $numOfEntries;
                 }
                 $pageCmd = $pageCmdExists ? $entryForm['formCmd'] : '';
                 $entryKeys = $pageCmdExists ? array_keys($formEntries[$entryForm['formCmd']]->arrEntries) : array_keys($defaultEntries->arrEntries);
                 $entryPos = array_search($entry['entryId'], $entryKeys);
                 $position = floor($entryPos / $entriesPerPage);
                 $pageUrlResult = \Cx\Core\Routing\Url::fromModuleAndCmd($entries->moduleName, $pageCmd, FRONTEND_LANG_ID, array('pos' => $position * $entriesPerPage));
                 break;
             default:
                 break;
         }
         //If page url is empty then dont show it in the result
         if (!$pageUrlResult) {
             continue;
         }
         //Get the search results title and content from the form context field 'title' and 'content'
         $title = current($entry['entryFields']);
         $content = '';
         $objInputfields = new MediaDirectoryInputfield($entry['entryFormId'], false, $entry['entryTranslationStatus'], $this->moduleName);
         $inputFields = $objInputfields->getInputfields();
         foreach ($inputFields as $arrInputfield) {
             $contextType = isset($arrInputfield['context_type']) ? $arrInputfield['context_type'] : '';
             if (!in_array($contextType, array('title', 'content'))) {
                 continue;
             }
             $strType = isset($arrInputfield['type_name']) ? $arrInputfield['type_name'] : '';
             $strInputfieldClass = "\\Cx\\Modules\\MediaDir\\Model\\Entity\\MediaDirectoryInputfield" . ucfirst($strType);
             try {
                 $objInputfield = safeNew($strInputfieldClass, $this->moduleName);
                 $arrTranslationStatus = contrexx_input2int($arrInputfield['type_multi_lang']) == 1 ? $entry['entryTranslationStatus'] : null;
                 $arrInputfieldContent = $objInputfield->getContent($entry['entryId'], $arrInputfield, $arrTranslationStatus);
                 if (\Cx\Core\Core\Controller\Cx::instanciate()->getMode() == \Cx\Core\Core\Controller\Cx::MODE_FRONTEND && \Cx\Core\Setting\Controller\Setting::getValue('blockStatus', 'Config')) {
                     $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE'] = preg_replace('/\\[\\[(BLOCK_[A-Z0-9_-]+)\\]\\]/', '{\\1}', $arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE']);
                     \Cx\Modules\Block\Controller\Block::setBlocks($arrInputfieldContent[$this->moduleLangVar . '_INPUTFIELD_VALUE'], \Cx\Core\Core\Controller\Cx::instanciate()->getPage());
                 }
             } catch (\Exception $e) {
                 \DBG::log($e->getMessage());
                 continue;
             }
             $inputFieldValue = $arrInputfieldContent[$this->moduleConstVar . '_INPUTFIELD_VALUE'];
             if (empty($inputFieldValue)) {
                 continue;
             }
             if ($contextType == 'title') {
                 $title = $inputFieldValue;
             } elseif ($contextType == 'content') {
                 $content = \Cx\Core_Modules\Search\Controller\Search::shortenSearchContent($inputFieldValue, $searchDescriptionLength);
             }
         }
         $results[] = array('Score' => 100, 'Title' => html_entity_decode(contrexx_strip_tags($title), ENT_QUOTES, CONTREXX_CHARSET), 'Content' => $content, 'Link' => $pageUrlResult->toString());
     }
     return $results;
 }
 /**
  * send a mail to the email with the message
  *
  * @static
  * @param integer $uploadId the upload id
  * @param string $subject the subject of the mail for the recipient
  * @param string $email the recipient's mail address
  * @param null|string $message the message for the recipient
  */
 public static function sendMail($uploadId, $subject, $emails, $message = null)
 {
     global $objDatabase, $_CONFIG;
     /**
      * get all file ids from the last upload
      */
     $objResult = $objDatabase->Execute("SELECT `id` FROM " . DBPREFIX . "module_filesharing WHERE `upload_id` = '" . intval($uploadId) . "'");
     if ($objResult !== false && $objResult->RecordCount() > 0) {
         while (!$objResult->EOF) {
             $files[] = $objResult->fields["id"];
             $objResult->MoveNext();
         }
     }
     if (!is_int($uploadId) && empty($files)) {
         $files[] = $uploadId;
     }
     /**
      * init mail data. Mail template, Mailsubject and PhpMailer
      */
     $objMail = $objDatabase->SelectLimit("SELECT `subject`, `content` FROM " . DBPREFIX . "module_filesharing_mail_template WHERE `lang_id` = " . FRONTEND_LANG_ID, 1, -1);
     $content = str_replace(array(']]', '[['), array('}', '{'), $objMail->fields["content"]);
     if (empty($subject)) {
         $subject = $objMail->fields["subject"];
     }
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     if (\Env::get('ClassLoader')->loadFile($cx->getCodeBaseLibraryPath() . '/phpmailer/class.phpmailer.php')) {
         $objMail = new \phpmailer();
         /**
          * Load mail template and parse it
          */
         $objTemplate = new \Cx\Core\Html\Sigma('.');
         $objTemplate->setErrorHandling(PEAR_ERROR_DIE);
         $objTemplate->setTemplate($content);
         $objTemplate->setVariable(array("DOMAIN" => $_CONFIG["domainUrl"], 'MESSAGE' => $message));
         if ($objTemplate->blockExists('filesharing_file')) {
             foreach ($files as $file) {
                 $objTemplate->setVariable(array('FILE_DOWNLOAD' => self::getDownloadLink($file)));
                 $objTemplate->parse('filesharing_file');
             }
         }
         if ($_CONFIG['coreSmtpServer'] > 0 && \Env::get('ClassLoader')->loadFile($cx->getCodeBaseCorePath() . '/SmtpSettings.class.php')) {
             if (($arrSmtp = SmtpSettings::getSmtpAccount($_CONFIG['coreSmtpServer'])) !== false) {
                 $objMail->IsSMTP();
                 $objMail->Host = $arrSmtp['hostname'];
                 $objMail->Port = $arrSmtp['port'];
                 $objMail->SMTPAuth = true;
                 $objMail->Username = $arrSmtp['username'];
                 $objMail->Password = $arrSmtp['password'];
             }
         }
         $objMail->CharSet = CONTREXX_CHARSET;
         $objMail->SetFrom($_CONFIG['coreAdminEmail'], $_CONFIG['coreGlobalPageTitle']);
         $objMail->Subject = $subject;
         $objMail->Body = $objTemplate->get();
         foreach ($emails as $email) {
             $objMail->AddAddress($email);
             $objMail->Send();
             $objMail->ClearAddresses();
         }
     }
 }