/** * Execute response and return html response * * @return \Ip\Response */ public function execute() { ipContent()->setBlockContent('main', $this->content); $layout = $this->getLayout(); if ($layout[0] == '/' || $layout[1] == ':') { // Check if absolute path: '/' for unix, 'C:' for windows $viewFile = $layout; if (!is_file($viewFile)) { $viewFile = ipThemeFile('main.php'); } } elseif (strpos($layout, '/') !== false) { //impresspages path. Eg. Ip/Internal/xxx.php $viewFile = $layout; if (!is_file(ipFile($viewFile))) { $viewFile = ipThemeFile('main.php'); } } else { //layout file. Like main.php $viewFile = ipThemeFile($layout); if (!is_file($viewFile)) { $viewFile = ipThemeFile('main.php'); } } $content = ipView($viewFile, $this->getLayoutVariables())->render(); $response = new \Ip\Response($content, $this->getHeaders(), $this->getStatusCode()); return $response; }
protected static function initConfig() { ipAddCss('Ip/Internal/Core/assets/admin/admin.css'); ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js'); ipAddJsVariable('ipTranslationSaving', __('Saving...', 'Ip-admin', false)); ipAddJs('Ip/Internal/Design/assets/optionsBox.js'); ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml()); if (file_exists(ipThemeFile(Model::INSTALL_DIR . 'Options.js'))) { ipAddJs(ipThemeUrl(Model::INSTALL_DIR . 'Options.js')); } elseif (file_exists(ipThemeFile(Model::INSTALL_DIR . 'options.js'))) { ipAddJs(ipThemeUrl(Model::INSTALL_DIR . 'options.js')); } $model = Model::instance(); $theme = $model->getTheme(ipConfig()->theme()); if (!$theme) { throw new \Ip\Exception("Theme doesn't exist"); } $options = $theme->getOptionsAsArray(); $fieldNames = array(); foreach ($options as $option) { if (empty($option['name'])) { continue; } $fieldNames[] = $option['name']; } ipAddJsVariable('ipModuleDesignOptionNames', $fieldNames); }
public function getLayout() { if ($this->layout) { return $this->layout; } return is_file(ipThemeFile('404.php')) ? '404.php' : 'main.php'; }
public static function ipBeforeController() { $request = \Ip\ServiceLocator::request(); $sessionLifetime = ini_get('session.gc_maxlifetime'); if (!$sessionLifetime) { $sessionLifetime = 120; } if ($sessionLifetime > 30) { $sessionLifetime = $sessionLifetime - 20; } ipAddJsVariable('ipSessionRefresh', $sessionLifetime); if (ipConfig()->isDebugMode()) { ipAddJs('Ip/Internal/Core/assets/ipCore/jquery.js', null, 10); // default, global jQuery ipAddJs('Ip/Internal/Core/assets/ipCore/console.log.js', null, 10); ipAddJs('Ip/Internal/Core/assets/ipCore/functions.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/jquery.tools.form.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form/color.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form/file.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form/richtext.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form/repositoryFile.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form/url.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/form.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/validator.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/widgets.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/ipCore.js'); } else { ipAddJs('Ip/Internal/Core/assets/ipCore.min.js', null, 10); } //Form init $validatorTranslations = array('Ip-admin' => static::validatorLocalizationData('Ip-admin'), ipContent()->getCurrentLanguage()->getCode() => static::validatorLocalizationData('Ip')); ipAddJsVariable('ipValidatorTranslations', $validatorTranslations); if (ipAdminId() || \Ip\Internal\Admin\Model::isLoginPage() || \Ip\Internal\Admin\Model::isPasswordResetPage()) { if (ipConfig()->isDebugMode()) { ipAddJs('Ip/Internal/Core/assets/admin/managementMode.js'); ipAddJs('Ip/Internal/Core/assets/admin/functions.js'); ipAddJs('Ip/Internal/Core/assets/admin/validator.js'); ipAddJs('Ip/Internal/Core/assets/admin/bootstrap/bootstrap.js'); ipAddJs('Ip/Internal/Core/assets/admin/bootstrap-switch/bootstrap-switch.js'); } else { ipAddJs('Ip/Internal/Core/assets/admin.min.js', null, 10); } ipAddJs('Ip/Internal/Core/assets/tinymce/pastePreprocess.js'); ipAddJs('Ip/Internal/Core/assets/tinymce/default.js'); } if (ipAdminId()) { ipAddJs('Ip/Internal/Core/assets/js/tiny_mce/jquery.tinymce.min.js'); ipAddJs('Ip/Internal/Core/assets/js/tiny_mce/tinymce.min.js'); ipAddJsVariable('ipBrowseLinkModalTemplate', ipView('view/browseLinkModal.php')->render()); ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.full.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.browserplus.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.gears.js'); ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/jquery.plupload.queue/jquery.plupload.queue.js'); if (is_file(ipThemeFile('setup/admin.js'))) { ipAddJs(ipThemeUrl('setup/admin.js')); } ipAddCss('Ip/Internal/Core/assets/admin/admin.css'); } }
public function send() { ipContent()->setBlockContent('main', $this->content); if ($this->getLayout()) { $layout = $this->getLayout(); } else { $layout = 'main.php'; } if ($layout[0] == '/' || $layout[1] == ':') { // Check if absolute path: '/' for unix, 'C:' for Windows $viewFile = $layout; } else { $viewFile = ipThemeFile($layout); } $this->setContent(ipView($viewFile, $this->getLayoutVariables())->render()); $this->output(); }
public function __construct($name, $pluginName, $core) { $this->name = $name; $this->pluginName = $pluginName; $this->themeSectionsFolder = ipThemeFile('sections/'); $this->widgetDir = 'Plugin/CustomSection/Widget/CustomSection/'; $this->widgetAssetsDir = $this->widgetDir . \Ip\Application::ASSETS_DIR . '/'; $this->core = false; $this->layouts = array(); // get a list of available custom layouts if (is_dir($this->themeSectionsFolder)) { foreach (scandir($this->themeSectionsFolder) as $sectionFile) { if (is_file($this->themeSectionsFolder . '/' . $sectionFile) && substr($sectionFile, -4) == '.php') { $name = substr($sectionFile, 0, -4); $this->layouts[] = array('name' => $name, 'title' => $name); } } } }
</div> </div> <div class="row"> <div class="small-12 column mobileMenuButton"><?php echo __('Menu', 'Glara'); ?> </div> <?php if (count(ipContent()->getLanguages()) > 1) { ?> <div class="small-12 column"> <nav class="languages"> <?php echo ipSlot('languages'); ?> </nav> </div> <?php } ?> <div class="small-12 column"> <nav class="main_nav"> <?php $items = \Ip\Menu\Helper::getMenuItems('menu1', 1, 2); echo ipSlot('menu', array('items' => $items, 'view' => ipThemeFile('view/menu.php'))); ?> </nav> </div> </div> </header> <div class="row content">
public function generateHead() { $cacheVersion = $this->getCacheVersion(); $cssFiles = $this->getCss(); $inDesignPreview = false; $data = ipRequest()->getRequest(); if (!empty($data['ipDesign']['pCfg']) || !empty($data['restoreDefault'])) { $inDesignPreview = \Ip\Internal\Design\ConfigModel::instance()->isInPreviewState(); } if ($inDesignPreview) { $themeAssetsUrl = ipThemeUrl(\Ip\Application::ASSETS_DIR . '/'); $designService = \Ip\Internal\Design\Service::instance(); $theme = ipConfig()->theme(); foreach ($cssFiles as &$file) { if (strpos($file['value'], $themeAssetsUrl) === 0) { $pathinfo = pathinfo($file['value']); if ($pathinfo['extension'] == 'css' && $themeAssetsUrl . $pathinfo['basename'] == $file['value']) { $themeFile = \Ip\Application::ASSETS_DIR . '/' . $pathinfo['filename'] . '.less'; if (file_exists(ipThemeFile($themeFile))) { $file['value'] = $designService->getRealTimeUrl($theme, $themeFile); $file['cacheFix'] = false; } } } if ($file['cacheFix']) { $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion; } } } else { foreach ($cssFiles as &$file) { if ($file['cacheFix']) { $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion; } } } $cssFiles = ipFilter('ipCss', $cssFiles); $response = ipResponse(); $data = array('title' => $response->getTitle(), 'keywords' => $response->getKeywords(), 'description' => $response->getDescription(), 'favicon' => $response->getFavicon(), 'charset' => $response->getCharset(), 'css' => $cssFiles); $head = ipView('Ip/Internal/Config/view/head.php', $data)->render(); $head = ipFilter('ipHead', $head); return $head; }
/** * Load example content from file * * Example content should be placed in theme's directory * * @param string $filename * @return $this */ public function exampleContentFrom($filename) { $this->exampleContent = ipView(ipThemeFile($filename)); return $this; }
/** * Renders widget's HTML output * * You can extend this method when generating widget's HTML. * * @param int $revisionId Widget revision ID * @param int $widgetId Widget ID * @param int $widgetId Widget instance ID * @param array $data Widget data array * @param string $skin Skin name * @return string Widget's HTML code */ public function generateHtml($revisionId, $widgetId, $data, $skin) { try { if ($this->core) { $skinFile = 'Ip/Internal/' . $this->pluginName . '/' . Model::WIDGET_DIR . '/' . $this->name . '/' . self::SKIN_DIR . '/' . $skin . '.php'; } else { $skinFile = 'Plugin/' . $this->pluginName . '/' . Model::WIDGET_DIR . '/' . $this->name . '/' . self::SKIN_DIR . '/' . $skin . '.php'; } if (!is_file(ipFile($skinFile)) && !is_file(ipThemeFile(\Ip\View::OVERRIDE_DIR . '/' . $skinFile))) { $skin = 'default'; if ($this->core) { $skinFile = 'Ip/Internal/' . $this->pluginName . '/' . Model::WIDGET_DIR . '/' . $this->name . '/' . self::SKIN_DIR . '/' . $skin . '.php'; } else { $skinFile = 'Plugin/' . $this->pluginName . '/' . Model::WIDGET_DIR . '/' . $this->name . '/' . self::SKIN_DIR . '/' . $skin . '.php'; } } $answer = ipView($skinFile, $data)->render(); } catch (\Ip\Exception $e) { if (ipIsManagementState()) { $answer = $e->getMessage() . "\n " . $e->getTraceAsString(); } else { $answer = ''; } } return $answer; }
/** * Returns possible layout pages. * files starting with underscore (for example, _layout.php) are considered hidden. * @return array layouts (e.g. ['main.php', 'home.php']) * @throws \Ip\Exception */ public static function getThemeLayouts() { $themeDir = ipThemeFile(''); $files = scandir($themeDir); $layouts = array(); foreach ($files as $filename) { if ('php' == strtolower(pathinfo($filename, PATHINFO_EXTENSION))) { if ($filename[0] != '_') { $layouts[] = $filename; } } } return $layouts; }
/** * Get MVC view object * * Get a view object using specified view file and data array. * @param string $file MVC view file pathname. * @param array $data View's data. * @param int $_callerDepth * @return \Ip\View * @throws \Ip\Exception\View */ function ipView($file, $data = array(), $_callerDepth = 0) { if ($file[0] == '/' || $file[1] == ':') { // Absolute filename return new \Ip\View($file, $data); } if (preg_match('%^(Plugin|Theme|file|Ip)/%', $file)) { $relativePath = $file; } else { $relativePath = \Ip\Internal\PathHelper::ipRelativeDir($_callerDepth + 1) . $file; } $fileInThemeDir = ipThemeFile(\Ip\View::OVERRIDE_DIR . '/' . $relativePath); if (is_file($fileInThemeDir)) { return new \Ip\View($fileInThemeDir, $data); } $absolutePath = ipFile($relativePath); if (file_exists($absolutePath)) { // The most common case return new \Ip\View($absolutePath, $data); } // File was not found, check whether it is in theme override dir. if (strpos($relativePath, 'Theme/' . ipConfig()->theme() . '/override/') !== 0) { $file = esc($file); throw new \Ip\Exception\View("View {$file} not found."); } $pathFromWebsiteRoot = str_replace(ipFile('Theme/' . ipConfig()->theme() . '/override/'), '', $absolutePath); return ipView($pathFromWebsiteRoot); }
/** * Returns possible layout pages. * files starting with underscore (for example, _layout.php) are considered hidden. * @return array layouts (e.g. ['main.php', 'home.php']) * @throws \Ip\Exception */ public static function getThemeLayouts() { $themeDir = ipThemeFile(''); $files = scandir($themeDir); $layouts = array(); foreach ($files as $filename) { if ('php' == strtolower(pathinfo($filename, PATHINFO_EXTENSION))) { if ($filename[0] != '_') { $file_contents = file_get_contents($themeDir . $filename); preg_match_all("(@Layout Name:(.*)\n)siU", $file_contents, $file_layout); if (isset($file_layout[1]) && isset($file_layout[1][0]) && !empty($file_layout[1][0])) { $layout_name = preg_replace('/[^a-zA-Z0-9\\s]/', '', $file_layout[1][0]); } else { $layout_name = ''; } $layouts[] = array($filename, trim($layout_name) != '' ? $layout_name : $filename); } } } return $layouts; }
/** * @param string $relativePath * @param string $destinationDir * @return string */ public static function copyTemporaryFile($relativePath, $destinationDir) { $newBasename = \Ip\Internal\File\Functions::genUnoccupiedName($relativePath, $destinationDir); if (!copy(ipFile('file/tmp/' . $relativePath), $destinationDir . $newBasename)) { trigger_error("Can't copy file from " . htmlspecialchars(ipThemeFile('') . $relativePath) . ' to ' . htmlspecialchars($destinationDir . $newBasename)); } return $newBasename; }