XML feed for Wordpress Social Board plugin modifications - php

At work, I've been tasked with modifying the Wordpress Social Board plugin by duplicating their RSS feed functionality to display an XML feed specific to our calendaring system.
For example, this is what our XML feed outputs:
<?xml version="1.0"?>
<events>
<event>
<eventid>1449080815796</eventid>
<sponsorid>14</sponsorid>
<inputsponsor>Administration</inputsponsor>
<displayedsponsor>Lesbian, Gay, Bisexual, and Transgender (LGBT) Resource Center, The Division of Student Affairs</displayedsponsor>
<displayedsponsorurl></displayedsponsorurl>
<date>2016-01-25</date>
<timebegin>18:00</timebegin>
<timeend>20:00</timeend>
<repeat_vcaldef></repeat_vcaldef>
<repeat_startdate></repeat_startdate>
<repeat_enddate></repeat_enddate>
<categoryid>119</categoryid>
<category>Diversity</category>
<title>New 2 &apos;Quse Discussion Group</title>
<description>New 2 &apos;Quse is a discussion group for students who are new to SU/ESF and the lesbian, gay, bisexual, transgender, queer, asexual, and ally (LGBTQA) campus communities.</description>
<location>LGBT Resource Center (750 Ostrom)</location>
<price></price>
<contact_name>Abby Fite</contact_name>
<contact_phone>443-3983</contact_phone>
<contact_email>alfite#syr.edu</contact_email>
<url>http://lgbt.syr.edu</url>
<recordchangedtime>2015-12-02 13:26:55</recordchangedtime>
<recordchangeduser>dsalgbt2</recordchangeduser>
</event>
</events>
There is one place in the code that actually formats their RSS feed:
elseif ( $feed_class == 'rss' ) {
$rss_output = (#$this->sboption['section_rss']['rss_output']) ? $this->sboption['section_rss']['rss_output'] : array('title' => true, 'thumb' => true, 'text' => true, 'user' => true, 'tags' => false, 'share' => true, 'info' => true);
$iframe = #$this->sboption['section_rss']['rss_iframe'];
$fcount = 0;
if ( $channel = #$feed->channel ) { // rss
if (#$channel->item)
foreach($channel->item as $item) {
$link = #$item->link;
if ( $this->make_remove($link) ) {
$fcount++;
$thumb = $url = '';
foreach($item->children('media', true)->thumbnail as $thumbnail) {
$thumb = $thumbnail->attributes()->url;
}
if ( ! $thumb) {
foreach($item->children('media', true)->content as $content) {
$thumb = $content->children('media', true)->thumbnail->attributes()->url;
if (#$content->attributes()->type == 'image/jpeg')
$url = #$content->attributes()->url;
}
}
if ( ! $thumb) {
if (#$item->enclosure->attributes()->type == 'image/jpeg')
$thumb = #$item->enclosure->attributes()->url;
}
if (#$item->category && #$rss_output['tags'])
foreach($item->category as $category) {
$cats[] = (string) $category;
}
// set Snippet or Full Text
$text = $description = '';
if (#$this->sboption['section_rss']['rss_text'])
$description = $item->description;
else
$description = (#$item->children("content", true)->encoded) ? $item->children("content", true)->encoded : $item->description;
if (#$description) {
$description = preg_replace("/<script.*?\/script>/s", "", $description);
if (#$attr['words']) {
if ( ! $thumb) {
$thumb = sb_getsrc($description);
}
$text = $this->word_limiter($description, $link);
} else {
$text = $description;
}
}
if ($iframe) {
if ( ! $url)
$url = (#$thumb) ? $thumb : '';
}
$sbi = $this->make_timestr($item->pubDate, $link);
$itemdata = array(
'thumb' => (#$thumb) ? $thumb : '',
'thumburl' => $url,
'title' => '<a href="' . $link . '"'.$target.'>' . (#$attr['titles'] ? $this->title_limiter($item->title) : $item->title) . '</a>',
'text' => $text,
'tags' => #implode(', ', $cats),
'url' => $link,
'iframe' => $iframe ? 'icbox' : '',
'date' => $item->pubDate,
'user' => array(
'name' => $channel->title,
'url' => $channel->link,
'image' => #$channel->image->url
),
'type' => 'pencil',
'icon' => array(#$themeoption['social_icons'][12], #$themeoption['type_icons'][0])
);
$final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
if ( isset($slideshow) ) {
$itemdata['text'] = #$this->format_text($description);
if ($url)
$itemdata['thumb'] = $url;
$finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
}
if ( $fcount >= $results ) break;
}
}
} elseif ( $entry = #$feed->entry ) { // atom
// get feed link
foreach($feed->link as $link) {
if ($link->attributes()->rel == 'alternate')
$user_url = $link->attributes()->href;
}
foreach($feed->entry as $item) {
$link = #$item->link[0]->attributes()->href;
if ( $this->make_remove($link) ) {
$fcount++;
$title = (string) $item->title;
$thumb = $url = '';
foreach($item->media as $thumbnail) {
$thumb = $thumbnail->attributes()->url;
}
if ( ! $thumb) {
foreach($item->link as $linkitem) {
if (#$linkitem->attributes()->rel == 'enclosure') {
if (#$linkitem->attributes()->type == 'image/jpeg')
$thumb = #$content->attributes()->url;
}
}
}
$cats = '';
if (#$item->category && #$rss_output['tags']) {
foreach($item->category as $category) {
$cats .= $category->attributes()->term.', ';
}
$cats = rtrim($cats, ", ");
}
// set Snippet or Full Text
$text = $description = '';
if (#$this->sboption['section_rss']['rss_text']) {
$description = (string) $item->summary;
} else {
$content = (string) #$item->content;
$description = ($content) ? $content : (string) $item->summary;
}
if (#$description) {
if (#$attr['words']) {
if ( ! $thumb) {
$thumb = sb_getsrc($description);
}
$text = $this->word_limiter($description, $link);
}
else {
$text = $description;
}
}
if ($iframe)
$url = (#$thumb) ? $thumb : '';
$sbi = $this->make_timestr($item->published, $link);
$itemdata = array(
'thumb' => #$thumb,
'thumburl' => $url,
'title' => '<a href="' . $link . '"'.$target.'>' . (#$attr['titles'] ? $this->title_limiter($title) : $title) . '</a>',
'text' => #$text,
'tags' => #$cats,
'url' => $link,
'iframe' => $iframe ? 'icbox' : '',
'date' => $item->published,
'user' => array(
'name' => $feed->title,
'url' => #$user_url,
'image' => #$feed->logo
),
'type' => 'pencil',
'icon' => array(#$themeoption['social_icons'][12], #$themeoption['type_icons'][0])
);
$final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
if ( isset($slideshow) ) {
$itemdata['text'] = #$this->format_text($description);
if ($url)
$itemdata['thumb'] = $url;
$finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
}
if ( $fcount >= $results ) break;
}
}
}
}
I've duplicated the code into another feed class and modified, but it is not pulling any values it seems:
elseif ( $feed_class == 'dsa' ) {
$rss_output = (#$this->sboption['section_dsa']['dsa_output']) ? $this->sboption['section_dsa']['dsa_output'] : array('title' => true, 'thumb' => true, 'text' => true, 'user' => true, 'tags' => false, 'share' => true, 'info' => true);
$iframe = #$this->sboption['section_dsa']['dsa_iframe'];
$fcount = 0;
if ( $channel = #$feed->events ) { // rss
if (#$channel->event)
foreach($channel->event as $item) {
$link = #$item->displayedsponsorurl;
if ( $this->make_remove($link) ) {
$fcount++;
$thumb = $url = '';
foreach($item->children('media', true)->thumbnail as $thumbnail) {
$thumb = $thumbnail->attributes()->url;
}
if ( ! $thumb) {
foreach($item->children('media', true)->content as $content) {
$thumb = $content->children('media', true)->thumbnail->attributes()->url;
if (#$content->attributes()->type == 'image/jpeg')
$url = #$content->attributes()->url;
}
}
if ( ! $thumb) {
if (#$item->enclosure->attributes()->type == 'image/jpeg')
$thumb = #$item->enclosure->attributes()->url;
}
if (#$item->category && #$rss_output['tags'])
foreach($item->category as $category) {
$cats[] = (string) $category;
}
// set Snippet or Full Text
$text = $description = '';
if (#$this->sboption['section_dsa']['dsa_text'])
$description = $item->description;
else
$description = (#$item->children("content", true)->encoded) ? $item->children("content", true)->encoded : $item->description;
if (#$description) {
$description = preg_replace("/<script.*?\/script>/s", "", $description);
if (#$attr['words']) {
if ( ! $thumb) {
$thumb = sb_getsrc($description);
}
$text = $this->word_limiter($description, $link);
} else {
$text = $description;
}
}
if ($iframe) {
if ( ! $url)
$url = (#$thumb) ? $thumb : '';
}
$sbi = $this->make_timestr($item->pubDate, $link);
$itemdata = array(
'thumb' => (#$thumb) ? $thumb : '',
'thumburl' => $url,
'title' => '<a href="' . $link . '"'.$target.'>' . (#$attr['titles'] ? $this->title_limiter($item->title) : $item->title) . '</a>',
'text' => $text,
'tags' => #implode(', ', $cats),
'url' => $link,
'iframe' => $iframe ? 'icbox' : '',
'date' => $item->date,
'user' => array(
'name' => $channel->title,
'url' => $channel->link,
'image' => #$channel->image->url
),
'type' => 'pencil',
'icon' => array(#$themeoption['social_icons'][12], #$themeoption['type_icons'][0])
);
$final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
if ( isset($slideshow) ) {
$itemdata['text'] = #$this->format_text($description);
if ($url)
$itemdata['thumb'] = $url;
$finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
}
if ( $fcount >= $results ) break;
}
}
} elseif ( $entry = #$feed->entry ) { // atom
// get feed link
foreach($feed->link as $link) {
if ($link->attributes()->rel == 'alternate')
$user_url = $link->attributes()->href;
}
foreach($feed->entry as $item) {
$link = #$item->link[0]->attributes()->href;
if ( $this->make_remove($link) ) {
$fcount++;
$title = (string) $item->title;
$thumb = $url = '';
foreach($item->media as $thumbnail) {
$thumb = $thumbnail->attributes()->url;
}
if ( ! $thumb) {
foreach($item->link as $linkitem) {
if (#$linkitem->attributes()->rel == 'enclosure') {
if (#$linkitem->attributes()->type == 'image/jpeg')
$thumb = #$content->attributes()->url;
}
}
}
$cats = '';
if (#$item->category && #$rss_output['tags']) {
foreach($item->category as $category) {
$cats .= $category->attributes()->term.', ';
}
$cats = rtrim($cats, ", ");
}
// set Snippet or Full Text
$text = $description = '';
if (#$this->sboption['section_dsa']['dsa_text']) {
$description = (string) $item->summary;
} else {
$content = (string) #$item->content;
$description = ($content) ? $content : (string) $item->summary;
}
if (#$description) {
if (#$attr['words']) {
if ( ! $thumb) {
$thumb = sb_getsrc($description);
}
$text = $this->word_limiter($description, $link);
}
else {
$text = $description;
}
}
if ($iframe)
$url = (#$thumb) ? $thumb : '';
$sbi = $this->make_timestr($item->published, $link);
$itemdata = array(
'thumb' => #$thumb,
'thumburl' => $url,
'title' => '<a href="' . $link . '"'.$target.'>' . (#$attr['titles'] ? $this->title_limiter($title) : $title) . '</a>',
'text' => #$text,
'tags' => #$cats,
'url' => $link,
'iframe' => $iframe ? 'icbox' : '',
'date' => $item->published,
'user' => array(
'name' => $feed->title,
'url' => #$user_url,
'image' => #$feed->logo
),
'type' => 'pencil',
'icon' => array(#$themeoption['social_icons'][12], #$themeoption['type_icons'][0])
);
$final[$sbi] = $layoutobj->sb_create_item($feed_class, $itemdata, $attr, $rss_output, $sbi);
if ( isset($slideshow) ) {
$itemdata['text'] = #$this->format_text($description);
if ($url)
$itemdata['thumb'] = $url;
$finalslide[$sbi] = $slidelayoutobj->sb_create_slideitem($feed_class, $itemdata, $attr, $rss_output, $sbi);
}
if ( $fcount >= $results ) break;
}
}
}
}
I apologize for this being a highly specific question. I am inexperienced with PHP, especially for Wordpress plugins and have been tasked to get this working ASAP...
Am I just missing something with the operators not pulling in the values? I haven't set all the values yet, I'm just modifying the ones that already exist before moving onto adding anything.
There are no direct errors my logs pulled, so I believe it's just not pulling in the right values, but I'm not sure how to fix that.

Related

Run a function inside a worpress shortcode php function

I am trying to create a shortcode to connect to an API but there is a problem with the shortcode. I know that it is because a function is inside a functinon but I can't figure out how to fix. I tried something that didn't work.
// Add Shortcode
function api_test() {
function execute_request( $args ) {
global $base_url;
$target_url = add_query_arg( $args, $base_url );
$data = wp_remote_get( $target_url );
echo '<pre><code>';
print_r( $data['body'] );
echo '<code></pre>';
}
if ( ! current_user_can( 'manage_options' ) ) die();
// API variables, please override
$base_url = 'https://website.com';
$email = 'email#gmail.com';
$product_id = '1146';
$license_key = '0g96b29x5v27fmfnmbr4hxaflky';
$instance = '';
$request = ( isset( $_GET['request'] ) ) ? $_GET['request'] : '';
$links = array(
'check' => 'Check request',
'activation' => 'Activation request',
'deactivation' => 'Deactivation',
'version_check' => 'Version Check',
);
foreach ( $links as $key => $value ) {
echo '' . $value . ' | ';
}
// Valid check request
if ( $request == 'check' ) {
$args = array(
'wc-api' => 'serial-numbers-api',
'request' => 'check',
'email' => $email,
'serial_key' => $license_key,
'product_id' => $product_id
);
echo '<br>';
echo '<br>';
echo '<b>Valid check request:</b><br />';
//execute_request( $args );
$this->execute_request($args);
}
}
add_shortcode( 'api-test', 'api_test' );
Just create execute_request() outside of shortcode.
function execute_request( $args ) {
global $base_url;
$target_url = add_query_arg( $args, $base_url );
$data = wp_remote_get( $target_url );
echo '<pre><code>';
print_r( $data['body'] );
echo '<code></pre>';
}
function api_test() {
if ( ! current_user_can( 'manage_options' ) ) die();
// API variables, please override
$base_url = 'https://website.com';
$email = 'email#gmail.com';
$product_id = '1146';
$license_key = '0g96b29x5v27fmfnmbr4hxaflky';
$instance = '';
$request = ( isset( $_GET['request'] ) ) ? $_GET['request'] : '';
$links = array(
'check' => 'Check request',
'activation' => 'Activation request',
'deactivation' => 'Deactivation',
'version_check' => 'Version Check',
);
foreach ( $links as $key => $value ) {
echo '' . $value . ' | ';
}
// Valid check request
if ( $request == 'check' ) {
$args = array(
'wc-api' => 'serial-numbers-api',
'request' => 'check',
'email' => $email,
'serial_key' => $license_key,
'product_id' => $product_id
);
echo '<br>';
echo '<br>';
echo '<b>Valid check request:</b><br />';
//execute_request( $args );
execute_request($args);
}
}
add_shortcode( 'api-test', 'api_test' );

Why categories relation with products disappear when I update products in Opencart?

I'm developing an extension in Opencart when I try updating existing products with a relationship to some categories, the products get uncategorized and leave their categories although I disabled all kinds of categorizing in product importing or updating.
Here a snippet of product import & update function:
public function format_product( $product, $update = false, $force_update = false ){
if( empty( $product ) ){
return $product;
}
if( !$update || $force_update ){
$temp = array(
'product_description' => array(),
'model' => isset( $product->sku ) ? $product->sku : '',
'sku' => isset( $product->sku ) ? $product->sku : '',
'upc' => '',
'ean' => '',
'jan' => '',
'isbn' => '',
'mpn' => '',
'location' => '',
'price' => '0',
'points' => '',
'tax_class_id' => '0',
'quantity' => '0',
'minimum' => '1',
'subtract' => '1',
'stock_status_id' => '5',
'shipping' => '1',
'date_available' => date( 'Y-m-d', strtotime( '-1 day') ),
'length' => '',
'width' => '',
'height' => '',
'length_class_id' => '1',
'weight' => '',
'weight_class_id' => '1',
'status' => '1',
'sort_order' => '0',
'manufacturer' => '',
'manufacturer_id' => '0',
'product_store' => array(0),
// 'product_category' => array(),
'product_option' => array(),
'image' => '' // This is Pending.
);
// Add to selected stores.
if ( !empty( $this->all_stores ) ) {
$temp['product_store'] = $this->all_stores;
}
$languageCodes = array();
foreach ( $this->languages as $key => $lng ) {
// Check for name in current language.
$lng_code = explode( '-', $lng['code'] );
$lng_code = $lng_code[0];
$name = $product->name;
$description = $product->description;
/*$product_name = array_key_exists( $lng_code, $name ) ? $name[$lng_code] : $name['en'];
$product_desc = array_key_exists( $lng_code, $description ) ? $description[$lng_code] : $description['en'];*/
$product_name = isset( $name->$lng_code ) ? $name->$lng_code : '';
if( empty( $product_name )){
$product_name = isset( $name->en ) ? $name->en : '';
}
/*set url*/
if(version_compare(VERSION, '3.0.0','<') ) {
if(isset($name->en)){
$urlData = $name->en;
}elseif (isset($name->$lng_code)) {
$urlData = $name->en;
}
if(!empty($urlData)){
$url = strtolower($urlData);
$urlKey = str_replace(' ', '-', $url);
$temp['keyword'] = $urlKey;
}
}
/*set url*/
$product_desc = isset( $description->$lng_code ) ? $description->$lng_code : '';
if( empty( $product_desc )){
$product_desc = isset( $description->en ) ? $description->en : '';
}
$temp['product_description'][$lng['language_id']] = array(
'name' => $product_name,
'description' => $product_desc,
'meta_title' => $product_name,
'meta_description' => '',
'meta_keyword' => '',
'tag' => '',
);
$languageCodes[] = $lng_code;
$languageIds[$lng_code] = $lng['language_id'];
}
/*attribute group code*/
if(!empty($languageCodes)){
$language_code = $languageCodes[0];
$attributeGrouplanguageId = $languageIds[$language_code];
}
/*load model*/
if( $this->is_admin ){
$this->load->model('catalog/attribute_group');
}else{
$admin_dir = str_replace( 'system/', 'admin/', DIR_SYSTEM );
require_once $admin_dir . "model/catalog/attribute_group.php";
$this->model_catalog_attribute_group = new ModelCatalogAttributeGroup( $this->registry );
}
/*load model*/
$attribute_group_id = $this->model_extension_module_knawat_dropshipping->getAttributeGroup('knawat');
if(!$attribute_group_id){
/*add attribute set*/
$attributeGroupArray = array();
$attributeGroupArray['sort_order'] = 2;
$attributeGroupArray['attribute_group_description'][$attributeGrouplanguageId] = array(
'name' => 'Knawat'
);
$attribute_group_id = $this->model_catalog_attribute_group->addAttributeGroup($attributeGroupArray);
}
/*add attribute set*/
/*attribute group code*/
/*load model*/
if( $this->is_admin ){
$this->load->model('catalog/attribute');
}else{
$admin_dir = str_replace( 'system/', 'admin/', DIR_SYSTEM );
require_once $admin_dir . "model/catalog/attribute.php";
$this->model_catalog_attribute = new ModelCatalogAttribute( $this->registry );
}
/*load model*/
/*variation array*/
if (isset($product->variations[0]->attributes) && !empty($product->variations[0]->attributes)) {
$attribute = $product->variations[0]->attributes;
if($attribute[0]){
if (isset($attribute[0]->name) || !empty($attribute[0]->name) ) {
$variationdata = (array)$attribute[0]->name;
}
}
}
/*variation array*/
/*attribute code*/
if (isset($product->attributes) && !empty($product->attributes)) {
$subArray = array();
foreach ($product->attributes as $key => $attribute) {
$attributeNames = (array)$attribute->name;
foreach ($attributeNames as $key => $value) {
if(!empty($variationdata[$key]) && !in_array($variationdata[$key], $attributeNames)){
if(in_array($key, $languageCodes)){
$attributeId = $this->model_extension_module_knawat_dropshipping->getAttributeData($value);
if(!$attributeId){
$languageId = $languageIds[$key];
$newArray[$languageId] = array(
'language_id' => $languageId,
'name' => $value
);
}
}
}
}
if(!empty($newArray)){
$subArray['attribute_group_id'] = $attribute_group_id;
$subArray['sort_order'] = 2;
$subArray['attribute_description'] = $newArray;
$this->model_catalog_attribute->addAttribute($subArray);
}
}
}
/*attribute code*/
/*product code*/
if(!empty($product->attributes)){
foreach ($product->attributes as $key => $attribute) {
$attributeNames = (array)$attribute->name;
if($variationdata != $attributeNames){
$productAttributes = array();
foreach ($attributeNames as $key => $value) {
if(in_array($key, $languageCodes)){
$languageId = $languageIds[$key];
if(isset($attribute->options[0]->$key)){
$options = $attribute->options[0]->$key;
}else{
if(isset($attribute->options[0]->en)){
$options = $attribute->options[0]->en;
}else if (isset($attribute->options[0]->ar)) {
$options = $attribute->options[0]->ar;
}else if (isset($attribute->options[0]->tr)){
$options = $attribute->options[0]->tr;
}
}
$attributeId = $this->model_extension_module_knawat_dropshipping->getAttributeData($value);
$productAttributes[$languageId] = array(
'text' => $options
);
$attributeId = (int) $attributeId;
$temp['product_attribute'][] = array(
'attribute_id' => $attributeId,
'product_attribute_description' => $productAttributes
);
}
}
}
}
}
/*product code end*/
/**
* Setup Product Category.
*/
//make products get uncategorized in both import and update.
// if( isset( $product->categories ) && !empty( $product->categories ) ) {
// $new_cats = array();
// foreach ( $product->categories as $category ) {
// if( isset( $category->name ) && !empty( $category->name ) ){
// $new_cats[] = (array)$category->name;
// }
// }
// $temp['product_category'] = $this->model_extension_module_knawat_dropshipping->parse_categories( $new_cats );
// }
/**
* Setup Product Images.
*/
if( isset( $product->images ) && !empty( $product->images ) ) {
$images = (array)$product->images;
$product_sku = isset( $product->sku ) ? $product->sku : '';
$product_images = $this->parse_product_images( $images, $product_sku );
if( !empty( $product_images ) ){
$temp['image'] = $product_images[0];
unset( $product_images[0] );
if( count( $product_images ) > 0 ){
foreach ($product_images as $pimage ) {
$temp_image['image'] = $pimage;
$temp_image['sort_order'] = '0';
$temp['product_image'][] = $temp_image;
}
}
}
}
}else{
$temp = array();
}
if( isset( $product->variations ) && !empty( $product->variations ) ){
$quantity = 0;
$price = $product->variations[0]->sale_price;
if( isset( $product->variations[0]->market_price ) ){
$market_price = $product->variations[0]->market_price;
}
if( empty( $market_price ) ){
$market_price = $price;
}
foreach ( $product->variations as $vvalue ) {
$quantity += $vvalue->quantity;
}
if(isset($product->variations[0]->weight)){
$weight = $product->variations[0]->weight;
$temp['weight'] = $weight;
}
$temp['price'] = $market_price;
$temp['quantity'] = $quantity;
if( $quantity > 0 ){
$temp['stock_status_id'] = '7';
}else{
$temp['stock_status_id'] = '5';
}
if(!empty($price)){
if($price < $market_price){
$temp['product_special'][] = array(
'customer_group_id' => 1,
'price' => $price,
'priority' => 1,
'date_start' => 0000-00-00,
'date_end' => 0000-00-00
);
}
}
$temp['product_option'] = $this->model_extension_module_knawat_dropshipping->parse_product_options( $product->variations, $price,$update );
}
if(!empty($temp['product_option'])){
foreach ($temp['product_option'] as $key) {
$i = 0;
if(isset($key['product_option_value'])){
$j = count($key['product_option_value']);
}else{
$j = 0;
}
foreach ($key['product_option_value'] as $value) {
if($value['quantity'] == 0){
$i++;
}
}
}
if($i == $j){
$temp['stock_status_id'] = '5';
}
}
if(empty($temp['product_option']) && !$update){
$this->log->write("Product Failed , It's variations not available or available with zero quantity, Sku : ".$temp['sku']);
return false;
}
///////////////////////////////////
/////// #TODO Custom Fields ///////
///////////////////////////////////
error_log("Orginal Product: " . json_encode($product));
error_log("temp Product: " . json_encode($temp));
return $temp;
}
If anyone can help me with this problem. Thank you
So the answer to this question is as follows:
editProduct function in CatalogModel class in Opencart removes all relation_id_to_category before beginning to modify an existing product, so in order to not make the attached categories in a product be removed you should comment out this line of code and everything as it should but it may affect other modules working in Opencart so do it at your own risk.

How to show gravity form uploaded file in post page

I am working with multi file upload with gravity form. So after uploading I want to show the uploaded file in single post page (single.php). How to show the uploaded files in the post page. I have been using this.
(http://pastebin.com/r9w2beDW)
class GW_Multi_File_Merge_Tag {
private static $instance = null;
private $_merge_tag_args = array();
private $_settings = array();
private function __construct() {
add_filter( 'gform_pre_replace_merge_tags', array( $this, 'replace_merge_tag' ), 10, 7 );
}
public static function get_instance() {
if( null == self::$instance )
self::$instance = new self;
return self::$instance;
}
public function get_default_args() {
return array(
'form_id' => false,
'exclude_forms' => array(),
'default_markup' => '{filename}.{ext}',
'markup' => array(
array(
'file_types' => array( 'jpg', 'png', 'gif' ),
'markup' => ''
),
array(
'file_types' => array( 'mp4', 'ogg', 'webm' ),
'markup' => '
Your browser does not support the video tag.
'
),
array(
'file_types' => array( 'ogv' ),
'markup' => '
Your browser does not support the video tag.
'
)
)
);
}
public function register_settings( $args = array() ) {
$args = wp_parse_args( $args, $this->get_default_args() );
if( ! $args['form_id'] ) {
$this->_settings['global'] = $args;
} else {
$this->_settings[$args['form_id']] = $args;
}
}
public function replace_merge_tag( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER );
foreach( $matches as $match ) {
$input_id = $match[1];
$field = GFFormsModel::get_field( $form, $input_id );
if( ! $this->is_applicable_field( $field ) )
continue;
if( $format != 'html' ) {
$value = $this->_merge_tag_args['value'];
} else {
if( $entry['id'] == null && is_callable( array( 'GWPreviewConfirmation', 'preview_image_value' ) ) ) {
$files = GWPreviewConfirmation::preview_image_value( 'input_' . $field->id, $field, $form, $entry );
} else {
$value = GFFormsModel::get_lead_field_value( $entry, $field );
$files = empty( $value ) ? array() : json_decode( $value, true );
}
$value = '';
foreach( $files as &$file ){
$value .= $this->get_file_markup( $file, $form['id'] );
}
}
$text = str_replace( $match[0], $value, $text );
}
return $text;
}
public function get_file_markup( $file, $form_id ) {
$value = str_replace( " ", "%20", $file );
$file_info = pathinfo( $value );
extract( $file_info ); // gives us $dirname, $basename, $extension, $filename
if( ! $extension )
return $value;
$markup_settings = $this->get_markup_settings( $form_id );
if( empty( $markup_settings ) )
return $value;
$markup_found = false;
foreach( $markup_settings as $file_type_markup ) {
$file_types = array_map( 'strtolower', $file_type_markup['file_types'] );
if( ! in_array( strtolower( $extension ), $file_types ) )
continue;
$markup_found = true;
$markup = $file_type_markup['markup'];
$tags = array(
'{url}' => $file,
'{filename}' => $filename,
'{basename}' => $basename,
'{ext}' => $extension
);
foreach( $tags as $tag => $tag_value ) {
$markup = str_replace( $tag, $tag_value, $markup );
}
$value = $markup;
break;
}
if( ! $markup_found && $default_markup = $this->get_default_markup( $form_id ) ) {
$tags = array(
'{url}' => $file,
'{filename}' => $filename,
'{basename}' => $basename,
'{ext}' => $extension
);
foreach( $tags as $tag => $tag_value ) {
$default_markup = str_replace( $tag, $tag_value, $default_markup );
}
$value = $default_markup;
}
return $value;
}
public function get_markup_settings( $form_id ) {
$form_markup_settings = rgars( $this->_settings, "$form_id/markup" ) ? rgars( $this->_settings, "$form_id/markup" ) : array();
$global_markup_settings = rgars( $this->_settings, 'global/markup' ) ? rgars( $this->_settings, 'global/markup' ) : array();
return array_merge( $form_markup_settings, $global_markup_settings );
}
public function get_default_markup( $form_id ) {
$default_markup = rgars( $this->_settings, "$form_id/default_markup" );
if( ! $default_markup )
$default_markup = rgars( $this->_settings, 'global/default_markup' );
return $default_markup;
}
public function is_excluded_form( $form_id ) {
$has_global_settings = isset( $this->_settings['global'] );
$excluded_forms = (array) rgars( $this->_settings, 'global/exclude_forms' );
$explicity_excluded = $has_global_settings && in_array( $form_id, $excluded_forms );
$passively_excluded = ! $has_global_settings && ! isset( $this->_settings[$form_id] );
return $explicity_excluded || $passively_excluded;
}
public function is_applicable_field( $field ) {
$is_valid_form = ! $this->is_excluded_form( $field['formId'] );
$is_file_upload_filed = GFFormsModel::get_input_type( $field ) == 'fileupload';
$is_multi = rgar( $field, 'multipleFiles' );
return $is_valid_form && $is_file_upload_filed && $is_multi;
}
}
function gw_multi_file_merge_tag() {
return GW_Multi_File_Merge_Tag::get_instance();
}
gw_multi_file_merge_tag()->register_settings( array(
'form_id' => 1,
'markup' => array(
array(
'file_types' => array( 'jpg', 'jpeg', 'png', 'gif' ),
'markup' => '{filename}'
),
array(
'file_types' => array( 'pdf', 'txt' ),
'markup' => '{filename}{filenam}'
),
array(
'file_types' => array( 'mp4', 'ogg', 'webm' ),
'markup' => 'Your browser does not support the video tag.{filename}'
),
array(
'file_types' => array( 'ogv' ),
'markup' => 'Your browser does not support the video tag.{filename}'
)
)
) );
But cannot show the file or file link in post page. Can anyone help me?

Facebook autoupload photos does not show on timeline

Below is my code for uploading images, creating posts and to fanpage. Auto posting works fine apart from one thing - when images are posted to album, nothing shows up on the fan page timeline. Could you help me resolve the problem or point to some documentation. I have tried to google it, but none of the results from stackoverflow or facebook developer helped me.
$function ips_fanpage_post( $id, $row = false, $force_type = 'post' )
{
require_once( ABS_PATH . '/connect/facebook/facebook.php');
if( !is_array( $row ) )
{
$row = PD::getInstance()->simpleSelect( IPS__FILES, "`id` = '$id'", 1);
if( empty($row) )
{
ips_log( "ips_fanpage_post($id)" );
return;
}
global ${IPS_LNG};
$row['type'] = 'post';
$row['caption'] = ${IPS_LNG}['meta_site_title'];
$row['description'] = 'เยี่ยมไหม แย่ไหม ชอบไหม';
$row['image'] = IMG_LINK . '/' . $row['img_url'];
$row['link'] = seoLink($row['id'], $row['title']);
$row['message'] = 'เยี่ยมไหม แย่ไหม ชอบไหม';
}
$image = null;
if( !empty( $_FILES["file"]["tmp_name"] ) )
{
$image = realpath($_FILES["file"]["tmp_name"]);
}
else
{
if( file_exists( IMG_PATH . '/' . basename( $row['image'] ) ) )
{
$image = IMG_PATH . '/' . basename( $row['image'] );
}
elseif( file_exists( ABS_PATH . '/upload/img_obrazki/' . basename( $row['image'] ) ) )
{
$image = ABS_PATH . '/upload/img_obrazki/' . basename( $row['image'] );
}
elseif( file_exists( ABS_PATH . '/upload/import/' . basename( $row['image'] ) ) )
{
$image = ABS_PATH . '/upload/import/' . basename( $row['image'] );
}
}
if( empty( $image ) )
{
return array('Nie można odnależć określonego obrazka.');
}
$fanpage_id = Config::GET('apps_facebook_fanpageid');
$facebook = new Facebook(array(
'appId' => Config::GET('apps_facebook_appid'),
'secret' => Config::GET('apps_facebook_appsecret'),
'cookie' => true,
'fileUpload' => true
));
if( $row['type'] == 'upload' || $force_type == 'upload' )
{
$params = array(
'access_token' => Config::GET('apps_facebook_token')
);
$accounts = $facebook->api('/me/accounts', 'GET', $params);
foreach($accounts['data'] as $account)
{
if( $account['id'] == $fanpage_id || (isset($account['name']) && $account['name'] == $fanpage_id) )
{
$fanpage_token = $account['access_token'];
}
}
$image = str_replace( '_middle', '', $image );
if( !isset( $fanpage_token ) )
{
ips_log( 'Pusty $fanpage_token, prawdopodobnie nie jest adminem.' );
return false;
}
$params = array(
'message' => 'เยี่ยมไหม แย่ไหม ชอบไหม',
'image' => '#' . $image,
'no_story' => 1,
'aid' => $row['album_id'],
'access_token' => $fanpage_token
);
try
{
$rest = $facebook->api( '$row['album_id']' . '/photos', 'post', $params );
if( $rest )
{
$data = array(
'id' => 'NULL',
'file_id' => $row['album_id'],
'post_id' => $rest['id'],
'title' => $row['title'],
'data' => date("Y-m-d H:i:s"),
'link_post' => 'https://www.facebook.com/photo.php?fbid=' . $rest['id'],
'type' => 'upload'
);
PD::getInstance()->insert("fanpage_post", $data);
return true;
}
ips_log( $rest );
return false;
} catch (FacebookApiException $e) {
ips_log($e);
return $e->getMessage();
}
}
else
{
$image = str_replace( ABS_PATH, substr( ABS_URL, 0 , -1 ), $image );
if( substr( $image, 0 , 4 ) != 'http' )
{
$image = substr( ABS_URL, 0 , -1 ) . $image;
}
$attachment = '{
"name":"คลิกที่นี่ ตอนนี้",
"href":"'. $row['link'] .'",
"caption":"'. $row['caption'] .'",
"description":"'. $row['description'] .'",
"properties":null,
"media":[{
"type":"image",
"src":"' . $image . '",
"href":"' . $row['link'] . '",
}],
"auto_publish":true
}';
try {
$rest = $facebook->api(array(
"uid" => $fanpage_id,
"method" => "stream.publish",
"access_token" => Config::GET('apps_facebook_token'),
"message" => $row['message'],
"attachment" => $attachment,
"caption" => $row['caption']
));
if( $rest )
{
$data = array(
'id' => 'NULL',
'file_id' => $id,
'post_id' => $rest,
'title' => $row['title'],
'data' => date("Y-m-d H:i:s"),
'link_post' => 'https://www.facebook.com/'. str_replace('_', '/posts/', $rest),
'type' => 'post'
);
PD::getInstance()->insert("fanpage_post", $data);
return true;
}
ips_log( $rest );
return false;
} catch (FacebookApiException $e) {
/**
* Błąd zapisany do pliku log
*/
ips_log($e);
return false;
}
}
}
https://developers.facebook.com/docs/reference/api/page/#photos:
no_story: If set to 1, optionally suppresses the feed story that is automatically generated on the page when you upload a photo.

Wordpress - How to get all Author (or all User) Names and their associated ID's?

At the moment I am doing the following to get a list of all authors:
$authors = wp_list_authors('html=0&style=none&echo=0&exclude_admin=1&optioncount=0&show_fullname=1&hide_empty=1&orderby=name&order=ASC');
$authors_array = explode(',', $authors);
for ($j = 0; $j < count($authors_array); $j++)
{
echo '<li id="">'.$authors_array[$j].'</li>';
}
How can I also get the user's id?
I have looked everywhere and I can't think of a way to get all authors and another bit of meta data.
Another way I found was to do the following (swear I couldn't find anything like this earlier):
$authors = get_users('role=author&orderby=display_name&order=ASC');
foreach ($authors as $author) {
if (count_user_posts($author->ID) > 0) {
echo '<li id="' . $author->ID . '">' . $author->display_name . '</li>';
}
}
You can either override the function in functions.php or create a new function based on the original. Looking at the code it's easy enough to just include the $author_id in the foreach loop.
Code for original is here
Try this and make sure you add the new parameter (includeauthorid) into the function call...
$authors = wp_list_authors('html=0&style=none&echo=0&exclude_admin=1&optioncount=0&show_fullname=1&hide_empty=1&orderby=name&order=ASC&includeauthorid=1');
new function - ps I wouldn't recommend changing the original. Just put this in functions.php.
function wp_list_authors($args = '') {
global $wpdb;
$defaults = array(
'orderby' => 'name', 'order' => 'ASC', 'number' => '',
'optioncount' => false, 'exclude_admin' => true,
'show_fullname' => false, 'hide_empty' => true,
'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
'style' => 'list', 'html' => true,
'includeauthorid' => false
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
$return = '';
$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
$query_args['fields'] = 'ids';
$authors = get_users( $query_args );
$author_count = array();
foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
$author_count[$row->post_author] = $row->count;
foreach ( $authors as $author_id ) {
$author = get_userdata( $author_id );
if ( $exclude_admin && 'admin' == $author->display_name )
continue;
$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
if ( !$posts && $hide_empty )
continue;
$link = '';
if ( $show_fullname && $author->first_name && $author->last_name )
$name = "$author->first_name $author->last_name";
else
$name = $author->display_name;
if( $includeauthorid)
$name .= ' ('. $author_id .')';
if ( !$html ) {
$return .= $name . ', ';
continue; // No need to go further to process HTML.
}
if ( 'list' == $style ) {
$return .= '<li>';
}
$link = '' . $name . '';
if ( !empty( $feed_image ) || !empty( $feed ) ) {
$link .= ' ';
if ( empty( $feed_image ) ) {
$link .= '(';
}
$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
$alt = $title = '';
if ( !empty( $feed ) ) {
$title = ' title="' . esc_attr( $feed ) . '"';
$alt = ' alt="' . esc_attr( $feed ) . '"';
$name = $feed;
$link .= $title;
}
$link .= '>';
if ( !empty( $feed_image ) )
$link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';
else
$link .= $name;
$link .= '</a>';
if ( empty( $feed_image ) )
$link .= ')';
}
if ( $optioncount )
$link .= ' ('. $posts . ')';
$return .= $link;
$return .= ( 'list' == $style ) ? '</li>' : ', ';
}
$return = rtrim($return, ', ');
if ( !$echo )
return $return;
echo $return;
}

Categories