/** * Insert new page * * @param int $parentId * @param string $title * @param array $data * @return int page id * @throws \Ip\Exception */ public static function addPage($parentId, $title, $data = array()) { $data['title'] = $title; if (!isset($data['createdAt'])) { $data['createdAt'] = date('Y-m-d H:i:s'); } if (!isset($data['updatedAt'])) { $data['updatedAt'] = date('Y-m-d H:i:s'); } if (!isset($data['isVisible'])) { $data['isVisible'] = !ipGetOption('Pages.hideNewPages'); } if (!isset($data['languageCode'])) { $data['languageCode'] = ipDb()->selectValue('page', 'languageCode', array('id' => $parentId)); if (empty($data['languageCode'])) { $data['languageCode'] = ipDb()->selectValue('page', 'languageCode', array('alias' => $parentId)); } if (empty($data['languageCode'])) { throw new \Ip\Exception('Page languageCode should be set if parent is absent'); } } if (!isset($data['urlPath'])) { $dataForPath = $data; $dataForPath['parentId'] = $parentId; $data['urlPath'] = UrlAllocator::allocatePathForNewPage($dataForPath); } $newPageId = Model::addPage($parentId, $data); return $newPageId; }
public static function ipJs($jsFiles) { if (ipGetOption('ConcatenateJsCss.disableInAdmin', 1) && ipAdminId() || ipStorage()->get('ConcatenateJsCss', 'concatenationInProgress') > time()) { return $jsFiles; } ipStorage()->set('ConcatenateJsCss', 'concatenationInProgress', time() + 60); //if some CSS / JS links to the website itself, we may have an infinite recursion. So we have to disable ourself during the concatenation $tinymceUrl = ipFileUrl('Ip/Internal/Core/assets/js/tiny_mce'); $answer = array('concatenateJsCss_tinymce_fix' => array('type' => 'content', 'value' => "var tinyMCEPreInit = {\n suffix: '.min',\n base: '" . $tinymceUrl . "',\n query: ''\n};", 'attributes' => array(), 'cacheFix' => false)); $chunk = array(); foreach ($jsFiles as &$file) { if ($file['type'] == 'content') { //we have faced a piece of inline JS. It can't be concatenated. We have to split concatenated JS in to two parts. if (!empty($chunk)) { $answer = array_merge($answer, self::concatenateChunk($chunk)); } $chunk = array(); //add current inline content JS $answer[] = $file; } else { $chunk[] = $file; } } if (!empty($chunk)) { $answer = array_merge($answer, self::concatenateChunk($chunk)); } ipStorage()->remove('ConcatenateJsCss', 'concatenationInProgress'); return $answer; }
public static function ipBeforeController() { $style = ipGetOption('Colorbox.style', 1); ipAddCss('Plugin/Colorbox/assets/theme' . $style . '/colorbox.css'); ipAddJs('Plugin/Colorbox/assets/colorbox/jquery.colorbox-min.js'); ipAddJs('Plugin/Colorbox/assets/colorboxInit.js'); }
public function index() { ipAddJsVariable('ipTranslationAreYouSure', __('Are you sure?', 'Ip-admin', false)); ipAddJs('Ip/Internal/Core/assets/js/angular.js'); ipAddJs('Ip/Internal/Pages/assets/js/pages.js'); ipAddJs('Ip/Internal/Pages/assets/js/pagesLayout.js'); ipAddJs('Ip/Internal/Pages/assets/js/menuList.js'); ipAddJs('Ip/Internal/Pages/assets/jstree/jstree.min.js'); ipAddJs('Ip/Internal/Pages/assets/js/jquery.pageTree.js'); ipAddJs('Ip/Internal/Pages/assets/js/jquery.pageProperties.js'); ipAddJs('Ip/Internal/Grid/assets/grid.js'); ipAddJs('Ip/Internal/Grid/assets/gridInit.js'); ipAddJs('Ip/Internal/Grid/assets/subgridField.js'); ipAddJsVariable('languageList', Helper::languageList()); ipAddJsVariable('ipPagesLanguagesPermission', ipAdminPermission('Languages')); $menus = Model::getMenuList(); foreach ($menus as $key => &$menu) { $default = 'top'; if ($key == 0) { $default = 'bottom'; } $menu['defaultPosition'] = Model::getDefaultMenuPagePosition($menu['alias'], false, $default); $default = 'below'; $menu['defaultPositionWhenSelected'] = Model::getDefaultMenuPagePosition($menu['alias'], true, $default); } $menus = ipFilter('ipPagesMenuList', $menus); ipAddJsVariable('menuList', $menus); $variables = array('addPageForm' => Helper::addPageForm(), 'addMenuForm' => Helper::addMenuForm(), 'languagesUrl' => ipConfig()->baseUrl() . '?aa=Languages.index'); $layout = ipView('view/layout.php', $variables); ipResponse()->setLayoutVariable('removeAdminContentWrapper', true); ipAddJsVariable('listStylePageSize', ipGetOption('Pages.pageListSize', 30)); return $layout->render(); }
protected function config() { $reservedDirs = ipGetOption('Config.reservedDirs'); if (!is_array($reservedDirs)) { $reservedDirs = array(); } return array('type' => 'table', 'table' => 'language', 'allowCreate' => false, 'allowSearch' => false, 'actions' => array(array('label' => __('Add', 'Ip-admin', false), 'class' => 'ipsCustomAdd')), 'preventAction' => array($this, 'preventAction'), 'beforeUpdate' => array($this, 'beforeUpdate'), 'afterUpdate' => array($this, 'afterUpdate'), 'beforeDelete' => array($this, 'beforeDelete'), 'deleteWarning' => __('Are you sure you want to delete? All pages and other language related content will be lost forever!', 'Ip-admin', false), 'sortField' => 'languageOrder', 'fields' => array(array('label' => __('Title', 'Ip-admin', false), 'field' => 'title'), array('label' => __('Abbreviation', 'Ip-admin', false), 'field' => 'abbreviation', 'showInList' => true), array('type' => 'Checkbox', 'label' => __('Visible', 'Ip-admin', false), 'field' => 'isVisible'), array('label' => __('Url', 'Ip-admin', false), 'field' => 'url', 'showInList' => false, 'validators' => array(array('Regex', '/^([^\\/\\\\])+$/', __('You can\'t use slash in URL.', 'Ip-admin', false)), array('Unique', array('table' => 'language', 'allowEmpty' => true), __('Language url should be unique', 'Ip-admin', false)), array('NotInArray', $reservedDirs, __('This is a system directory name.', 'Ip-admin', false)))), array('label' => __('RFC 4646 code', 'Ip-admin', false), 'field' => 'code', 'showInList' => false, 'validators' => array(array('Unique', array('table' => 'language'), __('Language code should be unique', 'Ip-admin', false)))), array('type' => 'Select', 'label' => __('Text direction', 'Ip-admin', false), 'field' => 'textDirection', 'showInList' => false, 'values' => array(array('ltr', __('Left To Right', 'Ip-admin', false)), array('rtl', __('Right To Left', 'Ip-admin', false)))))); }
public static function domain() { $domain = ipGetOption('GoogleAnalytics.domain'); if (empty($domain)) { $domain = parse_url(ipConfig()->baseUrl(), PHP_URL_HOST); } return $domain; }
/** * @param \Ip\Response $response * @return mixed */ public static function ipSendResponse($response) { if (ipGetOption('MaintenanceMode.enabled') == 1 && ipAdminId() === false) { if (substr(ipRequest()->getRelativePath(), 0, 5) != 'admin') { return new \Ip\Response(ipGetOption('MaintenanceMode.content')); } } return $response; }
public static function AddThis($widget = false) { if ($widget) { $layout = ipGetOption('AddThis.widgetLayout'); } else { $layout = ipGetOption('AddThis.slotLayout'); } return ipView('view/' . $layout . '.php')->render(); }
/** * @throws \Ip\Exception\Db */ public function activate() { $savedTableTypes = ipGetOption(TableType::OPTION); if (empty($savedTableTypes)) { ipSetOption(TableType::OPTION, array()); TableType::create(array('name' => 'default', 'language' => ipContent()->getLanguages()[0]->getId(), 'columnOption' => TableType::SHOW_ALL_COLUMNS, 'specificColumns' => array()))->save(); } $this->createDataTableRepository(); }
public static function getAdvancedForm() { $form = new \Ip\Form(); $form->addClass('ipsConfigForm'); $form->addClass('ipsConfigFormAdvanced'); $form->addClass('hidden'); $form->setAjaxSubmit(0); $field = new \Ip\Form\Field\Checkbox(array('name' => 'automaticCron', 'value' => ipGetOption('Config.automaticCron', 1), 'label' => __('Execute cron automatically', 'Ip-admin', false), 'hint' => __('ImpressPages execute cron once every hour on randomly selected visitor page load. I you have setup cron manually, you can disable automatic cron functionality.', 'Ip-admin'))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'cronPassword', 'value' => ipGetOption('Config.cronPassword', 1), 'label' => __('Cron password', 'Ip-admin', false), 'hint' => __('Protect cron from being abusively executed by the strangers.', 'Ip-admin', false), 'note' => '<span class="ipsUrlLabel">' . __('Cron URL: ', 'Ip-admin') . '</span><a target="_blank" class="ipsUrl"></a>')); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'removeOldEmails', 'value' => ipGetOption('Config.removeOldEmails', 0), 'label' => __('Remove old emails from the log', 'Ip-admin', false))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'removeOldEmailsDays', 'value' => ipGetOption('Config.removeOldEmailsDays', 720), 'label' => __('Days to keep emails', 'Ip-admin', false), 'hint' => __('Meaningful only if "Remove old emails" is on.', 'Ip-admin', false))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'removeOldRevisions', 'value' => ipGetOption('Config.removeOldRevisions', 0), 'label' => __('Remove old page revisions', 'Ip-admin', false))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Text(array('name' => 'removeOldRevisionsDays', 'value' => ipGetOption('Config.removeOldRevisionsDays', 720), 'label' => __('Days to keep revisions', 'Ip-admin', false), 'hint' => __('Meaningful only if "Remove old page revisions" is on.', 'Ip-admin', false))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'allowAnonymousUploads', 'value' => ipGetOption('Config.allowAnonymousUploads', 1), 'label' => __('Allow anonymous uploads', 'Ip-admin', false), 'hint' => __('Disabling this feature will prevent users from uploading files to your website. E.g. in contact forms.', 'Ip-admin'))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); $field = new \Ip\Form\Field\Checkbox(array('name' => 'trailingSlash', 'value' => ipGetOption('Config.trailingSlash', 1), 'label' => __('Add trailing slash at the end of page URL', 'Ip-admin', false), 'hint' => __('This won\'t change existing URLs. Only new and updated pages will get slash at the end.', 'Ip-admin'))); $field->addClass('ipsAutoSave'); $field->addAttribute('data-fieldid', $field->getName()); $field->addAttribute('id', $field->getName()); $field->addAttribute('data-fieldname', $field->getName()); $form->addField($field); return $form; }
/** * @param int $width width of area where image should fit * @param int $quality image quoality from 0 to 100 * @param bool $forced if true, and supplied image has different proportions, resulting image will have white edges to make image exactly $Width x $height */ public function __construct($width, $quality = null, $forced = false) { if ($quality === null) { $quality = ipGetOption('Config.defaultImageQuality'); } $this->width = $width; $this->quality = (int) $quality; $this->forced = $forced; }
public static function ipBeforeController() { $pubId = ipGetOption('AddThis.addThisUid'); if ($pubId) { $data['pubid'] = $pubId; // AddThis publisher ID, if applicable } $data['data_track_addressbar'] = true; ipAddJsVariable("addthis_config", $data); ipAddJs('http://s7.addthis.com/js/300/addthis_widget.js'); }
public static function ipPagePropertiesForm($form, $info) { if (ipGetOption('Keywordlist.useMetadata') == 0) { $current = Model::getPageKey($info['pageId']); $fieldset = new \Ip\Form\Fieldset(__('Keywordlist', 'Keywordlist', false)); $form->addFieldset($fieldset); $form->addField(new \Ip\Form\Field\Text(array('name' => 'keywordlist', 'label' => __('Keywords', 'Keywordlist', false), 'value' => $current['keywords'], 'note' => __('One or more keywords (commaseparated) wich are related to current page.', 'Keywordlist', false)))); $form->addField(new \Ip\Form\Field\Textarea(array('name' => 'pagedescription', 'label' => __('Description', 'Keywordlist', false), 'value' => $current['description'], 'note' => __('Short description of current page.', 'Keywordlist', false)))); } return $form; }
public static function ipSendResponse($response) { $enableAdmin = ipGetOption('AnyScript.enableInAdmin', 0); if ($enableAdmin && ipRoute()->isAdmin() || !ipRoute()->isAdmin()) { $anyJavascript = ipGetOption('AnyScript.anyJavascript'); $anyCss = ipGetOption('AnyScript.anyCss'); ipAddJsContent("anyJavascript", $anyJavascript); ipAddJsContent("anyCss", '$("head").append("<style>' . preg_replace('/\\s+/', ' ', trim($anyCss)) . '</style>");'); } return $response; }
/** * Get language specific option value * @param string $key Option key * @param string $languageCode Language code * @param null $defaultValue A value to return if the option is not set * @return string Option value * @throws Exception */ public function getOptionLang($key, $languageCode, $defaultValue = null) { $parts = explode('.', $key, 2); if (!isset($parts[1])) { throw new \Ip\Exception("Option key must have plugin name separated by dot."); } $answer = \Ip\ServiceLocator::storage()->get('Config', $parts[0] . '.' . $languageCode . '.' . $parts[1]); if ($answer === null) { $answer = ipGetOption($key, $defaultValue); } return $answer; }
/** * @param int $x1 left top coordinate of source * @param int $y1 left top coordinate of source * @param int $x2 right bottom coordinate of source * @param int $y2 right bottom coordinate of source * @param int $widthDest required width of detination image * @param int $heightDest required height of detination image * @param null $quality */ public function __construct($widthDest, $heightDest, $quality = null) { if ($heightDest <= 0 || $widthDest <= 0) { throw new \Ip\Exception\Repository\Transform("Incorrect width or height"); } if ($quality === null) { $quality = ipGetOption('Config.defaultImageQuality'); } $this->widthDest = $widthDest; $this->heightDest = $heightDest; $this->quality = (int) $quality; }
public static function ipCronExecute($info) { if ($info['firstTimeThisMonth'] || $info['test']) { if (ipGetOption('Config.removeOldEmails', 0)) { Db::deleteOld(ipGetOption('Config.removeOldEmailsDays', 720)); } } if ($info['firstTimeThisHour'] || $info['test']) { $queue = new Module(); $queue->send(); } }
/** * @return array */ public function getAvailableFonts() { $fontsString = ipGetOption('Config.availableFonts'); $tmpFonts = explode("\n", $fontsString); $fonts = array(); foreach ($tmpFonts as &$font) { $tmpFont = trim($font); if ($tmpFont != '') { $fonts[] = $tmpFont; } } return $fonts; }
public function adminHtmlSnippet() { $maxLevel = (int) ipGetOption('Content.widgetHeadingMaxLevel', 6); if ($maxLevel > 6) { $maxLevel = 6; } if ($maxLevel < 1) { $maxLevel = 1; } $variables = array('optionsForm' => $this->optionsForm()); $variables2 = array('maxLevel' => $maxLevel); return ipView('snippet/options.php', $variables)->render() . "\n" . ipView('snippet/controls.php', $variables2)->render(); }
public static function ipAdminLoginPrevent($data) { if (empty($data['username'])) { return 'Missing login data'; //in theory should never happen } $ip = ipRequest()->getServer('REMOTE_ADDR'); $antiBruteForce = SecurityModel::instance(); $failedLogins = $antiBruteForce->failedLoginCount($data['username'], $ip); if ($failedLogins > ipGetOption('Admin.allowFailedLogins', 20)) { return __('You have exceeded failed login attempts.', 'Ip-admin', false); } return null; }
/** * @param int $x1 left top coordinate of source * @param int $y1 left top coordinate of source * @param int $x2 right bottom coordinate of source * @param int $y2 right bottom coordinate of source * @param int $widthDest required width of destination image * @param int $heightDest required height of destination image * @param null $quality */ public function __construct($x1, $y1, $x2, $y2, $widthDest, $heightDest, $quality = null) { if ($quality === null) { $quality = ipGetOption('Config.defaultImageQuality'); } list($x1, $y1, $x2, $y2) = $this->fixSourceRatio($x1, $y1, $x2, $y2, $widthDest, $heightDest); $this->x1 = $x1; $this->y1 = $y1; $this->x2 = $x2; $this->y2 = $y2; $this->widthDest = $widthDest; $this->heightDest = $heightDest; $this->quality = (int) $quality; }
private static function getMenuAliases() { $cfgMenuString = ipGetOption('Sitemap.menuList'); if ($cfgMenuString) { $menus = preg_split("/[\\s,]+/", $cfgMenuString); } else { $currLanguage = ipContent()->getCurrentLanguage()->getCode(); $menusObj = \Ip\Internal\Pages\Service::getMenus($currLanguage); $menus = array(); foreach ($menusObj as $menuObj) { $menus[] = $menuObj['alias']; } } return $menus; }
/** * @return mixed */ public static function ipDefaultPageId_70($info) { $languageCode = $info['languageCode']; $defaultPageId = ipGetOption('Config.defaultPageId_' . $languageCode, null); if ($defaultPageId) { return $defaultPageId; } $menus = \Ip\Internal\Pages\Service::getMenus($languageCode); foreach ($menus as $menu) { $pages = \Ip\Internal\Pages\Service::getChildren($menu['id'], 0, 1); if (!empty($pages[0]['id'])) { return $pages[0]['id']; } } return null; }
/** * Upload file to temporary folder */ public function upload() { ipRequest()->mustBePost(); $post = ipRequest()->getPost(); if (isset($post['secureFolder']) && $post['secureFolder']) { //upload to secure publicly not accessible folder. if (!ipGetOption('Config.allowAnonymousUploads', 1)) { throw new \Exception('Anonymous uploads are not enabled. You can enable them by turning on "anonymous uploads" configuration value in admin.'); } else { //do nothing. Anonymous uploads are allowed to secure folder } $secureFolder = true; } else { $secureFolder = false; $this->backendOnly(); if (!ipAdminPermission('Repository upload')) { throw new \Ip\Exception('Permission denied'); } } $uploadModel = UploadModel::instance(); try { $uploadModel->handlePlupload($secureFolder); } catch (\Ip\Exception\Repository\Upload\ForbiddenFileExtension $e) { // Return JSON-RPC response $message = __('Forbidden file type.', 'Ip-admin'); ipLog()->info('Repository.invalidUploadedFileExtension: ' . $e->getMessage(), array('plugin' => 'Repository')); // TODO JSONRPC $answer = array('jsonrpc' => '2.0', 'error' => array('code' => $e->getCode(), 'message' => $message, 'id' => 'id')); return new \Ip\Response\Json($answer); } catch (\Ip\Exception\Repository\Upload $e) { ipLog()->error('Repository.fileUploadError', array('plugin' => 'Repository', 'exception' => $e)); $message = __('Can\'t store uploaded file. Please check server configuration.', 'Ip-admin'); // TODO JSONRPC $answer = array('jsonrpc' => '2.0', 'error' => array('code' => $e->getCode(), 'message' => $message, 'id' => 'id')); return new \Ip\Response\Json($answer); } $fileName = $uploadModel->getUploadedFileName(); $file = $uploadModel->getUploadedFile(); $targetDir = $uploadModel->getTargetDir(); // Return JSON-RPC response $answerArray = array("jsonrpc" => "2.0", "result" => null, "id" => "id", "fileName" => $fileName); if (!$secureFolder) { $answerArray['dir'] = $targetDir; $answerArray['file'] = $file; } return new \Ip\Response\Json($answerArray); }
public static function getMenusList() { if (ipGetOption('AsdMenuWidget.multilanguage') == 'Yes') { $multilanguage = null; } else { $languageCode = ipContent()->getCurrentLanguage()->code; $multilanguage = "`languageCode` = '{$languageCode}' AND"; } $table = ipTable('page'); $sql = "SELECT `title`, `alias`, `languageCode`, `parentId`, `id` FROM {$table} WHERE {$multilanguage} `isVisible` = 1 AND `isDeleted` = 0 ORDER BY `languageCode` ASC, `title` ASC"; $results = ipDb()->fetchAll($sql); foreach ($results as $result) { $allPages[$result['parentId']][$result['id']] = $result; } $returnData = makeMenu(0, $allPages, 0, $multilanguage); return $returnData; }
public static function getKeywordData() { $pageTable = ipTable('page'); $keywordlistTable = ipTable(self::TABLE_NAME); $langCode = ipContent()->getCurrentLanguage()->getCode(); $excludeFields = ' AND p.IsVisible = 1 AND p.IsDisabled = 0 AND p.IsDeleted = 0'; $securedPages = ipGetOption('Keywordlist.securedPages') == 1 ? '' : 'AND p.IsSecured = 0'; if (ipGetOption('Keywordlist.useMetadata') == 1) { $sql = "SELECT p.id, p.title, p.urlPath, p.keywords, p.description FROM {$pageTable} p WHERE p.languageCode = '{$langCode}' AND p.keywords != '' {$excludeFields} {$securedPages}"; } else { $sql = "SELECT p.id, p.title, p.urlPath, k.keywords, k.description FROM {$pageTable} p, {$keywordlistTable} k WHERE p.id = k.pageid AND p.languageCode = '{$langCode}' AND k.keywords != '' {$excludeFields} {$securedPages}"; } $keywordArray = array(); $entries = array(); $entries = ipDb()->fetchAll($sql); $existingChars = array(); if (!empty($entries)) { // prepare array with keywords and pages $keywordArray = array(); $charSource = array('ä', 'ö', 'ü', 'ß', 'Ä', 'Ö', 'Ü'); $charReplace = array('a', 'o', 'u', 's', 'A', 'O', 'U'); foreach ($entries as $entry) { $keywords = array_map('trim', explode(",", $entry['keywords'])); foreach ($keywords as $keyword) { $firstChar = strtoupper(str_replace($charSource, $charReplace, mb_substr($keyword, 0, 1, 'UTF-8'))); if (is_numeric($firstChar)) { $firstChar = '0-9'; } $keywordArray[] = array('keyword' => $keyword, 'char' => $firstChar, 'id' => $entry['id'], 'title' => $entry['title'], 'description' => $entry['description'], 'urlPath' => $entry['urlPath']); } } // sorting keywordarray depending first char of keyword foreach ($keywordArray as $key => $row) { $char[$key] = $row['char']; } array_multisort($char, SORT_ASC, SORT_STRING, $keywordArray); $existingChars = array_unique($char); } $keywordData = array(); $keywordData['entries'] = $keywordArray; $keywordData['chars'] = $existingChars; return $keywordData; }
public function index() { $this->init(); if (ipRequest()->getRequest('pass', '') != ipGetOption('Config.cronPassword')) { ipLog()->notice('Cron.incorrectPassword: Incorrect cron password from ip `{ip}`.', array('ip' => ipRequest()->getServer('REMOTE_ADDR'))); $response = new \Ip\Response(); $response->setContent('Fail. Please see logs for details.'); return $response; } ipStorage()->set('Cron', 'lastExecutionStart', time()); $data = array('firstTimeThisYear' => $this->firstTimeThisYear, 'firstTimeThisMonth' => $this->firstTimeThisMonth, 'firstTimeThisWeek' => $this->firstTimeThisWeek, 'firstTimeThisDay' => $this->firstTimeThisDay, 'firstTimeThisHour' => $this->firstTimeThisHour, 'lastTime' => $this->lastTime, 'test' => ipRequest()->getQuery('test')); ipLog()->info('Cron.started', $data); ipEvent('ipCronExecute', $data); ipStorage()->set('Cron', 'lastExecutionEnd', time()); ipLog()->info('Cron.finished'); $response = new \Ip\Response(); $response->setContent(__('OK', 'Ip-admin')); return $response; }
/** * @param array|string $data * @param null $defaultImage */ public function __construct($data, $defaultImage = null) { if (is_string($data)) { $data = $this->parseStr($data); } if (!empty($data['imageOrig']) && file_exists(ipFile('file/repository/' . $data['imageOrig']))) { $this->imageOrig = $data['imageOrig']; if (isset($data['x1']) && isset($data['y1']) && isset($data['x2']) && isset($data['y2'])) { $this->x1 = $data['x1']; $this->y1 = $data['y1']; $this->x2 = $data['x2']; $this->y2 = $data['y2']; if (empty($data['requiredWidth'])) { $data['requiredWidth'] = $this->x2 - $this->x1; } if (empty($data['requiredHeight'])) { $data['requiredHeight'] = $this->y2 - $this->y1; } $this->requiredWidth = $data['requiredWidth']; $this->requiredHeight = $data['requiredHeight']; $quality = null; $quality = ipGetOption('Config.slotImageQuality'); if (!$quality) { $quality = ipGetOption('Config.defaultImageQuality'); } $transform = array('type' => 'crop', 'x1' => $this->getX1(), 'y1' => $this->getY1(), 'x2' => $this->getX2(), 'quality' => $quality, 'y2' => $this->getY2(), 'width' => $this->getRequiredWidth(), 'height' => $this->getRequiredHeight()); $this->image = ipFileUrl(ipReflection($this->getImageOrig(), $transform, null)); } } else { $this->image = $defaultImage; } if (!empty($data['id'])) { $this->id = $data['id']; } else { $this->id = mt_rand(2, 2147483647); //1 used for inline logo } }
private static function makeRequest($method, $args = array(), $timeout = 10) { $args['apikey'] = ipGetOption('AsdMailChimp.apikey'); $endPoint = str_replace('<dc>', substr($args['apikey'], strpos($args['apikey'], "-") + 1), 'https://<dc>.api.mailchimp.com/2.0'); $url = $endPoint . '/' . $method . '.json'; if (function_exists('curl_init') && function_exists('curl_setopt')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args)); $result = curl_exec($ch); curl_close($ch); } else { $json_data = json_encode($args); $result = file_get_contents($url, null, stream_context_create(array('http' => array('protocol_version' => 1.1, 'user_agent' => 'PHP-MCAPI/2.0', 'method' => 'POST', 'header' => "Content-type: application/json\r\n" . "Connection: close\r\n" . "Content-length: " . strlen($json_data) . "\r\n", 'content' => $json_data)))); } return $result ? json_decode($result, true) : false; }
public static function ipBeforeApplicationClosed() { /* Automatic execution of cron. The best solution is to setup cron service to launch file www.yoursite.com/ip_cron.php few times a day. By default fake cron is enabled */ if (\Ip\Internal\Admin\Model::isSafeMode() || !ipGetOption('Config.automaticCron', 1)) { return; } $lastExecution = \Ip\ServiceLocator::storage()->get('Cron', 'lastExecutionStart'); if ($lastExecution && date('Y-m-d H') == date('Y-m-d H', $lastExecution)) { // we execute cron once an hour and cron has been executed this hour return; } if (function_exists('curl_init')) { $ch = curl_init(); $url = ipConfig()->baseUrl() . '?pa=Cron&pass='******'Config.cronPassword')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, ipConfig()->baseUrl()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, ipGetOption('Config.cronTimeout', 10)); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $fakeCronAnswer = curl_exec($ch); if ($fakeCronAnswer != __('OK', 'Ip-admin', false)) { ipLog()->error('Cron.failedFakeCron', array('result' => $fakeCronAnswer, 'type' => 'curl', 'error' => curl_error($ch))); } } else { $request = new \Ip\Request(); $request->setQuery(array('pa' => 'Cron', 'pass' => ipGetOption('Config.cronPassword'))); $fakeCronAnswer = \Ip\ServiceLocator::application()->handleRequest($request)->getContent(); if ($fakeCronAnswer != __('OK', 'Ip-admin', false)) { ipLog()->error('Cron.failedFakeCron', array('result' => $fakeCronAnswer, 'type' => 'subrequest')); } } }