getRouteName(); if (Drupal::moduleHandler()->moduleExists('zoho_custom_alter_changes')) { $site_path = \Drupal::service('site.path'); // $libraries['custom_drupalSettings'] = array // ( // 'js' => array // ( // 'https://zdblogs.zohocorp.com/themes/gin/custom/js/zdblogs-drupalSettingsLoader.js' => array() // ), // ); // $common_files_array['files'] = array( // 'header' => true, // 'css' => array // ( // 'theme' => array // ( // 'https://www.zohowebstatic.com/sites/all/themes/zoho/css/global.css' => array('group' => 100), // ) // ), // 'js' => array // ( // 'https://www.zohowebstatic.com/sites/all/themes/zoho/scripts/var_init.js' => array('group' => 100) // ) // ); // if(isset($common_files_array['files'])) // { // $libraries['common_files'] = $common_files_array['files']; // } $libraries['core_files'] = array ( 'js' => array ( 'https://blog.zoho.com/core/assets/vendor/jquery/jquery.min.js' => array(), 'https://blog.zoho.com/core/misc/drupalSettingsLoader.js' => array(), 'https://blog.zoho.com/core/misc/drupal.js' => array(), 'https://blog.zoho.com/core/misc/drupal.init.js' => array() ) ); $libraries['node_view_counter'] = array ( 'js' => array ( 'https://blog.zoho.com/core/modules/statistics/statistics.js' => array(), 'https://blog.zoho.com/modules/contrib/nodeviewcount/nodeviewcount.js' => array() ) ); $custom_theme_library_array['files'] = array( 'css' => array ( 'theme' => array ( 'https://blog.zoho.com/sites/zblogs/theme/css/style.min.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/blocks.style.build.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/global-styles-inline.css' => array(), // 'https://blog.zoho.com/sites/zblogs/theme/css/dashicons.min.css' => array(), // 'https://blog.zoho.com/sites/zblogs/theme/css/frontend.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/pagenavi-css.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/bootstrap.min.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/font-awesome.min.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/style.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/style_login_widget.css' => array() ) ) ); if(isset($custom_theme_library_array['files'])) { $libraries['custom_theme_library'] = $custom_theme_library_array['files']; } $login_page_library_array['files'] = array( 'css' => array ( 'theme' => array ( 'https://www.zohowebstatic.com/sites/all/themes/zoho/css/global.css' => array(), 'https://blog.zoho.com/sites/zblogs/theme/css/font-awesome.min.css' => array(), 'https://css.zohostatic.in/iam/M_3240134/components/css/signin.css' => array(), 'https://blog.zoho.com/sites/zblogs/common/css/login-page.css' => array() ) ), 'js' => array ( 'https://blog.zoho.com/sites/zblogs/common/js/login-page.js' => array(), ) ); if(isset($login_page_library_array['files'])) { $libraries['login_page_library'] = $login_page_library_array['files']; } $footer_section_array['files'] = array( 'css' => array ( 'theme' => array ( 'https://blog.zoho.com/sites/zblogs/common/css/zohodblogs.css' => array(), ) ), 'js' => array ( 'https://blog.zoho.com/sites/zblogs/theme/js/emoji-release.min.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/mpp-frontend.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/skip-link-focus-fix.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/bootstrap.min.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/comment-reply.min.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/main.js' => array(), 'https://blog.zoho.com/sites/zblogs/theme/js/akismet-frontend.js' => array(), 'https://www.zohowebstatic.com/sites/default/files/js/zcms.js' => array(), 'https://www.zohowebstatic.com/sites/all/themes/zoho/scripts/zohocustom.js' => array(), 'https://blog.zoho.com/sites/zblogs/common/js/zohodblogs.js' => array(), ) ); if(isset($footer_section_array['files'])) { $libraries['footer_section'] = $footer_section_array['files']; } $libraries['custom_admin'] = array ( 'css' => array ( 'theme' => array ( 'https://blog.zoho.com/sites/zblogs/admin/css/zblogsadmin.css' => array(), ) ), 'js' => array ( 'https://blog.zoho.com/sites/zblogs/admin/js/zblogsadmin.js' => array() ), ); } \Drupal::moduleHandler()->alter('zoho_custom_alter_changes_library_info_build', $libraries); return $libraries; } function zoho_custom_alter_changes_group_node_details() { $group_details = array(); $group_details['local_home_path'] = ''; $group_details['live_home_path'] = '/blog'; $group_details['local_domain'] = 'https://blog.zoho.com'; $group_details['live_domain'] = 'https://www.zoho.com'; $group_details['default_post_count'] = 20; return $group_details; } /** * Implements hook_menu_local_tasks_alter(). */ function zoho_custom_alter_changes_menu_local_tasks_alter(&$data, $route_name) { if($route_name == 'user.login' && isset($data['tabs'][0])) { // Remove all tabs from user login form. foreach ($data['tabs'][0] as $key => $tab){ if($key != 'user.login') { $data['tabs'][0][$key]['#access'] = FALSE; } } } } // function zoho_custom_alter_changes_user_login($account) // { // // We want to redirect user on login. // $local_home_path = \Drupal::service('site.path'); // if(strpos($local_home_path, 'sites/default') !== false) // { // $local_home_path = ''; // } // else // { // $search = 'sites'; // $search = '/'.preg_quote($search, '/').'/'; // $local_home_path = preg_replace($search, '', $local_home_path, 1); // } // $redirect = new RedirectResponse(Url::fromUserInput('/admin/group')->toString()); // $redirect->send(); // exit; // // return $response = new RedirectResponse($local_home_path."/_a/content"); // } function zoho_custom_alter_changes_page_attachments(array &$page) { } function zoho_custom_alter_changes_form_alter(&$form, &$form_state, $form_id) { // if($form_id == 'system_performance_settings') // { // $group_owner = \Drupal\user\Entity\User::load('3'); // // $products_details = json_decode(\Drupal::httpClient()->get('http://lzdblogs.zohocorp.com/sites/zblogs/images/cmstest/group-details.json', array('verify' => FALSE, 'headers' => array('Accept' => 'application/json')))->getBody()->getContents(),TRUE); // $products_details = json_decode(file_get_contents('sites/zblogs/images/cmstest/group-details.json'),TRUE); // foreach($products_details as $product_name => $product_detail) // { // foreach($product_detail as $lang_key => $lang_details) // { // $group_label = $lang_details['group_title']; // $group_product_logo = $lang_details['featured_image']; // $group_product_meta_title = $lang_details['meta_title']; // $group_product_related_topics = $lang_details['related_topics']; // $group_product_service_name = $lang_details['service_name']; // $group_product_title = $lang_details['product_title']; // $group_product_uri = 'internal:'.$lang_details['url']; // $group_product_description = $lang_details['desc']; // if($lang_key == 'en') // { // $group_to_create = \Drupal::entityTypeManager()->getStorage('group')->create(['type' => 'product']); // don't change anything on this // $group_to_create->set('label', $group_label); // $group_to_create->set('langcode', $lang_key); // $group_to_create->set('field_product_logo', $group_product_logo); // $group_to_create->set('field_meta_title', $group_product_meta_title); // $group_to_create->set('field_related_topics', $group_product_related_topics); // $group_to_create->set('field_service_name', $group_product_service_name); // $group_to_create->set('field_product_title_and_folder_n', ['uri' => $group_product_uri,'title' => $group_product_title]); // // $group_to_create->field_product_title_and_folder_n->setValue(array('uri'=>$group_product_uri, 'title' => $group_product_title)); // $group_to_create->set('field_product_description', $group_product_description); // $group_to_create->setOwner($group_owner); // $group_to_create->save(); // $header_details = $lang_details['header_details']; // $group_path = $lang_details['url']; // $header_title = $group_to_create->label().' Header'; // $header_path = $group_path.'product-blog-menu/index.html'; // $uid = '3'; // $header_node = Node::create([ // 'type' => 'product_header', // 'title' => $header_title, // 'langcode' => $lang_key, // 'status' => '1', // 'uid' => $uid, // 'path' => [ // 'alias' => $header_path, // ], // 'body' => [ // 'value' => $header_details, // ] // ]); // // $node->setPublished(true); // $header_node->save(); // $nid = $header_node->id(); // $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->create([ // 'path' => "/node/".$nid, // 'alias' => $header_path, // 'langcode' => $lang_key, // ]); // $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->save($path_alias); // $group_to_create->addContent($header_node, 'group_node:product_header'); // } // else // { // $lang_group_to_create['label'][0]['value'] = $group_label; // $lang_group_to_create['field_product_logo'][0]['value'] = $group_product_logo; // $lang_group_to_create['status'][0]['value'] = '1'; // $lang_group_to_create['field_meta_title'][0]['value'] = $group_product_meta_title; // $lang_group_to_create['field_related_topics'][0]['value'] = $group_product_related_topics; // $lang_group_to_create['field_service_name'][0]['value'] = $group_product_service_name; // $lang_group_to_create['field_product_title_and_folder_n'][0]['uri'] = $group_product_uri; // $lang_group_to_create['field_product_title_and_folder_n'][0]['title'] = $group_product_title; // $lang_group_to_create['field_product_description'][0]['value'] = $group_product_description; // $lang_group = $group_to_create->addTranslation($lang_key,$lang_group_to_create)->save(); // $lang_header_details = $lang_details['header_details']; // $lang_header_title = $group_to_create->label().' Header'; // $lang_header_node['title'][0]['value'] = $lang_header_title; // $lang_header_node['type'][0]['target_id'] = 'product_header'; // $lang_header_node['status'][0]['value'] = '1'; // $lang_header_node['path'][0]['alias'] = $header_path; // $lang_header_node['body'][0]['value'] = $lang_header_details; // $lang_node = $header_node->addTranslation($lang_key,$lang_header_node)->save(); // $lang_path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->create([ // 'path' => "/node/".$nid, // 'alias' => $header_path, // 'langcode' => $lang_key, // ]); // $lang_path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')->save($lang_path_alias); // } // } // } // } $site_path = \Drupal::service('site.path'); $current_user = \Drupal::currentUser(); $uid = $current_user->id(); $anonymous_user = $current_user->isAnonymous(); $path = \Drupal::service('path.current')->getPath(); $current_uri = \Drupal::request()->getRequestUri(); $roles = $current_user->getRoles(); $route = \Drupal::routeMatch()->getRouteName(); if($route == 'node.add') { $form['actions']['preview']['#type'] = 'hidden'; } if($route == 'entity.node.delete_form' || $route == 'entity.node.delete_multiple_form' || $route == 'entity.comment.delete_form' || $route == 'comment.multiple_delete_confirm') { if(!in_array('administrator', $roles)) { throw new AccessDeniedHttpException(); } } $local_domain = ''; $live_domain = ''; if($form_id == 'user_login_form' || $form_id == 'comment_comment_form') { $local_domain = 'https://'.\Drupal::request()->getHost(); $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; $live_domain = $local_domain; } else { $live_domain = 'https://'.$site_domain; } } if($form_id == 'user_login_form') { $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { $redirect_path = \Drupal::urlGenerator()->generateFromRoute(''); if($accessed_language != 'en') { $redirect_path_array = explode('/', $redirect_path); array_pop($redirect_path_array); $redirect_path = implode('/', $redirect_path_array); } $response = new TrustedRedirectResponse('https://'.$site_domain.$redirect_path); $response->send(); } } if(!$anonymous_user) { // $form['#attached']['library'][] = 'zoho_custom_alter_changes/custom_admin'; } if($form_id == 'comment_comment_form' && strpos($current_uri, '/edit') === false) { $language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $form['#attached']['drupalSettings']['page_lang'] = $language; $author_title = $form['field_author']['widget'][0]['value']['#title']; if(!empty($author_title)) { $form['field_author']['widget'][0]['value']['#title'] = t($author_title); } $email_title = $form['field_email']['widget'][0]['value']['#title']; if(!empty($email_title)) { $form['field_email']['widget'][0]['value']['#title'] = t($email_title); } $url_title = $form['field_url']['widget'][0]['value']['#title']; if(!empty($url_title)) { $form['field_url']['widget'][0]['value']['#title'] = t($url_title); } $comment_body_title = $form['field_comment_body']['widget'][0]['value']['#title']; if(!empty($comment_body_title)) { $form['field_comment_body']['widget'][0]['value']['#title'] = t($comment_body_title); } if(!$anonymous_user) { $uid = $current_user->id(); $author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_user' => $uid]); $author_detail = array(); $author_exist = false; if(count($author_details) > 0) { $author_detail = current($author_details); if(!empty($author_detail)) { $author_mail = $author_detail->field_author_email->value; $author_name = $author_detail->field_author_display_name->value; $author_exist = true; } } if(!$author_exist) { $author_name = $current_user->getAccountName(); $author_mail = $current_user->getEmail(); } $form['langcode']['widget'][0]['value']['#default_value'] = $language; $form['langcode']['widget'][0]['value']['#disabled'] = true; $form['field_author']['widget'][0]['value']['#default_value'] = $author_name; $form['field_author']['widget'][0]['value']['#disabled'] = true; $form['field_email']['widget'][0]['value']['#default_value'] = $author_mail; $form['field_email']['widget'][0]['value']['#disabled'] = true; $form['actions']['submit']['#value'] = t('Post Comment'); } else { $action_url = $local_domain.$form['#action']; $form['#action'] = $action_url; $form['langcode']['widget'][0]['value']['#default_value'] = $language; $form['langcode']['widget'][0]['value']['#disabled'] = true; $form['actions']['submit']['#value'] = t('Post Comment'); $form['#attached']['library'][] = 'zoho_custom_alter_changes/footer_section'; $privacy_link_array = array('en'=>'https://www.zoho.com/privacy.html','es-xl'=>'https://www.zoho.com/privacy.html','pt-br'=>'https://www.zoho.com/privacy.html','ar'=>'https://www.zoho.com/privacy.html','id'=>'https://www.zoho.com/privacy.html','fr'=>'https://www.zoho.com/privacy.html','th'=>'https://www.zoho.com/privacy.html'); $form['markup'] = array( '#type' => 'markup', '#markup' => ''.t("By submitting this form, you agree to the processing of personal data according to our").' '.''.t("Privacy Policy.").'', '#weight' => 15, ); $form['actions']['submit']['#submit'][] = 'zoho_custom_alter_changes_comment_custom_submit'; } } elseif($form_id == 'comment_comment_form' && strpos($current_uri, '/edit') !== false) { $author_name = $form['field_author']['widget'][0]['value']['#default_value']; $author_mail = $form['field_email']['widget'][0]['value']['#default_value']; $form['author']['name']['#default_value'] = $author_name; $form['author']['mail']['#default_value'] = $author_mail; $form['#attached']['library'][] = 'zoho_custom_alter_changes/custom_admin'; } if(($route == 'entity.taxonomy_term.add_form' || $route == 'entity.taxonomy_term.edit_form') && $form['vid']['#value'] == 'author') { if($route == 'entity.taxonomy_term.edit_form') { $term_uid = ''; if(!in_array('administrator', $roles)) { $form['name']['#disabled'] = true; $form['field_guest_author']['#disabled'] = true; $form['field_author_email']['#disabled'] = true; $form['langcode']['#disabled'] = true; // unset($form['relations']); $form['relations']['parent']['#disabled'] = true; $form['relations']['weight']['#disabled'] = true; if(isset($form['field_user'])) { $form['field_user']['#disabled'] = true; if(count($form['field_user']['widget']['#default_value']) > 0) { $term_uid = $form['field_user']['widget']['#default_value'][0]; } if($uid != $term_uid) { throw new AccessDeniedHttpException(); } } } } if(!in_array('administrator', $roles)) { if(isset($form['actions']['overview'])) { $form['actions']['overview']['#disabled'] = true; } } if($route == 'entity.taxonomy_term.add_form') { $form['path']['widget'][0]['alias']['#default_value'] = '/zauthor/'; } $form['#validate'][] = 'zoho_custom_alter_changes_term_form_validate'; } if($form_id == 'group_content_product-group_membership_edit_form' || $form_id == 'group_content_product-group_membership_add_form') { $form['#validate'][] = 'group_role_form_validate'; } if(!in_array('administrator', $current_user->getRoles())) { if(strpos($form_id, 'group_content_group_content_type_') === 0) { throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException(); } } if($form_id == 'user_form' || $form_id == 'user_register_form') { $form['#validate'][] = 'user_form_validate'; if(!in_array('administrator', $roles)) { $default_roles = $form['account']['roles']['#default_value']; if(!in_array('administrator', $default_roles)) { unset($form['account']['roles']['#options']['administrator']); } else { throw new AccessDeniedHttpException(); } } // $form['actions']['submit']['#submit'][] = 'custom_user_profile_form_submit'; $current_path = \Drupal::service('path.current')->getPath(); $uid_from_current_path = explode('/', $current_path)[2]; $user_existing_group_list = zcustom_get_current_user_groups($uid_from_current_path); $form['field_profile_user_groups_list']['widget']['#default_value'] = array_keys($user_existing_group_list); // $form['#validate'][] = 'user_form_validate'; $form['actions']['submit']['#submit'][] = 'zcustom_manage_user_profile_group_access'; } if($form_id == 'metatag_defaults_edit_form') { if($path == '/admin/config/search/metatag/front') { $form['actions']['submit']['#submit'][] = 'zcustom_home_details'; } } } function zcustom_home_details(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { $form_state_data = $form_state->getValues(); $meta_details = array(); $meta_details['description'] = $form_state_data['description']; \Drupal::configFactory()->getEditable('zoho_custom_alter_changes.settings')->set('home_meta_details', $meta_details)->save(); } function zcustom_manage_user_profile_group_access(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { $user_already_have_Access = array(); $form_state_data = $form_state->getValues(); $user_id = $form_state_data['uid']; /* User existing groups list - start */ $user_existing_group_list = zcustom_get_current_user_groups($user_id); // ksm($user_existing_group_list); /* User existing groups list - end */ $account = \Drupal\user\Entity\User::load($user_id); $drupal_roles = $account->getRoles(); $form_state_input = $form_state->getUserinput(); if(!empty($form_state_input['field_profile_user_groups_list'])) { /* selected groups list - start */ $user_selected_groups_list = $form_state_input['field_profile_user_groups_list']; /* selected groups list - end */ // ksm($user_selected_groups_list); foreach ($user_selected_groups_list as $key => $group_id) { if($group_id != '_none') { if(!empty($group_id)) { // if gid of user_selected_groups_list not in user_existing_group_list, then add it for now if( !in_array($group_id, array_keys($user_existing_group_list)) ) { $group_obj = \Drupal\group\Entity\Group::load($group_id); $values = ['group_roles' => array('product-'.$drupal_roles[1]), 'gid' => [$group_id]]; $group_obj->addMember($account, $values); // ksm('New access to this group - '. $group_id); } else if( in_array($group_id, array_keys($user_existing_group_list)) ) // user already have access to this product. So no changes here { $user_already_have_Access[] = $group_id; // ksm('user already have access to this group - '. $group_id); } } } } // Get the diff of existing groups and selected groups - Which will return removed gid from existing group array $diff_user_groups = array_diff($user_existing_group_list, $user_selected_groups_list); if(!empty($diff_user_groups)) { foreach ($diff_user_groups as $gid => $group_title) { if($gid != '_none') { // if this gid not in user_already_have_Access list, then remove this gid for this user if( !in_array($gid, $user_already_have_Access) ) { $diff_group = \Drupal\group\Entity\Group::load($gid); $diff_group->removeMember($account); } } } } } } function zcustom_get_current_user_groups($user_id) { $products = array(); $database = \Drupal::database(); $og_result = $database->select('group_content_field_data', 'gcfd'); $og_result->join('groups_field_data','gfd', 'gfd.id = gcfd.gid'); $og_result->fields('gcfd', array('gid')); $og_result->fields('gfd', array('label')); $og_result->condition('gcfd.entity_id', $user_id, '='); $og_result->condition('gcfd.type', 'product-group_membership', '='); $og_result = $og_result->execute()->fetchAll(); if(!empty($og_result)) { foreach ($og_result as $key => $value) { $products[$value->gid] = $value->label; } } else { $products = array(); } return $products; } function zoho_custom_alter_changes_term_form_validate($form, FormStateInterface $form_state) { $form_state_values = $form_state->getValues(); if ($form_state_values['vid'] == 'author') { if(strpos($form_state_values['path'][0]['alias'], '/zauthor/') === false) { $form_state->setErrorByName('Validate', t('URL alias should start with /zauthor/')); } if($form_state_values['path'][0]['alias'] == '/zauthor') { $form_state->setErrorByName('Validate', t('Invalid author URL alias')); } } } function user_form_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { $roles = $form_state->getValues()['roles']; if (count($roles) > 2) { $form_state->setErrorByName('role', t('More than one role given')); } } function group_role_form_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state) { $route = \Drupal::routeMatch()->getRouteName(); if($route != 'entity.group.add_form') { $roles = $form_state->getValues()['group_roles']; if (count($roles) > 1) { $form_state->setErrorByName('role', t('More than one role given')); } elseif(count($roles) == 0) { $form_state->setErrorByName('role', t('Role not given')); } } } // function custom_user_profile_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) // { // ksm($form_state); // } function zoho_custom_alter_changes_comment_custom_submit(&$form, &$form_state) { $action_url = explode('node/', parse_url($_SERVER['REQUEST_URI'])['path']); $node_id = explode('/', $action_url[1])[0]; $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $language = $accessed_language_obj->getId(); $accessed_langcode = $language; if($language == 'ja') { $language = 'jp'; } $node = \Drupal\node\Entity\Node::load($node_id); if($node->hasTranslation($accessed_langcode)) { $node = $node->getTranslation($accessed_langcode); } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } $zoho_send_mail = false; $home_lang = ''; if($language != 'en') { $home_lang = '/'.$language; } $home_path = $live_domain.$live_home_path.$home_lang; $title = $node->getTitle(); $node_path = $node->toUrl('canonical', ['language' => $node->language()])->toString(); if($language != 'en') { $node_path = str_replace(array($local_domain.$local_home_path.'/'.$language.'/',$local_home_path.'/'.$language.'/'), array('/','/'), $node_path); } else { $node_path = str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $node_path); } $node_path = $home_path.$node_path; if(strpos($node_path,'/zsites/') !== false) { $node_path = str_replace('/zsites','/sites/',$node_path); } $node_owner_name = ''; $node_owner_mail = ''; if(!empty($node->field_post_created_by)) { $node_owner_name = $node->field_post_created_by->entity->field_author_display_name->value; $node_owner_mail = $node->field_post_created_by->entity->field_author_email->value; } if(strpos($node_owner_mail,'@zohocorp.com') !== false && strpos($node_owner_mail,'svembu@zohocorp.com') === false && strpos($node_owner_mail,'mani@zohocorp.com') === false && strpos($node_owner_mail,'raju@zohocorp.com') === false && strpos($node_owner_mail,'raju@zohocorp.com') === false) { $zoho_send_mail = true; } $database = \Drupal::database(); $query = $database->select('comment_field_data', 'c'); $query->addField('c', 'cid'); $query->condition('c.entity_id', $node_id); $query->condition('c.langcode', $accessed_langcode); $query->orderBy('created', 'DESC')->range(0, 1); $cid = $query->execute()->fetchField(); $response = new TrustedRedirectResponse($node_path.'#comment-'.$cid); $form_state->setResponse($response); $author_name = $form_state->getValue('field_author')[0]['value']; $approve_link = $local_domain.$local_home_path.'/comment/'.$cid.'/edit'; $trash_link = $local_domain.$local_home_path.'/comment/'.$cid.'/delete'; if(!empty($cid) && !empty($node_owner_mail)) { $comment_obj = \Drupal::entityTypeManager()->getStorage('comment')->load($cid); $author_email = $comment_obj->field_email->value; if(isset($comment_obj->field_url->value)) { $author_url = $comment_obj->field_url->value; } else { $author_url = '-'; } $comment = $comment_obj->field_comment_body->value; $send_mail = new \Drupal\Core\Mail\Plugin\Mail\PhpMail(); // this is used to send HTML emails // $to = 'vignesh.g@zohocorp.com'; if($zoho_send_mail) { $to = $node_owner_mail.',vignesh.g@zohocorp.com'; } else { $to = 'vignesh.g@zohocorp.com'; } $from = 'cms-team@zohocorp.com'; $message['headers'] = array( 'content-type' => 'text/html', 'reply-to' => $from, 'from' => $from ); $body .= 'Hello '.$node_owner_name.','."

"; $body .= 'A new comment on the post "'.$title.'" is waiting for your approval'."
".$node_path."

"; $body .= 'Author: '.$author_name."
".'Email: '.$author_email."
".'URL: '.$author_url."
".'Comment: '."
".$comment."

"; $body .= 'Approve it: '.$approve_link."
".'Trash it: '.$trash_link.'
'; $message['to'] = $to; $message['subject'] = '[Zoho Blogs] Please moderate: "'.$title.'"'; $message['body'] = $body; $send_mail->mail($message); } } function zoho_custom_alter_changes_preprocess_html(&$variables) { $route = \Drupal::routeMatch()->getRouteName(); $path = \Drupal::service('path.current')->getPath(); $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $site_path = \Drupal::service('site.path'); if(($anonymous_user) && $route == 'system.403') { throw new NotFoundHttpException(); } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $default_post_count = 0; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; $default_post_count = $group_details['default_post_count']; } $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; } $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); $accessed_langcode = $accessed_language; if($accessed_language == 'ja') { $accessed_language = 'jp'; } if($accessed_language == 'en') { $variables['html_attributes']['lang'] = 'en-US'; } $variables['html_attributes']['zohodblogs-lang'] = $accessed_language; $variables['attributes']['site'][] = "zohodblogs"; if($anonymous_user && $route == 'user.login') { $variables['page']['#attached']['library'][] = 'zoho_custom_alter_changes/core_files'; $variables['page']['#attached']['library'][] = 'zoho_custom_alter_changes/login_page_library'; $variables['head_title']['title'] = t('Zoho Blog - Dashboard login'); $html_head = $variables['page']['#attached']['html_head']; foreach($html_head as $meta_key => $meta_details) { if($meta_details[1] == 'robots') { $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = 'noindex , nofollow'; // if(empty($site_domain) || strpos($live_domain, $site_domain) === false) // { // // unset($page['#attached']['html_head'][$meta_key]); // } } elseif($meta_details[1] == 'system_meta_generator' || $meta_details[1] == 'shortlink' || $meta_details[1] == 'HandheldFriendly' || $meta_details[1] == 'MobileOptimized') { unset($variables['page']['#attached']['html_head'][$meta_key]); } } } if(!$anonymous_user) { if(!in_array('administrator', $current_user->getRoles())) { if($path == '/node/add') { $node_add_url = '/admin/group'; $response = new RedirectResponse(URL::fromUserInput($node_add_url)->toString()); $response->send(); exit; } if($route == 'entity.user.edit_form' || $route == 'entity.user.canonical') { $uid = $current_user->id(); $author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_user' => $uid]); $author_detail = array(); $author_exist = false; if(count($author_details) > 0) { $author_detail = current($author_details); if(!empty($author_detail)) { if($route == 'entity.user.canonical') { $author_alias = $author_detail->path[0]->alias; } else { $author_alias = '/taxonomy/term/'.$author_detail->tid->value.'/edit'; } if($accessed_language != 'en') { $author_detail = $author_detail->getTranslation($accessed_langcode); if($route == 'entity.user.canonical') { $author_alias = '/'.$accessed_language.$author_detail->path[0]->alias; } else { $author_alias = '/'.$accessed_language.'/taxonomy/term/'.$author_detail->tid->value.'/edit'; } } $author_exist = true; } } if(!$author_exist) { $author_alias = '/'; } $redirect = new RedirectResponse(Url::fromUserInput($author_alias)->toString());; $redirect->send(); exit; } } } if($route == 'entity.group.collection') { $variables['#attached']['library'][] = 'zoho_custom_alter_changes/zohocommon_custom_files'; } $product_home_route = 'zoho_custom_alter_changes.zproductpage_'; if($accessed_language != 'en') { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $path))[1]; } else { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $path))[1]; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if(strpos($product_home_route, '_sites') !== false) { $product_home_route = 'zoho_custom_alter_changes.zproductpage_zsites'; } } if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { // Define variables for the language direction. // $lang_direction = \Drupal::languageManager()->getCurrentLanguage(\Drupal\Core\Language\LanguageInterface::TYPE_CONTENT); // $direction = $lang_direction->getDirection(); // $variables['html_attributes']['dir'] = $direction; // $variables['page']['#attached']['library'][] = 'zoho_custom_alter_changes/core_libraries'; // unset($variables['html_attributes']['dir']); unset($variables['html_attributes']['prefix']); $node_type = ''; $group = ''; $page_title = ''; $page_feed_title = ''; $page_og_title = ''; $page_twitter_title = ''; $page_desc = ''; $page_og_desc = ''; $page_twitter_desc = ''; $page_status = false; $site_domain = ''; $result_count_query = 0; $pager_prev = true; $pager_next = true; if(!empty($group_details)) { $variables['page']['#attached']['drupalSettings']['group_details'] = $group_details; } if($route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { if($route == 'zoho_custom_alter_changes.zhomepage') { $node_type = 'article_home'; } elseif($route == $product_home_route) { $node_type = 'product_home'; } elseif($route == 'zoho_custom_alter_changes.zauthorpage') { $node_type = 'author'; } elseif($route == 'zoho_custom_alter_changes.ztagpage') { $node_type = 'tags'; } if($anonymous_user) { $variables['attributes']['class'] = []; } if($node_type == 'product_home' || $node_type == 'author' || $node_type == 'tags') { $page_status_params = array(); $page_status_params['accessed_langcode'] = $accessed_langcode; $page_status_params['accessed_language'] = $accessed_language; $page_status_params['type'] = $node_type; $status_result = zoho_custom_alter_changes_page_status($page_status_params); $page_status = $status_result['status']; $entity_path = $status_result['entity_path']; $gid = $status_result['gid']; $tid = $status_result['id']; } else { $page_status = true; $entity_path = ''; $gid = ''; $tid = ''; } if($node_type == 'article_home') { if(!isset($_GET['s'])) { $variables['attributes']['class'][] = 'home blog'; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; } else { $page_title = t("You searched for").' '.htmlspecialchars($_GET['s']); $variables['attributes']['class'][] = 'archive search search-results'; $variables['attributes']['class'][] = 'search-results'; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; } $variables['node_type'] = 'article_home'; } elseif($node_type == 'product_home') { $variables['attributes']['class'][] = 'archive category'; $variables['attributes']['class'][] = 'category-'.$entity_path; $variables['attributes']['class'][] = 'category-'.$gid; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; $variables['node_type'] = 'product_home'; $group = Group::load($gid); $page_entity = $group; if(!empty($page_entity)) { if($page_entity->hasTranslation($accessed_langcode)) { $page_entity = $page_entity->getTranslation($accessed_langcode); } $group_label = $page_entity->label->value; $group_label_name = $page_entity->field_product_title_and_folder_n->title; $group_title = strtolower(str_replace(' ', '-', $group_label)); $variables['attributes']['data-prdname'][] = $page_entity->field_service_name->value; $variables['attributes']['data-prdname-display'][] = $group_label; $page_title = $group_label_name." Archives - Zoho Blog"; if(isset($page_entity->field_meta_title)) { if(!empty($page_entity->field_meta_title->value)) { $page_title = $page_entity->field_meta_title->value." Archives - Zoho Blog"; } } $page_feed_title = $page_title; if(isset($page_entity->field_product_description)) { if(!empty($page_entity->field_product_description->value)) { $page_desc = strip_tags($page_entity->field_product_description->value); } } } } elseif($node_type == 'author') { $variables['attributes']['class'][] = 'archive author'; $variables['attributes']['class'][] = 'author-'.$entity_path; $variables['attributes']['class'][] = 'author-'.$tid; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; $variables['term_type'] = 'taxonomy'; $page_entity = \Drupal\taxonomy\Entity\Term::load($tid); if(!empty($page_entity)) { if($page_entity->hasTranslation($accessed_langcode)) { $page_entity = $page_entity->getTranslation($accessed_langcode); } $page_feed_title = $page_entity->field_author_display_name->value; $page_title = $page_entity->field_author_display_name->value.t(", Author at Zoho Blog"); } } elseif($node_type == 'tags') { $variables['attributes']['class'][] = 'archive tag'; $variables['attributes']['class'][] = 'tag-'.$entity_path; $variables['attributes']['class'][] = 'tag-'.$tid; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; $variables['term_type'] = 'taxonomy'; $page_entity = \Drupal\taxonomy\Entity\Term::load($tid); if(!empty($page_entity)) { if($page_entity->hasTranslation($accessed_langcode)) { $page_entity = $page_entity->getTranslation($accessed_langcode); } $page_feed_title = $page_entity->name->value; $page_title = $page_entity->name->value.t(" Archives - Zoho Blog"); } } $post_count_params = array(); $post_count_params['type'] = $node_type; $post_count_params['gid'] = $gid; $post_count_params['tid'] = $tid; $post_count_params['accessed_langcode'] = $accessed_langcode; $result_count_query = zoho_custom_alter_changes_posts_count($post_count_params); $pager_count = ceil($result_count_query/$default_post_count); \Drupal::configFactory()->getEditable('zoho_custom_alter_changes.settings')->set('zoho_custom_alter_changes_pager_count', $pager_count)->save(); $pager = ''; if(isset($_GET['page'])) { $pager = urlencode($_GET['page']); } if(empty($pager) || $pager < 1 || !is_numeric($pager)) { $pager = 0; } $pager = round($pager); } if($route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') { $node = \Drupal::routeMatch()->getParameter('node_preview'); if(empty($node)) { $node = \Drupal::routeMatch()->getParameter('node'); } if(!empty($node)) { if($node->hasTranslation($accessed_langcode)) { $node = $node->getTranslation($accessed_langcode); } $page_title = $node->title->value; $page_feed_title = $page_title; $node_type = $node->type->target_id; $node_nid = $node->id(); $group_contents = GroupContent::loadByEntity($node); $gid = ''; $group = array(); $group_type = ''; $group_label = ''; $group_title = ''; $group_ids = array(); foreach($group_contents as $group_content) { $group_ids[] = $group_content->getGroup()->id(); } if(!empty($group_ids)) { $gid = array_unique($group_ids)[0]; $group = Group::load($gid); } if(!empty($group)) { $group_type = $group->type->target_id; $group_label = $group->label->value; $group_title = strtolower(str_replace(' ', '-', $group_label)); $variables['attributes']['data-prdname'][] = $group->field_service_name->value; $variables['attributes']['data-prdname-display'][] = $group_label; } $root_name = $local_domain; $variables['root_name'] = $root_name; $variables['node_id'] = $node->id(); if($anonymous_user) { $nodeviewcount['url'] = $root_name."/nodeviewcount/updateCounter"; $nodeviewcount['data'] = array( $node_nid => array( "nid" => $node_nid, "uid" => 0, "view_mode" => "full" ) ); $statistics['url'] = $root_name."/core/modules/statistics/statistics.php"; $statistics['data'] = array( "nid" => $node_nid, ); $variables['page']['#attached']['drupalSettings']['nodeviewcount'] = $nodeviewcount; $variables['page']['#attached']['drupalSettings']['statistics'] = $statistics; } // if($anonymous_user) // { // if($node_type == 'product' || $node_type == 'post_category') // { // throw new NotFoundHttpException(); // } // } if($anonymous_user) { $variables['attributes']['class'] = []; } if($node_type == 'article_content') { $variables['attributes']['class'][] = 'post-template-default'; $variables['attributes']['class'][] = 'single'; $variables['attributes']['class'][] = 'single-post'; $variables['attributes']['class'][] = 'postid-'.$node_nid; $variables['attributes']['class'][] = 'single-format-standard'; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; $variables['attributes']['class'][] = 'category-'.$group->field_service_name->value; } } } if($route == 'system.404') { $variables['head_title']['title'] = t('Page Not Found - Zoho Blog'); $variables['attributes']['class'][] = 'error404'; $variables['attributes']['class'][] = 'i18n-'.$accessed_language; $variables['node_type'] = 'not_found'; } $domain_name = $local_domain; $html_head = $variables['page']['#attached']['html_head']; $page_alias = ''; foreach($html_head as $meta_key => $meta_details) { if($meta_details[1] == 'canonical_url') { $canonical_url = $meta_details[0]['#attributes']['href']; $canonical_url = str_replace('/zsites','/sites/',$canonical_url); $canonical_url = str_replace($local_domain.$local_home_path, $live_domain.$live_home_path, $canonical_url); $page_alias = $canonical_url; if($page_status && $pager != 0) { $canonical_url = $canonical_url.'?page='.$pager; } $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['href'] = $canonical_url; if($route == 'system.404') { unset($variables['page']['#attached']['html_head'][$meta_key]); } if(isset($_GET['s'])) { unset($variables['page']['#attached']['html_head'][$meta_key]); } } elseif($meta_details[1] == 'og_url') { $og_url = $meta_details[0]['#attributes']['content']; $og_url = str_replace('/zsites','/sites/',$og_url); $og_url = str_replace($local_domain.$local_home_path, $live_domain.$live_home_path, $og_url); if($page_status && $pager != 0) { $og_url = $og_url.'?page='.$pager; } $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = $og_url; if($route == 'system.404') { unset($variables['page']['#attached']['html_head'][$meta_key]); } if(isset($_GET['s'])) { unset($variables['page']['#attached']['html_head'][$meta_key]); } } elseif($meta_details[1] == 'twitter_cards_type' || $meta_details[1] == 'twitter_cards_site' || $meta_details[1] == 'twitter_cards_creator') { if($route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { unset($variables['page']['#attached']['html_head'][$meta_key]); } } elseif($meta_details[1] == 'twitter_cards_page_url') { $twitter_url = $meta_details[0]['#attributes']['content']; $twitter_url = str_replace('/zsites','/sites',$twitter_url); $twitter_url = str_replace($local_domain.$local_home_path, $live_domain.$live_home_path, $twitter_url); if($page_status && $pager != 0) { $twitter_url = $twitter_url.'?page='.$pager; } $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = $twitter_url; if($route == 'system.404') { unset($variables['page']['#attached']['html_head'][$meta_key]); } if(isset($_GET['s'])) { unset($variables['page']['#attached']['html_head'][$meta_key]); } } elseif($meta_details[1] == 'og_title') { $page_og_title = $meta_details[0]['#attributes']['content']; } elseif($meta_details[1] == 'twitter_cards_title') { $page_twitter_title = $meta_details[0]['#attributes']['content']; } elseif($meta_details[1] == 'description') { $page_desc = strip_tags($meta_details[0]['#attributes']['content']); } elseif($meta_details[1] == 'og_description') { $page_og_desc = strip_tags($meta_details[0]['#attributes']['content']); } elseif($meta_details[1] == 'twitter_cards_description') { $page_twitter_desc = strip_tags($meta_details[0]['#attributes']['content']); } elseif($meta_details[1] == 'robots') { $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = 'max-image-preview:large'; if($route == 'system.404' || (!$page_status && ($route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage'))) { unset($page['#attached']['html_head'][$meta_key]); } if(isset($_GET['s'])) { $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = 'noindex, follow'; } } elseif($meta_details[1] == 'system_meta_generator' || $meta_details[1] == 'shortlink' || $meta_details[1] == 'HandheldFriendly' || $meta_details[1] == 'MobileOptimized') { unset($variables['page']['#attached']['html_head'][$meta_key]); } elseif($meta_details[1] == 'image_src') { $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['href'] = $local_domain.parse_url($meta_details[0]['#attributes']['href'])['path']; } elseif($meta_details[1] == 'twitter_cards_image') { $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = $local_domain.parse_url($meta_details[0]['#attributes']['content'])['path']; } elseif($meta_details[1] == 'og_locale') { $locale_code_details = zoho_custom_alter_changes_locale_details($accessed_langcode,'meta'); $locale_code = $locale_code_details['locale_code']; $variables['page']['#attached']['html_head'][$meta_key][0]['#attributes']['content'] = $locale_code; } } if($route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { $page_og_title = ''; $page_twitter_title = ''; $page_og_desc = ''; $page_twitter_desc = ''; } if($route == 'entity.node.canonical' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { if(empty($page_og_title) && !empty($page_title)) { $og_title = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:title', 'content' => $page_title, ), ); $variables['page']['#attached']['html_head'][] = array($og_title,'og_title'); } if(empty($page_twitter_title) && !empty($page_title)) { $twitter_title = array( '#tag' => 'meta', '#attributes' => array( 'name' => 'twitter:title', 'content' => $page_title, ), ); $variables['page']['#attached']['html_head'][] = array($twitter_title,'twitter_cards_title'); } if(empty($page_og_desc) && !empty($page_desc)) { $og_desc = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:description', 'content' => $page_desc, ), ); $variables['page']['#attached']['html_head'][] = array($og_desc,'og_description'); } if(empty($page_twitter_desc) && !empty($page_desc)) { $twitter_desc = array( '#tag' => 'meta', '#attributes' => array( 'name' => 'twitter:description', 'content' => $page_desc, ), ); $variables['page']['#attached']['html_head'][] = array($twitter_desc,'twitter_cards_description'); } if(($route == 'zoho_custom_alter_changes.zhomepage' && isset($_GET['s'])) || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { $variables['head_title']['title'] = $page_title; if($route == 'zoho_custom_alter_changes.zauthorpage') { $og_img_src = 'https://blog.zoho.com/sites/zblogs/images/author_profile/avatar.png'; if(!empty($page_entity)) { $image_entity = $page_entity->field_profile_picture; if(!empty($image_entity)) { $img_entity = $image_entity->entity; if(!empty($img_entity)) { if($img_entity->hasTranslation($accessed_langcode)) { $img_entity = $img_entity->getTranslation($accessed_langcode); } $og_img_src = $img_entity->field_image_url->value; if(!empty($og_img_src)) { $og_img_src_parsed = parse_url($og_img_src)['path']; $og_img_src = $local_domain.$og_img_src_parsed; } } } if(!empty($og_img_src)) { $og_img = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image', 'content' => $og_img_src, ), ); $variables['page']['#attached']['html_head'][] = array($og_img,'og_image'); } $og_type = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:type', 'content' => 'profile', ), ); $variables['page']['#attached']['html_head'][] = array($og_type,'og_type'); } } } } if($route == 'entity.node.canonical') { $node = \Drupal::routeMatch()->getParameter('node'); if($node->hasTranslation($accessed_langcode)) { $node = $node->getTranslation($accessed_langcode); } if($node->type->target_id == 'article_content') { // $zs_tag = array( // '#tag' => 'meta', // '#attributes' => array( // 'zs_custom_field' => 'page_type', // 'zs_content' => 'articles', // ), // ); // $variables['page']['#attached']['html_head'][] = array($zs_tag, 'zs_tag'); $image_entity = $node->field_media_source; $og_img_status = false; if(!empty($image_entity)) { $img_entity = $image_entity->entity; if(!empty($img_entity)) { if($img_entity->hasTranslation($accessed_langcode)) { $img_entity = $img_entity->getTranslation($accessed_langcode); } $og_img_src = $img_entity->field_image_url->value; if(!empty($og_img_src)) { $og_img_status = true; $og_img_src_parsed = parse_url($og_img_src)['path']; $og_img_src = $local_domain.$og_img_src_parsed; $og_img_obj = zoho_custom_alter_changes_FileObjLoad($og_img_src_parsed); if(!empty($og_img_obj)) { $og_img_height = $og_img_obj->height; $og_img_width = $og_img_obj->width; $og_img_type = $og_img_obj->getMimeType(); $og_img_ht = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image:height', 'content' => $og_img_height, ), ); $og_img_wt = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image:width', 'content' => $og_img_width, ), ); $og_img_typ = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image:type', 'content' => $og_img_type, ), ); $variables['page']['#attached']['html_head'][] = array($og_img_ht,'og_image_height'); $variables['page']['#attached']['html_head'][] = array($og_img_wt,'og_image_width'); $variables['page']['#attached']['html_head'][] = array($og_img_typ,'og_image_type'); } $st_img = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'st:image', 'content' => $og_img_src, ), ); $variables['page']['#attached']['html_head'][] = array($st_img,'st_image'); } } } if(!$og_img_status) { $img_src = 'https://blog.zoho.com/sites/zblogs/images/product_logo/zoho-logo-blog-3.png'; $og_img = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image', 'content' => $img_src, ), ); $og_img_url = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image:url', 'itemprop' => 'image', 'content' => $img_src, ), ); $og_img_secure_url = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'og:image:secure_url', 'content' => $img_src, ), ); $twit_img = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'twitter:image', 'content' => $img_src, ), ); $st_img = array( '#tag' => 'meta', '#attributes' => array( 'property' => 'st:image', 'content' => $img_src, ), ); $image_src = array( '#tag' => 'link', '#attributes' => array( 'rel' => 'image_src', 'href' => $img_src, ), ); $variables['page']['#attached']['html_head'][] = array($og_img,'og_image'); $variables['page']['#attached']['html_head'][] = array($og_img_url,'og_image_url'); $variables['page']['#attached']['html_head'][] = array($og_img_secure_url,'og_image_secure_url'); $variables['page']['#attached']['html_head'][] = array($twit_img,'twitter_image'); $variables['page']['#attached']['html_head'][] = array($st_img,'st_image'); $variables['page']['#attached']['html_head'][] = array($image_src,'image_src'); } } } if($route == 'entity.node.canonical' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == 'zoho_custom_alter_changes.ztagpage' || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == $product_home_route) { if($route == 'zoho_custom_alter_changes.ztagpage') { $page_feed_title = $page_feed_title.' '.t('Tag'); } if($route == 'zoho_custom_alter_changes.zauthorpage') { $page_feed_title = t('Posts by').' '.$page_feed_title; } $siteName = \Drupal::config('system.site')->get('name'); $siteName = t($siteName); $feed_1 = array( '#type' => 'html_tag', '#tag' => 'link', '#attributes' => array( 'rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $siteName.' » '.t('Feed'), 'href' => $live_domain.$live_home_path.'/feed', ) ); $feed_2 = array( '#type' => 'html_tag', '#tag' => 'link', '#attributes' => array( 'rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $siteName.' » '.t('Comments Feed'), 'href' => $live_domain.$live_home_path.'/comments/feed', ) ); $variables['page']['#attached']['html_head'][] = array($feed_1,'feed_alternative'); $variables['page']['#attached']['html_head'][] = array($feed_2,'feed_alternative_1'); if($route == 'entity.node.canonical' || $route == 'zoho_custom_alter_changes.ztagpage' || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == $product_home_route) { if(!empty($page_alias)) { $feed_3 = array( '#type' => 'html_tag', '#tag' => 'link', '#attributes' => array( 'rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => $siteName.' » '.$page_feed_title.' '.t('Feed'), 'href' => $page_alias.'/feed', ) ); $variables['page']['#attached']['html_head'][] = array($feed_3,'feed_alternative_2'); } } if($route == 'zoho_custom_alter_changes.ztagpage' || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zhomepage') { if($pager + 1 < 1) { $pager_prev = false; } if($pager_count < $pager + 1) { throw new NotFoundHttpException(); } if($page_status) { if($pager_prev) { if($pager > 0) { $pager_prev_val = $pager - 1; if($pager != 0) { if($pager_prev_val == 0) { $pager_prev_alias = $page_alias; } else { $pager_prev_alias = $page_alias.'?page='.$pager_prev_val; } $pager_prev_tag = array( '#type' => 'html_tag', '#tag' => 'link', '#attributes' => array( 'rel' => 'prev', 'href' => $pager_prev_alias, ) ); $variables['page']['#attached']['html_head'][] = array($pager_prev_tag,'page_prev'); } } } if($pager_count <= $pager + 1) { $pager_next = false; } if($pager_next) { $pager_next_val = $pager + 1; $pager_next_alias = $page_alias.'?page='.$pager_next_val; $pager_next_tag = array( '#type' => 'html_tag', '#tag' => 'link', '#attributes' => array( 'rel' => 'next', 'href' => $pager_next_alias, ) ); $variables['page']['#attached']['html_head'][] = array($pager_next_tag,'page_next'); } } } } $headerLinks = $variables['page']['#attached']['html_head_link']; foreach ($headerLinks as $key => $linksData) { if(isset($linksData[0]['hreflang'])) { unset($variables['page']['#attached']['html_head_link'][$key]); // hreflang tags } if(isset($linksData[0]['type'])) { if($linksData[0]['type'] == "image/vnd.microsoft.icon") { if(isset($linksData[0]['rel'])) { $variables['page']['#attached']['html_head_link'][$key][0]['rel'] = "shortcut icon"; } if(isset($linksData[0]['href'])) { $variables['page']['#attached']['html_head_link'][$key][0]['href'] = "https://www.zohowebstatic.com/sites/all/themes/zoho/favicon.ico"; } } } } } } function zoho_custom_alter_changes_term_replace($string, $type) { $output = ''; if($type == 'tags') { $output = str_replace('/ztag/','/tag/', $string); } elseif($type == 'author') { $output = str_replace('/zauthor/','/author/', $string); } else { $output = $string; } return $output; } function zoho_custom_alter_changes_FileObjLoad($file_path) { if(strpos($file_path, '/') === 0) { $file_path = ltrim($file_path, '/'); } else { $file_path = $file_path; } if(strpos($file_path, 'sites/zblogs/images/') === 0) { $extn = pathinfo($file_path, PATHINFO_EXTENSION); $file_uri = str_replace('sites/zblogs/images/', 'public://', $file_path); $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $file_uri]); if(!empty($files)) { $file_id = array_keys($files)[0]; $files = $files[$file_id]; if($extn == 'svg') { $request = \Drupal::httpClient()->get('http://blog.zoho.com/'.$file_path); $response = $request->getBody()->getContents(); // $fileContents = file_get_contents($file_path); if ($response) { $svg = simplexml_load_string($response); if ($svg) { if (!empty($svg['width']) && !empty($svg['height'])) { $svg_width = (integer) $svg['width']; $svg_height = (integer) $svg['height']; } else if (!empty($svg['viewBox'])) { // Try with viewBox $parts = explode(' ', $svg['viewBox']); if (4 <= count($parts)) { $svg_width = (integer) $parts[2]; $svg_height = (integer) $parts[3]; } } $files->width = $svg_width; $files->height = $svg_height; $file_obj = $files; } } } else { $image = \Drupal::service('image.factory')->get($file_path); $img_width = $image->getToolkit()->getWidth(); $img_height = $image->getToolkit()->getHeight(); $files->width = $img_width; $files->height = $img_height; $file_obj = $files; } } } else { $file_obj = ''; } return $file_obj; } function zoho_custom_alter_changes_locale_details($accessed_langcode,$type) { $locale_code = $accessed_langcode; $locale_title = $accessed_langcode; if($accessed_langcode == 'en') { $locale_code = 'en-US'; $locale_title = 'English'; } elseif($accessed_langcode == 'es-xl') { $locale_code = 'es'; $locale_title = 'Español'; } elseif($accessed_langcode == 'pt-br') { $locale_code = 'pt-BR'; $locale_title = 'Português (Brasil)'; } elseif($accessed_langcode == 'ar') { $locale_code = 'ar'; $locale_title = 'العربية'; } elseif($accessed_langcode == 'id') { $locale_code = 'id-ID'; $locale_title = 'Bahasa Indonesia'; } elseif($accessed_langcode == 'th') { $locale_code = 'th-TH'; $locale_title = 'ภาษาไทย'; } elseif($accessed_langcode == 'fr') { $locale_code = 'fr-FR'; $locale_title = 'Français'; } if($type == 'meta') { $locale_code = str_replace('-','_',$locale_code); } $locale_code_details['locale_code'] = $locale_code; $locale_code_details['locale_title'] = $locale_title; return $locale_code_details; } function zoho_custom_alter_changes_search_result($params) { $current_path = \Drupal::service('path.current')->getPath(); $database = \Drupal::database(); $search_result_obj = array(); $accessed_langcode = $params['accessed_langcode']; $accessed_language = $params['accessed_language']; $search_word_param = $params['search_word_param']; $gid = $params['gid']; if($accessed_language == 'en') { $search_words = search_index_split($search_word_param,'en'); $data_string = ''; $word_string_array = array(); $word_string_count = ''; $word_string = ''; foreach($search_words as $words) { $data_string .= "(search_dataset.data LIKE '% ".$words." %') AND "; $word_string_array[] = "(search_index.word = '".$words."')"; } $word_string_count = count($word_string_array); foreach($word_string_array as $key => $ws) { if($word_string_count > 1) { if($key == '0') { $word_string .= $ws; } else { $word_string .= ' OR '.$ws; } } else { $word_string .= $ws; } } $query_string = $data_string."(".$word_string.")"; $search_type = 'article_content'; $search_result_obj = $database->query("SELECT SUM(search_index.score * search_total.count) AS score, MIN(node_field_data.nid) AS nid FROM node_field_data LEFT JOIN search_index ON node_field_data.nid = search_index.sid AND (search_index.type = 'node_search' AND search_index.langcode = node_field_data.langcode) LEFT JOIN search_total ON search_index.word = search_total.word INNER JOIN search_dataset ON search_index.sid = search_dataset.sid AND (search_index.type = search_dataset.type AND search_index.langcode = search_dataset.langcode) WHERE ((node_field_data.status = 1) AND (node_field_data.type IN ('$search_type')) AND ((search_index.type = 'node_search') AND $query_string)) GROUP BY search_index.sid HAVING (COUNT(*) >= 1)")->fetchAll(); } else { // $search_words = preg_replace('/[^A-Za-z0-9\-]/', ' ', trim($search_word_param)); $search_words = trim($search_word_param); $search_query_title = $database->select('node_field_data', 'd'); $search_query_title->addField('d', 'nid'); $search_query_title->condition('d.status', '1'); $search_query_title->condition('d.type', 'article_content'); $search_query_title->condition('d.langcode', $accessed_langcode); $search_query_title->condition('d.title', '%'.$search_words.'%','like'); if(!empty($gid)) { $search_query_title->join('group_content_field_data', 'gc', 'd.nid = gc.entity_id'); $search_query_title->condition('gc.gid', $gid); $search_query_title->condition('gc.type', 'group_content_type%', 'like'); } $search_query_title_result = $search_query_title->execute()->fetchAll(); $search_query_content = $database->select('node__body', 'b'); $search_query_content->addField('b', 'entity_id','nid'); $search_query_content->join('node_field_data', 'f', 'f.nid = b.entity_id'); $search_query_content->condition('f.status', '1'); $search_query_content->condition('b.bundle', 'article_content'); $search_query_content->condition('b.langcode', $accessed_langcode); $search_query_content->condition('b.body_value', '%'.$search_words.'%','like'); if(!empty($gid)) { $search_query_content->join('group_content_field_data', 'gc', 'b.entity_id = gc.entity_id'); $search_query_content->condition('gc.gid', $gid); $search_query_content->condition('gc.type', 'group_content_type%', 'like'); } $search_query_content_result = $search_query_content->execute()->fetchAll(); $search_result_obj = array_merge($search_query_title_result,$search_query_content_result); $search_result_obj = array_map("unserialize", array_unique(array_map("serialize", $search_result_obj))); } return $search_result_obj; } function zoho_custom_alter_changes_preprocess_page(&$variables) { $route = \Drupal::routeMatch()->getRouteName(); $current_path = \Drupal::service('path.current')->getPath(); if($route == 'entity.group.canonical') { $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $roles = $current_user->getRoles(); if(!in_array('administrator', $roles)) { $node_add_url = '/admin/group'; $response = new RedirectResponse(URL::fromUserInput($node_add_url)->toString()); $response->send(); exit; } } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $default_post_count = 0; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; $default_post_count = $group_details['default_post_count']; } $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; } $variables['site_domain'] = $site_domain; $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); $accessed_langcode = $accessed_language; if($accessed_language == 'ja') { $accessed_language = 'jp'; } $product_home_route = 'zoho_custom_alter_changes.zproductpage_'; if($accessed_language != 'en') { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $current_path))[1]; } else { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $current_path))[1]; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if(strpos($product_home_route, '_sites') !== false) { $product_home_route = 'zoho_custom_alter_changes.zproductpage_zsites'; } } if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { $site_path = \Drupal::service('site.path'); $group = array(); $gid = ''; $tid = ''; $nids = array(); $result_count_query = 0; $database = \Drupal::database(); $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $variables['current_user'] = $current_user; $variables['site_domain'] = $site_domain; $user = array(); $type = ''; $term_alias = ''; $variables['language'] = $accessed_language_obj; $home_lang = ''; if($accessed_language != 'en') { $home_lang = '/'.$accessed_language; } $home_path = ''; $live_page_status = '0'; if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { $live_page_status = '1'; } $variables['live_page_status'] = $live_page_status; if(!empty($site_domain) && strpos($local_domain, $site_domain) === false && $accessed_language != 'en') { $home_path = $live_home_path.$home_lang; } else { if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { $home_path = $live_home_path.$home_lang; } else { $home_path = $local_home_path.$home_lang; } } $variables['home_path'] = $home_path; $variables['revert_home_path'] = $local_home_path.$home_lang; $variables['accessed_language'] = $accessed_language; if(!$anonymous_user) { $variables['#attached']['library'][] = 'zoho_custom_alter_changes/custom_admin'; } if($route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') { $node = \Drupal::routeMatch()->getParameter('node_preview'); if(empty($node)) { $node = \Drupal::routeMatch()->getParameter('node'); } if(isset($node)) { if($node->hasTranslation($accessed_langcode)) { $node = $node->getTranslation($accessed_langcode); } $node_id = $node->id(); $type = $node->getType(); $variables['language'] = $accessed_language_obj; if($route == 'entity.node.preview') { $variables['node'] = $node; } $group_ids = array(); $group_contents = GroupContent::loadByEntity($node); foreach($group_contents as $group_content) { $group_ids[] = $group_content->getGroup()->id(); } if(!empty($group_ids)) { $gid = array_unique($group_ids)[0]; $group = Group::load($gid); if($group->hasTranslation($accessed_langcode)) { $group = $group->getTranslation($accessed_langcode); } $group_type = $group->type->target_id; if($group_type == 'product') { $variables['group_obj'] = $group; } } if($type == 'article_content') { $read_time_query = $database-> select('zoho_node_read_time', 't'); $read_time_query->addField('t', 'read_time'); $read_time_query->addField('c', 'totalcount'); $read_time_query->join('node_counter', 'c', 'c.nid = t.nid'); $read_time_query->condition('t.nid', $node_id); $read_time_query->condition('t.language', $accessed_langcode); $read_time_result = $read_time_query->execute()->fetchAll(); if(isset($read_time_result[0])) { $read_time = $read_time_result[0]->read_time; } else { $new_read_time = $database->select('zoho_node_read_time','t') ->fields('t',array('read_time')) ->condition('t.nid',$node_id) ->condition('t.language', $accessed_langcode); $new_read_time_query = $new_read_time->execute()->fetchAll(); $new_time = $new_read_time_query[0]->read_time; $read_time = $new_time; } if($read_time == '0') { $read_time = '0'; } $totalcount = 0; if(isset($read_time_result[0]->totalcount)) { $totalcount = $read_time_result[0]->totalcount; } if ($totalcount > 999 && $totalcount <= 999999) { $totalcount = number_format(($totalcount / 1000), 1) . 'K'; } elseif ($totalcount > 999999 && $totalcount <= 999999999) { $totalcount = number_format(($totalcount / 1000000), 1) . 'M'; } elseif ($totalcount > 999999999 && $totalcount <= 999999999999) { $totalcount = number_format(($totalcount / 1000000000), 1) . 'B'; } elseif ($totalcount > 999999999999) { $totalcount = number_format(($totalcount / 1000000000000), 1) . 'T'; } if(!empty($totalcount)) { $viewscount = $totalcount; } else { $viewscount = '0'; } $variables['dynamic_values'] = array('read_time'=>$read_time,'viewscount'=>$viewscount); /***** Previous & Next Pages - Post - Start *****/ $post_node_query = \Drupal::entityQuery('node') ->condition('type', $type) ->condition('langcode', $accessed_langcode) ->condition('status', '1') ->sort('created' , 'DESC'); $post_node_ids = $post_node_query->execute(); $post_node_ids = array_values($post_node_ids); $nid_keys = $post_node_ids; $nid_key = array_search($node_id, $nid_keys); $prev_nid = ''; $next_nid = ''; if($nid_key != false || $nid_key == 0) { if(isset($nid_keys[$nid_key+1])) { $prev_nid = $nid_keys[$nid_key+1]; } if(isset($nid_keys[$nid_key-1])) { $next_nid = $nid_keys[$nid_key-1]; } } if(!empty($prev_nid)) { $prev_node = \Drupal\node\Entity\Node::load($prev_nid); if($prev_node->hasTranslation($accessed_langcode)) { $prev_node = $prev_node->getTranslation($accessed_langcode); } $variables['prev_node'] = $prev_node; } else { $variables['prev_node'] = ''; } if(!empty($next_nid)) { $next_node = \Drupal\node\Entity\Node::load($next_nid); if($next_node->hasTranslation($accessed_langcode)) { $next_node = $next_node->getTranslation($accessed_langcode); } $variables['next_node'] = $next_node; } else { $variables['next_node'] = ''; } /***** Previous & Next Pages - Post - End *****/ /***** Popular Posts Section - Post - Start *****/ $popular_post_node_array = array(); $popular_post_query = $database->select('node_field_data', 'n'); $popular_post_query->addField('n', 'nid','entity_id'); $popular_post_query->join('group_content_field_data', 'gc', 'gc.entity_id = n.nid'); $popular_post_query->condition('n.status', '1'); $popular_post_query->condition('n.type', 'article_content'); $popular_post_query->condition('n.langcode', $accessed_langcode); $popular_post_query->condition('n.nid', $node_id, 'Not like'); $popular_post_query->condition('gc.gid', $gid, 'like'); $popular_post_query->condition('gc.type', 'group_content_type%', 'like'); $popular_post_query->orderBy('n.created', 'DESC'); $popular_post_query->range(0, 5); $popular_post_result = $popular_post_query->execute()->fetchAll(); foreach($popular_post_result as $popular_post_val) { if(!empty($popular_post_val->entity_id)) { $popular_post_node = \Drupal\node\Entity\Node::load($popular_post_val->entity_id); if($popular_post_node->hasTranslation($accessed_langcode)) { $popular_post_node = $popular_post_node->getTranslation($accessed_langcode); } if(!empty($popular_post_node)) { $popular_post_node_array[$popular_post_val->entity_id] = $popular_post_node; } } } $variables['popular_post_node'] = $popular_post_node_array; /***** Popular Posts Section - Post - End *****/ $entity_path = $node->toUrl('canonical')->toString(); $switcher_params = array(); $switcher_params['type'] = $type; $switcher_params['entity_path'] = $entity_path; $switcher_params['accessed_langcode'] = $accessed_langcode; $switcher_params['accessed_language'] = $accessed_language; $switcher_params['site_details'] = $group_details; $switcher = zoho_custom_alter_changes_lang_switcher($switcher_params); $variables['switcher'] = $switcher; } } } if($route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { $type = ''; if($route == 'zoho_custom_alter_changes.zhomepage') { if(!isset($_GET['s'])) { $type = 'article_home'; } else { $type = 'search'; } } elseif($route == $product_home_route) { $type = 'product_home'; } elseif($route == 'zoho_custom_alter_changes.zauthorpage') { $type = 'author'; } elseif($route == 'zoho_custom_alter_changes.ztagpage') { $type = 'tags'; } if($type == 'search') { $search_word_param = ''; $search_word_param = urlencode($_GET['s']); $params = array(); $cat_id = ''; if(isset($_GET['cat']) && !empty($_GET['cat'])) { $cat_id = urlencode($_GET['cat']); } $params['gid'] = $cat_id; $params['search_word_param'] = $search_word_param; $params['accessed_langcode'] = $accessed_langcode; $params['accessed_language'] = $accessed_language; $search_result_obj = zoho_custom_alter_changes_search_result($params); } $cat_id = ''; $nids = array(); if($type == 'search') { if(isset($_GET['cat'])) { $cat_id = urlencode($_GET['cat']); } if(empty($cat_id) || !is_numeric($cat_id)) { $cat_id = 0; } $cat_id = round($cat_id); if(count($search_result_obj) > 0) { $pager_count = ceil(count($search_result_obj)/$default_post_count); \Drupal::configFactory()->getEditable('zoho_custom_alter_changes.settings')->set('zoho_custom_alter_changes_pager_count', $pager_count)->save(); $encoded_result = json_encode($search_result_obj); $decoded_result = json_decode($encoded_result, true); $nids = array_column($decoded_result, 'nid'); // \Drupal::logger('nids')->error('
' . print_r($nids, TRUE) . '
'); } } $gid = ''; $tid = ''; $entity_path = ''; if($type == 'product_home' || $type == 'tags' || $type == 'author') { $page_status_params = array(); $page_status_params['accessed_langcode'] = $accessed_langcode; $page_status_params['accessed_language'] = $accessed_language; $page_status_params['type'] = $type; $status_result = zoho_custom_alter_changes_page_status($page_status_params); if(!empty($status_result)) { $page_status = $status_result['status']; if($page_status) { if($type == 'product_home') { $gid = $status_result['gid']; $group_obj = \Drupal\group\Entity\Group::load($gid); if($group_obj->hasTranslation($accessed_langcode)) { $group_obj = $group_obj->getTranslation($accessed_langcode); } $variables['group_obj'] = $group_obj; $entity_path = $status_result['entity_path']; } elseif($type == 'tags' || $type == 'author') { $tid = $status_result['id']; $term = \Drupal\taxonomy\Entity\Term::load($tid); if($term->hasTranslation($accessed_langcode)) { $term = $term->getTranslation($accessed_langcode); } $variables['term'] = $term; $entity_path = $status_result['entity_path']; } } else { throw new NotFoundHttpException(); } } } $recent_posts_params = array(); $recent_posts_params['accessed_langcode'] = $accessed_langcode; $recent_posts_params['accessed_language'] = $accessed_language; $recent_posts_params['type'] = $type; $recent_posts_params['nids'] = $nids; $recent_posts_params['tid'] = $tid; $recent_posts_params['cat_id'] = $cat_id; $recent_posts_params['gid'] = $gid; $recent_posts_params['default_post_count'] = $default_post_count; $recent_posts_result = zoho_custom_alter_changes_recent_posts($recent_posts_params); $recent_nodes = $recent_posts_result['recent_nodes']; $product_list = $recent_posts_result['product_list']; $recent_nodes_count = count($recent_nodes); $feature_post_nodes = array(); if($type == 'article_home') { $feature_posts_params['accessed_langcode'] = $accessed_langcode; $feature_post_nodes = zoho_custom_alter_changes_feature_posts($feature_posts_params); } /***** Language Switcher - Start *****/ $switcher_params = array(); $switcher_params['type'] = $type; $switcher_params['entity_path'] = $entity_path; $switcher_params['accessed_langcode'] = $accessed_langcode; $switcher_params['accessed_language'] = $accessed_language; $switcher_params['site_details'] = $group_details; $switcher = zoho_custom_alter_changes_lang_switcher($switcher_params); /***** Language Switcher - End *****/ $search_status = 0; $search_keyword = ''; if($type == 'search' && $recent_nodes_count > 0) { $search_status = 1; $search_keyword = htmlspecialchars(urldecode($search_word_param)); } $not_found_params = array(); $not_found_params['recent_nodes_count'] = $recent_nodes_count; $not_found_params['home_path'] = $home_path; $not_found_content = zoho_custom_alter_changes_post_not_found($not_found_params); $variables['search_data'] = array('status' => $search_status,'keyword'=>$search_keyword); $variables['recent_nodes_count'] = $recent_nodes_count; $variables['recent_nodes'] = $recent_nodes; $variables['recent_nodes_group_array'] = $product_list; $variables['feature_post_nodes'] = $feature_post_nodes; $variables['pager_section'] = $pager_string; $variables['not_found_content'] = $not_found_content; $variables['switcher'] = $switcher; } /***** Language Switcher - End *****/ // $variables['#attached']['library'][] = 'zoho_custom_alter_changes/common_files'; // if($anonymous_user && $pager < 2) if($anonymous_user) { $variables['#attached']['library'][] = 'zoho_custom_alter_changes/core_files'; } if($anonymous_user && $type == 'article_content') { $variables['#attached']['library'][] = 'zoho_custom_alter_changes/node_view_counter'; } $variables['#attached']['library'][] = 'zoho_custom_alter_changes/custom_theme_library'; $variables['#attached']['library'][] = 'zoho_custom_alter_changes/footer_section'; } if($route == 'entity.taxonomy_term.canonical') { $current_path = \Drupal::service('path.current')->getPath(); $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } $current_user = \Drupal::currentUser(); $roles = $current_user->getRoles(); $anonymous_user = $current_user->isAnonymous(); $term_alias = ''; $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); $accessed_langcode = $accessed_language; if($accessed_language == 'ja') { $accessed_language = 'jp'; } $home_lang = ''; if($accessed_language != 'en') { $home_lang = '/'.$accessed_language; } $term = \Drupal::routeMatch()->getParameter('taxonomy_term'); if(!empty($term)) { if($term->hasTranslation($accessed_langcode)) { $term = $term->getTranslation($accessed_langcode); } $term_alias = $term->path[0]->alias; $tid = $term->id(); $type = $term->bundle(); if($type == 'tags' || $type == 'author') { if($accessed_language != 'en') { $term_alias = str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $term_alias); } else { $term_alias = str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $term_alias); } if(!empty($site_domain)) { $term_alias = $live_home_path.$home_lang.$term_alias; } else { $term_alias = $home_lang.$term_alias; } if($type == 'tags') { $term_alias = zoho_custom_alter_changes_term_replace($term_alias, $type); } if($type == 'author') { $term_alias = zoho_custom_alter_changes_term_replace($term_alias, $type); } if(!in_array('administrator', $roles)) { $response = new RedirectResponse(URL::fromUserInput($term_alias)->toString()); $response->send(); exit; } } } } } function zoho_custom_alter_changes_page_status($page_status_params) { $status = array(); if(!empty($page_status_params)) { if(isset($page_status_params['type'])) { $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } if(empty($site_domain)) { $site_domain = $local_domain; } $type = $page_status_params['type']; if($type == 'product_home' || $type == 'tags' || $type == 'author') { $accessed_langcode = $page_status_params['accessed_langcode']; $accessed_language = $page_status_params['accessed_language']; $database = \Drupal::database(); $status['status'] = false; $status['page'] = '404'; $status['id'] = ''; $status['gid'] = ''; $status['entity_path'] = ''; $current_path = \Drupal::service('path.current')->getPath(); if($accessed_language != 'en') { $current_path = str_replace('/'.$accessed_language.'/','/',$current_path); } if(strpos($current_path, '/blog/') === 0) { $current_path = str_replace('/blog/','/',$current_path); } $entity_path = ''; if($type == 'product_home') { $entity_path = explode('/',$current_path)[1]; } elseif($type == 'tags') { $entity_path = explode('/tag/',$current_path)[1]; } elseif($type == 'author') { $entity_path = explode('/author/',$current_path)[1]; } if(!empty($entity_path)) { $encoded_path = urlencode($entity_path); $entity_path = htmlspecialchars(urldecode($entity_path)); } if($type == 'product_home') { if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if($entity_path == 'sites') { $entity_path = 'zsites'; } } $status['page'] = $type; $group_entity_array = $database->select('group__field_product_title_and_folder_n', 'p'); $group_entity_array->addField('p', 'entity_id'); $group_entity_array->condition('p.field_product_title_and_folder_n_uri', 'internal:/'.$entity_path.'/','like'); $group_entity_array->condition('p.bundle', 'product', 'like'); $group_entity_array_result = $group_entity_array->execute()->fetchField(); if(!empty($group_entity_array_result)) { $gid = $group_entity_array_result; $status['status'] = true; $status['gid'] = $gid; $status['entity_path'] = $entity_path; } } if($type == 'tags' || $type == 'author') { $status['page'] = $type; $entity_array = $database->select('path_alias', 'p'); $entity_array->addField('p', 'path'); if($type == 'tags') { $entity_array->condition('p.alias', '/ztag/'.$entity_path,'like'); } else { $entity_array->condition('p.alias', '/zauthor/'.$entity_path,'like'); } $entity_array->condition('p.langcode', $accessed_langcode); $entity_array_result = $entity_array->execute()->fetchField(); if(!empty($entity_array_result)) { if(strpos($entity_array_result,'/taxonomy/term/') === 0) { $entity_array_result = str_replace('/taxonomy/term/','',$entity_array_result); $status['status'] = true; $status['id'] = $entity_array_result; $status['entity_path'] = $entity_path; } } } } } } return $status; } function zoho_custom_alter_changes_posts_count($post_count_params) { $type = $post_count_params['type']; $gid = $post_count_params['gid']; $tid = $post_count_params['tid']; $accessed_langcode = $post_count_params['accessed_langcode']; $database = \Drupal::database(); $count_query = $database->select('node_field_data', 'n'); $count_query->condition('n.status', '1'); $count_query->condition('n.type', 'article_content'); $count_query->condition('n.langcode', $accessed_langcode); if($type == 'product_home' && !empty($gid)) { $count_query->join('group_content_field_data', 'gc', 'gc.entity_id = n.nid'); $count_query->condition('gc.gid', $gid, 'like'); $count_query->condition('gc.type', 'group_content_type%', 'like'); } if($type == 'author') { if(!empty($tid)) { $count_query->join('node__field_post_created_by', 'fpc', 'fpc.entity_id = n.nid and fpc.langcode = n.langcode'); $count_query->condition('fpc.field_post_created_by_target_id', $tid, 'like'); } } if($type == 'tags') { if(!empty($tid)) { $count_query->join('node__field_tags', 'ft', 'ft.entity_id = n.nid and ft.langcode = n.langcode'); $count_query->condition('ft.field_tags_target_id', $tid, 'like'); } } $count_query->addExpression('COUNT(*)'); $result_count_query = $count_query->execute()->fetchField(); return $result_count_query; } function zoho_custom_alter_changes_recent_posts($recent_posts_params) { $accessed_langcode = $recent_posts_params['accessed_langcode']; $accessed_language = $recent_posts_params['accessed_language']; $type = ''; if(isset($recent_posts_params['type'])) { $type = $recent_posts_params['type']; } $gid = ''; if(isset($recent_posts_params['gid'])) { $gid = $recent_posts_params['gid']; } $tid = ''; if(isset($recent_posts_params['tid'])) { $tid = $recent_posts_params['tid']; } $nids = array(); if(isset($recent_posts_params['nids'])) { $nids = $recent_posts_params['nids']; } $cat_id = ''; if(isset($recent_posts_params['cat_id'])) { $cat_id = $recent_posts_params['cat_id']; } $default_post_count = $recent_posts_params['default_post_count']; $database = \Drupal::database(); $query = $database->select('node_field_data', 'n')->extend('Drupal\Core\Database\Query\PagerSelectExtender'); $query->addField('n', 'nid','entity_id'); $query->addField('c', 'totalcount'); $query->addField('t', 'read_time'); $query->addField('n', 'created'); $query->join('node_counter', 'c', 'c.nid = n.nid'); $query->join('zoho_node_read_time', 't', 't.nid = n.nid'); $query->condition('n.status', '1'); $query->condition('n.type', 'article_content'); $query->condition('n.langcode', $accessed_langcode); $query->condition('t.language', $accessed_langcode); if($type == 'product_home' && !empty($gid)) { $query->join('group_content_field_data', 'gc', 'gc.entity_id = n.nid'); $query->condition('gc.gid', $gid, 'like'); $query->condition('gc.type', 'group_content_type%', 'like'); } if($type == 'author') { if(!empty($tid)) { $query->join('node__field_post_created_by', 'fpc', 'fpc.entity_id = n.nid and fpc.langcode = n.langcode'); $query->condition('fpc.field_post_created_by_target_id', $tid, 'like'); } } if($type == 'tags') { if(!empty($tid)) { $query->join('node__field_tags', 'ft', 'ft.entity_id = n.nid and ft.langcode = n.langcode'); $query->condition('ft.field_tags_target_id', $tid, 'like'); } } if($type == 'search') { if(!empty($nids)) { $query->condition('n.nid', $nids,'IN'); if(!empty($cat_id)) { $query->join('group_content_field_data', 'gc', 'gc.entity_id = n.nid'); $query->condition('gc.type', 'group_content_type%', 'like'); $query->condition('gc.gid', $cat_id, 'like'); } } else { $nids = array('0'); $query->condition('n.nid', $nids,'IN'); } } $query->limit($default_post_count); $query->distinct('entity_id'); $query->orderBy('created', 'DESC'); $result_query = $query->execute()->fetchAll(); // \Drupal::logger('result_query')->error('
' . print_r($result_query, TRUE) . '
'); $encoded_result = json_encode($result_query); $decoded_result = json_decode($encoded_result, true); $result_nids = array_column($decoded_result, 'entity_id'); // \Drupal::logger('nids_column')->error('
' . print_r($result_nids, TRUE) . '
'); $recent_nodes_array = array(); $recent_nodes = array(); $product_list = array(); if(!empty($result_nids)) { $recent_nodes_array = \Drupal\node\Entity\Node::loadMultiple($result_nids); } if(!empty($recent_nodes_array)) { $product_list = zoho_custom_alter_changes_product_obj(); foreach($decoded_result as $decoded_result_array) { if(isset($recent_nodes_array[$decoded_result_array['entity_id']])) { $recent_node = array(); $recent_node_id = $decoded_result_array['entity_id']; $recent_node = $recent_nodes_array[$recent_node_id]; if($recent_node->hasTranslation($accessed_langcode)) { $recent_node = $recent_node->getTranslation($accessed_langcode); } $recent_nodes[$recent_node_id] = $recent_node; $recent_nodes[$recent_node_id]->viewscount = $decoded_result_array['totalcount']; $recent_nodes[$recent_node_id]->read_time = $decoded_result_array['read_time']; $recent_node_gid = '0'; $recent_node_group_ids = array(); $recent_node_group_contents = GroupContent::loadByEntity($recent_node); foreach($recent_node_group_contents as $recent_node_group_content) { $recent_node_group_ids[] = $recent_node_group_content->getGroup()->id(); } if(!empty($recent_node_group_ids)) { $recent_node_gid = array_unique($recent_node_group_ids)[0]; $recent_nodes[$recent_node_id]->gid = $recent_node_gid; } } } } $recent_posts_result['product_list'] = $product_list; $recent_posts_result['recent_nodes'] = $recent_nodes; return $recent_posts_result; } function zoho_custom_alter_changes_post_not_found($not_found_params) { $not_found_content = ''; $recent_nodes_count = $not_found_params['recent_nodes_count']; $home_path = $not_found_params['home_path']; if($recent_nodes_count < 1) { $not_found_content = '

'.t("It seems we can't find what you're looking for. Perhaps searching can help.").'

'; } return $not_found_content; } function zoho_custom_alter_changes_feature_posts($feature_posts_params) { $feature_post_nodes = array(); $accessed_langcode = $feature_posts_params['accessed_langcode']; $feature_post_query = \Drupal::entityQuery('node') ->condition('type', 'article_content') ->condition('langcode', $accessed_langcode) ->condition('status', '1') ->condition('sticky', '1') ->sort('created' , 'DESC') ->range(0, 5); $feature_post_ids = $feature_post_query->execute(); if(count($feature_post_ids) > 0) { $feature_post_nodes = \Drupal\node\Entity\Node::loadMultiple($feature_post_ids); } return $feature_post_nodes; } function zoho_custom_alter_changes_lang_switcher($switcher_params) { if(isset($switcher_params['type']) && !empty($switcher_params['type'])) { $type = $switcher_params['type']; if($type == 'article_home' || $type == 'article_content' || $type == 'product_home' || $type == 'author' || $type == 'tags' || $type == 'search') { $database = \Drupal::database(); $entity_path = $switcher_params['entity_path']; $accessed_langcode = $switcher_params['accessed_langcode']; $accessed_language = $switcher_params['accessed_language']; $site_details = $switcher_params['site_details']; $local_domain = $site_details['local_domain']; $live_domain = $site_details['live_domain']; $local_home_path = $site_details['local_home_path']; $live_home_path = $site_details['live_home_path']; if($accessed_language != 'en') { $entity_path = str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $entity_path); } else { $entity_path = str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $entity_path); } if($type == 'author' || $type == 'tags' || $type == 'article_content') { $pages_query = $database->select('path_alias', 'p'); $pages_query->addField('p', 'alias'); $pages_query->addField('p', 'langcode'); $pages_query->addField('p', 'path'); if($type == 'author' || $type == 'tags') { $pages_query->join('taxonomy_term_field_data', 'f', 'f.tid = SUBSTRING_INDEX(p.path,\'taxonomy/term/\',-1) and p.langcode = f.langcode'); $pages_query->condition('f.status', '1'); } else { $pages_query->join('node_field_data', 'f', 'f.nid = SUBSTRING_INDEX(p.path,\'node/\',-1) and p.langcode = f.langcode'); $pages_query->condition('f.status', '1',); $pages_query->condition('f.type', 'article_content'); } if($type == 'tags') { $pages_query->condition('p.alias', '/ztag/'.$entity_path,'like'); } elseif($type == 'author') { $pages_query->condition('p.alias', '/zauthor/'.$entity_path,'like'); } else { $pages_query->condition('p.alias',$entity_path,'like'); } $pages_query->orderBy('p.id','ASC'); $pages_query_result = $pages_query->execute()->fetchAll(); } else { $pages_query = $database->select('path_alias', 'p'); $pages_query->addField('p', 'langcode'); $pages_query->join('node_field_data', 'f', 'f.nid = SUBSTRING_INDEX(p.path,\'node/\',-1) and p.langcode = f.langcode'); $pages_query->condition('f.status', '1'); $pages_query->condition('f.type', 'article_content'); if($type == 'product_home') { $pages_query->condition('p.alias', '/'.$entity_path.'/%','like'); } $pages_query->distinct('langcode'); $pages_query_result = $pages_query->execute()->fetchAll(); } $entity_path = str_replace('index.html','',$entity_path); if($type == 'search') { $entity_path = $entity_path.'?s='.htmlspecialchars($_GET['s']); } if($type == 'product_home' || $type == 'tags' || $type == 'author') { if($type == 'tags') { $entity_path = '/tag/'.$entity_path; } if($type == 'author') { $entity_path = '/author/'.$entity_path; } else { $entity_path = '/'.$entity_path; } } $switcher_string = ''; $switcher = ''; if(count($pages_query_result) > 1) { $entity_lang_array = array(); foreach($pages_query_result as $pages_details) { $entity_lang = $pages_details->langcode; if(!in_array($entity_lang,$entity_lang_array)) { $entity_lang_array[] = $entity_lang; $page_lang = ''; if($entity_lang != 'en') { if($entity_lang == 'ja') { $page_lang = '/jp'; } else { $page_lang = '/'.$entity_lang; } } if($entity_lang == 'ja') { $entity_lang = 'jp'; } $locale_code_details = zoho_custom_alter_changes_locale_details($entity_lang,'lang_switcher'); $entity_locale_code = $locale_code_details['locale_code']; $lang_title = $locale_code_details['locale_title']; if($type == 'article_home' || $type == 'search' || $type == 'product_home') { $entity_id = ''; } else { $entity_id = $pages_details->path; } if(strpos($entity_id,'/taxonomy/term/') === 0) { $entity_id = str_replace('/taxonomy/term/','',$entity_id); } if(strpos($entity_id,'/node/') === 0) { $entity_id = str_replace('/node/','',$entity_id); } $current_lang_class = ''; $first_lang_class = ''; $entity_id_class = ''; if($accessed_langcode == $entity_lang) { $current_lang_class = ' current-lang'; } if($entity_lang == 'en') { $first_lang_class = ' lang-item-first'; } if($type == 'article_home') { $entity_id_class = ' lang-item'; } else { $entity_id_class = ' lang-item-'.$entity_id; } $entity_path_alias = $live_domain.$live_home_path.$page_lang.$entity_path; $switcher_string .= '
  • '.$lang_title.'
  • '; } } if(!empty($switcher_string)) { $switcher = '
      '.$switcher_string.'
    '; } } return $switcher; } } return ''; } function zoho_custom_alter_changes_product_list() { // $list = array(); // $db = \Drupal::database(); // $product_list = $db->select('group_content_field_data', 'grp_content') // ->fields('grp_content', ['gid']) // ->condition('grp_content.type', 'product-group_membership', '=') // ->execute() // ->fetchAll(); // if(!empty($product_list)) // { // foreach ($product_list as $products) // { // $gid = $products->gid; // $gid_object = \Drupal\group\Entity\Group::load($gid); // $list[$gid] = $gid_object->label(); // } // return $list; // } $list = array(); $product_list = \Drupal::entityTypeManager()->getStorage('group')->loadByProperties(['status' => '1']); if(!empty($product_list)) { foreach ($product_list as $key => $product) { $gid = $key; $list[$gid] = $product->label(); } } return $list; } function zoho_custom_alter_changes_product_obj() { $product_list = \Drupal::entityTypeManager()->getStorage('group')->loadByProperties(['status' => '1']); return $product_list; } function zoho_custom_alter_changes_read_time($entity) { $words_per_minute = \Drupal::config('node_read_time.settings')->get('reading_time')['words_per_minute'] ?: 225; $reading_time_service = \Drupal::service('node_read_time.reading_time'); $reading_time = $reading_time_service ->setWordsPerMinute($words_per_minute) ->collectWords($entity) ->calculateReadingTime() ->getReadingTime(); // Clear the words variable. $reading_time_service->setWords(0); return $reading_time; } function wrapper_change(array &$form, FormStateInterface $form_state) { $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); if(!empty($form_state->getValues())) { $lang_val = $form_state->getValues()['langcode'][0]['value']; } else { $lang_val = $accessed_language; } $group_array = array(); $group_array = $form['#group']; $author_options_array = author_values($lang_val,$group_array); $author_options = $author_options_array['author_details']; $form['field_post_created_by']['widget']['#options'] = $author_options; $renderer = \Drupal::service('renderer'); $renderedField_author = $renderer->render($form['field_post_created_by']); $response = new AjaxResponse(); $response->addCommand(new ReplaceCommand('#author-wrapper', $renderedField_author)); return $response; } function author_values($accessed_language,$group_array) { $author_options = array('none' => '--Select--'); $user_options = array(); if(!empty($group_array)) { // $members = $group_array->getMembers(); // $userids = array(); // foreach($members as $member) // { // $user = $member->getUser(); // $userids[] = $user->id(); // } $all_user_array = \Drupal::service('entity_type.manager')->getStorage('user')->loadByProperties(); $userids = array_keys($all_user_array); $author_details = array(); if(count($userids) > 0) { $author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_user' => $userids]); if(count($author_details) > 0) { foreach($author_details as $author_detail) { if($author_detail->hasTranslation($accessed_language)) { $author_detail = $author_detail->getTranslation($accessed_language); if(isset($author_detail->field_user)) { if(!empty($author_detail->field_user->target_id)) { $user_options[$author_detail->field_user->target_id] = $author_detail->tid->value; } } $author_options[$author_detail->tid->value] = $author_detail->field_author_display_name->value; } } } $guest_author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_guest_author' => '1']); if(count($guest_author_details) > 0) { foreach($guest_author_details as $guest_author_detail) { if($guest_author_detail->hasTranslation($accessed_language)) { $guest_author_detail = $guest_author_detail->getTranslation($accessed_language); $author_options[$guest_author_detail->tid->value] = $guest_author_detail->field_author_display_name->value; } } } } } $author_options_array['author_details'] = $author_options; $author_options_array['user_details'] = $user_options; return $author_options_array; } function zoho_custom_alter_changes_form_node_form_alter(&$form, FormStateInterface $form_state) { $current_user = \Drupal::currentUser(); $uid = $current_user->id(); $roles = $current_user->getRoles(); $language_manager = \Drupal::languageManager(); $langcodes = $language_manager->getLanguages(); $accessed_language_obj = $language_manager->getCurrentLanguage(); $accessed_langcode = $accessed_language_obj->getId(); if($form['#form_id'] == 'node_article_content_form' || $form['#form_id'] == 'node_article_content_edit_form') { // $current_user = \Drupal::currentUser(); // $user_name = $current_user->getAccountName(); // $form['field_post_created_by']['widget']['0']['target_id']['#value'] = $user_name; } $form['#validate'][] = 'zoho_custom_alter_changes_node_form_validate'; if(!in_array('administrator', $roles)) { if($form['#form_id'] != 'node_article_content_form' && $form['#form_id'] != 'node_article_content_edit_form') { throw new AccessDeniedHttpException(); // throw new NotFoundHttpException(); } } $group_array = array(); $node = $form_state->getFormObject()->getEntity(); if($node->isNew()) { $current_path = \Drupal::request()->getRequestUri(); if(strpos($current_path, '/group/') === 0) { $gid = explode('/', $current_path)[2]; $group_array = \Drupal\group\Entity\Group::load($gid); if(!empty($group_array)) { if($group_array->hasTranslation($accessed_langcode)) { $group_array = $group_array->getTranslation($accessed_langcode); } $group_title = $group_array->label(); if($form['#form_id'] == 'node_article_content_form' || $form['#form_id'] == 'node_product_home_form') { // $group_array_new = $group_array->toArray(); // $group_alias = Url::fromUri($group_array_new['field_product_title_and_folder_n'][0]['uri']); // $group_alias = $group_alias->toString().'/'; // $form['path']['widget'][0]['alias']['#value'] = $group_alias; } $form['markup'] = array( '#markup' => '
    ', '#allowed_tags' => ['div','label', 'select', 'option'], '#weight' => -1, ); // $rendered_message = \Drupal\Core\Render\Markup::create(); // \Drupal::messenger()->addMessage($rendered_message); } } } else { $gid = ''; $gids = array(); $nid = $node->nid->value; $ids = \Drupal::entityQuery('group_content') ->condition('entity_id', $nid) ->execute(); $relations = \Drupal\group\Entity\GroupContent::loadMultiple($ids); foreach($relations as $rel) { if($rel->getEntity()->getEntityTypeId() == 'node') { $gids[] = $rel->getGroup()->id(); } } if(!empty($gids[0])) { $gid = $gids[0]; } if(!empty($gid)) { $group_array = \Drupal\group\Entity\Group::load($gid); if(!empty($group_array)) { if($group_array->hasTranslation($accessed_langcode)) { $group_array = $group_array->getTranslation($accessed_langcode); } $group_title = $group_array->label(); $form['markup'] = array( '#markup' => '
    ', '#allowed_tags' => ['div','label', 'select', 'option'], '#weight' => -1, ); // $rendered_message = \Drupal\Core\Render\Markup::create('
    You are in '.$group_title.' product
    '); // \Drupal::messenger()->addMessage($rendered_message); } } } // ksm($form); // ksm($node); if($form['#form_id'] == 'node_article_content_form' || $form['#form_id'] == 'node_article_content_edit_form') { $languages_array = array(); $languages_array = array('_none' => '- Select a value -'); $user_options = array(); foreach($langcodes as $lang_val) { $languages_array[$lang_val->getId()] = $lang_val->getName(); } $form['langcode']['widget'][0]['value']['#options'] = $languages_array; $form['langcode']['widget'][0]['value']['#required'] = true; $default_language = $form['langcode']['widget'][0]['value']['#default_value']; $form['#group'] = $group_array; $form['langcode']['widget'][0]['value']['#ajax'] = array( 'callback' => 'wrapper_change', 'event' => 'change', 'wrapper' => 'category-wrapper', ); $form['field_post_created_by']['#attributes'] = array( 'id' => 'author-wrapper', ); // $form['field_post_created_by']['widget']['#options'] = array('_none' => '- Select a value -'); $form_state->setCached(FALSE); if($default_language != 'und') { $author_options_array = author_values($default_language,$group_array); $form['field_post_created_by']['widget']['#options'] = $author_options_array['author_details']; // $form['field_post_created_by']['#validated'] = TRUE; // $form['field_post_created_by']['#limit_validation_errors'] = array(); // if(isset($author_options_array['user_details'])) // { // $user_options = $author_options_array['user_details']; // $form['field_post_created_by']['widget']['#default_value'][] = $user_options[$uid]; // } } if(isset($author_options_array['user_details'])) { $user_options = $author_options_array['user_details']; } if($form['#form_id'] == 'node_article_content_form') { if(isset($user_options[$uid])) { $form['field_post_created_by']['widget']['#default_value'][] = $user_options[$uid]; } } elseif($form['#form_id'] == 'node_article_content_edit_form') { if(in_array('content_manager', $current_user->getRoles()) || in_array('content_editor', $current_user->getRoles())) { $default_uid = ''; $default_tid = ''; if(count($form['field_post_created_by']['widget']['#default_value']) > 0) { $default_tid = $form['field_post_created_by']['widget']['#default_value'][0]; if(!empty($default_tid)) { $default_term = \Drupal\taxonomy\Entity\Term::load($default_tid); $default_uid = $default_term->field_user->target_id; } } if($default_uid != $uid) { throw new AccessDeniedHttpException(); } } } } } function zoho_custom_alter_changes_node_form_validate($form, FormStateInterface $form_state) { $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_langcode = $accessed_language_obj->getId();; $path_alias = $form_state->getValue('path')[0]['alias']; $node = $form_state->getFormObject()->getEntity(); $node_type = $node->getType(); $group_array = array(); if($node->isNew()) { $current_path = \Drupal::request()->getRequestUri(); if(strpos($current_path, '/group/') === 0) { $gid = explode('/', $current_path)[2]; $group_array = \Drupal\group\Entity\Group::load($gid); if($group_array->hasTranslation($accessed_langcode)) { $group_array = $group_array->getTranslation($accessed_langcode); } } } else { $gid = ''; $gids = array(); $nid = $node->nid->value; $ids = \Drupal::entityQuery('group_content') ->condition('entity_id', $nid) ->execute(); $relations = \Drupal\group\Entity\GroupContent::loadMultiple($ids); foreach($relations as $rel) { if($rel->getEntity()->getEntityTypeId() == 'node') { $gids[] = $rel->getGroup()->id(); } } if(!empty($gids[0])) { $gid = $gids[0]; } if(!empty($gid)) { $group_array = \Drupal\group\Entity\Group::load($gid); if($group_array->hasTranslation($accessed_langcode)) { $group_array = $group_array->getTranslation($accessed_langcode); } } } if(!empty($group_array)) { $group_array = $group_array->toArray(); $group_alias = Url::fromUri($group_array['field_product_title_and_folder_n'][0]['uri']); $group_alias = $group_alias->toString(); // if($node_type == 'zp_help_resource') // { // $group_alias = '/content/'; // } // if($gid != '73') // { if(strpos($path_alias, $group_alias) === 0) { $path_validate = true; } else { $path_validate = false; } if($path_validate == false) { $form_state->setErrorByName('Validate', t('Alias should start with '. $group_alias)); } // } } if($path_alias == '' || $path_alias == NULL) { $form_state->setErrorByName('Validate', t('Alias should not be empty')); } if($node_type == 'article_content') { if(strpos($path_alias, '.html') === false) { $form_state->setErrorByName('Validate', t('Alias should be end with .html')); } $meta_desc = $form_state->getValue('field_metatags')[0]['basic']['description']; if(empty($meta_desc)) { $form_state->setErrorByName('Validate', t('Meta description should not be empty')); } } } function zoho_custom_alter_changes_node_insert(Drupal\Core\Entity\EntityInterface $entity) { $batch = array( 'operations' => array(), 'finished' => 'custom_blocks_node_insert_finished_callback', 'title' => t('Node Insert - Batch'), 'init_message' => t('Node insert process is starting...'), 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('Node insert has encountered an error.') ); $batch['operations'][] = array('custom_blocks_node_insert_batch_process', array($entity)); if(!empty($batch['operations'])) { batch_set($batch); } } function zoho_custom_alter_changes_read_time_update($entity) { $nid = $entity->id(); $database = \Drupal::database(); $config = \Drupal::config('node_read_time.settings')->get('reading_time')['container']; if($config[$entity->getType()]['is_activated']) { $read_time = zoho_custom_alter_changes_read_time($entity); $read_time_insert_field = [ 'nid' => $nid, 'read_time' => $read_time, 'language' => $entity->language()->getId(), 'read_time_details' => 'null', ]; $read_time_update_field = [ 'read_time' => $read_time, 'read_time_details' => 'null', ]; $read_time_query = $database->merge('zoho_node_read_time') ->keys(['nid', 'language'], ['nid' => $nid, 'language' => $entity->language()->getId()]) ->insertFields($read_time_insert_field) ->updateFields($read_time_update_field) ->execute(); } } function custom_blocks_node_insert_batch_process($entity, &$context) { $context['message'] = 'Node is inserting...'; $nid = $entity->id(); $field_arr_insert = [ 'nid' => $nid, 'totalcount' => 0, 'daycount' => 0, 'timestamp' => time(), 'weekcount' => 0, 'monthcount' => 0, 'yearcount' => 0, ]; $field_arr_update = [ 'totalcount' => 0, 'daycount' => 0, 'timestamp' => time(), 'weekcount' => 0, 'monthcount' => 0, 'yearcount' => 0, ]; $database = \Drupal::database(); $query = $database->merge('node_counter') ->keys(['nid'], ['nid' => $nid]) ->insertFields($field_arr_insert) ->updateFields($field_arr_update) ->execute(); zoho_custom_alter_changes_read_time_update($entity); if($entity->getType() == 'article_content') { $language = $entity->language()->getId(); if(!empty($entity->field_tags)) { $node_save = false; $term_id_array = array(); foreach($entity->field_tags as $tag) { $save = false; $term = \Drupal\taxonomy\Entity\Term::load($tag->target_id); $title = $term->name->value; $vid = $term->vid->target_id; $term_lang = $term->language()->getId(); if($language != $term_lang) { $node_save = true; $existing_terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $title, 'vid' => $vid,'langcode'=>$language]); $term = array(); if(empty($existing_terms)) { $term = \Drupal\taxonomy\Entity\Term::create([ 'vid' => $vid, 'name' => $title, 'langcode'=>$language, ]); $term->save(); } else { foreach($existing_terms as $old_term) { $term = $old_term; } } $term_id_array[] = array('target_id' => $term->id()); } else { $term_id_array[] = array('target_id' => $term->id()); } // $new_alias = '/tag/'.preg_replace('/[^A-Za-z0-9\-]/', '', strtolower(str_replace(' ', '-', $term->name->value))); $new_alias = '/ztag/'. strtolower(str_replace(' ', '-', $term->name->value)); if(!empty($term->path[0]->alias)) { if($new_alias != $term->path[0]->alias) { $save = true; $term->path[0]->alias = $new_alias; } } else { $save = true; $term->path[0]->alias = $new_alias; } if($save == true) { $term->Save(); } } if($node_save == true) { $entity->field_tags = $term_id_array; $entity->save(); } } } } function custom_blocks_node_insert_finished_callback($success, $results, $operations) { // The 'success' parameter means no fatal PHP errors were detected. All // other error management should be handled using 'results'. if ($success) { \Drupal::messenger()->addStatus(t('Node insert was completed')); } else { \Drupal::messenger()->addError(t($operations)); } } function zoho_custom_alter_changes_node_update(Drupal\Core\Entity\EntityInterface $entity) { $batch = array( 'operations' => array(), 'finished' => 'custom_blocks_node_update_finished_callback', 'title' => t('Node Update - Batch'), 'init_message' => t('Node update process is starting...'), 'progress_message' => t('Processed @current out of @total.'), 'error_message' => t('Node update has encountered an error.') ); $batch['operations'][] = array('custom_blocks_node_update_batch_process', array($entity)); if(!empty($batch['operations'])) { batch_set($batch); } } function custom_blocks_node_update_batch_process($entity, &$context) { $context['message'] = 'Node is Updating...'; $nid = $entity->id(); $database = \Drupal::database(); zoho_custom_alter_changes_read_time_update($entity); if($entity->getType() == 'article_content') { $language = $entity->language()->getId(); if(!empty($entity->field_tags)) { $node_save = false; $term_id_array = array(); foreach($entity->field_tags as $tag) { $save = false; $term = \Drupal\taxonomy\Entity\Term::load($tag->target_id); $title = $term->name->value; $vid = $term->vid->target_id; $term_lang = $term->language()->getId(); if($language != $term_lang) { $node_save = true; $existing_terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $title, 'vid' => $vid,'langcode'=>$language]); $term = array(); if(empty($existing_terms)) { $term = \Drupal\taxonomy\Entity\Term::create([ 'vid' => $vid, 'name' => $title, 'langcode'=>$language, ]); $term->save(); } else { foreach($existing_terms as $old_term) { $term = $old_term; } } $term_id_array[] = array('target_id' => $term->id()); } else { $term_id_array[] = array('target_id' => $term->id()); } // $new_alias = '/tag/'.preg_replace('/[^A-Za-z0-9\-]/', '', strtolower(str_replace(' ', '-', $term->name->value))); $new_alias = '/ztag/'. strtolower(str_replace(' ', '-', $term->name->value)); if(!empty($term->path[0]->alias)) { if($new_alias != $term->path[0]->alias) { $save = true; $term->path[0]->alias = $new_alias; } } else { $save = true; $term->path[0]->alias = $new_alias; } if($save == true) { $term->Save(); } } if($node_save == true) { $entity->field_tags = $term_id_array; $entity->save(); } } } } function custom_blocks_node_update_finished_callback($success, $results, $operations) { // The 'success' parameter means no fatal PHP errors were detected. All // other error management should be handled using 'results'. if ($success) { \Drupal::messenger()->addStatus(t('Node update was completed')); } else { \Drupal::messenger()->addError(t($operations)); } } function zoho_custom_alter_changes_node_predelete(Drupal\Core\Entity\EntityInterface $node) { $nid = $node->id(); $language = $node->language()->getId(); if(!empty($nid)) { $database = \Drupal::database(); $database->delete('zoho_node_read_time') ->condition('nid', $nid) ->condition('language', $language) ->execute(); } } function zoho_custom_alter_changes_css_alter(&$css, $assets) { $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $current_path = \Drupal::service('path.current')->getPath(); $route = \Drupal::routeMatch()->getRouteName(); $site_path = \Drupal::service('site.path'); if(!$anonymous_user || $current_path == '/_l/login') { // UPDATE THIS PATH TO YOUR MODULE'S CSS PATH. $path = drupal_get_path('theme', 'gin') . '/dist/css/gin.css'; if (isset($css[$path])) { // Use anything greater than 100 to have it load after the theme // as CSS_AGGREGATE_THEME is set to 100. // Let's be on the safe side and assign a high number to it. $css[$path]['group'] = 200; } } // if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') // { // $g_path = 'https://www.zohowebstatic.com/sites/all/themes/zoho/css/global.css'; // $css[$g_path]['group'] = '-900'; // $css[$g_path]['type'] = 'external'; // } $unusedList = array ( 'core/assets/vendor/normalize-css/normalize.css', 'core/misc/normalize-fixes.css', 'core/modules/system/css/components/align.module.css', 'core/modules/system/css/components/fieldgroup.module.css', 'core/modules/system/css/components/container-inline.module.css', 'core/modules/system/css/components/clearfix.module.css', 'core/modules/system/css/components/details.module.css', 'core/modules/system/css/components/hidden.module.css', 'core/modules/system/css/components/item-list.module.css', 'core/modules/system/css/components/js.module.css', 'core/modules/system/css/components/nowrap.module.css', 'core/modules/system/css/components/position-container.module.css', 'core/modules/system/css/components/progress.module.css', 'core/modules/system/css/components/reset-appearance.module.css', 'core/modules/system/css/components/resize.module.css', 'core/modules/system/css/components/sticky-header.module.css', 'core/modules/system/css/components/tablesort.module.css', 'core/modules/system/css/components/tree-child.module.css', 'core/themes/claro/css/components/ajax-progress.module.css', 'core/themes/claro/css/components/autocomplete-loading.module.css', 'core/themes/claro/css/components/tabledrag.css', 'core/themes/claro/css/base/elements.css', 'core/themes/claro/css/base/typography.css', 'core/themes/claro/css/base/print.css', 'core/themes/claro/css/layout/system-admin--layout.css', 'core/themes/claro/css/layout/breadcrumb.css', 'core/themes/claro/css/layout/layout.css', 'core/themes/claro/css/components/system-admin--admin-list.css', 'core/themes/claro/css/components/system-admin--links.css', 'core/themes/claro/css/components/system-admin--modules.css', 'core/themes/claro/css/components/system-admin--panel.css', 'core/themes/claro/css/components/system-admin--status-report.css', 'core/themes/claro/css/layout/card-list.css', 'core/themes/claro/css/components/card.css', 'core/themes/claro/css/classy/components/container-inline.css', 'core/themes/claro/css/classy/components/exposed-filters.css', 'core/themes/claro/css/classy/components/field.css', 'core/themes/claro/css/classy/components/icons.css', 'core/themes/claro/css/classy/components/inline-form.css', 'core/themes/claro/css/classy/components/item-list.css', 'core/themes/claro/css/classy/components/link.css', 'core/themes/claro/css/classy/components/links.css', 'core/themes/claro/css/classy/components/menu.css', 'core/themes/claro/css/classy/components/more-link.css', 'core/themes/claro/css/classy/components/tablesort.css', 'core/themes/claro/css/classy/components/textarea.css', 'core/themes/claro/css/classy/components/ui-dialog.css', 'core/themes/claro/css/components/accordion.css', 'core/themes/claro/css/components/action-link.css', 'core/themes/claro/css/components/content-header.css', 'core/themes/claro/css/components/container-inline.css', 'core/themes/claro/css/components/container-inline.module.css', 'core/themes/claro/css/components/breadcrumb.css', 'core/themes/claro/css/components/button.css', 'core/themes/claro/css/components/details.css', 'core/themes/claro/css/components/divider.css', 'core/themes/claro/css/components/messages.css', 'core/themes/claro/css/components/entity-meta.css', 'core/themes/claro/css/components/fieldset.css', 'core/themes/claro/css/components/form.css', 'core/themes/claro/css/components/form--checkbox-radio.css', 'core/themes/claro/css/components/form--checkbox-radio--ie.css', 'core/themes/claro/css/components/form--field-multiple.css', 'core/themes/claro/css/components/form--managed-file.css', 'core/themes/claro/css/components/form--text.css', 'core/themes/claro/css/components/form--select.css', 'core/themes/claro/css/components/help.css', 'core/themes/claro/css/components/image-preview.css', 'core/themes/claro/css/components/menus-and-lists.css', 'core/themes/claro/css/components/modules-page.css', 'core/themes/claro/css/components/node.css', 'core/themes/claro/css/components/page-title.css', 'core/themes/claro/css/components/pager.css', 'core/themes/claro/css/components/skip-link.css', 'core/themes/claro/css/components/tables.css', 'core/themes/claro/css/components/table--file-multiple-widget.css', 'core/themes/claro/css/components/search-admin-settings.css', 'core/themes/claro/css/components/tablesort-indicator.css', 'core/themes/claro/css/components/system-status-report-general-info.css', 'core/themes/claro/css/components/system-status-report.css', 'core/themes/claro/css/components/system-status-counter.css', 'core/themes/claro/css/components/system-status-report-counters.css', 'core/themes/claro/css/components/tableselect.css', 'core/themes/claro/css/components/tabs.css', 'core/themes/claro/css/components/views-ui.css', 'themes/gin/dist/css/theme/font.css', 'themes/gin/dist/css/theme/variables.css', 'themes/gin/dist/css/components/coffee.css', 'themes/gin/dist/css/components/node_preview.css', 'themes/gin/dist/css/components/responsive_preview.css', 'themes/gin/dist/css/components/settings_tray.css', 'themes/gin/dist/css/components/settings_tray_edit.css', 'themes/gin/dist/css/components/toolbar.css', 'themes/gin/dist/css/components/toolbar_secondary.css', 'core/themes/claro/css/theme/colors.css', 'core/themes/claro/css/layout/local-actions.css', 'themes/gin/dist/css/components/breadcrumb.css', 'themes/gin/dist/css/layout/horizontal_toolbar.css', 'themes/gin/dist/css/theme/accent.css', 'themes/gin/dist/css/components/dialog.css', 'themes/gin/dist/css/components/contextual_links.css', 'themes/gin/dist/css/base/gin.css', 'themes/gin/dist/css/layout/classic_toolbar.css' ); if($anonymous_user) { foreach ($unusedList as $key => $value) { unset($css[$value]); } } if(!$anonymous_user && ($route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version')) { unset($css['core/themes/claro/css/base/elements.css']); } } function zoho_custom_alter_changes_js_alter(&$javascript, $assets) { $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $current_path = \Drupal::service('path.current')->getPath(); $route = \Drupal::routeMatch()->getRouteName(); $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; } $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); $accessed_langcode = $accessed_language; if($accessed_language == 'ja') { $accessed_language = 'jp'; } $product_home_route = 'zoho_custom_alter_changes.zproductpage_'; if($accessed_language != 'en') { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $current_path))[1]; } else { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $current_path))[1]; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if(strpos($product_home_route, '_sites') !== false) { $product_home_route = 'zoho_custom_alter_changes.zproductpage_zsites'; } } if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { if($anonymous_user) { $core_js_files = array( 'core/assets/vendor/jquery/jquery.min.js', 'core/misc/drupalSettingsLoader.js', 'core/misc/drupal.js', 'core/misc/drupal.init.js' ); foreach ($core_js_files as $core_key => $core_value) { unset($javascript[$core_value]); } } } // if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') // { // $g_path = 'https://www.zohowebstatic.com/sites/all/themes/zoho/scripts/ipcallback.js'; // $javascript[$g_path]['group'] = '-900'; // $javascript[$g_path]['type'] = 'external'; // $g_path = 'https://zdblogs.zohocorp.com/themes/gin/custom/js/zdblogs-drupalSettingsLoader.js'; // $javascript[$g_path]['group'] = '-100'; // $javascript[$g_path]['type'] = 'external'; // } $unusedList_anonymous = array ( 'themes/gin/dist/js/init.js', 'core/misc/touchevents-test.js', 'core/misc/debounce.js', 'core/misc/announce.js', 'core/misc/message.js', 'core/themes/claro/js/messages.js', 'themes/gin/dist/js/toolbar.js', 'themes/gin/dist/js/accent.js', 'core/assets/vendor/jquery/jquery.min.js', 'core/misc/drupalSettingsLoader.js', 'core/misc/drupal.js', 'core/misc/drupal.init.js', ); $unusedList = array( "core/modules/statistics/statistics.js", "modules/contrib/nodeviewcount/nodeviewcount.js" ); // \Drupal::logger('javascript')->error('
    ' . print_r($javascript, TRUE) . '
    '); if($anonymous_user) { foreach ($unusedList_anonymous as $key => $value) { unset($javascript[$value]); } // $jquery_min = 'https://blog.zoho.com/core/assets/vendor/jquery/jquery.min.js'; // $javascript[$jquery_min] = array('type' => 'file', 'data' => $jquery_min, 'minified' =>true, 'weight' => -20, 'group' => -100, 'scope' => 'footer' ); // $dSettings_loader = 'https://blog.zoho.com/core/misc/drupalSettingsLoader.js'; // $javascript[$dSettings_loader] = array('type' => 'file', 'data' => $dSettings_loader, 'minified' =>true, 'weight' => -17.999, 'group' => -100, 'scope' => 'footer' ); // $drupal_js = 'https://blog.zoho.com/core/misc/drupal.js'; // $javascript[$drupal_js] = array('type' => 'file', 'data' => $drupal_js, 'minified' =>true, 'weight' => -17.997, 'group' => -100, 'scope' => 'footer' ); // $dInit = 'https://blog.zoho.com/core/misc/drupal.init.js'; // $javascript[$dInit] = array('type' => 'file', 'data' => $dInit, 'minified' =>true, 'weight' => -16.996, 'group' => -100, 'scope' => 'footer' ); } if(!$anonymous_user) { foreach ($unusedList as $key => $value) { unset($javascript[$value]); } } } function zoho_custom_alter_changes_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { $route = \Drupal::routeMatch()->getRouteName(); $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); if($anonymous_user && $route == 'user.login') { if(str_replace('-', '_', $variables['element']['#id']) == 'user_login_form') { if($hook == 'form' & !empty($variables['element']['#id'])) { $suggestions[] = 'form__' . str_replace('-', '_', $variables['element']['#id']); } } } } /** * Implements hook_preprocess_HOOK() for page_alter. */ function zoho_custom_alter_changes_theme_suggestions_page_alter(&$suggestions, $variables) { $route = \Drupal::routeMatch()->getRouteName(); if($route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') { $node = \Drupal::routeMatch()->getParameter('node_preview'); if(empty($node)) { $node = \Drupal::routeMatch()->getParameter('node'); } if(getType($node) == 'string') { $node = \Drupal\node\Entity\Node::load($node); } if(!empty($node)) { $content_type = $node->bundle(); $suggestions[] = 'page__'.$content_type; } } // if ($route == 'entity.taxonomy_term.canonical' && $tid = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) { // $term = \Drupal\taxonomy\Entity\Term::load($tid); // $suggestions[] = 'page__taxonomy__' . $term->bundle(); // } $error = ''; if($route == 'system.404') { $error = 404; } if(!empty($error)) { $suggestions[] = 'page__' . $error; } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; } $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); if($accessed_language == 'ja') { $accessed_language = 'jp'; } $current_path = \Drupal::service('path.current')->getPath(); $product_home_route = 'zoho_custom_alter_changes.zproductpage_'; if($accessed_language != 'en') { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $current_path))[1]; } else { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $current_path))[1]; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if(strpos($product_home_route, '_sites') !== false) { $product_home_route = 'zoho_custom_alter_changes.zproductpage_zsites'; } } if($route == 'zoho_custom_alter_changes.zhomepage') { $suggestions[] = 'page__article_home'; } if($route == $product_home_route) { $suggestions[] = 'page__product_home'; } if($route == 'zoho_custom_alter_changes.zauthorpage') { $suggestions[] = 'page__taxonomy__author'; } if($route == 'zoho_custom_alter_changes.ztagpage') { $suggestions[] = 'page__taxonomy__tags'; } } /* Custom html.html.twig file for no_theme template */ /** * implement hook */ function zoho_custom_alter_changes_theme_suggestions_html_alter(array &$suggestions, array $variables, $hook) { $route = \Drupal::routeMatch()->getRouteName(); if ($node = \Drupal::routeMatch()->getParameter('node')) { if (is_object($node)) { if($route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version') { if($node->getType() == 'product_header' || $node->getType() == 'common_header' || $node->getType() == 'common_footer') { // $suggestions[] = 'html__' . $node->getType(); $suggestions[] = 'html__custom_no_theme'; } if($node->getType() == 'no_theme') { $suggestions[] = 'html__no_theme'; } } } } } /* Custom html.html.twig file for no_theme template */ function zoho_custom_alter_changes_preprocess_field(&$variables) { $element = $variables['element']; if($element['#field_name'] == 'field_comments') { $route = \Drupal::routeMatch(); $all_user_array = \Drupal::service('entity_type.manager')->getStorage('user')->loadByProperties(); $accessed_language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $accessed_langcode = $accessed_language; if($accessed_language == 'ja') { $accessed_language = 'jp'; } $home_lang = ''; if($accessed_language != 'en') { $home_lang = '/'.$accessed_language; } $home_path = ''; $site_domain = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } if(empty($site_domain)) { $site_domain = $local_domain; } $live_page_status = '0'; if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { $live_page_status = '1'; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false && $accessed_language != 'en') { $home_path = $live_home_path.$home_lang; } else { if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { $home_path = $live_home_path.$home_lang; } else { $home_path = $local_home_path.$home_lang; } } $view = $route->getRouteName(); $node_path = ''; // $local_home_path = \Drupal::service('site.path'); if($view == 'entity.node.canonical' || $view == 'entity.node.preview') { $current_user = \Drupal::currentUser(); $anonymous_user = $current_user->isAnonymous(); $comment_user = array('uid'=>'0','name'=>'anonymous_user','author_id'=>''); if(!$anonymous_user) { $uid = $current_user->id(); $author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_user' => $uid]); $author_detail = array(); $author_exist = false; if(count($author_details) > 0) { $author_detail = current($author_details); if(!empty($author_detail)) { $name = $author_detail->field_author_display_name->value; $author_id = $author_detail->tid->value; $author_exist = true; } } if(!$author_exist) { $name = $current_user->getAccountName(); $author_id = ''; } $name = strtoupper($name); $comment_user = array('uid'=>$uid,'name'=>$name,'author_id'=>$author_id); } $variables['comment_user'] = $comment_user; $node = $route->getParameter('node'); if($view == 'entity.node.canonical') { $node_type = $node->type->target_id; $node_path = $node->toUrl('canonical', ['language' => $node->language()])->toString(); } $variables['home_path'] = $home_path; $variables['live_page_status'] = $live_page_status; $variables['accessed_language'] = $home_path; $variables['revert_home_path'] = $local_home_path.$home_lang; $variables['comment_node_path'] = $node_path; } $variables['view'] = $view; if($view == 'entity.node.canonical' || $view == 'entity.node.preview' || $view == 'entity.node.latest_version') { $comment_output = ''; $user_id_array = array(); $database = \Drupal::database(); $node = \Drupal::routeMatch()->getParameter('node_preview'); if(empty($node)) { $node = \Drupal::routeMatch()->getParameter('node'); } if($node->hasTranslation($accessed_language)) { $node = $node->getTranslation($accessed_language); } $node_id = $node->id(); $node_path = $home_path . $node->toUrl('canonical', ['language' => $node->language()])->toString(); $comment_status = $node->field_comments->status; // $comment_count = \Drupal::service('comment.statistics')->read(array_fill_keys([$node_id], ''), 'node')[0]->comment_count; $query = $database->select('comment_field_data', 'c') ->fields('c', ['cid','pid','uid']) ->condition('c.entity_id', $node_id) ->condition('c.langcode', $accessed_langcode) ->condition('c.status', '1') ->condition('c.entity_type', 'node') ->orderBy('cid', 'DESC') ->execute(); $query->allowRowCount = TRUE; $comment_count = $query->rowCount(); if($comment_count != 0) { $query_result = $query->fetchAll(); foreach($query_result as $result) { $cid = $result->cid; $pid = $result->pid; $uid = $result->uid; $user_id_array[$cid] = $uid; if($pid != null) { $comment_array[$pid][$cid] = $cid; } else { $comment_array['parent'][$cid] = $cid; } } $comment_output .= '

    '.$comment_count.' '.t("Replies to").' '.$node->title->value.'

    '; $comment_output .= '
      '; $total_count = 1; foreach($comment_array['parent'] as $parent_comment) { $parent_id = $parent_comment; $user_id = $user_id_array[$parent_id]; $comment_type = $total_count%2; if($user_id != '0') { if($comment_type == 1) { $c_t_class = 'odd alt'; } else { $c_t_class = 'even'; } // $user_obj = \Drupal\user\Entity\User::load($user_id); $user_obj = $all_user_array[$user_id]; $user_name = strtolower($user_obj->name->value); $class_name = "comment byuser comment-author-".$user_name." bypostauthor ".$c_t_class." depth-1"; } else { if($comment_type == 1) { $c_t_class = 'odd alt thread-even'; } else { $c_t_class = 'even thread-odd thread-alt'; } $class_name = "comment ".$c_t_class." depth-1"; } $comment_output .= '
    1. '; $comment_output .= zoho_custom_alter_changes_comments_format($parent_id,$node_id,$node_path,$all_user_array,$local_domain); if(isset($comment_array[$parent_id])) { $comment_output .= '
        '; foreach($comment_array[$parent_id] as $first_level) { $total_count++; $first_level_pid = $first_level; $first_level_user_id = $user_id_array[$first_level_pid]; $first_level_comment_type = $total_count%2; if($first_level_user_id != '0') { if($first_level_comment_type == 1) { $first_level_c_t_class = 'odd alt'; } else { $first_level_c_t_class = 'even'; } // $first_level_user_obj = \Drupal\user\Entity\User::load($first_level_user_id); $first_level_user_obj = $all_user_array[$first_level_user_id]; $first_level_user_name = strtolower($first_level_user_obj->name->value); $first_level_class_name = "comment byuser comment-author-".$first_level_user_name." bypostauthor ".$first_level_c_t_class." depth-2"; } else { if($first_level_comment_type == 1) { $first_level_c_t_class = 'odd alt thread-even'; } else { $first_level_c_t_class = 'even thread-odd thread-alt'; } $first_level_class_name = "comment ".$first_level_c_t_class." depth-2"; } $comment_output .= '
      1. '; $comment_output .= zoho_custom_alter_changes_comments_format($first_level_pid,$node_id,$node_path,$all_user_array,$local_domain); if(isset($comment_array[$first_level_pid])) { $comment_output .= '
          '; foreach($comment_array[$first_level_pid] as $second_level) { $total_count++; $second_level_pid = $second_level; $second_level_user_id = $user_id_array[$second_level_pid]; $second_level_comment_type = $total_count%2; if($second_level_user_id != '0') { if($second_level_comment_type == 1) { $second_level_c_t_class = 'odd alt'; } else { $second_level_c_t_class = 'even'; } // $second_level_user_obj = \Drupal\user\Entity\User::load($second_level_user_id); $second_level_user_obj = $all_user_array[$second_level_user_id]; $second_level_user_name = strtolower($second_level_user_obj->name->value); $second_level_class_name = "comment byuser comment-author-".$second_level_user_name." bypostauthor ".$second_level_c_t_class." depth-3"; } else { if($second_level_comment_type == 1) { $second_level_c_t_class = 'odd alt thread-even'; } else { $second_level_c_t_class = 'even thread-odd thread-alt'; } $second_level_class_name = "comment ".$second_level_c_t_class." depth-3"; } $comment_output .= '
        1. '; $comment_output .= zoho_custom_alter_changes_comments_format($second_level_pid,$node_id,$node_path,$all_user_array,$local_domain); if(isset($comment_array[$second_level_pid])) { $comment_output .= '
            '; foreach($comment_array[$second_level_pid] as $third_level) { $total_count++; $third_level_pid = $third_level; $third_level_user_id = $user_id_array[$third_level_pid]; $third_level_comment_type = $total_count%2; if($third_level_user_id != '0') { if($third_level_comment_type == 1) { $third_level_c_t_class = 'odd alt'; } else { $third_level_c_t_class = 'even'; } // $third_level_user_obj = \Drupal\user\Entity\User::load($third_level_user_id); $third_level_user_obj = $all_user_array[$third_level_user_id]; $third_level_user_name = strtolower($third_level_user_obj->name->value); $third_level_class_name = "comment byuser comment-author-".$third_level_user_name." bypostauthor ".$third_level_c_t_class." depth-4"; } else { if($third_level_comment_type == 1) { $third_level_c_t_class = 'odd alt thread-even'; } else { $third_level_c_t_class = 'even thread-odd thread-alt'; } $third_level_class_name = "comment ".$third_level_c_t_class." depth-4"; } $comment_output .= '
          1. '; $comment_output .= zoho_custom_alter_changes_comments_format($third_level_pid,$node_id,$node_path,$all_user_array,$local_domain); $comment_output .= '
          2. '; } $comment_output .= '
          '; } $comment_output .= '
        2. '; } $comment_output .= '
        '; } $comment_output .= '
      2. '; } $comment_output .= '
      '; } $comment_output .= '
    2. '; $total_count++; } $comment_output .= '
    '; if($comment_status == '1') { $privacy_link_array = array('en'=>'https://www.zoho.com/privacy.html','es-xl'=>'https://www.zoho.com/es-xl/privacy.html','pt-br'=>'https://www.zoho.com/pt-br/privacy.html','ar'=>'https://www.zoho.com/ar/privacy.html','id'=>'https://www.zoho.com/id/privacy.html','fr'=>'https://www.zoho.com/fr/privacy.html','th'=>'https://www.zoho.com/th/privacy.html'); $comment_output .= '

    '.t("Comments are closed.").'

    '.t("By submitting this form, you agree to the processing of personal data according to our").' '.''.t("Privacy Policy.").''; } } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false && $accessed_language != 'en' && !empty($group_details)) { $comment_output = str_replace($home_path, '/'.$accessed_language.$live_home_path, $comment_output); } $variables['comment_output'] = array('value' => $comment_output); } } } function zoho_custom_alter_changes_comments_format($cid,$node_id,$node_path,$all_user_array,$local_domain) { $comment_obj = \Drupal::entityTypeManager()->getStorage('comment')->load($cid); $uid = $comment_obj->getOwnerId(); $user = array(); $img_src = 'https://blog.zoho.com/sites/zblogs/images/author_profile/avatar.png'; $img_alt = ''; $img_title = ''; if($uid != '0') { $user = $all_user_array[$uid]; $author_details = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'author', 'status' => 1, 'field_user' => $uid]); $author_detail = array(); $author_exist = false; if(count($author_details) > 0) { $author_detail = current($author_details); if(!empty($author_detail)) { $author_name = $author_detail->field_author_display_name->value; $author_exist = true; } } if($author_exist) { $img_entity = $author_detail->field_profile_picture->entity; if(!empty($img_entity)) { $img_src = $local_domain.$img_entity->field_image_url->value; $img_alt = $local_domain.$img_entity->field_alt_text->value; $img_title = $local_domain.$img_entity->field_title_text->value; } } } $created_time = $comment_obj->created->value; $datetime = date('y-m-d\Th:i:s+00:00',$created_time); $date = date('F j, Y \a\t g:i A',$created_time); $author = $comment_obj->field_author->value; $comment = $comment_obj->field_comment_body->value; $comment = zoho_custom_alter_changes_txt_to_url($comment); if(isset($comment_obj->field_url->value)) { $website_url = $comment_obj->field_url->value; $website_url_parsed = parse_url($website_url); if(!isset($website_url_parsed['scheme'])) { $website_url = 'http://'.$website_url; } $author_tag = ''.$author.''; } else { $author_tag = $author; } $comment_output = ''; return $comment_output; } /** * Implements hook_mail(). */ function zoho_custom_alter_changes_mail($key, &$message, $params) { // $subject = $params['subject'] ? $params['subject'] : ''; // $body = $params['message'] ? $params['message'] : ''; // switch ($key) // { // case 'theme_editor': // $message['from'] = 'cms-team@zohocorp.com'; // $message['subject'] = $subject; // $message['body'][] = $body; // break; // } } function zoho_custom_alter_changes_txt_to_url($string) { //text to url $url = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/'; // $string= preg_replace($url, '$0', $string); //A link with the "mailto:" prefix $email_regex = '/([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/i'; $string = preg_replace($email_regex, '$0', $string); return $string; } /** * Implements hook_preprocess_HOOK(). * Implements hook_preprocess_pager(). * * @param $variables */ function zoho_custom_alter_changes_preprocess_pager(&$variables) { $route = \Drupal::routeMatch()->getRouteName(); $path = \Drupal::service('path.current')->getPath(); $local_domain = ''; $live_domain = ''; $local_home_path = ''; $live_home_path = ''; $group_details = zoho_custom_alter_changes_group_node_details(); if(!empty($group_details)) { $local_domain = $group_details['local_domain']; $live_domain = $group_details['live_domain']; $local_home_path = $group_details['local_home_path']; $live_home_path = $group_details['live_home_path']; } $site_domain = ''; $home_path = ''; $server_header_details = $_SERVER; if(isset($server_header_details['HTTP_X_FORWARDED_SERVER'])) { $site_domain = $server_header_details['HTTP_X_FORWARDED_SERVER']; } if(empty($site_domain)) { $site_domain = $local_domain; } $accessed_language_obj = \Drupal::languageManager()->getCurrentLanguage(); $accessed_language = $accessed_language_obj->getId(); if($accessed_language == 'ja') { $accessed_language = 'jp'; } $product_home_route = 'zoho_custom_alter_changes.zproductpage_'; if($accessed_language != 'en') { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/'.$accessed_language.'/',$local_home_path.'/'.$accessed_language.'/'), array('/','/'), $path))[1]; } else { $product_home_route = $product_home_route.explode('/',str_replace(array($local_domain.$local_home_path.'/',$local_home_path.'/'), array('/','/'), $path))[1]; } if(!empty($site_domain) && strpos($local_domain, $site_domain) === false) { if(strpos($product_home_route, '_sites') !== false) { $product_home_route = 'zoho_custom_alter_changes.zproductpage_zsites'; } } $variables['pager_modify'] = '0'; if($route == 'system.404' || $route == 'entity.node.canonical' || $route == 'entity.node.preview' || $route == 'entity.node.latest_version' || $route == 'zoho_custom_alter_changes.zhomepage' || $route == $product_home_route || $route == 'zoho_custom_alter_changes.zauthorpage' || $route == 'zoho_custom_alter_changes.ztagpage') { $current_path_pager = parse_url(\Drupal::request()->getRequestUri())['path']; if(!empty($site_domain) && strpos($site_domain,$local_domain) === false) { $home_lang = ''; if($accessed_language != 'en') { $home_lang = '/'.$accessed_language; } $home_path = $live_home_path.$home_lang; $current_path_pager = $home_path.$current_path_pager; } $current_pager = ''; if(isset($_GET['page'])) { $current_pager = urlencode($_GET['page']); } if(empty($current_pager) || $current_pager < 1 || !is_numeric($current_pager)) { $current_pager = 0; } $current_pager = round($current_pager) + 1; $total_pager_count = 0; $total_pager_count = \Drupal::config('zoho_custom_alter_changes.settings')->get('zoho_custom_alter_changes_pager_count'); // if(isset($variables['items']['pages'])) // { // if(!empty($variables['items']['pages'])) // { // $total_pager_count = count($variables['items']['pages']); // } // } $variables['current_path'] = $current_path_pager; $variables['current_pager'] = $current_pager; $variables['total_pager_count'] = $total_pager_count; $variables['pager_modify'] = '1'; } }