Recherche avancée

Médias (1)

Mot : - Tags -/Rennes

Autres articles (14)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Use, discuss, criticize

    13 avril 2011, par

    Talk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
    The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
    A discussion list is available for all exchanges between users.

  • Other interesting software

    13 avril 2011, par

    We don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
    The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
    We don’t know them, we didn’t try them, but you can take a peek.
    Videopress
    Website : http://videopress.com/
    License : GNU/GPL v2
    Source code : (...)

Sur d’autres sites (3783)

  • How to create a scheduled task – Introducing the Piwik Platform

    28 août 2014, par Thomas Steur — Development

    This is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to create a custom theme in Piwik). This time you’ll learn how to execute scheduled tasks in the background, for instance sending a daily email. For this tutorial you will need to have basic knowledge of PHP.

    What can you do with scheduled tasks ?

    Scheduled tasks let you execute tasks regularly (hourly, weekly, …). For instance you can :

    • create and send custom reports or summaries
    • sync users and websites with other systems
    • clear any caches
    • import third-party data into Piwik
    • monitor your Piwik instance
    • execute any other task you can think of

    Getting started

    In this series of posts, we assume that you have already set up your development environment. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik.

    To summarize the things you have to do to get setup :

    • Install Piwik (for instance via git).
    • Activate the developer mode : ./console development:enable --full.
    • Generate a plugin : ./console generate:plugin --name="MyTasksPlugin". There should now be a folder plugins/MyTasksPlugin.
    • And activate the created plugin under Settings => Plugins.

    Let’s start creating a scheduled task

    We start by using the Piwik Console to create a tasks template :

    ./console generate:scheduledtask

    The command will ask you to enter the name of the plugin the task should belong to. I will simply use the above generated plugin name “MyTasksPlugin”. There should now be a file plugins/MyTasksPlugin/Tasks.php which contains some examples to get you started easily :

    class Tasks extends \Piwik\Plugin\Tasks
    {
       public function schedule()
       {
           $this->hourly('myTask');  // method will be executed once every hour
           $this->daily('myTask');   // method will be executed once every day
           $this->weekly('myTask');  // method will be executed once every week
           $this->monthly('myTask'); // method will be executed once every month

           // pass a parameter to the task
           $this->weekly('myTaskWithParam', 'anystring');

           // specify a different priority
           $this->monthly('myTask', null, self::LOWEST_PRIORITY);
           $this->monthly('myTaskWithParam', 'anystring', self::HIGH_PRIORITY);
       }

       public function myTask()
       {
           // do something
       }

       public function myTaskWithParam($param)
       {
           // do something
       }
    }

    A simple example

    As you can see in the generated template you can execute tasks hourly, daily, weekly and monthly by registering a method which represents the actual task :

    public function schedule()
    {
       // register method remindMeToLogIn to be executed once every day
       $this->daily('remindMeToLogIn');  
    }

    public function remindMeToLogIn()
    {
       $mail = new \Piwik\Mail();
       $mail->addTo('me@example.com');
       $mail->setSubject('Check stats');
       $mail->setBodyText('Log into your Piwik instance and check your stats!');
       $mail->send();
    }

    This example sends you an email once a day to remind you to log into your Piwik daily. The Piwik platform makes sure to execute the method remindMeToLogIn exactly once every day.

    How to pass a parameter to a task

    Sometimes you want to pass a parameter to a task method. This is useful if you want to register for instance one task for each user or for each website. You can achieve this by specifying a second parameter when registering the method to execute.

    public function schedule()
    {
       foreach (\Piwik\Site::getSites() as $site) {
           // create one task for each site and pass the URL of each site to the task
           $this->hourly('pingSite', $site['main_url']);
       }
    }

    public function pingSite($siteMainUrl)
    {
       file_get_contents($siteMainUrl);
    }

    How to test scheduled tasks

    After you have created your task you are surely wondering how to test it. First, you should write a unit or integration test which we will cover in one of our future blog posts. Just one hint : You can use the command ./console generate:test to create a test. To manually execute all scheduled tasks you can execute the API method CoreAdminHome.runScheduledTasks by opening the following URL in your browser :

    http://piwik.example.com/index.php?module=API&method=CoreAdminHome.runScheduledTasks&token_auth=YOUR_API_TOKEN

    Don’t forget to replace the domain and the token_auth URL parameter.

    There is one problem with executing the scheduled tasks : The platform makes sure they will be executed only once an hour, a day, etc. This means you can’t simply reload the URL and test the method again and again as you would have to wait for the next hour or day. The proper solution is to set the constant DEBUG_FORCE_SCHEDULED_TASKS to true within the file Core/TaskScheduler.php. Don’t forget to set it back to false again once you have finished testing it.

    Starting from Piwik 2.6.0 you can alternatively execute the following command :

    ./console core:run-scheduled-tasks --force --token-auth=YOUR_TOKEN_AUTH

    The option “–force” will make sure to execute even tasks that are not due to run at this time. So you won’t have to modify any files.

    Which tasks are registered and when is the next execution time of my task ?

    The TasksTimetable plugin from the Marketplace can answer this question for you. Simply install and activate the plugin with one click by going to Settings => Marketplace => Get new functionality. It’ll add a new admin menu item under Settings named Scheduled Tasks.

    Publishing your Plugin on the Marketplace

    In case you want to share your task(s) with other Piwik users you can do this by pushing your plugin to a public GitHub repository and creating a tag. Easy as that. Read more about how to distribute a plugin.

    Advanced features

    Isn’t it easy to create scheduled tasks ? We never even created a file ! Of course, based on our API design principle “The complexity of our API should never exceed the complexity of your use case.” you can accomplish more if you want. For instance, you can define priorities, you can directly register methods from different objects and classes, you can specify at which time of a day a task should run and more.

    Would you like to know more about tasks ? Go to our Tasks class reference in the Piwik Developer Zone.

    If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.

  • How to expose new API methods in the HTTP Reporting API – Introducing the Piwik Platform

    26 février 2015, par Thomas Steur — Development

    This is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to write UI tests for your plugin). This time you’ll learn how to extend our Reporting API. For this tutorial you will need to have basic knowledge of PHP.

    What is Piwik’s Reporting API ?

    It allows third party applications to access analytics data and manipulate miscellaneous data (such as users or websites) through HTTP requests.

    What is it good for ?

    The Reporting API is used by the Piwik UI to render reports, to manage users, and more. If you want to add a feature to the Piwik UI, you might have to expose a method in the API to access this data. As the API is called via HTTP it allows you to fetch or manipulate any Piwik related data from anywhere. In these exposed API methods you can do pretty much anything you want, for example :

    • Enhance existing reports with additional data
    • Filter existing reports based on custom rules
    • Access the database and generate custom reports
    • Persist and read any data
    • Request server information

    Getting started

    In this series of posts, we assume that you have already set up your development environment. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik.

    To summarize the things you have to do to get setup :

    • Install Piwik (for instance via git).
    • Activate the developer mode : ./console development:enable.
    • Generate a plugin : ./console generate:plugin --name="MyApiPlugin". There should now be a folder plugins/MyApiPlugin.
    • And activate the created plugin : ./console plugin:activate "MyApiPlugin"

    Let’s start creating an API

    We start by using the Piwik Console to create a new API :

    ./console generate:api

    The command will ask you to enter the name of the plugin the created API should belong to. I will simply use the above chosen plugin name “MyApiPlugin”. There should now be a file plugins/MyApiPlugin/API.php which contains already an example to get you started easily :

    1. class API extends \Piwik\Plugin\API
    2. {
    3.     public function getAnswerToLife($truth = true)
    4.     {
    5.         if ($truth) {
    6.             return 42;
    7.         }
    8.  
    9.         return 24;
    10.     }
    11.  
    12.     public function getExampleReport($idSite, $period, $date, $wonderful = false)
    13.     {
    14.         $table = DataTable::makeFromSimpleArray(array(
    15.             array('label' => 'My Label 1', 'nb_visits' => '1'),
    16.             array('label' => 'My Label 2', 'nb_visits' => '5'),
    17.         ));
    18.  
    19.         return $table;
    20.     }
    21. }

    Télécharger

    Any public method in that file will be available via the Reporting API. For example the method getAnswerToLife can be called via this URL : index.php?module=API&method=MyApiPlugin.getAnswerToLife. The URL parameter method is a combination of your plugin name and the method name within this class.

    Passing parameters to your method

    Both example methods define some parameters. To pass any value to a parameter of your method simply specify them by name in the URL. For example ...&method=MyApiPlugin.getExampleReport&idSite=1&period=week&date=today&wonderful=1 to pass values to the parameters of the method getExampleReport.

    Returning a value

    In an API method you can return any boolean, number, string or array value. A resource or an object cannot be returned unless it implements the DataTableInterface such as DataTable (the primary data structure used to store analytics data in Piwik), DataTable\Map (stores a set of DataTables) and DataTable\Simple (a DataTable where every row has two columns : label and value).

    Did you know ? You can choose the response format of your API request by appending a parameter &format=JSON|XML|CSV|... to the URL. Check out the Reporting API Reference for more information.

    Best practices

    Check user permissions

    Do not forget to check whether a user actually has permissions to access data or to perform an action. If you’re not familiar with Piwik’s permissions and how to check them read our User Permission guide.

    Keep API methods small

    At Piwik we aim to write clean code. Therefore, we recommend to keep API methods small (separation of concerns). An API pretty much acts like a Controller :

    1. public function createLdapUser($idSite, $login, $password)
    2. {
    3.     Piwik::checkUserHasAdminAccess($idSite);
    4.     $this->checkLogin($login);
    5.     $this->checkPassword($password);
    6.    
    7.     $myModel = new LdapModel();
    8.     $success = $myModel->createUser($idSite, $login, $password);
    9.    
    10.     return $success;
    11. }

    Télécharger

    This is not only easy to read, it will also allow you to create simple tests for LdapModel (without having to bootstrap the whole Piwik layer) and you will be able to reuse it in other places if needed.

    Calling APIs of other plugins

    For example if you want to fetch an existing report from another plugin, say a list of all Page URLs, do not request this report by calling that method directly :

    \Piwik\Plugins\Actions\API::getInstance()->getPageUrls($idSite, $period, $date);

    . Instead, issue a new API request :

    $report = \Piwik\API\Request::processRequest('Actions.getPageUrls', array(
       'idSite' => $idSite,
       'period' => $period,
       'date'   => $date,
    ));

    This has several advantages :

    • It avoids a fatal error if the requested plugin is not available on a Piwik installation
    • Other plugins can extend the called API method via events (adding additional report data to a report, doing additional permission checks) but those events will be only triggered when requesting the report as suggested
    • If the method parameters change, your request will most likely still work

    Publishing your Plugin on the Marketplace

    In case you want to share your API with other Piwik users you can do this by pushing your plugin to a public GitHub repository and creating a tag. Easy as that. Read more about how to distribute a plugin and best practices when publishing a plugin.

    Isn’t it easy to create a API ? We never even created a file ! If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.

  • How to expose new API methods in the HTTP Reporting API – Introducing the Piwik Platform

    26 février 2015, par Thomas Steur — Development

    This is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to write UI tests for your plugin). This time you’ll learn how to extend our Reporting API. For this tutorial you will need to have basic knowledge of PHP.

    What is Piwik’s Reporting API ?

    It allows third party applications to access analytics data and manipulate miscellaneous data (such as users or websites) through HTTP requests.

    What is it good for ?

    The Reporting API is used by the Piwik UI to render reports, to manage users, and more. If you want to add a feature to the Piwik UI, you might have to expose a method in the API to access this data. As the API is called via HTTP it allows you to fetch or manipulate any Piwik related data from anywhere. In these exposed API methods you can do pretty much anything you want, for example :

    • Enhance existing reports with additional data
    • Filter existing reports based on custom rules
    • Access the database and generate custom reports
    • Persist and read any data
    • Request server information

    Getting started

    In this series of posts, we assume that you have already set up your development environment. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik.

    To summarize the things you have to do to get setup :

    • Install Piwik (for instance via git).
    • Activate the developer mode : ./console development:enable.
    • Generate a plugin : ./console generate:plugin --name="MyApiPlugin". There should now be a folder plugins/MyApiPlugin.
    • And activate the created plugin : ./console plugin:activate "MyApiPlugin"

    Let’s start creating an API

    We start by using the Piwik Console to create a new API :

    ./console generate:api

    The command will ask you to enter the name of the plugin the created API should belong to. I will simply use the above chosen plugin name “MyApiPlugin”. There should now be a file plugins/MyApiPlugin/API.php which contains already an example to get you started easily :

    1. class API extends \Piwik\Plugin\API
    2. {
    3.     public function getAnswerToLife($truth = true)
    4.     {
    5.         if ($truth) {
    6.             return 42;
    7.         }
    8.  
    9.         return 24;
    10.     }
    11.  
    12.     public function getExampleReport($idSite, $period, $date, $wonderful = false)
    13.     {
    14.         $table = DataTable::makeFromSimpleArray(array(
    15.             array('label' => 'My Label 1', 'nb_visits' => '1'),
    16.             array('label' => 'My Label 2', 'nb_visits' => '5'),
    17.         ));
    18.  
    19.         return $table;
    20.     }
    21. }

    Télécharger

    Any public method in that file will be available via the Reporting API. For example the method getAnswerToLife can be called via this URL : index.php?module=API&method=MyApiPlugin.getAnswerToLife. The URL parameter method is a combination of your plugin name and the method name within this class.

    Passing parameters to your method

    Both example methods define some parameters. To pass any value to a parameter of your method simply specify them by name in the URL. For example ...&method=MyApiPlugin.getExampleReport&idSite=1&period=week&date=today&wonderful=1 to pass values to the parameters of the method getExampleReport.

    Returning a value

    In an API method you can return any boolean, number, string or array value. A resource or an object cannot be returned unless it implements the DataTableInterface such as DataTable (the primary data structure used to store analytics data in Piwik), DataTable\Map (stores a set of DataTables) and DataTable\Simple (a DataTable where every row has two columns : label and value).

    Did you know ? You can choose the response format of your API request by appending a parameter &format=JSON|XML|CSV|... to the URL. Check out the Reporting API Reference for more information.

    Best practices

    Check user permissions

    Do not forget to check whether a user actually has permissions to access data or to perform an action. If you’re not familiar with Piwik’s permissions and how to check them read our User Permission guide.

    Keep API methods small

    At Piwik we aim to write clean code. Therefore, we recommend to keep API methods small (separation of concerns). An API pretty much acts like a Controller :

    1. public function createLdapUser($idSite, $login, $password)
    2. {
    3.     Piwik::checkUserHasAdminAccess($idSite);
    4.     $this->checkLogin($login);
    5.     $this->checkPassword($password);
    6.    
    7.     $myModel = new LdapModel();
    8.     $success = $myModel->createUser($idSite, $login, $password);
    9.    
    10.     return $success;
    11. }

    Télécharger

    This is not only easy to read, it will also allow you to create simple tests for LdapModel (without having to bootstrap the whole Piwik layer) and you will be able to reuse it in other places if needed.

    Calling APIs of other plugins

    For example if you want to fetch an existing report from another plugin, say a list of all Page URLs, do not request this report by calling that method directly :

    \Piwik\Plugins\Actions\API::getInstance()->getPageUrls($idSite, $period, $date);

    . Instead, issue a new API request :

    $report = \Piwik\API\Request::processRequest('Actions.getPageUrls', array(
       'idSite' => $idSite,
       'period' => $period,
       'date'   => $date,
    ));

    This has several advantages :

    • It avoids a fatal error if the requested plugin is not available on a Piwik installation
    • Other plugins can extend the called API method via events (adding additional report data to a report, doing additional permission checks) but those events will be only triggered when requesting the report as suggested
    • If the method parameters change, your request will most likely still work

    Publishing your Plugin on the Marketplace

    In case you want to share your API with other Piwik users you can do this by pushing your plugin to a public GitHub repository and creating a tag. Easy as that. Read more about how to distribute a plugin and best practices when publishing a plugin.

    Isn’t it easy to create a API ? We never even created a file ! If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.