Exemplo n.º 1
0
function fn_seo_settings_update($type, $option, $new_value, $redirect_only)
{
    $old_value = Registry::get('addons.seo.' . $option);
    fn_iterate_through_seo_names(function ($seo_name) use($option, $old_value, $new_value, $redirect_only) {
        // We shouldn't consider null value
        if (false === fn_check_seo_object_exists($seo_name['object_id'], $seo_name['type'], $seo_name['company_id'])) {
            fn_delete_seo_name($seo_name['object_id'], $seo_name['type'], '', $seo_name['company_id']);
            return;
        }
        Registry::set('addons.seo.' . $option, $old_value);
        $url = fn_generate_seo_url_from_schema(array('type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'lang_code' => $seo_name['lang_code']), false);
        fn_seo_update_redirect(array('src' => $url, 'type' => $seo_name['type'], 'object_id' => $seo_name['object_id'], 'company_id' => $seo_name['company_id'], 'lang_code' => $seo_name['lang_code']), 0, false);
        if (!$redirect_only) {
            Registry::set('addons.seo.' . $option, $new_value);
            fn_create_seo_name($seo_name['object_id'], $seo_name['type'], $seo_name['name'], 0, '', $seo_name['company_id'], $seo_name['lang_code'], true);
        }
    }, db_quote("type = ?s ?p", $type, fn_get_seo_company_condition('?:seo_names.company_id', $type)));
}
Exemplo n.º 2
0
/**
 * Updates SEO names according to path when parent was changed for object.
 *
 * @param integer $object_id   object ID
 * @param string  $object_type object type
 * @param array   $params      params
 *
 * @return bool Whether SEO-names were regenerated successfully.
 */
function fn_seo_update_tree_object($object_id, $object_type, $params)
{
    if (isset($params['old_id_path']) && empty($params['old_id_path'])) {
        return false;
        // newly created object, skip
    }
    // Update item itself if it wasn't deleted
    if (!isset($params['after_deletion']) || !$params['after_deletion']) {
        $lang_codes = array();
        $seo_settings = fn_get_seo_settings($params['company_id']);
        if ($seo_settings['single_url'] == 'Y') {
            $lang_codes[] = Registry::get('settings.Appearance.frontend_default_language');
        } else {
            $lang_codes = array_keys(Languages::getAll());
        }
        foreach ($lang_codes as $lang_code) {
            $seo_name = fn_seo_get_name($object_type, $object_id, '', $params['company_id'], $lang_code);
            fn_create_seo_name($object_id, $object_type, $seo_name, 0, '', $params['company_id'], $lang_code, true);
        }
    }
    if (empty($params['old_id_path'])) {
        return true;
    }
    $condition = fn_get_seo_company_condition('?:seo_names.company_id', '', $params['company_id']);
    // Regenerate siblings' SEO-names
    fn_iterate_through_seo_names('fn_regenerate_seo_name', db_quote("path = ?s AND type IN (?a) ?p", $params['old_id_path'], $params['object_types'], $condition));
    // Regenerate children SEO-names
    fn_iterate_through_seo_names('fn_regenerate_seo_name', db_quote("path LIKE ?l AND type IN (?a) ?p", $params['old_id_path'] . '/%', $params['object_types'], $condition));
    return true;
}