/** * Updates SEO name for object * @param array $object_data object data * @param array $object_id object ID * @param string $type object type * @param string $lang_code language code * @return mixed, updated SEO name on success, false on failure */ function fn_seo_update_object($object_data, $object_id, $type, $lang_code) { fn_set_hook('seo_update_objects_pre', $object_data, $object_id, $type, $lang_code, $seo_objects); if (!empty($object_id) && isset($object_data['seo_name'])) { $_object_name = ''; $seo_vars = fn_get_seo_vars($type); if (!empty($object_data['seo_name'])) { $_object_name = $object_data['seo_name']; } elseif (!empty($object_data[$seo_vars['description']])) { $_object_name = $object_data[$seo_vars['description']]; } if (empty($_object_name)) { $_object_name = fn_seo_get_default_object_name($object_id, $type, $lang_code); } $_company_id = ''; if (fn_allowed_for('ULTIMATE')) { if (!empty($seo_vars['not_shared']) && Registry::get('runtime.company_id')) { $_company_id = Registry::get('runtime.company_id'); } elseif (!empty($object_data['company_id'])) { $_company_id = $object_data['company_id']; } } $lang_code = fn_get_corrected_seo_lang_code($lang_code); // always create redirect, execept it manually disabled $create_redirect = isset($object_data['seo_create_redirect']) ? !empty($object_data['seo_create_redirect']) : true; $is_tree_object = fn_check_seo_schema_option($seo_vars, 'tree_options'); // If this is tree object and we need to create redirect - create it for all children if ($create_redirect && $is_tree_object) { $i = 0; $items_per_pass = 100; $children = fn_seo_get_object_children($type); if (!empty($children)) { $path = fn_get_seo_parent_path($object_id, $type); $path .= !empty($path) ? '/' . $object_id : $object_id; while ($data = db_get_array("SELECT object_id, type FROM ?:seo_names WHERE path = ?s OR path LIKE ?l AND type IN (?a) LIMIT ?i, ?i", $path, $path . '/%', $children, $i, $items_per_pass)) { $i += $items_per_pass; foreach ($data as $obj) { $url = fn_generate_seo_url_from_schema(array('type' => $obj['type'], 'object_id' => $obj['object_id'], 'lang_code' => $lang_code), false); fn_seo_update_redirect(array('src' => $url, 'type' => $obj['type'], 'object_id' => $obj['object_id'], 'company_id' => $_company_id, 'lang_code' => $lang_code), 0, false); } } } } fn_create_seo_name($object_id, $type, $_object_name, 0, '', $_company_id, $lang_code, $create_redirect); return true; } return false; }
/** * Updates SEO name for object * @param array $object_data object data * @param array $object_id object ID * @param string $type object type * @param string $lang_code language code * @return mixed, updated SEO name on success, false on failure */ function fn_seo_update_object($object_data, $object_id, $type, $lang_code) { fn_set_hook('seo_update_objects_pre', $object_data, $object_id, $type, $lang_code, $seo_objects); if (!empty($object_id) && isset($object_data['seo_name'])) { $_company_id = ''; if (fn_allowed_for('ULTIMATE')) { if (!empty($seo_vars['not_shared']) && Registry::get('runtime.company_id')) { $_company_id = Registry::get('runtime.company_id'); } elseif (!empty($object_data['company_id'])) { $_company_id = $object_data['company_id']; } } // Do nothing if SEO name was not changed $old_name = fn_seo_get_name($type, $object_id, '', $_company_id, $lang_code); if ($object_data['seo_name'] == $old_name) { return true; } $_object_name = ''; $seo_vars = fn_get_seo_vars($type); if (!empty($object_data['seo_name'])) { $_object_name = $object_data['seo_name']; } elseif (!empty($object_data[$seo_vars['description']])) { $_object_name = $object_data[$seo_vars['description']]; } if (empty($_object_name)) { $_object_name = fn_seo_get_default_object_name($object_id, $type, $lang_code); } $lang_code = fn_get_corrected_seo_lang_code($lang_code); // always create redirect, execept it manually disabled $create_redirect = isset($object_data['seo_create_redirect']) ? !empty($object_data['seo_create_redirect']) : true; $is_tree_object = fn_check_seo_schema_option($seo_vars, 'tree_options'); // If this is tree object and we need to create redirect - create it for all children if ($create_redirect && $is_tree_object) { $children = fn_seo_get_object_children($type); if (!empty($children)) { $path = fn_get_seo_parent_path($object_id, $type); $path .= !empty($path) ? '/' . $object_id : $object_id; fn_iterate_through_seo_names(function ($seo_name) use($_company_id, $lang_code) { $url = fn_generate_seo_url_from_schema(array('type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'lang_code' => $lang_code), false); fn_seo_update_redirect(array('src' => $url, 'type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'company_id' => $_company_id, 'lang_code' => $lang_code), 0, false); }, db_quote("path = ?s OR path LIKE ?l AND type IN (?a)", $path, $path . '/%', $children)); } } fn_create_seo_name($object_id, $type, $_object_name, 0, '', $_company_id, $lang_code, $create_redirect); return true; } return false; }