Wp All import Hot to Add Child Element in XML that not have - wpallimport

I had a problem with wp all import... I try to explain:
this is my XML
<Node>
<CodeID>1533</CodeID>
....
<Size>36|37|38</Size>
</Node>
the problem is that I need a child element of Size in this way
<Variations>
<Variation1>36</Variation1>
<Variation2>37</Variation2>
<Variation3>38</Variation3>
</Variations>
Is there a way or a functions to modify to have this xml and add all variations as a child element and not all in the same line?

<?php
$string = "<?xml version='1.0'?>
<Item>
<Node>
<CodeID>1533</CodeID>
<Size>36|37|38</Size>
</Node>
<Node>
<CodeID>L534</CodeID>
<Size>S|M|L</Size>
</Node>
</Item>";
$xml = simplexml_load_string($string);
$xml2 = simplexml_load_string($string);
//$xml = simplexml_load_file("./Items.xml", 'SimpleXMLElement', LIBXML_NOCDATA);
$i=0;
foreach ($xml as $item)
{
$variations_array = explode("|",$item->Size);
$j=0;
foreach ($variations_array as $variation)
{
$xml2->Node[$i]->Variations->Variation[$j] = $variation;
$j++;
}
$i++;
}
echo $xml2->asXML();
//$xml2->asXML("./Items2.xml");
/*
<?xml version="1.0"?>
<Item>
<Node>
<CodeID>1533</CodeID>
<Size>36|37|38</Size>
<Variations>
<Variation>36</Variation>
<Variation>37</Variation>
<Variation>38</Variation>
</Variations>
</Node>
<Node>
<CodeID>L534</CodeID>
<Size>S|M|L</Size>
<Variations>
<Variation>S</Variation>
<Variation>M</Variation>
<Variation>L</Variation>
</Variations>
</Node>
</Item>
*/
?>

Related

Wordpress - custom PHP function to save multiple nodes inside XML into multiple user meta fields

We have a XML containing multiple nodes inside one parent. I will give you the example below:
<PARENT>
<Data>
<DATE_FIELD>11.07.2018</DATE_FIELD>
<SUM_AVG/>
<DOUBLE_AVG/>
<THIRD_AVG/>
<FOURTH_AVG>45000.00</FOURTH_AVG>
</Data>
<Data>
<DATE_FIELD>10.08.2018</DATE_FIELD>
<SUM_AVG>546.45</SUM_AVG>
<DOUBLE_AVG>472.50</DOUBLE_AVG>
<THIRD_AVG>180.00</THIRD_AVG>
<FOURTH_AVG>44453.55</FOURTH_AVG>
</Data>
<Data>
<DATE_FIELD>10.09.2018</DATE_FIELD>
<SUM_AVG>536.59</SUM_AVG>
<DOUBLE_AVG>482.36</DOUBLE_AVG>
<THIRD_AVG>180.00</THIRD_AVG>
<FOURTH_AVG>43916.96</FOURTH_AVG>
</Data>
<Data>
<DATE_FIELD>12.06.2023</DATE_FIELD>
<SUM_AVG>995.85</SUM_AVG>
<DOUBLE_AVG>23.10</DOUBLE_AVG>
<THIRD_AVG>180.00</THIRD_AVG>
<FOURTH_AVG>1009.23</FOURTH_AVG>
</Data>
<Data>
<DATE_FIELD>10.07.2023</DATE_FIELD>
<SUM_AVG>1009.23</SUM_AVG>
<DOUBLE_AVG>9.80</DOUBLE_AVG>
<THIRD_AVG>180.00</THIRD_AVG>
<FOURTH_AVG/>
</Data>
</PARENT>
We would like to store these multiple values inside different custom fields inside the wp_usermeta table (Table containing custom fields for Users), using WP ALL IMPORT plugin. By default, you have to manually assign corresponding nodes inside the settings of the plugin.
For this, I have tried to hook a custom PHP function into the "pmxi_saved_post" action, loop through the "Data" nodes & add each one to an appropriately sepparate named custom field. So, for each node inside "Data", we have to store it into a separate custom field.
The problem is that it doesn't store anything inside the wp_usermeta table.
Here is the code:
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($id) {
foreach( $data as $key => $value ) {
update_post_meta( $post_id, $key, $value );
}
I have managed to get it working, with the following function:
function wpallimport_post_saved( $post_id, $xml_data, $is_update ) {
if(!empty($xml_data->PARENT){
$xml = $xml_data->PARENT;
$counter = 1;
foreach($xml->Data as $counts => $data){
foreach($data as $key => $user_meta){
update_user_meta( $post_id, strtolower($key) . "-data-" . $counter , current($user_meta));
}
$counter++;
}
}
}

How can I add a custom button to Add and Edit posts / pages?

What function / hook do I need to use in order to insert a button here, on the Add and Edit post pages?
Thank you very much!
the hook you are looking for is media_buttons_context. You could do something like the following:
add_action('media_buttons_context', 'add_my_custom_button');
function add_my_custom_button($context) {
//path to my icon
$img = 'penguin.png';
//our popup's title
$title = 'An Inline Popup!';
//append the icon
$context .= "<a title='{$title}' href='#'>
<img src='{$img}' /></a>";
return $context;
}
Source Here!

How do you create a new view in Jomsocial

I am having a hard time figuring out how the exactly the routing works in JomSocial. Does anyone know how to create a new view?
First of all, you create a controller to make a request of a view:
file: controllers/hello.php
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
class CommunityHelloController extends CommunityBaseController
{
function helloWorld() //index.php?option=com_community&view=hello&task=helloWorld
{
$document = JFactory::getDocument();
$viewType = $document->getType();
$view = $this->getView('hello', '' , $viewType);
echo $view->get('helloWorld');
}
function hello() //index.php?option=com_community&view=hello&task=hello
{
$document = JFactory::getDocument();
$viewType = $document->getType();
$view = $this->getView('hello', '' , $viewType);
echo $view->get('helloWorld');
}
}
?>
View: views/hello/view.html.php
Here you place variables that will be passed to template file
For example:
<?php
defined('_JEXEC') or die('Restricted access');
jimport ( 'joomla.application.component.view' );
class CommunityViewHello extends CommunityView {
function helloWorld() //This function shows a "Hello World" without an template view
{
echo 'Hello World';
}
function hello()
{
$user = CFactory::getUser($userid);
$tmpl = new CTemplate( ); //Call a template file
echo $tmpl->set ( 'user', $user )
->fetch ( 'hello' ); // Returns the templates/default/hello.php file
}
}
File templates/default/hello.php:
<?php defined('_JEXEC') or die();?>
<h2> This is an example </h2>
<div class="container">
<p> Hello, <?php echo $user->name; ?></p>
</div>
That's all!
I may have made this as a comment to the answer given by #Thavia-Farias in 2013, but my reputation is not high enough to comment. The content of my answer will restate her information along with crucial new information, corrections, and enhancements according to my experience using Jomsocial 4.2.1:
First off, the controllers/hello.php as provided by #Thavia-Farias has an error: In both the function helloWorld() and function helloWorld()function hello(), the final line is echo $view->get('helloWorld');, but the function in function hello() should be echo $view->get('hello');. As it stands, both *index.php?option=com_community&view=hello&task=helloworld and index.php?option=com_community&view=hello&task=hello will both call the helloworld view, rather than the second one calling the hello view as it should.
Also, in my experience, rather than putting the template at the path /templates/default/hello.php, I put it at /templates/customtemplatename/html/com_community/layouts if you are using a cusomt template or /components/com_community/templates/jomsocial/layouts/ if you are using the default jomsocial template.
create /components/com_community/controllers/hello.php:
<?php
defined('_JEXEC') or die();
class CommunityHelloController extends CommunityBaseController
{
public function renderView($viewfunc, $var = NULL) {
$my = CFactory::getUser();
$jinput = JFactory::getApplication()->input;
$document = JFactory::getDocument();
$viewType = $document->getType();
$viewName = $jinput->get('view', $this->getName());
$view = $this->getView($viewName, '', $viewType);
echo $view->get($viewfunc, $var);
}
function helloWorld()
{
$this->renderView(__FUNCTION__);
}
function hello()
{
$this->renderView(__FUNCTION__);
}
function display($cacheable = false, $urlparams = false) {
$this->renderView(__FUNCTION__);
}
}
?>
create /var/www/html/components/com_community/views/hello/view.html.php:
<?php
defined('_JEXEC') or die('Restricted access');
jimport ( 'joomla.application.component.view' );
class CommunityViewHello extends CommunityView {
function helloWorld() //This function shows a "Hello World" without an template view
{
echo 'Hello World';
}
function display() //This function what happens when the hello view is called without a task
{
echo 'welcome to the main landing page for the hello view! There is nothing else shown here besides this message.';
}
function hello()
{
echo $tmpl->fetch('hello');
}
}
As you can see, if you want your view to have a default view even when no task is called, similar to what happens with /index.php?option=com_community&view=groups then you will want to name a task as function display in the controller and in the view.
finally, create /components/com_community/templates/jomsocial/layouts/hello.php:
<?php defined('_JEXEC') or die();?>
<h2> This is an example </h2>
<div class="container">
<p> Hello, <?php echo $my->name; ?></p>
</div>
$my was defined way back in the controller! When your views and tasks group big enough, you will have different files for each task. The tasks files are with the fetch function in the view.html.php.
$tmpl = new CTemplate( ); //Call a template file
echo $tmpl->set ( 'vars1', $vars1)
echo $tmpl->set ( 'vars2', $vars2)
echo $tmpl->set ( 'vars3', $vars3)
->fetch ( 'hello' );
calls the /components/com_community/templates/jomsocial/layouts/hello.php file.
Using ->fetch ( 'hello.greeting' ); calls /components/com_community/templates/jomsocial/layouts/hello.greeting.php.
If you want to create a new directory for these then ->fetch ( 'hello/create' ); calls
/components/com_community/templates/jomsocial/layouts/hello/create.php
If you want to create menu items and aliases for your new components, then you need to create a new file (as well as a second and modify a third if you want to do pass menu-item defined parameters to your tasks):
create file: /components/com_community/views/hello/metadata.xml:
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<view title="Groups">
<message>
<![CDATA[
Hello view
]]>
</message>
<options var="task">
<default name="Hello" msg="displays landing page" />
<option value="hello" name="- one greeting" msg="Display detail page of one greeting" />
<option value="helloWorld" name="- helloworldview" msg="Display whatever you have in the hello world task" />
</options>
</view>
<state>
<name>Hello Groups Layout</name>
<description>Hello Groups listings</description>
</state>
</metadata>
This file will add items to the "community" section of the menu in the administrator menu panel. The option values are the names of the tasks. The option without a value that is uses the default tag will pull up the display function described earlier.
If you need to add parameters to the file, then you need to do something a bit complicated:
create /components/com_community/views/hello/tmpl/default.xml:
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="Name" option="View">
<message>
</message>
</layout>
<fields name="params">
<fieldset
name="basic"
label="Selected Group">
<field
name="item_id"
query="SELECT `id`, `name` FROM #__community_groups_category WHERE ORDER BY `id`"
type="sql"
key_field="id"
value_field="name"
label="Associated Group"
require="true"
description="Select the jomsocial group whose hello task this will be associated with">
</field>
</fieldset>
</fields>
</metadata>
This will create a tab wherein users can specify one group out of available groups in the database. It will assign the id of the group to the parameters field in the #__menu database table in the params colums JSON object as the value for the item_id key. In order for your view to use that value when rendering the page, include the following code in views/hello/view.html.php:
$mainframe = JFactory::getApplication();
$jinput = $mainframe->input;
$document = JFactory::getDocument();
// Get category id from the query string if there are any.
$groupId = $jinput->getInt('group', 0);
// Load the parameters.
$params = $mainframe->getParams();
$params_array = $params->toArray();
if (isset($params_array['item_id']))
{
$groupId = $params_array['item_id'];
}
In this way, your task can receive the necessary specifics from either the URL if given from within your component(option=com_community&view=hello&task=hello&groupid=5), or from being called by a main menu or jomsocial toolbar item drawing of the stored parameters in the menu database table for that menu item.
The options and tab that you create here will be visible for all menu items of this task. If you want different tabs for different menu options, you will have to create entirely different views. having everything in one view may lead to unused and potentially misleading tabs where values can be set by your users but that will not or should not be used by the actual task specified by the user.
Forgive me for not testing every line of this code in an integrated component. I have done all of these functions in my view but have abridged my code which was built with initial guidance from #Thavia-Farias's answer. While it is more clear than posting my extensive code, it has not been tested in it's current form for functionality. Be sure to check your php error logs to debug your project. I have to log in as root (sudo su) and check with nano /var/log/mysqld/error_log on my system. Good luck!

How to improve this script to load half of the youtube embedding code

I have this script
$alt .='<div id="fragment-'.($j+1).'" class="ui-tabs-panel">
'.get_post_meta($niphell[post_id], 'embed', true).'</div>';
on a wordpress theme which takes the information from a custom field and it echo it on the featured section. On that custom field I put the embedding code from YouTube and I want to write only the YT video ID on that custom field. The rest of the code to be on the script. "embed" is the custom field.
For example, for normal posts I have this code
<object width= "640" height="384"><param name="movie" value="http://www.youtube.com/v/<?php $values = get_post_custom_values("youtubeid"); echo $values[0]; ?>?modestbranding=1&autoplay=1&rel=0&fs=1&color1=0xffffff&color2=0xffffff&border=0&loop=1&showinfo=0&iv_load_policy=3"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/<?php $values = get_post_custom_values("youtubeid"); echo $values[0]; ?>?modestbranding=1&autoplay=1&rel=0&fs=1&color1=0xffffff&color2=0xffffff&border=0&loop=1&showinfo=0&iv_load_policy=3" type="application/x-shockwave-flash" allowfullscreen="false" width="640" height="384"></embed></object>
and when I want to post a new video I only write the video ID and pres publish.
So, if can anybody help me with this piece of code I will make him a statue :) My programing skills are zero so... The whole piece of code is here: http://predi.ro/stick/featured.txt All I need is to get the YT emedding code on that script so when I add a new featured video, all I need to do is to write only the YT video ID, not the whole embedding code.
Something like the following function would work. Where ever you want the video to appear, simply call the function and pass the video ID as the argument. Just add the function to the right after the opening
function embedYouTube($id)
{
$url = 'http://www.youtube.com/v/';
$params = '?modestbranding=1&autoplay=1&rel=0&fs=1&color1=0xffffff&color2=0xffffff&border=0&loop=1&showinfo=0&iv_load_policy=3';
$code = '<object width="640" height="384">' .
'<param name="movie" value="' . $url . $id . $params . '"></param>' .
'<param name="allowFullScreen" value="false"></param>' .
'<param name="allowscriptaccess" value="always"></param>' .
'<embed src="' . $url . $id . $params . '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="false" width="640" height="384"></embed>' .
'</object>';
echo $code;
}
For example.
<? embedYouTube("7DK68JJW9pk"); ?>

HTTPservice Help

My Flex code is unable to reach the PHP, but when i do normally it works like
http://localhost/search/populate.php?urlWeb=http://www.google.com
$url = addslashes( $_GET['urlWeb'] );
if( !$url )
{
die( "You need to define a URL to process." );
}
else if( substr($url,0,7) != "http://" )
{
$url = "http://$url";
$output = "<loginsuccess>";
$output .="yes";
$output .= "</loginsuccess>";
print($output);
}
<mx:HTTPService id="addWeb" resultFormat="object" result="Added(event)" showBusyCursor="true" method="GET" url="http://localhost/search/populate.php" useProxy="false">
<mx:request xmlns="">
<urlWeb>
{urlWeb.text}
</urlWeb>
</mx:request>
</mx:HTTPService>
it may be a crossdomain.xml issue. Try placing a crossdomain.xml file (http://localhost/crossdomain.xml) with the following contents:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" secure="false" />
</cross-domain-policy>
And run the app again. If it still doesn't work can you please add fault handler to your HTTPService, check if you have an error and if you do post it here so we can see what's the problem?

Resources