I am using a video script and I want to randomize the url thumbs :
there's a common.php that defines global vars for the thumbs dir and url :
define('THUMB_FILES_DIR',' ');
define('THUMB_FILES_URL','');
define('THUMBS_DIR',THUMB_FILES_DIR.'/thumbs');
define('THUMBS_URL',THUMB_FILES_URL.'/thumbs');
and the functions to get the thumbs are :
/**
* FUNCTION USED TO GET THUMBNAIL
* #param ARRAY video_details, or videoid will also work
*/
function get_thumb($vdetails,$num='default',$multi=false,$count=false,$return_full_path=true,$return_big=true,$size=false){
global $db,$Cbucket,$myquery;
$num = $num ? $num : 'default';
#checking what kind of input we have
if(is_array($vdetails))
{
if(empty($vdetails['title']))
{
#check for videoid
if(empty($vdetails['videoid']) && empty($vdetails['vid']) && empty($vdetails['videokey']))
{
if($multi)
return $dthumb[0] = default_thumb();
return default_thumb();
}else{
if(!empty($vdetails['videoid']))
$vid = $vdetails['videoid'];
elseif(!empty($vdetails['vid']))
$vid = $vdetails['vid'];
elseif(!empty($vdetails['videokey']))
$vid = $vdetails['videokey'];
else
{
if($multi)
return $dthumb[0] = default_thumb();
return default_thumb();
}
}
}
}else{
if(is_numeric($vdetails))
$vid = $vdetails;
else
{
if($multi)
return $dthumb[0] = default_thumb();
return default_thumb();
}
}
#checking if we have vid , so fetch the details
if(!empty($vid))
$vdetails = $myquery->get_video_details($vid);
if(empty($vdetails['title']))
{
if($multi)
return default_thumb();
return default_thumb();
}
#Checking if there is any custom function for
if(count($Cbucket->custom_get_thumb_funcs) > 0)
{
foreach($Cbucket->custom_get_thumb_funcs as $funcs)
{
//Merging inputs
$in_array = array(
'num' => $num,
'multi' => $multi,
'count' => $count,
'return_full_path' => $return_full_path,
'return_big' => $return_big
);
if(function_exists($funcs))
{
$func_returned = $funcs($vdetails,$in_array);
if($func_returned)
return $func_returned;
}
}
}
#get all possible thumbs of video
if($vdetails['file_name'])
$vid_thumbs = glob(THUMBS_DIR."/".$vdetails['file_name']."*");
#replace Dir with URL
if(is_array($vid_thumbs))
foreach($vid_thumbs as $thumb)
{
if(file_exists($thumb) && filesize($thumb)>0)
{
$thumb_parts = explode('/',$thumb);
$thumb_file = $thumb_parts[count($thumb_parts)-1];
if(!is_big($thumb_file) || $return_big)
{
if($return_full_path)
$thumbs[] = THUMBS_URL.'/'.$thumb_file;
else
$thumbs[] = $thumb_file;
}
}elseif(file_exists($thumb))
unlink($thumb);
}
if(count($thumbs)==0)
{
if($count)
return count($thumbs);
if($multi)
return $dthumb[0] = default_thumb();
return default_thumb();
}
else
{
if($multi)
return $thumbs;
if($count)
return count($thumbs);
//Now checking for thumb
if($num=='default')
{
$num = $vdetails['default_thumb'];
}
if($num=='big' || $size=='big')
{
$num = 'big-'.$vdetails['default_thumb'];
if(!file_exists(THUMBS_DIR.'/'.$vdetails['file_name'].'-'.$num.'.jpg'))
$num = 'big';
}
$default_thumb = array_find($vdetails['file_name'].'-'.$num,$thumbs);
if(!empty($default_thumb))
return $default_thumb;
return $thumbs[0];
}
}
/**
* Function used to check weaether given thumb is big or not
*/
function is_big($thumb_file)
{
if(strstr($thumb_file,'big'))
return true;
else
return false;
}
function GetThumb($vdetails,$num='default',$multi=false,$count=false)
{
return get_thumb($vdetails,$num,$multi,$count);
}
/**
* function used to get detaulf thumb of ClipBucket
*/
function default_thumb()
{
if(file_exists(TEMPLATEDIR.'/images/thumbs/processing.png'))
{
return TEMPLATEURL.'/images/thumbs/processing.png';
}elseif(file_exists(TEMPLATEDIR.'/images/thumbs/processing.jpg'))
{
return TEMPLATEURL.'/images/thumbs/processing.jpg';
}else
return BASEURL.'/files/thumbs/processing.jpg';
}
I want to randomize the thumbs url from which is serverd the images this way
http://img[random number].domainname
if I create an array with the values of the thumbs url and then shuffle the result to the
define('THUMB_FILES_DIR',' ');
define('THUMB_FILES_URL','');
all the thumbs will have the same url value
how to do to have different values passed to html pages ?
Instead of using global variables for the thumbs url, you need to use a function. Then it can pick a URL at random when it's called.
Related
I want to create anonymous functions and add them to the hook instead of using defined functions in the hooks.
Error:spl_object_hash() expects exactly 1 parameter, 2 given in D:server\www\deneme\sistem\kanca.php on line 313
Error Problem function benzersiz_Filtre_id() spl_object_hash function
Misuse: kanca_cek("panel_main",function(){ return "a";});
Normal use: kanca_cek("panel_main","db_filter");
function kanca_tak($ad,$fonksiyon,$onem=10,$deger=1){
return self::filtre_ekle($ad,$fonksiyon,$onem,$deger);
}
function kanca_sil($ad,$fonksiyon,$onem=10){
return self::filtre_sil($ad,$fonksiyon,$onem);
}
function tum_kancalari_sil($ad,$onem=false){
return self::tum_filtreleri_sil($ad,$onem);
}
function kanca_sor($ad,$fonksiyon_kontrol=false){
return self::filtre_sor($ad,$fonksiyon_kontrol);
}
function kanca_saydir($ad){
if(!isset($this->islemSayaci) || !isset($this->islemSayaci[$ad]))
return 0;
return $this->islemSayaci[$ad];
}
function islemSayaci($ad,$kanca=false){
$kancaSor=($kanca ? "kanca":"filtre");
if(isset($this->islemSayaci[$ad][$kancaSor]))
$this->islemSayaci[$ad][$kancaSor]++;
else
$this->islemSayaci[$ad][$kancaSor]=1;
}
function kanca_cek($ad,$deger=''){
$depo = array();
$uFv=array();
if (isset($this->filtreler['hepsi'])) {
$this->guncelFiltre[] = $ad;
$depo = func_get_args();
$this->tum_kancalari_cagir($depo);
}
if (!isset($this->filtreler[$ad])) {
if (isset($this->filtreler['hepsi']))
array_pop($this->guncelFiltre);
return;
}
if (!isset($this->filtreler['hepsi']))
$this->guncelFiltre[] = $ad;
if (is_array($deger) && 1 == count($deger) && isset($deger[0]) && is_object($deger[0])) // array(&$this)
$depo[] =& $deger[0];
elseif(!empty($deger))
$depo[] = $deger;
for ($a = 2; $a < func_num_args(); $a++)
$depo[] = func_get_arg($a);
// Sort
if (!isset($this->topluFiltreler[$ad])) {
ksort($this->filtreler[$ad]);
$this->topluFiltreler[$ad] = true;
}
self::islemSayaci($ad,true);
do {
foreach ((array) current($this->filtreler[$ad]) as $yaz){
/**
*#param $uFv değişkeni call_user_func_array fonksiyonunda kullanıcı tanımlı fonksiyona gönderilecek değerleri içerir
*#param accepted_args varsa ve gelen değer eğer dizeyse $uFv ile $yaz["accepted_args"] birleştirir $uFv değişkenine atar.
* #example call_user_func_array gönderilecek değerleri oluşturur.
*/
$uFv=array_slice($depo, 0, (int) $yaz['accepted_args']);
if(isset($yaz["accepted_args"]) && is_array($yaz["accepted_args"]))
$uFv=array_merge($uFv,$yaz["accepted_args"]);
if (isset($yaz['fonksiyon']) && !is_null($yaz['fonksiyon']))
call_user_func_array($yaz["fonksiyon"], $uFv);
// call_user_func_array($yaz['fonksiyon'], array_slice($depo, 0, (int) $yaz['accepted_args']));
}
} while (next($this->filtreler[$ad]) !== false);
array_pop($this->guncelFiltre);
}
function referans_diziyle_kancala($ad,$deger){
if (isset($this->filtreler['hepsi'])) {
$this->guncelFiltre[] = $ad;
$depo = func_get_args();
$this->tum_kancalari_cagir($depo);
}
if (!isset($this->filtreler[$ad])) {
if (isset($this->filtreler['hepsi']))
array_pop($this->guncelFiltre);
return;
}
if (!isset($this->filtreler['hepsi']))
$this->guncelFiltre[] = $tag;
// Sort
if (!isset($this->topluFiltreler[$ad])) {
ksort($this->filtreler[$ad]);
$this->topluFiltreler[$ad] = true;
}
reset($this->filtreler[$tag]);
do {
foreach ((array) current($this->filtreler[$ad]) as $yaz)
if (isset($yaz['fonksiyon']) && !is_null($yaz['fonksiyon']))
call_user_func_array($yaz['fonksiyon'], array_slice($deger, 0, (int) $yaz['accepted_args']));
} while (next($this->filtreler[$ad]) !== false);
array_pop($this->guncelFiltre);
}
function filtre_ekle($ad,$fonksiyon,$onem,$deger=1,$sadeceKelime=0){
$fk=($sadeceKelime ? $ad."_".password_hash(rand(0,10000),PASSWORD_DEFAULT):$fonksiyon);
$cId=self::benzersiz_Filtre_id($ad,$fk,$onem);
if($sadeceKelime){
$this->filtreler[$ad][$onem][$cId]=array(
'deger'=>$fonksiyon,
'accepted_args'=>$deger,
'sK'=>$sadeceKelime);
}
else{
$this->filtreler[$ad][$onem][$cId]=array(
'fonksiyon'=>$fonksiyon,
'accepted_args'=>$deger,
'sK'=>$sadeceKelime);
}
unset($this->topluFiltreler[$ad]);
}
function filtre_sil($ad,$fonksiyon,$onem=10){
$fSil = self::benzersiz_Filtre_id($ad, $fonksiyon, $onem);
$varMi = isset($this->filtreler[$ad][$onem][$fSil]);
if (true === $varMi) {
unset($this->filtreler[$ad][$onem][$fSil]);
if (empty($this->filtreler[$ad][$onem]))
unset($this->filtreler[$ad][$onem]);
unset($this->topluFiltreler[$ad]);
}
return $varMi;
}
function tum_filtreleri_sil($ad,$onem=false){
if (isset($this->filtreler[$ad])) {
if (false !== $onem && isset($this->filtreler[$ad][$onem]))
unset($this->filtreler[$ad][$onem]);
else
unset($this->filtreler[$ad]);
}
if (isset($this->topluFiltreler[$ad]))
unset($this->topluFiltreler[$ad]);
return true;
}
function filtre_sor($ad,$fonksiyon_kontrol=false){
$sor=!empty($this->filtreler[$ad]);
if($fonksiyon_kontrol===false || $sor==false)
return $sor;
if(!$idSor=self::benzersiz_Filtre_id($ad,$fonksiyon_kontrol,false))
return false;
foreach ((array) array_keys($this->filtreler[$ad]) as $onem) {
if (isset($this->filtreler[$ad][$onem][$idSor]))
return $onem;
}
return false;
}
function guncel_filtre(){
return end($this->guncelFiltre);
}
public function filtrele($ad, $deger)
{
$depo = array();
$dondur=null;
$uFv=array();//call_user_func_array gönderilen Dizisi
// Do 'all' actions first
if(isset($this->filtreler["all"]))
{
$this->guncelFiltre=$ad;
$depo=func_get_arg();
$this->tum_kancalari_cagir($depo);
}
if(!isset($this->filtreler[$ad]))
{
if(isset($this->filtreler["all"]))
array_pop($this->guncelFiltre);
return $deger;
}
if (!isset($this->filtreler['hepsi']))
$this->guncelFiltre[] = $ad;
// Sort
if (!isset($this->topluFiltreler[$ad])) {
ksort($this->filtreler[$ad]);
$this->topluFiltreler[$ad] = true;
}
if (empty($depo))
$depo = func_get_args();
$keySifirla = array_map('array_values', $this->filtreler[$ad]);
do {
$conDizi=(is_array($keySifirla) ? $keySifirla:(array) $KXC);
foreach (current($conDizi) as $kx=>$yaz){
if (isset($yaz['fonksiyon']) && !is_null($yaz['fonksiyon'])) {
$depo[1] = $deger;
}
if(isset($yaz["deger"])){
if(is_array($yaz["deger"])){
foreach($yaz["deger"] as $yK)
$deger[]=$yK;
}else{
$deger=$yaz["deger"];
}
}else{
if(is_callable($yaz["fonksiyon"]) && $yaz["fonksiyon"] instanceof Closure) {
$yaz["fonksiyon"]();
}
elseif(function_exists($yaz["fonksiyon"])){
/**
*#param $uFv değişkeni call_user_func_array fonksiyonunda kullanıcı tanımlı fonksiyona gönderilecek değerleri içerir
*#param accepted_args varsa ve gelen değer eğer dizeyse $uFv ile $yaz["accepted_args"] birleştirir $uFv değişkenine atar.
* #example call_user_func_array gönderilecek değerleri oluşturur.
*/
$uFv=array_slice($depo, 1, (int) $yaz['accepted_args']);
if(isset($yaz["accepted_args"]) && is_array($yaz["accepted_args"]))
$uFv=array_merge($uFv,$yaz["accepted_args"]);
$deger = call_user_func_array($yaz["fonksiyon"], $uFv);
}
else{
hata_ekle($yaz["fonksiyon"]." fonksiyonu bulunamadı.","hata");
return false;
}
}
}
} while (next($keySifirla) !== false);
array_pop($this->guncelFiltre);
self::islemSayaci($ad);
return $deger;
}
function referans_diziyle_filtrele($ad,$deger){
// Do 'all' actions first
if (isset($this->filtrele['all'])) {
$this->guncelFiltre[] = $ad;
$depo = func_get_args();
$this->tum_kancalari_cagir($depo);
}
if (!isset($this->filtrele[$ad])) {
if (isset($this->filtrele['all']))
array_pop($this->guncelFiltre);
return $deger[0];
}
if (!isset($this->filtrele['all']))
$this->guncelFiltre[] = $ad;
// Sort
if (!isset($this->topluFiltreler[$ad])) {
ksort($this->filtrele[$ad]);
$this->topluFiltreler[$ad] = true;
}
reset($this->filtrele[$ad]);
do {
foreach ((array) current($this->filtrele[$ad]) as $yaz)
if (isset($yaz['fonksiyon']) && !is_null($yaz['fonksiyon']))
$deger[0] = call_user_func_array($yaz['fonksiyon'], array_slice($deger, 0, (int) $deger['accepted_args']));
} while (next($this->filtrele[$ad]) !== false);
array_pop($this->guncelFiltre);
return $depo[0];
}
public function tum_kancalari_cagir($deger)
{
reset($this->filtreler['hepsi']);
do {
foreach ((array) current($this->filtreler['hepsi']) as $yaz)
if (isset($yaz['fonksiyon']) && !is_null($yaz['fonksiyon']))
call_user_func_array($yaz['fonksiyon'], $depo);
} while (next($this->filtreler['hepsi']) !== false);
}
function dumps(){
echo "<pre>";
print_r($this);
echo "</pre>";
}
function benzersiz_Filtre_id($ad,$fonksiyon,$onem){
static $idSaydir=0;
if(is_string($fonksiyon))
return $fonksiyon;
if(is_object($fonksiyon))
$fonksiyon=array($fonksiyon,'');
else
$fonksiyon=(array) $fonksiyon;
if(is_object($fonksiyon[0]))
{
if(function_exists('spl_object_hash')){
return spl_object_hash($fonksiyon[0],$fonksiyon[1]);
}else{
$nesneId=get_class($fonksiyon[0]).$fonksiyon[1];
if (!isset($fonksiyon[0]->filter_id)) {
if (false === $onem)
return false;
$nesneId .= isset($this->filtreler[$ad][$onem]) ? count((array) $$this->filtreler[$ad][$onem]) : $idSaydir;
$fonksiyon[0]->filter_id = $idSaydir;
++$idSaydir;
} else {
$nesneId .= $fonksiyon[0]->filter_id;
}
return $nesneId;
}
} else if (is_string($fonksiyon[0])) {
if(count($fonksiyon)>=2)
return $fonksiyon[0] . $fonksiyon[1];
else
return $fonksiyon[0];
}
}
}
Problem Function 313 line code
if(function_exists('spl_object_hash')){
return spl_object_hash($fonksiyon[0],$fonksiyon[1]);
}else{
$nesneId=get_class($fonksiyon[0]).$fonksiyon[1];
the function from which the error was received
function benzersiz_Filtre_id($ad,$fonksiyon,$onem){
static $idSaydir=0;
if(is_string($fonksiyon))
return $fonksiyon;
if(is_object($fonksiyon))
$fonksiyon=array($fonksiyon,'');
else
$fonksiyon=(array) $fonksiyon;
if(is_object($fonksiyon[0]))
{
if(function_exists('spl_object_hash')){
return spl_object_hash($fonksiyon[0],$fonksiyon[1]);
}else{
$nesneId=get_class($fonksiyon[0]).$fonksiyon[1];
if (!isset($fonksiyon[0]->filter_id)) {
if (false === $onem)
return false;
$nesneId .= isset($this->filtreler[$ad][$onem]) ? count((array) $$this->filtreler[$ad][$onem]) : $idSaydir;
$fonksiyon[0]->filter_id = $idSaydir;
++$idSaydir;
} else {
$nesneId .= $fonksiyon[0]->filter_id;
}
return $nesneId;
}
} else if (is_string($fonksiyon[0])) {
if(count($fonksiyon)>=2)
return $fonksiyon[0] . $fonksiyon[1];
else
return $fonksiyon[0];
}
}
As documented spl_object_hash requires only one argument.
So the part you are using is wrong
if(function_exists('spl_object_hash')){
return spl_object_hash($fonksiyon[0],$fonksiyon[1]);
}else{
$nesneId=get_class($fonksiyon[0]).$fonksiyon[1];
}
As you want the ID (hash) of one object, I suppose you mean
return spl_object_hash($fonksiyon);
// or
return spl_object_hash($fonksiyon[0]);
You can remove the function_exists part, because SPL is part of PHP since 5.0.
I'm trying to load a website url from a textfile, then unset this string from an array and pick a random website from the array.
But once I try to access the array from my function the array would return NULL, does someone know where my mistake is located at?
My current code looks like the following:
<?php
$activeFile = 'activeSite.txt';
$sites = array(
'http://wwww.google.com',
'http://www.ebay.com',
'http://www.icloud.com',
'http://www.hackforums.net',
'http://www.randomsite.com'
);
function getActiveSite($file)
{
$activeSite = file_get_contents($file, true);
return $activeSite;
}
function unsetActiveSite($activeSite)
{
if(($key = array_search($activeSite, $sites)) !== false)
{
unset($sites[$key]);
return true;
}
else
{
return false;
}
}
function updateActiveSite($activeFile)
{
$activeWebsite = getActiveSite($activeFile);
if(!empty($activeWebsite))
{
$unsetActive = unsetActiveSite($activeWebsite);
if($unsetActive == true)
{
$randomSite = $sites[array_rand($sites)];
return $randomSite;
}
else
{
echo 'Could not unset the active website.';
}
}
else
{
echo $activeWebsite . ' did not contain any active website.';
}
}
$result = updateActiveSite($activeFile);
echo $result;
?>
$sites is not avaliable in unsetActiveSite function you need to create a function called "getSites" which return the $sites array and use it in unsetActiveSite
function getSites(){
$sites = [
'http://wwww.google.com',
'http://www.ebay.com',
'http://www.icloud.com',
'http://www.hackforums.net',
'http://www.randomsite.com'
];
return $sites;
}
function unsetActiveSite($activeSite)
{
$sites = getSites();
if(($key = array_search($activeSite, $sites)) !== false)
{
unset($sites[$key]);
return true;
}
else
{
return false;
}
}
hi all when Using exif_imagetype() [function.exif-imagetype]: function for checking images if the user hits the submit button without uploading anything the exif function returns an error in the webpage itself. my question is how to get rid of this error. am pasting the error below
Warning: exif_imagetype() [function.exif-imagetype]: Filename cannot be empty in /mounted- storage/home98a/sub009/sc61374-HGPS/sitakalyanam.com/newsita/php4upload.class.php on line 88
<?php
/*
- PHP4 Image upload script
*/
class imageupload
{
//pblic variables
var $path = '';
var $errorStr = '';
var $imgurl = '';
//private variables
var $_errors = array();
var $_params = array();
var $_lang = array();
var $_maxsize = 1048576;
var $_im_status = false;
//public methods
function imageupload ()
{
//require 'photouploadconfig.php';
if($_GET['Choice']=="1")
{
require 'Photouploddir1.php';
}
elseif ($_GET['Choice']=="2")
{
require 'Photouploddir2.php';
}
elseif ($_GET['Choice']=="3")
{
require 'Photouploddir3.php';
}
elseif ($_GET['horoschoice']=="1")
{
require 'horosuploaddir.php';
}
elseif ($_GET['videoChoice']=="5")
{
require 'videouploaddir.php';
}
$this->_types = $types;
$this->_lang = $lang;
$this->_upload_dir = $upload_dir;
$this->_maxsize = $maxsize;
$this->path = $PHP_SELF;
if (is_array($_FILES['__upload']))
{
$this->_params = $_FILES['__upload'];
if (function_exists('exif_imagetype'))
$this->_doSafeUpload();
else
$this->_doUpload();
if (count($this->_errors) > 0)
$this->_errorMsg();
}
}
function allowTypes ()
{
$str = '';
if (count($this->_types) > 0) {
$str = 'Allowed types: (';
$str .= implode(', ', $this->_types);
$str .= ')';
}
return $str;
}
// private methods
function _doSafeUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if (exif_imagetype($this->_params['tmp_name']) && in_a rray(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;
if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -4);
$this->new_name = md5(time()).$ext;
move_uploaded_file($this->_params['tmp_name'], $this->_up load_dir.$this->new_name);
$this->imgurl =$this->new_name;
//$this->imgurl = .$this->new_name;
}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}
function _doUpload ()
{
preg_match('/\.([a-zA-Z]+?)$/', $this->_params['name'], $matches);
if(in_array(strtolower($matches[1]), $this->_types))
{
if ($this->_params['size'] > $this->_maxsize)
$this->_errors[] = $this->_lang['E_SIZE'];
else
$this->_im_status = true;
if ($this->_im_status == true)
{
$ext = substr($this->_params['name'], -3);
$this->new_name = md5(time()).$ext;
move_uploaded_file($this->_params['tmp_name'], $this- >_upload_dir.$this->new_name);
$this->imgurl = ''.$this->new_name;
//$this->imgurl = ''.$this->_upload_dir.''.$this->new_name;
//$this->imgurl = ''.$this->new_name;
//$this->imgurl = $this->_upload_dir.'/'.$this->new_name;
}
}
else
$this->_errors[] = $this->_lang['E_TYPE'];
}
function _errorMsg()
{
$this->errorStr = implode('<br />', $this->_errors);
}
}
?>
You are getting that message because you are never checking if the user uploaded a file or not, you're just assuming they are. When the user does not upload a file then $_FILES will be an empty array.
That means that $this->_params['tmp_name'] won't exist. You need to check if a file was uploaded, not just assume one was.
Just simply check the size of $_FILES.
if(count($_FILES) === 0){
echo "no file uploaded";
}
Change your code to this one and then try
if (isset($_FILES['__upload']))
{
$this->_params = $_FILES['__upload'];
if (function_exists('exif_imagetype'))
$this->_doSafeUpload();
else
$this->_doUpload();
if (count($this->_errors) > 0)
$this->_errorMsg();
}
I have problem. In my function, return shows only first player from server. I wanted to show all players from server, but i cant get this working. Here is my code:
function players() {
require_once "inc/SampQueryAPI.php";
$query = new SampQueryAPI('uh1.ownserv.pl', 25052); // Zmień dane obok! //
if($query->isOnline())
{
$aInformation = $query->getInfo();
$aServerRules = $query->getRules();
$aPlayers = $query->getDetailedPlayers();
if(!is_array($aPlayers) || count($aPlayers) == 0)
{
return 'Brak graczy online';
}
else
{
foreach($aPlayers as $sValue)
{
$playerid = $sValue['playerid'];
$playername = htmlentities($sValue['nickname']);
$playerscore = $sValue['score'];
$playerping = $sValue['ping'];
return '<li>'.$playername.' (ID: '.$playerid.'), Punkty ('.$playerscore.'), Ping ('.$playerping.')</li>';
}
}
}
}
You're returning from within your loop.
Instead, you should concatenate the results for each iteration and then return that concatenated string outside the loop.
e.g.
$result = "";
foreach($aPlayers as $sValue) {
# add to $result...
}
return $result
function players() {
require_once "inc/SampQueryAPI.php";
$query = new SampQueryAPI('uh1.ownserv.pl', 25052); // Zmień dane obok! //
if($query->isOnline())
{
$aInformation = $query->getInfo();
$aServerRules = $query->getRules();
$aPlayers = $query->getDetailedPlayers();
if(!is_array($aPlayers) || count($aPlayers) == 0)
{
return 'Brak graczy online';
}
else
{
$ret = '';
foreach($aPlayers as $sValue)
{
$playerid = $sValue['playerid'];
$playername = htmlentities($sValue['nickname']);
$playerscore = $sValue['score'];
$playerping = $sValue['ping'];
$ret .= '<li>'.$playername.' (ID: '.$playerid.'), Punkty ('.$playerscore.'), Ping ('.$playerping.')</li>';
}
return $ret;
}
}
}
In a function you can only return ONE value.
Try creating a list of players and return the list when all records have been added to it.
In your case, list of players will result in an array of players
It seems I've hit a wall here and could use some help
Would like to pass a MySql variable to a Joomla Module
Im using Yootheme's Widget-kit to display tweets from a search term. Works great and all but you need to enter the twitter search term in the Module back end.
Instead I would like to use a variable ( already used on the page) and pass that variable to the Twitter module so it can display the tweets I want
Here are some lines of PHP with the variable I'd like to use
$document->setTitle(JText::sprintf('COVERAGE_DATA_PLACE', $this->country->country_name, $this->city->city_name));
$text = JString::str_ireplace('%city_name%',$this->city->city_name,$text);
$this->setBreadcrumbs(array('country','city'));
Is there any way to take the "City" variable and send it to the 'word" field found in the twitter module?
Here is the Code for the twitter module
<?php
Class: TwitterWidgetkitHelper
Twitter helper class
*/
class TwitterWidgetkitHelper extends WidgetkitHelper {
/* type */
public $type;
/* options */
public $options;
/*
Function: Constructor
Class Constructor.
*/
public function __construct($widgetkit) {
parent::__construct($widgetkit);
// init vars
$this->type = strtolower(str_replace('WidgetkitHelper', '', get_class($this)));
$this->options = $this['system']->options;
// create cache
$cache = $this['path']->path('cache:');
if ($cache && !file_exists($cache.'/twitter')) {
mkdir($cache.'/twitter', 0777, true);
}
// register path
$this['path']->register(dirname(__FILE__), $this->type);
}
/*
Function: site
Site init actions
Returns:
Void
*/
public function site() {
// add translations
foreach (array('LESS_THAN_A_MINUTE_AGO', 'ABOUT_A_MINUTE_AGO', 'X_MINUTES_AGO', 'ABOUT_AN_HOUR_AGO', 'X_HOURS_AGO', 'ONE_DAY_AGO', 'X_DAYS_AGO') as $key) {
$translations[$key] = $this['system']->__($key);
}
// add stylesheets/javascripts
$this['asset']->addFile('css', 'twitter:styles/style.css');
$this['asset']->addFile('js', 'twitter:twitter.js');
$this['asset']->addString('js', sprintf('jQuery.trans.addDic(%s);', json_encode($translations)));
// rtl
if ($this['system']->options->get('direction') == 'rtl') {
$this['asset']->addFile('css', 'twitter:styles/rtl.css');
}
}
/*
Function: render
Render widget on site
Returns:
String
*/
public function render($options) {
if ($tweets = $this->_getTweets($options)) {
// get options
extract($options);
return $this['template']->render("twitter:styles/$style/template", compact('tweets', 'show_image', 'show_author', 'show_date', 'image_size'));
}
return 'No tweets found.';
}
/*
Function: _getURL
Create Twitter Query URL
Returns:
String
*/
protected function _getURL($options) {
// get options
extract($options);
// clean options
foreach (array('from_user', 'to_user', 'ref_user', 'word', 'nots', 'hashtag') as $var) {
$$var = preg_replace('/[##]/', '', preg_replace('/\s+/', ' ', trim($$var)));
}
// build query
$query = array();
if ($from_user) {
$query[] = 'from:'.str_replace(' ', ' OR from:', $from_user);
}
if ($to_user) {
$query[] = 'to:'.str_replace(' ', ' OR to:', $to_user);
}
if ($ref_user) {
$query[] = '#'.str_replace(' ', ' #', $ref_user);
}
if ($word) {
$query[] = $word;
}
if ($nots) {
$query[] = '-'.str_replace(' ', ' -', $nots);
}
if ($hashtag) {
$query[] = '#'.str_replace(' ', ' #', $hashtag);
}
$limit = min($limit ? intval($limit) : 5, 100);
// build timeline url
if ($from_user && !strpos($from_user, ' ') && count($query) == 1) {
$url = 'http://twitter.com/statuses/user_timeline/'.strtolower($from_user).'.json';
if ($limit > 15) {
$url .= '?count='.$limit;
}
return $url;
}
// build search url
if (count($query)) {
$url = 'http://search.twitter.com/search.json?q='.urlencode(implode(' ', $query));
if ($limit > 15) {
$url .= '&rpp='.$limit;
}
return $url;
}
return null;
}
/*
Function: _getTweets
Get Tweet Object Array
Returns:
Array
*/
protected function _getTweets($options) {
// init vars
$tweets = array();
// query twitter
if ($url = $this->_getURL($options)) {
if ($path = $this['path']->path('cache:twitter')) {
$file = rtrim($path, '/').sprintf('/twitter-%s.php', md5($url));
// is cached ?
if (file_exists($file)) {
$response = file_get_contents($file);
}
// refresh cache ?
if (!file_exists($file) || (time() - filemtime($file)) > 300) {
// send query
$request = $this['http']->get($url);
if (isset($request['status']['code']) && $request['status']['code'] == 200) {
$response = $request['body'];
file_put_contents($file, $response);
}
}
}
}
// create tweets
if (isset($response)) {
$response = json_decode($response, true);
if (is_array($response)) {
if (isset($response['results'])) {
foreach ($response['results'] as $res) {
$tweet = new WidgetkitTweet();
$tweet->user = $res['from_user'];
$tweet->name = $res['from_user'];
$tweet->image = $res['profile_image_url'];
$tweet->text = $res['text'];
$tweet->created_at = $res['created_at'];
$tweets[] = $tweet;
}
} else {
foreach ($response as $res) {
$tweet = new WidgetkitTweet();
$tweet->user = $res['user']['screen_name'];
$tweet->name = $res['user']['name'];
$tweet->image = $res['user']['profile_image_url'];
$tweet->text = $res['text'];
$tweet->created_at = $res['created_at'];
$tweets[] = $tweet;
}
}
}
}
return array_slice($tweets, 0, $options['limit'] ? intval($options['limit']) : 5);
}
}
class WidgetkitTweet {
public $user;
public $name;
public $image;
public $text;
public $created_at;
public function getLink() {
return 'http://twitter.com/'.$this->user;
}
public function getText() {
// format text
$text = preg_replace('#(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)#', '$1', $this->text);
$text = preg_replace('/#(\w+)/', '#$1', $text);
$text = preg_replace('/\s+#(\w+)/', ' #$1', $text);
return $text;
}
}
// bind events
$widgetkit = Widgetkit::getInstance();
$widgetkit['event']->bind('site', array($widgetkit['twitter'], 'site'));
I believe you can do what you want with this:
http://www.j-plant.com/joomla-extensions/free-extensions/26-module-plant.html
This plugin supports module parameters overriding. Use the next code
for overriding parameters:
[moduleplant id="77" <param_name_1>="<param_value_1>" <param_name_N>="<param_value_N>"]
replace and with the necessary parameter name and value.
You can override as many parameters as you want.
Available module parameters can be found in module XML manifest
file. A manifest file is usually located in the next path:
modules/<module_type>/<module_type>.xml