*

francesko

  • *
  • 4 posts
By default the Print Ad plugin print the title, address, contact number, price and description. How can i include the custom fields on the printing page ?

How can i print the full image, not thumbnail ?



Thanks

Marked as best answer by frosticek on September 14, 2017, 08:53:37 AM
*

francesko

  • *
  • 4 posts
Re: How to show custom fields on print-ad plugin, delivered with zara theme
« Reply #1 on: September 14, 2017, 12:10:01 AM »
Finally i have got to work for Custom fields! Here is the solution:

In index.php :

Find:
Code: [Select]
View::newInstance()->_exportVariableToView('user', User::newInstance()->findByPrimaryKey(osc_item_user_id()));Add Code Below:
Code: [Select]
View::newInstance()->_erase('metafields');
Find:
Code: [Select]
// prepare arrays to be posted
    if(count($image_id)>0){
$image_id = implode(",", $image_id);
$image_path = implode(",", $image_path);
$image_ext = implode(",", $image_ext);
    }

Add Code Below:
Code: [Select]
    // Get & store all custom fields for the current item
    if( osc_count_item_meta() > 0 ) {
for ( $mindex = 0; osc_has_item_meta() ; $mindex++ ) {
    $meta_id[] = osc_item_meta_id();
    $meta_name[] = osc_item_meta_name();
    $meta_value[] = osc_item_meta_value();
}
    }

    // prepare arrays to be posted
    if(count($meta_id)>0){
$meta_id = implode(",", $meta_id);
$meta_name = implode(",", $meta_name);
$meta_value = implode(",", $meta_value);
    }

Find:

Code: [Select]
View::newInstance()->_reset('resources') ; //reset resources array (no helper function exisits for this as of now, but has been suggested)
Add Code Below:
Code: [Select]
View::newInstance()->_reset('metafields') ;
Find:
Code: [Select]
<form name="printform" id="printform" action="'.$path.'print.php" method="post" target="printme" onsubmit="formpopup();">Add Code Below:
Code: [Select]
<input type="hidden" name="meta_id" value="'.htmlspecialchars($meta_id).'">
<input type="hidden" name="meta_name" value="'.htmlspecialchars($meta_name).'">
<input type="hidden" name="meta_value" value="'.htmlspecialchars($meta_value).'">
============================
In print.php :

Find:
Code: [Select]
// Get posted dataAdd Code Below:
Code: [Select]
$meta_id = explode(",",$_POST['meta_id']);
$meta_name = explode(",",$_POST['meta_name']);
$meta_value = explode(",",$_POST['meta_value']);

Find:
Code: [Select]
    <div id="desc">
        <?php
          $dd 
explode("Tweet$"$desc2);
          
$first $arr[0];
        
?>

<b><?php _e('Description''printad'); ?>:</b> <?php echo $dd[0]; ?>
    </div>
Add Code Below:
Code: [Select]
<b><?php _e('Additional Informations''printad'); ?>:</b><br>
<?php if($meta_id[0]!=''){ ?>
<?php for($dindex=0$dindex<count($meta_id); $dindex++){ ?>
<?php if($meta_value[$dindex]!=''){ ?>
<li><?php echo $meta_id[$dindex]; ?> - <?php echo $meta_name[$dindex]; ?> : <?php echo $meta_value[$dindex]; ?></li>
<?php ?>
<?php ?>
<?php ?>

If you don't want to show meta id delete:
Code: [Select]
<?php echo $meta_id[$dindex]; ?> -from print.php


Here is the full code if you need it:
index.php:
Code: [Select]
<?php
/*
Plugin Name: Print Ad
Plugin URI: http://www.osclass.org
Description: Allows users to print an ad
Version: 3.0
Author: Jesse modified by MB-themes.com
Author URI: http://www.osclass.org/
Short Name: printad
*/





function print_ad() {

    
// make user information available
    
View::newInstance()->_exportVariableToView('user'User::newInstance()->findByPrimaryKey(osc_item_user_id()));
View::newInstance()->_erase('metafields');

    
$path osc_base_url() . 'oc-content/plugins/print_ad/';

    
// Get item data
    
$desc osc_item_description();
    
$desc =  htmlspecialchars($desc);
    
$title htmlspecialchars(osc_item_title());
    
$pr explode("<div"osc_item_formated_price(), 2);
    
$price $pr[0];
    
    
$pub_date osc_item_pub_date();
    
$country osc_item_country();
    
$region osc_item_region();
    
$city osc_item_city();
    
$zip osc_item_zip();

    
// store user information
    
$phone osc_user_phone();
    
$mobil osc_user_phone_mobile();
    
$mobil2 osc_item_city_area();
    
$website osc_user_website();
    
$address osc_user_address();


    
// Get & store all the image data for the current item
    
osc_reset_resources();
    if( 
osc_count_item_resources() > ) {
for ( $pindex 0osc_has_item_resources() ; $pindex++ ) {
    $image_id[] = osc_resource_id();
    $image_path[] = osc_resource_path(); 
    $image_ext[] = osc_resource_extension();
}
    }

    
// prepare arrays to be posted
    
if(count($image_id)>0){
$image_id implode(","$image_id);
$image_path implode(","$image_path);
$image_ext implode(","$image_ext);
    }

    
// Get & store all custom fields for the current item
    
if( osc_count_item_meta() > ) {
for ( $mindex 0osc_has_item_meta() ; $mindex++ ) {
    $meta_id[] = osc_item_meta_id();
    $meta_name[] = osc_item_meta_name(); 
    $meta_value[] = osc_item_meta_value();
}
    }

    
// prepare arrays to be posted
    
if(count($meta_id)>0){
$meta_id implode(","$meta_id);
$meta_name implode(","$meta_name);
$meta_value implode(","$meta_value);
    }

    
View::newInstance()->_reset('resources') ; //reset resources array (no helper function exisits for this as of now, but has been suggested)
View::newInstance()->_reset('metafields') ;
    echo 
'
    <script>
            function formpopup()
        {
            window.open("about :blank","printme","width=750,height=600,scrollbars=yes,menubar=yes");
            return true;
        }
    </script>

    <form name="printform" id="printform" action="'
.$path.'print.php" method="post" target="printme" onsubmit="formpopup();">

<input type="hidden" name="meta_id" value="'
.htmlspecialchars($meta_id).'">
<input type="hidden" name="meta_name" value="'
.htmlspecialchars($meta_name).'">
<input type="hidden" name="meta_value" value="'
.htmlspecialchars($meta_value).'">

<input type="hidden" name="image_id" value="'
.htmlspecialchars($image_id).'">
<input type="hidden" name="image_path" value="'
.htmlspecialchars($image_path).'">
<input type="hidden" name="image_ext" value="'
.htmlspecialchars($image_ext).'">

<input type="hidden" name="contact_name" value="'
.osc_item_contact_name().'">
<input type="hidden" name="contact_email" value="'
.osc_item_contact_email().'">
<input type="hidden" name="contact_email_en" value="'
.osc_item_show_email().'">
<input type="hidden" name="contact_phone" value="'
.$phone.'">
<input type="hidden" name="mobil" value="'
.$mobil.'">
<input type="hidden" name="mobil2" value="'
.$mobil2.'">
<input type="hidden" name="contact_website" value="'
.$website.'">
<input type="hidden" name="contact_address" value="'
.$address.'">

<input type="hidden" name="site_title" value="'
.osc_page_title().'">
<input type="hidden" name="site_url" value="'
.osc_base_url().'">
        <input type="hidden" name="desc" value="'
.$desc.'">
        <input type="hidden" name="title" value="'
.$title.'">
        <input type="hidden" name="price" value="'
.$price.'">
        <input type="hidden" name="pub_date" value="'
.$pub_date.'">
        <input type="hidden" name="country" value="'
.$country.'">
        <input type="hidden" name="region" value="'
.$region.'">
        <input type="hidden" name="city" value="'
.$city.'">
        <input type="hidden" name="zip" value="'
.$zip.'">

        <a id="print_ad" href="#" onClick="formpopup();document.printform.submit();return false;" class="tr1" title="' 
__('Print this page friendly''print_ad') . '"><i class="fa fa-print tr1"></i></a>
    </form>

    '
//end echo

//end print_ad()



    // This is needed in order to be able to activate the plugin
    
osc_register_plugin(osc_plugin_path(__FILE__), '') ;
    
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
    
osc_add_hook(osc_plugin_path(__FILE__) . '_uninstall''') ;


?>


print.php:

Code: [Select]
<?php

// Enable OSClass functions
define('ABS_PATH'dirname(dirname(dirname(dirname(__FILE__)))) . '/');
require_once 
ABS_PATH 'oc-load.php'

// Get posted data
$meta_id explode(",",$_POST['meta_id']);
$meta_name explode(",",$_POST['meta_name']);
$meta_value explode(",",$_POST['meta_value']);

$image_id explode(",",$_POST['image_id']);
$image_path explode(",",$_POST['image_path']);
$image_ext explode(",",$_POST['image_ext']);

$contact_phone $_POST['contact_phone'];
$mobil $_POST['mobil'];
$mobil2 $_POST['mobil2'];
$contact_website $_POST['contact_website'];
$contact_name $_POST['contact_name'];
$contact_email $_POST['contact_email'];
$contact_email_en $_POST['contact_email_en'];
$contact_address $_POST['contact_address'];

$site_title $_POST['site_title'];
$site_url $_POST['site_url'];
$desc stripslashes($_POST['desc']);
$title stripslashes($_POST['title']);
$price $_POST['price'];
$pub_date $_POST['pub_date'];
$country $_POST['country'];
$region $_POST['region'];
$city $_POST['city'];
$zip $_POST['zip'];
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>

<link href="<?php echo osc_current_web_theme_url('style.css'); ?>" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><?php _e('Print Ad','printad'); ?></title>

<script language="javascript">function printpage(){window.print();}</script>

<script language="javascript">
function toggle() {
var ele = document.getElementById("pics");
var text = document.getElementById("displayText");
if(ele.style.display == "none") {
    ele.style.display = "block";
text.innerHTML = "<?php _e('Hide photos','printad'); ?>";
  }
else {
ele.style.display = "none";
text.innerHTML = "<?php _e('Show photos','printad'); ?>";
}
}
</script>



</head>
<body id="print-ad-body">   
    <div id="title">
       <font size="5"><?php echo $title?></font>
       <div id="print" style="font-weight:bold;padding-top: 4px;padding-right: 4px;color:#278827;"><a href="#" onclick="printpage();"><?php _e('Print!','printad'); ?></a></div>
    </div>
    <div id="info">
<b><?php _e('Address','printad'); ?>:</b><br><?php if($contact_address!='') echo $contact_address.'<br>'?><?php echo $city.', '.$region?><br>
<br>
<b><?php _e('Published','printad'); ?>:</b><br><?php echo osc_format_date($pub_date); ?><br>
<br>
<b><?php _e('Contact info','printad'); ?>:</b><br>
<?php if($contact_name!='') echo $contact_name.'<br>'?>
<?php if($contact_phone!='')echo $contact_phone.'<br>'?>
<?php if($contact_phone=='' && $mobil != '')echo $mobil.'<br>'?>
<?php if($contact_phone=='' && $mobil == '' && $mobil2 != '')echo $mobil2.'<br>'?>
<?php if($contact_email!='' && $contact_email_en == 1)echo $contact_email'<br>'?>
<?php if($contact_website!='')echo $contact_website.'<br>'?>
        <br>
<b><?php _e('Price','printad'); ?>:</b><br><?php echo $price?><br>
<br>
    </div>

    <div id="desc">
        <?php
          $dd 
explode("Tweet$"$desc2);
          
$first $arr[0];
        
?>

<b><?php _e('Description''printad'); ?>:</b> <?php echo $dd[0]; ?>
    </div><br>
<b><?php _e('Additional Informations''printad'); ?>:</b><br>
<?php if($meta_id[0]!=''){ ?>
<?php for($dindex=0$dindex<count($meta_id); $dindex++){ ?>
<?php if($meta_value[$dindex]!=''){ ?>
<li><?php echo $meta_id[$dindex]; ?> - <?php echo $meta_name[$dindex]; ?> : <?php echo $meta_value[$dindex]; ?></li>
<?php ?>
<?php ?>
<?php ?>

    <?php if($image_id[0]!=''){ ?>

    <div id="pictures">
    <a id="displayText" href="javascript:toggle();"><?php _e('Hide photos','printad'); ?></a>
<div id="pics">
    <?php for($index=0$index<count($image_id); $index++){ ?>
<li><img src="<?php echo $image_path[$index].$image_id[$index].'_thumbnail.'.$image_ext[$index]; ?>" width="140"></li>
    <?php ?>
</div>
    </div>
    <?php ?>
    <div id="footer">
<?php echo __('This listing is placed on','printad') . ' '?> <b><?php echo $site_title.'</b> - <i>'.$site_url?></i>
    </div>
</body>
</html>
« Last Edit: September 14, 2017, 12:43:24 AM by francesko »

*

ally

  • ***
  • 33 posts
Re: How to show custom fields on print-ad plugin, delivered with zara theme
« Reply #2 on: December 01, 2017, 01:39:22 AM »
Hi,

What folder is the index.php and print.php located. I can't find the print.php file.

On my index.php under Zara theme folder it only has this code:

<?php
/*
Theme Name: OSClass Zara Premium Theme
Theme URI: http://www.mb-themes.com/
Description: This is the Premium OSClass Zara Theme, most powerful theme for osclass
Version: 1.2.9
Author: MB Themes
Author URI: http://www.mb-themes.com/
Widgets: header,footer
Theme update URI: zara-theme-full-responsive
*/
?>

Any help please..

Thanks

*

MB Themes

Re: How to show custom fields on print-ad plugin, delivered with zara theme
« Reply #3 on: December 01, 2017, 08:48:48 AM »
@ally
Look into print ad plugin folder.
oc-content/plugins/print_ad/
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

ally

  • ***
  • 33 posts
Re: How to show custom fields on print-ad plugin, delivered with zara theme
« Reply #4 on: December 01, 2017, 06:50:02 PM »
Hi,

I tried to replace the index.php and print.php code with the new code and still the same result. It still shows thumbnail on image.