Recreate structure of html page from array - php

Good morning everyone,
I'm trying to recreate a html page extracting data from an array.
This is the array
$MiniSiteStructureArray = array(
'section_1' => array(
'class' => 'main full',
'contents' => array(
'img' => array(
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
),
'div' => array(
'class' => 'cover sfondo',
'img' => array(
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
),
'div_1' => array(
'class' => 'cover-mob sfondo-mob',
'img' => array(
'class' => 'cover-image-mob',
'src' => 'assets/images/cover-img-mobile.jpg'
)
),
'a' => array(
'class' => 'button order light',
'div' => array(
'class' => 'data-min',
'div' => array(
'class' => 'label-holder',
'img' => array(
'src' => 'assets/images/sfondo-cta.jpg'
),
'p' => array(
'class' => 'label',
'strong' => 'text'
)
),
'div_1' => array(
'class' => 'price-holder'
)
)
),
'div_2' => array(
'class' => 'cta',
'p' => array(
'class' => 'main-title',
'a' => array(
'strong' => 'text'
)
)
),
'img_1' => array(
'class' => 'main-title',
'src' => 'assets/images/extra_1.png'
)
)
),
'section_2' => array(
'class' => 'gallery',
'id' => 'video',
'contents' => array(
'p' => array(
'class' => 'title video-title',
'span' => array(
'strong' => 'text'
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item video',
'div' => array(
'class' => 'wrapper video-wrapper',
'img' => array(
'class' => 'play-vid pointer thumb',
'src' => 'assets/images/img-spot-tv.png'
),
'img_1' => array(
'class' => 'play-icon hover',
'src' => 'assets/images/play.png'
)
)
)
)
)
)
)
),
'section_3' => array(
'class' => 'gallery',
'id' => 'image',
'contents' => array(
'p' => array(
'class' => 'title image-title',
'span' => array(
'strong' => array(
'strong' => 'text'
)
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-1.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_1' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-2.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_2' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-3.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
'div_i' => array(
'class' => 'internal single',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper image-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/img-i.png'
),
'p' => array(
'class' => 'caption image-caption',
'span' => 'text'
)
)
)
),
)
),
'div_1' => array(
'class' => 'counter'
)
)
),
'section_4' => array(
'class' => 'main',
'id' => 'info',
'contents' => array(
'div' => array(
'class' => 'cover sfondo',
'img' => array(
'class' => 'cover-image',
'src' => 'assets/images/collection-img.jpg'
)
),
'div' => array(
'class' => 'cover-mob sfondo-mob',
'img' => array(
'class' => 'cover-image-mob',
'src' => 'assets/images/collection-img-mobile.jpg'
)
),
'a' => array(
'class' => 'button order light',
'div' => array(
'class' => 'data-min',
'div' => array(
'class' => 'label-holder',
'img' => array(
'src' => 'assets/images/sfondo-cta.jpg'
),
'p' => array(
'class' => 'label',
'strong' => 'text'
)
),
'div_1' => array(
'class' => 'price-holder',
)
)
),
'p' => array(
'class' => 'text-numero-1',
'span' => array(
'strong' => '',
'strong_1' => 'text',
'strong_2' => 'text',
'strong_3' => array(
'class' => 'text-anziche',
'strike' => 'text'
)
)
)
)
),
'section_5' => array(
'class' => 'banner resize',
'id' => 'num1',
'contents' => array(
'div' => array(
'class' => 'cover'
),
'div_1' => array(
'class' => 'container',
'img' => array(
'class' => 'banner-image',
'src' => 'assets/images/number-1.png'
),
'p' => array(
'class' => 'cta num1-cta',
'span' => array(
'a' => 'text'
)
)
)
)
),
'section_6' => array(
'class' => 'gallery',
'id' => 'gifts',
'contents' => array(
'p' => array(
'class' => 'title gifts-title',
'span' => array(
'strong' => array(
'strong' => 'text'
)
)
),
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'arrow-container prev',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-sx_1.png'
)
),
'div_1' => array(
'class' => 'arrow-container next',
'img' => array(
'class' => 'arrow',
'src' => 'assets/images/freccia-dx_1.png'
)
),
'div_2' => array(
'class' => 'gallery-holder',
'div' => array(
'class' => 'internal double',
'div' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper gifts-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/gift-1.jpg'
),
'p' => array(
'class' => 'caption gifts-caption',
'span' => 'text'
)
)
),
'div_1' => array(
'class' => 'gallery-item',
'div' => array(
'class' => 'wrapper gifts-wrapper',
'img' => array(
'class' => 'thumb',
'src' => 'assets/images/gift-2.jpg'
),
'p' => array(
'class' => 'caption gifts-caption',
'span' => 'text'
)
)
)
)
)
),
'div_1' => array(
'class' => 'counter'
),
'p' => array(
'class' => 'disclaimer gifts-disclaimer',
'span' => array(
'span' => 'text'
)
)
)
),
'section_7' => array(
'class' => 'footer',
'contents' => array(
'div' => array(
'class' => 'container',
'div' => array(
'class' => 'box',
'div' => array(
'class' => 'wrapper',
'p' => array(
'class' => 'icon pointer',
'img' => array(
'src' => 'assets/images/icn-piano-opera.png'
)
),
'a' => array(
'class' => 'link',
'p' => array(
'class' => 'title',
'span' => 'text'
)
)
)
),
'div_1' => array(
'class' => 'box',
'div' => array(
'class' => 'wrapper',
'p' => array(
'class' => 'icon pointer',
'img' => array(
'src' => 'assets/images/icn-piano-opera.png'
)
),
'a' => array(
'class' => 'link gtm-externallinks',
'p' => array(
'class' => 'title',
'span' => 'text'
)
)
)
)
)
)
),
'section_8' => array(
'class' => 'partners resize',
'contents' => array(
'div' => array(
'class' => 'container',
'img' => array(
'class' => 'partner',
'src' => 'assets/images/logo-dinsey-lucasfilm_2_1.png'
),
'img_1' => array(
'class' => 'partner',
'src' => 'assets/images/logo-mondadori_1_1.png'
)
)
)
),
'section9' => array(
'class' => 'partners-light',
'contents' => array(
'div' => array(
'class' => 'container',
'img' => array(
'class' => 'partner',
'src' => 'assets/images/copyrightLucasLight.png'
)
)
)
));
foreach ($MiniSiteStructureArray as $section => $sectionStructure) {
foreach ($sectionStructure['contents'] as $tag => $contents) {
$tags[] = $tag;
}
$a = formatTag($tags);
$sections[] = $section;
}
$b = formatTag($sections);
as you can see html tags aren't well formed (es. div and div_1), so I have created this function
function formatTag($tags) {
$correctTags = array();
foreach ($tags as $tag) {
switch ($tag) {
case strpos($tag, "img"):
$tag = "img";
break;
case strpos($tag, "div"):
$tag = "div";
break;
case strpos($tag, "a"):
$tag = "a";
break;
case strpos($tag, "p"):
$tag = "p";
break;
case strpos($tag, "section"):
$tag = "section";
break;
}
array_push($correctTags, $tag);
}
return $correctTags;
}
So my idea is to recreate the array with new keys (well formed tag).
But now i'm stuck.
Supposing that the newKeysArray is done and supposing to create section_1.
How can I do?
Thanks
Edit : New array
$structureArray = array(
'tag' => 'section_8',
'class' => 'partners resize',
'contents' => array(
'tag' => 'div',
'class' => 'container',
'contents' => array(
'tag' => 'img',
'class' => 'partner',
'src' => 'assets/images/logo-dinsey-lucasfilm_2_1.png'
)
)
);
Better?
Edit_2 : NewNewArray
$structureArray = array(
'tag' => array(
'tagName' => 'section_1',
'class' => 'main full',
'contents' => array(
'tag' => array(
'tagName' => 'img',
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
),
),
),
'tag_1' => array(
'tagName' => 'div',
'class' => 'cover sfondo',
'contents' => array(
'tag' => array(
'tagName' => 'img',
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
),
),
);
This should be better, don't you think?
In this case I manually incremented key tag because in html page it not appears
Edit_3_I_hope: NewNewNewArray
$structureArray = array(
'tag' => array(
'tagName' => 'section_1',
'tagAttributes' => array(
'class' => 'main full',
),
'contents' => array(
'tag' => array(
'tagName' => 'img',
'tagAttributes' => array(
'class' => 'logo',
'src' => 'assets/images/logo-480x176.png'
)
),
),
),
'tag_1' => array(
'tagName' => 'div',
'tagAttributes' => array(
'class' => 'cover sfondo',
),
'contents' => array(
'tag' => array(
'tagName' => 'img',
'tagAttributes' => array(
'class' => 'cover-image',
'src' => 'assets/images/cover-img-header.png'
)
)
),
),
);
Now, it seems very good

My proposal for the array structure:
$htmlArray = ['tag' => ['name' => 'ul'],
'attrs' => [['name' => 'class','value' => 'beautiful_list'],
['name' => 'id', 'value' => 'unique_list']],
'text' => ['tag' => ['name' => 'li'
'text' => 'item 1'],
'tag' => ['name' => 'li'
'text' => 'item 2']]];
I hope this is somewhat clear?
These two is equivalent:
array()
[]

Related

FOREACH in LINE BOT FLEX

can anyone help me with this problem?
I had a LINE Messenger BOT, and I want to implement foreach() loop to show a list from the database I have. but I struggle with the code. here is what I wrote
function indexflex($title,$label,$text){
$data = $this->Dbs->getdata_kamusengineer()->result();
foreach ($data as $d) {
$dariindo=$d->dariindo;
$bajep=$d->bajep;
$arraynumber= 0;
$itemindeks=array (
'type' => 'box',
'layout' => 'vertical',
'contents' => array (
$arraynumber++ => array (
'type' => 'box',
'layout' => 'horizontal',
'contents' => array (
0 => array (
'type' => 'text',
'text' => $dariindo,
'align' => 'center',
'wrap' => true,
'gravity' => 'center',
'contents' => array (
),
),
1 => array (
'type' => 'separator',
'margin' => 'sm',
'color' => '#000000FF',
),
2 => array (
'type' => 'text',
'text' => $bajep,
'align' => 'center',
'align' => 'center',
'wrap' => true,
'gravity' => 'center',
'contents' =>
array (
),
),
),
),
),
);
}
$item = array (
'type' => 'bubble',
'direction' => 'ltr',
'header' => array (
'type' => 'box',
'layout' => 'vertical',
'contents' => array (
0 => array (
'type' => 'text',
'text' => $title,
'weight' => 'bold',
'align' => 'center',
'wrap' => true,
'contents' =>
array (
),
),
),
),
'body' => $itemindeks,
'footer' => array (
'type' => 'box',
'layout' => 'horizontal',
'contents' => array (
0 => array (
'type' => 'button',
'action' => array (
'type' => 'message',
'label' => $label,
'text' => $text,
),
'style' => 'primary',
),
),
),
);
return $item;
}
but the result not what i want, it just shows one of my data from many.
image of the result
can anyone help me what's wrong with this code?
Thanks,

How to set Default value on search form?

I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!
I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!

CGridview fit with screen Resolution without Scroll

Im using Editable Grid extension of CGridview.
MY Grid:
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider,
'template' => '{items}{pager} ',
'id' => 'PO-grid',
'htmlOptions'=>array(
//'style'=>'width:1100px;'
),
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'PO_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]ref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'SupplierRef',
'name' => '[{gridNum}][{rowNum}]productref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Product',
'name' => '[{gridNum}][{rowNum}]productname',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '2'
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Qty',
'name' => '[{gridNum}][{rowNum}]qty',
'tag' => 'textField',
'tagHtmlOptions' => array(
'size' => '2',
'readonly'=>true,'width'=>'10px','style'=>'width:70px;'
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Description',
'name' => '[{gridNum}][{rowNum}]description',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '5'
'readonly'=>true
)
),
array('class'=>'CButtonColumn','template' => '{delete}',
'buttons'=>array(
'delete' => array(
'options'=>array('style'=>'margin-left:20px'),
'imageUrl'=>\Yii::app()->request->baseUrl.'/images/delete.png', )
),
),
),
));?>
My problem is, Gridview is fit with 1600 X 900 px screen , it should not fit with below px.
Anyone please help me to reolve this problem.
I want to make this grid fit with screen 1366 px.

dynamic menu and submenu by clicking menu the submenu should be displayed,my id not firing in jquery

global.php
return array(
'navigation' => array(
'default' => array(
array(
'label' =>'Home',
'route' => 'home',
'use_route_match' => true,
),
array(
'label'=>'Access',
'route' => 'access',
'constraints' =>
array (
'class' => 'access',
),
'use_route_match' => true,
'pages' => array(
'city'=> array(
'label'=>'City',
'route' => 'city',
'id' => 'city',
'use_route_match' => true,
),
),
),
array(
'label'=>'Privacy',
'route' => 'privacy',
'use_route_match' => true,
),
),
),
);

loop options into array

I have an array that has a value with multiple options that is broken down into it's own array. One of those values I want to populate with a loop. Is this possible with the ; in the forloop I would think it would break. What is the best way to accomplish this request?
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array(
for ($x=0; $x<=10; $x++){
array('name' => __($x , 'title'), 'value' => $x)
}
)
),
Here is the complete array outside of what I posted:
$meta_boxes[] = array(
'id' => 'januas_speakers',
'title' => __('Ensemble', 'januas'),
'pages' => array('ja-event'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __('Visible', 'januas'),
'desc' => __('Select Yes to show the box in the event page, No to hide it.', 'januas'),
'id' => 'januas_speakers_visible',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Position', 'januas'),
'desc' => __('Select the preferred position for the box.', 'januas'),
'id' => 'januas_speakers_position',
'type' => 'select',
'options' => array(
array('name' => __('Main', 'januas'), 'value' => 'main'),
array('name' => __('Sidebar', 'januas'), 'value' => 'sidebar'),
)
),
array(
'name' => __('Order', 'januas'),
'desc' => __('Insert the box order (ex: 1).', 'januas'),
'id' => 'januas_speakers_order',
'std' => 1,
'type' => 'text_small'
),
array(
'name' => __('Show Title', 'januas'),
'desc' => __('Select Yes to show the box title, No to hide it.', 'januas'),
'id' => 'januas_speakers_showtitle',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Show in Top menu', 'januas'),
'desc' => __('Select Yes to show the menu item in the event page top menu, No to hide it.', 'januas'),
'id' => 'januas_speakers_showinmenu',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_images_gallery',
'type' => 'image_gallery'
),
array(
'name' => __('Ensemble List', 'januas'),
'desc' => 'Select the ensemble memebers for this event.',
'id' => 'januas_speakers_completelist',
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'januas'),
'value' => $x,
);
}, range(0,11))
),
array(
'name' => __('Display order', 'januas'),
'desc' => '',
'id' => 'januas_speakers_speakersorder',
'type' => 'event_speakers'
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_speakers_backtotop',
'type' => 'backtotop'
)
),
);
You could use array_map:
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'title'),
'value' => $x,
);
}, range(0,11))
),
You should use array_push
$a = array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array()
);
for ($x=0; $x<=10; $x++){
array_push( $a['options'], array('name' => __($x , 'title'), 'value' => $x) );
}
print_r($a);
Do you need to run the loop inside of options? How about this approach.
$foo = array();
for ($x=0;$x<10;$x++)
$foo[] = $x;
$bar = array(
'name' => 'hello',
'options' => $foo
);
print_r($bar);
https://eval.in/54925

Categories