/** * Returns array of update SQL with default options, $source, $destination - database structures * @access public * @param string $source structure dump of database to update * @param string $destination structure dump of the reference database * @param bool $asString if true - result will be a string, otherwise - array * @return array|string update sql statements - in array or string (separated with ';') */ public function getUpdates($source, $destination, $asString = false) { // Remove double spaces $source = Converter::spaces2space($source); $destination = Converter::spaces2space($destination); // Cut sql to check if structure is same $source_cut = strstr($source, 'AUTO_INCREMENT=', true); $destination_cut = strstr($source, 'AUTO_INCREMENT=', true); // Same structure - return nothing if ($source_cut == $destination_cut) { // return ''; } $result = $asString ? '' : []; $compRes = $this->compare($source, $destination); if (empty($compRes)) { return $result; } $compRes = $this->filterDiffs($compRes); if (empty($compRes)) { return $result; } $result = $this->getDiffSql($compRes); if ($asString) { $result = implode(";\r\n", $result) . ';'; } return $result; }
/** * @param string $module * @param array $fields * @return string */ public static function requireTableForExternalModule($module = P, $fields = []) { $data = new CustomSettingRepository(); $data->setWhereModule($module); $data->getAsArrayOfObjectData(); foreach ($data->getAsArrayOfObjectData() as $key => $field) { // Any existing data if (isset($fields[$field['key']])) { $field = array_merge($fields[$field['key']], $field); } // Supplied data if (!isset($field['module'])) { $field['module'] = P; } $field['title'] = Converter::symb2Ttl($field['key']); $field['type'] = $field['input_type']; $options_array = []; if ($field['input_options'] && is_string($field['input_options'])) { $options_array = json_decode($field['input_options'], JSON_OBJECT_AS_ARRAY); } // Validators and editors if (isset($options_array['editor_wysiwyg'])) { $field['edit'] = 'wysiwyg'; } if (isset($options_array['editor_files'])) { $field['edit'] = 'files'; } if (isset($options_array['editor_pages'])) { $field['edit'] = 'pages'; } if (isset($options_array['require'])) { $field['required'] = true; $field['validate']['require'] = true; } if (isset($options_array['is_digit'])) { $field['validate']['is_digit'] = true; } if (isset($options_array['alphanum'])) { $field['validate']['alphanum'] = true; } if (isset($options_array['url'])) { $field['validate']['url'] = true; } if (isset($options_array['email'])) { $field['validate']['email'] = true; } // Input Type if ($field['input_type'] == 'select') { $field['options'] = ModuleSettings::getSelectTypeSettingOption(P, $field['key']); } $fields[$field['key']] = $field; } if (!$fields) { return false; } $form_array = ['action' => '?p=' . P . '&do=_settings', 'button' => __('Update'), 'fields' => $fields]; return CmsFormHelper::outputForm(self::$tables['settings'], $form_array)->enableAjax(); }
public function edit() { $id = abs((int) $_GET['id']); if (!$id) { return; } $subscriber = new EmailSubscriberEntity($id); echo BreadCrumbs::getInstance()->addCrumb(Converter::symb2Ttl(P), '?p=' . P)->addCrumb('Edit Email Subscriber')->addCrumb($subscriber->getEmail()); echo self::__subscribers_form($subscriber)->setAction('?p=' . P . '&do=_edit&id=' . $id); }
/** View one */ public function view() { if (!isset($_GET['id']) || !ctype_digit((string) $_GET['id'])) { return; } $feedback_id = $_GET['id']; $feedback = new Feedback($feedback_id); if (!$feedback) { return; } $feedback_data = $feedback->getAsArray(); $form = CmsForm::getInstance()->outputTagForm(false); $feedback_data['date_created'] = date(CFG_CMS_DATETIME_FORMAT, $feedback_data['date_created']); unset($feedback_data['id']); unset($feedback_data['client_id']); foreach ($feedback_data as $k => $item) { if (!is_string($item)) { continue; } $form->addField(Converter::symb2Ttl($k), CmsHtml::getInstance($k)->value(htmlspecialchars($item, ENT_QUOTES))); } echo $form; }
private function generateContent() { ob_start(); // Requesting P page $method = false; $call_object = false; // Find in classes under Vendor - Modules $real_class = Converter::to_camel_case(P); $class = '\\TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class; if (!class_exists($class)) { // Not vendor module - check main CMS admin object $class = '\\TMCms\\Admin\\' . $real_class . '\\Cms' . $real_class; $call_object = true; if (!class_exists($class)) { // Search for exclusive module CMS pages created in Project folder for this individual site $file_path = DIR_MODULES . strtolower($real_class) . '/' . 'Cms' . $real_class . '.php'; if (file_exists($file_path)) { require_once $file_path; // Check for module itself $file_path = DIR_MODULES . strtolower($real_class) . '/' . 'Module' . $real_class . '.php'; if (file_exists($file_path)) { require_once $file_path; } // Require all objects class files $objects_path = DIR_MODULES . strtolower($real_class) . '/Entity/'; if (file_exists($objects_path)) { foreach (array_diff(scandir($objects_path), ['.', '..']) as $object_file) { require_once $objects_path . $object_file; } } // CmsClass $real_class = Converter::to_camel_case(P); $class = '\\TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class; } } } // Try autoload PSR-0 or PSR-4 if (!class_exists($class)) { $class = 'TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class; } // Try to find the right directory of requested class if (!class_exists($class)) { $class_name = 'Cms' . $real_class; $directory_iterator = new RecursiveDirectoryIterator(DIR_MODULES); $iterator = new RecursiveIteratorIterator($directory_iterator); foreach ($iterator as $file) { if ($file->getFilename() == $class_name . '.php') { $module_path = $file->getPathInfo()->getPathName(); $module_name = $file->getPathInfo()->getFilename(); $module_directory_iterator = new RecursiveDirectoryIterator($module_path); $module_iterator = new RecursiveIteratorIterator($module_directory_iterator); foreach ($module_iterator as $module_file) { $module_file_directory = $module_file->getPathInfo()->getFilename(); $module_file_name = $module_file->getFileName(); if (!in_array($module_file_name, ['.', '..']) and in_array($module_file_directory, [$module_name, 'Entity'])) { require_once $module_file->getPathName(); } } $class = implode('\\', ['\\TMCms', 'Modules', $module_name, $class_name]); break; } } } // Still no class if (!class_exists($class)) { dump('Requested class "' . $class . '" not found'); } // Check existence of requested method if (class_exists($class)) { $call_object = true; // Check requested method exists or set default if (method_exists($class, P_DO)) { $method = P_DO; } else { $method = '_default'; } // Final check we have anything to run if (!method_exists($class, $method)) { dump('Method "' . $method . '" not found in class "' . $class . '"'); } } // Check user's permission if (!Users::getInstance()->checkAccess(P, $method)) { error('You do not have permissions to access this page ("' . P . ' - ' . $method . '")'); die; } // Call required method if ($call_object) { $obj = new $class(); $obj->{$method}(); } else { call_user_func([$class, $method]); } $this->content = ob_get_clean(); }
/** * Get values avaiable for column in table * @param string $table * @param string $column * @return array */ public static function getEnumPairs($table, $column) { $result = self::q_assoc_row('SHOW COLUMNS FROM `' . self::sql_prepare($table) . '` WHERE `field` = "' . self::sql_prepare($column) . '"'); $result = str_replace(["enum('", "')", "''"], ['', '', "'"], $result['Type']); $result = explode("','", $result); $res = []; foreach ($result as $v) { $res[$v] = Converter::symb2Ttl($v); } return $res; }
/** * Action for Upload files using uploader plugin with multiple files and partial uploads */ public function _upload_multiple() { $if_file_exists = $_GET['exists']; $extract_zips = isset($_GET['extract']) && $_GET['extract'] && class_exists('ZipArchive'); $allowed_extensions = isset($_GET['allowed_extensions']) ? array_filter(explode(',', $_GET['allowed_extensions'])) : []; // Current path in chage $dir = $_GET['path']; $tmp = explode('/', $dir); $dir = []; foreach ($tmp as $v) { if ($v) { $dir[] = $v; } } $dir = implode('/', $dir); if ($dir) { $dir .= '/'; } if ($dir && $dir[0] == '/') { $dir = substr($dir, 1); } $targetDir = DIR_BASE . $dir; // Get a file name if (isset($_REQUEST["name"])) { $fileName = $_REQUEST["name"]; } elseif (!empty($_FILES)) { $fileName = $_FILES["file"]["name"]; } else { $fileName = uniqid('file_'); } // Check file is allowed if ($allowed_extensions) { $ext = pathinfo($fileName, PATHINFO_EXTENSION); if (!in_array($ext, $allowed_extensions)) { error('Extension "' . $ext . '" is not allowed'); } } // $fileName = strtolower($fileName); $fileName = Converter::data2words(strtolower($fileName), ['@', '-', '_', '.']); $filePath = $targetDir . $fileName; // Behaviour if file already exists on server if (file_exists($filePath)) { switch ($if_file_exists) { default: case 'skip': // End upload ob_get_clean(); die('1'); case 'overwrite': // Do nothing - file will be overwritten break; case 'rename': // Generate new name $f_name = pathinfo($filePath, PATHINFO_FILENAME); $f_ext = pathinfo($filePath, PATHINFO_EXTENSION); $name_iterator = 1; while (is_file($filePath)) { $filePath = DIR_BASE . $dir . $f_name . '_' . $name_iterator . '.' . $f_ext; ++$name_iterator; } break; } } // Chunking might be enabled $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0; $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0; // Open temp file if (!($out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb"))) { error('Failed to open output stream.'); } if (!empty($_FILES)) { if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) { error('Failed to move uploaded file.'); } // Read binary input stream and append it to temp file if (!($in = @fopen($_FILES["file"]["tmp_name"], "rb"))) { error('Failed to open input stream.'); } } else { if (!($in = @fopen("php://input", "rb"))) { error('Failed to open input stream.'); } } // Save file from chunks while ($buff = fread($in, 4096)) { fwrite($out, $buff); } @fclose($out); @fclose($in); // Check if file has been uploaded if (!$chunks || $chunk == $chunks - 1) { // Strip the temp .part suffix off rename("{$filePath}.part", $filePath); } $extention = pathinfo($filePath, PATHINFO_EXTENSION); // Resizeimages and remove EXIF meta if (in_array($extention, ['jpg', 'jpeg', 'png', 'gif'])) { $image = new Image(); $image->open($filePath); list($width, $height) = getimagesize($filePath); if ($width > 4096) { // Maximim is for 4k screens 4096x3072 $w = 4096; $ratio = $width / $w; $h = $height / $ratio; $image->resize($w, $h); $image->save($filePath, $extention, 90); } } // Extract ZIPs if ($extract_zips && pathinfo($filePath, PATHINFO_EXTENSION) === 'zip') { // Unzip $zip = new ZipArchive(); $zip_open_result = $zip->open($filePath); if ($zip_open_result === true) { $zip->extractTo(rtrim($targetDir, '/')); $zip->close(); // Delete archive unlink($filePath); } else { dump('ZipArchive failed to open ' . $filePath . '. With error code - ' . $zip_open_result); } } ob_get_clean(); die('1'); }
<?php use TMCms\Admin\Structure\Entity\PageClickmap; use TMCms\Admin\Structure\Entity\PageClickmapRepository; use TMCms\Strings\Converter; if (!$_POST || !isset($_POST['x'], $_POST['y'], $_POST['l'])) { exit; } $period = 3600; // 1 hour $max_count = 600; $ip = Converter::ip2long(); $clickmap_points = new PageClickmapRepository(); $clickmap_points->setWhereIpLong($ip); $clickmap_points->addWhereFieldIsHigher('ts', NOW - $period); $count_of_clicks_for_period = $clickmap_points->getCountOfObjectsInCollection(); if ($count_of_clicks_for_period < $max_count) { $click = new PageClickmap(); $click->loadDataFromArray(['x' => (int) $_POST['x'], 'y' => (int) $_POST['y'], 'page_id' => (int) $_POST['l'], 'ip_long' => $ip])->save(); } exit;
private static function combineParamsFromDB($table, array $order_keys) { // Fields from DB $fields = $types = SQL::getFieldsWithAllData($table); unset($fields['id']); // Sort to match defined order for form $sorted = $not_sorted = []; foreach ($fields as $k => $v) { if (($key = array_search($k, $order_keys)) !== false) { $sorted[$key] = $k; } else { $not_sorted[] = $k; } } ksort($sorted); $fields = array_merge($sorted, $not_sorted); $params = []; foreach ($fields as $v) { $field = []; $type = $types[$v]['Type']; if (strpos($type, 'text') !== false) { $field['type'] = 'textarea'; } if (strpos($type, 'enum') !== false) { $field['type'] = 'select'; $field['options'] = SQL::getEnumPairs($table, $types[$v]['Field']); } $field['name'] = Converter::symb2Ttl($v); $params[$v] = $field; } return $params; }
/** * @param bool $download_as_file * @return string */ public function exportAsSerializedData($download_as_file = false) { if (!$this->getCollectedObjects()) { $this->collectObjects(false, true); } $objects = []; $object = NULL; foreach ($this->getCollectedObjects() as $object) { /** @var Entity $object */ $objects[] = $object; } if (!$objects) { error('No Objects selected'); } $data = []; $data['objects'] = serialize($objects); $data['class'] = Converter::getPathToClassFile($object); $data['class'] = str_replace(DIR_BASE, '', $data['class']); $data = serialize($data); if (!$download_as_file) { return $data; } FileSystem::streamOutput(Converter::classWithNamespaceToUnqualifiedShort($object) . '.cms_obj', $data); return $data; }
/** * Get top page header * @return string */ public function getMenuHeaderView() { if (!defined('USER_ID') || !USER_ID) { return ''; } ob_start(); // Notifications from system $notification_repository = new UsersMessageEntityRepository(); $notification_repository->setWhereToUserId(USER_ID); $notification_repository->setWhereFromUserId(0); $notification_repository->addOrderByField('ts', true); $notification_repository->setWhereSeen(0); $total_notifications = $notification_repository->getCountOfObjectsInCollection(); $notification_repository->setLimit(10); $notifications = $notification_repository->getAsArrayOfObjects(); // Messages from users $messages_repository = new UsersMessageEntityRepository(); $messages_repository->setWhereToUserId(USER_ID); $messages_repository->addWhereFieldIsNot('from_user_id', 0); $messages_repository->addOrderByField('ts', true); $messages_repository->setWhereSeen(0); $total_messages = $messages_repository->getCountOfObjectsInCollection(); $messages_repository->setLimit(10); $messages = $messages_repository->getAsArrayOfObjects(); // Custom notifiers // TODO $custom_notifiers = []; $custom_notifiers[] = $this->getHelpTextsNotifier(); // Logo image and link $logo = ''; if (array_key_exists('logo', Configuration::getInstance()->get('cms'))) { $logo = Configuration::getInstance()->get('cms')['logo']; } $logo_link = DIR_CMS_URL; if (array_key_exists('logo_link', Configuration::getInstance()->get('cms'))) { $logo_link = Configuration::getInstance()->get('cms')['logo_link']; } $user_avatar = Users::getInstance()->getUserData('avatar'); if (!$user_avatar) { $user_avatar = '/vendor/devp-eu/tmcms-core/src/assets/cms/layout/img/avatar.png'; } $languages = AdminLanguages::getPairs(); $current_language = Users::getInstance()->getUserLng(); ?> <div class="page-header-inner"> <?php if ($logo) { ?> <div class="page-logo"> <a href="<?php echo $logo_link; ?> "> <img src="<?php echo $logo; ?> " alt="logo" class="logo-default"> </a> <div class="menu-toggler sidebar-toggler"></div> </div> <?php } ?> <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse"></a> <div class="top-menu"> <ul class="nav navbar-nav pull-right"> <li class="dropdown dropdown-extended dropdown-home" id="header_home_bar"> <a href="/" target="_blank" class="dropdown-toggle" data-hover="dropdown" data-close-others="true"> <i class="icon-home"></i> </a> </li> <?php if (count($languages) > 1) { ?> <li class="dropdown dropdown-language"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php echo LNG; ?> .png"> <span class="langname"><?php echo strtoupper(LNG); ?> </span> <i class="fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <?php foreach ($languages as $k => $v) { if ($k == LNG) { continue; } ?> <li> <a href="?p=users&do=_change_lng&lng=<?php echo $k; ?> "> <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php echo $k; ?> .png"> <?php echo $v; ?> </a> </li> <?php } ?> </ul> </li> <?php } ?> <?php if ($notifications) { ?> <li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <i class="icon-bell"></i> <span class="badge badge-default"><?php echo count($notifications); ?> </span> </a> <ul class="dropdown-menu"> <li> <p> You have <?php echo $total_notifications; ?> new notifications </p> </li> <li> <ul class="dropdown-menu-list scroller" style="height: 250px;"> <?php foreach ($notifications as $k => $message) { /** @var UsersMessageEntity $message */ ?> <li> <a href="#"> <span class="label label-sm label-icon label-warning"> <i class="fa fa-bell-o"></i> </span> <?php echo $message->getMessage(); ?> <span class="time"> <?php echo Converter::getTimeFromEventAgo($message->getTs()); ?> </span> </a> </li> <?php } ?> </ul> </li> <li class="external"> <a href="?p=home&do=notifications"> See all notifications <i class="m-icon-swapright"></i> </a> </li> </ul> </li> <?php } ?> <?php if ($messages) { ?> <li class="dropdown dropdown-extended dropdown-inbox" id="header_inbox_bar"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <i class="icon-envelope-open"></i> <span class="badge badge-default"><?php echo count($messages); ?> </span> </a> <ul class="dropdown-menu"> <li> <p> You have <?php echo $total_messages; ?> new messages </p> </li> <li> <ul class="dropdown-menu-list scroller" style="height: 250px;"> <?php foreach ($notifications as $k => $message) { /** @var UsersMessageEntity $message */ $user = new AdminUser($message->getFromUserId()); $avatar = $user->getAvatar(); ?> <li> <a href="?p=users&do=chat&user_id=2"> <?php if ($avatar) { ?> <span class="photo"> <img src="<?php echo $avatar; ?> " alt="" style="height=40px"> </span> <?php } ?> <span class="subject"> <span class="from"><?php echo $user->getName(); ?> </span> <span class="time"><?php echo Converter::getTimeFromEventAgo($message->getTs()); ?> </span> </span> <span class="message"><?php echo Converter::cutLongStrings($message->getMessage()); ?> </span> </a> </li> <?php } ?> </ul> </li> <li class="external"> <a href="?p=users&do=chat"> See all messages <i class="m-icon-swapright"></i> </a> </li> </ul> </li> <?php } ?> <?php if ($custom_notifiers) { ?> <?php echo implode('', $custom_notifiers); ?> <?php } ?> <li class="dropdown dropdown-user"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> <img alt="" class="img-circle" src="<?php echo $user_avatar; ?> " style="height: 29px;"> <span class="username"><?php echo Users::getInstance()->getUserData('name'); ?> </span> <i class="fa fa-angle-down"></i> </a> <ul class="dropdown-menu"> <li> <a href="?p=users&do=users_edit&id=<?php echo USER_ID; ?> "> <i class="icon-user"></i> My Profile </a> </li> <li> <a href="?p=home&do=notifications"> <i class="icon-envelope-open"></i>My notifications <span class="badge badge-danger"> <?php echo count($notifications); ?> </span> </a> </li> <li class="divider"></li> <li> <a href="#" onclick="clipboard_forms.copy_page_forms(); return false;"> <i class="icon-cloud-download"></i>Copy form data </a> </li> <li> <a href="#" onclick="clipboard_forms.paste_page_forms(); return false;"> <i class="icon-cloud-upload"></i>Paste form data </a> </li> <li class="divider"></li> <li> <a href="?p=home&do=_exit" onclick="return confirm('<?php echo __('Are you sure?'); ?> ');"> <i class="icon-key"></i> Log Out </a> </li> </ul> </li> <?php // TODO right panel ?> <!-- <li class="dropdown dropdown-quick-sidebar-toggler">--> <!-- <a href="javascript:;" class="dropdown-toggle">--> <!-- <i class="icon-logout"></i>--> <!-- </a>--> <!-- </li>--> </ul> </div> </div> <?php return ob_get_clean(); }
private function getRealEntityName($entity = NULL) { if (!$entity) { $entity = $this->getRealEntityInUse(); } return Converter::classWithNamespaceToUnqualifiedShort($entity); }