60 $this->AutoMarkup =
get_package(
'page::auto_markup' ,
'last' , __FILE__ );
61 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
62 $this->Link =
get_package(
'link' ,
'last' , __FILE__ );
63 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
64 $this->SecurityParser =
get_package(
'security::security_parser' ,
'last' , __FILE__ );
65 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
66 $this->SubscriptionAccess =
get_package(
'subscription::subscription_access' ,
'last' , __FILE__ );
67 $this->UserAlgorithms =
get_package(
'user::user_algorithms' ,
'last' , __FILE__ );
105 $Code = $this->CachedMultyFS->get_template( __FILE__ ,
get_field( $Subscription ,
'template' ).
'.tpl' );
108 $Code = $this->String->print_record( $Code , $User );
110 $Subscription =
set_field( $Subscription ,
'subscription_id' ,
get_field( $Subscription ,
'id' ) );
111 $Code = $this->String->print_record( $Code , $Subscription );
113 $Code = $this->AutoMarkup->compile_string( $Code );
117 catch( Exception $e )
153 $UserId = $this->Security->get( $UserId ,
'integer' );
154 $SubscriptionId = $this->Security->get( $SubscriptionId ,
'integer' );
156 $Link = $this->Link->get_links( $UserId , $SubscriptionId ,
'user' ,
'subscription' );
158 if( isset(
$Link[ 0 ] ) )
161 return( md5(
"$UserId.$LinkId" ) );
166 catch( Exception $e )
198 $UserId = $this->Security->get( $UserId ,
'integer' );
199 $Hash = $this->Security->get( $Hash ,
'string' );
201 $Subscriptions = $this->SubscriptionAccess->get_subscriptions_for_user( $UserId );
203 foreach( $Subscriptions as $i => $Subscription )
205 $SubscriptionId =
get_field( $Subscription ,
'id' );
209 $this->SubscriptionAccess->unsubscribe_user( $UserId , $SubscriptionId );
214 catch( Exception $e )
250 $UserId = $this->Security->get( $UserId ,
'integer' );
251 $SubscriptionId = $this->Security->get( $SubscriptionId ,
'integer' );
253 $Links = $this->Link->get_links( $UserId , $SubscriptionId ,
'user' ,
'subscription' );
255 return( isset( $Links[ 0 ] ) );
257 catch( Exception $e )
289 $id = $this->Security->get( $id ,
'integer' );
291 $Subscriptions = $this->SubscriptionAccess->unsafe_select(
292 $this->SubscriptionAccess->NativeTable.
".id = $id"
295 if( count( $Subscriptions ) === 0 || count( $Subscriptions ) > 1 )
297 throw(
new Exception(
'Subscription with id '.$id.
' was not found' ) );
301 return( $Subscriptions[ 0 ] );
304 catch( Exception $e )
340 private function get_subscription_parameters( $Subscription , $From , $Sender )
345 $Settings->load_package_settings(
346 'subscription::subscription_algorithms' ,
'last' ,
'cf_'.
get_field( $Subscription ,
'template' )
348 $From = $Settings->get_setting(
'email' , $From );
349 $Subject = $Settings->get_setting(
'subject' ,
'Subscription' );
350 $Sender = $Settings->get_setting(
'email_sender' , $Sender );
352 return( array( $From , $Subject , $Sender ) );
354 catch( Exception $e )
382 private function get_email_parameters( $Subscription )
387 $SiteSettings->load_package_settings(
'page::page_composer' ,
'last' ,
'cf_site' );
388 $Sender = $SiteSettings->get_setting(
'email_sender' ,
'System' );
389 $From = $SiteSettings->get_setting(
'system_email' ,
'ultimix@localhost' );
391 return( $this->get_subscription_parameters( $Subscription , $From , $Sender ) );
393 catch( Exception $e )
425 private function send_email( $EmailAddress , $Message , $Subscription )
429 $Email =
get_package(
'mail' ,
'last' , __FILE__ );
431 list( $From , $Subject , $Sender ) = $this->get_email_parameters( $Subscription );
433 $Email->send_email( $From , $EmailAddress , $Subject , $Message , $Sender );
435 catch( Exception $e )
467 $UserId = $this->Security->get( $UserId ,
'integer' );
468 $SubscriptionId = $this->Security->get( $SubscriptionId ,
'integer' );
472 $User = $this->UserAlgorithms->get_by_id( $UserId );
473 $Subscription = $this->
get_by_id( $SubscriptionId );
477 $this->send_email(
get_field( $User ,
'email' ) , $Message , $Subscription );
480 catch( Exception $e )