function piklist($option, $arguments = array())
{
    if (!is_array($arguments) && strstr($arguments, '=')) {
        parse_str($arguments, $arguments);
    }
    if (is_array($option) || is_object($option)) {
        $list = array();
        $arguments = is_array($arguments) ? $arguments : array($arguments);
        foreach ($option as $key => $value) {
            if (count($arguments) > 1) {
                if (in_array('_key', $arguments)) {
                    $_value = $arguments[1];
                    $list[$key] = is_object($value) ? $value->{$_value} : $value[$_value];
                } else {
                    $__key = $arguments[0];
                    $_key = is_object($value) ? $value->{$__key} : (isset($value[$__key]) ? $value[$__key] : null);
                    $_value = $arguments[1];
                    $list[$_key] = is_object($value) ? $value->{$_value} : (isset($value[$_value]) ? $value[$_value] : null);
                }
            } else {
                $_value = $arguments[0];
                array_push($list, is_object($value) && isset($value->{$_value}) ? $value->{$_value} : (isset($value[$_value]) ? $value[$_value] : null));
            }
        }
        return $list;
    } else {
        switch ($option) {
            case 'field':
                if (piklist_setting::get('active_section')) {
                    piklist_setting::register_setting($arguments);
                } else {
                    piklist_form::render_field($arguments, isset($arguments['return']) ? $arguments['return'] : false);
                }
                break;
            case 'list_table':
                piklist_list_table::render($arguments);
                break;
            case 'post_type_labels':
                return piklist::post_type_labels($arguments);
                break;
            case 'taxonomy_labels':
                return piklist::taxonomy_labels($arguments);
                break;
            case 'option':
            case 'post_custom':
            case 'post_meta':
            case 'get_post_custom':
            case 'user_custom':
            case 'user_meta':
            case 'get_user_custom':
            case 'term_custom':
            case 'term_meta':
            case 'get_term_custom':
                switch ($option) {
                    case 'user_custom':
                    case 'user_meta':
                    case 'get_user_custom':
                        $type = 'user';
                        break;
                    case 'term_custom':
                    case 'term_meta':
                    case 'get_term_custom':
                        $type = 'term';
                        break;
                    case 'post_custom':
                    case 'post_meta':
                    case 'get_post_custom':
                        $type = 'post';
                        break;
                    default:
                        $type = 'option';
                        break;
                }
                return piklist::object($type, $arguments);
                break;
            case 'dashes':
                return piklist::dashes($arguments);
                break;
            case 'slug':
                return piklist::slug($arguments);
                break;
            case 'performance':
                piklist::performance();
                break;
            case 'include_meta_boxes':
                // TODO: Improve
                if (isset($arguments['post_type'])) {
                    $post_type = $arguments['post_type'];
                    unset($arguments['post_type']);
                } else {
                    $post_type = null;
                }
                piklist::include_meta_boxes($arguments, $post_type);
                break;
            case 'include_actions':
                // TODO: Improve
                if (isset($arguments['action'])) {
                    $post_type = $arguments['action'];
                    unset($arguments['action']);
                }
                piklist::include_actions($action, $arguments);
                break;
            case 'include_user_profile_fields':
                piklist_user::include_user_profile_fields($arguments);
                break;
            case 'comments_template':
                $file = isset($arguments[0]) ? $arguments[0] : '/comments.php';
                $seperate_comments = isset($arguments[1]) ? $arguments[1] : false;
                piklist_comments::comments_template($file, $seperate_comments);
                break;
            default:
                $return = isset($arguments['return']) ? $arguments['return'] : false;
                $loop = isset($arguments['loop']) ? $arguments['loop'] : null;
                unset($arguments['return']);
                unset($arguments['loop']);
                return piklist::render($option, $arguments, $return, $loop);
                break;
        }
    }
}
Exemplo n.º 2
0
/**
 * piklist
 * The core helper function for the Piklist framework.
 *
 * @since 1.0
 */
function piklist($option, $arguments = array())
{
    if (!is_array($arguments) && strstr($arguments, '=')) {
        parse_str($arguments, $arguments);
    }
    if (is_array($option) || is_object($option)) {
        return empty($arguments) ? piklist::object_format($option) : piklist::pluck($option, $arguments);
    } else {
        switch ($option) {
            case 'field':
                if (piklist_setting::get('active_section')) {
                    piklist_setting::register_setting($arguments);
                } else {
                    return piklist_form::render_field($arguments, isset($arguments['return']) ? $arguments['return'] : false);
                }
                break;
            case 'form':
                return piklist_form::render_form($arguments['form'], isset($arguments['add_on']) ? $arguments['add_on'] : null);
                break;
            case 'list_table':
                piklist_list_table::render($arguments);
                break;
            case 'post_type_labels':
                return piklist::post_type_labels($arguments);
                break;
            case 'taxonomy_labels':
                return piklist::taxonomy_labels($arguments);
                break;
            case 'option':
            case 'post_custom':
            case 'post_meta':
            case 'get_post_custom':
            case 'user_custom':
            case 'user_meta':
            case 'get_user_custom':
            case 'term_custom':
            case 'term_meta':
            case 'get_term_custom':
                switch ($option) {
                    case 'user_custom':
                    case 'user_meta':
                    case 'get_user_custom':
                        $type = 'user';
                        break;
                    case 'term_custom':
                    case 'term_meta':
                    case 'get_term_custom':
                        $type = 'term';
                        break;
                    case 'post_custom':
                    case 'post_meta':
                    case 'get_post_custom':
                        $type = 'post';
                        break;
                    default:
                        $type = 'option';
                        break;
                }
                return piklist::object($type, $arguments);
                break;
            case 'dashes':
                return piklist::dashes($arguments);
                break;
            case 'slug':
                return piklist::slug($arguments);
                break;
            case 'humanize':
                return piklist::humanize($arguments);
                break;
            case 'performance':
                piklist::performance();
                break;
            case 'comments_template':
                $file = isset($arguments[0]) ? $arguments[0] : '/comments.php';
                $seperate_comments = isset($arguments[1]) ? $arguments[1] : false;
                piklist_comments::comments_template($file, $seperate_comments);
                break;
            case 'include_meta_boxes':
                piklist::render('shared/notice', array('content' => sprintf(__('This page is using the old Piklist WorkFlow system. Please update your code to the %snew WorkFlow system%s.', 'piklist'), '<a href="https://piklist.com/user-guide/docs/building-workflows-piklist-v0-9-9/" target="_blank">', '</a>'), 'notice_type' => 'error'));
                break;
            case 'prefix':
                return piklist::$prefix;
                break;
            case 'url':
                return isset(piklist::$add_ons[$arguments]) ? piklist::$add_ons[$arguments]['url'] : null;
                break;
            case 'path':
                return isset(piklist::$add_ons[$arguments]) ? piklist::$add_ons[$arguments]['path'] : null;
                break;
            default:
                $return = isset($arguments['return']) ? $arguments['return'] : false;
                $loop = isset($arguments['loop']) ? $arguments['loop'] : null;
                unset($arguments['return']);
                unset($arguments['loop']);
                return piklist::render($option, $arguments, $return, $loop);
                break;
        }
    }
}