I'd like the have the output of the html return two possible markups based on a parameter the user can set. The parameter text_mode will be defined by the user by adding basic or advanced.
Right now, the $output is set for testing to show the basic version whereby the user's string is wrapped in a <p>. If the text_mode is set to advanced, then it's not wrapped.
<?php
function PCHiddenTextBlock( $settings = array() ) {
//---- Get Settings ----
//The functions default settings will be merged with what's passed in.
$settingsDefault = array(
'small_heading' => '',
'text' => '',
'text_mode' => 'basic', //or advanced
'color_scheme' => 'accent4',//accent4 or accent1
'container_id' => '',
'container_class' => 'x_extraContent',
);
$settings = array_merge($settingsDefault, $settings);
//---- Set Variables ----
//These will allow the markup build up to be as clean as possible.
//If container_id is set, prepare the attribute
$has_container_id = strlen($settings['container_id']) > 0;
$possible_container_id_attribute = ($has_container_id) ? " id='{$settings['container_id']}'" : "";
//Color scheme variables
switch($settings['color_scheme']) {
case 'accent1':
$gcol_color_class = 'bg-color-accent1-C';
$color_accent_class = 'color-accent1-8';
$hover_color_class = 'hover-color-base-4';
break;
default: //accent4
$gcol_color_class = 'bg-color-accent4-D';
$color_accent_class = 'color-accent4-A';
$hover_color_class = 'hover-color-base-4';
}
//---- Build Output ----
//Line by line, concatenating strings with new line and tab characters.
$output = "\n<!-- Hidden Text Block -->";
$output .= "\n<div class='{$settings['container_class']} gcol-1 {$gcol_color_class}'{$possible_container_id_attribute}>";
$output .= "\n\t<div class='padbox-standard-content'>";
$output .= "\n\t\t<h2 class='small-heading color-accent1-9'>{$settings['small_heading']}</h2>";
$output .= "\n\t\t<p>{$settings['text']}</p>"; // basic version
$output .= "\n\t\t<a href='' class='x_extraContentClose box-close-icon {$color_accent_class} {$hover_color_class}'></a>";
$output .= "\n\t</div><!-- padbox-standard-content-->";
$output .= "\n</div><!-- Hiddent Text Block -->";
//---- Return Output ----
return $output;
}
Just use an if statement:
if ($settings['text_mode'] == 'basic') {
$output .= "\n\t\t<p>{$settings['text']}</p>"; // basic version
} else {
$output .= "\n\t\t{$settings['text']}<"; // advanced version
}
Related
I am working on a project where I have MediaWiki PHP Scripts that import publications information from a DB into a Publications Page.
I need to convert this scripts to Wordpress Plugin but I don't really know the best way to do it. Quite lost right now I try to do the Tutorial: Writing a simple WordPress plugin from scratch but I did not have success on that and I still don't have this working.
Original MediaWiki Code
Here you will see my original MediaWiki Code:
<?php
# the function registered by the extension gets the text between the
# tags as input and can transform it into arbitrary HTML code.
# Note: The output is not interpreted as WikiText but directly
# included in the HTML output. So Wiki markup is not supported.
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/YourExtensionName.php");
$wgExtensionFunctions[] = "wfExampleExtension";
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
// Register the extension with the WikiText parser.
// The first parameter is the name of the new tag. In this case it defines
// the tag:
// <server-id> ... </server-id>
// The second parameter is the callback function for processing the text
// between the tags.
//
function wfExampleExtension() {
global $wgParser; // MediaWiki global variable
$wgParser->setHook("server-id", "renderSERVERID");
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
// The callback function for converting the input text to HTML output.
// The function registered by the extension gets the text between the
// tags as $input and transforms it into arbitrary HTML code.
// Note: the output is not interpreted as WikiText but directly included in
// the HTML output. So Wiki markup is not supported.
//
// To activate the extension, include it from your LocalSettings.php
// with: include("extensions/YourExtensionName.php");
//
// $argv is an array containing any arguments passed to the extension like:
// <server-id what="foo" bar>..
//
// According to the metawiki, this works in MediaWiki 1.5.5.
// <server-id what="person" id="62">This text is not actually used</server-id>
//
// Personal information:
// <server-id what='person' id='62'></server-id>
//
// Information for a group:
// <server-id what='publications' cc='IP02'></server-id>
//
function renderSERVERID($input, $argv) {
// connect to the database
$idDBLink = odbc_connect('SERVER ID', 'some_db', 'some_db_pw');
if (!$idDBLink) { exit("Connection to database failed! Please contact root#server-id.org."); }
$html = "";
if ($argv['what'] == 'person') {
$id = split(",", trim($argv["id"]));
if ($id != '') {
// information about someone:
// 1. personal contacts and summary
// 2. publications by person
// 3. advisory work by person
//
$html .= personById($idDBLink, $id[0]);
$internalIds = authorIdByNumber($idDBLink, $id); // use all Ids
$html .= pubsById($idDBLink, $internalIds);
$html .= advisingById($idDBLink, $internalIds);
}
}
else if ($argv['what'] == 'advising') {
$id = split(",", trim($argv["id"]));
if ($id != '') {
$internalIds = authorIdByNumber($idDBLink, $id); // use all Ids
$html .= iconv('latin1', 'UTF-8', advisingById($idDBLink, $internalIds));
}
}
else if ($argv['what'] == 'publications') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
$id = trim($argv["id"]);
if ($cc != '') {
$html .= iconv('latin1', 'UTF-8', pubsByCC($idDBLink, $cc));
}
else if ($id != '') {
$html .= iconv('latin1', 'UTF-8', pubsById($idDBLink, authorIdByNumber($idDBLink, array($id))));
}
}
/*else if ($argv['what'] == 'publications') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
if ($cc != '') {
$html .= pubsByCC($idDBLink, $cc);
}
}*/
else if ($argv['what'] == 'calls') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
$showClosed = isset($argv['showclosed']) ? trim($argv['showclosed']) : "";
if ($cc != '') {
$html .= iconv('latin1', 'UTF-8', callsByCC($idDBLink, $cc, $showClosed == "yes"));
}
}
else {
// oops! no text...
}
odbc_close($idDBLink);
return $html;
}
?>
My WordPress Try Version
Here you will see what I try to do with WordPress Code:
<?php
// ==================================================
// WordPress Plugin
// ==================================================
/*
Plugin Name: Publications Importer
Plugin URI: http://someperson.me/downloads/publications-importer
Description: Integrates the Publications Importer plugin into your WordPress install.
Version: 0.0.1
Author: Someone
Author URI: http://someperson.me/
*/
require_once 'server-id-config.php';
require_once 'server-id-util.php';
require_once 'server-id-people.php';
require_once 'server-id-pubs.php';
require_once 'server-id-advising.php';
defined( 'ABSPATH' ) or die( 'Plugin file cannot be accessed directly.' );
if ( ! class_exists( 'Publication' ) ) {
class Publication
{
/**
* Tag identifier used by file includes and selector attributes.
* #var string
*/
protected $tag = 'publications-importer';
/**
* User friendly name used to identify the plugin.
* #var string
*/
protected $name = 'Publications Importer';
/**
* Current version of the plugin.
* #var string
*/
protected $version = '0.0.1';
public function __construct()
{
add_shortcode( $this->tag, array( &$this, 'shortcode' ) );
}
public function shortcode( $atts, $content = null )
{
extract( shortcode_atts( array(
'what' => false,
'cc' => false
), $atts ) );
$styles = array();
if ( is_numeric( $what ) ) {
$styles[] = esc_attr( 'what: ' . $what );
}
$classes = array(
$this->tag
);
if ( !empty( $cc ) ) {
$classes[] = esc_attr( $cc );
}
ob_start();
?><pre cc="<?php esc_attr_e( implode( ' ', $classes ) ); ?>"<?php
echo ( count( $styles ) > 0 ? ' style="' . implode( ' ', $styles ) . '"' : '' );
?>><p><?php echo $content; ?></p></pre><?php
return ob_get_clean();
}
}
new Publication;
}
// ==================================================
// END WordPress Plugin
// ==================================================
# the function registered by the extension gets the text between the
# tags as input and can transform it into arbitrary HTML code.
# Note: The output is not interpreted as WikiText but directly
# included in the HTML output. So Wiki markup is not supported.
# To activate the extension, include it from your LocalSettings.php
# with: include("extensions/YourExtensionName.php");
$wgExtensionFunctions[] = "wfExampleExtension";
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
// Register the extension with the WikiText parser.
// The first parameter is the name of the new tag. In this case it defines
// the tag:
// <server-id> ... </server-id>
// The second parameter is the callback function for processing the text
// between the tags.
//
function wfExampleExtension() {
global $wgParser; // MediaWiki global variable
$wgParser->setHook("server-id", "renderSERVERID");
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//
// The callback function for converting the input text to HTML output.
// The function registered by the extension gets the text between the
// tags as $input and transforms it into arbitrary HTML code.
// Note: the output is not interpreted as WikiText but directly included in
// the HTML output. So Wiki markup is not supported.
//
// To activate the extension, include it from your LocalSettings.php
// with: include("extensions/YourExtensionName.php");
//
// $argv is an array containing any arguments passed to the extension like:
// <server-id what="foo" bar>..
//
// According to the metawiki, this works in MediaWiki 1.5.5.
// <server-id what="person" id="62">This text is not actually used</server-id>
//
// Personal information:
// <server-id what='person' id='62'></server-id>
//
// Information for a group:
// <server-id what='publications' cc='IP02'></server-id>
//
function renderSERVERID($input, $argv) {
// connect to the database
$idDBLink = odbc_connect('SERVER ID', 'some_db', 'some_db_pw');
if (!$idDBLink) { exit("Connection to database failed! Please contact root#server-id.org."); }
$html = "";
if ($argv['what'] == 'person') {
$id = split(",", trim($argv["id"]));
if ($id != '') {
// information about someone:
// 1. personal contacts and summary
// 2. publications by person
// 3. advisory work by person
//
$html .= personById($idDBLink, $id[0]);
$internalIds = authorIdByNumber($idDBLink, $id); // use all Ids
$html .= pubsById($idDBLink, $internalIds);
$html .= advisingById($idDBLink, $internalIds);
}
}
else if ($argv['what'] == 'advising') {
$id = split(",", trim($argv["id"]));
if ($id != '') {
$internalIds = authorIdByNumber($idDBLink, $id); // use all Ids
$html .= iconv('latin1', 'UTF-8', advisingById($idDBLink, $internalIds));
}
}
else if ($argv['what'] == 'publications') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
$id = trim($argv["id"]);
if ($cc != '') {
$html .= iconv('latin1', 'UTF-8', pubsByCC($idDBLink, $cc));
}
else if ($id != '') {
$html .= iconv('latin1', 'UTF-8', pubsById($idDBLink, authorIdByNumber($idDBLink, array($id))));
}
}
/*else if ($argv['what'] == 'publications') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
if ($cc != '') {
$html .= pubsByCC($idDBLink, $cc);
}
}*/
else if ($argv['what'] == 'calls') {
// information about some "centro de custo":
// 1. currently, only a list of publications
//
$cc = trim($argv["cc"]);
$showClosed = isset($argv['showclosed']) ? trim($argv['showclosed']) : "";
if ($cc != '') {
$html .= iconv('latin1', 'UTF-8', callsByCC($idDBLink, $cc, $showClosed == "yes"));
}
}
else {
// oops! no text...
}
odbc_close($idDBLink);
return $html;
}
?>
So what I exactly need to know is:
1) Should not WordPress be able to interpret the MediaWiki tags (for example: <server-id what='publications' cc='IP02'></server-id>) and do this automatically?
2) Where can I find more documentation about this kind of migrations?
3) Am I doing this the wrong way?
WordPress and MediaWiki are independent applications and one can not expect a plugin written for one to be directly portable to the other. If you are lucky some of the code may be reusable but it will not be as simple as a cut and paste. The two application has different ways of doing things.
1) No, WordPress will not be able to understand such tags. WordPress can be made to understand MediaWiki style markdown tags with additional plugins but I do not recognise the tag example you highlight.
2) I think your current approach is sound, you will need to understand what the MediaWiki code is doing and re-create this within a WordPress plugin. I doubt there is a short cut to this other than taking some time to get to grips with WP plugins. If you enjoy coding and writing plugins thin this is time well spent. Being able to customise WordPress is very useful.
3) Other than re-coding it yourself the other option would be to see if there is a WordPress plugin that does what you are looking for. Your question does not detail what exactly the functionality is that you are trying to add.
Having written plugins for both MediaWiki and WordPress I have found the easier more enjoyable to work with.
I tried using $pdf-getAliasNumPage() and it shows the page number if it is rendered in PDF.
But when I experimented on a basic PHP and printed it, it returns only "{:pnp:}".
I used to have an if condition if the page is already changed so that I can reset a value = 0 again, but the condition was always false due to the returned value of getAliasNumPage() is equal to "{:pnp:}".
Is there any way I can find the page number as an integer? What TCPDF function is that?
I only declared AddPage() once because I don't need it.
Already used $pdf->getPage(); only returns 0.
Thanks!
$this->payroll_id = $request->getParameter('payroll_id');
$this->class = new PsPayroll();
$config = sfTCPDFPluginConfigHandler::loadConfig();
$pdf = new reportPDF(LANDSCAPE, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$month = $this->class->mlFetchPayroll();
$month->execute(array($this->payroll_id));
$catch = "";
while ($print_month = $month->fetch()){
$catch = $print_month[8];
}
$pdf->SetCreator(Aaron);
$pdf->setMonth($catch);
$pdf->SetAuthor('');
$pdf->SetTitle('Payroll Report');
$pdf->SetSubject('');
$pdf->SetKeywords('');
$pdf->SetHeaderData('logo.png', '25', '', $catch);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 4, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER + 15);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(true);
$pdf->SetFont('freesans', '', 9.5, '', true);
$html .= '<table class = "table hover">
<thead>
<tr>
<th>Employee Information</th>
<th>Monthly Salary</th>
<th>Earnings</th>
<th>Deductions</th>
<th>Net Pay Signature</th>
</tr>
</thead>
<tbody>';
$pager = 1;
$prepare = $this->class->mlFetchPayroll();
$prepare->execute(array($this->payroll_id));
while ($myrow = $prepare->fetch()){
$total_net_pay = 0;
$total_earning = 0;
$total_deduction = 0;
$html .= '<br><tr nobr="true"><td>' . $myrow[2] . '<br>'. $myrow[3] . '<br>' . $myrow[4] . '</td><td>' . number_format($myrow[5], 2) . '</td><td>';
$earning_array = $this->class->mlFetchEarningPayslip($myrow[10]);
foreach ($earning_array as $k => $valk){
$net_pay += $valk;
$total_earning += $valk;
$html .= '<table><tr><td>' . $k . '</td><td>' . number_format($valk, 2) . '</td></tr></table>';
}
$html .= "</td><td>";
$deduction_array = $this->class->mlFetchDeductionPayslip($myrow[10]);
foreach ($deduction_array as $i => $val){
$net_pay -= $val;
$total_deduction += $val;
$html .= '<table><tr><td>' . $i . '</td><td>'. number_format($val, 2) . '</td></tr></table>';
}
$html .= '</td><td>';
$array_date = $this->class->mlDivideMonth($myrow[8]);
$k = 0;
foreach ($array_date as $value){
$breakdown = 0.00;
$k++;
$monthly_salary = $myrow[5];
$monthly_salary += $total_earning - $this->class->mlFetchPERA($myrow[10]);
$monthly_salary -= $total_deduction;
$break_down = $monthly_salary/ 4;
$html .= '<table><tr><td align="right">';
if ($breakdown < 0)
$html .= 0;
else if ($k == 2){
$a = round($break_down, 2);
$b = $a + $this->class->mlFetchPERA($myrow[10]);
$c = number_format($b, 2);
$html .= $c;
}
else{
$a = round($break_down, 2);
$b = number_format($a, 2);
$html .= $b;
}
$html .= ' </td><td>............... </td><td>' . $value . '</td></tr></table>';
}
$html .= '</td></tr>';
$pager = $pdf->getAliasNumPage();
if ($pager == 1){
$html .= 'This is first page ' . $pdf->getAliasNumPage();
}
else{
$pager = $pdf->getAliasNumPage();
$html .= "This is page " . $pdf->getAliasNumPage();
}
// $html .= 'sample '. $pager;
}
$html .= '</tbody></table>';
$pdf->AddPage();
$pdf->writeHTML($html, true, false, false, true, 'Aaron');
$pdf->Output('payroll_'.$catch.'.pdf', 'I');
throw new sfStopException();
both PageNo() and getPage() will return the current page number.
$this->PageNo();
$this->getPage();
The correct function is PageNo()
http://www.tcpdf.org/doc/code/classTCPDF.html#a9ad828b184f08828f570a7e52316ba79
TCPDF::PageNo()
Returns the current page number.
Returns
int page number
Edit.
OK, now (I think) I understand what you want to do, you add only 1 page and use auto page breaks, you also don't want to automatically number the pages in the footer. In that case you should use getAliasNumPage() and getAliasNbPages(). Define the following variable (edit the text as you will):
$PgNo= "This is the page " . $pdf->getAliasNumPage() . " of " . $pdf->getAliasNbPages();
Put it anywhere in the php document (it is important to put it after defining the fonts) and then just use the variable $PgNo (or however you will call it) wherever you need. You have to define it only once and it will later on get the values automatically depending on which page in the pdf document it is located.
The result of $this->getAliasNumPage() is NOT a number . It's... {:pnp:}
You can check this:
$text = "My Footer - Página ".$this->getAliasNumPage().'/'.$this->getAliasNbPages();
$this->Cell(0, 10, $text, 0, false, 'C', 0, '', 0, false, 'T', 'M');
And you will see the number.
But if you perform
echo $text;
you'll see the string doesn't have the number but only {:pnp:}
This came from the fact at this time (so when it executes the Footer function), the PDF is not yet created. So TCPDF can't know the number of pages. So it can't give you this value.
What can you do? in order to get a different footer eg on some pages, you must count the page number. So, declare a global $var at beginning of the Footer() function. Before the Footer() function, set $var to 0 and then, inside Footer() just $var++.
For the last page, just use this:
class mypdf extends tcpdf
{
// Declare for use in all function
protected $last_page = false;
// Will be called at the end
public function Close()
{
$this->last_page = true;
parent::Close();
}
public function Footer()
{
if ($this->last_page)
{
// Here you can display the footer for the last page
}
}
}
Edit: I forgot one option. If you want to know the full number of pages before the display or (eg) if you want to know the size of a PDF bloc to see if it fits a page and so on, you can use the rollbackTransaction();
First, you perform all operations (AddPages, MultiCell, and so on) which will give you the capability of the reading size of the result and all other values.
Then you perform a $pdf = $pdf -> rollbackTransaction(); which will "undo" everything and then you run all your functions again, using this time all the value you get from the "first run".
Im using this code from google api
I am getting all of the goals names and number
But I cant see a way to get the goal completed amount
This is what I get:
Account ID = xxx
Web Property ID = xxx
Internal Web Property ID = xxx
Profile ID = xxx
Goal Number = 1
Goal Name = Open User (MT Register)
Goal Value = 0
Goal Active = 1
Goal Type = URL_DESTINATION
Created = 2012-07-22T10:20:02.183Z
Updated = 2012-08-15T12:43:06.045Z
Goal URL = /04_thankyou.php
Case Sensitive =
Match Type = REGEX
First Step Required = 1
Destination Goal Steps
Step Number = 1
Step Name = abc
Step URL = /01_insert_phone.php
Step Number = 2
Step Name = abcd
Step URL = /02_progress.step
Step Number = 3
Step Name = abcde
Step URL = /03_insert_pincode.php
This is the code:
function getEventDetailsHtml(&$details) {
$html = '<h4>Event Goal</h4><pre>' .
'Use Event Value = ' . $details->getUseEventValue();
// Get all the event goal conditions.
$conditions = $details->getEventConditions();
foreach ($conditions as &$condition) {
$html .= "Event Type = $condition->getEventType()";
$eventType = $condition->getType();
if ($condition->getType() == 'VALUE') {
// Process VALUE.
$html .= "Comparison Type = $condition->getComparisonType()" .
"Comparison Value = $condition->getComparisonValue()";
} else {
// Process CATEGORY, ACTION, LABEL.
$html .= "Match Type = $condition->getMatchType()" .
"Expression = $condition->getExpression()";
}
}
return $html . '</pre>';
}
function getVisitNumPagesDetailsHtml(&$details) {
$html = '<h4>Visit Num Pages Goal</h4>';
$html .= <<<HTML
<pre>
Comparison Type = {$details->getComparisonType()}
Comparison Value = {$details->getComparisonValue()}
</pre>
HTML;
return $html;
}
function getVisitTimeOnSiteDetailsHtml(&$details) {
$html = '<h4>Visit Time On Site Goal</h4>';
$html .= <<<HTML
<pre>
Comparison Type = {$details->getComparisonType()}
Comparison Value = {$details->getComparisonValue()}
</pre>
HTML;
return $html;
}
function getUrlDestinationDetailsHtml(&$details) {
$html .= <<<HTML
<pre>
Goal URL = {$details->getUrl()}
Case Sensitive = {$details->getCaseSensitive()}
Match Type = {$details->getMatchType()}
First Step Required = {$details->getFirstStepRequired()}
</pre>
HTML;
$html .= '<h4>Destination Goal Steps</h4>';
$steps = $details->getSteps();
if (count($steps) == 0) {
$html .= '<p>No Steps Configured</p>';
} else {
foreach ($steps as &$step) {
$html .= <<<HTML
<pre>
Step Number = {$step->getNumber()}
Step Name = {$step->getName()}
Step URL = {$step->getUrl()}
</pre>
HTML;
}
}
return $html;
}
require_once 'google_api.php';
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
} else {
$analytics = new Google_AnalyticsService($client);
try {
$goals = $analytics->management_goals
->listManagementGoals('25788360',
'UA-25788360-20',
'~all');
} catch (Exception $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
$html = '';
$items = $goals->getItems();
foreach ($items as &$goal) {
$html .= "
<pre>
Account ID = {$goal->getAccountId()}
Web Property ID = {$goal->getWebPropertyId()}
Internal Web Property ID = {$goal->getInternalWebPropertyId()}
Profile ID = {$goal->getProfileId()}
Goal Number = {$goal->getId()}
Goal Name = {$goal->getName()}
Goal Value = {$goal->getValue()}
Goal Active = {$goal->getActive()}
Goal Type = {$goal->getType()}
Created = {$goal->getCreated()}
Updated = {$goal->getUpdated()}
</pre>";
// Now get the HTML for the type of goal.
switch($goal->getType()) {
case 'URL_DESTINATION':
$html .= getUrlDestinationDetailsHtml(
$goal->getUrlDestinationDetails());
break;
case 'VISIT_TIME_ON_SITE':
$html .= getVisitTimeOnSiteDetailsHtml(
$goal->getVisitTimeOnSiteDetails());
break;
case 'VISIT_NUM_PAGES':
$html .= getVisitNumPagesDetailsHtml(
$goal->getVisitNumPagesDetails());
break;
case 'EVENT':
$html .= getEventDetailsHtml(
$goal->getEventDetails());
break;
}
echo $html;
}
It seems like you are using the Management API. This is meant for management purposes only. Getting and setting goals.
If you want data from goals as well you want to be looking at the Core Reporting API.
The available data for goals can be found here:
https://developers.google.com/analytics/devguides/reporting/core/dimsmets/goalconversions
The implementation guide can be found here:
https://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide
I did not provide a full implementation example seeing that you already know how to setup the use of a Google API.
Good luck with you quest!
EDIT:
Added an example on how to use it:
<?php
$client = new apiAnalyticsService();
function queryCoreReportingApi() {
$optParams = array( //OPTINAL SETTINGS
'dimensions' => '', //A comma-separated list of Multi-Channel Funnels dimensions. E.g., 'mcf:source,mcf:medium'. (string)
'sort' => '', //A comma-separated list of dimensions or metrics that determine the sort order for the Analytics data. (string)
'filters' => '', //A comma-separated list of dimension or metric filters to be applied to the Analytics data. (string)
'start-index' => '', //An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter. (integer, 1+)
'fields' => '', //Selector specifying which fields to include in a partial response.
'max-results' => '25'); //The maximum number of entries to include in this feed. (integer)
return $service->data_mcf->get(
$id, //Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics profile ID. (string)
'2010-01-01', //Start date for fetching Analytics data. All requests should specify a start date formatted as YYYY-MM-DD. (string)
'2010-01-15', //End date for fetching Analytics data. All requests should specify an end date formatted as YYYY-MM-DD. (string)
'ga:totalConversions', //A comma-separated list of Multi-Channel Funnels metrics. E.g., 'mcf:totalConversions,mcf:totalConversionValue'. At least one metric must be specified. (string)
$optParams);
}
This is the issue.
I have a block called 'User Favorites Block'
It's placed in the region 'First Sidebar'
'First Sidebar' appears on the front-page.
The function is supposed to grab the data from the f25_favorites table and list them inside the block. Right now the table is an empty array.
When I return $output, none of my divs or anything are output.
When I do print($output), everything is displayed.
This is my test code to show that my 'if' statement is returning true. http://d.pr/zDph
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
dsm($mypaths);
print_r(count($mypaths));
$output .= 'n<div id="f25-favorites">n';
$output .= '<div id="f25-favorites-list">n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
print "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>n';
$output .= '<div id="f25-favorites-add">n';
$output .= '</div>n';
$output .= 'n</div>n';
return $output;
}
This outputs this: http://d.pr/Uhrs
Note the 0 on the top left, that's the output of the 'count()'
And the print of the text within the 'if'
So, this is my theme:
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
/*dsm($mypaths);
print_r(count($mypaths));*/
$output .= '\n<div id="f25-favorites">\n';
$output .= '<div id="f25-favorites-list">\n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>\n';
$output .= '<div id="f25-favorites-add">\n';
$output .= '</div>\n';
$output .= '\n</div>\n';
return $output;
}
It's called with this hook_theme() function:
/*
* Implentation of hook_theme().
*/
function f25_favorites_theme () {
return array(
'f25_favorites_my_favorites' => array (
'arguments' => array ('mypaths' => array())
),
);
}
Which is called with this hook_block() function:
/*
* Implementation of hook_block().
*
*/
function f25_favorites_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks = array();
$blocks['f25-favorites'] = array(
'info' => t('User Favorites Block'),
'cache' => BLOCK_NO_CACHE,
);
return $blocks;
}
if ($op == 'view') {
switch ($delta) {
case 0:
$mypaths = f25_favorites_user_favorites();
$block = array(
'subject' => t('User Favorites Block'),
'content' => theme_f25_favorites_my_favorites($mypaths)
);
return $block;
};
}
}
Noteworthy
My theme is a 'Sub-theme' of a theme called 'Zen'
Zen has a block.tpl.php which looks like this: http://d.pr/AaO1
Here is the full code of my module: http://d.pr/cGqc
It could be a region-related problem. Try switching to Garland and add the block to a plain old Garland region, and see if it appears.
If you see it in Garland then make sure your sub-theme really is defining that "First Sidebar" region and then actually printing its variable in the tpl files.
(FWIW I tried your code on Garland and it displays the block fine.)
Also, you might want to change your function call from:
theme_f25_favorites_my_favorites($mypaths)
to:
theme('f25_favorites_my_favorites', $mypaths)
...if you want to keep the code flexible (i.e. have Drupal call any preprocess functions and allow other people, or yourself in the future, to override the template's output)
I am finishing some edits on a drupal project that was done by another programmer (I have no contact with him). I'm a newbie and trying to find out how the Paging module works. There are no numbers of pages showing. I suppose the programmer added some custom module or something.
I found a file named "pager.php" in the project's own theme folder with this function, that is probably doing the pagination:
function _my_pager_link($page, $text, $class, $title) {
$query = array();
$query[] = drupal_query_string_encode(array(
'page' => implode(',', $page)), array());
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
$attributes['title'] = $title;
$attributes['class'] = $class;
return l("<span>$text</span>", $_GET['q'], array('html' => TRUE,
'attributes' => $attributes,
'query' => count($query) ? implode('&', $query) : NULL));
}
function my_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$curr = $pager_page_array[$element];
$total = $pager_total[$element];
$output = '';
if ($total > 1) {
$output .= '<div class="pager">';
if ($curr > 0) {
$page_new = pager_load_array($curr - 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('‹ previous'), 'pager-prev', t('Go to previous page'));
}
if ($curr < $total - 1) {
$page_new = pager_load_array($curr + 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('next ›'), 'pager-next', t('Go to next page'));
}
$output .= '<div class="cleaner"></div>';
$output .= '</div>';
}
return $output;
}
Now there is just 'previous page' and 'next page' on the web. I would like it to be like this
'previous page '... 2 3 4 ... 'next page'
How can I add the list of pages there?
Thank You
Copy and paste http://api.drupal.org/api/function/theme_pager/6
Add salt and voila!
You need to set the global values like so:
global $pager_page_array, $pager_total;
$pager_page_array[0] = $your_page_count_goes_here;
$pager_total[0] = $your_page_total_goes_here;
And then you can call theme('pager', ...) or any custom paging theme function that you may have.