diff --git a/classes/SubscriberService.php b/classes/SubscriberService.php index c77c485..8de9258 100644 --- a/classes/SubscriberService.php +++ b/classes/SubscriberService.php @@ -9,19 +9,22 @@ trait SubscriberService /** * Handles subscriber registration * either by registration in the frontend or by creating in the backend + * * @param $subscriber - * @param $listOfCategoryIds array of subscribing Ids + * @param $listOfCategoryIds array of subscribing ids * @return void */ - public function onSubscriberRegister($subscriber, $listOfCategoryIds = []) + public function onSubscriberRegister($subscriber, $listOfCategoryIds) { // Register category - foreach ($listOfCategoryIds as $category) { - if (is_numeric($category) && Categories::where(['id' => $category, 'hidden' => 2])->count() == 1 && Db::table('indikator_news_relations')->where(['subscriber_id' => $subscriber->id, 'categories_id' => $category])->count() == 0) { - Db::table('indikator_news_relations')->insertGetId([ - 'subscriber_id' => $subscriber->id, - 'categories_id' => $category - ]); + if (is_array($listOfCategoryIds)) { + foreach ($listOfCategoryIds as $category) { + if (is_numeric($category) && Categories::where(['id' => $category, 'hidden' => 2])->count() == 1 && Db::table('indikator_news_relations')->where(['subscriber_id' => $subscriber->id, 'categories_id' => $category])->count() == 0) { + Db::table('indikator_news_relations')->insertGetId([ + 'subscriber_id' => $subscriber->id, + 'categories_id' => $category + ]); + } } } diff --git a/components/Post.php b/components/Post.php index c1f74da..51dcdb0 100644 --- a/components/Post.php +++ b/components/Post.php @@ -76,7 +76,7 @@ protected function loadPost() $this->page->meta_image_src = $post->image; // Create keyword list, from category name and tag list. - $post_keywords = $post->category->name.', '; + $post_keywords = isset($post->category->name) ? $post->category->name.', ' : ''; foreach ($post->tags as $key => $tag) { $post_keywords .= $tag; if ($key != (count($post->tags) - 1)) { diff --git a/components/Subscribe.php b/components/Subscribe.php index 2993447..ea46229 100644 --- a/components/Subscribe.php +++ b/components/Subscribe.php @@ -42,9 +42,8 @@ public function onSubscription() // Validate input data $rules = [ - 'name' => 'required|between:2,64', - 'email' => 'required|email|between:8,64', - 'category' => 'array' + 'name' => 'required|between:2,64', + 'email' => 'required|email|between:8,64' ]; $validation = Validator::make($data, $rules); @@ -52,11 +51,12 @@ public function onSubscription() throw new ValidationException($validation); } - $email = post('email'); + // Get input data $name = post('name'); + $email = post('email'); $categories = post('category', []); - // looking for existing subscriber + // Looking for existing subscriber $subscriberResult = Subscribers::email($email); if ($subscriberResult->count() > 0) { @@ -64,17 +64,17 @@ public function onSubscription() // Update the name $subscriber->name = $name; } + // Register new one else { - // Register new one $subscriber = Subscribers::create([ 'name' => $name, 'email' => $email, - 'common' => '', + 'comment' => '', 'locale' => App::getLocale(), 'created' => 2, 'statistics' => 0, - 'created_at' => date('Y-m-d H:i:s'), - 'updated_at' => date('Y-m-d H:i:s'), + 'created_at' => now(), + 'updated_at' => now(), 'registered_at' => now(), 'registered_ip' => Request::ip(), 'status' => 3 diff --git a/components/subscribe/default.htm b/components/subscribe/default.htm index 9f80a47..10d10a4 100644 --- a/components/subscribe/default.htm +++ b/components/subscribe/default.htm @@ -1,4 +1,4 @@ -