Пример #1
0
 public function searchQuery($searchVariables)
 {
     if (isset($searchVariables[$this->field]) && $searchVariables[$this->field] !== '') {
         return ' `' . $this->field . '` = ' . ipDb()->getConnection()->quote($searchVariables[$this->field] * 100) . '';
     }
     return null;
 }
Пример #2
0
 /**
  * Get error
  *
  * @param array $values
  * @param int $valueKey
  * @param $environment
  * @return string|bool
  */
 public function getError($values, $valueKey, $environment)
 {
     if (!array_key_exists($valueKey, $values)) {
         return false;
     }
     if ($values[$valueKey] == '' && empty($this->data['allowEmpty'])) {
         return false;
     }
     $table = $this->data['table'];
     $idField = empty($this->data['idField']) ? 'id' : $this->data['idField'];
     $row = ipDb()->selectRow($table, '*', array($valueKey => $values[$valueKey]));
     if (!$row) {
         return false;
     }
     if (isset($values[$idField]) && $values[$idField] == $row[$idField]) {
         return false;
     }
     if ($this->errorMessage !== null) {
         return $this->errorMessage;
     }
     if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
         $errorText = __('The value should be unique', 'Ip-admin');
     } else {
         $errorText = __('The value should be unique', 'Ip');
     }
     return $errorText;
 }
Пример #3
0
 /**
  * @param string $languageCode
  * @param int $parentId
  * @return array
  */
 protected static function getList($languageCode, $parentId)
 {
     $pages = ipDb()->selectAll('page', '*', array('parentId' => $parentId, 'isDeleted' => 0), 'ORDER BY `pageOrder`');
     $answer = array();
     //generate jsTree response array
     foreach ($pages as $page) {
         $pageData = array();
         $pageData['state'] = 'closed';
         $jsTreeId = 'page_' . $page['id'];
         if (!empty($_SESSION['Pages.nodeOpen'][$jsTreeId])) {
             $pageData['state'] = 'open';
         }
         $children = self::getList($languageCode, $page['id']);
         if (count($children) === 0) {
             $pageData['children'] = false;
             $pageData['state'] = 'leaf';
         }
         $pageData['children'] = $children;
         if ($page['isVisible']) {
             $icon = '';
         } else {
             $icon = ipFileUrl('Ip/Internal/Pages/assets/img/file_hidden.png');
         }
         $pageData['li_attr'] = array('id' => $jsTreeId, 'rel' => 'page', 'languageId' => $languageCode, 'pageId' => $page['id']);
         $pageData['data'] = array('title' => $page['title'] . '', 'icon' => $icon);
         //transform null into empty string. Null break JStree into infinite loop
         $pageData['text'] = htmlspecialchars($page['title']);
         $answer[] = $pageData;
     }
     return $answer;
 }
Пример #4
0
 private static function generatePasswordResetSecret($userId)
 {
     $secret = md5(ipConfig()->get('sessionName') . uniqid());
     $data = array('resetSecret' => $secret, 'resetTime' => time());
     ipDb()->update('administrator', $data, array('id' => $userId));
     return $secret;
 }
Пример #5
0
 public function searchQuery($searchVariables)
 {
     if (isset($searchVariables[$this->field]) && $searchVariables[$this->field] !== '') {
         return ' `' . $this->field . '` like ' . ipDb()->getConnection()->quote('%' . json_encode($searchVariables[$this->field]) . '%') . '';
     }
     return null;
 }
Пример #6
0
 public static function checkIfChildren($parentIds, $id)
 {
     $parentIds = implode(',', $parentIds);
     if (empty($parentIds)) {
         return false;
     }
     $table = ipTable('page');
     $sql = "SELECT `id` FROM {$table} WHERE `parentId` IN ({$parentIds}) AND `isVisible` = 1 AND `isDeleted` = 0 ";
     $results = ipDb()->fetchAll($sql);
     $ids = array();
     $found = false;
     foreach ($results as $result) {
         $ids[] = $result['id'];
         if ($result['id'] == $id) {
             $found = true;
             break;
         }
     }
     if ($found) {
         return true;
     } elseif (!empty($ids)) {
         return self::checkIfChildren($ids, $id);
     } else {
         return false;
     }
 }
Пример #7
0
 public static function removePermission($permission, $administratorId = null)
 {
     if ($administratorId === null) {
         $administratorId = ipAdminId();
     }
     $condition = array('permission' => $permission, 'administratorId' => $administratorId);
     ipDb()->delete('permission', $condition);
 }
Пример #8
0
 public static function getByCode($languageCode)
 {
     $row = ipDb()->selectRow('language', '*', array('code' => $languageCode));
     if (!$row) {
         return null;
     }
     return new self($row['id'], $row['code'], $row['url'], $row['title'], $row['abbreviation'], $row['isVisible'], $row['textDirection']);
 }
Пример #9
0
 public static function veryEmail_10($vcode)
 {
     $fcode = substr($vcode, 0, strpos($vcode, '-!'));
     $mail = substr($vcode, strpos($vcode, '-!') + 2, 250);
     ipDb()->update('comments', array('approved' => '1'), array('verification_code' => $fcode, 'email' => $mail));
     $data = array('message' => __('Your email address has been verified. Thank you.', 'Comments'));
     return ipView('view/mailVerified.php', $data)->render();
 }
Пример #10
0
 /**
  * Find all files bind to particular module
  */
 public function findFiles($plugin, $instanceId = null)
 {
     $where = array('plugin' => $plugin);
     if ($instanceId !== null) {
         $where['instanceId'] = $instanceId;
     }
     return ipDb()->selectAll('repository_file', '*', $where);
 }
Пример #11
0
 public static function ipWidgetDuplicated($data)
 {
     $oldId = $data['oldWidgetId'];
     $newId = $data['newWidgetId'];
     $newRevisionId = ipDb()->selectValue('widget', 'revisionId', array('id' => $newId));
     $widgetTable = ipTable('widget');
     $sql = "\n            UPDATE\n                {$widgetTable}\n            SET\n                `blockName` = REPLACE(`blockName`, 'block_" . (int) $oldId . "', 'block_" . (int) $newId . "')\n            WHERE\n                `revisionId` = :newRevisionId\n            ";
     ipDb()->execute($sql, array('newRevisionId' => $newRevisionId));
 }
Пример #12
0
 /**
  * Get all storage values
  *
  * @return array Key=>value array of all storage values
  */
 public function getAll()
 {
     $values = ipDb()->selectAll($this->tableName, array($this->keyColumn, $this->valueColumn), array($this->namespaceColumn => $this->namespace));
     $result = array();
     foreach ($values as $value) {
         $result[$value[$this->keyColumn]] = json_decode($value[$this->valueColumn], true);
     }
     return $result;
 }
Пример #13
0
 /**
  * Drops the datatable repository db table
  */
 private function dropDataTableRepository()
 {
     $ipTable = ipTable(TableRepository::DATA_TABLE_REPOSITORY);
     $sql = "\n            DROP TABLE {$ipTable}\n        ";
     try {
         ipDb()->execute($sql);
     } catch (\Ip\Exception\Db $e) {
         ipLog()->error("Could not drop repository table. Statement: {$sql}, Message: " . $e->getMessage());
     }
 }
Пример #14
0
 /**
  * @param string $alias
  * @param string|null $languageCode
  * @return \Ip\Page
  */
 public function getPageByAlias($alias, $languageCode = null)
 {
     if ($languageCode === null) {
         $languageCode = ipContent()->getCurrentLanguage()->getCode();
     }
     $row = ipDb()->selectRow('page', '*', array('alias' => $alias, 'languageCode' => $languageCode, 'isDeleted' => 0));
     if (!$row) {
         return null;
     }
     return new \Ip\Page($row);
 }
Пример #15
0
 public static function emptyPageForm()
 {
     $form = new \Ip\Form();
     $form->setEnvironment(\Ip\Form::ENVIRONMENT_ADMIN);
     $pages = ipDb()->selectAll('page', 'id, title', array('isDeleted' => 1));
     foreach ($pages as $page) {
         $field = new \Ip\Form\Field\Checkbox(array('name' => 'page[]', 'label' => $page['title'], 'value' => true, 'postValue' => $page['id']));
         $form->addField($field);
     }
     return $form;
 }
Пример #16
0
 public static function newUrl($preferredUrl)
 {
     $suffix = '';
     $url = ipDb()->selectAll('language', 'id', array('url' => $preferredUrl . $suffix));
     if (empty($url)) {
         return $preferredUrl;
     }
     while (!empty($url)) {
         $suffix++;
         $url = ipDb()->selectAll('language', 'id', array('url' => $preferredUrl . $suffix));
     }
     return $preferredUrl . $suffix;
 }
Пример #17
0
 public static function importData($tablePrefix)
 {
     $errors = array();
     $sqlFile = self::ipFile('Plugin/Install/sql/data.sql');
     $fh = fopen($sqlFile, 'r');
     $sql = fread($fh, utf8_decode(filesize($sqlFile)));
     fclose($fh);
     $sql = str_replace("INSERT INTO `ip_", "INSERT INTO `" . $tablePrefix, $sql);
     $sql = str_replace("[[[[version]]]]", ipApplication()->getVersion(), $sql);
     $sql = str_replace("[[[[dbversion]]]]", \Ip\Internal\Update\Model::getDbVersion(), $sql);
     $sql = str_replace("[[[[time]]]]", date('Y-m-d H:i:s'), $sql);
     $sql = str_replace("[[[[timestamp]]]]", time(), $sql);
     ipDb()->execute($sql);
     return $errors;
 }
Пример #18
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param array $context
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     if (!ipDb()->isConnected()) {
         // do not log things if we have no database connection
         return;
     }
     if (!is_string($message)) {
         // Probably programmer made a mistake, used Logger::log($message, $context)
         $row = array('level' => \Psr\Log\LogLevel::ERROR, 'message' => 'Code uses ipLog()->log() without giving $level info.', 'context' => json_encode(array('args' => func_get_args())));
         ipDb()->insert('log', $row);
         return;
     }
     $row = array('level' => $level, 'message' => $message, 'context' => json_encode($context));
     ipDb()->insert('log', $row);
 }
Пример #19
0
 public static function download()
 {
     $requestFile = ipFile('') . ipRequest()->getRelativePath();
     $fileDir = ipFile('file/');
     if (mb_strpos($requestFile, $fileDir) !== 0) {
         return null;
     }
     $file = mb_substr($requestFile, mb_strlen($fileDir));
     $file = urldecode($file);
     if (empty($file)) {
         throw new \Ip\Exception('Required parameter is missing');
     }
     $absoluteSource = realpath(ipFile('file/' . $file));
     if (!$absoluteSource || !is_file($absoluteSource)) {
         throw new \Ip\Exception\Repository\Transform("File doesn't exist", array('filename' => $absoluteSource));
     }
     if (strpos($absoluteSource, realpath(ipFile('file/'))) !== 0 || strpos($absoluteSource, realpath(ipFile('file/secure'))) === 0) {
         throw new \Exception("Requested file (" . $file . ") is outside of public dir");
     }
     $mime = \Ip\Internal\File\Functions::getMimeType($absoluteSource);
     $fsize = filesize($absoluteSource);
     // set headers
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: public");
     header('Content-type: ' . $mime);
     header("Content-Transfer-Encoding: binary");
     header("Content-Length: " . $fsize);
     // download
     // @readfile($file_path);
     $file = @fopen($absoluteSource, "rb");
     if ($file) {
         while (!feof($file)) {
             print fread($file, 1024 * 8);
             flush();
             if (connection_status() != 0) {
                 @fclose($file);
                 die;
             }
         }
         @fclose($file);
     }
     //TODO provide method to stop any output by ImpressPages
     ipDb()->disconnect();
     exit;
 }
Пример #20
0
 public static function getMenus()
 {
     $menuAliases = self::getMenuAliases();
     $currLangCode = ipContent()->getCurrentLanguage()->getCode();
     if (!empty($menuAliases)) {
         $menuPages = array();
         foreach ($menuAliases as $menuAlias) {
             $menuRec = ipDb()->selectAll('page', 'id, title, alias', array('isDeleted' => 0, 'alias' => $menuAlias, 'parentId' => 0, 'isDisabled' => 0, 'isSecured' => 0, 'languageCode' => $currLangCode), 'ORDER BY `pageOrder`');
             if (!empty($menuRec)) {
                 $menuPages = array_merge($menuPages, $menuRec);
             }
         }
     } else {
         $menuPages = ipDb()->selectAll('page', 'id, title, alias', array('isDeleted' => 0, 'alias' => $menuAlias, 'parentId' => 0, 'isDisabled' => 0, 'isSecured' => 0, 'languageCode' => $currLangCode), 'ORDER BY `pageOrder`');
     }
     return $menuPages;
 }
Пример #21
0
    public function activate()
    {
        $sql = '
        CREATE TABLE IF NOT EXISTS
           ' . ipTable(\Plugin\MasonryGrid\Config::TABLE_NAME) . '
        (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `itemOrder` double,
        `widgetId` int(11),
        `title` varchar(255),
        `image` varchar(255),
		`description` text,
		`url` varchar(255),
        `isVisible` int(1),
        PRIMARY KEY (`id`)
        )';
        ipDb()->execute($sql);
    }
Пример #22
0
 /**
  * @parem string $languageCode
  * @param $languageCode
  * @param string $urlPath
  * @returns bool true if url is available
  */
 public static function isPathAvailable($languageCode, $urlPath)
 {
     $pageId = ipDb()->selectValue('page', '`id`', array('languageCode' => $languageCode, 'urlPath' => $urlPath, 'isDeleted' => 0));
     if ($pageId) {
         return false;
     }
     //if lash exists, remove. If there is no slash, add it.
     if (substr($urlPath, -1) == '/') {
         $urlPath = substr($urlPath, 0, -1);
     } else {
         $urlPath .= '/';
     }
     $pageId = ipDb()->selectValue('page', '`id`', array('languageCode' => $languageCode, 'urlPath' => $urlPath, 'isDeleted' => 0));
     if (!$pageId) {
         return true;
     }
     return false;
 }
Пример #23
0
 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;
 }
Пример #24
0
 private static function arrayToMenuItem($pages, $depth, $curDepth, $order)
 {
     $items = array();
     foreach ($pages as $pageRow) {
         $page = new \Ip\Page($pageRow['id']);
         $item = new Item();
         $subSelected = false;
         if ($curDepth < $depth) {
             $children = ipDb()->selectAll('page', '*', array('parentId' => $page->getId(), 'isVisible' => 1, 'isSecured' => 0, 'isDeleted' => 0), "ORDER BY {$order}");
             if ($children) {
                 $childrenItems = self::arrayToMenuItem($children, $depth, $curDepth + 1, $order);
                 $item->setChildren($childrenItems);
             }
         }
         if ($page->isCurrent() || $page->getRedirectUrl() && $page->getLink() == \Ip\Internal\UrlHelper::getCurrentUrl()) {
             $item->markAsCurrent(true);
         } elseif ($page->isInCurrentBreadcrumb() || $subSelected || $page->getRedirectUrl() && self::existInBreadcrumb($page->getLink())) {
             $item->markAsInCurrentBreadcrumb(true);
         }
         if ($page->isDisabled()) {
             $item->setUrl('');
         } elseif ($page->getRedirectUrl()) {
             $url = $page->getRedirectUrl();
             if (!preg_match('/^((http|https):\\/\\/)/i', $url)) {
                 $url = 'http://' . $url;
             }
             $item->setUrl($url);
         } else {
             $item->setUrl($page->getLink());
         }
         $metaTitle = $page->getMetaTitle();
         $item->setBlank($page->isBlank());
         $item->setTitle($page->getTitle());
         $item->setDepth($curDepth);
         $item->setDisabled($page->isDisabled());
         $item->setId($page->getId());
         $item->setAlias($page->getAlias());
         $item->setPageTitle(empty($metaTitle) ? $page->getTitle() : $metaTitle);
         $items[] = $item;
     }
     return $items;
 }
Пример #25
0
    public function activate()
    {
        $sql = '
        CREATE TABLE IF NOT EXISTS
           ' . ipTable('slideshow') . '
        (
        `id` int(11) NOT NULL AUTO_INCREMENT,
		`widgetId` int(11),
        `slideshowOrder` double,
        `title` varchar(255),
        `text` varchar(255),
        `url` varchar(255),
        `Enabled` boolean,
        `image` varchar(255),
		`lang` varchar(3),
		`itemOrder` double,
		`isVisible` int(1),
        PRIMARY KEY (`id`)
        )';
        ipDb()->execute($sql);
    }
Пример #26
0
 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);
 }
Пример #27
0
 protected static function updateTableUrl($oldUrl, $newUrl, $table, $keyFields)
 {
     $old = parse_url($oldUrl);
     $new = parse_url($newUrl);
     $oldPart = $old['host'] . $old['path'];
     $newPart = $new['host'] . $new['path'];
     $quotedPart = substr(ipDb()->getConnection()->quote('://' . $oldPart), 1, -1);
     $search = '%' . addslashes($quotedPart) . '%';
     $tableWithPrefix = ipTable($table);
     $records = ipDb()->fetchAll("SELECT * FROM {$tableWithPrefix} WHERE `value` LIKE ?", array($search));
     if (!$records) {
         return;
     }
     if ($newUrl == ipConfig()->baseUrl()) {
         //the website has been moved
         $search = '%\\b(https?://)' . preg_quote($oldPart, '%') . '%';
     } else {
         //internal page url has changed
         // \b - start at word boundary
         // (https?://) - protocol
         // (/?) - allow optional slash at the end of url
         // (?= ) - symbols expected after url
         // \Z - end of subject or end of line
         $search = '%\\b(https?://)' . preg_quote($oldPart, '%') . '(/?)(?=["\'?]|\\s|\\Z)%';
     }
     foreach ($records as $row) {
         // ${1} - protocol, ${2} - optional '/'
         $after = preg_replace($search, '${1}' . $newPart . '${2}', $row['value']);
         if ($after != $row['value']) {
             $where = array();
             foreach ($keyFields as $keyField) {
                 $where[$keyField] = $row[$keyField];
             }
             ipDb()->update($table, array('value' => $after), $where);
         }
     }
 }
Пример #28
0
 /**
  * @ignore
  */
 public function close()
 {
     ipEvent('ipBeforeApplicationClosed');
     ipDb()->disconnect();
 }
Пример #29
0
 public function remove()
 {
     $sql = 'DROP TABLE IF EXISTS ' . ipTable('comments');
     ipDb()->execute($sql);
 }
Пример #30
0
 public static function deleteOldLogs($days)
 {
     $logTable = ipTable('log');
     ipDb()->execute("delete from {$logTable} where  (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`time`)) > ?", array($days * 24 * 60 * 60));
 }