Esempio n. 1
0
function mixkeyword($contentsource)
{
    $keywordsdata = new Keywords();
    $keywordslist = $keywordsdata->GetKeywordsList();
    $replacedarray = array();
    $matchnum = 0;
    if (count($keywordslist) > 0) {
        foreach ($keywordslist as $keywords) {
            if (preg_match_all("/(<a[^>]+>.*?<\\/a>)|(<img[^>]+>)|<strong>.*?<\\/strong>|<h[1-6]>.*?<\\/h[1-6]>/i", $contentsource, $matches, PREG_SET_ORDER)) {
                foreach ($matches as $match) {
                    $contentsource = str_replace($match[0], "<link>" . $matchnum . "</link>", $contentsource);
                    $replacedarray[$matchnum] = $match[0];
                    $matchnum++;
                }
            }
            if ($keywords->url != $cururl) {
                $patterns = "/(?<!<link>){$keywords->name}(?!<\\/link>)/i";
                $replacements = '<a href="' . $keywords->url . '">' . $keywords->name . '</a>';
                $contentsource = preg_replace($patterns, $replacements, $contentsource, 1);
            } else {
                $patterns = "/(?<!<link>){$keywords->name}(?!<\\/link>)/i";
                $replacements = '<strong>' . $keywords->name . '</strong>';
                $contentsource = preg_replace($patterns, $replacements, $contentsource, 1);
            }
        }
    }
    if (preg_match_all("/(?<=<link>)\\d+(?=<\\/link>)/", $contentsource, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $contentsource = str_replace("<link>" . $match[0] . "</link>", $replacedarray[$match[0]], $contentsource);
        }
    }
    return $contentsource;
}
Esempio n. 2
0
<?php

require_once 'admin.inc.php';
require_once '../include/keywords.class.php';
$curpage = $_GET["p"];
$curpage = isset($curpage) && is_numeric($curpage) ? $curpage : 1;
if ($curpage < 1) {
    $curpage = 1;
}
$searchkey = $_POST["searchkey"];
$keywhere = "";
if ($searchkey != "") {
    $keywhere = "where name like '%{$searchkey}%'";
}
$keywordsdata = new Keywords();
$keywordscount = $keywordsdata->GetKeywordsList($keywhere);
$total = count($keywordscount);
$take = 20;
$skip = ($curpage - 1) * $take;
$totalpage = (int) ($total % $take == 0 ? $total / $take : $total / $take + 1);
$keywordslist = $keywordsdata->TakeKeywordsList($skip, $take, $keywhere);
$action = $_POST["action"];
if ($action == "update") {
    $idarr = $_POST["chk"];
    if (count($idarr) > 0) {
        foreach ($idarr as $id) {
            $name = $_POST["name"];
            $url = $_POST["url"];
            $order = $_POST["order"];
            if (is_numeric($id)) {
                $sql = "update yiqi_keywords set name='" . $name[$id] . "',url='" . $url[$id] . "',displayorder='" . $order[$id] . "' WHERE kid = '{$id}' limit 1";