Invalid argument on php file - php

I'm getting an error that says:
"Warning: Invalid argument supplied for foreach() in /home/content/a2pewpnas01_data01/19/3920219/html/wp-content/plugins/estimated-dispatch-date-woocommerce/includes/plugin-functions.php on line 98"
The line 98 is this: foreach($eddwc_holiday as $eddwc_hday){
Here is the complete code:
<?php
if(!function_exists('eddwc_option')){
function eddwc_option($key){
$value = EDDWC()->get_option($key);
return $value;
}
}
if(!function_exists('eddwc_update_variable')){
function eddwc_update_variable($post_id,$value){
update_post_meta( $post_id, EDDWCP_METAKEY.'_variable', wc_clean($value) );
}
}
if(!function_exists('eddwc_update_simple')){
function eddwc_update_simple($post_id,$value){
update_post_meta( $post_id, EDDWCP_METAKEY.'_simple', wc_clean($value) );
}
}
if(!function_exists('eddwc_update_variation')){
function eddwc_update_variation($post_id,$value){
update_post_meta( $post_id, EDDWCP_METAKEY.'_variation', wc_clean($value) );
}
}
if(!function_exists('eddwc_get_variation')){
function eddwc_get_variation($post_id){
return get_post_meta($post_id,EDDWCP_METAKEY.'_variation',true);
}
}
if(!function_exists('eddwc_get_variable')){
function eddwc_get_variable($post_id){
return get_post_meta($post_id,EDDWCP_METAKEY.'_variable',true);
}
}
if(!function_exists('eddwc_get_simple')){
function eddwc_get_simple($post_id){
return get_post_meta($post_id,EDDWCP_METAKEY.'_simple',true);
}
}
if(!function_exists('eddwc_get_external')){
function eddwc_get_external($post_id){
return get_post_meta($post_id,EDDWCP_METAKEY.'_external',true);
}
}
if(!function_exists('eddwc_get_grouped')){
function eddwc_get_grouped($post_id){
return get_post_meta($post_id,EDDWCP_METAKEY.'_grouped',true);
}
}
if(!function_exists('eddwc_get_actual_date')){
function eddwc_get_actual_date($value){
$date = eddwc_get_dispatch_date($value);
return $date;
}
}
if(!function_exists('eddwc_get_general_date')){
function eddwc_get_general_date($value,$seperator = ' - '){
$general_option = eddwc_option('product_general_date_settings');
$val = explode(',', $value);
$final_date = '';
if(isset($val[0]) && !isset($val[1])){
$final_date = $val[0];
} else if(isset($val[0]) && isset($val[1])){
if($val[0] == $val[1]){
$final_date = $val[0];
} else {
if(isset($general_option['actual_date'])){
$final_date = eddwc_get_dispatch_date($val[0]) .$seperator. eddwc_get_dispatch_date($val[1]);
} else {
$final_date = $val[0] .$seperator. $val[1];
}
}
}
return $final_date;
}
}
if(!function_exists('eddwc_get_static_date')){
function eddwc_get_static_date($date = ''){
$eddwc_range = explode(',' , $date);
if(count($eddwc_range) > 1){
if(isset($eddwc_range[0]) && isset($eddwc_range[1]) && ($eddwc_range[0] > $eddwc_range[1]) ){
$eddwc_range = $eddwc_range[0];
} else {
$eddwc_range = $eddwc_range[1];
}
} else {
if(isset($eddwc_range[0])){
$eddwc_range = $eddwc_range[0];
}
}
return $eddwc_range;
}
}
if(!function_exists('eddwc_get_dispatch_date')){
function eddwc_get_dispatch_date($date) {
$eddwc_holiday = eddwc_option('holiday');
$eddwc_holidays = array();
foreach($eddwc_holiday as $eddwc_hday){
$eddwc_holidays[] = $eddwc_hday['date'];
}
$eddwc_workdays = eddwc_option('operation_days');
$cutOff = eddwc_option('day_cutoftime');
list($cut_hrs,$cut_min) = explode(':',$cutOff);
$cut_hrs = intval($cut_hrs);
$cut_min = intval($cut_min);
$wp_timezone_string = get_option('timezone_string');
$wp_timezone_offset = get_option('gmt_offset');
if ($wp_timezone_string) {
$eddwc_timezone = $wp_timezone_string;
} else {
$eddwc_timezone = ini_get('date.timezone');
}
date_default_timezone_set($eddwc_timezone);
$eddwc_date = new DateTime;
$eddwc_cut_off = $cutOff;
$eddwc_time = clone $eddwc_date;
$eddwc_time->setTime($cut_hrs,$cut_min);
$eddwc_next_date = clone $eddwc_date;
if ($eddwc_date >= $eddwc_time){
$eddwc_next_date->modify('+1 day');
}
$i = 0;
while ($i < $date){
$eddwc_next_date->modify('+1 day');
$ndate = strtolower($eddwc_next_date->format('D'));
if (in_array($ndate, $eddwc_workdays)) {
//$i++;
if (in_array($eddwc_next_date->format('d-m-Y'), $eddwc_holidays) == false) {
$i++;
}
}
}
return $eddwc_next_date->format(eddwc_option('date_display_format'));
}
}
?>
What is wrong with this code?
Thanks

Related

Adding a 0 at the end of the input when it is less than 9 digits

I have an e-commerce site in opencart and I have a problem in the RG field which is as follows, when the user registers it fills all the fields normally but in the RG field there are those users that have one digit less in the RG that they are usually 9 more digits have users with 8 and they usually register on the site more when they are going to make a purchase they can not conclude it because the RG is with a number less would like to know if it is possible to put a code that does the following when the User to enter a RG with one digit less or less than 9 add a 0 at the end of the field so that it is complete.
This is uexatamente the input that I need to change so that when the user clicks on register it will be saved with the longest digit
<Input type = "text" name = "custom_field [account] [2]" value = "" placeholder = "RG" id = "input-custom-field2" class = "form-control">
I do not know if this is where I am going to implement my code but this is one of the controllers responsible for the registration of the form
<?php
class ControllerAccountRegister extends Controller {
private $error = array();
public function index() {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', '', 'SSL'));
}
$this->load->language('account/register');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$this->load->model('account/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->customer->login($this->request->post['email'], $this->request->post['password']);
unset($this->session->data['guest']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname']
//'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
$this->response->redirect($this->url->link('account/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', '', 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', 'SSL'));
$data['text_your_details'] = $this->language->get('text_your_details');
$data['text_your_address'] = $this->language->get('text_your_address');
$data['text_your_password'] = $this->language->get('text_your_password');
$data['text_newsletter'] = $this->language->get('text_newsletter');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_loading'] = $this->language->get('text_loading');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
// $data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_newsletter'] = $this->language->get('entry_newsletter');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_confirm'] = $this->language->get('entry_confirm');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_upload'] = $this->language->get('button_upload');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
// if (isset($this->error['lastname'])) {
// $data['error_lastname'] = $this->error['lastname'];
// } else {
// $data['error_lastname'] = '';
// }
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['address_1'])) {
$data['error_address_1'] = $this->error['address_1'];
} else {
$data['error_address_1'] = '';
}
if (isset($this->error['city'])) {
$data['error_city'] = $this->error['city'];
} else {
$data['error_city'] = '';
}
if (isset($this->error['postcode'])) {
$data['error_postcode'] = $this->error['postcode'];
} else {
$data['error_postcode'] = '';
}
if (isset($this->error['country'])) {
$data['error_country'] = $this->error['country'];
} else {
$data['error_country'] = '';
}
if (isset($this->error['zone'])) {
$data['error_zone'] = $this->error['zone'];
} else {
$data['error_zone'] = '';
}
if (isset($this->error['custom_field'])) {
$data['error_custom_field'] = $this->error['custom_field'];
} else {
$data['error_custom_field'] = array();
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
if (isset($this->error['confirm'])) {
$data['error_confirm'] = $this->error['confirm'];
} else {
$data['error_confirm'] = '';
}
$data['action'] = $this->url->link('account/register', '', 'SSL');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
// if (isset($this->request->post['lastname'])) {
// $data['lastname'] = $this->request->post['lastname'];
// } else {
// $data['lastname'] = '';
// }
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['company'])) {
$data['company'] = $this->request->post['company'];
} else {
$data['company'] = '';
}
if (isset($this->request->post['address_1'])) {
$data['address_1'] = $this->request->post['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->request->post['address_2'])) {
$data['address_2'] = $this->request->post['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->request->post['postcode'])) {
$data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->request->post['city'])) {
$data['city'] = $this->request->post['city'];
} else {
$data['city'] = '';
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->request->post['zone_id'])) {
$data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->request->post['custom_field'])) {
if (isset($this->request->post['custom_field']['account'])) {
$account_custom_field = $this->request->post['custom_field']['account'];
} else {
$account_custom_field = array();
}
if (isset($this->request->post['custom_field']['address'])) {
$address_custom_field = $this->request->post['custom_field']['address'];
} else {
$address_custom_field = array();
}
$data['register_custom_field'] = $account_custom_field + $address_custom_field;
} else {
$data['register_custom_field'] = array();
}
if (isset($this->request->post['password'])) {
$data['password'] = $this->request->post['password'];
} else {
$data['password'] = '';
}
if (isset($this->request->post['confirm'])) {
$data['confirm'] = $this->request->post['confirm'];
} else {
$data['confirm'] = '';
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} else {
$data['newsletter'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->request->post['agree'])) {
$data['agree'] = $this->request->post['agree'];
} else {
$data['agree'] = false;
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/register.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/register.tpl', $data));
}
}
public function validate() {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
// if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
// $this->error['lastname'] = $this->language->get('error_lastname');
// }
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$this->error['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$this->error['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$this->error['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$this->error['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$this->error['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$this->error['confirm'] = $this->language->get('error_confirm');
}
// Agree to terms
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
return !$this->error;
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
may be you can use this script.
function putZeroToLastItem($text) {
$length = strlen($text);
if( $length < 9 ) {
$text .= '0'
}
return $text
}
I hope , this script will solve your porblem.
<?php
$num = 3;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 03
?>
Try this simple snippet
You want to add 0 after the number (9 digit)? Use jquery if you want it in client side.
function addZero (data){
return data+(data <10 ? '0':'');
}
var num =$('#number').val();
var nNum = addZero(num);
Hope it helps.
A reduced way of #mehfatitem:
function putZeroToLastItem($text) {
return (strlen($text) < 9) ? $text . '0' : $text;
}

Illegal string offset 'formId' in repeater gravityform

PLease Help me,
I have this errors
Warning: Illegal string offset 'formId' in
C:\xampp\htdocs\wp-content\plugins\repeater-add-on-for-gravity-forms\class-gf-field-repeater.php
on line 287
Warning: Illegal string offset 'children' in
C:\xampp\htdocs\wp-content\plugins\repeater-add-on-for-gravity-forms\class-gf-field-repeater.php
on line 291
...
if (empty($value)) {
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
...
Hi I solved adding $value = array() in line 287.
if (empty($value)) {
$value = array();
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
That's work for me, I hope it could help you.
<?php
class GF_Field_Repeater extends GF_Field {
public $type = 'repeater';
public static function init_admin() {
$admin_page = rgget('page');
if ($admin_page == 'gf_edit_forms' && !empty($_GET['id'])) {
add_action('gform_field_standard_settings' , array('GF_Field_Repeater', 'gform_standard_settings'), 10, 2);
add_action('gform_field_appearance_settings' , array('GF_Field_Repeater', 'gform_appearance_settings'), 10, 2);
add_action('gform_editor_js_set_default_values', array('GF_Field_Repeater', 'gform_set_defaults'));
add_action('gform_editor_js', array('GF_Field_Repeater', 'gform_editor'));
add_filter('gform_tooltips', array('GF_Field_Repeater', 'gform_tooltips'));
}
if ($admin_page == 'gf_entries') {
add_filter('gform_form_post_get_meta', array('GF_Field_Repeater', 'gform_hide_children'));
}
}
public static function init_frontend() {
add_action('gform_form_args', array('GF_Field_Repeater', 'gform_disable_ajax'));
add_action('gform_enqueue_scripts', array('GF_Field_Repeater', 'gform_enqueue_scripts'), 10, 2);
add_filter('gform_pre_render', array('GF_Field_Repeater', 'gform_unhide_children_validation'));
add_filter('gform_pre_validation', array('GF_Field_Repeater', 'gform_bypass_children_validation'));
}
public static function gform_enqueue_scripts($form, $is_ajax) {
if (!empty($form)) {
if (GF_Field_Repeater::get_field_index($form) !== false) {
wp_enqueue_script('gforms_repeater_postcapture_js', plugins_url('js/jquery.postcapture.min.js', __FILE__), array('jquery'), '0.0.1');
wp_enqueue_script('gforms_repeater_js', plugins_url('js/gf-repeater.min.js', __FILE__), array('jquery'), GF_REPEATER_VERSION);
wp_enqueue_style('gforms_repeater_css', plugins_url('css/gf-repeater.css', __FILE__), array(), GF_REPEATER_VERSION);
}
}
}
public function get_form_editor_field_title() {
return 'Repeater';
}
public function get_form_editor_field_settings() {
return array(
'admin_label_setting',
'css_class_setting',
'description_setting',
'error_message_setting',
'label_setting',
'prepopulate_field_setting'
);
}
public static function gform_set_defaults() {
echo "
case \"repeater\" :
field.label = \"Repeater\";
break;
";
}
public static function gform_standard_settings($position, $form_id) {
if ($position == 1600) {
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_start\">Start ";
gform_tooltip('form_field_repeater_start');
echo " </label>
<input type=\"number\" id=\"field_repeater_start\" min=\"1\" value=\"1\" onchange=\"SetFieldProperty('start', this.value);\">
</li>";
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_min\">Min ";
gform_tooltip('form_field_repeater_min');
echo " </label>
<input type=\"number\" id=\"field_repeater_min\" min=\"1\" value=\"1\" onchange=\"SetFieldProperty('min', this.value);\">
</li>";
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_max\">Max ";
gform_tooltip('form_field_repeater_max');
echo " </label>
<input type=\"number\" id=\"field_repeater_max\" min=\"1\" onchange=\"SetFieldProperty('max', this.value);\">
</li>";
}
}
public static function gform_appearance_settings($position, $form_id) {
if ($position == 400) {
echo "<li class=\"repeater_settings field_setting\">
<input type=\"checkbox\" id=\"field_repeater_hideLabel\" onchange=\"SetFieldProperty('hideLabel', this.checked);\">
<label for=\"field_repeater_hideLabel\" class=\"inline\">Hide Label & Description ";
gform_tooltip('form_field_repeater_hideLabel');
echo " </label>
</li>";
}
}
public static function gform_editor() {
echo "<script type=\"text/javascript\">
fieldSettings['repeater'] += ', .repeater_settings';
jQuery(document).bind('gform_load_field_settings', function(event, field, form){
jQuery('#field_repeater_start').val(field['start']);
jQuery('#field_repeater_min').val(field['min']);
jQuery('#field_repeater_max').val(field['max']);
jQuery('#field_repeater_hideLabel').prop('checked', field['hideLabel']);
});
</script>";
}
public static function gform_tooltips($tooltips) {
$tooltips['form_field_repeater_start'] = "The number of times the repeater will be repeated when the form is rendered. Leaving this field blank or setting it to a number higher than the maximum number is the same as setting it to 1.";
$tooltips['form_field_repeater_min'] = "The minimum number of times the repeater is allowed to be repeated. Leaving this field blank or setting it to a number higher than the maximum field is the same as setting it to 1.";
$tooltips['form_field_repeater_max'] = "The maximum number of times the repeater is allowed to be repeated. Leaving this field blank or setting it to a number lower than the minimum field is the same as setting it to unlimited.";
$tooltips['form_field_repeater_hideLabel'] = "If this is checked, the repeater label and description will not be shown to users on the form.";
return $tooltips;
}
function validate($value, $form) {
$repeater_required = $this->repeaterRequiredChildren;
if (!empty($repeater_required)) {
$dataArray = json_decode($value, true);
foreach ($form['fields'] as $key=>$value) {
$fieldKeys[$value['id']] = $key;
if (is_array($value['inputs'])) {
foreach ($value['inputs'] as $inputKey=>$inputValue) {
$inputKeys[$value['id']][$inputValue['id']] = $inputKey;
}
}
}
if ($dataArray['repeatCount'] < $this->min) {
$this->failed_validation = true;
$this->validation_message = "A minimum number of ".$this->min." is required.";
return;
}
if ($this->max && $dataArray['repeatCount'] > $this->max) {
$this->failed_validation = true;
$this->validation_message = "A maximum number of ".$this->max." is allowed.";
return;
}
for ($i = 1; $i < $dataArray['repeatCount'] + 1; $i++) {
foreach ($dataArray['children'] as $field_id=>$field) {
$inputNames = $field['inputs'];
$repeatSkips = $field['conditionalLogic']['skip'];
if (!is_array($inputNames)) { continue; }
if (is_array($repeatSkips)) {
if (in_array($i, $repeatSkips) || in_array('all', $repeatSkips)) { continue; }
}
foreach ($inputNames as $inputName) {
if (is_array($inputName)) { $inputName = reset($inputName); }
if (substr($inputName, -2) == '[]') {
$getInputName = substr($inputName, 0, strlen($inputName) - 2).'-'.$dataArray['repeaterId'].'-'.$i;
} else {
$getInputName = $inputName.'-'.$dataArray['repeaterId'].'-'.$i;
}
$getInputName = str_replace('.', '_', strval($getInputName));
$getInputData = rgpost($getInputName);
$getInputIdNum = preg_split("/(_|-)/", $getInputName);
if (in_array($getInputIdNum[1], $repeater_required)) {
$fieldKey = $fieldKeys[$getInputIdNum[1]];
$fieldType = $form['fields'][$fieldKey]['type'];
$failedValidation = false;
switch($fieldType) {
case 'name':
$requiredIDs = array(3, 6);
if (in_array($getInputIdNum[2], $requiredIDs) && empty($getInputData)) { $failedValidation = true; }
break;
case 'address':
$skipIDs = array(2);
if (!in_array($getInputIdNum[2], $skipIDs) && empty($getInputData)) { $failedValidation = true; }
break;
default:
if (empty($getInputData)) { $failedValidation = true; }
}
if ($failedValidation) {
$this->failed_validation = true;
if ($this->errorMessage) { $this->validation_message = $this->errorMessage; } else { $this->validation_message = "A required field was left blank."; }
return;
}
}
}
}
}
}
}
public function get_field_content($value, $force_frontend_label, $form) {
if (is_admin()) {
$admin_buttons = $this->get_admin_buttons();
$field_content = "{$admin_buttons}
<div class=\"gf-pagebreak-first gf-pagebreak-container gf-repeater gf-repeater-start\">
<div class=\"gf-pagebreak-text-before\">begin repeater</div>
<div class=\"gf-pagebreak-text-main\"><span>REPEATER</span></div>
<div class=\"gf-pagebreak-text-after\">top of repeater</div>
</div>";
} else {
$field_label = $this->get_field_label($force_frontend_label, $value);
$description = $this->get_description($this->description, 'gsection_description gf_repeater_description');
$hide_label = $this->hideLabel;
$validation_message = ( $this->failed_validation && ! empty( $this->validation_message ) ) ? sprintf( "<div class='gfield_description validation_message'>%s</div>", $this->validation_message ) : '';
if (!empty($field_label)) { $field_label = "<h2 class='gf_repeater_title'>{$field_label}</h2>"; } else { $field_label = ''; }
if ($hide_label) { $field_label = ''; $description = ''; }
$field_content = "<div class=\"ginput_container ginput_container_repeater\">{$field_label}{FIELD}</div>{$description}{$validation_message}";
}
return $field_content;
}
public function get_field_input($form, $value = '', $entry = null) {
if (is_admin()) {
return '';
} else {
$form_id = $form['id'];
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$id = (int) $this->id;
$field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id";
$tabindex = $this->get_tabindex();
$repeater_parem = $this->inputName;
$repeater_start = $this->start;
$repeater_min = $this->min;
$repeater_max = $this->max;
$repeater_required = $this->repeaterRequiredChildren;
$repeater_children = $this->repeaterChildren;
if (!empty($repeater_parem)) {
$repeater_parem_value = GFFormsModel::get_parameter_value($repeater_parem, $value, $this);
if (!empty($repeater_parem_value)) { $repeater_start = $repeater_parem_value; }
}
if (!empty($repeater_children)) {
$repeater_children_info = array();
$repeater_parems = GF_Field_Repeater::get_children_parem_values($form, $repeater_children);
foreach($repeater_children as $repeater_child) {
$repeater_children_info[$repeater_child] = array();
$repeater_child_field_index = GF_Field_Repeater::get_field_index($form, 'id', $repeater_child);
if (!empty($repeater_required)) {
if (in_array($repeater_child, $repeater_required)) {
$repeater_children_info[$repeater_child]['required'] = true;
}
}
if (!empty($repeater_parems)) {
if (array_key_exists($repeater_child, $repeater_parems)) {
$repeater_children_info[$repeater_child]['prePopulate'] = $repeater_parems[$repeater_child];
}
}
if ($repeater_child_field_index !== false) {
if ($form['fields'][$repeater_child_field_index]['inputMask']) {
$repeater_children_info[$repeater_child]['inputMask'] = $form['fields'][$repeater_child_field_index]['inputMaskValue'];
} elseif ($form['fields'][$repeater_child_field_index]['type'] == 'phone' && $form['fields'][$repeater_child_field_index]['phoneFormat'] = 'standard') {
$repeater_children_info[$repeater_child]['inputMask'] = "(999) 999-9999";
}
if ($form['fields'][$repeater_child_field_index]['conditionalLogic']) {
$repeater_children_info[$repeater_child]['conditionalLogic'] = $form['fields'][$repeater_child_field_index]['conditionalLogic'];
}
}
}
$repeater_children = $repeater_children_info;
}
if (empty($value)) {
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
return sprintf("<input name='input_%d' id='%s' type='hidden' class='gform_repeater' value='%s' %s />", $id, $field_id, $value, $tabindex);
}
}
public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) {
$dataArray = json_decode($value, true);
$value = Array();
for ($i = 1; $i < $dataArray['repeatCount'] + 1; $i++) {
foreach ($dataArray['children'] as $field_id=>$field) {
$inputData = Array();
if (array_key_exists('inputs', $field)) {
$inputNames = $field['inputs'];
$repeatSkips = $field['conditionalLogic']['skip'];
if (is_array($repeatSkips)) {
if (in_array($i, $repeatSkips) || in_array('all', $repeatSkips)) { continue; }
}
if (is_array($inputNames)) {
foreach ($inputNames as $inputName) {
if (substr($inputName, -2) == '[]') {
$getInputName = substr($inputName, 0, strlen($inputName) - 2).'-'.$dataArray['repeaterId'].'-'.$i;
} else {
$getInputName = $inputName.'-'.$dataArray['repeaterId'].'-'.$i;
}
$getInputData = rgpost(str_replace('.', '_', strval($getInputName)));
if (!empty($getInputData)) {
if (is_array($getInputData)) {
foreach ($getInputData as $theInputData) {
$inputData[] = $theInputData;
}
} else {
$inputData[] = $getInputData;
}
}
}
}
} else {
if (GF_Field_Repeater::get_field_type($form, $field_id) == 'section') { $inputData = '[gfRepeater-section]'; }
}
$childValue[$field_id] = $inputData;
}
$value[$i] = $childValue;
}
return maybe_serialize($value);
}
public function get_value_entry_list($value, $entry, $field_id, $columns, $form) {
if (empty($value)) {
return '';
} else {
$dataArray = GFFormsModel::unserialize($value);
$arrayCount = count($dataArray);
if ($arrayCount > 1) { $returnText = $arrayCount.' entries'; } else { $returnText = $arrayCount.' entry'; }
return $returnText;
}
}
public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') {
if (empty($value)) {
return '';
} else {
$dataArray = GFFormsModel::unserialize($value);
$arrayCount = count($dataArray);
$output = "\n";
$count = 0;
$repeatCount = 0;
$display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE);
$form_id = $this->formId;
$get_form = GFFormsModel::get_form_meta_by_id($form_id);
$form = $get_form[0];
foreach ($dataArray as $key=>$value) {
$repeatCount++;
$tableContents = '';
if (!empty($value) && !is_array($value)) {
$save_value = $value;
unset($value);
$value[0] = $save_value;
}
foreach ($value as $childKey=>$childValue) {
$count++;
$childValueOutput = '';
if (empty($display_empty_fields) && count($childValue) == 0) { continue; }
if (is_numeric($childKey)) {
$field_index = GF_Field_Repeater::get_field_index($form, 'id', $childKey);
if ($field_index === false) { continue; }
$entry_title = $form['fields'][$field_index]['label'];
} else {
$entry_title = $childKey;
}
$entry_title = str_replace('[gfRepeater-count]', $repeatCount, $entry_title);
if ($format == 'html') {
if ($childValue == '[gfRepeater-section]') {
if ($media == 'email') {
$tableStyling = ' style="font-size:14px;font-weight:bold;background-color:#eee;border-bottom:1px solid #dfdfdf;padding:7px 7px"';
} else {
$tableStyling = ' class="entry-view-section-break"';
}
} else {
if ($media == 'email') {
$tableStyling = ' style="background-color:#EAF2FA;font-family:sans-serif;font-size:12px;font-weight:bold"';
} else {
$tableStyling = ' class="entry-view-field-name"';
}
}
$tableContents .= "<tr>\n<td colspan=\"2\"".$tableStyling.">".$entry_title."</td>\n</tr>\n";
} else {
$tableContents .= $entry_title.": ";
}
if (is_array($childValue)) {
if (count($childValue) == 1) {
$childValueOutput = $childValue[0];
} elseif (count($childValue) > 1) {
if ($format == 'html') {
if ($media == 'email') {
$childValueOutput = "<ul style=\"list-style:none;margin:0;padding:0;\">\n";
} else {
$childValueOutput = "<ul>\n";
}
}
foreach ($childValue as $childValueData) {
if ($format == 'html') {
$childValueOutput .= "<li>".$childValueData."</li>";
} else {
$childValueOutput .= $childValueData."\n";
}
}
if ($format == 'html') { $childValueOutput .= "</ul>\n"; }
}
if ($media == 'email') { $tableStyling = ''; } else { $tableStyling = ' class=\"entry-view-field-value\"'; }
if ($format == 'html') {
$tableContents .= "<tr>\n<td colspan=\"2\"".$tableStyling.">".$childValueOutput."</td>\n</tr>\n";
} else {
$tableContents .= $childValueOutput."\n";
}
}
}
if (!empty($tableContents)) {
if ($format == 'html') {
if ($media == 'email') { $tableStyling = ' width="100%" border="0" cellpadding="5" bgcolor="#FFFFFF"'; } else { $tableStyling = ' class="widefat fixed entry-detail-view"'; }
$output .= "<table cellspacing=\"0\"".$tableStyling.">\n";
$output .= $tableContents;
$output .= "</table>\n";
} else {
$output .= $tableContents."\n";
}
}
}
}
if ($count !== 0) {
if ($format == 'text') { $output = rtrim($output); }
return $output;
} else { return ''; }
}
public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) {
$output = GF_Field_Repeater::get_value_entry_detail($raw_value, '', false, $format, 'email');
$output = preg_replace("/[\r\n]+/", "\n", $output);
return trim($output);
}
public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false) {
if (empty($input_id)) { $input_id = $this->id; }
$output = rgar($entry, $input_id);
$output = GF_Field_Repeater::get_value_entry_detail($output, '', false, 'text', 'email');
$output = preg_replace("/[\r\n]+/", ", ", trim($output));
return $output;
}
public static function gform_hide_children($form) {
$form_id = $form['id'];
$repeaterChildren = Array();
$grid_modified = false;
$grid_meta = GFFormsModel::get_grid_column_meta($form_id);
foreach($form['fields'] as $key=>$field) {
if ($field->type == 'repeater') {
if (is_array($field->repeaterChildren)) { $repeaterChildren = array_merge($repeaterChildren, $field->repeaterChildren); }
} elseif ($field->type == 'repeater-end') { array_push($repeaterChildren, $field->id); }
if (!empty($repeaterChildren)) {
if (in_array($field->id, $repeaterChildren)) {
unset($form['fields'][$key]);
if (is_array($grid_meta)) {
$grid_pos = array_search($field->id, $grid_meta);
if ($grid_pos) {
$grid_modified = true;
unset($grid_meta[$grid_pos]);
}
}
}
}
}
if ($grid_modified) { GFFormsModel::update_grid_column_meta($form_id, $grid_meta); }
$form['fields'] = array_values($form['fields']);
return $form;
}
public static function gform_disable_ajax($args) {
$get_form = GFFormsModel::get_form_meta_by_id($args['form_id']);
$form = reset($get_form);
if (GF_Field_Repeater::get_field_index($form) !== false) {
$args['ajax'] = false;
}
return $args;
}
public static function gform_bypass_children_validation($form) {
if (GF_Field_Repeater::get_field_index($form) === false) { return $form; }
$repeaterChildren = Array();
foreach($form['fields'] as $key=>$field) {
if ($field->type == 'repeater') {
if (is_array($field->repeaterChildren)) { $repeaterChildren = array_merge($repeaterChildren, $field->repeaterChildren); }
}
if (!empty($repeaterChildren)) {
if (in_array($field->id, $repeaterChildren) && !$field->adminOnly) {
$form['fields'][$key]['adminOnly'] = true;
$form['fields'][$key]['repeaterChildValidationHidden'] = true;
}
}
}
return $form;
}
public static function gform_unhide_children_validation($form) {
if (GF_Field_Repeater::get_field_index($form) === false) { return $form; }
foreach($form['fields'] as $key=>$field) {
if ($field->repeaterChildValidationHidden) {
$form['fields'][$key]['adminOnly'] = false;
$form['fields'][$key]['repeaterChildValidationHidden'] = false;
}
}
return $form;
}
public static function get_field_index($form, $key = 'type', $value = 'repeater') {
if (is_array($form)) {
if (!array_key_exists('fields', $form)) { return false; }
} else { return false; }
foreach ($form['fields'] as $field_key=>$field_value) {
if (is_object($field_value)) {
if (property_exists($field_value, $key)) {
if ($field_value[$key] == $value) { return $field_key; }
}
}
}
return false;
}
public static function get_field_type($form, $id) {
$field_index = GF_Field_Repeater::get_field_index($form, 'id', $id);
if ($field_index !== false) { return $form['fields'][$field_index]['type']; }
return false;
}
public static function get_children_parems($form, $children_ids) {
foreach($form['fields'] as $key=>$value) {
if (in_array($value['id'], $children_ids)) {
if ($value['inputName']) {
$parems[$value['id']] = $value['inputName'];
} elseif ($value['inputs']) {
foreach($value['inputs'] as $key=>$value) {
if ($value['name']) { $parems[$value['id']] = $value['name']; }
}
}
}
}
if (!empty($parems)) { return $parems; } else { return false; }
}
public static function get_children_parem_values($form, $children_ids) {
global $wp_filter;
$children_parems = GF_Field_Repeater::get_children_parems($form, $children_ids);
if (empty($children_parems)) { return false; }
// Check the URL first
foreach($_GET as $url_key=>$url_value) {
$key = array_search($url_key, $children_parems);
if ($key !== false) {
$parems[$key][0] = $url_value;
} else {
$split_key = preg_split('/\D+\K/', $url_key);
$key = array_search($split_key[0], $children_parems);
if ($key !== false) { $parems[$key][$split_key[1]] = $url_value; }
}
}
// Then check the filters
foreach($wp_filter as $key=>$value) {
$split_key = preg_split('/^gform_field_value_+\K/', $key);
if (!empty($split_key[1])) {
$key1 = array_search($split_key[1], $children_parems);
if ($key1 !== false) {
$parems[$key1][0] = apply_filters($key, '');
} else {
$split_key2 = preg_split('/\D+\K/', $split_key[1]);
$key2 = array_search($split_key2[0], $children_parems);
if ($key2 !== false) { $parems[$key2][$split_key2[1]] = apply_filters($key, ''); }
}
}
}
if (!empty($parems)) { return $parems; } else { return false; }
}
}
GF_Fields::register(new GF_Field_Repeater());

Warning: explode() expects parameter 2 to be string, Array given in (line 120 of display_ket.module

can someone help me to resolve this problem I've try any solution but still getting error, for firts time I using split date then i use explode because i received error and using php 5.6 .. $par is input
Warning: explode() expects parameter 2 to be string, array given in
konversitgl()
My Code .
function konversitgl($par){
$elemen=explode("-",$par); // this line 120
return $elemen[2].'/'.$elemen[1].'/'.$elemen[0];
}
function balikin_tgl($par){
$elemen=explode("/",$par );
return $elemen[2].'-'.$elemen[1].'-'.$elemen[0];
}
function tglInd($par){
$elemen=explode("-",$par );
$var=milih_bulan();
return number_format($elemen[2]).' '.$var[$elemen[1]].' '.$elemen[0];
}
function tglformat($par){
$elemen=explode("/",$par );
return $elemen[2].'-'.$elemen[1].'-'.$elemen[0];
}
function get_triwulan($bln){
if ($bln<=3){
$n = 1;
} elseif ($bln<=6){
$n = 2;
} elseif ($bln<=9){
$n = 3;
} else {
$n = 4;
}
return $n;
}
function valid_tanggal($tgl_cek){
global $user;
$panjang = strlen($tgl_cek);
//if (!ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $tgl_cek)){
if (!preg_match ("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/", $tgl_cek)){
$hasil_cek = false;
}else{
$tahun = substr($tgl_cek,-4);
$tgl = substr($tgl_cek,0,2);
$bulan = substr($tgl_cek,3,2);
if($bulan>12){
$hasil_cek = false;
}else if($tgl>31){
$hasil_cek = false;
}else{
if($bulan==02){
if($tgl>29){
$hasil_cek = false;
}else{
$hasil_cek = true;
}
}else{
$hasil_cek = true;
}
}
}
return $hasil_cek;
}
db_set_active('default');
$xx = date('Y-m-d');
$yy = substr($xx,0,4);
$mm = substr($xx,5,2);
$dd = substr($xx,8,2);
if($awal==NULL){
$awal = $yy."-".$mm."-01";
}
if($akhir==NULL){
$akhir = $yy."-".$mm."-".$dd;
}
Change you function to this.
function konversitgl($par)
{
if(is_string($par))
{
$elemen = explode("-", $par); // this line 120
return $elemen[2] . '/' . $elemen[1] . '/' . $elemen[0];
}
}

base64 in PHP Otp Library

I trying to make some simple library for encrypting files in PHP with OTP method. My problem is that some chars in decrypted code are different than original. I worked on it almost one week but without result. Is there problem with base64 chars or with encoding/decoding mechanism ?
Many thanks for the answers.
final class Otp
{
private static $charSet = array('+','/','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z');
public static function encryptFile($originalFilePath, $encryptedFilePath, $keyFilePath)
{
if(!self::existsFile($keyFilePath) || !self::existsFile($encryptedFilePath)) {
if($originalFileData = self::existsFile($originalFilePath)) {
$originalFileBase64Data = base64_encode($originalFileData);
$originalFileBase64DataLength = strlen($originalFileBase64Data) - 1;
$originalFileBase64DataArray = str_split($originalFileBase64Data);
$encryptedData = NULL;
$encryptedDataKey = NULL;
for ($i = 0; $i <= $originalFileBase64DataLength; $i++) {
$randKey = rand(0, sizeOf(self::$charSet) - 1);
$arrayKey = array_search($originalFileBase64DataArray[$i], self::$charSet);
if($randKey > $arrayKey) {
$str = '-' . ($randKey - $arrayKey);
} elseif($randKey < $arrayKey) {
$str = ($randKey + $arrayKey);
} else {
$str = $randKey;
}
$encryptedData .= self::$charSet[$randKey];
$encryptedDataKey .= $str. ';';
}
$encryptedDataString = $encryptedData;
$encryptedDataKeyString = $encryptedDataKey;
if(!self::existsFile($keyFilePath)) {
file_put_contents($keyFilePath, $encryptedDataKeyString);
}
if(!self::existsFile($encryptedFilePath)) {
file_put_contents($encryptedFilePath, $encryptedDataString);
}
return 'OK';
} else {
return 'Source file not exists';
}
} else {
return 'Encrypted data already exists';
}
}
public static function decryptFile($encryptedFilePath, $keyFilePath, $decryptedFilePath)
{
$keyFileData = self::existsFile($keyFilePath);
$encryptedFileData = self::existsFile($encryptedFilePath);
$encryptedFileDataLength = strlen($encryptedFileData) - 1;
if($encryptedFileData && $keyFileData) {
$encryptedFileDataArray = str_split($encryptedFileData);
$keyFileDataArray = explode(';', $keyFileData);
$decryptedData = NULL;
for ($i = 0; $i <= $encryptedFileDataLength; $i++) {
$poziciaaktualneho = array_search($encryptedFileDataArray[$i], self::$charSet);
$poziciasifrovana = $keyFileDataArray[$i];
if($poziciasifrovana < 0) {
$move = $poziciasifrovana + $poziciaaktualneho;
} elseif($poziciasifrovana > 0) {
$move = $poziciasifrovana - $poziciaaktualneho;
} else {
$move = '0';
}
$decryptedData .= self::$charSet[$move];
}
if(!self::existsFile($decryptedFilePath)) {
file_put_contents($decryptedFilePath, base64_decode($decryptedData));
return 'OK';
} else {
return 'Decrypted data already exists';
}
}
}
private static function existsFile($filePath)
{
$fileData = #file_get_contents($filePath);
if($fileData) {
return $fileData;
}
return FALSE;
}
}
$originalFilePath = 'original.jpg';
$keyFilePath = 'Otp_Key_' . $originalFilePath;
$encryptedFilePath = 'Otp_Data_' . $originalFilePath;
$decryptedFilePath = 'Otp_Decrypted_' . $originalFilePath;
echo Otp::encryptFile($originalFilePath, $encryptedFilePath, $keyFilePath);
echo Otp::decryptFile($encryptedFilePath, $keyFilePath, $decryptedFilePath);
The problem seems to be only happening when $poziciaaktualneho is equal to $poziciasifrovana and so by adding another if statement on line 78 to check for this and instead set $move equal to $poziciasifrovana I was able to fix the problem. The below script should work:
final class Otp
{
private static $charSet = array('+','/','0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z');
public static function encryptFile($originalFilePath, $encryptedFilePath, $keyFilePath)
{
if(!self::existsFile($keyFilePath) || !self::existsFile($encryptedFilePath)) {
if($originalFileData = self::existsFile($originalFilePath)) {
$originalFileBase64Data = base64_encode($originalFileData);
$originalFileBase64DataLength = strlen($originalFileBase64Data) - 1;
$originalFileBase64DataArray = str_split($originalFileBase64Data);
$encryptedData = NULL;
$encryptedDataKey = NULL;
for ($i = 0; $i <= $originalFileBase64DataLength; $i++) {
$randKey = rand(0, sizeOf(self::$charSet) - 1);
$arrayKey = array_search($originalFileBase64DataArray[$i], self::$charSet);
if($randKey > $arrayKey) {
$str = '-' . ($randKey - $arrayKey);
} elseif($randKey < $arrayKey) {
$str = ($randKey + $arrayKey);
} else {
$str = $randKey;
}
$encryptedData .= self::$charSet[$randKey];
$encryptedDataKey .= $str. ';';
}
$encryptedDataString = $encryptedData;
$encryptedDataKeyString = $encryptedDataKey;
if(!self::existsFile($keyFilePath)) {
file_put_contents($keyFilePath, $encryptedDataKeyString);
}
if(!self::existsFile($encryptedFilePath)) {
file_put_contents($encryptedFilePath, $encryptedDataString);
}
return 'OK';
} else {
return 'Source file not exists';
}
} else {
return 'Encrypted data already exists';
}
}
public static function decryptFile($encryptedFilePath, $keyFilePath, $decryptedFilePath)
{
$keyFileData = self::existsFile($keyFilePath);
$encryptedFileData = self::existsFile($encryptedFilePath);
$encryptedFileDataLength = strlen($encryptedFileData) - 1;
if($encryptedFileData && $keyFileData) {
$encryptedFileDataArray = str_split($encryptedFileData);
$keyFileDataArray = explode(';', $keyFileData);
$decryptedData = NULL;
for ($i = 0; $i <= $encryptedFileDataLength; $i++) {
$poziciaaktualneho = array_search($encryptedFileDataArray[$i], self::$charSet);
$poziciasifrovana = $keyFileDataArray[$i];
if ($poziciasifrovana == $poziciaaktualneho) {
$move = $poziciasifrovana;
} elseif($poziciasifrovana < 0) {
$move = $poziciasifrovana + $poziciaaktualneho;
} elseif($poziciasifrovana > 0) {
$move = $poziciasifrovana - $poziciaaktualneho;
} else {
$move = '0';
}
$decryptedData .= self::$charSet[$move];
}
if(!self::existsFile($decryptedFilePath)) {
file_put_contents($decryptedFilePath, base64_decode($decryptedData));
return 'OK';
} else {
return 'Decrypted data already exists';
}
}
}
private static function existsFile($filePath)
{
$fileData = #file_get_contents($filePath);
if($fileData) {
return $fileData;
}
return FALSE;
}
}
$originalFilePath = 'original.jpg';
$keyFilePath = 'Otp_Key_' . $originalFilePath;
$encryptedFilePath = 'Otp_Data_' . $originalFilePath;
$decryptedFilePath = 'Otp_Decrypted_' . $originalFilePath;
echo Otp::encryptFile($originalFilePath, $encryptedFilePath, $keyFilePath);
echo Otp::decryptFile($encryptedFilePath, $keyFilePath, $decryptedFilePath);
Warning: I would not recommend using my solution in an enterprise setting if at all since I do not know why this fixes your script or what was
originally wrong with it and it is most likely not air tight.

PHP - ID generator//not working on linux

I have made an "ID generator" for a website known as xat now this fully works on any up to date windows machine. But I do not understand why when I run it on a linux Debian server I get:
root#vps:/idgen# php get.php
[3:45:42 PM] Connected to MySQL server
[3:45:42 PM] Starting ID Generator With 0 IDs to begin with.
PHP Fatal Error: Call to undefined function curl_init() in /idgen/get.php on line 70
root#vps:/idgen#
(I am new to linux machines. I did some research but till don't understand it :L my code is very long. Its
<?php
set_time_limit(0);
ini_set('display_error', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');
$idGen = new IDGenerator;
$loop = 1;
while(true)
{
switch(#$argv[1]) {
case '0':
default:
$list = fopen('proxies.txt', 'r');
while(!feof($list))
{
$proxy = fgets($list);
$idGen->generate($proxy);
}
fclose($list);
break;
}
$loop++;
usleep(50000);
$idGen->report('Starting loop #'.$loop);
}
class IDGenerator
{
public $sql = NULL;
public $one = array('1','2','3','4','5','6','7','8','9','0');
public $two = array('11','22','33','44','55','66','77','88','99','00');
public $three = array('111','222','333','444','555','666','777','888','999','000');
public $four = array('0000','1010','1111','1212','1313','1414','1515','1616','1717','1818','1919','2020','2121','2222','2323','2424','2525','2626','2727','2828','2929','3030','3131','3232','3333','3434','3535','3636','3737','3838','3939','4040','4141','4242','4343','4444','4545','4646','4747','4848','4949','5050','5151','5252','5353','5454','5555','5656','5757','5858','5959','6060','6161','6262','6363','6464','6565','6666','6767','6868','6969','7070','7171','7272','7373','7474','7575','7676','7777','7878','7979','8080','8181','8282','8383','8484','8585','8686','8787','8888','8989','9090','9191','9292','9393','9494','9595','9696','9797','9898','9999');
public $five = array('00000','10101','11111','12121','13131','14141','15151','16161','17171','18181','19191','20202','21212','22222','23232','24242','25252','26262','27272','28282','29292','30303','31313','32323','33333','34343','35353','36363','37373','38383','39393','40404','41414','42424','43434','44444','45454','46464','47474','48484','49494','50505','51515','52525','53535','54545','55555','56565','57575','58585','59595','60606','61616','62626','63636','64646','65656','66666','67676','68686','69696','70707','71717','72727','73737','74747','75757','76767','77777','78787','79797','80808','81818','82828','83838','84848','85858','86868','87878','88888','89898','90909','91919','92929','93939','94949','95959','96969','97979','98989','99999');
public $six = array('000000','101010','111111','121212','131313','141414','151515','161616','171717','181818','191919','202020','212121','222222','232323','242424','252525','262626','272727','282828','292929','303030','313131','323232','333333','343434','353535','363636','373737','383838','393939','404040','414141','424242','434343','444444','454545','464646','474747','484848','494949','505050','515151','525252','535353','545454','555555','565656','575757','585858','595959','606060','616161','626262','636363','646464','656565','666666','676767','686868','696969','707070','717171','727272','737373','747474','757575','767676','777777','787878','797979','808080','818181','828282','838383','848484','858585','868686','878787','888888','898989','909090','919191','929292','939393','949494','959595','969696','979797','989898','999999');
public $seven = array('0000000','1010101','1111111','1212121','1313131','1414141','1515151','1616161','1717171','1818181','1919191','2020202','2121212','2222222','2323232','2424242','2525252','2626262','2727272','2828282','2929292','3030303','3131313','3232323','3333333','3434343','3535353','3636363','3737373','3838383','3939393','4040404','4141414','4242424','4343434','4444444','4545454','4646464','4747474','4848484','4949494','5050505','5151515','5252525','5353535','5454545','5555555','5656565','5757575','5858585','5959595','6060606','6161616','6262626','6363636','6464646','6565656','6666666','6767676','6868686','6969696','7070707','7171717','7272727','7373737','7474747','7575757','7676767','7777777','7878787','7979797','8080808','8181818','8282828','8383838','8484848','8585858','8686868','8787878','8888888','8989898','9090909','9191919','9292929','9393939','9494949','9595959','9696969','9797979','9898989','9999999');
public $eight = array('00000000','10101010','11111111','12121212','13131313','14141414','15151515','16161616','17171717','18181818','19191919','20202020','21212121','22222222','23232323','24242424','25252525','26262626','27272727','28282828','29292929','30303030','31313131','32323232','33333333','34343434','35353535','36363636','37373737','38383838','39393939','40404040','41414141','42424242','43434343','44444444','45454545','46464646','47474747','48484848','49494949','50505050','51515151','52525252','53535353','54545454','55555555','56565656','57575757','58585858','59595959','60606060','61616161','62626262','63636363','64646464','65656565','66666666','67676767','68686868','69696969','70707070','71717171','72727272','73737373','74747474','75757575','76767676','77777777','78787878','79797979','80808080','81818181','82828282','83838383','84848484','85858585','86868686','87878787','88888888','89898989','90909090','91919191','92929292','93939393','94949494','95959595','96969696','97979797','98989898','99999999');
public $nine = array('000000000','101010101','111111111','121212121','131313131','141414141','151515151','161616161','171717171','181818181','191919191','202020202','212121212','222222222','232323232','242424242','252525252','262626262','272727272','282828282','292929292','303030303','313131313','323232323','333333333','343434343','353535353','363636363','373737373','383838383','393939393','404040404','414141414','424242424','434343434','444444444','454545454','464646464','474747474','484848484','494949494','505050505','515151515','525252525','535353535','545454545','555555555','565656565','575757575','585858585','595959595','606060606','616161616','626262626','636363636','646464646','656565656','666666666','676767676','686868686','696969696','707070707','717171717','727272727','737373737','747474747','757575757','767676767','777777777','787878787','797979797','808080808','818181818','828282828','838383838','848484848','858585858','868686868','878787878','888888888','898989898','909090909','919191919','929292929','939393939','949494949','959595959','969696969','979797979','989898989','999999999');
public $proxy;
public $cp = array();
public function __construct()
{
include('database.class.php');
$this->sql = new Database($this);
$this->report('Connected to MySQL Server');
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report('Starting ID Generator With '.$nc.' IDs to begin with.');
}
public function generate($ip='111.111.111.111',$port=1, $elapsed=0) {
if( ( $elapsed - time() ) >= 0 && $elapsed != 0) {
//This causes MAJOR terminal/CMD flood.
// $this->report('Proxy: '.$ip.':'.$port.' will be trying again in '.$this->sec2hms($elapsed-time()));
return;
}
$this->cp = array(
'ip' => $ip,
'port' => $port
);
$proxy = $ip.':'.$port;
$tries = 0;
$xData = '';
$timeout = 3;
// echo "Tries -> ";
while($xData=='' && $tries < 3) {
$ch = curl_init(); //curl init :D
curl_setopt($ch, CURLOPT_URL, 'http://xat.com/web_gear/chat/auser3.php?t='.rand(100000000000,1000000000000000000000000000000000)); //url
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$rdata = $data;
if(#$data{0} == '<') {
return;//Bad Proxy Detected.
}
if(strpos($data, 'Not Found') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
}
if($data != '&UserId=0&k1=0&k2=0') {
if(strpos($data, '&k2=0') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
} else {
$xData = $data;
}
} else {
echo $data."\n";
}
$tries++;
}
if($xData=='') {
return;//Dead Proxy
}
if (strlen($data) < 50 && $data) {
$this->check($data);
}
}
public function sec2hms($sec, $padHours = false) {
#$hms = "";
#$days = intval($sec/86400);
if($days > 0 ) {
if($days == 1) {
#$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$days.' Day');
} else {
#$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$days.' Days');
}
}
#$sec-= ($days*86400);
#$hours = intval(intval($sec) / 3600);
if($hours > 0) {
if($days > 0) { #$s = ', '; }
if($hours == 1) {
#$hms .= #$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$hours.' Hour');
} else {
#$hms .= #$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$hours.' Hours');
}
}
#$minutes = intval(($sec / 60) % 60);
if($minutes > 0) {
if($hours > 0) { #$d = ', '; }
if($minutes == 1) {
#$hms .= #$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minute';
} else {
#$hms .= #$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minutes';
}
}
#$seconds = intval($sec % 60);
if($seconds > 0) {
if($minutes > 0) { #$p = ', '; }
if($seconds == 1) {
#$hms .= #$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Second';
} else {
#$hms .= #$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Seconds';
}
}
return #$hms;
}
public function report($data) {
$time = date('g:i:s A', time());
echo "[$time] $data\n";
}
public function rwrite($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = true;
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$auser['added'] = date('l, F jS Y g:i:s A');
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a rare id, we have '.$nc.' ids now.');
}
public function write($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = false;
$auser['added'] = date('l, F jS Y g:i:s A');
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a normal id, we have '.$nc.' ids now.');
}
public function determinePrice($id='0') {
if($id=='0' || !is_numeric($id)) {
return '0';//0 xats cuz of no id.
}
$price = 100;//Start the bid off at 100 xats, NO FREE IDS.
if ( $this->strposa($id, $this->nine) ) {
$price = $price + 900;// never mind that, make it 1k
} else
if ( $this->strposa($id, $this->eight) ) {
$price = $price + 800;
} else
if ( $this->strposa($id, $this->seven) ) {
$price = $price + 700;
} else
if ( $this->strposa($id, $this->six) ) {
$price = $price + 600;
} else
if ( $this->strposa($id, $this->five) ) {
$price = $price + 500;
} else
if ( $this->strposa($id, $this->four) ) {
$price = $price + 150;
} else
if ( $this->strposa($id, $this->three) ) {
$price = $price + 20;
}
return $price;
}
public function idFix($data='&UserId=0&k1=0&k2=0')
{
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$user = explode('&', $data);
return array(
'UserId'=> str_replace('UserId=', '', #$user[1]),
'k1' => str_replace('k1=', '', #$user[2]),
'k2'=> str_replace('k2=', '', #$user[3])
);
}
public function randomString($chars=32) {
$letters = range('a','z');
$caps = range('A', 'Z');
$numbers = range(0, 9);
$array = array_merge(range('a','z'), array_merge(range('A', 'Z'), range(0,9)));
for($x=0;$x<=100;$x++) {
shuffle($array);//shuffle it up really good =D
}
$i = 0;
$ch = '';
for($index=0; $index<$chars; $index++) {
$ch .= $array[ array_rand($array) ];
}
return $ch;
}
public function CheckForID($id=0)
{
if($id==0) return true;
$check = $this->sql->select('*', 'ids', 'UserId='.$id);
if(!$check)
{
return false;
}
return true;
}
public function check($data='&UserId=0&k1=0&k2=0') {
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$auser = $this->idFix($data);
$this->storage($auser['UserId'], $data);
}
public function storage($id, $data) {
if ($this->strposa($id,$this->nine) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->eight) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->seven) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->six) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->five) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->four) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->three) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else {
$this->write($data);
return true;
}
return false;
}
public function reset() {
die('restart me!');
}
public function strposa($haystack, $needles=array(), $offset=1) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle);
if ($res !== false)
{
$chr[$needle] = $res;
}
}
if(empty($chr))
{
return false;
}
return min($chr);
}
}
?>
The PHP fatal error actually has nothing whatsoever to do with Linux itself, it's the cURL extension that's missing from PHP.
To get back to the Debian side of things, to install the extension, run this in a command line / terminal:
sudo apt-get install php5-curl
Note: Don't EVER copy-paste stuff from the internet into your console. You could be copying hidden text as well and potentially compromise your system. Go ahead and type it.

Categories