public function paymentUrl($options) { if (empty($options['id'])) { throw new \Ip\Exception('"id" setting is missing in paymentUrl function'); } if (empty($options['price'])) { throw new \Ip\Exception('"price" setting is missing in paymentUrl function'); } if (empty($options['currency'])) { throw new \Ip\Exception('"currency" setting is missing in paymentUrl function'); } $paymentUrl = ipJob('ipPaymentUrl', $options); return $paymentUrl; }
/** * 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); }
/** * @ignore * @param Request $request * @param array $options * @param bool $subrequest * @return Response\Json|Response\PageNotFound|Response\Redirect * @throws Exception * @ignore */ public function _handleOnlyRequest(\Ip\Request $request, $options = array(), $subrequest = true) { if (empty($options['skipInitEvents'])) { \Ip\ServiceLocator::dispatcher()->_bindApplicationEvents(); } $result = ipJob('ipRouteLanguage', array('request' => $request, 'relativeUri' => $request->getRelativePath())); if ($result) { $requestLanguage = $result['language']; $routeLanguage = $requestLanguage->getCode(); ipRequest()->_setRoutePath($result['relativeUri']); } else { $routeLanguage = null; $requestLanguage = ipJob('ipRequestLanguage', array('request' => $request)); ipRequest()->_setRoutePath($request->getRelativePath()); } //find out and set locale $locale = $requestLanguage->getCode(); if (strlen($locale) == '2') { $locale = strtolower($locale) . '_' . strtoupper($locale); } else { $locale = str_replace('-', '_', $locale); } $locale .= '.utf8'; if ($locale == "tr_TR.utf8" && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5)) { //Overcoming this bug https://bugs.php.net/bug.php?id=18556 setlocale(LC_COLLATE, $locale); setlocale(LC_MONETARY, $locale); setlocale(LC_NUMERIC, $locale); setlocale(LC_TIME, $locale); setlocale(LC_MESSAGES, $locale); setlocale(LC_CTYPE, "en_US.utf8"); } else { setLocale(LC_ALL, $locale); } setlocale(LC_NUMERIC, "C"); //user standard C syntax for numbers. Otherwise you will get funny things with when autogenerating CSS, etc. ipContent()->_setCurrentLanguage($requestLanguage); $_SESSION['ipLastLanguageId'] = $requestLanguage->getId(); if (empty($options['skipTranslationsInit'])) { if (!empty($options['translationsLanguageCode'])) { $languageCode = $options['translationsLanguageCode']; } else { $languageCode = $requestLanguage->getCode(); } $this->initTranslations($languageCode); } if (empty($options['skipModuleInit'])) { $this->modulesInit(); } ipEvent('ipInitFinished'); $routeAction = ipJob('ipRouteAction', array('request' => $request, 'relativeUri' => ipRequest()->getRoutePath(), 'routeLanguage' => $routeLanguage)); if (!empty($routeAction)) { if (!empty($routeAction['page'])) { ipContent()->_setCurrentPage($routeAction['page']); } if (!empty($routeAction['environment'])) { ipRoute()->setEnvironment($routeAction['environment']); } else { if (!empty($routeAction['controller']) && $routeAction['controller'] == 'AdminController') { ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_ADMIN); } else { ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_PUBLIC); } } if (!empty($routeAction['controller'])) { ipRoute()->setController($routeAction['controller']); } if (!empty($routeAction['plugin'])) { ipRoute()->setPlugin($routeAction['plugin']); } if (!empty($routeAction['name'])) { ipRoute()->setName($routeAction['name']); } if (!empty($routeAction['action'])) { ipRoute()->setAction($routeAction['action']); } } //check for CSRF attack if (empty($options['skipCsrfCheck']) && $request->isPost() && $request->getPost('securityToken') != $this->getSecurityToken() && (empty($routeAction['controller']) || $routeAction['controller'] != 'PublicController')) { ipLog()->error('Core.possibleCsrfAttack', array('post' => ipRequest()->getPost())); $data = array('status' => 'error'); if (ipConfig()->isDevelopmentEnvironment()) { $data['errors'] = array('securityToken' => __('Possible CSRF attack. Please pass correct securityToken.', 'Ip-admin')); } // TODO JSONRPC return new \Ip\Response\Json($data); } if (empty($routeAction)) { $routeAction = array('plugin' => 'Core', 'controller' => 'PublicController', 'action' => 'pageNotFound'); } $eventInfo = $routeAction; if (!empty($routeAction['plugin'])) { $plugin = $routeAction['plugin']; $controller = $routeAction['controller']; if (in_array($plugin, \Ip\Internal\Plugins\Model::getModules())) { $controllerClass = 'Ip\\Internal\\' . $plugin . '\\' . $controller; } else { if (!in_array($plugin, \Ip\Internal\Plugins\Service::getActivePluginNames())) { throw new \Ip\Exception("Plugin '" . esc($plugin) . "' doesn't exist or isn't activated."); } $controllerClass = 'Plugin\\' . $plugin . '\\' . $controller; } if (!class_exists($controllerClass)) { throw new \Ip\Exception('Requested controller doesn\'t exist. ' . esc($controllerClass)); } // check if user is logged in if ($controller == 'AdminController' && !\Ip\Internal\Admin\Backend::userId()) { if (ipConfig()->get('rewritesDisabled')) { return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'index.php/admin'); } else { return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'admin'); } } if ($controller == 'AdminController') { if (!ipAdminPermission($plugin)) { throw new \Ip\Exception('User has no permission to access ' . esc($plugin) . ''); } } $eventInfo['controllerClass'] = $controllerClass; $eventInfo['controllerType'] = $controller; } if (empty($eventInfo['page'])) { $eventInfo['page'] = null; } // change layout if safe mode if (\Ip\Internal\Admin\Service::isSafeMode()) { ipSetLayout(ipFile('Ip/Internal/Admin/view/safeModeLayout.php')); } else { if ($eventInfo['page']) { ipSetLayout($eventInfo['page']->getLayout()); } } ipEvent('ipBeforeController', $eventInfo); $controllerAnswer = ipJob('ipExecuteController', $eventInfo); return $controllerAnswer; }
/** * Get Id of the default page in current or specified language * @param string $languageCode * @return int */ public function getDefaultPageId($languageCode = null) { if ($languageCode == null) { $languageCode = ipContent()->getCurrentLanguage()->getCode(); } $pageId = ipJob('ipDefaultPageId', array('languageCode' => $languageCode)); return $pageId; }
/** * @param string $source * @param string $destination * @param array $options * @return string */ public function createReflection($source, $destination, $options) { $absoluteSource = str_replace('\\', '/', realpath(ipFile('file/repository/' . $source))); $absoluteDestinationDir = dirname(ipFile('file/' . $destination)); $destinationFileName = basename($destination); if (!is_dir($absoluteDestinationDir)) { mkdir($absoluteDestinationDir, 0777, $recursive = true); } if (!is_file($absoluteSource)) { return false; } $data = array('source' => $absoluteSource, 'destination' => $absoluteDestinationDir . '/' . $destinationFileName, 'options' => $options); ipJob('ipCreateReflection', $data); ipEvent('ipReflectionCreated', $data); if (is_file($absoluteDestinationDir . '/' . $destinationFileName)) { return true; } else { return false; } }
public function login($username, $password) { $ip = ipRequest()->getServer('REMOTE_ADDR'); $preventReason = ipJob('ipAdminLoginPrevent', array('username' => $username)); if ($preventReason) { $this->errors = array('global_error' => $preventReason); ipLog()->notice('Admin.loginPrevented: {username} from {ip}', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR'))); return false; } $administrator = \Ip\Internal\Administrators\Service::getByUsername($username); if (!$administrator) { \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR'))); ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip)); $this->errors = array('login' => __('Following user doesn\'t exist', 'Ip-admin')); return false; } if (\Ip\Internal\Administrators\Service::checkPassword($administrator['id'], $password)) { Service::setAdminLogin($username); return true; } else { \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR'))); ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip)); $this->errors = array('password' => __('Incorrect password', 'Ip-admin')); return false; } }
/** * Replace placeholders with actual values in string or array of strings. Default placeholders: * websiteTitle * websiteEmail * websiteUrl * userId * userEmail * userName * * @param string $content * @param array $customValues * @param string $context plugin name which executes the function. Makes possible to have different values in different contexts. * @return string */ function ipReplacePlaceholders($content, $context = 'Ip', $customValues = array()) { $info = array('content' => $content, 'context' => $context, 'customValues' => $customValues); if (is_array($content)) { $answer = array(); foreach ($content as $item) { $answer[] = ipJob('ipReplacePlaceholders', $info); } return $answer; } else { return ipJob('ipReplacePlaceholders', $info); } }
/** * @param int $unixTimestamp * @param string $context * @param int $languageCode * @return string */ public static function formatDateTime($unixTimestamp, $context = null, $languageCode = null) { $data = array('timestamp' => $unixTimestamp, 'context' => $context); $formattedDate = ipJob('ipFormatDateTime', $data); if ($formattedDate === null) { if (function_exists('datefmt_create') && function_exists('datefmt_format')) { if ($languageCode === null) { if ($context == 'Ip-admin') { $code = ipConfig()->adminLocale(); } else { $languageCode = ipContent()->getCurrentLanguage()->getId(); $code = $languageCode; } } $locale = str_replace('-', '_', $languageCode); $fmt = datefmt_create($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT, date_default_timezone_get()); $formattedDate = datefmt_format($fmt, $unixTimestamp); } else { $formattedDate = date('Y-m-d H:i', $unixTimestamp); } } return $formattedDate; }