예제 #1
0
function migrator_init(&$a)
{
    $x = argc();
    if ($x > 1) {
        api_login($a);
        switch (argv(1)) {
            case "version":
                json_return_and_die(array("status" => "OK", 'platform' => PLATFORM_NAME, 'platform_version' => RED_VERSION, 'zot_version' => ZOT_REVISION, 'db_version' => DB_UPDATE_VERSION, 'migrator_version' => MIGRATOR_VERSION));
                break;
            case "import":
                if (PLATFORM_NAME == "redmatrix") {
                    json_error_die(400, 'Bad Request', 'Cannot import to Redmatrix, only to Hubzilla.');
                }
                switch (argv(2)) {
                    case 'account':
                        migrator_import_account($a);
                        break;
                    case 'identity':
                        migrator_import_identity($a, argv(3));
                        break;
                    case 'items':
                        migrator_import_items($a, argv(3));
                        break;
                    case 'directory':
                        migrator_update_directory($a, argv(3));
                        break;
                    default:
                        json_error_die(404, 'Not Found', 'No such endpoint');
                        break;
                }
            case "export":
                switch (argv(2)) {
                    case "users":
                        export_users($a);
                        break;
                    case "channel_hashes":
                        export_channel_hashes($a, argv(3));
                        break;
                    case "identity":
                        export_identity($a, argv(3));
                        break;
                    case "first_post":
                        first_post($a, argv(3));
                        break;
                    case "items":
                        export_items($a, argv(3), argv(4), argv(5));
                        break;
                    default:
                        json_error_die(404, 'Not Found', 'No such endpoint');
                        break;
                }
                break;
            default:
                json_error_die(404, 'Not Found', 'No such endpoint');
                break;
        }
    }
}
예제 #2
0
파일: api.php 프로젝트: msooon/hubzilla
/**
 * Returns user info array.
 */
function api_get_user(&$a, $contact_id = null, $contact_xchan = null)
{
    global $called_api;
    $user = null;
    $extra_query = "";
    if (!is_null($contact_xchan)) {
        $user = local_channel();
        $extra_query = " and abook_xchan = '" . dbesc($contact_xchan) . "' ";
    } else {
        if (!is_null($contact_id)) {
            $user = $contact_id;
            $extra_query = " AND abook_id = %d ";
        }
        if (is_null($user) && x($_GET, 'user_id')) {
            $user = intval($_GET['user_id']);
            $extra_query = " AND abook_id = %d ";
        }
        if (is_null($user) && x($_GET, 'screen_name')) {
            $user = dbesc($_GET['screen_name']);
            $extra_query = " AND xchan_addr like '%s@%%' ";
            if (api_user() !== false) {
                $extra_query .= " AND abook_channel = " . intval(api_user());
            }
        }
        if (is_null($user) && argc() > count($called_api) - 1 && strstr($a->cmd, '/users')) {
            $argid = count($called_api);
            list($xx, $null) = explode(".", argv($argid));
            if (is_numeric($xx)) {
                $user = intval($xx);
                $extra_query = " AND abook_id = %d ";
            } else {
                $user = dbesc($xx);
                $extra_query = " AND xchan_addr like '%s@%%' ";
                if (api_user() !== false) {
                    $extra_query .= " AND abook_channel = " . intval(api_user());
                }
            }
        }
    }
    if (!$user) {
        if (api_user() === false) {
            api_login($a);
            return False;
        } else {
            $user = local_channel();
            $extra_query = " AND abook_channel = %d AND abook_self = 1 ";
        }
    }
    logger('api_user: '******', user: '******'abook_self'])) {
        $usr = q("select * from channel where channel_id = %d limit 1", intval(api_user()));
        $profile = q("select * from profile where uid = %d and `is_default` = 1 limit 1", intval(api_user()));
        $item_normal = item_normal();
        // count public wall messages
        $r = q("SELECT COUNT(`id`) as `count` FROM `item`\n\t\t\t\t\tWHERE `uid` = %d\n\t\t\t\t\tAND item_wall = 1 {$item_normal} \n\t\t\t\t\tAND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", intval($usr[0]['channel_id']));
        $countitms = $r[0]['count'];
    } else {
        $r = q("SELECT COUNT(`id`) as `count` FROM `item`\n\t\t\t\t\tWHERE author_xchan = '%s'\n\t\t\t\t\tAND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", intval($uinfo[0]['xchan_hash']));
        $countitms = $r[0]['count'];
    }
    // count friends
    if ($usr) {
        $r = q("SELECT COUNT(abook_id) as `count` FROM abook\n\t\t\t\t\tWHERE abook_channel = %d AND abook_self = 0 ", intval($usr[0]['channel_id']));
        $countfriends = $r[0]['count'];
        $countfollowers = $r[0]['count'];
    }
    $r = q("SELECT count(`id`) as `count` FROM item where item_starred = 1 and uid = %d " . item_normal(), intval($uinfo[0]['channel_id']));
    $starred = $r[0]['count'];
    if (!intval($uinfo[0]['abook_self'])) {
        $countfriends = 0;
        $countfollowers = 0;
        $starred = 0;
    }
    $ret = array('id' => intval($uinfo[0]['abook_id']), 'self' => intval($uinfo[0]['abook_self']) ? 1 : 0, 'uid' => intval($uinfo[0]['abook_channel']), 'guid' => $uinfo[0]['xchan_hash'], 'name' => $uinfo[0]['xchan_name'] ? $uinfo[0]['xchan_name'] : substr($uinfo[0]['xchan_addr'], 0, strpos($uinfo[0]['xchan_addr'], '@')), 'screen_name' => substr($uinfo[0]['xchan_addr'], 0, strpos($uinfo[0]['xchan_addr'], '@')), 'location' => $usr ? $usr[0]['channel_location'] : '', 'profile_image_url' => $uinfo[0]['xchan_photo_l'], 'url' => $uinfo[0]['xchan_url'], 'contact_url' => $a->get_baseurl() . "/connections/" . $uinfo[0]['abook_id'], 'protected' => false, 'friends_count' => intval($countfriends), 'created_at' => api_date($uinfo[0]['abook_created']), 'utc_offset' => "+00:00", 'time_zone' => 'UTC', 'geo_enabled' => false, 'statuses_count' => intval($countitms), 'lang' => get_app()->language, 'description' => $profile ? $profile[0]['pdesc'] : '', 'followers_count' => intval($countfollowers), 'favourites_count' => intval($starred), 'contributors_enabled' => false, 'follow_request_sent' => true, 'profile_background_color' => 'cfe8f6', 'profile_text_color' => '000000', 'profile_link_color' => 'FF8500', 'profile_sidebar_fill_color' => 'AD0066', 'profile_sidebar_border_color' => 'AD0066', 'profile_background_image_url' => '', 'profile_background_tile' => false, 'profile_use_background_image' => false, 'notifications' => false, 'following' => '', 'verified' => true);
    $x = api_get_status($uinfo[0]['xchan_hash']);
    if ($x) {
        $ret['status'] = $x;
    }
    //		logger('api_get_user: ' . print_r($ret,true));
    return $ret;
}
예제 #3
0
파일: api.php 프로젝트: Avantians/Textcube
function mt_getRecentPostTitles()
{
    $params = func_get_args();
    $result = api_login($params[1], $params[2]);
    if ($result) {
        return $result;
    }
    $post = new Post();
    $post->open();
    $out = array();
    for ($i = 0; $post->_count > 0 && $i < $params[3]; $i++) {
        array_push($out, api_get_post($post, "mt"));
        if (!$post->shift()) {
            break;
        }
    }
    $post->close();
    return $out;
}
예제 #4
0
 public function api($api_function = false, $params = false)
 {
     if (isset($_REQUEST['api_key']) and user_id() == 0) {
         api_login($_REQUEST['api_key']);
     }
     if (!defined('MW_API_CALL')) {
         define('MW_API_CALL', true);
     }
     $set_constants = true;
     $mod_class_api = false;
     $mod_class_api_called = false;
     $mod_class_api_class_exist = false;
     $caller_commander = false;
     if ($api_function == false) {
         $api_function_full = $this->app->url_manager->string();
         $api_function_full = $this->app->format->replace_once('api_html', '', $api_function_full);
         $api_function_full = $this->app->format->replace_once('api/api', 'api', $api_function_full);
         $api_function_full = $this->app->format->replace_once('api', '', $api_function_full);
         $api_function_full = trim($api_function_full, '/');
         //$api_function_full = substr($api_function_full, 4);
     } else {
         $api_function_full = $api_function;
     }
     if (isset($api_function_full) and $api_function_full != '') {
         if (ltrim($api_function_full, '/') == 'module') {
             $set_constants = false;
         }
     }
     if ($set_constants == true) {
         $this->app->content_manager->define_constants();
     }
     if (defined('TEMPLATE_DIR')) {
         $load_template_functions = TEMPLATE_DIR . 'functions.php';
         if (is_file($load_template_functions)) {
             include_once $load_template_functions;
         }
     }
     //$api_function_full = str_ireplace('api/', '', $api_function_full);
     $api_function_full = str_replace('..', '', $api_function_full);
     $api_function_full = str_replace('\\', '/', $api_function_full);
     $api_function_full = str_replace('//', '/', $api_function_full);
     $api_function_full = $this->app->database_manager->escape_string($api_function_full);
     if (is_string($api_function_full)) {
         $mod_api_class = explode('/', $api_function_full);
     } else {
         $mod_api_class = $api_function_full;
     }
     $try_class_func = array_pop($mod_api_class);
     // $try_class_func2 = array_pop($mod_api_class);
     $mod_api_class_copy = $mod_api_class;
     $try_class_func2 = array_pop($mod_api_class_copy);
     $mod_api_class2 = implode(DS, $mod_api_class_copy);
     $mod_api_class = implode(DS, $mod_api_class);
     $mod_api_class_clean = ltrim($mod_api_class, '/');
     $mod_api_class_clean = ltrim($mod_api_class_clean, '\\');
     $mod_api_class_clean_uc1 = ucfirst($mod_api_class_clean);
     $mod_api_class1 = normalize_path(modules_path() . $mod_api_class, false) . '.php';
     $mod_api_class_native = normalize_path(mw_includes_path() . $mod_api_class, false) . '.php';
     $mod_api_class_native_system = normalize_path(dirname(MW_PATH) . DS . $mod_api_class, false) . '.php';
     $mod_api_class_native_global_ns = normalize_path(mw_includes_path() . 'classes' . DS . $mod_api_class2, false) . '.php';
     $mod_api_class1_uc1 = normalize_path(modules_path() . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class_native_uc1 = normalize_path(mw_includes_path() . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class_native_global_ns_uc1 = normalize_path(mw_includes_path() . 'classes' . DS . $mod_api_class_clean_uc1, false) . '.php';
     $mod_api_class2 = normalize_path(modules_path() . DS . $mod_api_class_clean . DS . $mod_api_class_clean, false) . '.php';
     $mod_api_class2_uc1 = normalize_path(modules_path() . DS . $mod_api_class_clean . DS . $mod_api_class_clean, false) . '.php';
     $try_class = '\\' . str_replace('/', '\\', $mod_api_class);
     if (class_exists($try_class, false)) {
         $caller_commander = 'class_is_already_here';
         $mod_class_api_class_exist = true;
     } else {
         if (is_file($mod_api_class1)) {
             $mod_class_api = true;
             include_once $mod_api_class1;
         } elseif (is_file($mod_api_class_native_system)) {
             $mod_class_api = true;
             include_once $mod_api_class_native_system;
         } elseif (is_file($mod_api_class1_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class1_uc1;
         } elseif (is_file($mod_api_class_native_global_ns_uc1)) {
             $try_class = str_replace('/', '\\', $mod_api_class2);
             $mod_class_api = true;
             include_once $mod_api_class_native_global_ns_uc1;
         } elseif (is_file($mod_api_class_native_global_ns)) {
             $try_class = str_replace('/', '\\', $mod_api_class2);
             $mod_class_api = true;
             include_once $mod_api_class_native_global_ns;
         } elseif (is_file($mod_api_class_native_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class_native_uc1;
         } elseif (is_file($mod_api_class_native)) {
             $mod_class_api = true;
             include_once $mod_api_class_native;
         } elseif (is_file($mod_api_class2)) {
             $mod_class_api = true;
             include_once $mod_api_class2;
         } elseif (is_file($mod_api_class2_uc1)) {
             $mod_class_api = true;
             include_once $mod_api_class2_uc1;
         }
     }
     $api_exposed = '';
     // user functions
     $api_exposed .= 'user_login user_logout social_login_process';
     // content functions
     $api_exposed .= 'set_language ';
     $api_exposed .= api_expose(true);
     if (is_logged()) {
         $api_exposed .= api_expose_user(true);
     }
     if (is_admin()) {
         $api_exposed .= api_expose_admin(true);
     }
     $api_exposed = explode(' ', $api_exposed);
     $api_exposed = array_unique($api_exposed);
     $api_exposed = array_trim($api_exposed);
     $hooks = api_bind(true);
     if (is_logged()) {
         $hooks_admin = api_bind_user(true);
         if (is_array($hooks_admin)) {
             $hooks = array_merge($hooks, $hooks_admin);
         }
     }
     if (is_admin()) {
         $hooks_admin = api_bind_admin(true);
         if (is_array($hooks_admin)) {
             $hooks = array_merge($hooks, $hooks_admin);
         }
     }
     if ($api_function == false) {
         $api_function = $this->app->url_manager->segment(1);
     }
     if (!defined('MW_API_RAW')) {
         if ($mod_class_api != false) {
             $url_segs = $this->app->url_manager->segment(-1);
         }
     } else {
         if (is_array($api_function)) {
             $url_segs = $api_function;
         } else {
             $url_segs = explode('/', $api_function);
         }
     }
     if (!defined('MW_API_FUNCTION_CALL')) {
         define('MW_API_FUNCTION_CALL', $api_function);
     }
     switch ($caller_commander) {
         case 'class_is_already_here':
             if ($params != false) {
                 $data = $params;
             } elseif (!$_POST and !$_REQUEST) {
                 $data = $this->app->url_manager->params(true);
                 if (empty($data)) {
                     $data = $this->app->url_manager->segment(2);
                 }
             } else {
                 //$data = $_REQUEST;
                 $data = array_merge($_GET, $_POST);
             }
             static $loaded_classes = array();
             //$try_class_n = src_
             if (isset($loaded_classes[$try_class]) == false) {
                 $res = new $try_class($data);
                 $loaded_classes[$try_class] = $res;
             } else {
                 $res = $loaded_classes[$try_class];
                 //
             }
             if (method_exists($res, $try_class_func) or method_exists($res, $try_class_func2)) {
                 if (method_exists($res, $try_class_func2)) {
                     $try_class_func = $try_class_func2;
                 }
                 $res = $res->{$try_class_func}($data);
                 if (defined('MW_API_RAW')) {
                     $mod_class_api_called = true;
                 }
                 return $this->_api_responce($res);
             }
             break;
         default:
             $res = false;
             if (isset($hooks[$api_function_full])) {
                 $data = array_merge($_GET, $_POST);
                 $call = $hooks[$api_function_full];
                 if (!empty($call)) {
                     foreach ($call as $call_item) {
                         $res = call_user_func($call_item, $data);
                     }
                 }
                 if ($res != false) {
                     return $this->_api_responce($res);
                 }
             }
             if ($mod_class_api == true and $mod_api_class != false) {
                 $mod_api_class = str_replace('..', '', $mod_api_class);
                 $try_class = str_replace('/', '\\', $mod_api_class);
                 $try_class_full = str_replace('/', '\\', $api_function_full);
                 $try_class_full2 = str_replace('\\', '/', $api_function_full);
                 $mod_api_class_test = explode('/', $try_class_full2);
                 $try_class_func_test = array_pop($mod_api_class_test);
                 $mod_api_class_test_full = implode('/', $mod_api_class_test);
                 $mod_api_err = false;
                 if (!defined('MW_API_RAW')) {
                     if (!in_array($try_class_full, $api_exposed) and !in_array($try_class_full2, $api_exposed) and !in_array($mod_api_class_test_full, $api_exposed)) {
                         $mod_api_err = true;
                         foreach ($api_exposed as $api_exposed_value) {
                             if ($mod_api_err == true) {
                                 if ($api_exposed_value == $try_class_full) {
                                     $mod_api_err = false;
                                 } elseif (strtolower('\\' . $api_exposed_value) == strtolower($try_class_full)) {
                                     $mod_api_err = false;
                                 } elseif ($api_exposed_value == $try_class_full2) {
                                     $mod_api_err = false;
                                 } else {
                                     $convert_slashes = str_replace('\\', '/', $try_class_full);
                                     if ($convert_slashes == $api_exposed_value) {
                                         $mod_api_err = false;
                                     }
                                 }
                             }
                         }
                     } else {
                         $mod_api_err = false;
                     }
                 }
                 if ($mod_class_api and $mod_api_err == false) {
                     if (!class_exists($try_class, false)) {
                         $remove = $url_segs;
                         $last_seg = array_pop($remove);
                         $last_prev_seg = array_pop($remove);
                         $last_prev_seg2 = array_pop($remove);
                         if (class_exists($last_prev_seg, false)) {
                             $try_class = $last_prev_seg;
                         } elseif (class_exists($last_prev_seg2, false)) {
                             $try_class = $last_prev_seg2;
                         }
                     }
                     if (!class_exists($try_class, false)) {
                         $try_class_mw = ltrim($try_class, '/');
                         $try_class_mw = ltrim($try_class_mw, '\\');
                         $try_class = $try_class_mw;
                     }
                     if (class_exists($try_class, false)) {
                         if ($params != false) {
                             $data = $params;
                         } elseif (!$_POST and !$_REQUEST) {
                             $data = $this->app->url_manager->params(true);
                             if (empty($data)) {
                                 $data = $this->app->url_manager->segment(2);
                             }
                         } else {
                             $data = array_merge($_GET, $_POST);
                         }
                         $res = new $try_class($data);
                         if (method_exists($res, $try_class_func) or method_exists($res, $try_class_func2)) {
                             if (method_exists($res, $try_class_func2)) {
                                 $try_class_func = $try_class_func2;
                             }
                             $res = $res->{$try_class_func}($data);
                             $mod_class_api_called = true;
                             return $this->_api_responce($res);
                         }
                     } else {
                         mw_error('The api class ' . $try_class . '  does not exist');
                     }
                 }
             }
             break;
     }
     if ($api_function) {
     } else {
         $api_function = 'index';
     }
     if ($api_function == 'module' and $mod_class_api_called == false) {
         $this->module();
     } else {
         $err = false;
         if (!in_array($api_function, $api_exposed)) {
             $err = true;
         }
         if ($err == true) {
             foreach ($api_exposed as $api_exposed_item) {
                 if ($api_exposed_item == $api_function) {
                     $err = false;
                 }
             }
         }
         if (isset($api_function_full)) {
             foreach ($api_exposed as $api_exposed_item) {
                 if (is_string($api_exposed_item) and is_string($api_function_full)) {
                     $api_function_full = str_replace('\\', '/', $api_function_full);
                     $api_function_full = ltrim($api_function_full, '/');
                     if (strtolower($api_exposed_item) == strtolower($api_function_full)) {
                         $err = false;
                     }
                 }
             }
         }
         if ($err == false) {
             if ($mod_class_api_called == false) {
                 if (!$_POST and !$_REQUEST) {
                     //  $data = $this->app->url_manager->segment(2);
                     $data = $this->app->url_manager->params(true);
                     if (empty($data)) {
                         $data = $this->app->url_manager->segment(2);
                     }
                 } else {
                     //$data = $_REQUEST;
                     $data = array_merge($_GET, $_POST);
                 }
                 $api_function_full_2 = explode('/', $api_function_full);
                 unset($api_function_full_2[count($api_function_full_2) - 1]);
                 $api_function_full_2 = implode('/', $api_function_full_2);
                 if (function_exists($api_function)) {
                     $res = $api_function($data);
                 } elseif (class_exists($api_function, false)) {
                     //
                     $segs = $this->app->url_manager->segment();
                     $mmethod = array_pop($segs);
                     $class = new $api_function($this->app);
                     if (method_exists($class, $mmethod)) {
                         $res = $class->{$mmethod}($data);
                     }
                 } else {
                     $api_function_full_2 = str_replace(array('..', '/'), array('', '\\'), $api_function_full_2);
                     $api_function_full_2 = __NAMESPACE__ . '\\' . $api_function_full_2;
                     if (class_exists($api_function_full_2, false)) {
                         //
                         $segs = $this->app->url_manager->segment();
                         $mmethod = array_pop($segs);
                         $class = new $api_function_full_2($this->app);
                         if (method_exists($class, $mmethod)) {
                             $res = $class->{$mmethod}($data);
                         }
                     } elseif (isset($api_function_full)) {
                         $api_function_full = str_replace('\\', '/', $api_function_full);
                         $api_function_full1 = explode('/', $api_function_full);
                         $mmethod = array_pop($api_function_full1);
                         $mclass = array_pop($api_function_full1);
                         if (class_exists($mclass, false)) {
                             $class = new $mclass($this->app);
                             if (method_exists($class, $mmethod)) {
                                 $res = $class->{$mmethod}($data);
                             }
                         }
                     }
                 }
             }
             if (isset($res) and isset($hooks[$api_function]) and is_array($hooks[$api_function]) and !empty($hooks[$api_function])) {
                 foreach ($hooks[$api_function] as $hook_key => $hook_value) {
                     if ($hook_value != false and $hook_value != null) {
                         $hook_value($res);
                     }
                 }
             } else {
                 //error('The api function ' . $api_function . ' does not exist', __FILE__, __LINE__);
             }
             // print $api_function;
         } else {
             $api_function = mw()->format->clean_html($api_function);
             $api_function = mw()->format->clean_xss($api_function);
             mw_error('The api function ' . $api_function . ' is not defined in the allowed functions list');
         }
         if (isset($res)) {
             return $this->_api_responce($res);
         }
         return;
     }
 }
예제 #5
0
/**
 * Returns user info array.
 */
function api_get_user(&$a, $contact_id = Null, $type = "json")
{
    global $called_api;
    $user = null;
    $extra_query = "";
    $url = "";
    $nick = "";
    logger("api_get_user: Fetching user data for user " . $contact_id, LOGGER_DEBUG);
    // Searching for contact URL
    if (!is_null($contact_id) and intval($contact_id) == 0) {
        $user = dbesc(normalise_link($contact_id));
        $url = $user;
        $extra_query = "AND `contact`.`nurl` = '%s' ";
        if (api_user() !== false) {
            $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
        }
    }
    // Searching for unique contact id
    if (!is_null($contact_id) and intval($contact_id) != 0) {
        $user = dbesc(api_unique_id_to_url($contact_id));
        if ($user == "") {
            die(api_error($a, $type, t("User not found.")));
        }
        $url = $user;
        $extra_query = "AND `contact`.`nurl` = '%s' ";
        if (api_user() !== false) {
            $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
        }
    }
    if (is_null($user) && x($_GET, 'user_id')) {
        $user = dbesc(api_unique_id_to_url($_GET['user_id']));
        if ($user == "") {
            die(api_error($a, $type, t("User not found.")));
        }
        $url = $user;
        $extra_query = "AND `contact`.`nurl` = '%s' ";
        if (api_user() !== false) {
            $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
        }
    }
    if (is_null($user) && x($_GET, 'screen_name')) {
        $user = dbesc($_GET['screen_name']);
        $nick = $user;
        $extra_query = "AND `contact`.`nick` = '%s' ";
        if (api_user() !== false) {
            $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
        }
    }
    if (is_null($user) and $a->argc > count($called_api) - 1 and count($called_api) > 0) {
        $argid = count($called_api);
        list($user, $null) = explode(".", $a->argv[$argid]);
        if (is_numeric($user)) {
            $user = dbesc(api_unique_id_to_url($user));
            if ($user == "") {
                return false;
            }
            $url = $user;
            $extra_query = "AND `contact`.`nurl` = '%s' ";
            if (api_user() !== false) {
                $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
            }
        } else {
            $user = dbesc($user);
            $nick = $user;
            $extra_query = "AND `contact`.`nick` = '%s' ";
            if (api_user() !== false) {
                $extra_query .= "AND `contact`.`uid`=" . intval(api_user());
            }
        }
    }
    logger("api_get_user: user " . $user, LOGGER_DEBUG);
    if (!$user) {
        if (api_user() === false) {
            api_login($a);
            return False;
        } else {
            $user = $_SESSION['uid'];
            $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
        }
    }
    logger('api_user: '******', user: '******'t found, fetch it from the unique contacts
    if (count($uinfo) == 0) {
        $r = array();
        if ($url != "") {
            $r = q("SELECT * FROM unique_contacts WHERE url='%s' LIMIT 1", $url);
        } elseif ($nick != "") {
            $r = q("SELECT * FROM unique_contacts WHERE nick='%s' LIMIT 1", $nick);
        }
        if ($r) {
            // If no nick where given, extract it from the address
            if ($r[0]['nick'] == "" or $r[0]['name'] == $r[0]['nick']) {
                $r[0]['nick'] = api_get_nick($r[0]["url"]);
            }
            $ret = array('id' => $r[0]["id"], 'id_str' => (string) $r[0]["id"], 'name' => $r[0]["name"], 'screen_name' => $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'], 'location' => NULL, 'description' => NULL, 'url' => $r[0]["url"], 'protected' => false, 'followers_count' => 0, 'friends_count' => 0, 'listed_count' => 0, 'created_at' => api_date(0), 'favourites_count' => 0, 'utc_offset' => 0, 'time_zone' => 'UTC', 'geo_enabled' => false, 'verified' => false, 'statuses_count' => 0, 'lang' => '', 'contributors_enabled' => false, 'is_translator' => false, 'is_translation_enabled' => false, 'profile_image_url' => $r[0]["avatar"], 'profile_image_url_https' => $r[0]["avatar"], 'following' => false, 'follow_request_sent' => false, 'notifications' => false, 'statusnet_blocking' => false, 'notifications' => false, 'statusnet_profile_url' => $r[0]["url"], 'uid' => 0, 'cid' => 0, 'self' => 0, 'network' => '');
            return $ret;
        } else {
            die(api_error($a, $type, t("User not found.")));
        }
    }
    if ($uinfo[0]['self']) {
        $usr = q("select * from user where uid = %d limit 1", intval(api_user()));
        $profile = q("select * from profile where uid = %d and `is-default` = 1 limit 1", intval(api_user()));
        //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
        // count public wall messages
        $r = q("SELECT count(*) as `count` FROM `item`\n\t\t\t\t\tWHERE  `uid` = %d\n\t\t\t\t\tAND `type`='wall'", intval($uinfo[0]['uid']));
        $countitms = $r[0]['count'];
    } else {
        //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
        $r = q("SELECT count(*) as `count` FROM `item`\n\t\t\t\t\tWHERE  `contact-id` = %d", intval($uinfo[0]['id']));
        $countitms = $r[0]['count'];
    }
    // count friends
    $r = q("SELECT count(*) as `count` FROM `contact`\n\t\t\t\tWHERE  `uid` = %d AND `rel` IN ( %d, %d )\n\t\t\t\tAND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
    $countfriends = $r[0]['count'];
    $r = q("SELECT count(*) as `count` FROM `contact`\n\t\t\t\tWHERE  `uid` = %d AND `rel` IN ( %d, %d )\n\t\t\t\tAND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
    $countfollowers = $r[0]['count'];
    $r = q("SELECT count(*) as `count` FROM item where starred = 1 and uid = %d and deleted = 0", intval($uinfo[0]['uid']));
    $starred = $r[0]['count'];
    if (!$uinfo[0]['self']) {
        $countfriends = 0;
        $countfollowers = 0;
        $starred = 0;
    }
    // Add a nick if it isn't present there
    if ($uinfo[0]['nick'] == "" or $uinfo[0]['name'] == $uinfo[0]['nick']) {
        $uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
    }
    // Fetching unique id
    $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
    // If not there, then add it
    if (count($r) == 0) {
        q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']), dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
        $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
    }
    $network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
    $ret = array('id' => intval($r[0]['id']), 'id_str' => (string) intval($r[0]['id']), 'name' => $uinfo[0]['name'] ? $uinfo[0]['name'] : $uinfo[0]['nick'], 'screen_name' => $uinfo[0]['nick'] ? $uinfo[0]['nick'] : $uinfo[0]['name'], 'location' => $usr ? $usr[0]['default-location'] : $network_name, 'description' => $profile ? $profile[0]['pdesc'] : NULL, 'profile_image_url' => $uinfo[0]['micro'], 'profile_image_url_https' => $uinfo[0]['micro'], 'url' => $uinfo[0]['url'], 'protected' => false, 'followers_count' => intval($countfollowers), 'friends_count' => intval($countfriends), 'created_at' => api_date($uinfo[0]['created']), 'favourites_count' => intval($starred), 'utc_offset' => "0", 'time_zone' => 'UTC', 'statuses_count' => intval($countitms), 'following' => $uinfo[0]['rel'] == CONTACT_IS_FOLLOWER or $uinfo[0]['rel'] == CONTACT_IS_FRIEND, 'verified' => true, 'statusnet_blocking' => false, 'notifications' => false, 'statusnet_profile_url' => $a->get_baseurl() . "/contacts/" . $uinfo[0]['cid'], 'uid' => intval($uinfo[0]['uid']), 'cid' => intval($uinfo[0]['cid']), 'self' => $uinfo[0]['self'], 'network' => $uinfo[0]['network']);
    return $ret;
}
예제 #6
0
파일: api.php 프로젝트: nphyx/friendica
/**
 * Returns user info array.
 */
function api_get_user(&$a, $contact_id = Null)
{
    global $called_api;
    $user = null;
    $extra_query = "";
    if (!is_null($contact_id)) {
        $user = $contact_id;
        $extra_query = "AND `contact`.`id` = %d ";
    }
    if (is_null($user) && x($_GET, 'user_id')) {
        $user = intval($_GET['user_id']);
        $extra_query = "AND `contact`.`id` = %d ";
    }
    if (is_null($user) && x($_GET, 'screen_name')) {
        $user = dbesc($_GET['screen_name']);
        $extra_query = "AND `contact`.`nick` = '%s' ";
        if (local_user() !== false) {
            $extra_query .= "AND `contact`.`uid`=" . intval(local_user());
        }
    }
    if (is_null($user) && $a->argc > count($called_api) - 1) {
        $argid = count($called_api);
        list($user, $null) = explode(".", $a->argv[$argid]);
        if (is_numeric($user)) {
            $user = intval($user);
            $extra_query = "AND `contact`.`id` = %d ";
        } else {
            $user = dbesc($user);
            $extra_query = "AND `contact`.`nick` = '%s' ";
            if (local_user() !== false) {
                $extra_query .= "AND `contact`.`uid`=" . intval(local_user());
            }
        }
    }
    if (!$user) {
        if (local_user() === false) {
            api_login($a);
            return False;
        } else {
            $user = $_SESSION['uid'];
            $extra_query = "AND `contact`.`uid` = %d AND `contact`.`self` = 1 ";
        }
    }
    logger('api_user: '******' ', $user);
    // user info
    $uinfo = q("SELECT *, `contact`.`id` as `cid` FROM `contact`\n\t\t\t\tWHERE 1\n\t\t\t\t{$extra_query}", $user);
    if (count($uinfo) == 0) {
        return False;
    }
    if ($uinfo[0]['self']) {
        $usr = q("select * from user where uid = %d limit 1", intval(local_user()));
        $profile = q("select * from profile where uid = %d and `is-default` = 1 limit 1", intval(local_user()));
        // count public wall messages
        $r = q("SELECT COUNT(`id`) as `count` FROM `item`\n\t\t\t\t\tWHERE  `uid` = %d\n\t\t\t\t\tAND `type`='wall' \n\t\t\t\t\tAND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", intval($uinfo[0]['uid']));
        $countitms = $r[0]['count'];
    } else {
        $r = q("SELECT COUNT(`id`) as `count` FROM `item`\n\t\t\t\t\tWHERE  `contact-id` = %d\n\t\t\t\t\tAND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", intval($uinfo[0]['id']));
        $countitms = $r[0]['count'];
    }
    // count friends
    $r = q("SELECT COUNT(`id`) as `count` FROM `contact`\n\t\t\t\tWHERE  `uid` = %d AND `rel` IN ( %d, %d )\n\t\t\t\tAND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
    $countfriends = $r[0]['count'];
    $r = q("SELECT COUNT(`id`) as `count` FROM `contact`\n\t\t\t\tWHERE  `uid` = %d AND `rel` IN ( %d, %d )\n\t\t\t\tAND `self`=0 AND `blocked`=0 AND `pending`=0 AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND));
    $countfollowers = $r[0]['count'];
    $r = q("SELECT count(`id`) as `count` FROM item where starred = 1 and uid = %d and deleted = 0", intval($uinfo[0]['uid']));
    $starred = $r[0]['count'];
    if (!$uinfo[0]['self']) {
        $countfriends = 0;
        $countfollowers = 0;
        $starred = 0;
    }
    $ret = array('self' => intval($uinfo[0]['self']), 'uid' => intval($uinfo[0]['uid']), 'id' => intval($uinfo[0]['cid']), 'name' => $uinfo[0]['name'], 'screen_name' => $uinfo[0]['nick'] ? $uinfo[0]['nick'] : $uinfo[0]['name'], 'location' => $usr ? $usr[0]['default-location'] : '', 'profile_image_url' => $uinfo[0]['micro'], 'url' => $uinfo[0]['url'], 'contact_url' => $a->get_baseurl() . "/contacts/" . $uinfo[0]['cid'], 'protected' => false, 'friends_count' => intval($countfriends), 'created_at' => api_date($uinfo[0]['name-date']), 'utc_offset' => "+00:00", 'time_zone' => 'UTC', 'geo_enabled' => false, 'statuses_count' => intval($countitms), 'lang' => 'en', 'description' => $profile ? $profile[0]['pdesc'] : '', 'followers_count' => intval($countfollowers), 'favourites_count' => intval($starred), 'contributors_enabled' => false, 'follow_request_sent' => true, 'profile_background_color' => 'cfe8f6', 'profile_text_color' => '000000', 'profile_link_color' => 'FF8500', 'profile_sidebar_fill_color' => 'AD0066', 'profile_sidebar_border_color' => 'AD0066', 'profile_background_image_url' => '', 'profile_background_tile' => false, 'profile_use_background_image' => false, 'notifications' => false, 'following' => '', 'verified' => true, 'status' => array());
    return $ret;
}
예제 #7
0
$page_security = 'SA_API';
include_once API_ROOT . "/session-custom.inc";
include_once API_ROOT . "/vendor/autoload.php";
\Slim\Slim::registerAutoloader();
include_once API_ROOT . "/util.php";
include_once FA_ROOT . "/includes/date_functions.inc";
include_once FA_ROOT . "/includes/data_checks.inc";
// echo "sales quote => ".ST_SALESQUOTE;
// echo "sales order => ".ST_SALESORDER;
// echo "sales invoice => ".ST_SALESINVOICE;
// echo "cust delivery => ".ST_CUSTDELIVERY;
// echo "cust credit => ".ST_CUSTCREDIT;
$rest = new \Slim\Slim(array('log.enabled' => true, 'mode' => 'debug', 'debug' => true));
$rest->setName('SASYS');
// API Login Hook
api_login();
$req = $rest->request();
define("RESULTS_PER_PAGE", 2);
// API Routes
// ------------------------------- Items -------------------------------
// Get Items
$rest->get('/inventory/', function () use($rest) {
    global $req;
    include_once API_ROOT . "/inventory.inc";
    $page = $req->get("page");
    if ($page == null) {
        inventory_all();
    } else {
        // If page = 1 the value will be 0, if page = 2 the value will be 1, ...
        $from = --$page * RESULTS_PER_PAGE;
        inventory_all($from);
예제 #8
0
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
require_once __DIR__ . "/../app/util/api.php";
require_once __DIR__ . "/../templates/head.php";
require_once __DIR__ . "/../templates/body.php";
require_once __DIR__ . "/../config/luminate.php";
if (isset($_POST["survey_id"])) {
    $id = $_POST["survey_id"];
    $_SESSION["survey_id"] = $id;
} else {
    print "No ID";
    die;
}
$url = "https://secure2.convio.net/cmp/site/SRConsAPI";
$param = array("response_format" => "json", "api_key" => api_key(), "v" => "1.0", "method" => "getSingleSignOnToken", "login_name" => api_login(), "login_password" => api_pass());
$res = sendAPI($url, $param, true);
if (isset($res->getSingleSignOnTokenResponse->token)) {
    $token = $res->getSingleSignOnTokenResponse->token;
    $_SESSION["sso_token"] = $token;
} else {
    var_dump($res);
    die;
}
$url = "https://secure2.convio.net/cmp/site/CRSurveyAPI";
$param = array("response_format" => "json", "api_key" => api_key(), "v" => "1.0", "sso_auth_token" => $token, "method" => "getSurvey", "survey_id" => $id);
$res = sendAPI($url, $param);
if (isset($res->getSurveyResponse->survey->surveyQuestions)) {
    $Qs = $res->getSurveyResponse->survey->surveyQuestions;
} else {
    die;
예제 #9
0
파일: api.php 프로젝트: kandsten/phpBB3-API
$command = request_var('cmd', '');
$dom = new DOMDocument();
$root = $dom->createElement('community');
$root->setAttribute('system', 'phpbb3');
$root->setAttribute('base', $board_url);
header('Content-type: text/xml; charset=UTF-8');
#header('Content-type: text/plain; charset=UTF-8');
switch ($command) {
    case 'readtopic':
        api_read_topic($topicid);
        break;
    case 'userinfo':
        api_get_userinfo($userid);
        break;
    case 'login':
        api_login(request_var('username', '', true), request_var('password', '', true));
        break;
    case 'authenticate':
        api_authenticate();
        break;
    case 'verify':
        api_verify($_GET['username'], request_var('authcookie', ''));
        break;
    case 'exists':
        api_exists($_GET['username']);
        break;
    case 'get_cookie':
        api_js_getcookie();
        break;
    case 'verify_cookie':
        api_verify_cookie(request_var('authcookie', ''), request_var('site', ''), request_var('sitecookie', ''));