Example #1
0
/**
 * Performs all the feed-related admin actions
 */
function channel_admin()
{
    // Fix for #16: Admin (et al.) should not rely on l10n labels for actions:
    // Look for a meta-action first, which should be the (untranslated) *name* of
    // the (translated) action constant.
    // Fixme: should replace 'action's with a constant
    if (array_key_exists(CST_ADMIN_METAACTION, $_REQUEST)) {
        $__action__ = $_REQUEST[CST_ADMIN_METAACTION];
    } elseif (array_key_exists('action', $_REQUEST)) {
        $__action__ = $_REQUEST['action'];
    } else {
        $__action__ = "";
    }
    $ret__ = CST_ADMIN_DOMAIN_NONE;
    switch ($__action__) {
        case __('Add'):
        case 'ACT_ADMIN_ADD':
        case 'Add':
            $label = trim(sanitize($_REQUEST['new_channel'], RSS_SANITIZER_URL));
            $fid = trim(sanitize($_REQUEST['add_channel_to_folder'], RSS_SANITIZER_NUMERIC));
            list($flabel) = rss_fetch_row(rss_query("select name from " . getTable('folders') . " where id={$fid}"));
            // handle "feed:" urls
            if (substr($label, 0, 5) == 'feed:') {
                if (substr($label, 0, 11) == "feed://http") {
                    $label = substr($label, 5);
                } else {
                    // handle feed://example.com/rss.xml urls
                    $label = "http:" . substr($label, 5);
                }
            }
            if ($label != 'http://' && substr($label, 0, 4) == "http") {
                $tags = @$_REQUEST['channel_tags'];
                $ret = add_channel($label, $fid, null, null, $tags);
                //var_dump($ret);
                if (is_array($ret) && $ret[0] > -1) {
                    update($ret[0]);
                    rss_invalidate_cache();
                    // feedback
                    $newCid = $ret[0];
                    rss_error(sprintf(__('Adding %s to %s... '), htmlentities($label), "/{$flabel}") . __('OK') . "&nbsp;[<a href=\"" . getPath() . "admin/index.php?domain=" . CST_ADMIN_DOMAIN_CHANNEL . "&amp;action=edit&amp;cid={$newCid}\">" . __('edit') . "</a>]", RSS_ERROR_ERROR, true);
                    $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                } elseif (is_array($ret) && $ret[0] > -2) {
                    // okay, something went wrong, maybe thats a html url after all?
                    // let's try and see if we can extract some feeds
                    $feeds = extractFeeds($label);
                    if (!is_array($feeds) || sizeof($feeds) == 0) {
                        rss_error($ret[1], RSS_ERROR_ERROR, true);
                        $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                    } else {
                        //one single feed in the html doc, add that
                        if (is_array($feeds) && sizeof($feeds) == 1 && array_key_exists('href', $feeds[0])) {
                            $ret = add_channel($feeds[0]['href'], $fid);
                            if (is_array($ret) && $ret[0] > -1) {
                                update($ret[0]);
                                rss_invalidate_cache();
                                // feedback
                                $newCid = $ret[0];
                                rss_error(sprintf(__('Adding %s to %s... '), htmlentities($label), "/{$flabel}") . __('OK') . "&nbsp;[<a href=\"" . getPath() . "admin/index.php?domain=" . CST_ADMIN_DOMAIN_CHANNEL . "&amp;action=edit&amp;cid={$newCid}\">" . __('edit') . "</a>]", RSS_ERROR_ERROR, true);
                                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                            } else {
                                // failure
                                rss_error($ret[1], RSS_ERROR_ERROR, true);
                                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                            }
                        } else {
                            // multiple feeds in the channel
                            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n" . "<p>" . sprintf(__('The following feeds were found in <a href="%s">%s</a>, which one would you like to subscribe?'), $label, $label) . "</p>\n";
                            $cnt = 0;
                            while (list($id, $feedarr) = each($feeds)) {
                                // we need an URL
                                if (!array_key_exists('href', $feedarr)) {
                                    continue;
                                } else {
                                    $href = $feedarr['href'];
                                }
                                if (array_key_exists('type', $feedarr)) {
                                    $typeLbl = " [<a href=\"{$href}\">" . $feedarr['type'] . "</a>]";
                                }
                                $cnt++;
                                if (array_key_exists('title', $feedarr)) {
                                    $lbl = $feedarr['title'];
                                } elseif (array_key_exists('type', $feedarr)) {
                                    $lbl = $feedarr['type'];
                                    $typeLbl = "";
                                } elseif (array_key_exists('href', $feedarr)) {
                                    $lbl = $feedarr['href'];
                                } else {
                                    $lbl = "Resource {$cnt}";
                                }
                                echo "<p>\n\t<input class=\"indent\" type=\"radio\" id=\"fd_{$cnt}\" name=\"new_channel\" " . " value=\"{$href}\" />\n" . "\t<label for=\"fd_{$cnt}\">{$lbl} {$typeLbl}</label>\n" . "</p>\n";
                            }
                            echo "<p><input type=\"hidden\" name=\"add_channel_to_folder\" value=\"{$fid}\" />\n" . "<input type=\"hidden\" name=\"" . CST_ADMIN_DOMAIN . "\" value=\"" . CST_ADMIN_DOMAIN_CHANNEL . "\" />\n" . "<input type=\"hidden\" name=\"" . CST_ADMIN_METAACTION . "\" value=\"ACT_ADMIN_ADD\" />\n" . "<input type=\"submit\" class=\"indent\" name=\"action\" value=\"" . __('Add') . "\" />\n" . "</p>\n</form>\n\n";
                        }
                    }
                } elseif (is_array($ret)) {
                    rss_error($ret[1], RSS_ERROR_ERROR, true);
                    $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                } else {
                    rss_error(sprintf(__("I'm sorry, I don't think I can handle this URL: '%s'"), $label), RSS_ERROR_ERROR, true);
                    $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                }
            } else {
                rss_error(sprintf(__("I'm sorry, I don't think I can handle this URL: '%s'"), $label), RSS_ERROR_ERROR, true);
                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            }
            break;
        case CST_ADMIN_EDIT_ACTION:
            $id = sanitize($_REQUEST['cid'], RSS_SANITIZER_NUMERIC);
            channel_edit_form($id);
            break;
        case CST_ADMIN_DELETE_ACTION:
            $id = sanitize($_REQUEST['cid'], RSS_SANITIZER_NUMERIC);
            if (array_key_exists(CST_ADMIN_CONFIRMED, $_POST) && $_POST[CST_ADMIN_CONFIRMED] == __('Yes')) {
                $rs = rss_query("select distinct id from " . getTable("item") . " where cid={$id}");
                $ids = array();
                while (list($did) = rss_fetch_row($rs)) {
                    $ids[] = $did;
                }
                if (count($ids)) {
                    $sqldel = "delete from " . getTable('metatag') . " where fid in (" . implode(",", $ids) . ")";
                    rss_query($sqldel);
                }
                $sql = "delete from " . getTable("item") . " where cid={$id}";
                rss_query($sql);
                $sql = "delete from " . getTable("channels") . " where id={$id}";
                rss_query($sql);
                // Delete properties
                deleteProperty($id, 'rss.input.allowupdates');
                deleteProperty($id, 'rss.config.refreshinterval');
                deleteProperty($id, 'rss.config.refreshdate');
                // Invalidate cache
                rss_invalidate_cache();
                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            } elseif (array_key_exists(CST_ADMIN_CONFIRMED, $_REQUEST) && $_REQUEST[CST_ADMIN_CONFIRMED] == __('No')) {
                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            } else {
                list($cname) = rss_fetch_row(rss_query("select title from " . getTable("channels") . " where id = {$id}"));
                echo "<form class=\"box\" method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\">\n" . "<p class=\"error\">";
                printf(__("Are you sure you wish to delete '%s'?"), $cname);
                echo "</p>\n" . "<p><input type=\"submit\" name=\"" . CST_ADMIN_CONFIRMED . "\" value=\"" . __('No') . "\" />\n" . "<input type=\"submit\" name=\"" . CST_ADMIN_CONFIRMED . "\" value=\"" . __('Yes') . "\" />\n" . "<input type=\"hidden\" name=\"cid\" value=\"{$id}\" />\n" . "<input type=\"hidden\" name=\"" . CST_ADMIN_DOMAIN . "\" value=\"" . CST_ADMIN_DOMAIN_CHANNEL . "\" />\n" . "<input type=\"hidden\" name=\"action\" value=\"" . CST_ADMIN_DELETE_ACTION . "\" />\n" . "</p>\n</form>\n";
            }
            break;
        case __('Import'):
        case 'ACT_ADMIN_IMPORT':
            if (array_key_exists('opml', $_POST) && strlen(trim($_POST['opml'])) > 7) {
                $url = trim(sanitize($_POST['opml'], RSS_SANITIZER_NO_SPACES));
            } elseif (array_key_exists('opmlfile', $_FILES) && $_FILES['opmlfile']['tmp_name']) {
                if (is_uploaded_file($_FILES['opmlfile']['tmp_name'])) {
                    $url = $_FILES['opmlfile']['tmp_name'];
                } else {
                    $url = '';
                }
            } else {
                $url = '';
            }
            if (!$url) {
                $ret__ = CST_ADMIN_DOMAIN_OPML;
                break;
            }
            if (array_key_exists('opml_import_option', $_POST)) {
                $import_opt = $_POST['opml_import_option'];
            } else {
                $import_opt = CST_ADMIN_OPML_IMPORT_MERGE;
            }
            if ($import_opt == CST_ADMIN_OPML_IMPORT_FOLDER) {
                $opmlfid = sanitize($_POST['opml_import_to_folder'], RSS_SANITIZER_NUMERIC);
            } else {
                $opmlfid = getRootFolder();
            }
            @set_time_limit(0);
            @ini_set('max_execution_time', 300);
            // Parse into and OPML object
            $opml = getOpml($url);
            if (sizeof($opml) > 0) {
                if ($import_opt == CST_ADMIN_OPML_IMPORT_WIPE) {
                    rss_query("delete from " . getTable("metatag"));
                    rss_query("delete from " . getTable("channels"));
                    rss_query("delete from " . getTable("item"));
                    rss_query("delete from " . getTable("folders") . " where id > 0");
                }
                if ($import_opt == CST_ADMIN_OPML_IMPORT_FOLDER) {
                    $fid = $opmlfid;
                    list($prev_folder) = rss_fetch_row(rss_query("select name from " . getTable('folders') . " where id= {$opmlfid} "));
                } else {
                    $prev_folder = __('Root');
                    $fid = 0;
                }
                echo "<div class=\"frame\" style=\"background-color:#eee;font-size:small\"><ul>\n";
                while (list($folder, $items) = each($opml)) {
                    if ($folder != $prev_folder && $import_opt != CST_ADMIN_OPML_IMPORT_FOLDER) {
                        $fid = create_folder(strip_tags($folder), false);
                        $prev_folder = strip_tags($folder);
                    }
                    for ($i = 0; $i < sizeof($opml[$folder]); $i++) {
                        $url_ = isset($opml[$folder][$i]['XMLURL']) ? trim($opml[$folder][$i]['XMLURL']) : null;
                        $title_ = isset($opml[$folder][$i]['TEXT']) ? trim($opml[$folder][$i]['TEXT']) : null;
                        // support for title attribute (optional)
                        $title_ = isset($opml[$folder][$i]['TITLE']) ? trim($opml[$folder][$i]['TITLE']) : $title_;
                        $descr_ = isset($opml[$folder][$i]['DESCRIPTION']) ? trim($opml[$folder][$i]['DESCRIPTION']) : null;
                        $cats_ = isset($opml[$folder][$i]['CATEGORY']) ? trim($opml[$folder][$i]['CATEGORY']) : "";
                        $t__ = strip_tags($title_);
                        $d__ = strip_tags($descr_);
                        $f__ = strip_tags($prev_folder);
                        $u__ = sanitize($url_, RSS_SANITIZER_URL);
                        $c__ = $cats_;
                        //preg_replace(ALLOWED_TAGS_REGEXP,' ',$cats_);
                        if ($u__) {
                            echo "<li><p>" . sprintf(__('Adding %s to %s... '), $t__, $f__);
                            flush();
                            list($retcde, $retmsg) = add_channel($u__, $fid, $t__, $d__);
                            if ($retcde && count($c__)) {
                                __exp__submitTag($retcde, utf8_encode($c__), "'channel'");
                            }
                            echo ($retcde < 0 ? $retmsg : " OK") . "</p></li>\n";
                            flush();
                        }
                    }
                }
                echo "</ul>\n<p><b>" . __('Updating') . "...</b></p>\n";
                echo "</div>\n";
                flush();
                //update all the feeds
                update("");
                rss_invalidate_cache();
            }
            $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            break;
        case CST_ADMIN_SUBMIT_EDIT:
            $cid = sanitize($_POST['cid'], RSS_SANITIZER_NUMERIC);
            rss_plugin_hook('rss.plugins.admin.feed.properties.submit', null);
            // TBD
            $title = strip_tags(rss_real_escape_string(real_strip_slashes($_POST['c_name'])));
            $url = rss_real_escape_string($_POST['c_url']);
            $siteurl = rss_real_escape_string($_POST['c_siteurl']);
            $parent = rss_real_escape_string($_POST['c_parent']);
            $descr = strip_tags(rss_real_escape_string(real_strip_slashes($_POST['c_descr'])));
            $icon = rss_real_escape_string($_POST['c_icon']);
            $priv = array_key_exists('c_private', $_POST) && $_POST['c_private'] == '1';
            $tags = rss_real_escape_string($_POST['c_tags']);
            $old_priv = $_POST['old_priv'] == '1';
            // Feed Properties
            $prop_rss_input_allowupdates = rss_real_escape_string($_POST['prop_rss_input_allowupdates']);
            if ($prop_rss_input_allowupdates == 'default') {
                deleteProperty($cid, 'rss.input.allowupdates');
            } else {
                setProperty($cid, 'rss.input.allowupdates', 'feed', $prop_rss_input_allowupdates == 1);
            }
            deleteProperty($cid, 'rss.config.refreshinterval');
            $rss_config_refreshinterval = rss_real_escape_string($_POST['rss_config_refreshinterval']);
            if ($rss_config_refreshinterval > 60) {
                setProperty($cid, 'rss.config.refreshinterval', 'feed', $rss_config_refreshinterval);
            }
            if ($priv != $old_priv) {
                $mode = ", mode = mode ";
                if ($priv) {
                    $mode .= " | " . RSS_MODE_PRIVATE_STATE;
                    rss_query('update ' . getTable('item') . " set unread = unread | " . RSS_MODE_PRIVATE_STATE . " where cid={$cid}");
                } else {
                    $mode .= " & " . SET_MODE_PUBLIC_STATE;
                    rss_query('update ' . getTable('item') . " set unread = unread & " . SET_MODE_PUBLIC_STATE . " where cid={$cid}");
                }
                rss_invalidate_cache();
            } else {
                $mode = "";
            }
            $del = array_key_exists('c_deleted', $_POST) && $_POST['c_deleted'] == '1';
            $old_del = $_POST['old_del'] == '1';
            if ($del != $old_del) {
                if ($mode == "") {
                    $mode = ", mode = mode ";
                }
                if ($del) {
                    $mode .= " | " . RSS_MODE_DELETED_STATE;
                } else {
                    $mode .= " & " . SET_MODE_AVAILABLE_STATE;
                }
            }
            if ($url == '' || substr($url, 0, 4) != "http") {
                rss_error(sprintf(__("I'm sorry, I don't think I can handle this URL: '%s'"), $url), RSS_ERROR_ERROR, true);
                $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
                break;
            }
            if ($icon && cacheFavicon($icon)) {
                $icon = 'blob:' . $icon;
            }
            $sql = "update " . getTable("channels") . " set title='{$title}', url='{$url}', siteurl='{$siteurl}', " . " parent={$parent}, descr='{$descr}', icon='{$icon}', " . " daterefreshed = 1, etag = '' " . " {$mode} where id={$cid}";
            rss_query($sql);
            __exp__submitTag($cid, utf8_decode($tags), "'channel'");
            rss_invalidate_cache();
            $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            break;
        case CST_ADMIN_MOVE_UP_ACTION:
        case CST_ADMIN_MOVE_DOWN_ACTION:
            $id = sanitize($_REQUEST['cid'], RSS_SANITIZER_NUMERIC);
            $res = rss_query("select parent,position from " . getTable("channels") . " where id={$id}");
            list($parent, $position) = rss_fetch_row($res);
            if ($_REQUEST['action'] == CST_ADMIN_MOVE_UP_ACTION) {
                $res = rss_query("select id, position from " . getTable("channels") . " where parent={$parent} and id != {$id} and position<{$position} " . " order by abs({$position}-position) limit 1");
            } else {
                $res = rss_query("select id, position from " . getTable("channels") . " where parent={$parent} and id != {$id} and position>{$position} " . " order by abs({$position}-position) limit 1");
            }
            list($switch_with_id, $switch_with_position) = rss_fetch_row($res);
            //If this is already the first or last item in a folder we won't get any results from the query above
            if ($switch_with_position != "") {
                // right, lets!
                if ($switch_with_position != $position) {
                    rss_query("update " . getTable("channels") . " set position = {$switch_with_position} where id={$id}");
                    rss_query("update " . getTable("channels") . " set position = {$position} where id={$switch_with_id}");
                    rss_invalidate_cache();
                }
            }
            $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            break;
        case CST_ADMIN_MULTIEDIT:
            $ret__ = CST_ADMIN_DOMAIN_CHANNEL;
            $ids = array();
            foreach ($_REQUEST as $key => $val) {
                if (preg_match('/^fcb([0-9]+)$/', $key, $match)) {
                    if (($id = (int) $_REQUEST[$key]) > 0) {
                        $ids[] = $id;
                    }
                }
            }
            // no feed selected?
            if (count($ids) == 0) {
                break;
            } else {
                $sqlids = " (" . implode(',', $ids) . ")";
            }
            // MOVE TO FOLDER
            if (array_key_exists('me_move_to_folder', $_REQUEST)) {
                $fid = sanitize($_REQUEST['me_folder'], RSS_SANITIZER_NUMERIC);
                $sql = "update " . getTable('channels') . " set parent={$fid} where id in {$sqlids}";
                rss_query($sql);
                /// STATE
            } elseif (array_key_exists('me_state', $_REQUEST)) {
                $deprecated = array_key_exists('me_deprecated', $_REQUEST) ? $_REQUEST['me_deprecated'] : false;
                $private = array_key_exists('me_private', $_REQUEST) ? $_REQUEST['me_private'] : false;
                if ($private) {
                    rss_query('update ' . getTable('channels') . " set mode = mode | " . RSS_MODE_PRIVATE_STATE . " where id in {$sqlids}");
                    rss_query('update ' . getTable('item') . " set unread = unread | " . RSS_MODE_PRIVATE_STATE . " where cid in {$sqlids}");
                } else {
                    rss_query('update ' . getTable('channels') . " set mode = mode & " . SET_MODE_PUBLIC_STATE . " where id in {$sqlids}");
                    rss_query('update ' . getTable('item') . " set unread = unread & " . SET_MODE_PUBLIC_STATE . " where cid in {$sqlids}");
                }
                if ($deprecated) {
                    rss_query('update ' . getTable('channels') . " set mode = mode | " . RSS_MODE_DELETED_STATE . " where id in {$sqlids}");
                } else {
                    rss_query('update ' . getTable('channels') . " set mode = mode & " . SET_MODE_AVAILABLE_STATE . " where id in {$sqlids}");
                }
                // DELETE
            } elseif (array_key_exists('me_delete', $_REQUEST)) {
                if (array_key_exists('me_do_delete', $_REQUEST) && $_REQUEST['me_do_delete'] == "1") {
                    $sql = "delete from " . getTable('channels') . " where id in {$sqlids}";
                    rss_query($sql);
                }
            } elseif (array_key_exists('me_set_categories', $_POST)) {
                $tags = utf8_decode(trim(rss_real_escape_string($_POST['me_categories'])));
                if ($tags) {
                    foreach ($ids as $id) {
                        __exp__submitTag($id, $tags, '"channel"');
                    }
                }
            }
            rss_invalidate_cache();
            break;
        case 'dump':
            // Make sure this is a POST
            if (!isset($_POST['dumpact'])) {
                die('Sorry, you can\'t access this via a GET');
            }
            $tbl = array('"', '&quot;');
            error_reporting(E_ALL);
            rss_require('schema.php');
            $tables = getExpectedTables();
            unset($tables['cache']);
            //$tables=array('channels','tag','config');
            $bfr = '';
            $bfr .= '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n";
            $bfr .= '<dump prefix="' . getTable('') . '" date="' . date('r') . '">' . "\n";
            foreach ($tables as $table => $prefixed) {
                $rs = rss_query("select * from {$prefixed}");
                $bfr .= "<{$table}>\n";
                while ($row = rss_fetch_assoc($rs)) {
                    $r = "<row ";
                    foreach ($row as $key => $val) {
                        $val = htmlspecialchars($val);
                        $r .= " {$key}=\"{$val}\" ";
                    }
                    $r .= "/>\n";
                    $bfr .= $r;
                }
                $bfr .= "</{$table}>\n";
            }
            $bfr .= '</dump>' . "\n";
            $gzdata = gzencode($bfr, 9);
            // Delete the output buffer. This is probably a bad thing to do, if the ob'ing is turned off.
            // e.g. data was already sent to the brwoser.
            while (@ob_end_clean()) {
            }
            // Send the dump to the browser:
            header("Pragma: public");
            // required
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Connection: close");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: " . strlen($gzdata));
            header('Content-type: application/x-gzip');
            header('Content-disposition: inline; filename="gregarius.dump.' . date('MjSY') . '.xml.gz"');
            die($gzdata);
            break;
        default:
            break;
    }
    return $ret__;
}
Example #2
0
function __exp_addChannel($url, $folderid = 0, $title_ = null, $descr_ = null, $tags = null)
{
    rss_require('extlib/JSON.php');
    $json = new SERVICES_JSON();
    if (!isset($GLOBALS['rssuser'])) {
        require_once 'cls/user.php';
    }
    if (rss_user_check_user_level(RSS_USER_LEVEL_PRIVATE)) {
        $ret = add_channel($url, $folderid, $title_, $descr_, $tags);
    } else {
        $ret = array(-1, "Sorry, you are not privileged enough to add feeds");
    }
    return $json->encode($ret);
}
Example #3
0
function engine_doit(){
	global $CONF;
	$whats = explode(',', $_GET['what']);
	$result = null;

	if (isset($_GET['SYSTEM_redirect'])){
		unset($_GET['SYSTEM_redirect']);
		switch($_GET['what']){
			case 'topic':
				include('basichtml/viewtopic.php');
				break;
			case 'datetopics':
				include('basichtml/topic_list.php');
				break;
			case 'confirm_user':
				include('controller/confirm_user.php');
				break;
			case 'user_stopmail':
				include('controller/user_stopmail.php');
				break;
			case 'add_email':
				include('controller/add_email.php');
				break;
			case 'remove_email':
				include('controller/remove_email.php');
				break;
			case 'restore_password':
				include('controller/restore_password.php');
				break;
			case 'followchannel_acceptreject':
				include('controller/followchannel_acceptreject.php');
				break;
			case 'autoopenchannel':
				include('controller/autoopenchannel.php');
				break;
			case 'autoopentopic':
				include('controller/autoopentopic.php');
				break;
/*			case 'ETUEngine':
				include('tool/ETUEngine.php');
				$etu=new ETUEngine();
				$etu->start(1);
				break;
*/

		}
		return;
	} 
	foreach ($whats as $what)
	{
		switch($what)
		{
			case 'fromname':
				require_once("controller/fromname.php");
				$result['fromname'] = fromname($_GET['id_fromname']);
				break;
			case 'setuserfrom':
				require_once("class/User.php");
				$tuser = new RegUser();
				$tuser->setNickname($_GET['nick_setuserfrom']);
				$valid = $tuser->validatePassword($_GET['pass_setuserfrom']);
				if ($valid)
				{
					$tuser->load();
					$tuser->setCameFrom($_GET['fromid_setuserfrom']);
					$tuser->save();
				}
				break;
			case 'message':
				require_once('template/TMessage.php');
				require_once('class/Message.php');
				$message = new Message(); 
				if (isset($_GET['id_message']) && !empty($_GET['id_message']))
					$message->setId($_GET['id_message']);
				else { $result['message']=array(); break; }
				$tmessage = new TMessage(); $tmessage->setMessage($message);
				$result['message']=$tmessage->getJsonTags();
				break;
			case 'mymessages':
				require_once('template/TListMessage.php');
				$tlist = new TListMessage();	$tlist->setListType("cloneMy"); $tlist->setOnlySubsumed(true);
				if (isset($_GET['sorting_mymessages'])) $tlist->setSorting($_GET['sorting_mymessages']);
				if (isset($_GET['lastid_mymessages'])) $tlist->setLastId($_GET['lastid_mymessages']);
				$result['mymessages']=$tlist->getJsonTags();
				break;
			case 'regchannel':
				require_once("template/TChannel.php");
				require_once("class/Channel.php");
				$t = new TChannel();
				$o=new Channel();
				$prettyUrl='';
				if (isset($_GET['id_regchannel'])) {
					$o->setId($_GET['id_regchannel']);
				} elseif (isset($_GET['name_regchannel'])) {
					if (substr($_GET['name_regchannel'],-1,1)=='-'){
						$result['regchannel']=array("ok"=>false,"error"=>"invalid name","exist"=>true,'prettyUrl'=>'');
						break;
					} else {
						$o->setName($_GET['name_regchannel']);
						$prettyUrl=Channel::prettyUrlAvailable($_GET['name_regchannel']);
					}
				} elseif (isset($_GET['urlname_regchannel'])) {
					if ($_GET['urlname_regchannel'] != Channel::prettyUrl($_GET['urlname_regchannel'])){
						$result['regchannel']=array("ok"=>false,"error"=>"invalid url","exist"=>true, 'prettyUrl'=>'');
						break;
					}
					$o->setUrlname($_GET['urlname_regchannel']);
					$prettyUrl=$_GET['urlname_regchannel'];
				} else {
					$result['regchannel']=array("ok"=>false,"error"=>"no param", "exist"=>true, 'prettyUrl'=>'');
					break;
				}
				$t->setChannel($o);
				$r=$t->getJsonTags();
				if ($r['id']==null || $r['name']==null || $r['lang']==null)
					$result['regchannel']=array("ok"=>true,"error"=>"","exist"=>false,'prettyUrl'=>$prettyUrl);
				else
					$result['regchannel']=array("ok"=>true,"error"=>"","exist"=>true,'prettyUrl'=>$r['urlname']);
				break;
			case 'channels':
				require_once('template/TListChannel.php');
				$tlist = new TListChannel();	$tlist->setListType("cloneAll"); $tlist->setOnlySubsumed(true);
				if (isset($_GET['sorting_channels'])) $tlist->setSorting($_GET['sorting_channels']);
				$result['channels']=$tlist->getJsonTags();
				break;
			case 'followedchannels':
				require_once('template/TListChannel.php');
				$tlist = new TListChannel();
				if ($_SESSION['user']->isAnon())
					$tlist->setListType("cloneAll");
				else
					$tlist->setListType("cloneFollowed"); 
				$tlist->setOnlySubsumed(true);
				if (isset($_GET['sorting_followedchannels'])) $tlist->setSorting($_GET['sorting_followedchannels']);
				$result['followedchannels']=$tlist->getJsonTags();
				break;
			case 'mychannels':
				require_once('template/TListChannel.php');
				$tlist = new TListChannel();	$tlist->setListType("cloneMy"); $tlist->setOnlySubsumed(false);
				if (isset($_GET['sorting_mychannels'])) $tlist->setSorting($_GET['sorting_mychannels']);
				$result['mychannels']=$tlist->getJsonTags();
				break;
			case 'mostvisitedchannels':
				require_once('template/TListChannel.php');
				$tlist = new TListChannel();	$tlist->setListType("cloneMostVisited"); $tlist->setOnlySubsumed(false);
				if (isset($_GET['qtd_mostvisitedchannels'])) $tlist->setQtd($_GET['qtd_mostvisitedchannels']);
				if (isset($_GET['signed_mostvisitedchannels'])) $tlist->setSigned($_GET['signed_mostvisitedchannels']);
				$result['mostvisitedchannels']=$tlist->getJsonTags();
				break;
			case 'recommendedchannels':
				require_once('template/TListChannel.php');
				$tlist = new TListChannel();	$tlist->setListType("cloneRecommended"); $tlist->setOnlySubsumed(false);
				if (isset($_GET['qtd_recommendedchannels'])) $tlist->setQtd($_GET['qtd_recommendedchannels']);
				$result['recommendedchannels']=$tlist->getJsonTags();
				break;
			case 'channel':
				require_once('template/TChannel.php');
				require_once('class/Channel.php');
				$channel = new Channel(); 
				if (isset($_GET['id_channel']) && !empty($_GET['id_channel']))
					$channel->setId($_GET['id_channel']);
				elseif (isset($_GET['name_channel']) && !empty($_GET['name_channel'])) 
					$channel->setName($_GET['name_channel']);
				else { $result['channel']=array(); break; }
				$tchannel = new TChannel(); $tchannel->setChannel($channel);
				$result['channel']=(array('channel'=>$tchannel->getJsonTags(), "topics"=>array() ));
				break;
			case 'followedchanneltopics':
				require_once('template/TListTopic.php');
				$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneChannelFollowed"); $tlisttopic->setOnlySubsumed(true);
				if (isset($_GET['orderid_followedchanneltopics'])) $tlisttopic->setOrderId($_GET['orderid_followedchanneltopics']);
				if (isset($_GET['lastorderid_followedchanneltopics'])) $tlisttopic->setLastOrderId($_GET['lastorderid_followedchanneltopics']);
				if (isset($_GET['sorting_followedchanneltopics'])) $tlisttopic->setSorting($_GET['sorting_followedchanneltopics']);
				if (isset($_GET['qtd_followedchanneltopics'])) $tlisttopic->setQtd($_GET['qtd_followedchanneltopics']);
				$result['followedchanneltopics']=$tlisttopic->getJsonTags();
				break;
			case 'recenttopics':
				require_once('getter/recenttopics.php');
				$result['recenttopics']=recenttopics();
				break;
			case 'datetopics':
				require_once('template/TListTopic.php');
				if (!isset($_GET['year_datetopics'])) {
					$result['datetopics']=array();
					break;
				}
				$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneByDate"); $tlisttopic->setOnlySubsumed(true);
				$tlisttopic->setYear($_GET['year_datetopics']);
				if (isset($_GET['month_datetopics'])) $tlisttopic->setMonth($_GET['month_datetopics']);
				if (isset($_GET['day_datetopics'])) $tlisttopic->setDay($_GET['day_datetopics']);
				$result['datetopics']=$tlisttopic->getJsonTags();
				break;
			case 'searchtopics':
				require_once('template/TListTopic.php');
				require_once('tool/SearchTopic.php');
				if (isset($_GET['words_searchtopics'])){
					$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneSearch"); $tlisttopic->setOnlySubsumed(true);
					$tlisttopic->setSearch(SearchTopic::getQuery($_GET['words_searchtopics']));
					if (isset($_GET['orderid_searchtopics'])) $tlisttopic->setOrderId($_GET['orderid_searchtopics']);
					$result['searchtopics']=$tlisttopic->getJsonTags();
				} else $result['searchtopics']=array("ok"=>false,"error"=>"no words");
				break;
			case 'searchmain':
				require_once('template/TListChannel.php');
				require_once('tool/SearchEngine.php');
				if (isset($_GET['words_searchmain'])){
					$tlisttopic = new TListChannel(); $tlisttopic->setListType("cloneSearch"); $tlisttopic->setOnlySubsumed(true);
					$tlisttopic->setSearch(SearchEngine::getQueryChannels(unescape_ampersand($_GET['words_searchmain'])));
					//if (isset($_GET['orderid_searchtopics'])) $tlisttopic->setOrderId($_GET['orderid_searchtopics']);
					$result['searchmain']['channels']=$tlisttopic->getJsonTags();
				} else $result['searchmain']=array("ok"=>false,"error"=>"no words");
				break;
			case 'usertopics':
				require_once('template/TListTopic.php');
				require_once('class/User.php');
				if (isset($_GET['nickname_usertopics'])){
					$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneByUser"); $tlisttopic->setOnlySubsumed(true);
					if (isset($_GET['sorting_usertopics'])) $tlisttopic->setSorting($_GET['sorting_usertopics']);
					$u=new RegUser();
					$u->setNickname($_GET['nickname_usertopics']); $u->load();
					$tlisttopic->setUser($u);
					if (isset($_GET['orderid_usertopics'])) $tlisttopic->setOrderId($_GET['orderid_usertopics']);
					if (isset($_GET['idchannel_usertopics'])) $tlisttopic->setIdChannel($_GET['idchannel_usertopics']);
					$result['usertopics']=$tlisttopic->getJsonTags();
				} else $result['usertopics']=array();
				break;
			case 'userposttopics':
				require_once('template/TListTopic.php');
				require_once('class/User.php');
				if (isset($_GET['nickname_userposttopics'])){
					$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneByUserPost"); $tlisttopic->setOnlySubsumed(true);
					if (isset($_GET['sorting_userposttopics'])) $tlisttopic->setSorting($_GET['sorting_userposttopics']);
					$u=new RegUser();
					$u->setNickname($_GET['nickname_userposttopics']); $u->load();
					$tlisttopic->setUser($u);
					if (isset($_GET['orderid_userposttopics'])) $tlisttopic->setOrderId($_GET['orderid_userposttopics']);
					if (isset($_GET['idchannel_userposttopics'])) $tlisttopic->setIdChannel($_GET['idchannel_userposttopics']);
					$result['userposttopics']=$tlisttopic->getJsonTags();
				} else $result['userposttopics']=array();
				break;
			case 'uft':
				require_once('getter/uft.php');
				$result['uft']=uft();
				break;
			case 'followedtopics':
				require_once('conf/session.php');
				require_once('template/TListTopic.php');
				$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneFollowed"); $tlisttopic->setOnlySubsumed(true);
				if (isset($_GET['orderid_followedtopics'])) $tlisttopic->setOrderId($_GET['orderid_followedtopics']);
				if (isset($_GET['idchannel_followedtopics'])) $tlisttopic->setIdChannel($_GET['idchannel_followedtopics']);
				$result['followedtopics']=$tlisttopic->getJsonTags() ;
				break;
		
			case 'topic':
				if (!isset($_GET['id_topic']) || empty($_GET['id_topic'])) { $result['topic']=array(); break; }
				require_once('template/TTopic.php');
				require_once('template/TListPost.php');
				require_once('class/Topic.php');
				require_once('class/Channel.php');
				$topic = new Topic(); $topic->setId($_GET['id_topic']);
				if (!$topic->getChannel()->canIRead()){ $result['topic']=array("error"=>'you cant see this topic'); break; }
				$ttopic = new TTopic(); $ttopic->setTopic($topic);
				$tlistpost = new TListPost(); $tlistpost->setTopic($topic);
				$tlistpostbest = new TListPost(); $tlistpostbest->setTopic($topic); $tlistpostbest->setQtd($CONF['post_best_qt']); $tlistpostbest->setSorting("likes desc,date desc");
				$result['topic']=(array('topic'=>$ttopic->getJsonTags(), "posts"=>$tlistpost->getJsonTags(), "bestposts"=>$tlistpostbest->getJsonTags()) );
				break;

			case 'refresh_topic_previews':
				if (!isset($_GET['ids_refresh_topic_previews']) || empty($_GET['ids_refresh_topic_previews'])) { $result['refresh_topic_previews']=array(); break;}
				if (!isset($_GET['versions_refresh_topic_previews']) || empty($_GET['versions_refresh_topic_previews'])) { $result['refresh_topic_previews']=array(); break;}
				require_once("template/TListTopic.php");
				$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneUpdated"); $tlisttopic->setOnlySubsumed(true);
				$tlisttopic->setIds(explode(",",$_GET['ids_refresh_topic_previews']));
				$tlisttopic->setCounters(explode(",",$_GET['versions_refresh_topic_previews']));
				$result['refresh_topic_previews']=$tlisttopic->getJsonTags();
				break;
			case 'refresh_topics':
				if (!isset($_GET['ids_refresh_topics']) || empty($_GET['ids_refresh_topics'])) { $result['refresh_topics']=array(); break;}
				if (!isset($_GET['versions_refresh_topics']) || empty($_GET['versions_refresh_topics'])){ $result['refresh_topics']=array(); break;}
				require_once("template/TListTopic.php");
				$tlisttopic = new TListTopic();	$tlisttopic->setListType("cloneUpdated"); $tlisttopic->setWithPosts(true);
				if (isset($_GET['idchannel_refresh_topics'])) $tlisttopic->setIdChannel($_GET['idchannel_refresh_topics']);
				$tlisttopic->setIds(explode(",",$_GET['ids_refresh_topics']));
				$tlisttopic->setCounters(explode(",",$_GET['versions_refresh_topics']));
				$result['refresh_topics']=$tlisttopic->getJsonTags();
				break;
			case 'new_topic_previews':
				require_once("getter/new_topic_previews.php");
				$result['new_topic_previews']=new_topic_previews();
				break;
			case 'reguser':
				require_once("template/TUser.php");
				require_once("class/User.php");
				$tuser = new TUser();
				$u=new RegUser();
				if (isset($_GET['id_reguser'])) $u->setId($_GET['id_reguser']);
				elseif (isset($_GET['email_reguser'])) $u->setEmail($_GET['email_reguser']);
				elseif (isset($_GET['nickname_reguser'])) {
					if (substr($_GET['nickname_reguser'],-1,1)=='-'){
						$result['reguser']=array("ok"=>true,"error"=>"","exist"=>true);
						break;
					} else {
						$u->setNickname($_GET['nickname_reguser']);
					}
				} else {
					$result['reguser']=array("ok"=>false,"error"=>"no param");
					break;
				}
				$tuser->setUser($u);
				$r=$tuser->getJsonTags();
				if ($r['id']==null || $r['nickname']==null || $r['lang']==null)
					$result['reguser']=array("ok"=>true,"error"=>"","exist"=>false);
				else
					$result['reguser']=array("ok"=>true,"error"=>"","exist"=>true);
				break;
			case 'userscamefrom':
				require_once('template/TListUser.php');
				$tlist = new TListUser(); $tlist->setListType("cloneLastCameFrom");
				if (isset($_GET['camefrom_userscamefrom']))
					$tlist->setCameFrom($_GET['camefrom_userscamefrom']);
				if (isset($_GET['qtd_userscamefrom']))
					$tlist->setQtd($_GET['qtd_userscamefrom']);
				$result['userscamefrom']=$tlist->getJsonTags();
				break;
			case 'user':
				require_once("template/TUser.php");
				require_once("class/User.php");
				global $user;
				$tuser = new TUser(); 
				if (!isset($_GET['id_user']) || !isset($_GET['anon_user'])){
					$tuser->setUser($user);
					$tuser->setWithEmail(true);
				} else{
					if ($_GET['anon_user']){
						$u = new AnonUser(); $u->setId($_GET['id_user']);
					} else {
						$u = new RegUser(); $u->setId($_GET['id_user']); 
					}
					$tuser->setUser($u);
				}
				$result['user']=$tuser->getJsonTags();	
				break;
			case 'add_topic':
				require_once('controller/add_topic.php');
				$result['add_topic']=add_topic();
				break;
			case 'add_message':
				require_once('controller/add_message.php');
				$result['add_message']=add_message();
				break;
			case 'read_message':
				require_once('controller/read_message.php');
				$result['read_message']=read_message();
				break;
			case 'add_channel':
				require_once('controller/add_channel.php');
				$result['add_channel']=add_channel();
				break;
			case 'add_post':
				require_once('controller/add_post.php');
				$result['add_post']=add_post();
				break;
			case 'update_channel':
				require_once('controller/update_channel.php');
				$result['update_channel']=update_channel();
				break;
			case 'update_topic':
				require_once('controller/update_topic.php');
				$result['update_topic']=update_topic();
				break;
			case 'update_post':
				require_once('controller/update_post.php');
				$result['update_post']=update_post();
				break;
			case 'followtopic':
				require_once('controller/followtopic.php');
				$result['followtopic']=followtopic();
				break;
			case 'unfollowtopic':
				require_once('controller/unfollowtopic.php');
				$result['unfollowtopic']=unfollowtopic();
				break;
			case 'followchannel':
				require_once('controller/followchannel.php');
				$result['followchannel']=followchannel($_GET['channelid_followchannel']);
				break;
			case 'followchannels':
				require_once('controller/followchannel.php');
				$chids=explode(",",$_GET['channelids_followchannels']);
				for ($i=0;$i<count($chids);$i++)
					$result['followchannels'][$i]=followchannel($chids[$i]);
				break;
			case 'unfollowchannel':
				require_once('controller/unfollowchannel.php');
				$result['unfollowchannel']=unfollowchannel();
				break;
			case 'create_account':
				require_once('controller/create_account.php');
				$result['create_account']=create_account();
				break;
			case 'update_user_avatar':
				require_once('controller/update_user_avatar.php');
				$result['update_user_avatar'] = update_user_avatar($_GET['file'],$_GET['x1'],$_GET['y1'],$_GET['x2'],$_GET['y2']);
				break;
			case 'upload_temp_avatar':
				require_once('controller/upload_temp_avatar.php');
				$result['upload_temp_avatar'] = upload_temp_avatar();
				break;
			case 'update_channel_logo':
				require_once('controller/update_channel_logo.php');
				$result['update_channel_logo'] = update_channel_logo($_GET['file'],$_GET['x1'],$_GET['y1'],$_GET['x2'],$_GET['y2']);
				break;
			case 'upload_temp_logo':
				require_once('controller/upload_temp_logo.php');
				$result['upload_temp_logo'] = upload_temp_logo();
				break;
			case 'update_user':
				require_once('controller/update_user.php');
				$result['update_user'] = update_user();
				break;
			case 'change_user_lang':
				require_once('controller/change_user_lang.php');
				$result['change_user_lang']=change_user_lang();
				break;
			case 'like_dislike_this':
				require_once("controller/like_dislike_this.php");
				$result['like_dislike_this'] = like_dislike_this();
				break;
			case 'signin':
				$result['signin'] = signin($_POST['nickname_signin'], $_POST['password_signin'], false, $_POST['staysignedin_signin']);
				break;
			case 'signout':
				require_once("controller/signout.php");
				$result['signout'] = signout();
				break;
			case 'request_restore_password':
				require_once('controller/request_restore_password.php');
				$result['request_restore_password']=request_restore_password();
				break;
			case 'visittopic':
				require_once('class/Topic.php');
				if (!isset($_GET['topicid_visittopic'])) 
					$result['visittopic']=array("ok"=>false,"error"=>"error no id");
				else {
					$topic = new Topic();
					$topic->setId($_GET['topicid_visittopic']);
					if ($topic->visit())
						$result['visittopic']=array("ok"=>true,"error"=>"");
					else
						$result['visittopic']=array("ok"=>false,"error"=>"error db");
				}
				break;
			case 'deletetopic':
				require_once('controller/deletetopic.php');
				$result['deletetopic']=deletetopic();
				break;
			case 'lang':
				require_once('conf/location.php');
				global $LANG;
				$result['lang']=$LANG['JSON'];
				break;
			default:
				break;
		}
	}
	
	return $result;
}