Can't display footer (wordpress) - php

Problem:
run_overview() displays account_page-overview.php well.
The problem is that it blocks footer(), so the footer part disappears on frontend.
When I remove 'require $template;' of the run_overview(), it shows a footer part well, but doesn't show run_overview() part.
Action I took:
I tried changing the following code (and removed require $template;), but it doesn't display run_overview() part.
include locate_template('public/views/account_page-overview.php', false, false);
Need Help:
Would you please let me know if there is another method to display both run_overview() and footer()?
PHP Code:
private function run_overview(){
/*
* #param none
* #return none (print html)
*/
global $indeed_db;
$post_overview = get_user_meta($this->uid, 'uap_overview_post', true);
if ($post_overview && $post_overview!=-1){
//print the post for user
$post = get_post($post_overview);
$data['message'] = $post->post_content;
} else {
//predifined message
$data['message'] = uap_replace_constants($this->account_page_settings['uap_tab_overview_content'], $this->uid);
$data['message'] = stripslashes($data['message']);
$data['message'] = uap_correct_text($data['message']);
}
$data['title'] = $this->account_page_settings['uap_tab_overview_title'];
$data['stats'] = $indeed_db->get_stats_for_payments($this->affiliate_id);
$data['stats']['currency'] = get_option('uap_currency');
$data['help_url'] = $url = add_query_arg('uap_aff_subtab', 'help', $this->account_page_base_url);
$data['statsForLast30'] = $indeed_db->getReferralsAmountForLastDays( $this->affiliate_id, 30 );
$data['referralsStats'] = $indeed_db->get_stats_for_reports( 'last_month', $this->affiliate_id );
$data['referralsExtraStats'] = $indeed_db->get_referral_report_by_date( $this->affiliate_id, date( 'Y-m-d h:i:s', time() - 30 * 24 * 60 * 60 ), date( 'Y-m-d h:i:s', time() ) );
$this->print_top_messages();
$fullPath = UAP_PATH . 'public/views/account_page-overview.php';
$searchFilename = 'account_page-overview.php';
$template = apply_filters('uap_filter_on_load_template', $fullPath, $searchFilename );
require $template;
}
private function footer(){
global $indeed_db;
$data['footer_content'] = uap_replace_constants($this->account_page_settings['uap_ap_footer_msg'], $this->uid);
$data['footer_content'] = stripslashes($data['footer_content']);
$fullPath = UAP_PATH . 'public/views/account_page-footer.php';
$searchFilename = 'account_page-footer.php';
$template = apply_filters('uap_filter_on_load_template', $fullPath, $searchFilename );
require $template;
}
Thank you.

Related

adding database query in XLS

I have some difficulties getting the XLS function to add the query result in a xls file.
I have a html and a php file who is doing the job.
The query is working as it should, but i think the XLS function is not fetching the query result. I get "whitescreen" after pressing the button in the html file.
<div class="right" style="width:940px;">
Download as .XLS
</div>
i want the query to be saved in an xls file that can be saved localy.
The php is looking like this:
<?PHP
import( 'pages.admin' );
class AdminPortalStatistics extends AdminPage implements IView {
protected $template = 'order.stats';
public
function Execute() {
$kode = 'ST1';
$from = '2017-06-20';
$to = '2017-07-29';
if ($_GET['from'] && $_GET['to']) {
$from = $_GET['from'];
$to = $_GET['to'];
$query = "SELECT * from history_ordrer ho INNER JOIN history_cusomer hc ON ho.ordrenr = hc.ordrenr INNER JOIN history_mal hm ON ho.ordrenr = hm.ordrenr INNER JOIN histort_orderline hol ON ho.ordrenr = hol.ordrenr INNER JOIN kunde k ON ho.uid = k.uid WHERE ho.kode = ? AND ho.time BETWEEN ? AND ? AND ho.deleted is null order by ho.ordernr desc";
$orders = DB::query($query, $kode, $from, $to) - > fetchAll(DB::FETCH_ASSOC);
$this - > stats = $orders;
}
$this - > kode = $kode;
$this - > from = $from;
$this - > to = $to;
}
public function XLS( ) {
$this->Execute( );
$this->setTemplate( false );
$oldreporting = error_reporting( 0 );
require_once 'Spreadsheet/Excel/Writer.php';
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();
// sending HTTP headers
$workbook->send('test.xls');
// Creating a worksheet
$worksheet =& $workbook->addWorksheet( 'Report' );
// write the data
$fields = array_merge( array( 'Period' ), $this->series );
$worksheet->writeRow( $row++, 0, $fields );
foreach( $this->values as $graph ) {
$line = array_merge( array( $graph['label'] ), $graph['data'] );
$worksheet->writeRow( $row++, 0, $line );
}
// Let's send the file
$workbook->close();
error_reporting( $oldreporting );
}
}
?>

WordPress Custom Post Titles

I am looking for a method to change how a post title is shown on screen in WordPress that only applies to the post header.
I am trying to display Name, Gender, Age in the post title. The name I display is the current post title, and I am trying to add gender and age to this for display purposes only.
I have used the current code, but it applies to everything in my theme that uses the tile, and adds these fields to menu items as well.
I have not edited any of the PHP files within the theme, and would like to avoid that and do it via a function
Here is my code:
add_filter( 'the_title', function( $title ) {
$gender = get_field('gender');
$dob = get_field('date_of_birth');
$birthday = new DateTime($dob);
$interval = $birthday->diff(new DateTime);
if ('babysitters' == get_post_type()) {
$temp_title = $title;
$bbstitle = $temp_title .', ' .$gender .', ' .$interval->y;
return $bbstitle;
}
return $title;
} );
What am I doing where it replaces all titles with these appended fields, and not just the post header
UPDATED
function text_domain_custom_title($title) {
global $post;
if ($post->post_type == 'babysitters') {
$gender = get_field('gender', $post->ID);
$dob = get_field('date_of_birth', $post->ID);
$birthday = new DateTime($dob);
$interval = $birthday->diff(new DateTime);
$bbstitle = $title . ', ' . $gender . ', ' . $interval->y;
return $bbstitle;
} else {
return $title;
}
}
add_filter('the_title', 'text_domain_custom_title', 10, 2);
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Please note: This code is not tested, but it should work.
Reference:
get_field
How to append text to title of Custom Post Type post (without affecting all titles on page)?
<?php
add_filter('the_title', 'new_title', 10, 2);
function new_title($title, $id) {
if('babysitters' == get_post_type($id)){
$gender = get_field('gender');
$dob = get_field('date_of_birth');
$birthday = new DateTime($dob);
$interval = $birthday->diff(new DateTime);
$newtitle = $title .', ' .$gender .', ' .$interval->y;
}
else{
$newtitle = $title;
}
return $newtitle;
}
?>

PHP & IMAP: EmailReplyParser not returning message

I'm using the EmailReplyParser by Will Durand and the getContent() method doesn't appear to be returning anything.
// Code adapted from "Retrieve Your Gmail Emails Using PHP and IMAP" by David Walsh ( https://davidwalsh.name/gmail-php-imap ).
// Reference: http://php.net/manual/en/function.imap-open.php
public function imap () {
$array_messages = array();
// Attempt a connection.
$this->inbox = imap_open($this->array_parameters['hostname'], $this->array_parameters['username'], $this->array_parameters['password']) or die("I cannot connect: " . imap_last_error());
// Grab the Messages.
$emails = imap_search($this->inbox, 'ALL');
if( is_array($emails) && ( count($emails) > 0 ) ):
$user = $this->flexi_auth->get_user_identity();
// Organise the Messages in chronological order.
rsort($emails);
foreach($emails as $email_number):
$note_id = 0;
if ( $user == $this->flexi_auth->get_user_identity() ):
// Get the information specific to each Message.
$overview = imap_fetch_overview($this->inbox, $email_number, 0);
$message = imap_fetchbody($this->inbox, $email_number, 2);
// Get the meta data.
$array_messages['seen'] = $overview[0]->seen;
$array_messages['subject'] = $overview[0]->subject;
$array_messages['from'] = $overview[0]->from;
// Format the time.
$date = DateTime::createFromFormat( 'D, d M Y H:i:s O', $overview[0]->date);
$array_messages['date'] = $date->format('Y-m-d H:i:s');
// Get the Message.
$objMessage = (new EmailParser())->parse($message);
$fragment = current($objMessage->getFragments());
$array_messages['message'] = $fragment->getContent();
endif;
$note_id = $this->messages_model->add(
$array_messages['from'],
$array_messages['date'],
$array_messages['seen'],
$array_messages['message'],
$array_messages['subject']
);
if ( $note_id > 0 ):
imap_delete($this->inbox, $email_number);
endif;
endforeach;
endif;
imap_close($this->inbox, CL_EXPUNGE);
return true;
}
If I swap $fragment->getContent() for quoted_printable_decode($message), everything works.
I'm not seeing any errors with EmailReplyParser in so far as referencing it (the installation via Composer went without a problem).

Call to a member function on null ZF2 Doctrine ORM 2

$section = $objectManager->find('OEC\Entity\Section', $sectionId );
$class = $objectManager->find('OEC\Entity\Classes', $section->getClassId() );
$cycle = $objectManager->find('OEC\Entity\Cycle', $class->getCycleId() );
$branch = $objectManager->find('OEC\Entity\Branch', $cycle->getBranchId() );
$sectionArr = $class->getClassName()." ".$section->getSectionName()." - ". $branch->getBranchName()." ".$cycle->getCycleName();
$objectManager->close();
I am getting Call to a member function getCycleId() on null, although if I print_r($variable);exit; after each variable I obtain a result up until the end, only when I remove it it gives me the error. What can be the solution?
Try to debug it with something like:
$section = $objectManager->find('OEC\Entity\Section', $sectionId );
$class = $objectManager->find('OEC\Entity\Classes', $section->getClassId() );
if ($class === null) {
/* add debug info here*/
var_dump('ID of class was '.$section->getClassId());
var_dump('ID of section was '.$sectionId);
var_dump((new \Exception())->getTraceAsString());
die();
}
$cycle = $objectManager->find('OEC\Entity\Cycle', $class->getCycleId() );
$branch = $objectManager->find('OEC\Entity\Branch', $cycle->getBranchId() );
$sectionArr = $class->getClassName()." ".$section->getSectionName()." - ". $branch->getBranchName()." ".$cycle->getCycleName();
$objectManager->close();
Like I said in my comment, maybe the code is runnig multiple times.

php exports to cvs, but something happens that makes the csv totally unusable

I export every day the sales of yesterday (Magento) by a custom phpscript.
Since we got directbanking i had to change the code a bit.
The idea was to set the value "direct" in the CC_Type(Visa,JBC,...) so that we have good looking data for our analytics.
The csv looks actually clean and when i do a manually import (where you customize the import) with excel or mssql it works as wished. But when i let it open by it self (like our system would do to import the data in the night) strange things happen.
In the data-/functionbar (fx) you can see that the curser is ON the D and if I insert more letters they are appendet AFTER the p from onlineshop.
the header (first line) and every following dataline become imported without the "", I know that excel sometimes does this, but it never did before with this document.
Well thats a lie i never payed attation if it is so or not, because it simply worked.
//
class Mage_Shell_Compiler extends Mage_Shell_Abstract {
const OUTPUT = false;
const DEL = "\t";
const BR = "\r\n";
const FILEPATH = '../var/export/';
const FILENAME = 'tdtaCash';
protected $_orders = array();
protected $_csv_output = '';
protected $_headers = array(
"dtTag" => false, // Bestelldatum
"fiCBox" => 94,
"fiCashier" => "onlineshop",
"fiCurrency" => array('Visa', 'MC', 'Amex', 'DC', 'JCB', 'Direct'), // Zahlungsart
"dtRev" => false // Bruttoumsatz an diesem Tag mit dieser Zahlungsart
);
/// #see $_headers for details
protected function addOrderToRows($order, $rows) {
$order_data = $order->getOrigData();
$type = $order->getPayment()->getAdditionalInformation('CC_BRAND');
switch ($type) {
case 'VISA':
$type = 'Visa';
break;
case 'MasterCard':
$type = 'MC';
break;
case 'American Express':
$type = 'Amex';
break;
case 'Diners Club':
$type = 'DC';
break;
case 'JCB':
$type = 'JCB';
break;
default:
$brand = $order->getPayment()->getAdditionalInformation('BRAND');
if ($brand == 'DirectEbankingAT') {
$type = 'Direct';
}
break;
}
if (empty($rows[$type])) {
$row = $this->_headers;
$row["dtRev"] = 0;
} else
$row = $rows[$type];
//$row['dtTag'] = date('Y-m-d', strtotime($order_data['created_at']));
$row['dtTag'] = $this->formatDate($order_data['created_at'], 'exportdate', true);
$row["fiCurrency"] = $type;
$row["dtRev"] += $order_data['grand_total'];
$rows[$type] = $row;
return $rows;
}
protected function __($msg) {
if (self::OUTPUT)
print $msg . "\n";
}
/**
* Get Orders instance
*
* #return Mage_Sales_Model_Order
*/
protected function _getOrders($day = 1) {
$timeZoneOffset = Mage::getModel('core/date')->getGmtOffset();
$yesterday = date('Y-m-d', strtotime("-$day day")) . ' 00:00:00';
$yesterday = date('Y-m-d H:i:s', strtotime($yesterday) - $timeZoneOffset);
$day--;
$today = date('Y-m-d', strtotime("-$day day")) . ' 00:00:00';
$today = date('Y-m-d H:i:s', strtotime($today) - $timeZoneOffset);
if (!$this->_orders)
$this->_orders = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
/// #note uncommented to remove daily filter
->addAttributeToFilter('created_at', array("from" => $yesterday, "to" => $today))
->addAttributeToFilter('status', array('nin' => array('holded', 'canceled', 'pending_payment', 'pending')));
return $this->_orders;
}
protected function addRowToOutput($row) {
if (isset($row["dtRev"]))
$row["dtRev"] = number_format($row["dtRev"], 2);
$this->_csv_output .= '"' . implode('"' . self::DEL . '"', $row) . '"' . self::BR;
}
protected function addCsvHeader() {
$this->addRowToOutput(array_keys($this->_headers));
}
/**
* Run script
*
*/
public function run() {
if ($this->getArg('export')) {
$day = is_numeric($this->getArg('day')) ? $this->getArg('day') : 1;
$file = self::FILEPATH . self::FILENAME . '.csv';
$this->__('orders to export ' . count($this->_getOrders($day)));
// add header if file is empty
if (!strlen(trim(file_get_contents(dirname(__FILE__) . '/' . $file))))
$this->addCsvHeader();
$rows = array();
foreach ($this->_getOrders($day) as $order)
$rows = $this->addOrderToRows($order, $rows);
while ($row = array_shift($rows))
$this->addRowToOutput($row);
file_put_contents(dirname(__FILE__) . '/' . $file, $this->_csv_output, FILE_APPEND);
$this->__($this->_csv_output);
} else {
echo $this->usageHelp();
}
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp() {
return <<<USAGE
Usage: php -f export_tdtaCash.php -- [options]
export ... Appends data to file tdtaCash.csv in Directory var/export/
day ... days to count back
help ... This help
USAGE;
}
}
$shell = new Mage_Shell_Compiler();
$shell->run();
So my question is, may someone can explain me what kind of sourcery is responsable for this effect, and what can i do preventive to not get such results again?!
EDIT:
here is a screenshot of the CSV opend in Notepad++
Change file resolution from CSV to TXT and use Import file, specify TAB character as separator - and you'll be fine!
That's not a C SV, it's a T SV, a tab separated values file.
Excel won't know that unless you tell it and misinterprets the data.

Categories