Write Your First ownCloud App in 60 Minutes

ownCloud GmbH www.owncloud.com/contact Leipziger Platz 21 phone: +1 (877) 394-2030 90491 Nürnberg Germany www.owncloud.com Write Your First ownCloud App in 60 Minutes

ownCloud makes it easy to securely • You want to extend a photo manage- HTML – You need some basic HTML and store, sync, and share your files and ment desktop application with the CSS knowledge to develop the user documents, and access them from possibility to share photos with interface for your application. ownCloud all your devices and platforms. But others. provides functionality to create configu- ownCloud is even more than a modern ration dialogs and other basic user inter- file sync and share solution. Like apps • You want to extend your game to store face elements. ownCloud uses jQuery to on a smart phone, ownCloud supports a shared high-score list in a central enable the creation of a rich HTML5 web independently created applications as place. interface as part of your application. plug-ins or extensions that can run on top of ownCloud and provide additional • You want to extend your notes appli- SQL – ownCloud has functionality to features and functionalities. cation or RSS reader to sync data and read and write basic data to the data- status between different devices. base or file system. You will need some Example of apps that have already been SQL knowledge if you want to work with created for ownCloud include media more complex data structures in your player, calendar, and contacts. ownCloud application. This is optional and depends is a platform for a wide range of HTML5 How easy is it? on the type of application you want to applications and web services that you create. can host and run under your own control. Writing ownCloud applications is easy. You need some basic PHP and HTML ownCloud API – The ownCloud core Best of all, if you have some basic knowledge to write your first application. proviwdes a stable public API for programming skills in a few common Depending on the type of application you ownCloud application developers. You languages, you can create your own want to build, some JavaScript and SQL ownCloud app in about 60 minutes. knowledge is also useful. ownCloud has Why develop an app for ownCloud? a very open and friendly community so ownCloud is an open platform, and that you can always get help from experts via About ownCloud means everybody is welcome to join the mailing lists, IRC chat channels, or the ownCloud is a software platform ownCloud core developer community to forum at https://vimeo.com/81178032. that can replace proprietary help improve the core features and push cloud services such as Google ownCloud forward. But even if you don’t Drive, or box.net. Users want to do this, there are reasons why can host an ownCloud installa- you should consider writing an ownCloud What do you tion on their own hardware or at application. Perhaps you are missing a a provider that offers ownCloud feature and want to extend ownCloud need to know? hosting. ownCloud can also run to support it. Perhaps you don’t want to on most basic web spaces that A working knowledge of the following rely on proprietary services like Gmail for support PHP without the need for programming environments is needed to your web mail interface, or you want your special configurations. ownCloud write an ownCloud app. own application to manage your DVD is suitable for home users and collection. big organizations alike, and is PHP – You should know how to code available under the AGPL license some basic PHP and have a basic You can easily write your own ownCloud as . It is developed understanding of how the web and web application to implement any of these by an open, friendly and world- servers work. The PHP syntax is similar features, using an HTML5 interface or an wide community of developers. to C or C++ and a lot of other languages, API to provide the web service you want. Professional enterprise support so it should be easy to learn. ownCloud and services for ownCloud are provides a powerful framework to help Many people write ownCloud applica- delivered by ownCloud Windows, you with things like user management tions to build a syncing and sharing and and templating. backend for an existing application. Some examples are:

Page 1 of 3 YOUR CLOUD, YOUR DATA, YOUR WAY! will need to be familiar with the basic • css – The additional stylesheets of ’valu e’);. You can find more informa- calls that are required for registering this application are located here. tion here: http://owncloud.org/dev/ your application, loading and saving apps/getting-started/. configurations, and other basic functio- • img – All the needed images should nalities. be located in this folder. • The API – You can find the complete API documentation here: • js – You can put you Javascript http://owncloud.org/dev/apps/ files here. The JS libraries we use getting-started/. The most important How to start are jQuery and Torch. You can add calls are: scripts to your pages using OCP\ A good place to start is to look at the Util::addscript. Scripts can be OCP\App::addNavigationEntry ownCloud apps already written. You added this way in either appinfo/ This adds an navigation of your appli- can find all the ownCloud code in the app. or in your app‘s individual cation to the main navigation on the apps repository at https://github.com/ PHP scripts. left. You usually call this in app.php. ownCloud, a leading site for open source code sharing. You’ll find many applica- • l10n – Put your translations into this OCP\App::setActiveNavigationEntry tions here that will help you learn how folder if you want to support more This calls activated a navigation ownCloud apps are structured. You may than English. As soon as the transla- entry. You do this when inside your also find apps similar to the ones you are tion detects a l10n folder it knows that application. considering, and you may want to contri- this program is translatable. You can bute to those before writing your own. find more information about the trans- OCP\App::registerPersonal lation system here http://owncloud. You can use this call to register an The application template provided at org/dev/translation/. personal settings section on the user https://github.com/owncloud/apps/ settings page. tree/master/appframework is a good • lib – Application logic, classes, starting point for development. You can and functions go into php files in OCP\App::registerAdmin always ask questions on the mailing this folder. ownCloud uses the MVC You can use this call to register an lists, forum, or the chat channel if you principle. The libraries represent the admin settings section on the main need help. You can find all the possible model. Basically all data should be admin page. ways to contact the core team here: handled here so the php files that http://owncloud.org/contact/. the user calls only interact with the OCP\Config::getUserValue library. If you have a look at the lib Use this call to read a setting for the folder in, for example, the contacts The directory structure app, you will see three files: address- book.php, hooks.php and connector_ ownCloud applications have to be sabre.php. The addressbook.php file Helpful links structured in a specific way to work. The contains all methods that are required recommended directory structure is: for handling addresses. We mostly Getting started: use the classes as namespaces and http://owncloud.org/dev/apps/ • ajax – a directory for the ajax call write static functions; “real” OOP with getting-started/ controller files if needed in your dynamically instansiated objects is application. only used if needed. Existing apps: https://github.com/ownCloud • appinfo – The info.xml and the • templates – Templates for your user app.php are located in this folder. interface should go into this folder. Application template: The most important file is app.php. ownCloud has its own template https://github.com/owncloud/ ownCloud will call this file every time system. The templates are php files apps/tree/master/appframework it runs, so this is the place where you that are included by OC Template. can register your navigation entries Having a look at an example file Contacting the core team: or connect signals and slots. You should show you everything you need http://owncloud.org/contact/ can also put a .xml into this to know. The variables are assigned folder if needed. by using $tmpl->assign(‘name’,

Page 2 of 3 YOUR CLOUD, YOUR DATA, YOUR WAY! currently logged in user from the settings store.

OCP\Config::setUserValue Use this call to write a setting for the currently logged in user to the settings store.

OCP\DB::prepare Prepare an SQL statement for execu- tion.

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

Conclusion

One of the great advantages of working with an open platform like ownCloud is its easy extensibility. There is a whole community of users ready to help you get started. If you have an idea for a service to run on top of ownCloud, consider developing it yourself. You’ll find it’s Copyright 2016 ownCloud. All Rights Reserved. easy, fast, and well worth the effort. ownCloud and the ownCloud Logo are registe- red trademarks of ownCloud in the United States and/or other countries.

ownCloud GmbH Leipziger Platz 21 90491 Nürnberg Germany

www.owncloud.com/contact phone: +49 911 14888690

www.owncloud.com

@ownCloud facebook.com/owncloud gplus.is/owncloud linkedin.com/company/owncloud Whitepaper Write Your First ownCloud App in 60 Minutes 160902

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