GetDataField() public static method

@param string $customFieldName
public static GetDataField ( string $customFieldName, integer $groupIndex = 1, integer $fieldIndex = 1, integer $postId )
$customFieldName string
$groupIndex integer @param integer $fieldIndex @param integer $postId
$fieldIndex integer
$postId integer
Example #1
0
function mf_shortcodes($atts)
{
    global $post, $FIELD_TYPES;
    extract(shortcode_atts(array('field' => 'no field defined or field name is wrong', 'eip' => FALSE, 'filtered' => FALSE, 'imgtag' => FALSE, 'label' => "", 'loop' => FALSE, 'loopseparator' => "|", 'checked' => "yes", 'groupindex' => 1, 'fieldindex' => 1), $atts));
    if ($loop && RCCWP_CustomField::GetFieldDuplicates($post->ID, $field, $groupindex) > 1) {
        $fieldduplicatedata = get_field_duplicate($field);
    } else {
        $fielddata = RCCWP_CustomField::GetDataField($field, $groupindex, $fieldindex, $post->ID);
    }
    $fieldType = $fielddata['type'];
    $fieldID = $fielddata['id'];
    $fieldObject = $fielddata['properties'];
    $fieldValues = (array) $fielddata['meta_value'];
    $fieldMetaID = $fielddata['meta_id'];
    $fieldresults = GetProcessedFieldValue($fieldValues, $fieldType, $fieldObject);
    $shortcode_data = $fieldresults;
    if ($fielddata['type'] == $FIELD_TYPES['multiline_textbox'] && $filtered) {
        $shortcode_data = apply_filters('the_content', $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['image']) {
        $imgresults = split('&', $fieldresults);
        if ($imgtag) {
            $shortcode_data = "<img src=\"{$imgresults['0']}\"/>";
        } else {
            $shortcode_data = $imgresults[0];
        }
    }
    if ($fielddata['type'] == $FIELD_TYPES['listbox']) {
        $shortcode_data = implode(",", $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['checkbox_list']) {
        $shortcode_data = implode(",", $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['checkbox']) {
        if ($fieldresults) {
            $shortcode_data = $checked;
        }
    }
    if ($shortcode_data || $fieldduplicatedata) {
        if ($label) {
            $shortcode_data = $label . $shortcode_data;
        } else {
            $shortcode_data = get_label($field) . " : " . $shortcode_data;
        }
        /////
        if ($field == "duplicate") {
            if ($loop) {
                return implode($loopseparator, $fieldduplicatedata);
            } else {
                return $shortcode_data;
            }
        } else {
            return $shortcode_data;
        }
        /////
    } else {
        return "no data found, please check the field name";
    }
}
Example #2
0
function mf_shortcodes($atts)
{
    global $post, $FIELD_TYPES;
    extract(shortcode_atts(array('field' => 'no field defined or field name is wrong', 'eip' => FALSE, 'filtered' => FALSE, 'imgtag' => FALSE, 'label' => "", 'loop' => FALSE, 'loopseparator' => "|", 'checked' => "yes", 'groupindex' => 1, 'fieldindex' => 1), $atts));
    if ($loop && RCCWP_CustomField::GetFieldDuplicates($post->ID, $field, $groupindex) > 1) {
        $fieldduplicatedata = get_field_duplicate($field);
    } else {
        $fielddata = RCCWP_CustomField::GetDataField($field, $groupindex, $fieldindex, $post->ID);
    }
    $fieldType = $fielddata['type'];
    $fieldID = $fielddata['id'];
    $fieldObject = $fielddata['properties'];
    $fieldValues = (array) $fielddata['meta_value'];
    $fieldMetaID = $fielddata['meta_id'];
    $fieldresults = GetProcessedFieldValue($fieldValues, $fieldType, $fieldObject);
    $shortcode_data = $fieldresults;
    if ($fielddata['type'] == $FIELD_TYPES['multiline_textbox'] && $filtered) {
        $shortcode_data = apply_filters('the_content', $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['image']) {
        $imgresults = split('&', $fieldresults);
        if ($imgtag) {
            $shortcode_data = "<img src=\"{$imgresults['0']}\"/>";
        } else {
            $shortcode_data = $imgresults[0];
        }
    }
    if ($fielddata['type'] == $FIELD_TYPES['listbox']) {
        $shortcode_data = implode(",", $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['checkbox_list']) {
        $shortcode_data = implode(",", $fieldresults);
    }
    if ($fielddata['type'] == $FIELD_TYPES['checkbox']) {
        if ($fieldresults) {
            $shortcode_data = $checked;
        }
    }
    // Prepare fields for EIP
    $enableEditnplace = RCCWP_Options::Get('enable-editnplace');
    if ($eip && $enableEditnplace == 1 && current_user_can('edit_posts', $post->ID)) {
        switch ($fielddata['type']) {
            case $FIELD_TYPES["textbox"]:
                if (!$results) {
                    $results = "&nbsp";
                }
                $shortcode_data = "<div class='" . EIP_textbox($fieldMetaID) . "' >" . $fieldresults . "</div>";
                break;
            case $FIELD_TYPES["multiline_textbox"]:
                if (!$results) {
                    $results = "&nbsp";
                }
                $shortcode_data = "<div class='" . EIP_mulittextbox($fieldMetaID) . "' >" . $shortcode_data . "</div>";
                break;
        }
    }
    if ($shortcode_data || $fieldduplicatedata) {
        if ($label) {
            $shortcode_data = $label . $shortcode_data;
        } else {
            $shortcode_data = get_label($field) . " : " . $shortcode_data;
        }
        /////
        if ($field == "duplicate") {
            if ($loop) {
                return implode($loopseparator, $fieldduplicatedata);
            } else {
                return $shortcode_data;
            }
        } else {
            return $shortcode_data;
        }
        /////
    } else {
        return "no data found, please check the field name";
    }
}
function create_image($options)
{
    require_once "RCCWP_CustomField.php";
    global $post;
    // establish the default values, then override them with
    // whatever the user has passed in
    $options = array_merge(array('fieldName' => '', 'groupIndex' => 1, 'fieldIndex' => 1, 'param' => NULL, 'attr' => NULL, 'post_id' => NULL, 'tag_img' => true), (array) $options);
    // finally extract them into variables for this function
    extract($options);
    // check for a specified post id, or see if the $post global has one
    if ($post_id) {
        $post_id = $post_id;
    } elseif (isset($post->ID)) {
        $post_id = $post->ID;
    } else {
        return false;
    }
    // basic check
    if (empty($fieldName)) {
        return FALSE;
    }
    $field = RCCWP_CustomField::GetDataField($fieldName, $groupIndex, $fieldIndex, $post_id);
    if (!$field) {
        return FALSE;
    }
    $fieldType = $field['type'];
    $fieldID = $field['id'];
    $fieldCSS = $field['CSS'];
    $fieldObject = $field['properties'];
    $fieldValue = $field['meta_value'];
    if (empty($fieldValue)) {
        return "";
    }
    // override the default phpthumb parameters if needed
    // works with both strings and arrays
    if (!empty($param)) {
        if (is_array($param)) {
            $p = array();
            foreach ($param as $k => $v) {
                $p[] = $k . "=" . $v;
            }
            $fieldObject['params'] = implode('&', $p);
        } else {
            $fieldObject['params'] = $param;
        }
    }
    // remove the ? on the params if it happened to be there
    if (substr($fieldObject['params'], 0, 1) == "?") {
        $fieldObject['params'] = substr($fieldObject['params'], 1);
    }
    // check if exist params, if not exist params, return original image
    if (empty($fieldObject['params']) && FALSE === strstr($fieldValue, "&")) {
        $fieldValue = MF_FILES_URI . $fieldValue;
    } else {
        //check if exist thumb image, if exist return thumb image
        $md5_params = md5($fieldObject['params']);
        if (file_exists(MF_FILES_PATH . 'th_' . $md5_params . "_" . $fieldValue)) {
            $fieldValue = MF_FILES_URI . 'th_' . $md5_params . "_" . $fieldValue;
        } else {
            //generate thumb
            include_once dirname(__FILE__) . "/thirdparty/phpthumb/phpthumb.class.php";
            $phpThumb = new phpThumb();
            $phpThumb->setSourceFilename(MF_FILES_PATH . $fieldValue);
            $create_md5_filename = 'th_' . $md5_params . "_" . $fieldValue;
            $output_filename = MF_FILES_PATH . $create_md5_filename;
            $final_filename = MF_FILES_URI . $create_md5_filename;
            $params_image = explode("&", $fieldObject['params']);
            foreach ($params_image as $param) {
                if ($param) {
                    $p_image = explode("=", $param);
                    $phpThumb->setParameter($p_image[0], $p_image[1]);
                }
            }
            if ($phpThumb->GenerateThumbnail()) {
                if ($phpThumb->RenderToFile($output_filename)) {
                    $fieldValue = $final_filename;
                }
            }
        }
    }
    if ($tag_img) {
        // make sure the attributes are an array
        if (!is_array($attr)) {
            $attr = (array) $attr;
        }
        // we're generating an image tag, but there MAY be a default class.
        // if one was defined, however, override it
        if (!isset($attr['class']) && !empty($fieldCSS)) {
            $attr['class'] = $fieldCSS;
        }
        // ok, put it together now
        if (count($attr)) {
            foreach ($attr as $k => $v) {
                $add_attr .= $k . "='" . $v . "' ";
            }
            $finalString = "<img src='" . $fieldValue . "' " . $add_attr . " />";
        } else {
            $finalString = "<img src='" . $fieldValue . "' />";
        }
    } else {
        $finalString = $fieldValue;
    }
    return $finalString;
}
Example #4
0
function create_image($options)
{
    require_once "RCCWP_CustomField.php";
    global $post;
    // establish the default values, then override them with
    // whatever the user has passed in
    $options = array_merge(array('fieldName' => '', 'groupIndex' => 1, 'fieldIndex' => 1, 'param' => NULL, 'attr' => NULL, 'post_id' => NULL, 'tag_img' => true, 'wp_size' => 'original'), (array) $options);
    // finally extract them into variables for this function
    extract($options);
    // check for a specified post id, or see if the $post global has one
    if ($post_id) {
        $post_id = $post_id;
    } elseif (isset($post->ID)) {
        $post_id = $post->ID;
    } else {
        return false;
    }
    // basic check
    if (empty($fieldName)) {
        return FALSE;
    }
    $field = RCCWP_CustomField::GetDataField($fieldName, $groupIndex, $fieldIndex, $post_id);
    if (!$field) {
        return FALSE;
    }
    $fieldType = $field['type'];
    $fieldID = $field['id'];
    $fieldCSS = $field['CSS'];
    $fieldObject = $field['properties'];
    $fieldValue = $field['meta_value'];
    if ($fieldType == 16) {
        $data = wp_get_attachment_image_src($fieldValue, $wp_size);
        $fieldValue = $data[0];
    }
    if (empty($fieldValue)) {
        return "";
    }
    // override the default phpthumb parameters if needed
    // works with both strings and arrays
    if (!empty($param)) {
        if (is_array($param)) {
            $p = array();
            foreach ($param as $k => $v) {
                $p[] = $k . "=" . $v;
            }
            $fieldObject['params'] = implode('&', $p);
        } else {
            $fieldObject['params'] = $param;
        }
    }
    // remove the ? on the params if it happened to be there
    if (isset($fieldObject['params']) && !empty($fieldObject['params'])) {
        if (substr($fieldObject['params'], 0, 1) == "?") {
            $fieldObject['params'] = substr($fieldObject['params'], 1);
        }
    }
    // check if exist params, if not exist params, return original image
    if (empty($fieldObject['params']) && FALSE === strstr($fieldValue, "&")) {
        if ($fieldType == 9) {
            $fieldValue = MF_FILES_URI . $fieldValue;
            $fieldValue = apply_filters('mf_source_image', $fieldValue);
        }
    } else {
        //generate or check de thumb
        $fieldValue = aux_image($fieldValue, $fieldObject['params'], $fieldType);
    }
    if ($tag_img) {
        // make sure the attributes are an array
        if (!is_array($attr)) {
            $attr = (array) $attr;
        }
        // we're generating an image tag, but there MAY be a default class.
        // if one was defined, however, override it
        if (!isset($attr['class']) && !empty($fieldCSS)) {
            $attr['class'] = $fieldCSS;
        }
        // ok, put it together now
        if (count($attr)) {
            $add_attr = NULL;
            foreach ($attr as $k => $v) {
                $add_attr .= $k . "='" . $v . "' ";
            }
            $finalString = "<img src='" . $fieldValue . "' " . $add_attr . " />";
        } else {
            $finalString = "<img src='" . $fieldValue . "' />";
        }
    } else {
        $finalString = $fieldValue;
    }
    return $finalString;
}