/** * Ajout/modification des textes internationnalisés d'un élément. * * @param integer $iItemId * @param array $aItemLocalesData */ protected function setItemI18n($iItemId, $aItemLocalesData) { foreach ($this->okt->languages->list as $aLanguage) { if (empty($aItemLocalesData[$aLanguage['code']]['title'])) { continue; } $oCursor = $this->db->openCursor($this->t_items_locales); $oCursor->item_id = $iItemId; $oCursor->language = $aLanguage['code']; foreach ($aItemLocalesData[$aLanguage['code']] as $k => $v) { $oCursor->{$k} = $v; } $oCursor->content = $this->okt->HTMLfilter($oCursor->content); $oCursor->words = implode(' ', array_unique(text::splitWords($oCursor->title . ' ' . $oCursor->subtitle . ' ' . $oCursor->content . ' ' . $oCursor->author . ' ' . $oCursor->place))); $oCursor->meta_description = html::clean($oCursor->meta_description); $oCursor->meta_keywords = html::clean($oCursor->meta_keywords); $oCursor->insertUpdate(); $this->setItemSlug($iItemId, $aLanguage['code']); } }
private function getCommentCursor($cur) { if ($cur->comment_content !== null && $cur->comment_content == '') { throw new Exception(__('You must provide a comment')); } if ($cur->comment_author !== null && $cur->comment_author == '') { throw new Exception(__('You must provide an author name')); } if ($cur->comment_email != '' && !text::isEmail($cur->comment_email)) { throw new Exception(__('Email address is not valid.')); } if ($cur->comment_site !== null && $cur->comment_site != '') { if (!preg_match('|^http(s?)://|i', $cur->comment_site, $matches)) { $cur->comment_site = 'http://' . $cur->comment_site; } else { $cur->comment_site = strtolower($matches[0]) . substr($cur->comment_site, strlen($matches[0])); } } if ($cur->comment_status === null) { $cur->comment_status = (int) $this->settings->system->comments_pub; } # Words list if ($cur->comment_content !== null) { $cur->comment_words = implode(' ', text::splitWords($cur->comment_content)); } }
/** Recreates comments search engine index. @param start <b>integer</b> Start comment index @param limit <b>integer</b> Number of comments to index @return <b>integer</b> <var>$start</var> and <var>$limit</var> sum */ public function indexAllComments($start = null, $limit = null) { $strReq = 'SELECT COUNT(comment_id) ' . 'FROM ' . $this->prefix . 'comment'; $rs = $this->con->select($strReq); $count = $rs->f(0); $strReq = 'SELECT comment_id, comment_content ' . 'FROM ' . $this->prefix . 'comment '; if ($start !== null && $limit !== null) { $strReq .= $this->con->limit($start, $limit); } $rs = $this->con->select($strReq); $cur = $this->con->openCursor($this->prefix . 'comment'); while ($rs->fetch()) { $cur->comment_words = implode(' ', text::splitWords($rs->comment_content)); $cur->update('WHERE comment_id = ' . (int) $rs->comment_id); $cur->clean(); } if ($start + $limit > $count) { return null; } return $start + $limit; }
/** * Reconstruction des index de recherche de tous les produits * */ public function indexAllProducts() { $rsProducts = $this->getProds(array('visibility' => 2)); while ($rsProducts->fetch()) { $words = $rsProducts->title . ' ' . $rsProducts->subtitle . ' ' . $rsProducts->content_short . ' ' . $rsProducts->content . ' '; $words = implode(' ', text::splitWords($words)); $query = 'UPDATE ' . $this->t_products . ' SET ' . 'words=\'' . $this->db->escapeStr($words) . '\' ' . 'WHERE id=' . (int) $rsProducts->id; $this->db->execute($query); } return true; }
/** * Retourne la liste des thèmes disponibles avec les infos de l'administration. * * @return array */ public function getThemesAdminList() { $aThemes = $this->getThemesList(); foreach ($aThemes as $iThemeId => $aTheme) { # search indexes $aThemes[$iThemeId]['index'] = text::splitWords($aThemes[$iThemeId]['name'] . ' ' . $aThemes[$iThemeId]['desc'] . ' ' . $aThemes[$iThemeId]['tags']); $aThemes[$iThemeId]['index'] = array_map('strtolower', $aThemes[$iThemeId]['index']); $aThemes[$iThemeId]['index'] = array_unique($aThemes[$iThemeId]['index']); array_unshift($aThemes[$iThemeId]['index'], $iThemeId); # is active ? if ($aTheme['id'] == $this->okt->config->theme) { $aThemes[$iThemeId]['is_active'] = true; array_unshift($aThemes[$iThemeId]['index'], 'active'); array_unshift($aThemes[$iThemeId]['index'], 'actif'); } else { $aThemes[$iThemeId]['is_active'] = false; } # is mobile ? if ($aTheme['id'] == $this->okt->config->theme_mobile) { $aThemes[$iThemeId]['is_mobile'] = true; array_unshift($aThemes[$iThemeId]['index'], 'mobile'); array_unshift($aThemes[$iThemeId]['index'], 'mobil'); array_unshift($aThemes[$iThemeId]['index'], 'active'); array_unshift($aThemes[$iThemeId]['index'], 'actif'); } else { $aThemes[$iThemeId]['is_mobile'] = false; } # is tablet ? if ($aTheme['id'] == $this->okt->config->theme_tablet) { $aThemes[$iThemeId]['is_tablet'] = true; array_unshift($aThemes[$iThemeId]['index'], 'tablet'); array_unshift($aThemes[$iThemeId]['index'], 'tablette'); array_unshift($aThemes[$iThemeId]['index'], 'active'); array_unshift($aThemes[$iThemeId]['index'], 'actif'); } else { $aThemes[$iThemeId]['is_tablet'] = false; } # has screenshot ? if (file_exists($this->sPath . '/' . $aTheme['id'] . '/screenshot.jpg')) { $aThemes[$iThemeId]['screenshot'] = true; } else { $aThemes[$iThemeId]['screenshot'] = false; } # has config ? if (file_exists($this->sPath . '/' . $aTheme['id'] . '/admin/config.php')) { $aThemes[$iThemeId]['has_config'] = true; } else { $aThemes[$iThemeId]['has_config'] = false; } } return $aThemes; }
protected function importComments($post_id, $new_post_id, $db) { $count_c = $count_t = 0; $rs = $db->select('SELECT * FROM ' . $this->vars['db_prefix'] . 'comment ' . 'WHERE post_id = ' . (int) $post_id . ' '); while ($rs->fetch()) { $cur = $this->con->openCursor($this->prefix . 'comment'); $cur->post_id = (int) $new_post_id; $cur->comment_author = $this->cleanStr($rs->comment_auteur); $cur->comment_status = (int) $rs->comment_pub; $cur->comment_dt = $rs->comment_dt; $cur->comment_upddt = $rs->comment_upddt; $cur->comment_email = $this->cleanStr($rs->comment_email); $cur->comment_content = $this->cleanStr($rs->comment_content); $cur->comment_ip = $rs->comment_ip; $cur->comment_trackback = (int) $rs->comment_trackback; $cur->comment_site = $this->cleanStr($rs->comment_site); if ($cur->comment_site != '' && !preg_match('!^http://.*$!', $cur->comment_site)) { $cur->comment_site = substr('http://' . $cur->comment_site, 0, 255); } if ($rs->exists('spam') && $rs->spam && ($rs->comment_status = 0)) { $cur->comment_status = -2; } $cur->comment_words = implode(' ', text::splitWords($cur->comment_content)); $cur->comment_id = $this->con->select('SELECT MAX(comment_id) FROM ' . $this->prefix . 'comment')->f(0) + 1; $cur->insert(); if ($cur->comment_trackback && $cur->comment_status == 1) { $count_t++; } elseif ($cur->comment_status == 1) { $count_c++; } } if ($count_t > 0 || $count_c > 0) { $this->con->execute('UPDATE ' . $this->prefix . 'post SET ' . 'nb_comment = ' . $count_c . ', ' . 'nb_trackback = ' . $count_t . ' ' . 'WHERE post_id = ' . (int) $new_post_id . ' '); } }
protected function importComments($post_id, $new_post_id, &$db) { $count_c = $count_t = 0; $rs = $db->select('SELECT * FROM ' . $this->vars['db_prefix'] . 'comments ' . 'WHERE comment_post_ID = ' . (int) $post_id . ' '); while ($rs->fetch()) { $cur = $this->con->openCursor($this->prefix . 'comment'); $cur->post_id = (int) $new_post_id; $cur->comment_author = $this->cleanStr($rs->comment_author); $cur->comment_status = (int) $rs->comment_approved; $cur->comment_dt = $rs->comment_date; $cur->comment_email = $this->cleanStr($rs->comment_author_email); $cur->comment_content = $this->core->callFormater($this->vars['comment_formater'], $this->cleanStr($rs->comment_content)); $cur->comment_ip = $rs->comment_author_IP; $cur->comment_trackback = $rs->comment_type == 'trackback' ? 1 : 0; $cur->comment_site = substr($this->cleanStr($rs->comment_author_url), 0, 255); if (!isset($cur->comment_site)) { $cur->comment_site = NULL; } if ($rs->comment_approved == 'spam') { $cur->comment_status = -2; } $cur->comment_words = implode(' ', text::splitWords($cur->comment_content)); $cur->comment_id = $this->con->select('SELECT MAX(comment_id) FROM ' . $this->prefix . 'comment')->f(0) + 1; $cur->insert(); if ($cur->comment_trackback && $cur->comment_status == 1) { $count_t++; } elseif ($cur->comment_status == 1) { $count_c++; } } if ($count_t > 0 || $count_c > 0) { $this->con->execute('UPDATE ' . $this->prefix . 'post SET ' . 'nb_comment = ' . $count_c . ', ' . 'nb_trackback = ' . $count_t . ' ' . 'WHERE post_id = ' . (int) $new_post_id . ' '); } }
/** * Renvoie les données concernant un ou plusieurs utilisateurs. * La méthode renvoie false si elle échoue. * * @param array params Les paramètres * @param boolean count_only Permet de ne retourner que le compte * @return recordset */ public function getUsers($aParams = array(), $count_only = false) { $sReqPlus = 'WHERE 1 '; if (isset($aParams['id'])) { $sReqPlus .= 'AND u.id=' . (int) $aParams['id'] . ' '; } if (isset($aParams['username'])) { $sReqPlus .= 'AND u.username=\'' . $this->db->escapeStr($aParams['username']) . '\' '; } if (isset($aParams['active'])) { if ($aParams['active'] == 0) { $sReqPlus .= 'AND u.active=0 '; } elseif ($aParams['active'] == 1) { $sReqPlus .= 'AND u.active=1 '; } elseif ($aParams['active'] == 2) { $sReqPlus .= ''; } } if (isset($aParams['group_id'])) { if (is_array($aParams['group_id'])) { $aParams['group_id'] = array_map('intval', $aParams['group_id']); $sReqPlus .= 'AND u.group_id IN (' . implode(',', $aParams['group_id']) . ') '; } else { $sReqPlus .= 'AND u.group_id=' . (int) $aParams['group_id'] . ' '; } } if (!empty($aParams['group_id_not'])) { if (is_array($aParams['group_id_not'])) { $aParams['group_id_not'] = array_map('intval', $aParams['group_id_not']); $sReqPlus .= 'AND u.group_id NOT IN (' . implode(',', $aParams['group_id_not']) . ') '; } else { $sReqPlus .= 'AND u.group_id<>' . (int) $aParams['group_id_not'] . ' '; } } if (!empty($aParams['search'])) { $aWords = text::splitWords($aParams['search']); if (!empty($aWords)) { foreach ($aWords as $i => $w) { $aWords[$i] = 'u.username LIKE \'%' . $this->db->escapeStr($w) . '%\' OR ' . 'u.lastname LIKE \'%' . $this->db->escapeStr($w) . '%\' OR ' . 'u.firstname LIKE \'%' . $this->db->escapeStr($w) . '%\' OR ' . 'u.email LIKE \'%' . $this->db->escapeStr($w) . '%\' '; } $sReqPlus .= ' AND ' . implode(' AND ', $aWords) . ' '; } } if ($count_only) { $sQuery = 'SELECT COUNT(u.id) AS num_users ' . 'FROM ' . $this->t_users . ' AS u ' . $sReqPlus; } else { $sQuery = 'SELECT u.*, g.* ' . 'FROM ' . $this->t_users . ' AS u ' . 'LEFT JOIN ' . $this->t_groups . ' AS g ON g.group_id=u.group_id ' . $sReqPlus; if (isset($aParams['order'])) { $sQuery .= 'ORDER BY ' . $aParams['order'] . ' '; } else { $sQuery .= 'ORDER BY u.username DESC '; } if (isset($aParams['limit'])) { $sQuery .= 'LIMIT ' . $aParams['limit'] . ' '; } } if (($rs = $this->db->select($sQuery)) === false) { return new recordset(array()); } if ($count_only) { return (int) $rs->num_users; } else { return $rs; } }
/** * Reconstruction des index de recherche de tous les articles. * */ public function indexAllPosts() { $rsPosts = $this->db->select('SELECT post_id, language, title, subtitle, content FROM ' . $this->t_news_locales); while ($rsPosts->fetch()) { $words = $rsPosts->title . ' ' . $rsPosts->subtitle . ' ' . $rsPosts->content . ' '; $words = implode(' ', text::splitWords($words)); $query = 'UPDATE ' . $this->t_news . ' SET ' . 'words=\'' . $this->db->escapeStr($words) . '\' ' . 'WHERE post_id=' . (int) $rsPosts->id . ' ' . 'AND language=\'' . $this->db->escapeStr($rsPosts->language) . '\' '; $this->db->execute($query); } return true; }
/** * Enregistrement des textes internationalisés * * @return boolean */ protected function setQuestionI18n() { foreach ($this->okt->languages->list as $aLanguage) { $this->params['content'][$aLanguage['code']] = $this->okt->HTMLfilter($this->params['content'][$aLanguage['code']]); $words = implode(' ', text::splitWords($this->params['title'][$aLanguage['code']] . ' ' . $this->params['content'][$aLanguage['code']])); $query = 'INSERT INTO ' . $this->t_faq_locales . ' ' . '(faq_id, language, title, title_tag, title_seo, slug, content, meta_description, meta_keywords, words) ' . 'VALUES (' . (int) $this->params['id'] . ', ' . '\'' . $this->db->escapeStr($aLanguage['code']) . '\', ' . (empty($this->params['title'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['title_tag'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title_tag'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['title_seo'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title_seo'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['slugs'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['slugs'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['content'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['content'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['meta_description'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['meta_description'][$aLanguage['code']]) . '\'') . ', ' . (empty($this->params['meta_keywords'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['meta_keywords'][$aLanguage['code']]) . '\'') . ', ' . (empty($words) ? 'NULL' : '\'' . $this->db->escapeStr($words) . '\'') . ' ' . ') ON DUPLICATE KEY UPDATE ' . 'title=' . (empty($this->params['title'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title'][$aLanguage['code']]) . '\'') . ', ' . 'title_tag=' . (empty($this->params['title_tag'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title_tag'][$aLanguage['code']]) . '\'') . ', ' . 'title_seo=' . (empty($this->params['title_seo'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['title_seo'][$aLanguage['code']]) . '\'') . ', ' . 'slug=' . (empty($this->params['slugs'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['slugs'][$aLanguage['code']]) . '\'') . ', ' . 'content=' . (empty($this->params['content'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['content'][$aLanguage['code']]) . '\'') . ', ' . 'meta_description=' . (empty($this->params['meta_description'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['meta_description'][$aLanguage['code']]) . '\'') . ', ' . 'meta_keywords=' . (empty($this->params['meta_keywords'][$aLanguage['code']]) ? 'NULL' : '\'' . $this->db->escapeStr($this->params['meta_keywords'][$aLanguage['code']]) . '\'') . ', ' . 'words=' . (empty($words) ? 'NULL' : '\'' . $this->db->escapeStr($words) . '\'') . ' '; if (!$this->db->execute($query)) { return false; } if (!$this->setQuestionSlug($this->params['id'], $aLanguage['code'])) { return false; } } return true; }