Ejemplo n.º 1
0
/**
 * @since 3.4
 */
function qtranxf_standardize_admin_config($configs)
{
    foreach ($configs as $k => $config) {
        if (!is_array($config)) {
            continue;
        }
        if ($k === 'forms') {
            foreach ($config as $form_id => $frm) {
                if (isset($frm['form']['id'])) {
                    $id = $frm['form']['id'];
                    unset($frm['form']['id']);
                    if (empty($frm['form'])) {
                        unset($frm['form']);
                    }
                    $configs['forms'][$id] = $frm;
                    if ($id !== $form_id) {
                        unset($configs['forms'][$form_id]);
                    }
                    $form_id = $id;
                }
                if (isset($frm['fields'])) {
                    $configs['forms'][$form_id]['fields'] = qtranxf_standardize_config_fields($frm['fields']);
                }
            }
        } else {
            if ($k === 'anchors') {
                if (empty($config)) {
                    unset($configs['anchors']);
                } else {
                    foreach ($configs['anchors'] as $k => $anchor) {
                        $id = qtranxf_standardize_config_anchor($anchor);
                        if (is_null($id)) {
                            unset($configs['anchors'][$k]);
                        } else {
                            if (is_string($id)) {
                                $configs['anchors'][$id] = $anchor;
                                if ($id !== $k) {
                                    unset($configs['anchors'][$k]);
                                }
                            }
                        }
                    }
                    if (empty($configs['anchors'])) {
                        unset($configs['anchors']);
                    }
                }
            } else {
                $configs[$k] = qtranxf_standardize_admin_config($config);
                //recursive call
            }
        }
    }
    return $configs;
}
Ejemplo n.º 2
0
/**
 * filters i18n configurations for the current page
 */
function qtranxf_parse_page_config($config, $url_path, $url_query)
{
    global $q_config;
    //$q_config['i18n-log-dir'] = WP_CONTENT_DIR.'/i18n-config'; //qtranxf_dbg
    if (isset($q_config['i18n-log-dir'])) {
        if (!file_exists($q_config['i18n-log-dir'])) {
            if (!mkdir($q_config['i18n-log-dir'])) {
                unset($q_config['i18n-log-dir']);
            }
        }
        if (isset($q_config['i18n-log-dir'])) {
            qtranxf_write_config_log($config, 'all-pages');
        }
    }
    //qtranxf_dbg_log('qtranxf_parse_page_config: $url_path: "'.$url_path.'"; $url_query: "'.$url_query.'"');
    //qtranxf_dbg_log('qtranxf_parse_page_config: $config: ', $config);
    $page_configs = array();
    foreach ($config as $pgkey => $pgcfg) {
        $d = isset($pgcfg['preg_delimiter']) ? $pgcfg['preg_delimiter'] : '!';
        $matched = qtranxf_match_page($pgcfg, $url_path, $url_query, $d);
        //qtranxf_dbg_log('qtranxf_parse_page_config: $pgcfg: ', $pgcfg);
        //qtranxf_dbg_log('qtranxf_parse_page_config: $matched: ', $matched);
        if ($matched === false) {
            continue;
        }
        $post_type_key = '';
        if (isset($pgcfg['post_type'])) {
            if (is_string($pgcfg['post_type'])) {
                $post_type_key = $d . $pgcfg['post_type'] . $d;
                unset($pgcfg['post_type']);
            } else {
                $post_type_key = serialize($pgcfg['post_type']);
                foreach ($pgcfg['post_type'] as $k => $item) {
                    $pgcfg['post_type'][$k] = $d . $item . $d;
                }
            }
        }
        if (!isset($page_configs[$post_type_key])) {
            $page_configs[$post_type_key] = array();
        }
        $page_config =& $page_configs[$post_type_key];
        foreach ($pgcfg as $key => $cfg) {
            if (empty($cfg)) {
                continue;
            }
            if ($key === 'anchors') {
                //Anchor elements are defined by id only.
                //Merge unique id values only:
                foreach ($cfg as $k => $anchor) {
                    $id = qtranxf_standardize_config_anchor($anchor);
                    if (is_null($id)) {
                        continue;
                    }
                    if (!is_string($id)) {
                        $id = $k;
                    }
                    if (!isset($page_config['anchors'])) {
                        $page_config['anchors'] = array();
                    }
                    $page_config['anchors'][$id] = $anchor;
                }
            } else {
                if ($key === 'forms') {
                    if (!isset($page_config['forms'])) {
                        $page_config['forms'] = array();
                    }
                    foreach ($cfg as $form_id => $pgcfg_form) {
                        if (!isset($pgcfg_form['fields'])) {
                            continue;
                        }
                        // convert obsolete format for 'fields'
                        foreach ($pgcfg_form['fields'] as $k => $f) {
                            if (!isset($f['id'])) {
                                continue;
                            }
                            $id = $f['id'];
                            unset($f['id']);
                            $pgcfg_form['fields'][$id] = $f;
                            if ($id !== $k) {
                                unset($pgcfg_form['fields'][$k]);
                            }
                        }
                        //figure out obsolete id of form/collection
                        if (is_string($form_id)) {
                            $id = $form_id;
                        } else {
                            if (isset($pgcfg_form['form']['id'])) {
                                $id = $pgcfg_form['form']['id'];
                                unset($pgcfg_form['form']['id']);
                                if (empty($pgcfg_form['form'])) {
                                    unset($pgcfg_form['form']);
                                }
                            } else {
                                $id = '';
                            }
                        }
                        if (!isset($page_config['forms'][$id])) {
                            $page_config['forms'][$id] = $pgcfg_form;
                        } else {
                            $page_config['forms'][$id] = qtranxf_merge_config($page_config['forms'][$id], $pgcfg_form);
                        }
                    }
                } else {
                    if (!isset($page_config[$key])) {
                        $page_config[$key] = $cfg;
                    } else {
                        $page_config[$key] = qtranxf_merge_config($page_config[$key], $cfg);
                    }
                }
            }
        }
    }
    //qtranxf_dbg_log('qtranxf_parse_page_config: $page_configs: ', $page_configs);
    foreach ($page_configs as $post_type_key => &$page_config) {
        if (!empty($post_type_key)) {
            //qtranxf_dbg_log('qtranxf_parse_page_config: $post_type_key="'.$post_type_key.'"; page_config: ', $page_config);
            if (!empty($page_config)) {
                //clean up 'fields'
                if (!empty($page_config['forms'])) {
                    foreach ($page_config['forms'] as $form_id => $frm) {
                        if (!isset($frm['fields'])) {
                            continue;
                        }
                        foreach ($frm['fields'] as $k => $f) {
                            if (qtranxf_set_field_jquery($f)) {
                                $page_config['forms'][$form_id]['fields'][$k] = $f;
                            }
                        }
                    }
                }
                foreach ($page_config as $k => $cfg) {
                    if (empty($cfg)) {
                        unset($page_config[$k]);
                    }
                }
            }
        }
        if (empty($page_config)) {
            unset($page_configs[$post_type_key]);
        }
    }
    if (isset($q_config['i18n-log-dir'])) {
        qtranxf_write_config_log($page_configs, 'by-post-type', $url_path, $url_query);
    }
    return $page_configs;
}