GetFieldDuplicates() public static method

Get number of group duplicates given field name. The function returns 1 if there are no duplicates (just he original group), 2 if there is one duplicate and so on.
public static GetFieldDuplicates ( integer $postId, $fieldName, $groupIndex ) : number
$postId integer post id
return number of groups
Ejemplo n.º 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";
    }
}
Ejemplo n.º 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";
    }
}
/**
 * Get number of field duplicates given field name and group duplicate index.
 * The function returns 1 if there are no duplicates (just the original field), 
 * 2 if there is one duplicate and so on.
 *
 * @param string $fieldName
 * @param integer $groupIndex
 * @return number of field duplicates
 */
function getFieldDuplicates($fieldName, $groupIndex)
{
    require_once "RCCWP_CustomField.php";
    global $post;
    return RCCWP_CustomField::GetFieldDuplicates($post->ID, $fieldName, $groupIndex);
}
Ejemplo n.º 4
0
    /**
     * 
     * @param object $customGroup
     * @param integer $groupCounter
     * @param boolean $fromAjax
     *
     */
    function GroupDuplicate($customGroup, $groupCounter, $order, $fromAjax = true)
    {
        global $mf_domain;
        //getting the custom fields
        $customFields = RCCWP_CustomGroup::GetCustomFields($customGroup->id);
        //if don't have fields then finish
        if (count($customFields) == 0) {
            return;
        }
        require_once "RC_Format.php";
        if ($customGroup->duplicate != 0) {
            $add_class_rep = "mf_duplicate_group";
        } else {
            $add_class_rep = "";
        }
        ?>
		<div class="magicfield_group <?php 
        echo $add_class_rep;
        ?>
" id="freshpostdiv_group_<?php 
        echo $customGroup->id . '_' . $groupCounter;
        ?>
">
			<div>
			<div class="inside">
				<?php 
        foreach ($customFields as $field) {
            $customFieldName = RC_Format::GetInputName(attribute_escape($field->name));
            $customFieldTitle = attribute_escape($field->description);
            $groupId = $customGroup->id;
            $inputName = $field->id . "_" . $groupCounter . "_1_" . $groupId . "_" . $customFieldName;
            if (isset($_REQUEST['post'])) {
                $fc = RCCWP_CustomField::GetFieldDuplicates($_REQUEST['post'], $field->name, $groupCounter);
                $fields_order = RCCWP_CustomField::GetFieldsOrder($_REQUEST['post'], $field->name, $groupCounter);
                foreach ($fields_order as $element) {
                    RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, $element, $customGroup->id);
                }
            } else {
                RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, 1, $customGroup->id);
                $fc = 1;
            }
            if (!empty($fields_order)) {
                $tmp = $fields_order;
                sort($tmp);
                $top = $tmp[count($tmp) - 1];
            } else {
                $top = 1;
            }
            ?>
					<span style="display:none" id="<?php 
            echo "c" . $inputName . "Duplicate";
            ?>
">
						<input type="text" name="c<?php 
            echo $inputName;
            ?>
Counter" id="c<?php 
            echo $inputName;
            ?>
Counter" value='<?php 
            echo $top;
            ?>
' /> 
					</span>
				<?php 
        }
        ?>
			<br />
			<?php 
        if ($customGroup->duplicate != 0) {
            ?>
			<div class="mf_toolbox">
				<span class="hndle sortable_mf row_mf">
					<img title="Order" src="<?php 
            echo MF_URI;
            ?>
/images/move.png"/>
				</span>
				<span class="mf_counter" id="counter_<?php 
            echo $customGroup->id;
            ?>
_<?php 
            echo $groupCounter;
            ?>
">
					(<?php 
            echo $order;
            ?>
)
				</span>
				<span class="add_mf">
					<?php 
            if ($groupCounter != 1) {
                ?>
							<a class ="delete_duplicate_button" href="javascript:void(0);" id="delete_duplicate-freshpostdiv_group_<?php 
                echo $customGroup->id . '_' . $groupCounter;
                ?>
"> 
								<img class="duplicate_image"  src="<?php 
                echo MF_URI;
                ?>
images/delete.png" alt="<?php 
                _e('Remove field duplicate', $mf_domain);
                ?>
"/><?php 
                _e('Remove Group', $mf_domain);
                ?>
							</a>
						<?php 
            } else {
                ?>
 
							<a id="add_duplicate_<?php 
                echo $customGroup->id . "Duplicate" . "_" . $customGroup->id . "_" . $order;
                ?>
" class="duplicate_button" href="javascript:void(0);"> 
								<img class="duplicate_image" src="<?php 
                echo MF_URI;
                ?>
images/duplicate.png" alt="<?php 
                _e('Add group duplicate', $mf_domain);
                ?>
" title="Duplicate Field"/>
							</a>
					   <?php 
            }
            ?>
 
				</span>
				<br style="height:2px"/>
			</div>
			<?php 
        }
        ?>
			</div>
			</div> 
			<input type="hidden" name="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" id="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" value="<?php 
        echo $order;
        ?>
" />
		</div>
		<?php 
    }
Ejemplo n.º 5
0
    /**
     * 
     * @param object $customGroup
     * @param integer $groupCounter
     * @param boolean $fromAjax
     *
     */
    public static function GroupDuplicate($customGroup, $groupCounter, $order, $fromAjax = true)
    {
        global $mf_domain;
        global $CUSTOM_WRITE_PANEL;
        $ex_class = $customGroup->expanded ? "mf-group-expanded" : '';
        if ($customGroup->name == "__default") {
            // for the default group (top level), check the expand flag on the WRITE PANEL instead
            $ex_class = $CUSTOM_WRITE_PANEL->expanded ? "mf-group-expanded" : '';
        }
        $mf_post_id = apply_filters('mf_source_post_data', @$_REQUEST['post']);
        //getting the custom fields
        $customFields = RCCWP_CustomGroup::GetCustomFields($customGroup->id);
        //if don't have fields then finish
        if (count($customFields) == 0) {
            return;
        }
        require_once "RC_Format.php";
        if ($customGroup->duplicate != 0) {
            $add_class_rep = "mf_duplicate_group";
        } else {
            $add_class_rep = "";
        }
        ?>
		<div class="magicfield_group <?php 
        echo $add_class_rep;
        ?>
 <?php 
        echo $ex_class;
        ?>
" id="freshpostdiv_group_<?php 
        echo $customGroup->id . '_' . $groupCounter;
        ?>
">
			<a id="collapse_<?php 
        echo $customGroup->id . "Duplicate" . "_" . $customGroup->id . "_" . $order;
        ?>
" class="collapse_button" href="javascript:void(0);">Collapse</a>

      <div class="mf-group-loading"><?php 
        _e('Loading Data&hellip;', $mf_domain);
        ?>
</div>
      
      <div>
			<div class="inside">
			<div class="mf-fields">
				<?php 
        foreach ($customFields as $field) {
            $customFieldName = $field->name;
            $customFieldTitle = esc_attr($field->description);
            $groupId = $customGroup->id;
            $inputName = $field->id . "_" . $groupCounter . "_1_" . $groupId . "_" . $customFieldName;
            if (isset($mf_post_id)) {
                $fc = RCCWP_CustomField::GetFieldDuplicates($mf_post_id, $field->name, $groupCounter);
                $fields_order = RCCWP_CustomField::GetFieldsOrder($mf_post_id, $field->name, $groupCounter);
                foreach ($fields_order as $element) {
                    RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, $element, $customGroup->id);
                }
            } else {
                RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, 1, $customGroup->id);
                $fc = 1;
            }
            if (!empty($fields_order)) {
                $tmp = $fields_order;
                sort($tmp);
                $top = $tmp[count($tmp) - 1];
            } else {
                $top = 1;
            }
            ?>
					<span style="display:none" id="<?php 
            echo "c" . $inputName . "Duplicate";
            ?>
">
						<input type="text" name="c<?php 
            echo $inputName;
            ?>
Counter" id="c<?php 
            echo $inputName;
            ?>
Counter" value='<?php 
            echo $top;
            ?>
' /> 
					</span>
				<?php 
        }
        ?>
      </div>
	    <!-- /.mf-fields -->

			<?php 
        if ($customGroup->duplicate != 0) {
            $sgn = Inflect::singularize($customGroup->name);
            ?>
			
	    
			<div class="mf_toolbox">
				<span class="mf_counter sortable_mf" id="counter_<?php 
            echo $customGroup->id;
            ?>
_<?php 
            echo $groupCounter;
            ?>
"><?php 
            echo $order;
            ?>
</span>
				<span class="hndle sortable_mf row_mf">&nbsp;</span>

				<span class="mf_toolbox_controls">

					<?php 
            if ($groupCounter != 1) {
                ?>
							<a class ="delete_duplicate_button { lang: { confirm: '<?php 
                _e("Are you sure?", $mf_domain);
                ?>
' } }" href="javascript:void(0);" id="delete_duplicate-freshpostdiv_group_<?php 
                echo $customGroup->id . '_' . $groupCounter;
                ?>
"><span><?php 
                _e('Remove', $mf_domain);
                ?>
</span> <?php 
                echo $sgn;
                ?>
</a>
						<?php 
            } else {
                ?>
 
							<a id="add_duplicate_<?php 
                echo $customGroup->id . "Duplicate" . "_" . $customGroup->id . "_" . $order;
                ?>
" class="duplicate_button" href="javascript:void(0);" title="<?php 
                _e('Note: hold down the SHIFT key as you click to collapse this item before the new item is added', $mf_domain);
                ?>
"><span><?php 
                _e('Add Another', $mf_domain);
                ?>
</span> <?php 
                echo $sgn;
                ?>
</a>
					   <?php 
            }
            ?>
 
				</span>
			</div>
			<?php 
        }
        ?>
			</div>
			</div> 
			<input type="hidden" name="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" id="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" value="<?php 
        echo $order;
        ?>
" />
		</div>
		<?php 
    }
Ejemplo n.º 6
0
    /**
     * This method and   groupduplicated  will be merged in nexts commits
     * 
     * @param object $customGroup
     * @param integer $groupCounter
     * @param boolean $fromAjax
     *
     */
    function GroupDuplicate2($customGroup, $groupCounter, $order, $fromAjax = true)
    {
        global $flutter_domain;
        $counter = "";
        if ($groupCounter == 1) {
            $counter = "";
        } else {
            $tmp = $groupCounter;
            $counter = "(" . $tmp . ")";
        }
        //getting the custom fields
        $customFields = RCCWP_CustomGroup::GetCustomFields($customGroup->id);
        //if don't have fields then finish
        if (count($customFields) == 0) {
            return;
        }
        //¿?
        if ($customGroup->duplicate == 0 && $groupCounter != 1) {
            return;
        }
        require_once "RC_Format.php";
        if (empty($customGroup->name) || $customGroup->name == "__default") {
            $title = "Flutter custom fields";
        } else {
            $title = $customGroup->name;
        }
        ?>
		<div id="freshpostdiv_group_<?php 
        echo $customGroup->id . '_' . $groupCounter;
        ?>
" class="postbox1">	
            <div class="postbox" >
                <h3 class="hndle sortable_flutter">
                    <span><?php 
        echo $title;
        ?>
 <?php 
        echo $counter;
        ?>
</span>
                </h3>
            <div class="inside">
			<table class="form-table" style="width: 100%;" cellspacing="2" cellpadding="5">
			    <?php 
        foreach ($customFields as $field) {
            // Render a row for each field in the group
            //$customField = RCCWP_CustomField::Get($field->id);
            $customFieldName = RC_Format::GetInputName(attribute_escape($field->name));
            $customFieldTitle = attribute_escape($field->description);
            $groupId = $customGroup->id;
            $inputName = $field->id . "_" . $groupCounter . "_1_" . $groupId . "_" . $customFieldName;
            if (isset($_REQUEST['post'])) {
                $fc = RCCWP_CustomField::GetFieldDuplicates($_REQUEST['post'], $field->name, $groupCounter);
                $fields_order = RCCWP_CustomField::GetFieldsOrder($_REQUEST['post'], $field->name, $groupCounter);
                foreach ($fields_order as $element) {
                    RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, $element, $customGroup->id);
                }
            } else {
                RCCWP_WritePostPage::CustomFieldInterface($field->id, $groupCounter, 1, $customGroup->id);
                $fc = 1;
            }
            if (!empty($fields_order)) {
                $tmp = $fields_order;
                sort($tmp);
                $top = $tmp[count($tmp) - 1];
            } else {
                $top = 1;
            }
            ?>
               <tr style="display:none" id="<?php 
            echo "c" . $inputName . "Duplicate";
            ?>
">
					<th valign="top" scope="row">
					</th>
					<td>
						<img class="duplicate_image"  src="<?php 
            echo FLUTTER_URI;
            ?>
images/spinner.gif" alt=""/> <?php 
            _e('Loading', $flutter_domain);
            ?>
 ... 
						<input type="text" name="c<?php 
            echo $inputName;
            ?>
Counter" id="c<?php 
            echo $inputName;
            ?>
Counter" value='<?php 
            echo $top;
            ?>
' /> 
					</td>
			    </tr>
                <?php 
        }
        ?>
		    </table>
    		<br />
	    	<?php 
        if ($customGroup->duplicate != 0) {
            if ($groupCounter != 1) {
                ?>
                        <a class ="delete_duplicate_button" href="javascript:void(0);" id="delete_duplicate-freshpostdiv_group_<?php 
                echo $customGroup->id . '_' . $groupCounter;
                ?>
"> 
            		        <img class="duplicate_image"  src="<?php 
                echo FLUTTER_URI;
                ?>
images/delete.png" alt="<?php 
                _e('Remove field duplicate', $flutter_domain);
                ?>
"/><?php 
                _e('Remove Group', $flutter_domain);
                ?>
                	    </a>
                    <?php 
            } else {
                ?>
 
                        <a class="duplicate_button" id="add_duplicate_<?php 
                echo $customGroup->id . "Duplicate" . "_" . $customGroup->id;
                ?>
" href="javascript:void(0);"> 
            		    	<img class="duplicate_image" src="<?php 
                echo FLUTTER_URI;
                ?>
images/duplicate.png" alt="<?php 
                _e('Add group duplicate', $flutter_domain);
                ?>
"/> <?php 
                _e('Duplicate Group', $flutter_domain);
                ?>
	                	</a>
                   <?php 
            }
            ?>
 
			<br style="height:2px"/>
			<?php 
        }
        ?>
                </div>
            </div> 
            <input type="hidden" name="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" id="order_<?php 
        echo $customGroup->id;
        ?>
_<?php 
        echo $groupCounter;
        ?>
" value="<?php 
        echo $order;
        ?>
" />
        </div>
		<?php 
    }