Beispiel #1
0
 /**
  *
  */
 public function endLog()
 {
     if (!file_exists(DIR_FRONT_LOGS)) {
         FileSystem::mkDir(DIR_FRONT_LOGS);
     }
     if (count($this->stringBuffer)) {
         error_log(rtrim(join(PHP_EOL, $this->stringBuffer), PHP_EOL) . PHP_EOL, 3, DIR_FRONT_LOGS . $this->file);
     }
 }
Beispiel #2
0
 /**
  * @param string $str
  * @param string $flag
  */
 public function write($str = '', $flag = ILogger::WRITE_LOG)
 {
     static $log_id = '';
     if (!$log_id) {
         $log_id = uniqid();
     }
     // Create directory
     if (!file_exists(DIR_FRONT_LOGS)) {
         FileSystem::mkDir(DIR_FRONT_LOGS);
     }
     error_log(date('d.m.Y H:i:s') . "\t{$log_id}\t{$str}\n", 3, DIR_FRONT_LOGS . 'common.log');
 }
Beispiel #3
0
 /**
  * @param string $key
  * @param mixed $value
  * @param int $ttl
  * @return bool
  */
 public function set($key, $value, $ttl = 2592000)
 {
     if (!FileSystem::checkFileName($key)) {
         return false;
     }
     $path = $this->getPathToFile($key);
     if (!$path) {
         return false;
     }
     $file = $path . $key;
     FileSystem::mkDir($path);
     file_put_contents($file, serialize($value));
     touch($file, $this->calculateFileTouchTtl($ttl));
     return is_file($file) && $this->get($key) == $value;
     // Return true only if file is created and value is stored
 }
Beispiel #4
0
 /**
  * @return array
  */
 public function getPluginFilePairs()
 {
     if ($this->plugin_files) {
         // Already have found filed
         return $this->plugin_files;
     }
     foreach (Finder::getInstance()->getPathFolders(Finder::TYPE_PLUGINS) as $folder) {
         $folder = DIR_BASE . $folder;
         FileSystem::mkDir($folder);
         // Skip folder links
         $cms_plugin_files = array_diff(scandir($folder), ['.', '..']);
         // Make simple names for rendering in selects
         foreach ($cms_plugin_files as $k => $v) {
             $this->plugin_files[$v] = str_replace('plugin.php', '', $v);
         }
     }
     return $this->plugin_files;
 }
Beispiel #5
0
 /**
  * Save log into file, and try to send via email to Developers
  */
 public static function flushLog()
 {
     $last_flush_time = Settings::get('cms_tools_application_log_flush');
     if (NOW - $last_flush_time < 453600) {
         return;
         // We do not need stats too often, wait 7 days
     }
     // Send data to original developer site of the existing domain
     self::sendInformation();
     // Now prepare file with aggregated data
     $app_log = new AppLogEntityRepository();
     $app_log->addSimpleSelectFields(['id', 'ts', 'user_id', 'url', 'msg', 'p', 'do']);
     if ($last_flush_time) {
         $app_log->setWhereOld($last_flush_time);
     }
     $app_log->addOrderByField('ts', true);
     $app_log->setGenerateOutputWithIterator(false);
     $users = new AdminUserRepository();
     $users->setGenerateOutputWithIterator(false);
     $users->addSimpleSelectFieldsAsString('CONCAT(`' . $users->getDbTableName() . '`.`name`, " ", `' . $users->getDbTableName() . '`.`surname`) AS `user`');
     $app_log->mergeWithCollection($users, 'user_id');
     $data_log = $app_log->getAsArrayOfObjectData(true);
     $usage = new AdminUsageEntityRepository();
     $data_usage = $usage->getAsArrayOfObjectData(true);
     if ($data_log || $data_usage) {
         $data = ['data' => ['domain' => CFG_DOMAIN, 'ts' => NOW], 'logs' => ['app_log' => $data_log, 'usage' => $data_usage]];
         // Save in file
         if (!file_exists(DIR_CACHE)) {
             FileSystem::mkDir(DIR_CACHE);
         }
         file_put_contents(DIR_CACHE . 'log_data', gzencode(json_encode($data)));
         // Send stats
         Mailer::getInstance()->setSubject('Application and Usage log from ' . Configuration::getInstance()->get('site')['name'] . '(till ' . date(CFG_CMS_DATETIME_FORMAT, NOW) . ')')->setSender(Configuration::getInstance()->get('site')['email'])->setRecipient(CMS_SUPPORT_EMAIL)->setMessage('View attached file')->addAttachment(DIR_CACHE . 'log_data')->send();
         $usage->deleteObjectCollection();
     }
     Settings::getInstance()->set('cms_tools_application_log_flush', NOW);
 }
 /**
  * Action for Create directory
  */
 public function _create_directory()
 {
     $dir = $_GET['path'];
     if ($dir && $dir[0] == '/') {
         $dir = substr($dir, 1);
     }
     FileSystem::mkDir(DIR_BASE . $dir . $_POST['name']);
     App::add('Diretory "' . $dir . $_POST['name'] . '" created');
     Messages::sendGreenAlert('Diretory "' . $dir . $_POST['name'] . '" created');
     go('?p=' . P . '&do=show_files&nomenu&path=' . $dir);
 }
 /**
  * @return Element
  */
 public function getFieldView()
 {
     $field = NULL;
     // Type
     switch ($this->field_type) {
         default:
         case 'text':
             $field = CmsInputText::getInstance($this->component_name);
             break;
         case 'textarea':
             $field = CmsTextarea::getInstance($this->component_name);
             // Height
             if (isset($this->field_value['rows'])) {
                 $field->setRowCount($this->field_value['rows']);
             }
             break;
         case 'checkbox':
             $field = CmsCheckbox::getInstance($this->component_name);
             // Checked
             if (!isset($this->field_value['checked']) && isset($this->data[$this->component_name])) {
                 $this->field_value['checked'] = $this->data[$this->component_name];
             }
             if (isset($this->field_value['checked'])) {
                 $field->setChecked($this->field_value['checked']);
             }
             break;
         case 'checkbox_list':
             $field = CmsCheckboxList::getInstance($this->component_name);
             if (isset($this->field_value['checkboxes'])) {
                 $field->setCheckboxes($this->field_value['checkboxes']);
             }
             if (!isset($this->field_value['selected']) && isset($this->data[$this->component_name])) {
                 $this->field_value['selected'] = unserialize($this->data[$this->component_name]);
             }
             if (isset($this->field_value['selected'])) {
                 $field->setChecked(array_keys($this->field_value['selected']));
             }
             $field->setListView(true);
             break;
         case 'options':
         case 'select':
             $field = CmsSelect::getInstance($this->component_name);
             // Options
             if (isset($this->field_value['options'])) {
                 $field->setOptions($this->field_value['options']);
             }
             // Selected options
             if (!isset($this->field_value['selected']) && isset($this->data[$this->component_name])) {
                 $this->field_value['selected'] = $this->data[$this->component_name];
             }
             if (isset($this->field_value['selected'])) {
                 $field->setSelected($this->field_value['selected']);
                 $this->selected = $this->field_value['selected'];
             } else {
                 $this->selected = false;
             }
             break;
         case 'multiselect':
             $field = CmsMultipleSelect::getInstance($this->component_name);
             if (isset($this->field_value['options'])) {
                 $field->setOptions($this->field_value['options']);
             }
             if (!isset($this->field_value['selected']) && isset($this->data[$this->component_name])) {
                 $this->field_value['selected'] = $this->data[$this->component_name];
             }
             if (isset($this->field_value['selected'])) {
                 $field->setSelected($this->field_value['selected']);
                 $this->selected = $this->field_value['selected'];
             } else {
                 $this->selected = false;
             }
             $field->helper(false);
             break;
         case 'tags':
             $field = CmsInputTags::getInstance($this->component_name);
             break;
         case 'custom':
             // Skip because we have separate page for it
             break;
     }
     // Required for Widgets
     if ($field) {
         $field->setAttribute('data-page_id', $this->page_id);
     }
     // Set Widget
     switch ($this->widget_type) {
         case '':
             break;
         case 'wysiwyg':
             $field->enableWysiwyg();
             break;
         case 'tinymce':
             $field->enableWysiwyg();
             break;
         case 'calendar':
             $widget = new Calendar();
             if (isset($this->field_value['format'])) {
                 $widget->dateFormat($this->field_value['format']);
             }
             if (isset($this->field_value['showtime'])) {
                 $widget->showTime($this->field_value['showtime']);
             }
             $field->setWidget($widget);
             break;
         case 'files':
             $widget = new FileManager();
             // Path to opened folder
             if (isset($this->field_value['path'])) {
                 if (!file_exists(DIR_BASE . $this->field_value['path'])) {
                     FileSystem::mkDir(DIR_BASE . $this->field_value['path']);
                 }
                 $widget->path($this->field_value['path']);
             }
             // Allowed extensions
             if (isset($this->field_value['allowed_extensions'])) {
                 $widget->setAllowedExtensions($this->field_value['allowed_extensions']);
             }
             $field->setWidget($widget);
             break;
         case 'pages':
             $field->setWidget(new SitemapPages());
             break;
         case 'map':
             $field->enableGoogleMap();
             break;
     }
     // Special features for field
     if (isset($this->field_value['hint'])) {
         $field->setHintText($this->field_value['hint']);
     }
     return $field;
 }