Posts Tagged ‘cchost’

RSS reader in PHP, compatible with ccHost 4.5

diumenge, març 8th, 2009

Here a plugin for ccHost 4.5 or 5 to get RSS feeds and show them on your cchost_files/*.xml . It may be used out of ccHost without problems. Written in PHP5. License GPL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function getRSS($feed, $limit = 3) {
    // $feed must be a valid RSS url.
    // the function will return an array with the basic information for our news.
    // print_r($RSSData); for further information.
    // License: GPL  - Eduard Gamonal <edu at eduard-gamonal dot net>
 
    $feedData = file_get_contents($feed);
    $RSSData = new SimpleXMLElement($feedData);
 
    $news = array();
 
    $c = count($RSSData->channel->item);
    for ($i = 0; $i < $limit  and $i < $c; $i++) {
        $news[$i]['title'] = (string)$RSSData->channel->item[$i]->title;
        $news[$i]['link'] = (string)$RSSData->channel->item[$i]->link;
        $news[$i]['pubDate'] = (string)$RSSData->channel->item[$i]->pubDate;
        $news[$i]['description'] = (string)$RSSData->channel->item[$i]->description;
    }
 
    return $news;
}
?>

ccHost 4.5: Moderation control panel

diumenge, març 8th, 2009

When I started developing MusicaLliure.cat with ccHost 4.5, we needed a moderation control panel. It’s not used any more, since we coded a «flag it!» system to avoid having someone approving every new uploaded song.
Anyway, here it is the code, in case someone finds it useful. Notice that your moderators should have permission to publish/unpublish content, but not your users, obviously.
The css is *in* the file, but just feel free to put it in a separate file, as I like.

How does it look like? The moderator sees the queue. For each song, the title, author, a player and two buttons are shown. If the moderator clicks on the title or the author, a search is performed (Google).

As usual, you have to place the code below in local_files/viewfile, and the php part in local_files/lib/

License: GPL

<div>
 
<tal:block define="pendents php:cancons_pendents_de_moderacio()" /> 
<tal:block define="blocades php:cancons_blocades()" /> 
 
<style type="text/css">
 
.cpm {
    margin:15px auto 15px auto;
}
 
.cpm td{
    padding:5px;
    border:1px solid silver;
 
}
 
.cpm td#cpm_aprovala {
    background-color:green;
}
 
.cpm td#cpm_blocala {
    background-color:#cc0000;
}
 
#cpm_aprovala a, #cpm_blocala a {
    color:white;
    font-weight:bold;
}
 
#cpm_aprovala a:hover, #cpm_blocala  a:hover {
    color:silver;
}
 
.cpm td#cpm_idfitxer {
    text-align:center;
}
 
.cpm caption {
    font-size:1.2em;
    font-weight:bold;
}
 
</style>
<h2>Cançons pendents de moderació</h2>
<p><b>Autors</b>: per motius d&#39;etiqueta i educaci&oacute;, com per exemple evitar enviar els administradors a pres&oacute;, MusicaLliure.cat disposa d&#39;un equip de moderaci&oacute; que escolta i comprova que les can&ccedil;ons tinguin la llic&egrave;ncia adequada. Aqu&iacute; nom&eacute;s podeu veure les vostres, tot i que n&#39;hi pot haver m&eacute;s.</p>
<p><b>Moderadors</b>: cal escoltar total o parcialment la can&ccedil;&oacute; abans d&#39;aprovar-la. Si detecteu que incompleix els requisits de MusicaLliure.cat, bloqueu-la. Si ho dubteu, podeu fer clic al t&iacute;tol o al nom de l&#39;autor per fer-ne una cerca al Google. Nom&eacute;s quan estigueu segurs que la can&ccedil;&oacute; pot ser publicada, aproveu-la. Si us equivoqueu, que no us entri el p&agrave;nic. A la p&agrave;gina de la can&ccedil;&oacute; trobareu com blocar-la o despublicar-la.</p>
 
 
<table class="cpm">
<caption>Can&ccedil;ons pendents de moderaci&oacute;</caption>
<thead>
    <th>ID fitxer</th>
    <th>T&iacute;tol</th>
    <th>Autor</th>
    <th>Reproductor</th>
    <th>Penja-la</th>
    <th>Bloca-la</th>
</thead>
<tr tal:repeat="record pendents">
    <td id="cpm_idfitxer">
        <a href="http://beta.musicalliure.net/media/files/${record/user_name}/${record/upload_id}">${record/files/0/file_id}</a>
    </td>
 
    <td>
         <a href="http://www.google.com/search?hl=ca&q=%22${record/upload_name}%22">${record/upload_name}</a>
    </td>
 
    <td>        
        <a href="http://www.google.com/search?hl=ca&q=%22${record/user_real_name}%22">${record/user_real_name}</a>
    </td>
 
    <td>
        <object type="application/x-shockwave-flash" width="200" height="20" data="http://beta.musicalliure.net/cclib/xspf_player/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}">
        <param name="movie" value="http://beta.musicalliure.net/cclib/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}" />
        </object>
    </td>
 
    <td id="cpm_aprovala">
        <a href="http://beta.musicalliure.net/media/files/publish/${record/user_name}/${record/upload_id}">Aprova-la</a>
    </td>
 
    <td id="cpm_blocala">
        <a href="http://beta.musicalliure.net/media/admin/ban/${record/upload_id}">Bloca-la</a>
    </td>
 
</tr>
</table>
 
 
<table class="cpm">
<caption>Can&ccedil;ons blocades</caption>
<thead>
 
 
    <th>ID fitxer</th>
    <th>T&iacute;tol</th>
    <th>Autor</th>
    <th>Reproductor</th>
    <th>Desbloca-la</th>
</thead>
<tr tal:repeat="record blocades">
    <td id="cpm_idfitxer">
        <a href="http://beta.musicalliure.net/media/files/${record/user_name}/${record/upload_id}">${record/files/0/file_id}</a>
    </td>
 
    <td>
         <a href="http://www.google.com/search?hl=ca&q=%22${record/upload_name}%22">${record/upload_name}</a>
    </td>
 
    <td>        
        <a href="http://www.google.com/search?hl=ca&q=%22${record/user_real_name}%22">${record/user_real_name}</a>
    </td>
 
    <td>
        <object type="application/x-shockwave-flash" width="200" height="20" data="http://beta.musicalliure.net/cclib/xspf_player/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}">
        <param name="movie" value="http://beta.musicalliure.net/cclib/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}" />
        </object>
    </td>
 
    <td id="cpm_aprovala">
        <a href="http://beta.musicalliure.net/media/admin/ban/${record/upload_id}">Desbloca-la</a>
    </td>
 
</tr>
</table>
</div>

And here the cool and easy part:

<?php
    function cancons_pendents_de_moderacio() {
        //
        // retorna les cançons pendents de moderació
        //
 
        $c =& CCUploads::GetTable();
        $c->AddJoin( new CCFiles(), 'upload_id');
        $c->AddJoin( new CCUsers(), 'upload_user');    
 
        $c->SetOrder('upload_date','DESC');
 
        return $c->GetRecords('upload_published = 0 and upload_banned = 0');
 
    }
 
    function cancons_blocades() {
        //
        // Retorna les cançons blocades
        //
 
        $c =& CCUploads::GetTable();
        $c->AddJoin( new CCFiles(), 'upload_id');
        $c->AddJoin( new CCUsers(), 'upload_user');    
 
        $c->SetOrder('upload_date','DESC');
 
        return $c->GetRecords('upload_banned = 1');
    }
?>

How to use CCTable in ccHost 4.5

diumenge, març 8th, 2009

How to use the class CCTable to get what we want:

<?php
    function get_latest_songs() {
        //
        //
 
        $s =& CCUploads::GetTable();
        $s->SetOffsetAndLimit(0,10);
        $s->SetOrder('upload_id','DESC');
        $s->AddJoin(new CCUsers(), 'upload_user');
 
        return $s->GetRecords('upload_published = 1 and upload_banned = 0');
    }
?>

License: GPL

ccHost 4.5 plugin: count downloads by user

diumenge, març 8th, 2009

There are some useful scripts that aren’t, by default, in cchost 4.5 package. I wrote this one for MusicaLliure.cat. It returns how many songs have been downloaded for a given user.

License: GPL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
    function count_downloads_by_user($uid) {
    //
    // how many songs by user $uid have been downloaded?
    //
 
    $uploads =& CCUploads::GetTable();
    $where = "upload_user = '".$uid."'";
    // it counts downloads for unpublished songs, too.
    // init: not published -> 0 downloads.
    // if later on it's unpublished (and not deleted), we still take
    // its downloads into account.
 
    $records =& $uploads->GetRecords($where);
    $count = count($records);
    $sumdownloads = 0;
    for ($i = 0; $i < $count; $i++) {
 
        $files =& $records[$i]['files'];
 
        $fcount = count($files);
        for ($n = 0; $n < $fcount; $n++) {
            $file =& $files[$n];
            $sumdownloads += $file['file_num_download'];
        }
    }
 
    return $sumdownloads;
 
    }
?>

ccHost plugin: RSS feeds reader

divendres, setembre 5th, 2008

Developing MusicaLliure.net I created a plugin to get and show RSS feeds.

It’s PHP5, it works with ccHost 4.5 or 5. Not tested in previous versions.

License GPL 2 or later.

Download ccHost plugin: RSS feeds reader

You shall place this extra in cchost_files/lib. In  viewfile/*.xml you may include these lines:

<tal:block define=”news
php:getRSS(‘http://www.musicalliure.net/bloc/feed/‘, 2)” />

<ul class=”home_news”>
<li tal:repeat=”item news”><h4><a href=”${item/link}”>${item/title}</a></h4> ${item/pubDate}<br
/>${item/description}</li>
</ul>

Entra