Exemplo n.º 1
0
function wp_keywordlink_cvsimport()
{
    if (is_uploaded_file($_FILES['upload']['tmp_name'])) {
        $cvscontent = file($_FILES['upload']['tmp_name'], FILE_IGNORE_NEW_LINES);
        $links = get_option(WP_KEYWORDLINK_OPTION);
        // Keep some statistics
        $cnt = 0;
        $skip = 0;
        $replace = 0;
        $added = 0;
        foreach ($cvscontent as $row => $value) {
            // Skip the first row
            if ($cnt++ == 0) {
                // A little check to see if the file we are importing isn't complete garbage
                if (strstr($value, "Keyword") === FALSE) {
                    wp_keywordlink_topbarmessage("Not a Valid File! Please Cheack File Format");
                    return;
                }
                continue;
            }
            if (preg_match("/^#/", $value)) {
                $skip++;
                continue;
            }
            list($keyword, $link, $nofollow, $firstonly, $newwindow, $ignorecase, $isaffiliate, $docomments, $zh_CN, $desc) = explode(",", $value);
            // Strip "" from the beginning and end of the keyword and url
            $keyword = trim($keyword, "\"");
            $link = trim($link, "\"");
            if (!$desc) {
                $desc = $keyword;
            } else {
                $desc = trim($desc, "\"");
            }
            // Ignore empty keywords, or keywords with no link
            if ($keyword == "" || $link == "") {
                $skip++;
                continue;
            }
            // Count how many entries we are replacing
            if ($links[$keyword]) {
                $replace++;
            } else {
                $added++;
            }
            // Input validation
            if ($nofollow) {
                $nofollow = 1;
            }
            if ($firstonly) {
                $firstonly = 1;
            }
            if ($newwindow) {
                $newwindow = 1;
            }
            if ($ignorecase) {
                $ignorecase = 1;
            }
            if ($isaffiliate) {
                $isaffiliate = 1;
            }
            if ($docomments) {
                $docomments = 1;
            }
            if ($zh_CN) {
                $zh_CN = 1;
            }
            $newlinks[$keyword] = implode('|', array($link, $nofollow, $firstonly, $newwindow, $ignorecase, $isaffiliate, $docomments, $zh_CN, $desc));
        }
        // If we encountered no errors, merge the new keywords with the existing keywords
        foreach ($newlinks as $keyword => $parameters) {
            $links[$keyword] = $parameters;
        }
        // Update the wordpress database
        update_option(WP_KEYWORDLINK_OPTION, $links);
        wp_keywordlink_topbarmessage("Import complete (replaced {$replace} keywords, ignored {$skip} empty, added {$added} entries)");
    } else {
        wp_keywordlink_topbarmessage("Error uploading file");
    }
}
Exemplo n.º 2
0
function wp_pagelimit_updated()
{
    if (isset($_POST['page_limit'])) {
        $page_limit = $_POST['page_limit'];
        update_option(WP_PAGELIMIT_OPTION, $page_limit);
        wp_keywordlink_topbarmessage(__('Congratulate, Updated success', 'wp_keywordlink'));
    }
}