<?php
# Copyright (C) 2007 Youri Berret <mxondebian@free.fr>
#  
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 only.
#  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
## /LICENSE
###########
#
#
#  v 0.1 Youri Berret - Fri Nov 28 13:34:45 CET 2008
#
#TODO : 
#
#

#Definition de la classe
#
# nom débutant par une minuscule => variable
# nom débutant par une majuscule => Fonction
#
###################################################
# début de la définition de la classe presencePEP #
###################################################

class presencePEP
{
#Définition des variables principales
        private $defaultImage = 'defaultAvatar.png';
        # Omnipresence URL
        #PEP
        private $mssgInd = 'n/a';
##

#construit l'objet en analysant (parse) le fichier xml
function __construct($jid,$omniURL,$lang)
{
        $jid_hash = md5($jid);
        $this->url_jid_hash = $omniURL . $jid_hash;
        $this->lang=$lang;

        #Avatar
        $this->avatar="avatar";
        $this->avatarExt=".png";

        #PEP
        $omniPEP = $this->url_jid_hash . "/pep";
                #Music
                $omniPEPMuse = $omniPEP . '/tune';
                $this->omniPEPMuseAll = $omniPEPMuse . ".txt";
                $this->omniPEPMuseArtist = $omniPEPMuse . "/artist.txt";
                $this->omniPEPMuseSong = $omniPEPMuse . "/song.txt";
                #Mood
                $this->omniPEPMoodImage = $omniPEP . "/mood/image.png";
                $this->omniPEPMoodAll = $omniPEP . "/mood-" . $lang . ".txt";
                #Activity
                $this->omniPEPActiAll = $omniPEP . "/activity-" . $this->lang . ".txt";
                $this->omniPEPActiImage = $omniPEP . "/activity/image.png";

        #echo "$jid \n $omniURL \n $url_jid_hash \n\n$omniPEPActiImage\n";
}
 #fin constructeur

 #destructeur de l'objet
 #
 #function __destruct()
 #{
 #unset($xml);
 #}
 #fin destructeur de l'objet

##########################
#Fin des Fonction privée #
##########################

####################
#Fonction publique #
####################
# PEP
public function Muse($w)
{#return text
switch ($w) {
case "all":
        $museAll = @file_get_contents( $this->omniPEPMuseAll );
        echo empty($museAll) ? $this->mssgInd : $museAll;
        #echo $this->omniPEPMuseAll ;
        break;
case "artist":
        $museArtist = @file_get_contents( $this->omniPEPMuseArtist );
        echo empty($museArtist) ? $this->mssgInd : $museArtist;
        break;
case "song":
        $museSong = @file_get_contents( $this->omniPEPMuseSong );
        echo empty($museSong) ? $this->mssgInd : $museSong;
        break;
default:
        $museArtist = @file_get_contents( $this->omniPEPMuseArtist );
        echo empty($museArtist) ? $this->mssgInd : $museArtist;
        }
}
public function MoodImage()
{#return text (URL)
echo $this->omniPEPMoodImage;
}
public function MoodAll()
{#return text
$moodAll = @file_get_contents( $this->omniPEPMoodAll );
echo empty($moodAll) ? $this->mssgInd : $moodAll;
}
# PEP/Act
public function ActImage()
{#return text (URL)
echo $this->omniPEPActiImage;
}
public function ActAll()
{#return text
$actiAll = @file_get_contents( $this->omniPEPActiAll );
echo empty($actiAll) ? $this->mssgInd : $actiAll;
#echo $this->omniPEPActiAll;
}
# End PEP

# Avatar
public function Avatar($size)
{
        if ( $size == "96" xor $size == "80" xor $size == "64" xor $size == "32")
         {
         $urlAvatar = $this->url_jid_hash . "/" . $this->avatar . "-" . $size . $this->avatarExt;
         echo $urlAvatar;
         }else
         {
         $urlAvatar = $this->url_jid_hash . "/" . $this->avatar . $this->avatarExt;
         echo $urlAvatar;
         };
}
# END Avatar

# Status
public function StatusIm($theme)
{
        if ( $theme == "" or $theme == "default" or $theme == "crystal" )
        {
        $urlStatusIm = $this->url_jid_hash . "/" . "image-default.png";
        echo $urlStatusIm;
        }
        elseif ( $theme == "stellar" xor theme == "adiumy" xor $theme == "dcraven" xor $theme == "jabberlogo"  )
        {
        $urlStatusIm = $this->url_jid_hash . "/" . "image-" . $theme . ".png";
        echo $urlStatusIm;
        };
}
public function Status($w )
{
switch ($w) {
case "status":
        $urlStatusTxt = $this->url_jid_hash . "/text-" . $this->lang . ".txt";
        $statusTxt = @file_get_contents( $urlStatusTxt );
        echo empty($statusTxt) ? $this->mssgInd : $statusTxt;
        break;
case "message":
        $urlStatusMess =  $this->url_jid_hash . "/message.txt";
        $statusMess = @file_get_contents( $urlStatusMess );
        echo empty($statusMess) ? $this->mssgInd : $statusMess;
        break;
default:
        $urlStatusTxt = $this->url_jid_hash . "/text-" . $this->lang . ".txt";
        $statusTxt = @file_get_contents( $urlStatusTxt );
        echo empty($statusTxt) ? $this->mssgInd : $statusTxt;
        break;
        }
}
# END Status

#################################################
# Fin de la définition de la classe presencePEP #
#################################################
}
#########
# EXAMPLE
#########
# Variables
# Tune these two varaibles to your own settings
        # Your Jabber Identifier
        #$jabberID = "calico.jeff@im.apinc.org";
        # Omnipresence URL (use http://presence.jabberfr.org/ if you don't have one)
        #$url_omnipresence = "http://presence.jabberfr.org/";
        # Language  <fr|en>
        #$lang = "en";

#Create object
#$presObj = new presencePEP($jabberID,$url_omnipresence,$lang);

#$presObj->Muse("artist");      # all|artist|song
#$presObj->MoodImage();         # return URL to Mood Image
#$presObj->MoodAll();
#$presObj->Avatar("");          # return URL to your Avatar Image
#$presObj->StatusIm("dcraven");
#$presObj->Status("status");    # status|message
?>