Zoffix Znet > App-ZofCMS > App::ZofCMS::Plugin::YouTube

Download:
App-ZofCMS-1.001004.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.001004   Source  

NAME ^

App::ZofCMS::Plugin::YouTube - CRUD-type plugin to manage YouTube videos

SYNOPSIS ^

In your Main Config File or ZofCMS Template template:

    plugins => [ qw/YouTube/, ],

    plug_youtube => {
        dsn            => "DBI:mysql:database=test;host=localhost", # everything below is pretty much optional
        user            => '',
        pass            => '',
        opt             => { RaiseError => 1, AutoCommit => 1 },
        t_name          => 'plug_youtube',
        table           => 'videos',
        create_table    => 0,
        h_level         => 3,
        size            => 1,
        no_form         => 0,
        no_list         => 0,
        allow_edit      => 0,
        ua_args => [
            agent   => 'Opera 9.2',
            timeout => 30,
        ],
        filter          => {
            title       => qr/Foo/,
            description => qr/Bar/,
            link        => qr/234fd343/,
        },
    },

In your HTML::Template template:

    <h2>Post new video</h2>
    <tmpl_var name='plug_youtube_form'>

    <h2>Existing Videos</h2>
    <tmpl_var name='plug_youtube_list'>

DESCRIPTION ^

The module is a plugin for App::ZofCMS. It provides means to have a CRUD-like (Create, Read, Update, Delete) interface for managing YouTube videos. The plugin provides a form where a user can enter the title of the video, its YouTube URI and a description. That form is stored in a SQL database by the plugin and can be displayed as a list.

This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

^

When create_table option is turned on (see below) the plugin will create the following table where table_name is derived from table argument in plug_youtube (see below).

    CREATE TABLE table_name (
        title       TEXT,
        link        TEXT,
        description TEXT,
        embed       TEXT,
        time        VARCHAR(10),
        id          TEXT
    );

MAIN CONFIG FILE AND ZofCMS TEMPLATE FIRST-LEVEL KEYS ^

plugins

    plugins => [ qw/YouTube/ ],

Without saying it, you need to add the plugin in the list of plugins to execute.

plug_youtube

    plug_youtube => {
        dsn            => "DBI:mysql:database=test;host=localhost", # everything below is pretty much optional
        user            => '',
        pass            => '',
        opt             => { RaiseError => 1, AutoCommit => 1 },
        t_name          => 'plug_youtube',
        table           => 'videos',
        create_table    => 0,
        h_level         => 3,
        size            => 1,
        no_form         => 0,
        no_list         => 0,
        allow_edit      => 0,
        ua_args => [
            agent   => 'Opera 9.2',
            timeout => 30,
        ],
        filter          => {
            title       => qr/Foo/,
            description => qr/Bar/,
            link        => qr/234fd343/,
        },
    },

    plug_youtube => sub {
        my ( $t, $q, $config ) = @_;
        return {
            dsn => "DBI:mysql:database=test;host=localhost",
        }
    },

The plugin takes its config via plug_youtube first-level key that takes a hashref or a subref as a value and can be specified in either Main Config File or ZofCMS Template or both. or a subref as a value. If subref is specified, its return value will be assigned to plug_youtube as if it was already there. If sub returns an undef, then plugin will stop further processing. The @_ of the subref will contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and App::ZofCMS::Config object. If a certain key (does NOT apply to subrefs) in that hashref is set in both, Main Config File and ZofCMS Template, the value for that key that is set in ZofCMS Template will take precendence. The possible keys/values are as follows (virtually all are optional and have default values):

dsn

    dsn => "DBI:mysql:database=test;host=localhost",

Mandatory. Takes a scalar as a value which must contain a valid "$data_source" as explained in DBI's connect_cached() method (which plugin currently uses).

user

    user => '',

Optional. Takes a string as a value that specifies the user name to use when authorizing with the database. Defaults to: empty string

pass

    pass => '',

Optional. Takes a string as a value that specifies the password to use when authorizing with the database. Defaults to: empty string

opt

    opt => { RaiseError => 1, AutoCommit => 1 },

Optional. Takes a hashref as a value, this hashref contains additional DBI parameters to pass to connect_cached() DBI's method. Defaults to: { RaiseError => 1, AutoCommit => 1 }

table

    table => 'videos',

Optional. Takes a string as a value, specifies the name of the SQL table in which to store information about videos. Defaults to: videos

create_table

    create_table => 0,

Optional. When set to a true value, the plugin will automatically create needed SQL table, you can create it manually if you wish, see its format in USED SQL TABLE FORMAT section above. Generally you'd set this to a true value only once, at the start, and then you'd remove it because there is no "IF EXISTS" checks. Defaults to: 0

t_name

    t_name => 'plug_youtube',

Optional. Takes a string as a value. This string will be used as a "base name" for two keys that plugin generates in {t} special key. The keys are plug_youtube_list and plug_youtube_form (providing t_name is set to default) and are explained below in HTML::Template VARIABLES section below. Defaults to: plug_youtube

h_level

    h_level => 3,

Optional. When generating a list of YouTube videos, plugin will use HTML <h?> elements (see GENERATED HTML CODE section below). The h_level takes an integer between 1 and 6 and that value specifies what <h?> level to generate. Defaults to: 3 (generate <h3> elements)

size

    size => 1,
    # or
    size => [ 300, 200 ],

Optional. Takes either an integer from 0 to 3 or an arrayref with two elements that are positive intergers as a value. When the value is an arrayref the first element is treated as the value of width="" attribute and the second element is treated as the value for height="" attribute. These two control the size of the video. You can also use integers from 0 to 3 to specify a "prefabricated" size (sort'f like a shortcut). The relation between the integers and the sizes they represent is shown below. Defaults to: 1 ( size 425x344)

    0 => [ 320, 265 ],
    1 => [ 425, 344 ],
    2 => [ 480, 385 ],
    3 => [ 640, 505 ],

no_form

    no_form => 0,

Optional. Plugin generates an HTML form to input videos into the database, besides that, it also processes that form and makes sure everything is right. When no_form is set to a true value, the plugin will NOT generate the form and most importantly it will NOT process anything; so if you are making your own form for input, make sure to leave no_form as false. Defaults to: 0s

no_list

    no_list => 0,

Optional. Plugin automatically fetches all the available videos from the database and prepares an HTML list to present them. When no_list is set to a true value, plugin will not generate any lists. Defaults to: 0

allow_edit

    allow_edit => 0,

Optional. Applies only when both no_form and no_list are set to false values. Takes either true or false values. When set to a true value, plugin will add Edit and Delete buttons under every video with which the user will be able to (duh!) edit and delete videos. Defaults to: 0

Note: the "edit" is not that smart in this plugin, what actually happens is the video is deleted and its information is filled in the "entry" form. If the user never hits "Add" button on the form, the video will be lost; let me know if this creates a problem for you.

filter

    filter => {
        title       => qr/Foo/,
        description => qr/Bar/,
        link        => qr/234fd343/,
    },

Optional. You can set a filter when displaying the list of videos. The filter argument takes a hashref as a value. All keys take a regex (qr//) as a value. The field referenced by the key must match the regex in order for the video to be put in the list of videos. By default is not specified. You can specify either 1 or all 3 keys. Possible keys and what they reference are as follows:

title

    filter => {
        title => qr/Foo/,
    },

Optional. The title key's regex matches the titles of the videos.

description

    filter => {
        description => qr/Bar/,
    },

Optional. The description key's regex matches the descriptions of the videos.

link

    filter => {
        link => qr/234fd343/,
    },

Optional. The link key's regex matches the links of the videos.

ua_args

    ua_args => [
        agent   => 'Opera 9.2',
        timeout => 30,
    ],

Optional. Under the hood plugin uses LWP::UserAgent to access YouTube for fetching the "embed" code for the videos. The ua_args takes an arrayref as a value. This arrayref will be directly derefrenced into LWP::UserAgent's constructor (new() method). See LWP::UserAgent for possible options. Defaults to: [ agent => 'Opera 9.2', timeout => 30, ]

HTML::Template VARIABLES ^

The plugin generates two keys in {t} ZofCMS Template special key, thus making them available for use in your HTML::Template templates. Assuming t_name is left at its default value the following are the names of those two keys:

plug_youtube_form

    <tmpl_var name='plug_youtube_form'>

This variable will contain HTML form generated by the plugin, the form also includes display of errors.

plug_youtube_list

    <tmpl_var name='plug_youtube_list'>

This variable will contain the list of videos generated by the plugin.

GENERATED HTML CODE ^

form

    <form action="" method="POST" id="plug_youtube_form">

    <div>
        <p class="error">Incorrect YouTube link
        <input type="hidden" name="page" value="videos">
        <input type="hidden" name="dir" value="/admin/">
        <ul>
            <li>
                <label for="plug_youtube_title">Title: </label
                ><input type="text" id="plug_youtube_title" name="plug_youtube_title" value="xxx">
            </li>
            <li>

                <label for="plug_youtube_link">Link: </label
                ><input type="text" id="plug_youtube_link" name="plug_youtube_link" value="">
            </li>
            <li>
                <label for="plug_youtube_description">Description: </label
                ><textarea id="plug_youtube_description" name="plug_youtube_description" cols="60" rows="10"></textarea>
            </li>
        </ul>
        <input type="submit" name="plug_youtube_submit" value="Add">
    </div>
    </form>

list

Note: the <form> will not be there if allow_edit option is set to a false value.

    <ul id="plug_youtube_list">
        <li>
            <h3><a href="http://www.youtube.com/watch?v=RvcaNIwtkfI">Some club</a></h3>
            <p class="plug_youtube_time">Posted on: Wed Dec 10 21:14:01 2008</p>
            <div class="plug_youtube_video"><object width="200" height="165"><param name="movie" value="http://www.youtube.com/v/RvcaNIwtkfI&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RvcaNIwtkfI&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="165"></embed></object></div>
            <p class="plug_youtube_description">Description</p>
                <form action="" method="POST">
                <div>
                    <input type="hidden" name="plug_youtube_vid_edit_id" value="03716801501150291228961641000660045686842636">
                    <input type="hidden" name="page" value="videos">
                    <input type="hidden" name="dir" value="/admin/">
                    <input type="submit" class="submit_button_edit" name="plug_youtube_vid_edit_action" value="Edit">
                    <input type="submit" class="submit_button_delete" name="plug_youtube_vid_edit_action" value="Delete">
                </div>
                </form>
        </li>
        <li class="alt">
            <h3><a href="http://www.youtube.com/watch?v=RvcaNIwtkfI">Some club</a></h3>
            <p class="plug_youtube_time">Posted on: Wed Dec 10 21:13:30 2008</p>
            <div class="plug_youtube_video"><object width="200" height="165"><param name="movie" value="http://www.youtube.com/v/RvcaNIwtkfI&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RvcaNIwtkfI&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="200" height="165"></embed></object></div>
            <p class="plug_youtube_description">Description</p>
                <form action="" method="POST">
                <div>
                    <input type="hidden" name="plug_youtube_vid_edit_id" value="051156628115950712289616100613964522347914">
                    <input type="hidden" name="page" value="videos">
                    <input type="hidden" name="dir" value="/admin/">
                    <input type="submit" class="submit_button_edit" name="plug_youtube_vid_edit_action" value="Edit">
                    <input type="submit" class="submit_button_delete" name="plug_youtube_vid_edit_action" value="Delete">
                </div>
                </form>
        </li>
    </ul>

REPOSITORY ^

Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS

BUGS ^

To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues

If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org

AUTHOR ^

Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)

LICENSE ^

You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.

syntax highlighting: