Example #1
0
 /**
  * Loops all backend modules, and builds a list of those that have an
  * api.php file in their engine.
  */
 protected function loadModules()
 {
     $modules = BackendModel::getModules();
     foreach ($modules as &$module) {
         // class names of the API file are always based on the name o/t module
         $className = 'Backend\\Modules\\' . $module . '\\Engine\\Api';
         if ($module == 'Core') {
             $className = 'Backend\\Core\\Engine\\Api';
         }
         /*
          * check if the api.php file exists for this module, and load it so our methods are
          * accessible by the Reflection API.
          */
         if (!class_exists($className)) {
             continue;
         }
         $methods = get_class_methods($className);
         // we will need the parameters + PHPDoc to generate our text fields
         foreach ($methods as $key => $method) {
             $methods[$key] = array('name' => $method, 'parameters' => $this->loadParameters($className, $method));
         }
         // properly format so an iteration can do the work for us
         $this->modules[] = array('name' => $module, 'methods' => $methods);
     }
 }
Example #2
0
 /**
  * Load the datagrid
  */
 private function loadDataGrid()
 {
     // init var
     $items = array();
     // get modules
     $modules = BackendModel::getModules();
     // loop modules
     foreach ($modules as $module) {
         // build class name
         $className = 'Backend\\Modules\\' . $module . '\\Engine\\Model';
         if ($module == 'Core') {
             $className = 'Backend\\Core\\Engine\\Model';
         }
         // check if the getByTag-method is available
         if (is_callable(array($className, 'getByTag'))) {
             // make the call and get the item
             $moduleItems = (array) call_user_func(array($className, 'getByTag'), $this->id);
             // loop items
             foreach ($moduleItems as $row) {
                 // check if needed fields are available
                 if (isset($row['url'], $row['name'], $row['module'])) {
                     // add
                     $items[] = array('module' => \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($row['module']))), 'name' => $row['name'], 'url' => $row['url']);
                 }
             }
         }
     }
     // create datagrid
     $this->dgUsage = new BackendDataGridArray($items);
     $this->dgUsage->setPaging(false);
     $this->dgUsage->setColumnsHidden(array('url'));
     $this->dgUsage->setHeaderLabels(array('name' => \SpoonFilter::ucfirst(BL::lbl('Title')), 'url' => ''));
     $this->dgUsage->setColumnURL('name', '[url]', \SpoonFilter::ucfirst(BL::lbl('Edit')));
     $this->dgUsage->addColumn('edit', null, \SpoonFilter::ucfirst(BL::lbl('Edit')), '[url]', BL::lbl('Edit'));
 }
Example #3
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $isGod = BackendAuthentication::getUser()->isGod();
     // get possible languages
     if ($isGod) {
         $possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
     } else {
         $possibleLanguages = BL::getWorkingLanguages();
     }
     // get parameters
     $language = \SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
     $module = \SpoonFilter::getPostValue('module', BackendModel::getModules(), null, 'string');
     $name = \SpoonFilter::getPostValue('name', null, null, 'string');
     $type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->getEnumValues('locale', 'type'), null, 'string');
     $application = \SpoonFilter::getPostValue('application', array('Backend', 'Frontend'), null, 'string');
     $value = \SpoonFilter::getPostValue('value', null, null, 'string');
     // validate values
     if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'Frontend' && $module != 'Core') {
         $error = BL::err('InvalidValue');
     }
     // in case this is a 'act' type, there are special rules concerning possible values
     if ($type == 'act' && !isset($error)) {
         if (urlencode($value) != CommonUri::getUrl($value)) {
             $error = BL::err('InvalidActionValue', $this->getModule());
         }
     }
     // no error?
     if (!isset($error)) {
         // build item
         $item['language'] = $language;
         $item['module'] = $module;
         $item['name'] = $name;
         $item['type'] = $type;
         $item['application'] = $application;
         $item['value'] = $value;
         $item['edited_on'] = BackendModel::getUTCDate();
         $item['user_id'] = BackendAuthentication::getUser()->getUserId();
         // does the translation exist?
         if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
             // add the id to the item
             $item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
             // update in db
             BackendLocaleModel::update($item);
         } else {
             // insert in db
             BackendLocaleModel::insert($item);
         }
         // output OK
         $this->output(self::OK);
     } else {
         $this->output(self::ERROR, null, $error);
     }
 }
Example #4
0
 /**
  * Get warnings for active modules
  *
  * @return array
  */
 public static function getWarnings()
 {
     // init vars
     $warnings = array();
     $installedModules = BackendModel::getModules();
     // loop modules
     foreach ($installedModules as $module) {
         // model class
         $class = 'Backend\\Modules\\' . $module . '\\Engine\\Model';
         if ($module == 'Core') {
             $class = 'Backend\\Core\\Engine\\Model';
         }
         // method exists
         if (is_callable(array($class, 'checkSettings'))) {
             // add possible warnings
             $warnings = array_merge($warnings, call_user_func(array($class, 'checkSettings')));
         }
     }
     // Multiple modules can return the same errors.
     $warnings = array_unique($warnings, SORT_REGULAR);
     return (array) $warnings;
 }
Example #5
0
 private function getAllowedModule()
 {
     // create filter with modules which may not be displayed
     $filter = array('Authentication', 'Error', 'Core');
     // get all modules
     $modules = array_diff(BackendModel::getModules(), $filter);
     $allowedModule = false;
     if (BackendAuthentication::isAllowedModule('Dashboard')) {
         $allowedModule = 'Dashboard';
     } else {
         foreach ($modules as $module) {
             if (BackendAuthentication::isAllowedModule($module)) {
                 $allowedModule = $module;
                 break;
             }
         }
     }
     return $allowedModule;
 }
Example #6
0
 /**
  * Load the data
  */
 private function loadData()
 {
     $modules = BackendModel::getModules();
     $userSequence = BackendAuthentication::getUser()->getSetting('dashboard_sequence');
     $fs = new Filesystem();
     // user sequence does not exist?
     if (!isset($userSequence)) {
         // get group ID of user
         $groupId = BackendAuthentication::getUser()->getGroupId();
         // get group preset
         $userSequence = BackendGroupsModel::getSetting($groupId, 'dashboard_sequence');
     }
     // loop all modules
     foreach ($modules as $module) {
         // build pathName
         $pathName = BACKEND_MODULES_PATH . '/' . $module;
         // you have sufficient rights?
         if (BackendAuthentication::isAllowedModule($module) && $fs->exists($pathName . '/Widgets')) {
             $finder = new Finder();
             $finder->name('*.php');
             // loop widgets
             foreach ($finder->files()->in($pathName . '/Widgets') as $file) {
                 /** @ver $file \SplFileInfo */
                 $widgetName = $file->getBaseName('.php');
                 $className = 'Backend\\Modules\\' . $module . '\\Widgets\\' . $widgetName;
                 if ($module == 'Core') {
                     $className = 'Backend\\Core\\Widgets\\' . $widgetName;
                 }
                 if (!class_exists($className)) {
                     throw new BackendException('The widgetfile ' . $className . ' could not be found.');
                 }
                 // present?
                 $present = isset($userSequence[$module][$widgetName]['present']) ? $userSequence[$module][$widgetName]['present'] : false;
                 // if not present, continue
                 if (!$present) {
                     continue;
                 }
                 // create instance
                 /** @var $instance BackendBaseWidget */
                 $instance = new $className($this->getKernel());
                 // has rights
                 if (!$instance->isAllowed()) {
                     continue;
                 }
                 // hidden?
                 $hidden = isset($userSequence[$module][$widgetName]['hidden']) ? $userSequence[$module][$widgetName]['hidden'] : false;
                 // execute instance if it is not hidden
                 if (!$hidden) {
                     $instance->execute();
                 }
                 // user sequence provided?
                 $column = isset($userSequence[$module][$widgetName]['column']) ? $userSequence[$module][$widgetName]['column'] : $instance->getColumn();
                 $position = isset($userSequence[$module][$widgetName]['position']) ? $userSequence[$module][$widgetName]['position'] : $instance->getPosition();
                 $title = \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(\SpoonFilter::toCamelCase($widgetName));
                 $templatePath = $instance->getTemplatePath();
                 // reset template path
                 if ($templatePath == null) {
                     $templatePath = BACKEND_PATH . '/Modules/' . $module . '/Layout/Widgets/' . $widgetName . '.tpl';
                 }
                 // build item
                 $item = array('template' => $templatePath, 'module' => $module, 'widget' => $widgetName, 'title' => $title, 'hidden' => $hidden);
                 // add on new position if no position is set or if the position is already used
                 if ($position === null || isset($this->widgets[$column][$position])) {
                     $this->widgets[$column][] = $item;
                 } else {
                     // add on requested position
                     $this->widgets[$column][$position] = $item;
                 }
             }
         }
     }
     // sort the widgets
     foreach ($this->widgets as &$column) {
         ksort($column);
     }
 }
Example #7
0
 /**
  * Is the given module allowed for the current user
  *
  * @param string $module The module to check for.
  *
  * @return bool
  */
 public static function isAllowedModule($module)
 {
     $modules = BackendModel::getModules();
     $alwaysAllowed = array('Core', 'Error', 'Authentication');
     $module = \SpoonFilter::toCamelCase((string) $module);
     // is this module a module that doesn't require user level authentication?
     if (in_array($module, $alwaysAllowed)) {
         return true;
     }
     // users that aren't logged in can only access always allowed items
     if (!self::isLoggedIn()) {
         return false;
     }
     // module is active and God user, good enough
     if (in_array($module, $modules) && self::getUser()->isGod()) {
         return true;
     }
     // do we already know something?
     if (empty(self::$allowedModules)) {
         // init var
         $db = BackendModel::get('database');
         // get allowed modules
         $allowedModules = $db->getColumn('SELECT DISTINCT grm.module
              FROM users_sessions AS us
              INNER JOIN users AS u ON us.user_id = u.id
              INNER JOIN users_groups AS ug ON u.id = ug.user_id
              INNER JOIN groups_rights_modules AS grm ON ug.group_id = grm.group_id
              WHERE us.session_id = ? AND us.secret_key = ?', array(\SpoonSession::getSessionId(), \SpoonSession::get('backend_secret_key')));
         // add all modules
         foreach ($allowedModules as $row) {
             self::$allowedModules[$row] = true;
         }
     }
     // not available in our cache
     if (!isset(self::$allowedModules[$module])) {
         return false;
     } else {
         // return value that was stored in cache
         return self::$allowedModules[$module];
     }
 }
Example #8
0
 /**
  * Edit an index
  *
  * @param string $module   The module wherein will be searched.
  * @param int    $otherId  The id of the record.
  * @param array  $fields   A key/value pair of fields to index.
  * @param string $language The frontend language for this entry.
  */
 public static function saveIndex($module, $otherId, array $fields, $language = null)
 {
     // module exists?
     if (!in_array('Search', BackendModel::getModules())) {
         return;
     }
     // no fields?
     if (empty($fields)) {
         return;
     }
     // set language
     if (!$language) {
         $language = BL::getWorkingLanguage();
     }
     // get db
     $db = BackendModel::getContainer()->get('database');
     // insert search index
     foreach ($fields as $field => $value) {
         // reformat value
         $value = strip_tags((string) $value);
         // update search index
         $db->execute('INSERT INTO search_index (module, other_id, language, field, value, active)
              VALUES (?, ?, ?, ?, ?, ?)
              ON DUPLICATE KEY UPDATE value = ?, active = ?', array((string) $module, (int) $otherId, (string) $language, (string) $field, $value, 'Y', $value, 'Y'));
     }
     // invalidate the cache for search
     self::invalidateCache();
 }
Example #9
0
 /**
  * Get the locale that is used in the Frontend but doesn't exists.
  *
  * @param string $language The language to check.
  * @return array
  */
 public static function getNonExistingFrontendLocale($language)
 {
     $locale = array();
     $frontendModuleFiles = array();
     $installedModules = BackendModel::getModules();
     // pickup the Frontend module files
     $finder = new Finder();
     $finder->notPath('Cache')->name('*.php')->name('*.tpl')->name('*.js');
     // collect all files
     foreach ($finder->files()->in(FRONTEND_PATH) as $file) {
         // returns false if nothing found
         $module = self::getInbetweenStrings('Modules/', '/', $file->getPath());
         if ($module && !in_array($module, $installedModules)) {
             continue;
         }
         $filename = $file->getPath() . '/' . $file->getFilename();
         $frontendModuleFiles['Core'][$filename] = $file;
     }
     // Find the locale in files an sort them
     foreach ($frontendModuleFiles as $moduleName => $module) {
         $locale[$moduleName] = self::findLocaleInFiles($module);
     }
     // getAllFrontendDBLocale
     $oldLocale = self::getSortLocaleFrom('Frontend', $language);
     // filter the Foundlocale
     $nonExisting = array();
     foreach ($locale as $moduleName => &$module) {
         foreach ($module as $filename => &$file) {
             // extra filter for Core
             $file['locale'] = array_diff_key($file['locale'], $oldLocale['Core']);
             // output a converted array
             foreach ($file['locale'] as $localeName => $localeType) {
                 $key = $localeName;
                 $type = $localeType;
                 $nonExisting['Frontend' . $key . $type . $moduleName] = array('language' => $language, 'application' => 'Frontend', 'module' => $moduleName, 'type' => $type, 'name' => $key, 'used_in' => serialize($file['file']));
             }
         }
     }
     ksort($nonExisting);
     return $nonExisting;
 }
Example #10
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     ini_set('max_execution_time', 150);
     // Get all the modules
     $modules = BackendModel::getModules();
     // Check if modules is not empty
     if (!empty($modules)) {
         // Create filesystem object
         $filesystem = new Filesystem();
         // Loop the modules
         foreach ($modules as $module) {
             // Create var dir for ease of use
             $dir = FRONTEND_FILES_PATH . '/' . $module . '/Images/';
             // Check if dir exists
             if ($filesystem->exists($dir . 'Source/')) {
                 // Create Finder object
                 $finderDir = new Finder();
                 // Get all the dirs in the modules/images folder.
                 $dirs = $finderDir->directories()->in($dir)->exclude(array("Source", 'source'));
                 // Check if $dirs is not empty
                 if (!empty($dirs)) {
                     // Create Finder object for the files
                     $finderFiles = new Finder();
                     // Get all the files in the source-dir
                     $files = $finderFiles->files()->in($dir . 'Source/');
                     // Check if $files is not empty
                     if (!empty($files)) {
                         // Loop all the dirs
                         foreach ($dirs as $row) {
                             // Explode the dir-name
                             $chunks = explode("x", $row->getBasename(), 2);
                             // Create folder array
                             $folder = array();
                             $folder['dirname'] = $row->getBasename();
                             $folder['path'] = $row->getRealPath();
                             $folder['width'] = $chunks[0] != '' ? (int) $chunks[0] : null;
                             $folder['height'] = $chunks[1] != '' ? (int) $chunks[1] : null;
                             // Loop all the files
                             foreach ($files as $file) {
                                 set_time_limit(150);
                                 // Check if the file exists
                                 if (!$filesystem->exists($dir . $row->getBasename() . '/' . $file->getBasename())) {
                                     // generate the thumbnail
                                     $thumbnail = new \SpoonThumbnail($dir . 'Source/' . $file->getBasename(), $folder['width'], $folder['height']);
                                     $thumbnail->setAllowEnlargement(true);
                                     // if the width & height are specified we should ignore the aspect ratio
                                     if ($folder['width'] !== null && $folder['height'] !== null) {
                                         $thumbnail->setForceOriginalAspectRatio(false);
                                     }
                                     $thumbnail->parseToFile($folder['path'] . '/' . $file->getBasename());
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     echo "ok";
     die;
     // redirect
     //$this->redirect(BackendModel::createURLForAction('index') . '&report=generate_images');
 }
Example #11
0
 /**
  * Fetch the list of modules that require Google Maps API key
  *
  * @return array
  */
 public static function getModulesThatRequireGoogleMaps()
 {
     $modules = array();
     $installedModules = BackendModel::getModules();
     foreach ($installedModules as $module) {
         $setting = BackendModel::get('fork.settings')->get($module, 'requires_google_maps', false);
         if ($setting) {
             $modules[] = $module;
         }
     }
     return $modules;
 }
Example #12
0
 /**
  * Get the locale that is used in the backend but doesn't exists.
  *
  * @param string $language The language to check.
  * @return array
  */
 public static function getNonExistingBackendLocale($language)
 {
     $modules = BackendModel::getModules();
     // search fo the error module
     $key = array_search('error', $modules);
     // remove error module
     if ($key !== false) {
         unset($modules[$key]);
     }
     $used = array();
     // get labels from navigation
     $lbl = self::getLabelsFromBackendNavigation();
     foreach ((array) $lbl as $label) {
         $used['lbl'][$label] = array('files' => array('<small>used in navigation</small>'), 'module_specific' => array());
     }
     // get labels from table
     $lbl = (array) BackendModel::getContainer()->get('database')->getColumn('SELECT label FROM modules_extras');
     foreach ((array) $lbl as $label) {
         $used['lbl'][$label] = array('files' => array('<small>used in database</small>'), 'module_specific' => array());
     }
     $finder = new Finder();
     $finder->notPath('Cache')->notPath('Core/Js/ckeditor')->notPath('Core/Js/ckfinder')->name('*.php')->name('*.tpl')->name('*.js');
     foreach ($finder->files()->in(BACKEND_PATH) as $file) {
         // grab content
         $content = $file->getContents();
         // process based on extension
         switch ($file->getExtension()) {
             // javascript file
             case 'js':
                 $matches = array();
                 // get matches
                 preg_match_all('/\\{\\$(act|err|lbl|msg)(.*)(\\|.*)?\\}/iU', $content, $matches);
                 // any matches?
                 if (isset($matches[2])) {
                     // loop matches
                     foreach ($matches[2] as $key => $match) {
                         // set type
                         $type = $matches[1][$key];
                         // loop modules
                         foreach ($modules as $module) {
                             // determine if this is a module specific locale
                             if (substr($match, 0, mb_strlen($module)) == \SpoonFilter::toCamelCase($module) && mb_strlen($match) > mb_strlen($module)) {
                                 // cleanup
                                 $match = str_replace(\SpoonFilter::toCamelCase($module), '', $match);
                                 // init if needed
                                 if (!isset($used[$type][$match])) {
                                     $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                                 }
                                 // add module
                                 $used[$type][$match]['module_specific'][] = $module;
                             }
                         }
                         // init if needed
                         if (!isset($used[$match])) {
                             $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                         }
                         // add file
                         if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 break;
                 // PHP file
             // PHP file
             case 'php':
                 $matches = array();
                 $matchesURL = array();
                 // get matches
                 preg_match_all('/(BackendLanguage|BL)::(get(Label|Error|Message)|act|err|lbl|msg)\\(\'(.*)\'(.*)?\\)/iU', $content, $matches);
                 // match errors
                 preg_match_all('/&(amp;)?(error|report)=([A-Z0-9-_]+)/i', $content, $matchesURL);
                 // any errormessages
                 if (!empty($matchesURL[0])) {
                     // loop matches
                     foreach ($matchesURL[3] as $key => $match) {
                         $type = 'lbl';
                         if ($matchesURL[2][$key] == 'error') {
                             $type = 'Error';
                         }
                         if ($matchesURL[2][$key] == 'report') {
                             $type = 'Message';
                         }
                         $matches[0][] = '';
                         $matches[1][] = 'BL';
                         $matches[2][] = '';
                         $matches[3][] = $type;
                         $matches[4][] = \SpoonFilter::toCamelCase(\SpoonFilter::toCamelCase($match, '-'), '_');
                         $matches[5][] = '';
                     }
                 }
                 // any matches?
                 if (!empty($matches[4])) {
                     // loop matches
                     foreach ($matches[4] as $key => $match) {
                         // set type
                         $type = 'lbl';
                         if ($matches[3][$key] == 'Error' || $matches[2][$key] == 'err') {
                             $type = 'err';
                         }
                         if ($matches[3][$key] == 'Message' || $matches[2][$key] == 'msg') {
                             $type = 'msg';
                         }
                         // specific module?
                         if (isset($matches[5][$key]) && $matches[5][$key] != '') {
                             // try to grab the module
                             $specificModule = $matches[5][$key];
                             $specificModule = trim(str_replace(array(',', '\''), '', $specificModule));
                             // not core?
                             if ($specificModule != 'Core') {
                                 // dynamic module
                                 if ($specificModule == '$this->URL->getModule(' || $specificModule == '$this->getModule(') {
                                     // init var
                                     $count = 0;
                                     // replace
                                     $modulePath = str_replace(realpath(BACKEND_MODULES_PATH), '', realpath($file), $count);
                                     // validate
                                     if ($count == 1) {
                                         // split into chunks
                                         $chunks = (array) explode('/', trim($modulePath, '/'));
                                         // set specific module
                                         if (isset($chunks[0])) {
                                             $specificModule = $chunks[0];
                                         } else {
                                             continue;
                                         }
                                     }
                                 }
                                 // init if needed
                                 if (!isset($used[$type][$match])) {
                                     $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                                 }
                                 // add module
                                 $used[$type][$match]['module_specific'][] = $specificModule;
                             }
                         } else {
                             // loop modules
                             foreach ($modules as $module) {
                                 // determine if this is a module specific locale
                                 if (substr($match, 0, mb_strlen($module)) == \SpoonFilter::toCamelCase($module) && mb_strlen($match) > mb_strlen($module) && ctype_upper(substr($match, mb_strlen($module) + 1, 1))) {
                                     // cleanup
                                     $match = str_replace(\SpoonFilter::toCamelCase($module), '', $match);
                                     // init if needed
                                     if (!isset($used[$type][$match])) {
                                         $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                                     }
                                     // add module
                                     $used[$type][$match]['module_specific'][] = $module;
                                 }
                             }
                         }
                         // init if needed
                         if (!isset($used[$type][$match])) {
                             $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                         }
                         // add file
                         if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 break;
                 // template file
             // template file
             case 'tpl':
                 $matches = array();
                 // get matches
                 preg_match_all('/\\{\\$(act|err|lbl|msg)([A-Z][a-zA-Z_]*)(\\|.*)?\\}/U', $content, $matches);
                 // any matches?
                 if (isset($matches[2])) {
                     // loop matches
                     foreach ($matches[2] as $key => $match) {
                         // set type
                         $type = $matches[1][$key];
                         // loop modules
                         foreach ($modules as $module) {
                             // determine if this is a module specific locale
                             if (substr($match, 0, mb_strlen($module)) == \SpoonFilter::toCamelCase($module) && mb_strlen($match) > mb_strlen($module)) {
                                 // cleanup
                                 $match = str_replace(\SpoonFilter::toCamelCase($module), '', $match);
                                 // init if needed
                                 if (!isset($used[$type][$match])) {
                                     $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                                 }
                                 // add module
                                 $used[$type][$match]['module_specific'][] = $module;
                             }
                         }
                         // init if needed
                         if (!isset($used[$type][$match])) {
                             $used[$type][$match] = array('files' => array(), 'module_specific' => array());
                         }
                         // add file
                         if (!in_array($file->getRealPath(), $used[$type][$match]['files'])) {
                             $used[$type][$match]['files'][] = $file->getRealPath();
                         }
                     }
                 }
                 break;
         }
     }
     // init var
     $nonExisting = array();
     // check if the locale is present in the current language
     foreach ($used as $type => $items) {
         // loop items
         foreach ($items as $key => $data) {
             // process based on type
             switch ($type) {
                 // error
                 case 'err':
                     // module specific?
                     if (!empty($data['module_specific'])) {
                         // loop modules
                         foreach ($data['module_specific'] as $module) {
                             // if the error isn't found add it to the list
                             if (substr_count(BL::err($key, $module), '{$' . $type) > 0) {
                                 $nonExisting['Backend' . $key . $type . $module] = array('language' => $language, 'application' => 'Backend', 'module' => $module, 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     } else {
                         // if the error isn't found add it to the list
                         if (substr_count(BL::err($key), '{$' . $type) > 0) {
                             // init var
                             $exists = false;
                             // loop files
                             foreach ($data['files'] as $file) {
                                 // init var
                                 $count = 0;
                                 // replace
                                 $modulePath = str_replace(realpath(BACKEND_MODULES_PATH), '', realpath($file), $count);
                                 // validate
                                 if ($count == 1) {
                                     // split into chunks
                                     $chunks = (array) explode('/', trim($modulePath, '/'));
                                     // first part is the module
                                     if (isset($chunks[0]) && BL::err($key, $chunks[0]) != '{$' . $type . \SpoonFilter::toCamelCase($chunks[0]) . $key . '}') {
                                         $exists = true;
                                     }
                                 }
                             }
                             // doesn't exists
                             if (!$exists) {
                                 $nonExisting['Backend' . $key . $type . 'Core'] = array('language' => $language, 'application' => 'Backend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     }
                     break;
                     // label
                 // label
                 case 'lbl':
                     // module specific?
                     if (!empty($data['module_specific'])) {
                         // loop modules
                         foreach ($data['module_specific'] as $module) {
                             // if the label isn't found add it to the list
                             if (substr_count(BL::lbl($key, $module), '{$' . $type) > 0) {
                                 $nonExisting['Backend' . $key . $type . $module] = array('language' => $language, 'application' => 'Backend', 'module' => $module, 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     } else {
                         // if the label isn't found, check in the specific module
                         if (substr_count(BL::lbl($key), '{$' . $type) > 0) {
                             // init var
                             $exists = false;
                             // loop files
                             foreach ($data['files'] as $file) {
                                 // init var
                                 $count = 0;
                                 // replace
                                 $modulePath = str_replace(realpath(BACKEND_MODULES_PATH), '', realpath($file), $count);
                                 // validate
                                 if ($count == 1) {
                                     // split into chunks
                                     $chunks = (array) explode('/', trim($modulePath, '/'));
                                     // first part is the module
                                     if (isset($chunks[0]) && BL::lbl($key, $chunks[0]) != '{$' . $type . \SpoonFilter::toCamelCase($chunks[0]) . $key . '}') {
                                         $exists = true;
                                     }
                                 }
                             }
                             // doesn't exists
                             if (!$exists) {
                                 $nonExisting['Backend' . $key . $type . 'Core'] = array('language' => $language, 'application' => 'Backend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     }
                     break;
                     // message
                 // message
                 case 'msg':
                     // module specific?
                     if (!empty($data['module_specific'])) {
                         // loop modules
                         foreach ($data['module_specific'] as $module) {
                             // if the message isn't found add it to the list
                             if (substr_count(BL::msg($key, $module), '{$' . $type) > 0) {
                                 $nonExisting['Backend' . $key . $type . $module] = array('language' => $language, 'application' => 'Backend', 'module' => $module, 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     } else {
                         // if the message isn't found add it to the list
                         if (substr_count(BL::msg($key), '{$' . $type) > 0) {
                             // init var
                             $exists = false;
                             // loop files
                             foreach ($data['files'] as $file) {
                                 // init var
                                 $count = 0;
                                 // replace
                                 $modulePath = str_replace(realpath(BACKEND_MODULES_PATH), '', realpath($file), $count);
                                 // validate
                                 if ($count == 1) {
                                     // split into chunks
                                     $chunks = (array) explode('/', trim($modulePath, '/'));
                                     // first part is the module
                                     if (isset($chunks[0]) && BL::msg($key, $chunks[0]) != '{$' . $type . \SpoonFilter::toCamelCase($chunks[0]) . $key . '}') {
                                         $exists = true;
                                     }
                                 }
                             }
                             // doesn't exists
                             if (!$exists) {
                                 $nonExisting['Backend' . $key . $type . 'Core'] = array('language' => $language, 'application' => 'Backend', 'module' => 'Core', 'type' => $type, 'name' => $key, 'used_in' => serialize($data['files']));
                             }
                         }
                     }
                     break;
             }
         }
     }
     ksort($nonExisting);
     // return
     return $nonExisting;
 }
Example #13
0
 /**
  * Load the data
  */
 private function loadData()
 {
     $modules = BackendModel::getModules();
     $filesystem = new Filesystem();
     // fetch the hidden widgets for all groups the user is in
     $hiddenWidgets = [];
     $userGroups = BackendAuthentication::getUser()->getGroups();
     $groupCount = count($userGroups);
     foreach ($userGroups as $group) {
         foreach (BackendGroupsModel::getSetting($group, 'hidden_on_dashboard') as $module => $widgets) {
             foreach ($widgets as $widget) {
                 $hiddenWidgets[] = $module . $widget;
             }
         }
     }
     // only widgets hidden for all user groups should really be hidden
     $hiddenWidgets = array_count_values($hiddenWidgets);
     $hiddenWidgets = array_filter($hiddenWidgets, function ($hiddenCount) use($groupCount) {
         return $hiddenCount === $groupCount;
     });
     // loop all modules
     foreach ($modules as $module) {
         // build pathName
         $pathName = BACKEND_MODULES_PATH . '/' . $module;
         // you have sufficient rights?
         if (BackendAuthentication::isAllowedModule($module) && $filesystem->exists($pathName . '/Widgets')) {
             $finder = new Finder();
             $finder->name('*.php');
             // loop widgets
             foreach ($finder->files()->in($pathName . '/Widgets') as $file) {
                 /** @ver $file \SplFileInfo */
                 $widgetName = $file->getBasename('.php');
                 $className = 'Backend\\Modules\\' . $module . '\\Widgets\\' . $widgetName;
                 if ($module == 'Core') {
                     $className = 'Backend\\Core\\Widgets\\' . $widgetName;
                 }
                 // if the widget is hidden for all the users groups, don't render it
                 if (array_key_exists($module . $widgetName, $hiddenWidgets)) {
                     continue;
                 }
                 if (!class_exists($className)) {
                     throw new BackendException('The widgetfile ' . $className . ' could not be found.');
                 }
                 // create instance
                 /** @var $instance BackendBaseWidget */
                 $instance = new $className($this->getKernel());
                 // has rights
                 if (!$instance->isAllowed()) {
                     continue;
                 }
                 $instance->execute();
                 // user sequence provided?
                 $title = \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(\SpoonFilter::toCamelCase($widgetName));
                 $templatePath = $instance->getTemplatePath();
                 // reset template path
                 if ($templatePath == null) {
                     $templatePath = '/' . $module . '/Layout/Widgets/' . $widgetName . '.html.twig';
                 }
                 $templating = $this->get('template');
                 $content = trim($templating->getContent($templatePath));
                 if (empty($content)) {
                     continue;
                 }
                 // build item
                 $item = array('content' => $content, 'module' => $module, 'widget' => $widgetName, 'title' => $title);
                 // add on new position if no position is set or if the position is already used
                 $this->widgets[] = $item;
             }
         }
     }
 }