示例#1
0
/**
 * Create a new application
 * 
 * @param string $application_id   id op the app
 * @param string $title            name of the app
 * @param string $description      description of the app
 * @param string $icon_url         url to an icon
 * @param array  $application_info array containing additional data about the application
 * 
 * @return APIApplication|boolean
 */
function ws_pack_create_application($application_id, $title, $description = "", $icon_url = "", $application_info = array())
{
    $result = false;
    if (!($application = ws_pack_get_application_from_id($application_id))) {
        // check if api registration is allowed
        if (elgg_get_plugin_setting("allow_registration", "ws_pack") == "yes") {
            if (!empty($application_id) && !empty($title)) {
                $application = new APIApplication();
                $application->title = $title;
                $application->application_id = $application_id;
                // set a description
                if (!empty($description)) {
                    $application->description = $description;
                }
                if (!empty($icon_url)) {
                    $application->icon_url = $icon_url;
                }
                if (!empty($application_info) && is_array($application_info)) {
                    $application->extended_information = json_encode($application_info);
                }
                // make sure we can save the application
                $ia = elgg_set_ignore_access(true);
                if ($application->save()) {
                    $result = $application;
                }
                // restore access
                elgg_set_ignore_access($ia);
            }
        } else {
            // registration is not allowed
            $result = -1;
        }
    } else {
        // already existed, shouldn't happen
        $result = $application;
    }
    return $result;
}