Owncloud App Development Manual

Embed Size (px)

Citation preview

  • 8/12/2019 Owncloud App Development Manual

    1/4

    Write your first ownCloud App

    in 60 minutes

    ownCloud, Inc.

    10 Foster Road

    Lexington, MA 02421

    United States

    mail: [email protected]

    phone: +1 (877) 394-2030

    https://www.owncloud.com

  • 8/12/2019 Owncloud App Development Manual

    2/4

    YOUR CLOUD, YOUR DATA,YOUR WAY!Page 1 of 2

    Write your first ownCloud App in 60min

    ownCloud is a software that can be used

    to replace proprietary cloud services

    like Google Drive, Dropbox or box.net.

    Users can host an ownCloud installation

    on own hardware or at a provider that

    offers ownCloud hosting. ownCloud can

    also run on most basic webspaces that

    support PHP without the need for special

    configurations. ownCloud is suitable for

    home users and big organisations and is

    available under the AGPL license as free

    software. It is developed by an open and

    friendly worldwide community of develo-

    pers. Professional enterprise support and

    services around ownCloud is delivered by

    ownCloud Inc.

    Ehe core feature is to store, sync and

    share you files and documents and access

    them from all you devices cross platform.

    But ownCloud is more than just a modern

    file sync and share solution. ownCloud

    support an concept called ownCloud

    applications. An application is a plugin or

    extension that can run on top of ownC-

    loud and provide additional features and

    functionallities. Example for apps that are

    already part of ownCloud are the media

    player app, the calendar or the contacts

    app. ownCloud is a platform for HTML5 ap-

    plications and all kind of webservice that

    users want to host and run under own

    control.

    Why should you develop an appfor ownCloud ?

    Everybody is welcome to join the ownC-

    loud core developer community to help to

    improve the core features and help to

    push ownCloud forward. But even if you

    dont want to do this there are reason why

    you should consider to write an ownCloud

    application. Perhaps you are missing a

    feature and want to extend ownCloud to

    suport it. Perhaps you dont want to rely

    on proprietary services like gmail to

    provide you with a web-mail interface, or

    you want your own link shortening service

    running on your own machine or you want

    your own application to manage your DVD

    collection. You can easily write your own

    ownCloud application to implement this

    features. Your ownCloud application can

    provide an HTML5 interface or an RESTfull

    API to provide you with the webservice

    you want. Another reason to write an own-

    Cloud application is to build a syncing and

    sharing backend for an existing applica-

    tion. Example are:

    You want to extend a photo manage-

    ment desktop application with the

    posibility to share photos with others.

    You want extend your game to store

    a shared high score list on a central

    place.

    You want to extend you notes appli-

    cation or RSS reader to sync data and

    status between different devices.

    Writing ownCloud applications is easy and

    fun. So please try it if you have an idea for

    a free service that should run on top of

    ownCloud.

    How difficult is it?

    Writing ownCloud applications is easy.

    You need some basic PHP and HTML

    knowledge to write your first ownCloud

    application. Depending on the typ of

    application you want to build, some

    JavaScript and SQL knowledge is also use-

    ful. ownCloud has a very open and friend-

    ly community so you can always get help

    from experts via mailinglists, IRC chat

    channels or the forum.

    What do I have to know?

    PHP

    You should know how to code some basic

    PHP and you need some basic understan-

    ding how the web and webservers work.

    The PHP syntax is similar to C or C++

    and a lot of other languages so it should

    be easy to learn. ownCloud has a powerful

    framework to help you with thing like

    usermanagement or templating.

    HTMLYou need some basic HTML and CSS

    knowledge to develop the userinterface of

    your application. ownCloud provides you

    with some basic functionallity to create

    configuration dialogs or other basic user-

    interface elements. ownCloud is using

    jQuery so we suggest that you look into it

    if you want to create a rich HTML5 webin-

    terface as part of your application.

    SQL

    ownCloud has basic functionallity to read

    and write basic data to the database orto the filesystem. You need some SQL

    knowledge if you want to work with more

    complex data structures in your applica-

    tion. This is optional and depends on the

    type of application you want to create.

    ownCloud API

    The ownCloud core provides a stable

    public API for ownCloud application devel-

    opers. You should make yourself familiar

    with the basic calls that are required to

    be used like registering you application,

    loading and saving of configuration

    and other basic functionallities.

  • 8/12/2019 Owncloud App Development Manual

    3/4

    YOUR CLOUD, YOUR DATA,YOUR WAY!Page 2 of 2

    How to start

    All the ownCloud code is located at gitori-

    ous.org [7]In the apps repository are a lot

    of application located that you can use to

    look into and learn how an ownCloud

    application is structured. [1]Before you

    start, please check if there already is a

    similar app you could contribute to.

    For the beginning we suggest to use the

    application template as a starting point

    for the development. [2]You can always

    ask questions on the mailinglists, forum

    or the chat channel. You find all the possi-

    ble ways to contact the core team here: [3]

    The directory structure

    ownCloud applications have to be

    structured in a specific way to work. The

    recommended directory str ucture is:

    ajax a directory for the ajax call cont-

    roler files if needed in your application.

    appinfo The info.xml and the app.php

    are located in this folder. The most im-

    portant file is app.php. ownCloud will

    call this file everytime it runs, so this is

    the place where you can register your

    navigation entries or connect signals

    and slots. You can also put a database.

    xml into this folder if needed.

    css The addtional stylesheets of this

    application are located here.

    img All the needed images should be

    located in this folder.

    js You can put you Javascript fileshere. The JS libraries we use are jQuery

    and Torch. You can add scripts to

    your pages using OCP\Util::addscript.

    Scripts can be added this way in either

    appinfo/app.php or in your apps

    individual PHP scripts.

    l10n Put your translations into this

    folder if you want to support more than

    english. As soon as the translationdetects a l10n folder it knows that

    this program is translatable. You find

    more information about the translation

    system here [6]

    lib Please put you application logic,

    classes and functions into php files

    in this folder. ownCloud uses the MVC

    principle. The libraries represent the

    model. Basically all data should be

    handled here so the php files the user

    calls only interact with the library. If

    you have a look at the lib folder in, for

    example the contacts app, you will

    see three files: addressbook. php,

    hooks.php and connector_sabre.php.

    addressbook.php contains all methods

    that are required for handling addres-

    ses. We mostly use the classes as

    namespaces and write static functions,

    real OOP with dynamicaly instansia-

    ted objects is only used if it is useful.

    templates Templates for your user-

    interface should go into this folder.

    ownCloud has its own template sys-

    tem. The templates are php files that

    are included by OC_Template. Having

    a look at an example file should show

    you everything you need to know. The

    variables are assigned by using $tmpl-

    >assign(name, value);, You find more

    information here [4]

    The API You find the complete API

    documentation here [4]

    The most important calls are:

    OCP\App::addNavigationEntry

    This adds an navigation of your applica-

    tion to the main navigation on the left.

    You usually call this in app.php

    OCP\App::setActiveNavigationEntry

    This calls activated a navigation entry.

    You do this when inside your application

    OCP\App::registerPersonal

    You can use this call to register an perso-

    nal settings section on the user settings

    page.

    OCP\App::registerAdmin

    You can use this call to register an admin

    settings section on the main admin page.

    OCP\Config::getUserValue

    Use this call to to read a setting for the

    currently logged in user from the settings

    store.

    OCP\Config::setUserValue

    Use this call to to write a setting for the

    currently logged in user to the set tings

    store.

    OCP\DB::prepare

    Prepare an SQL statement for execution.

    OCP\User::isLoggedIn

    Check if a user is currently logged in.

    OCP\Util::addscript

    Load an additional JS script

    OCP\Util::addStyle

    Load an additional CSS style

    [1] https://github.com/owncloud/apps

    [2] https://github.com/owncloud/apps/

    tree/master/appframework

    [3] http://owncloud.org/contact/

    [4]http://owncloud.org/dev/apps/

    getting-started/

    [5] http://api.owncloud.org

    [6] http://owncloud.org/dev/translation/

    [7] https://github.com/owncloud

  • 8/12/2019 Owncloud App Development Manual

    4/4

    ownCloud, Inc.

    10 Foster Road

    Lexington, MA 02421

    United States

    mail: [email protected]

    phone: +1 (877) 394-2030

    https://www.owncloud.com