Pobieranie komend z aplikacji
969676
protected function getApplicationCommands()
    {
        $commands = [];
        foreach (StructureParser::getModules() as $module) {
            //namespace modułu
            $moduleNamespace = substr($module, strrpos($module, DIRECTORY_SEPARATOR) + 1, strlen($module));
            //iteracja po komendach konsolowych
            foreach (glob($module . '/Console/*Command.php') as $command) {
                $className = basename($command, '.php');
                $class = '\\' . $moduleNamespace . '\\Console\\' . $className;

                //reflection do sprawdzenia pochodzenia
                $r = new \ReflectionClass($class);
                if ($r->isSubclassOf('Mmi\\Console\\CommandAbstract')
                    && !$r->isAbstract()
                    && !$r->getConstructor()->getNumberOfRequiredParameters()
                ) {
                    $commands[] = $r->newInstance();
                }
            }
        }
        return $commands;
    }
95729
public function getLongitude()
    {
        //brak tagu GPS
        if (!isset($this->_exif['GPSLongitude']) || !isset($this->_exif['GPSLongitudeRef'])) {
            return;
        }
        //tag źle sformatowany
        if (!is_array($this->_exif['GPSLongitude']) || count($this->_exif['GPSLongitude']) != 3) {
            return;
        }
        //obliczanie do eleganckiej postaci
        $hours = round($this->_gpsValue($this->_exif['GPSLongitude'][0]));
        $minutes = round($this->_gpsValue($this->_exif['GPSLongitude'][1])) / 60;
        $seconds = $this->_gpsValue($this->_exif['GPSLongitude'][1]) / 3600;
        $sign = 1;
        if (strtolower($this->_exif['GPSLongitudeRef']) != 'e') {
            $sign = -1;
        }
        //zwrot w formie ułamka
        return $sign * ($hours + $minutes + $seconds);
    }
1055803
public static function postUpdate(Event $event) 
    { 
        //inicjalizacja autoloadera 
        self::_initAutoload($event); 
        //linkowanie zasobów web 
        self::_linkModuleWebResources(); 
        //kopiowanie binariów z modułów 
        self::_copyModuleBinaries(); 
    }
386352
public function indexAction()
    {
        $year = $this->year ? $this->year : date('Y');
        $month = $this->month ? $this->month : date('m');
        //form filtrujący
        $form = new \CmsAdmin\Form\Stat\StatObject(null, ['object' => $this->object,
            'year' => $year,
            'month' => $month,
        ]);
        //przekazanie formularza
        $this->view->objectForm = $form;
        if ($form->isMine()) {
            //przekierowanie po odczycie pól z formularza
            if ($form->getElement('object')->getValue() && $form->getElement('month')->getValue() >= 1 && $form->getElement('month')->getValue() <= 12 && $form->getElement('year')->getValue() <= date('Y')) {
                $this->getResponse()->redirect('cmsAdmin', 'stat', 'index', ['object' => $form->getElement('object')->getValue(),
                    'year' => $form->getElement('year')->getValue(),
                    'month' => $form->getElement('month')->getValue(),
                ]);
            }
            //przekierowanie na dany miesiąc - bez zmiany obiektu
            $this->getResponse()->redirect('cmsAdmin', 'stat', 'index', ['year' => $form->getElement('year')->getValue(),
                'month' => $form->getValue('month'),
            ]);
        }
        if (!$this->object || !$this->year || !$this->month) {
            return;
        }
        $object = $this->object;
        $year = intval($year);
        $month = intval($month);
        $label = \Cms\Orm\CmsStatLabelQuery::byObject($object)
            ->findFirst();
        if ($label === null) {
            return;
        }
        $this->view->label = $label;
        //staty dzienne

        $prevMonth = ($month - 1) > 0 ? $month - 1 : 12;
        $prevYear = ($prevMonth == 12) ? $year - 1 : $year;
        $day = (ltrim(date('m'), '0') == $month) ? date('d') : date('t', strtotime($year . '-' . $month));

        //statystyki dzienne
        $this->view->dailyChart = \Cms\Model\StatFlot::getCode('dailyChart', [
                //bieżący miesiąc
                ['object' => $label->object,
                    'label' => $label->label . ': ' . $this->view->_('dni'),
                    'data' => \Cms\Model\Stat::toDate($object, null, $year, $month, $day)
                ],
                //poprzedni miesiąc
                ['object' => $label->object,
                    'label' => $this->view->_('Poprzedni miesiąc: dni'),
                    'data' => \Cms\Model\Stat::toDate($object, null, $prevYear, $prevMonth, $day)
                ]], 'lines', true);
        //statystyki miesięczne
        $this->view->monthlyChart = \Cms\Model\StatFlot::getCode('monthlyChart', [
                ['object' => $label->object,
                    'label' => $label->label . ': ' . $this->view->_('miesiące'),
                    'data' => \Cms\Model\Stat::monthly($object, null, $year)
                ]], 'bars');
        //statystyki roczne
        $this->view->yearlyChart = \Cms\Model\StatFlot::getCode('yearlyChart', [
                ['object' => $label->object,
                    'label' => $label->label . ': ' . $this->view->_('lata'),
                    'data' => \Cms\Model\Stat::yearly($object, null)
                ]], 'bars');
        //rozkład godzinowy
        $this->view->avgHourlyChart = \Cms\Model\StatFlot::getCode('avgHourlyChart', [
                ['object' => $label->object,
                    'label' => $label->label . ': ' . $this->view->_('rozkład godzinowy'),
                    'data' => \Cms\Model\Stat::avgHourly($object, null, $year, $month)
                ]], 'bars');
        //rozkład godzinowy
        $this->view->avgHourlyAllChart = \Cms\Model\StatFlot::getCode('avgHourlyAllChart', [
                ['object' => $label->object,
                    'label' => $label->label . ': ' . $this->view->_('rozkład ogólny'),
                    'data' => \Cms\Model\Stat::avgHourly($object, null, null, null)
                ]], 'bars');
    }
193905
protected function _createTempFiles()
    {
        //jeśli już są pliki tymczasowe, to wychodzimy
        if ((new \Cms\Orm\CmsFileQuery)
            ->byObject('tmp-' . $this->getUploaderObject(), $this->getUploaderId())
            ->count()) {
            return true;
        }
        $objectId = null;
        if ($this->_form->hasRecord()) {
            $objectId = $this->_form->getRecord()->getPk();
        }
        //tworzymy pliki tymczasowe - linki do oryginałów
        \Cms\Model\File::link($this->getUploaderObject(), $objectId, 'tmp-' . $this->getUploaderObject(), $this->getUploaderId());
        return true;
    }
29524
public function editAction()
    {
        $form = new \CmsAdmin\Form\Text(new \Cms\Orm\CmsTextRecord($this->id));
        $this->view->textForm = $form;
        //brak wysłanych danych
        if (!$form->isMine()) {
            return;
        }
        //zapisany
        if ($form->isSaved()) {
            $this->getMessenger()->addMessage('messenger.text.text.saved', true);
            $this->getResponse()->redirect('cmsAdmin', 'text');
        }
        $this->getMessenger()->addMessage('messenger.text.text.error', false);
    }
650528
public function handleRequest()
    {
        //obsługa eksportera
        $this->_handleCsvExporter(FrontController::getInstance()->getRequest());
        //obsługa danych z POST
        $post = FrontController::getInstance()->getRequest()->getPost();
        //brak posta
        if ($post->isEmpty()) {
            return;
        }
        //jeśli przebudowano filtry lub sortowania render grida
        if ($this->_rebuildFilter($post) || $this->_rebuildOrder($post)) {
            $this->_render();
        }
    }
1243994
public function isVisible()
    {
        //jeśli nie jest aktywna
        if (!$this->active) {
            return false;
        }
        //jeśli status różny od aktywna (bieżąca)
        if ($this->status != \Cms\Orm\CmsCategoryRecord::STATUS_ACTIVE) {
            return false;
        }
        //nie osiągnięto czasu publikacji
        if (null !== $this->dateStart && $this->dateStart > date('Y-m-d H:i:s')) {
            return false;
        }
        //przekroczono czas publikacji
        if (null !== $this->dateEnd && $this->dateEnd < date('Y-m-d H:i:s')) {
            return false;
        }
        return true;
    }
1156079
public function fetchField()
    {
        $view = \Mmi\App\FrontController::getInstance()->getView();
        $view->headScript()->appendFile('/resource/cmsAdmin/js/tiny/tinymce.min.js');

        //bazowa wspólna konfiguracja
        $this->_baseConfig($view);
        //tryb edytora
        $mode = $this->getMode() ? $this->getMode() : 'default';
        //metoda konfiguracji edytora
        $modeConfigurator = '_mode' . ucfirst($mode);
        if (method_exists($this, $modeConfigurator)) {
            $this->$modeConfigurator();
        }

        $class = $this->getOption('id');
        $this->setOption('class', trim($this->getOption('class') . ' ' . $class));
        $object = 'tmp-' . $this->getUploaderObject();
        $objectId = $this->getUploaderId();
        $t = round(microtime(true));
        $hash = md5(\Mmi\Session\Session::getId() . '+' . $t . '+' . $objectId);
        //tworzenie kopii plików załadowanych do TinyMce
        $this->_createTempFiles();
        //aktualizacja wartości pola - poprawka ścieżek do plików
        $this->_updateValue();
        //dołączanie skryptu
        $view->headScript()->appendScript("
			tinyMCE.init({
				selector: '." . $class . "',
				language: request.locale,
				" . $this->_renderConfig('theme', 'theme', 'modern') . "
				" . $this->_renderConfig('skin', 'skin', 'lightgray') . "
				" . $this->_renderConfig('plugins', 'plugins') . "
				" . $this->_renderConfig('contextmenu', 'contextMenu') . "
				" . $this->_renderConfig('width', 'width', '') . "
				" . $this->_renderConfig('height', 'height', 320) . "
				" . $this->_renderConfig('resize', 'resize', true) . "
				" . $this->_renderConfig('menubar', 'menubar', true) . "
				" . $this->_renderConfig('image_advtab', 'imageAdvanceTab', true) . "
				" . $this->_renderConfig('font_formats', 'fontFormats') . "
				" . $this->_renderConfig('fontsize_formats', 'fontSizeFormats') . "
				" . $this->_renderConfig('content_css', 'css') . "
				" . $this->_renderConfigN('toolbar', 'toolbars') . "
				" . $this->_renderConfig('image_caption', 'imageCaption', false) . "
				" . ($this->getCustomConfig() ? trim($this->getCustomConfig(), ",") . "," : "") . "
				" . $this->_other . "
				" . $this->_common . "
				hash: '$hash',
				object: '$object',
				objectId: '$objectId',
				time: '$t',
				baseUrl: '" . $view->baseUrl . "',
                image_list: '" . $view->baseUrl . "' + '/?module=cms&controller=file&action=list&object=$object&objectId=$objectId&t=$t&hash=$hash',
                branding: false
			});
		");

        //unsety zbędnych opcji
        $this->unsetMode()->unsetCustomConfig()->unsetCss()->unsetTheme()->unsetSkin()
            ->unsetPlugins()->unsetContextMenu()->unsetResize()->unsetMenubar()
            ->unsetImageAdvanceTab()->unsetFontFormats()->unsetFontSizeFormats()
            ->unsetToolbars()->unsetImageCaption();

        return parent::fetchField();
    }
1195956
public function passCsv()
    {
        $csv = fopen('php://output', 'w');
        //nagłówek CSV
        fputcsv($csv, $this->_getHeader());
        //iteracja po danych
        foreach ($this->_getData() as $data) {
            //zapis linii CSV
            fputcsv($csv, $data);
        }
        fclose($csv);
    }
641635
protected function _synchronizeDrafts()
    {
        //iteracja po draftach bieżącego dokumentu
        foreach ((new CmsCategoryQuery())->whereCmsCategoryOriginalId()->equals($this->id)
            ->andFieldStatus()->equals(self::STATUS_DRAFT)
            ->find()
            as $draftRecord) {
            //synchronizacja uri
            $draftRecord->uri = $this->uri;
            //synchronizacja parentId
            $draftRecord->parentId = $this->parentId;
            //synchronizacja kolejności
            $draftRecord->order = $this->order;
            //bez przebudowy kolejności
            $draftRecord->setOption('block-ordering', true);
            //zapis
            $draftRecord->save();
        }
    }
417186
protected final function _prepareFields()
    {
        //jeśli pusty schemat połączeń
        if (empty($this->_query->getQueryCompile()->joinSchema)) {
            return '*';
        }
        $fields = '';
        //pobranie struktury tabeli
        $mainStructure = DbConnector::getTableStructure($this->_query->getTableName());
        //przygotowanie tabeli
        $table = DbConnector::getAdapter()->prepareTable($this->_query->getTableName());
        //iteracja po polach tabeli głównej
        foreach ($mainStructure as $fieldName => $info) {
            //dodawanie pola
            $fields .= $table . '.' . DbConnector::getAdapter()->prepareField($fieldName) . ', ';
        }
        //pola z tabel dołączonych
        foreach ($this->_query->getQueryCompile()->joinSchema as $schema) {
            //pobranie struktury tabeli dołączonej
            $structure = DbConnector::getTableStructure($schema[0]);
            //alias połączenia
            $joinAlias = isset($schema[5]) ? $schema[5] : $schema[0];
            //pola tabeli dołączonej
            foreach ($structure as $fieldName => $info) {
                $fields .= DbConnector::getAdapter()->prepareTable($joinAlias) . '.' . DbConnector::getAdapter()->prepareField($fieldName) . ' AS ' . DbConnector::getAdapter()->prepareField($joinAlias . '__' . $schema[0] . '__' . $fieldName) . ', ';
            }
        }
        return rtrim($fields, ', ');
    }
613988
public function deleteAttributeRelationAction()
    {
        //wyszukiwanie rekordu relacji
        $record = (new \Cms\Orm\CmsAttributeRelationQuery)
            ->whereObjectId()->equals($this->id)
            ->findPk($this->relationId);
        //jeśli znaleziono rekord
        if ($record && $record->delete()) {
            //wyszukiwanie stron w zmienionym szablonie
            foreach ((new \Cms\Orm\CmsCategoryQuery)->whereCmsCategoryTypeId()
                ->equals($this->id)
                ->findPairs('id', 'id') as $categoryId) {
                //usuwanie wartości usuniętych atrybutów
                (new \Cms\Model\AttributeValueRelationModel('category', $categoryId))
                    ->deleteAttributeValueRelationsByAttributeId($record->cmsAttributeId);
            }
            $this->getMessenger()->addMessage('messenger.attribute.attributeRelation.deleted', true);
        }
    }
1047125
public function updateAction()
    {
        $msg = $this->view->getTranslate()->_('Zmiana właściwości nie powiodła się.');
        $this->getResponse()->setTypePlain();
        $params = explode('-', $this->id);

        //błędne dane wejściowe
        if (!($this->getPost()->selected) || count($params) != 3) {
            return $msg;
        }
        $record = (new \Cms\Orm\CmsAclQuery)->findPk($params[2]);
        if (!$record) {
            return $msg;
        }
        //zmiana zasobu
        if ($params[1] == 'resource') {
            $resource = [];
            parse_str($this->getPost()->selected, $resource);
            $record->module = strtolower($resource['module']);
            $record->controller = isset($resource['controller']) ? strtolower($resource['controller']) : null;
            $record->action = isset($resource['action']) ? strtolower($resource['action']) : null;
        } else {
            //zmiana uprawnienia z allow na deny lub odwrotnie
            $record->access = $this->getPost()->selected == 'allow' ? 'allow' : 'deny';
        }
        $record->save();
        return 1;
    }
24120
public function addAction()
    {
        //wyszukiwanie kategorii
        if (null === $cat = (new \Cms\Orm\CmsCategoryQuery)->findPk($this->id)) {
            return;
        }
        //zakładka sekcje
        $widgetForm = (new \CmsAdmin\Form\CategoryAddWidget($cat));
        //zapisany form
        if ($widgetForm->isSaved()) {
            $this->getResponse()->redirect('cmsAdmin', 'categoryWidgetRelation', 'config', ['categoryId' => $this->id, 'widgetId' => $widgetForm->getElement('cmsWidgetId')->getValue()]);
        }
        //form do widoku
        $this->view->widgetForm = $widgetForm;
    }
267821
public final function fetchBegin()
    {
        $class = get_class($this);
        //dodawanie klasy z klasą forma
        $this->addClass(strtolower(substr($class, strrpos($class, '\\') + 1)));
        //dodawanie klasy błędu jeśli wystąpiły
        if ($this->getErrors()) {
            $this->addClass('error');
        }
        //element do widoku
        \Mmi\App\FrontController::getInstance()->getView()->_element = $this;
        //render szablonu
        return \Mmi\App\FrontController::getInstance()->getView()->renderTemplate(static::TEMPLATE_BEGIN);
    }
696980
public static function run()
    {
        foreach (Orm\CmsCronQuery::active()->find() as $cron) {
            if (!self::_getToExecute($cron)) {
                continue;
            }
            $output = '';
            try {
                $start = microtime(true);
                $output = \Mmi\Mvc\ActionHelper::getInstance()->action(new \Mmi\Http\Request(['module' => $cron->module, 'controller' => $cron->controller, 'action' => $cron->action]));
                $elapsed = round(microtime(true) - $start, 2);
            } catch (\Exception $e) {
                //error logging
                \Mmi\App\FrontController::getInstance()->getLogger()->error('CRON failed: @' . gethostname() . $cron->name . ' ' . $e->getMessage());
                return;
            }
            //zmień datę ostatniego wywołania
            $cron->dateLastExecute = date('Y-m-d H:i:s');
            //ponowne łączenie
            \App\Registry::$db->connect();
            //zapis do bazy bez modyfikowania daty ostatniej modyfikacji
            $cron->saveWithoutLastDateModify();
            //logowanie uruchomienia
            \Mmi\App\FrontController::getInstance()->getLogger()->info('CRON done: @' . gethostname() . ' ' . $cron->name . ' ' . $output .  ' in ' . $elapsed . 's');
        }
    }