public static function getSubmenuItems() { $submenuItems = ipFilter('ipAdminSystemSubmenu', array()); if (!$submenuItems) { if (ipRoute()->controller() == 'AdminController' && class_exists(ipRoute()->controllerClass())) { $submenuItems = self::getControllerMenu(ipRoute()->controllerClass()); } } return $submenuItems; }
/** * Get all user info collected from all user specific plugins. * @param int $userId * @return array */ function data($userId = null) { if ($userId === null) { $userId = $this->userId(); } if (!$userId) { return array(); } $info = array('userId' => $userId); $data = array('id' => $userId); return ipFilter('ipUserData', $data, $info); }
/** * Get list of all available permissions on the system */ public static function availablePermissions() { $permissions = array('Super admin', 'Content', 'Pages', 'Design', 'Plugins', 'Config', 'Config advanced', 'Languages', 'System', 'Administrators', 'Log', 'Email', 'Repository', 'Repository upload'); $plugins = \Ip\Internal\Plugins\Model::getActivePluginNames(); foreach ($plugins as $plugin) { if (is_file(ipFile('Plugin/' . $plugin . '/AdminController.php'))) { array_push($permissions, $plugin); } } $permissions = ipFilter('ipAvailablePermissions', $permissions); return $permissions; }
public function comments() { $langs = ipContent()->getLanguages(); $langs_values = array(); if (!empty($langs)) { foreach ($langs as $key => $val) { $langs_values[] = array($val->getId(), $val->getTitle()); } } $config = array('title' => __('Comments', 'Comments'), 'table' => 'comments', 'deleteWarning' => __('Do you really want to delete this item?', 'Comments'), 'sortField' => 'createdAt', 'sortDirection' => 'desc', 'createPosition' => 'top', 'pageSize' => 6, 'fields' => array(array('label' => __('Page I', 'ClassesEnroll'), 'type' => 'Tab'), array('label' => __('Page', 'Comments'), 'field' => 'zone_name', 'validators' => array('Required')), array('label' => __('User Id', 'Comments'), 'field' => 'user_id', 'preview' => false), array('label' => __('Name', 'Comments'), 'field' => 'name', 'validators' => array('Required')), array('label' => __('Email', 'Comments'), 'field' => 'email', 'validators' => array('Required', 'Email')), array('label' => __('Page II', 'ClassesEnroll'), 'type' => 'Tab'), array('label' => __('Link', 'Comments'), 'field' => 'link', 'preview' => false), array('type' => 'Textarea', 'label' => __('Comment', 'Comments'), 'field' => 'text', 'validators' => array('Required'), 'preview' => false), array('label' => __('IP', 'Comments'), 'field' => 'ip', 'validators' => array('Required'), 'preview' => false), array('label' => __('Modified at', 'Comments'), 'field' => 'modifiedAt', 'allowCreate' => false, 'allowUpdate' => true, 'preview' => false, 'transformations' => array('\\Plugin\\Comments\\Transformation\\MySqlTimestampNow')), array('label' => __('Page III', 'ClassesEnroll'), 'type' => 'Tab'), array('type' => 'Select', 'label' => __('Approved', 'Comments'), 'field' => 'approved', 'values' => array(array('0', 'No'), array('1', 'Yes')), 'validators' => array('Required')), array('label' => __('Session', 'Comments'), 'field' => 'session_id', 'validators' => array('Required'), 'allowCreate' => true, 'allowUpdate' => false, 'defaultValue' => '1-internal', 'preview' => false), array('label' => __('Verification Code', 'Comments'), 'field' => 'verification_code', 'validators' => array('Required'), 'allowCreate' => true, 'allowUpdate' => false, 'defaultValue' => '1-internal', 'preview' => false), array('type' => 'Select', 'label' => __('Active', 'Comments'), 'field' => 'active', 'values' => array(array('0', 'No'), array('1', 'Yes')), 'validators' => array('Required')), array('type' => 'Select', 'label' => __('Language', 'Comments'), 'field' => 'language_id', 'values' => $langs_values, 'validators' => array('Required'), 'preview' => false))); $config = ipFilter('Comments_commentsConfig', $config); return ipGridController($config); }
/** * Render page block content * @param int $revisionId * @return string */ public function render($revisionId = 0) { $data = array('blockName' => $this->name); $content = ipJob('ipGenerateBlock', $data); if ($content) { if (is_object($content) && method_exists($content, 'render')) { $content = $content->render(); } return (string) $content; } else { $content = $this->generateBlockHtml($revisionId); } return ipFilter('ipBlockContent', $content, $data); }
public function hasPermission($permission, $administratorId = null) { if (in_array($permission, array('InlineManagement'))) { $permission = 'Content'; } if ($administratorId == null) { $administratorId = ipAdminId(); } if (!isset($this->permissions[$administratorId])) { $this->permissions[$administratorId] = AdminPermissionsModel::getUserPermissions($administratorId); } $answer = isset($this->permissions[$administratorId][$permission]) || isset($this->permissions[$administratorId]['Super admin']); $answer = ipFilter('ipAdminPermission', $answer, array('permission' => $permission, 'administratorId' => $administratorId)); return $answer; }
public function pluginPropertiesForm() { $pluginName = ipRequest()->getQuery('pluginName'); if (!$pluginName) { throw new \Ip\Exception('Missing required parameters'); } $variables = array('plugin' => Helper::getPluginData($pluginName)); if (in_array($pluginName, Model::getActivePluginNames())) { $variables['form'] = Helper::pluginPropertiesForm($pluginName); } $variables['icon'] = $this->pluginIcon($pluginName); $layout = ipView('view/pluginProperties.php', $variables)->render(); $layout = ipFilter('ipPluginPropertiesHtml', $layout, array('pluginName' => $pluginName)); $data = array('html' => $layout); return new \Ip\Response\Json($data); }
public static function ipBeforeController() { //show admin submenu if needed if (ipRoute()->isAdmin()) { ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js'); ipAddCss('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.css'); $submenu = Submenu::getSubmenuItems(); $submenu = ipFilter('ipAdminSubmenu', $submenu); if ($submenu) { ipResponse()->setLayoutVariable('submenu', $submenu); } } // Show admin toolbar if admin is logged in: if (ipAdminId() && !ipRequest()->getRequest('pa') || ipRequest()->getRequest('aa') && ipAdminId()) { if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableAdminNavbar')) { ipAddJs('Ip/Internal/Admin/assets/admin.js'); ipAddJsVariable('ipAdminNavbar', static::getAdminNavbarHtml()); } } // Show popup with autogenerated user information if needed $adminIsAutogenerated = ipStorage()->get('Ip', 'adminIsAutogenerated'); if ($adminIsAutogenerated) { $adminId = \Ip\Internal\Admin\Backend::userId(); $admin = \Ip\Internal\Administrators\Model::getById($adminId); ipAddJs('Ip/Internal/Admin/assets/adminIsAutogenerated.js'); $data = array('adminUsername' => $admin['username'], 'adminPassword' => ipStorage()->get('Ip', 'adminIsAutogenerated'), 'adminEmail' => $admin['email']); ipAddJsVariable('ipAdminIsAutogenerated', ipView('view/adminIsAutoGenerated.php', $data)->render()); } if (ipContent()->getCurrentPage()) { // initialize management if (ipIsManagementState()) { if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableManagement')) { \Ip\Internal\Content\Helper::initManagement(); } } //show page content $response = ipResponse(); $response->setDescription(\Ip\ServiceLocator::content()->getDescription()); $response->setKeywords(ipContent()->getKeywords()); $response->setTitle(ipContent()->getTitle()); } }
/** * @param string $currentModule Name of the current (active) module * @return \Ip\Internal\Admin\MenuItem[] */ public function getAdminMenuItems($currentModule) { $answer = array(); $modules = \Ip\Internal\Plugins\Model::getModules(); foreach ($modules as $module) { // skipping modules that don't have 'index' (default) action in AdminController $controllerClass = 'Ip\\Internal\\' . $module . '\\AdminController'; if (!class_exists($controllerClass) || !method_exists($controllerClass, 'index')) { continue; } $moduleItem = new \Ip\Internal\Admin\MenuItem(); $moduleItem->setTitle(__($module, 'Ip-admin', false)); $moduleItem->setUrl(ipActionUrl(array('aa' => $module . '.index'))); $moduleItem->setIcon($this->getAdminMenuItemIcon($module)); if ($module == $currentModule) { $moduleItem->markAsCurrent(true); } if (ipAdminPermission($module)) { $answer[] = $moduleItem; } } $plugins = \Ip\Internal\Plugins\Service::getActivePlugins(); foreach ($plugins as $plugin) { $controllerClass = '\\Plugin\\' . $plugin['name'] . '\\AdminController'; if (!class_exists($controllerClass) || !method_exists($controllerClass, 'index')) { continue; } $moduleItem = new \Ip\Internal\Admin\MenuItem(); $moduleItem->setTitle(__($plugin['title'], 'Ip-admin', false)); $moduleItem->setUrl(ipActionUrl(array('aa' => $plugin['name']))); $moduleItem->setIcon($this->getAdminMenuItemIcon($plugin['name'])); if ($plugin['name'] == $currentModule) { $moduleItem->markAsCurrent(true); } if (ipAdminPermission($plugin['name'])) { $answer[] = $moduleItem; } } $answer = ipFilter('ipAdminMenu', $answer); return $answer; }
public function getPages() { $data = ipRequest()->getRequest(); if (empty($data['languageId'])) { throw new \Ip\Exception("Missing required parameters"); } $language = ipContent()->getLanguage($data['languageId']); if (!$language) { throw new \Ip\Exception("Language doesn't exist. " . $data['languageId']); } $languageCode = $language->getCode(); if (empty($data['menuName'])) { throw new \Ip\Exception("Missing required parameters"); } $menuName = $data['menuName']; $parentId = ipDb()->selectValue('page', 'id', array('languageCode' => $languageCode, 'alias' => $menuName, 'isDeleted' => 0)); $tree = JsTreeHelper::getPageTree($languageCode, $parentId); $tree = ipFilter('ipPageTree', $tree, array('languageCode' => $languageCode, 'parentId' => $parentId)); $responseData = array('tree' => $tree); return new \Ip\Response\Json($responseData); }
public function subscriptionPaymentSelection($key) { $data = Model::getPaymentData($key); $paymentMethods = Model::collectSubscriptionPaymentMethods($data); $paymentMethodName = ipRequest()->getPost('paymentMethod'); if ($paymentMethodName) { //redirect to selected payment page foreach ($paymentMethods as $paymentMethod) { if ($paymentMethod->name() == $paymentMethodName) { $paymentUrl = $paymentMethod->paymentUrl($data['data']); return new \Ip\Response\Json(array('redirect' => $paymentUrl)); } } } //display all available payment methods ipAddJs('assets/paymentSelection.js'); ipAddCss('assets/payments.css'); $response = ipView('view/selectPayment.php', array('paymentMethods' => $paymentMethods)); $response = ipFilter('ipSubscriptionPaymentSelectPageResponse', $response, array('paymentKey' => $key)); return $response; }
/** * Handle uploads made using PlUpload library * @param bool $secureFolder * @throws \Ip\Exception\Repository\Upload */ public function handlePlupload($secureFolder) { if (!$secureFolder && !ipAdminId()) { throw new \Ip\Exception\Repository\Upload("Trying to upload image to temporary directory without permission."); } if ($secureFolder) { $targetDir = ipFile('file/secure/tmp/'); } else { $targetDir = ipFile('file/tmp/'); } if ($secureFolder) { $sizeLimit = ipGetOption('Repository.publicUploadLimit', 4000); if ($this->folderSize($targetDir) > $sizeLimit * 1000000) { //4000 Mb by default ipLog()->error("Repository.publicUploadLimitReached: IP: `{ip}`. CurrentLimit `{limit}Mb`. Please update Repository.publicUploadLimit option to increase the limits.", array('ip' => $_SERVER['REMOTE_ADDR'], 'limit' => $sizeLimit)); throw new \Ip\Exception("Upload limit reached"); } } // Get parameters $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; // Clean the fileName for security reasons $fileName = \Ip\Internal\File\Functions::cleanupFileName($fileName); // Make sure the fileName is unique but only if chunking is disabled if ($chunks < 2 && file_exists($targetDir . $fileName)) { $fileName = \Ip\Internal\File\Functions::genUnoccupiedName($fileName, $targetDir); } //security check $fileExtension = strtolower(substr($fileName, strrpos($fileName, '.') + 1)); $whiteListExtensions = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'asf', 'asx', 'wmv', 'wmx', 'wm', 'avi', 'divx', 'flv', 'mov', 'qt', 'mpeg', 'mpg', 'mpe', 'mp4', 'm4v', 'ogv', 'webm', 'mkv', 'txt', 'asc', 'c', 'cc', 'h', 'csv', 'tsv', 'ics', 'rtx', 'css', 'htm', 'html', 'vtt', 'mp3', 'm4a', 'm4b', 'ra', 'ram', 'wav', 'ogg', 'oga', 'mid', 'midi', 'wma', 'wax', 'mka', 'rtf', 'js', 'pdf', 'class', 'tar', 'zip', 'gz', 'gzip', 'rar', '7z', 'doc', 'pot', 'pps', 'ppt', 'wri', 'xla', 'xls', 'xlt', 'xlw', 'mdb', 'mpp', 'docx', 'docm', 'dotx', 'dotm', 'eps', 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xlam', 'pptx', 'pptm', 'ppsx', 'ppsm', 'potx', 'potm', 'ppam', 'sldx', 'sldm', 'onetoc', 'onetoc2', 'onetmp', 'onepkg', 'odt', 'odp', 'ods', 'odg', 'odc', 'odb', 'odf', 'wp', 'wpd', 'key', 'numbers', 'pages', 'xml', 'json', 'iso', 'aac', 'img', 'psd', 'ai', 'sql', 'swf', 'svg'); $whiteListExtensions = ipFilter('ipWhiteListExtensions', $whiteListExtensions); if (!empty($fileExtension) && !in_array($fileExtension, $whiteListExtensions)) { //security risk throw new \Ip\Exception\Repository\Upload\ForbiddenFileExtension("Files with extension (." . esc($fileExtension) . ") are not permitted for security reasons.", array('extension' => $fileExtension, 'filename' => $fileName)); } //end security check // Look for the content type header $contentType = null; if (isset($_SERVER["HTTP_CONTENT_TYPE"])) { $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; } if (isset($_SERVER["CONTENT_TYPE"])) { $contentType = $_SERVER["CONTENT_TYPE"]; } // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 if (strpos($contentType, "multipart") !== false) { if (!isset($_FILES['file']['tmp_name']) || !is_uploaded_file($_FILES['file']['tmp_name'])) { throw new \Ip\Exception\Repository\Upload("Failed to move uploaded file."); } // Open temp file $out = fopen($targetDir . $fileName, $chunk == 0 ? "wb" : "ab"); if (!$out) { throw new \Ip\Exception\Repository\Upload("Failed to open output stream."); } //mark this file as uploaded by current user $this->setFileUploadedByThisUser($targetDir . $fileName); // Read binary input stream and append it to temp file $in = fopen($_FILES['file']['tmp_name'], "rb"); if (!$in) { throw new \Ip\Exception\Repository\Upload("Failed to open input stream."); } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } fclose($in); fclose($out); @unlink($_FILES['file']['tmp_name']); } else { // Open temp file $out = fopen($targetDir . '/' . $fileName, $chunk == 0 ? "wb" : "ab"); if (!$out) { throw new \Ip\Exception\Repository\Upload("Failed to open output stream."); } // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if (!$in) { throw new \Ip\Exception\Repository\Upload("Failed to open input stream."); } while ($buff = fread($in, 4096)) { if (function_exists('set_time_limit')) { set_time_limit(30); } fwrite($out, $buff); } fclose($in); fclose($out); } $this->uploadedFileName = $fileName; $this->uploadedFile = $targetDir . $fileName; $this->targetDir = $targetDir; }
/** * @param $paymentData * @return \Ip\SubscriptionPayment[] */ public static function collectSubscriptionPaymentMethods($paymentData) { return ipFilter('ipSubscriptionPaymentMethods', array(), $paymentData); }
public function generateJavascript() { $cacheVersion = $this->getCacheVersion(); $javascriptFiles = $this->getJavascript(); $javascriptFilesSorted = array(); foreach ($javascriptFiles as $level) { foreach ($level as &$file) { if ($file['type'] == 'file' && $file['cacheFix']) { $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion; } } $javascriptFilesSorted = array_merge($javascriptFilesSorted, $level); } $revision = $this->getCurrentRevision(); $page = ipContent()->getCurrentPage(); $javascriptFilesSorted = ipFilter('ipJs', $javascriptFilesSorted); $language = ipContent()->getCurrentLanguage(); $data = array('ip' => array('baseUrl' => ipConfig()->baseUrl(), 'safeMode' => \Ip\Internal\Admin\Service::isSafeMode(), 'languageId' => $language->getId(), 'languageUrl' => $language->getLink(), 'languageCode' => $language->getCode(), 'languageTextDirection' => $language->getTextDirection(), 'theme' => ipConfig()->theme(), 'pageId' => $page ? $page->getId() : null, 'revisionId' => $revision['revisionId'], 'securityToken' => \Ip\ServiceLocator::application()->getSecurityToken(), 'developmentEnvironment' => ipConfig()->isDevelopmentEnvironment(), 'debugMode' => ipconfig()->isDebugMode(), 'isManagementState' => ipIsManagementState(), 'isAdminState' => ipAdminId() ? 1 : 0, 'isAdminNavbarDisabled' => ipRequest()->getQuery('disableAdminNavbar') ? 1 : 0), 'javascriptVariables' => $this->getJavascriptVariables(), 'javascript' => $javascriptFilesSorted); $javascript = ipView('Ip/Internal/Config/view/javascript.php', $data)->render(); $javascript = ipFilter('ipJavaScript', $javascript); return $javascript; }
/** * Read theme config and create theme entity * @param $name * @param null $dir * @param null $url * @return Theme * @throws \Exception */ public function getTheme($name, $dir = null, $url = null) { if ($dir == null) { $dir = ipFile('Theme/'); } $metadata = new ThemeMetadata(); $metadata->setName($name); //new type config $themeJsonFile = $dir . $name . '/' . self::INSTALL_DIR . 'Theme.json'; if (file_exists($themeJsonFile)) { $config = $this->parseThemeJson($themeJsonFile); } else { $themeJsonFile = $dir . $name . '/' . self::INSTALL_DIR . 'theme.json'; if (file_exists($themeJsonFile)) { $config = $this->parseThemeJson($themeJsonFile); } else { $config = array(); } } $config = ipFilter('ipThemeConfig', $config); $metadata->setTitle(!empty($config['title']) ? $config['title'] : $name); if (!empty($config['author'])) { $metadata->setAuthorTitle($config['author']); } if (!empty($config['version'])) { $metadata->setVersion($config['version']); } if (!empty($config['thumbnail'])) { $metadata->setThumbnail($config['thumbnail']); } if (!empty($url)) { $metadata->setUrl($url); } if (!empty($config['doctype']) && defined('\\Ip\\View::' . $config['doctype'])) { $metadata->setDoctype('DOCTYPE_' . $config['doctype']); } else { $metadata->setDoctype('DOCTYPE_HTML5'); } if (!empty($config['options'])) { $metadata->setOptions($config['options']); } if (!empty($config['widget'])) { $metadata->setWidgetOptions($config['widget']); } $theme = new Theme($metadata); return $theme; }
public static function savePluginOptions($pluginName, $data) { $form = self::pluginPropertiesForm($pluginName); $errors = $form->validate($data); if ($errors) { return $errors; } ipFilter('ipPluginSaveOptions', $data, array('pluginName' => $pluginName)); //for internal use only. Don't use in your plugins as it is going to change return true; }
/** * @return \Ip\WidgetController[] */ public static function getAvailableWidgetObjects() { if (self::$widgetObjects !== null) { return self::$widgetObjects; } self::$widgetObjects = ipFilter('ipWidgets', array()); return self::$widgetObjects; }
public static function pagePropertiesForm($pageId) { $page = new \Ip\Page($pageId); $form = new \Ip\Form(); $form->setEnvironment(\Ip\Form::ENVIRONMENT_ADMIN); $field = new \Ip\Form\Field\Hidden(array('name' => 'aa', 'value' => 'Pages.updatePage')); $form->addField($field); $field = new \Ip\Form\Field\Hidden(array('name' => 'pageId', 'value' => $pageId)); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'title', 'label' => __('Title', 'Ip-admin', false), 'value' => $page->getTitle())); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'urlPath', 'label' => __('URL path', 'Ip-admin', false), 'value' => $page->getUrlPath())); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'isVisible', 'label' => __('Visible', 'Ip-admin', false), 'value' => $page->isVisible())); $form->addField($field); $layouts = \Ip\Internal\Design\Service::getLayouts(); $options = array(); foreach ($layouts as $layout) { $options[] = array($layout, $layout); } $field = new \Ip\Form\Field\Select(array('name' => 'layout', 'label' => __('Layout', 'Ip-admin', false), 'values' => $options, 'value' => $page->getLayout())); $form->addField($field); $fieldset = new \Ip\Form\Fieldset(__('Seo', 'Ip-admin', false)); $form->addFieldset($fieldset); $field = new \Ip\Form\Field\Text(array('name' => 'metaTitle', 'label' => __('Meta title', 'Ip-admin', false), 'value' => $page->getMetaTitle())); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'keywords', 'label' => __('Keywords', 'Ip-admin', false), 'value' => $page->getKeywords())); $form->addField($field); $field = new \Ip\Form\Field\Textarea(array('name' => 'description', 'label' => __('Description', 'Ip-admin', false), 'value' => $page->getDescription())); $form->addField($field); $fieldset = new \Ip\Form\Fieldset(__('Other', 'Ip-admin', false)); $form->addFieldset($fieldset); $field = new \Ip\Form\Field\Url(array('name' => 'redirectUrl', 'label' => __('Redirect', 'Ip-admin', false), 'value' => $page->getRedirectUrl())); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'isDisabled', 'label' => __('Disabled', 'Ip-admin', false), 'value' => $page->isDisabled(), 'note' => __('Won\'t be clickable in menu if selected.', 'Ip-admin', false))); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'isSecured', 'label' => __('Secured', 'Ip-admin', false), 'value' => $page->isSecured(), 'note' => __('Won\'t be accessible to view even knowing the URL.', 'Ip-admin', false))); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'isBlank', 'label' => __('Open in new window', 'Ip-admin', false), 'value' => $page->isBlank())); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'alias', 'label' => __('Alias (used in code)', 'Ip-admin', false), 'value' => $page->getAlias())); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'createdAt', 'label' => __('Created on', 'Ip-admin', false), 'value' => date('Y-m-d', strtotime($page->getCreatedAt())))); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'updatedAt', 'label' => __('Updated on', 'Ip-admin', false), 'value' => date('Y-m-d', strtotime($page->getUpdatedAt())))); $form->addField($field); $form = ipFilter('ipPagePropertiesForm', $form, array('pageId' => $pageId)); return $form; }
private function createReflectionRecord($source, $options, $desiredName) { $absoluteSource = realpath(ipFile('file/repository/' . $source)); if (!$absoluteSource || !is_file($absoluteSource)) { throw new \Ip\Exception\Repository\Transform("File doesn't exist", array('filename' => $absoluteSource)); } if (strpos($absoluteSource, realpath(ipFile('file/repository/'))) !== 0) { throw new \Exception("Requested file (" . $source . ") is outside repository dir"); } //if desired name ends with .jpg, .gif, etc., remove extension $desiredPathInfo = pathinfo($desiredName); if (!empty($desiredPathInfo['filename']) && isset($desiredPathInfo['extension']) && strlen($desiredPathInfo['extension']) <= 4) { $desiredName = $desiredPathInfo['filename']; } //update destination file extension $pathInfo = pathinfo($absoluteSource); if (isset($pathInfo['extension'])) { $ext = $pathInfo['extension']; } else { $ext = ''; } $ext = ipFilter('ipReflectionExtension', $ext, array('source' => $absoluteSource, 'options' => $options)); if ($desiredName == '') { $pathInfo = pathinfo($absoluteSource); $desiredName = $pathInfo['filename']; } if ($ext != '') { $desiredName = $desiredName . '.' . $ext; } $desiredName = \Ip\Internal\File\Functions::cleanupFileName($desiredName); //remove double dots if file name. For security reasons. $relativeDestinationPath = date('Y/m/d/'); $relativeDestinationPath = ipFilter('ipRepositoryNewReflectionFileName', $relativeDestinationPath, array('originalFile' => $source, 'options' => $options, 'desiredName' => $desiredName)); $destinationFileName = $this->getUnocupiedName($desiredName, $relativeDestinationPath); $reflection = $relativeDestinationPath . $destinationFileName; $this->storeReflectionRecord($source, $reflection, $options); return $reflection; }
public function updateConfig() { ipRequest()->mustBePost(); $configModel = ConfigModel::instance(); $form = $configModel->getThemeConfigForm(ipConfig()->theme()); $post = ipRequest()->getPost(); $errors = $form->validate($post); if ($errors) { return JsonRpc::error('Invalid form'); } $configModel = ConfigModel::instance(); $model = Model::instance(); $theme = $model->getTheme(ipConfig()->theme()); if (!$theme) { throw new \Ip\Exception("Theme doesn't exist"); } $options = $theme->getOptionsAsArray(); $valuesToStore = array(); foreach ($options as $option) { if (empty($option['name'])) { continue; } $field = $form->getField($option['name']); if (!$field) { continue; } switch ($option['type']) { case 'checkbox': /** * @var \Ip\Form\Field\Checkbox $field */ $value = $field->isChecked($post, $option['name']); break; case 'RepositoryFile': $value = ''; if (!empty($post[$option['name']][0])) { $value = $post[$option['name']][0]; } break; default: $value = $field->getValueAsString($post, $option['name']); } $valuesToStore[$option['name']] = $value; } $valuesToStore = ipFilter('ipDesignOptionsSave', $valuesToStore); foreach ($valuesToStore as $key => $value) { $configModel->setConfigValue(ipConfig()->theme(), $key, $value); } $lessCompiler = LessCompiler::instance(); $lessCompiler->rebuild(ipConfig()->theme()); \Ip\Internal\Core\Service::invalidateAssetCache(); ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml()); return JsonRpc::result(true); }
/** * Checks if there are some emails waiting in queue and sends them if possible. */ function send() { $alreadySent = Db::sentOrLockedCount(60); if ($alreadySent !== false) { $available = floor(ipGetOption('Email.hourlyLimit') * 0.8 - $alreadySent); //20% for immediate emails $lockKey = md5(uniqid(rand(), true)); if ($available > 0) { if ($available > 5 && !defined('CRON')) { //only cron job can send many emails at once. $available = 5; } $locked = Db::lock($available, $lockKey); } else { $available = 0; $locked = 0; } if ($locked == $available) { //if in queue left some messages if (ipGetOption('Email.hourlyLimit') - ($alreadySent + $available) > 0) { $locked = $locked + Db::lockOnlyImmediate(ipGetOption('Email.hourlyLimit') - ($alreadySent + $available), $lockKey); } } if ($locked) { $emails = Db::getLocked($lockKey); foreach ($emails as $key => $email) { if (function_exists('set_time_limit')) { set_time_limit((sizeof($emails) - $key) * 10 + 100); } $mail = new \PHPMailer(); /* $mail->Sender = $email['from']; $mail->addCustomHeader("Return-Path: " . $email['from']);*/ $mail->From = $email['from']; $mail->FromName = $email['fromName']; $mail->AddReplyTo($email['from'], $email['fromName']); $mail->WordWrap = 50; // set word wrap $mail->CharSet = ipConfig()->get('charset'); $mail->Subject = $email['subject']; /* foreach($this->posted_files as $file){ if(isset($_FILES[$file]['tmp_name']) && $_FILES[$file]['error'] == 0){ $mail->AddAttachment($_FILES[$file]['tmp_name'], $_FILES[$file]['name']); } }*/ $files = explode("\n", $email['files']); $fileNames = explode("\n", $email['fileNames']); $fileMimeTypes = explode("\n", $email['fileMimeTypes']); $fileCount = min(count($files), count($fileNames), count($fileMimeTypes)); for ($i = 0; $i < $fileCount; $i++) { if ($files[$i] != '') { if ($fileMimeTypes[$i] == '') { $answer = $mail->AddAttachment($files[$i], $fileNames[$i]); } else { $answer = $mail->AddAttachment($files[$i], $fileNames[$i], "base64", $fileMimeTypes[$i]); } if (!$answer) { ipLog()->error('Email.addAttachmentFailed: {subject} to {to}', array('to' => $email['to'], 'subject' => $email['subject'], 'filename' => $fileNames[$i])); return false; } } } if ($email['html']) { $mail->IsHTML(true); // send as HTML $mail->MsgHTML($email['email']); try { $altBody = \Ip\Internal\Text\Html2Text::convert($email['email']); } catch (\Ip\Internal\Text\Html2TextException $e) { $altBody = $email['email']; } $mail->AltBody = $altBody; } else { /*$h2t = new \Ip\Internal\Text\Html2Text($content, false); $mail->Body = $h2t->get_text();*/ $mail->Body = $email['email']; } $mail->AddAddress($email['to'], $email['toName']); $mail = ipFilter('ipSendEmailPHPMailerObject', $mail, $email); if (!$mail->Send()) { ipLog()->error('Email.sendFailed: {subject} to {to}', array('to' => $email['to'], 'subject' => $email['subject'], 'body' => $email['email'])); return false; } if (sizeof($emails) > 5) { sleep(1); } Db::unlockOne($email['id']); } } } return null; }
/** * Get a breadcrumb * * Gets an array of pages representing a tree path to a current page. * * @param int $pageId * @return \Ip\Page[] */ public function getBreadcrumb($pageId = null) { if ($pageId !== null) { $page = new \Ip\Page($pageId); } else { $page = ipContent()->getCurrentPage(); } if ($page) { $pages[] = $page; $parentPageId = $page->getParentId(); while (!empty($parentPageId)) { $parentPage = new \Ip\Page($parentPageId); $pages[] = $parentPage; $parentPageId = $parentPage->getParentId(); } } $breadcrumb = array(); if (!empty($pages)) { array_pop($pages); $breadcrumb = $pages; } $breadcrumb = array_reverse($breadcrumb); $breadcrumb = ipFilter('ipBreadcrumb', $breadcrumb); return $breadcrumb; }
public static function ipReplacePlaceholders($info) { $content = $info['content']; $userData = ipUser()->data(); $userEmail = !empty($userData['email']) ? $userData['email'] : ''; $userName = !empty($userData['name']) ? $userData['name'] : ''; $values = array('{websiteTitle}' => ipGetOptionLang('Config.websiteTitle'), '{websiteEmail}' => ipGetOptionLang('Config.websiteEmail'), '{websiteUrl}' => ipConfig()->baseUrl(), '{userId}' => ipUser()->userId(), '{userEmail}' => $userEmail, '{userName}' => $userName); foreach ($info['customValues'] as $key => $value) { $values['{' . $key . '}'] = $value; } $values = ipFilter('ipReplacePlaceholdersValues', $values, $info); $answer = strtr($content, $values); $answer = ipFilter('ipReplacePlaceholders', $answer, $info); return $answer; }
/** * @ignore * @param \Ip\Response $response * @throws \Ip\Exception */ public function handleResponse(\Ip\Response $response) { $response = ipFilter('ipSendResponse', $response); ipEvent('ipBeforeResponseSent', array('response' => $response)); if (method_exists($response, 'execute')) { $response = $response->execute(); } $response->send(); }
/** * @return \Ip\Form\Field[] */ private static function collectFieldTypes() { self::$fields = ipFilter('ipWidgetFormFieldTypes', array()); }