function onPublish($attribute, $contentObject, $publishedNodes)
 {
     $http = eZHTTPTool::instance();
     $userID = $attribute->attribute('contentobject_id');
     $data = unserialize($attribute->attribute('data_text'));
     $avialable = array_merge($data['unregister'], $data['register']);
     foreach ($avialable as $id) {
         $subscription = eZSubscription::fetchByUserSubscriptionListID($userID, $id);
         if (isset($subscription) and $subscription->attribute('status') == eZSubscription::StatusApproved and in_array($id, $data['unregister'])) {
             $subscription->unsubscribe();
         } elseif (isset($subscription) and $subscription->attribute('status') == eZSubscription::StatusRemovedSelf and in_array($id, $data['register'])) {
             $subscription->setAttribute('status', eZSubscription::StatusApproved);
             $subscription->sync();
         } elseif (!isset($subscription) and in_array($id, $data['register'])) {
             $list = eZSubscriptionList::fetch($id, eZSubscriptionList::StatusPublished, true, true);
             if ($list) {
                 $subscription = $list->registerUser($userID);
             }
         }
         if ($subscription) {
             $version = eZContentObjectVersion::fetchVersion($attribute->attribute('version'), $attribute->attribute('contentobject_id'));
             $user = eZUser::fetch($attribute->attribute('contentobject_id'));
             $userData = eZUserSubscriptionData::fetch($user->attribute('email'));
             $dm = $version->attribute('data_map');
             if (!$userData) {
                 $userData = eZUserSubscriptionData::create('', '', '', $user->attribute('email'));
             }
             if ($user->attribute('email')) {
                 $userData->updateAttribute('email', $user->attribute('email'));
                 $userData->store();
             }
             if (isset($dm['last_name'])) {
                 $userData->setAttribute('name', $dm['last_name']->attribute('data_text'));
                 $userData->store();
             }
             if (isset($dm['first_name'])) {
                 $userData->setAttribute('firstname', $dm['first_name']->attribute('data_text'));
                 $userData->store();
             }
             if (isset($dm['mobile'])) {
                 $userData->setAttribute('mobile', $dm['mobile']->attribute('data_text'));
                 $userData->store();
             }
         }
     }
     $http->removeSessionVariable('register_subscription');
     $http->removeSessionVariable('unregister_subscription');
 }
$res->setKeys(array(array('newsletter_view', 'register_subscription')));
if (!$subscriptionList) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$user = false;
$currentUser = eZUser::currentUser();
if ($currentUser->isLoggedIn()) {
    $user = $currentUser;
}
$warning = false;
$firstname = '';
$name = '';
$email = '';
if ($http->hasPostVariable('StoreButton')) {
    if ($user) {
        $subscription = eZSubscription::fetchByUserSubscriptionListID($user->attribute('contentobject_id'), $subscriptionList->attribute('id'));
        if (is_object($subscription) and $subscription->attribute('status') != eZSubscription::StatusRemovedSelf) {
            $warning = ezi18n('eznewsletter/register_subscription', 'You are already a registered subscriber');
        } elseif (is_object($subscription) and $subscription->attribute('status') == eZSubscription::StatusRemovedSelf) {
            $subscription->setAttribute('status', eZSubscription::StatusApproved);
            $subscription->store();
            $warning = ezi18n('eznewsletter/register_subscription', 'You have renewed your subscription.');
        } else {
            $subscription = $subscriptionList->registerUser($user->attribute('contentobject_id'));
            // stevo
            if ($subscription && $http->hasPostVariable('OutputFormat')) {
                $format = $http->postVariable('OutputFormat');
                eZDebug::writeNotice($http->postVariable('OutputFormat'));
                if (is_array($format)) {
                    $format = implode(',', $format);
                }
 function userExists($userID)
 {
     $subscription = eZSubscription::fetchByUserSubscriptionListID($userID, $this->attribute('id'));
     if ($subscription) {
         return true;
     }
     return false;
 }