get pagename in my wordpress plugin - plugins

I am adding specific js file to the front end from my wordpress plugin.
For Example :
if($wp->query_vars["pagename"] == 'pagename1'){
include js file 1.
}else if($wp->query_vars["pagename"] == 'pagename1'){
include js file 2.
}
But now i am not able to get the page name in$wp->query_vars.
Thank you
Balaji

Try this:
$post = get_post();
$post_name = $post->post_name;
To add javascript you could do this:
add_action( 'wp_enqueue_scripts', 'addSomescripts' );
function addSomeScripts() {
$post = get_post( );
$post_name = $post->post_name;
if($post_name == 'pagename1') {
wp_enqueue_script('script1', '/pathtoscript1.js');
} else if($post_name == 'pagename2') {
wp_enqueue_script('script2', '/pathtoscript2.js');
}
}

Related

output records in the form of html table from moodle database , custom block development

Please check this code for the custom block to be placed in the dashboard. We want to display an HTML table for the records. But it does not add up to the custom block, rather it appears on the top page.
enter image description here
class block_scorecard extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_scorecard');
}
function get_content() {
global $DB;
if ($this->content !== NULL) {
return $this->content;
}
$content = '';
$courses = $DB->get_records('scorm_scoes_track', ['element' => 'cmi.core.total_time']);
$table=new html_table();
$table->head=array('No of attempts','Time modified','status');
foreach ($courses as $course) {
$attempt=$course->attempt;
$timemodified=userdate($course->timemodified, get_string('strftimerecentfull'));
$status=$course->value;
$table->data[]=array($attempt, $timemodified, $status);
}
echo html_writer::table($table);
$this->content = new stdClass;
$this->content->text = $content;
}}
echo html_writer::table($table);
Should be
$content .= html_writer::table($table);

Joomla module not working

I made a module that display how many days ago a article was published
it looks like this.
{source}
<?php
$jinput = JFactory::getDocument()->input;
$option = $jinput->get('option');
$view = $jinput->get('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& $jinput->get("content");
$article->load($article_id);
$date = new JDate($article->get("publish_up"));
$currentTime = new JDate('now');
$interval = $date->diff($currentTime);
if($interval->d == 0) {
echo 'dzisiaj' . "<br>";
}
else if( $interval->d == 1) {
echo 'wczoraj' . "<br>";
}
else if( $interval->d > 1) {
echo $interval->format('%a dni temu') . "<br>";
}
}
?>
{/source}
And it works on my local joomla but when use it on custom template it doesnt work. I'm using Joomla 3.4.8.
The issue is you're trying to access the input values using Document Factory that's wrong you have to use
$jinput = JFactory::getApplication()->input;
Document Factory is used for other purpose like adding , styles or Js to the pages etc. read more about input here.
Hope it make sense.

How to remove Moodle Logo in version 2.8

Have just created a new Moodle page documentation. However, I would like to remove the Moodle logo that is shown in the footer. How can that be achieved? I have tried looking in admin/styles directory and also to try to change the image in pix/ moodlelogo.gif directory. However, none of those method seems to work.
There are two solutions:
I. First (hack Moodle core):
go to [moodle dir]\lib\outputrenderers.php
find public function home_link()
and replace it code:
public function home_link() {
global $CFG, $SITE;
if ($this->page->pagetype == 'site-index') {
// Special case for site home page - please do not remove
return '';
} else if (!empty($CFG->target_release) && $CFG->target_release != $CFG->release) {
// Special case for during install/upgrade.
return '';
} else if ($this->page->course->id == $SITE->id || strpos($this->page->pagetype, 'course-view') === 0) {
return '<div class="homelink"><a href="' . $CFG->wwwroot . '/">' .
get_string('home') . '</a></div>';
} else {
return '<div class="homelink"><a href="' . $CFG->wwwroot . '/course/view.php?id=' . $this->page->course->id . '">' .
format_string($this->page->course->shortname, true, array('context' => $this->page->context)) . '</a></div>';
}
}
II. Second (simple hide logo):
Add to your css file (for example "custom.css") next lines :
.sitelink {
display: none;
}
But remember: deleting moodle logo (free open source software) not good idea!

How to get typoscript setup in a scheduler/cron script?

I need to get the extension typoscript setup in schedular script.
I am using typo3 v 4.5.
My schedular script looks like this.
class tx_myext_scheduler extends tx_scheduler_Task {
public function execute() {
//here i need to get typoscript setup
}
}
and my extension setup looks like this.
plugin.tx_myext_pi1{
listView{
file.height = 216c
}
}
In schedualr script I need to get the file.height value.
How to do that ?
Currently i tried this without success
$pObj = $GLOBALS['TSFE'];
$conf = $pObj->tmpl->setup['plugin.']['tx_myext_pi1.'];
Thank you.
The TSFE is only available in the frontend, so have to initialize it yourself (that consumes some resources!). You can create it like that in scheduler: (source)
$GLOBALS['TT'] = new t3lib_timeTrackNull;
$GLOBALS['TSFE'] = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], 2, 0);
$GLOBALS['TSFE']->sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
$GLOBALS['TSFE']->sys_page->init(TRUE);
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->rootLine = '';
$GLOBALS['TSFE']->sys_page->getRootLine(1, '');
$GLOBALS['TSFE']->getConfigArray();
or in an eID script: (source)
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
$temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$GLOBALS['TSFE'] = new $temp_TSFEclassName($TYPO3_CONF_VARS, $pid, 0, true);
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();
or in a backend module: (source)
function loadTypoScriptForBEModule($extKey) {
require_once(PATH_t3lib . 'class.t3lib_page.php');
require_once(PATH_t3lib . 'class.t3lib_tstemplate.php');
require_once(PATH_t3lib . 'class.t3lib_tsparser_ext.php');
list($page) = t3lib_BEfunc::getRecordsByField('pages', 'pid', 0);
$pageUid = intval($page['uid']);
$sysPageObj = t3lib_div::makeInstance('t3lib_pageSelect');
$rootLine = $sysPageObj->getRootLine($pageUid);
$TSObj = t3lib_div::makeInstance('t3lib_tsparser_ext');
$TSObj->tt_track = 0;
$TSObj->init();
$TSObj->runThroughTemplates($rootLine);
$TSObj->generateConfig();
return $TSObj->setup['plugin.'][$extKey . '.'];
}
If you have missing class errors somewhere, maybe you have to add some requires.
This solution is perfect if the page is in standard mode, but doesn't work if the page is a Draft:
function loadTypoScriptForBEModule($extKey) {
require_once(PATH_t3lib . 'class.t3lib_page.php');
require_once(PATH_t3lib . 'class.t3lib_tstemplate.php');
require_once(PATH_t3lib . 'class.t3lib_tsparser_ext.php');
list($page) = t3lib_BEfunc::getRecordsByField('pages', 'pid', 0);
$pageUid = intval($page['uid']);
$sysPageObj = t3lib_div::makeInstance('t3lib_pageSelect');
$rootLine = $sysPageObj->getRootLine($pageUid);
$TSObj = t3lib_div::makeInstance('t3lib_tsparser_ext');
$TSObj->tt_track = 0;
$TSObj->init();
$TSObj->runThroughTemplates($rootLine);
$TSObj->generateConfig();
return $TSObj->setup['plugin.'][$extKey . '.'];
}

Jomsocial Extra Field

I am trying to create extra fields on the Jomsocial Groups Create New Group page, its suggested on the Jomsocial docs that the best way is to creat a plugin to do this.
As I have never created such a complex plugin do anyone have a working example to start with?
Here is the code that I have tried with
<?php
defined('_JEXEC') or die('Restricted access');
if (! class_exists ( 'plgSpbgrouppostcode' )) {
class plgSpbgrouppostcode extends JPlugin {
/**
* Method construct
*/
function plgSystemExample($subject, $config) {
parent::__construct($subject, $config);
// JPlugin::loadLanguage ( 'plg_system_example', JPATH_ADMINISTRATOR ); // only use if theres any language file
include_once( JPATH_ROOT .'/components/com_community/libraries/core.php' ); // loading the core library now
}
function onFormDisplay( $form_name )
{
/*
Add additional form elements at the bottom privacy page
*/
$elements = array();
if( $form_name == 'jsform-groups-forms' )
{
$obj = new CFormElement();
$obj->label = 'Labe1 1';
$obj->position = 'after';
$obj->html = '<input name="custom1" type="text">';
$elements[] = $obj;
$obj = new CFormElement();
$obj->label = 'Labe1 2';
$obj->position = 'after';
$obj->html = '<input name="custom2" type="text">';
$elements[] = $obj;
}
return $elements;