<?php
/**
* filter.php get's all post-data (that is send with a form (created on the tobetagged url to the file)
*
* it cleans up some code and saves it in a session
*
* @author hide@address.com
* @version 1.0.1
* @package TaggingManager
*/
// Get auto-posted values, filter, sort them and put them in session()
session_start();
$root_path = './';
include_once($root_path.'config.php');
$page_title = '';
$url = '';
$meta_descr = '';
$meta_lang = '';
$snipset = '';
$arrayTags = '';
$contentclean = '';
/**
* Function to trim a value
*
* @param string $value the value to trim
*/
function trim_value(&$value)
{
$value = trim($value);
}
// Get the posted html and parse it
// 1) remove the extra added script 'addme.php' from the code
// 2) stripslashes
// 3) e
if (array_key_exists('b', $_POST)) {
$rawhtml = $_POST["b"];
$rawhtml = ereg_replace($location."/addme.php", "", $rawhtml);
$content = stripslashes($_POST["b"]); // get content of page
$content = ereg_replace("<meta", "\n<meta", $content);
$content = html_entity_decode($content); //IE fix? :-)
$content = utf8_decode($content);
$is_title = false;
$is_descr = false;
$is_keywd = false;
$lines = preg_split("/\r?\n|\r/", $content); // turn the content in rows
$is_title = false;
$is_descr = false;
$is_keywd = false;
$close_tag = ($xhtml) ? " />" : ">";
foreach ($lines as $val) {
if (eregi("<meta name=\"description\" content=\"(.*)\"([[:space:]]?/)?>", $val, $descr)) {
$meta_descr = $descr[1];
$is_descr = true;
}
if (eregi("<meta name=\"keywords\" content=\"(.*)\"([[:space:]]?/)?>", $val, $keywd)) {
$meta_keywd = $keywd[1];
$is_keywd = true;
}
if (eregi("<meta content=\"(.*)\" name=description", $val, $descr)) {
$meta_descr = $descr[1];
$is_descr = true;
}
if (eregi("<meta content=\"(.*)\" name=keywords", $val, $keywd)) {
$meta_keywd = $keywd[1];
$is_keywd = true;
}
if ($is_descr && $is_keywd) break;
}
}
// Get the posted link
if (array_key_exists('t', $_POST)) {
$page_title = utf8_decode($_POST["t"]);
$page_title = stripslashes($page_title);
}
// Get the posted link
if (array_key_exists('u', $_POST)) {
$url = $_POST["u"];
} else {
if (isset($_GET['url'])){
$url= $_GET['url'];
}
}
// Get the posted snipset (the selected part on the tagged page)
if (array_key_exists('x', $_POST)) {
$snipset = utf8_decode($_POST["x"]);
$snipset = stripslashes($snipset);
}
//create suggestions based on title and meta_tags from html page
$unwanted = array("'", ":", "<", ">", ";", "-", "!", ".", "?", "/", "(", ")", "\"", "[", "$", "]", "=");
$ttlTags = stripslashes($page_title);
$ttlTags = strtolower($ttlTags);
$ttlTags = str_replace($unwanted, "", $ttlTags);
$ttlTags = str_replace(",","", $ttlTags);
$arrayTags1 = explode(' ',$ttlTags,-1);
$strTags = stripslashes($meta_keywd);
$strTags = strtolower ($strTags);
$strTags = str_replace($unwanted, "", $strTags);
$arrayTags2 = explode(',',$strTags,-1);
$arrayTags = array_merge($arrayTags1, $arrayTags2);
array_walk($arrayTags, 'trim_value');
asort($arrayTags);
$arrayTags = array_unique($arrayTags);
//insert stuff in session
$_SESSION['title'] = $page_title;
$_SESSION['url'] = $url;
$_SESSION['meta_descr'] = $meta_descr;
$_SESSION['meta_lang'] = $meta_lang;
$_SESSION['snipset'] = $snipset;
$_SESSION['arrayTags'] = $arrayTags;
$_SESSION['html'] = $content;
$_SESSION['rawhtml'] = $rawhtml;
header("Location: add.php");
?>