Hello,
I'm implementing some "shortcodes" in my silverstripe website. For example, i already created some for Youtube, Vimeo and Soundcloud but i can't find a way to add the Flickr one.
Here is a sample code for vimeo :
public static function Vimeo($args, $caption = null, $parser = null) {
if (empty($args['id']))
return;
$data = array();
$data['VimeoID'] = $args['id'];
$data['autoplay'] = false;
$data['caption'] = $caption ? Convert::raw2xml($caption) : false;
$data['width'] = 640;
$data['height'] = 385;
$data = array_merge($data, $args);
$template = new SSViewer('shortcode/Vimeo');
return $template->process(new ArrayData($data));
And this is what i found for flickr :
$query = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=" . API_KEY . "&photo_id=" . $photoid . "&format=json&nojsoncallback=1";
data = json_decode(file_get_contents($query));
echo "created by: " . data->photo->owner->username;
echo "link to photopage: " . "http://www.flickr.com/photos/" . data->photo->owner->nsid
But nothing for the .ss file
Does anybody know how to do it or already did it?
Thanks for help!
Thomas.
Hi
I finally found a solution for using the flickr shortcode ->
public static function Flickr($args, $caption = null, $parser = null) {
if (empty($args['set_id']) && empty($args['user_id']))
return;
$data = array();
$data['SET'] = $args['set_id'];
$data['USER'] = $args['user_id'];
if (!$scid = SiteConfig::current_site_config()->FlickrClientID) {
$data['KEY']= $scid = SiteConfig::current_site_config()->FlickrClientID = "id";
}
ini_set("flickr", "FLICKR");
$pics = json_decode(file_get_contents(
"http://www.flickr.com/services/rest/?method=flickr.photos.getAllContexts&api_key=".$scid."&format=json&set_id=".$args['set_id']), true);
$data['ID'] = $pics['id'];
$data = array_merge($data, $args);
$template = new SSViewer('shortcode/Flickr');
return $template->process(new ArrayData($data));
}
Using this iframe ->
<div class='Flickr clearfix'>
<iframe align="center" src="http://www.flickr.com/slideShow/index.gne?user_id=$USER&set_id=$SET" frameBorder="0" width="500" height="500" scrolling="no"><br /></iframe>
</div>
This solution works fine if you want to display some flickr set pictures.
Hope it'll help someone else.
See you
Related
I want so connect an external website with a moodle-system. I've already set up the webService and created a token to get access.
I've followed http://www.rumours.co.nz/manuals/using_moodle_web_services.htm set up but in contrast i wanted to realise the connection via REST as in https://github.com/moodlehq/sample-ws-clients/find/master
My approach is to have a moodle class which will handle the data exchange. In first place i just wanted to try to create some new hard coded Users via the webService but it fails with the Moodle-Response:
"invalidrecord Can not find data record in database table external_functions. "
Which seems to me as if i the call was successfully but moodle has a problem to find the "core_user_create_users" function. I've checked the local moodle Database and in the table external_functions is an entry for "core_user_create_users" so i'm kind of confused where moodle doesn't know what to do.
Thats my class:
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
class Moodle {
private $token;
private $domainName; // 'local.moodle.dev';
private $serverUrl;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$user2 = new stdClass();
$user2->username = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail2#moodle.com';
$user2->timezone = 'Pacific/Port_Moresby';
$users = array($user1, $user2);
$params = array('users' => $users);
/// REST CALL
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName;
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = "json";
$resp = $curl->post($serverurl . $restformat, $params);
//print_r($resp);
echo '</br>*************Server Response*************</br>';
var_dump($resp);
}
}
I'm using the curl class from the same github-project which i posted above - moodle is linkng to it in their Documentation..
docs.moodle.org/dev/Creating_a_web_service_client
The entry point of my call is hardcoded right now:
<?php
include_once (DOCUMENT_ROOT.'/tcm/api/moodle/moodle.php');
//entry point of code
if (isset($_POST)){
//token and domain would be in $_POST
$bla = new Moodle('0b5a1e98061c5f7fb70fc3b42af6bfc4', 'local.moodle.dev');
$bla->createUser();
}
Does anyone know how to solve the "invalidrecord Can not find data record in database table external_functions" error or has a different approach/suggestion how i can create my users remotely??
Thanks in advance
I got it finally working with the following code:
class Moodle {
private $token; //'0b5a1e98061c5f7fb70fc3b42af6bfc4';
private $domainName; // 'http://local.moodle.dev';
private $serverUrl;
public $error;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'Uk3#0d5w';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = '';
$user1->lang = 'en';
$user1->timezone = 'Australia/Sydney';
$user1->mailformat = 0;
$user1->description = '';
$user1->city = '';
$user1->country = 'AU'; //list of abrevations is in yourmoodle/lang/en/countries
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$restformat = "json";
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName. '&moodlewsrestformat=' . $restformat;
require_once (DOCUMENT_ROOT . '/tcm/api/moodle/curl.php');
$curl = new curl();
$resp = $curl->post($serverurl, $params);
echo '</br>************************** Server Response createUser()**************************</br></br>';
echo $serverurl . '</br></br>';
var_dump($resp);
}
}
Info:
For all moodle beginners.. Activating the moodle Debug messages helps a bit. You'll receive an additional error information in the response returned form the server.
Moodle -> Site Administration -> Development -> Debugging -> Debug Messages
Select: DEVELOPER:extra Moodle debug messages for developers
Hi i have an issue with prestashop module, I've just created module called TestModule and in install method I got following code:
public function install() {
$parent_tab = new Tab();
foreach (Language::getLanguages(true) as $lang) {
$parent_tab->name[$lang['id_lang']] = 'TestModule';
}
$parent_tab->class_name = 'TestModule';
$parent_tab->id_parent = 0;
#copy(_PS_MODULE_DIR_ . $this->name . '/logo.png', _PS_IMG_DIR_ . 't/TestModule.png');
$parent_tab->module = $this->name;
$parent_tab->add();
if (!parent::install()) {
return false;
}
return true;
}
And it created the Tab "TestModule", but when I'm clicking on it there is the information that "Controller not found". How can I set some content here?
See this bellow code , it will help you you made mistake
$langs = Language::getLanguages();
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$smarttab = new Tab();
$smarttab->class_name = "AdminSmartBlog";
$smarttab->module = "";
$smarttab->id_parent = 0;
foreach($langs as $l){
$smarttab->name[$l['id_lang']] = $this->l('Blog');
}
$smarttab->save();
$tab_id = $smarttab->id;
#copy(dirname(__FILE__)."/AdminSmartBlog.gif",_PS_ROOT_DIR_."/img/t/AdminSmartBlog.gif");
Hi I am trying to get my gravatar api working with my open cart admin/controller/common/header.php and my admin/view/template/common/header.tpl
Still not working gave it ago before that some one gave me advice on but now not working? So thought give it ago another way but nothing.
admin / controller/ header. php
This is just trimmed down version
<?php
class ControllerCommonHeader extends Controller {
protected function index($get_gravatar) {
}
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
admin / view / template / common / header.tpl
<?php
$email = $user_info['email']; // Not Working "Need it to pick up who ever logins"
$email = "your#rmail.com"; // Works
$default = "http://www.somewhere.com/homestar.jpg";
$size = 150;
?>
<li>
<a href="" class="text-center">
<img src="<?php echo $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;; ?>" alt="" />
</a>
</li>
Changes for getting gravatar image in header.tpl
Update system/library/user.php as below:
After: $this->username = $user_query->row['username'];
Add: $this->email = $user_query->row['email'];
Before: public function getUserName() {
Add:
public function getUserEmail() {
return $this->email;
}
Update admin/controller/common/header.php as below:
After: $this->data['logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());
Add: $this->data['email'] = $this->user->getUserEmail();
Update admin/view/template/common/header.tpl as below:
<div class="img-circle">
<img src="http://www.gravatar.com/avatar/<?php echo md5(strtolower(trim($email))); ?>">
</div>
Please let me know the result of these changes.
Note: In opencart, you need to assign values to variables like: $this->data['variable_name'] in controller files and use them template files like: $variable_name.
Have you tried adding an extension to your url => www.gravatar.com/avatar/far512q3tgfqwe*.jpg* for example, a quick google search and i came up with this url, check it for further info:
http://en.gravatar.com/site/implement/images/
Try this piece of code in your header.php to get the email of the current logged in user:
$this->load->model('user/user');
$email_data = $this->model_user_user->getUser($this->user->getId());
$email = $email_data['email'];
if you want to get emails for all users it need to be handled differently.
In the following code, I check if the form is valid, and if yes, I want it to redirect to the next page, however it's giving the following error:
AN ERROR OCCURRED
PAGE NOT FOUND
EXCEPTION INFORMATION:
Message: Invalid controller specified (undefined)
Here's the code:
public function indexAction()
{
global $current_user;
if ( is_user_logged_in() ) {
$mapper = new Site_Model_WpTerms();
$main_categories = $mapper->fetchTerms(0,'ptype',true);
$sizes = $mapper->fetchTerms(0,'size',true);
$genders = $mapper->fetchTerms(0,'gender',true);
$seasons = $mapper->fetchTerms(0,'season',true);
$decades = $mapper->fetchTerms(0,'decade',true);
$colors = $mapper->fetchTerms(0,'color',true);
$styles = $mapper->fetchTerms(0,'style',true);
$materials = $mapper->fetchTerms(0,'material',true);
$patterns = $mapper->fetchTerms(0,'pattern',true);
$others = $mapper->fetchTerms(0,'other',true);
$condition = $mapper->fetchTerms(0,'condition',true);
$shipping = $mapper->fetchTerms(0,'shipping',true);
$this->view->colors = $colors;
$form = new Site_Form_Submission($main_categories,$sizes,$genders,$seasons,$decades,$colors,$styles,$materials,$patterns,$others,$condition,$shipping);
$this->view->form = $form;
$this->view->finished_settings = self::finishedStep('finished_settings');
if ($this->getRequest()->isPost()) {
if (!$form->isValid($this->getRequest()->getParams())) {
$form->populate($this->getRequest()->getParams());
}else{
$this->_helper->redirector('getpaid');
}
}
}
else{
$this->_redirect('http://' . $_SERVER['HTTP_HOST'] . PHOTO_GUIDE);
}
}
I must mention that I'm using modules in my application.
Any help would be really appreciated!
Try the following code:
$redirector = $this->_helper->getHelper('Redirector');
$this->_redirector->setCode(303)
->setExit(false)
->setGotoSimple("this-action", "some-controller");
Try this $this->_helper->redirector('action','controller','module');
I have an extension that displays a basic user profile derived from the Yii widget class. My extension is defined as follows:
class BasicProfile extends CWidget
{
public $user_id;
private $userinfo = array();
private $userdetail = array();
private $availibility = array();
private $availabletime = array();
private $usereducation = array();
private $userlanguages = array();
private $userlivingplace = array();
public function init()
{
$this->userinfo = $users = Users::model()->findByPk($this->user_id);
$this->userdetail = $users->profile;
$this->availibility = $users->user_availibility;
$this->availabletime = $users->user_availabletime;
$this->usereducation = $users->user_education;
$this->userlanguages = $users->user_languagues;
$this->userlivingplace = $users->user_livingplaces;
}
public function run() {
$this->getUserDetail();
}
public function getUserDetail(){
$basic = $this->userinfo;
$detail = $this->userdetail;
$availibility = $this->availibility;
$availabletime = $this->availabletime;
$usereducation = $this->usereducation;
$userlanguages = $this->userlanguages;
$userlivingplaces = $this->userlivingplace;
$age = getAge(strtotime($detail['date_of_birth']));
$is_smoker = isSmoker($detail['is_smoker']);
$education = '';
foreach ($usereducation as $ue)
{
$e = $ue->educ;
$education .= $e['edu_name']. ', ';
}
$education = substr($education, 0, -2);
$languages = '';
foreach ($userlanguages as $ul)
{
$l = $ul->lang;
$languages .= $l['language_title']. ', ';
}
$languages = substr($languages, 0, -2);
$condition = array('where_condition'=>'up.user_id=:id AND up.is_currently_own=:own', 'where_data'=>array(':id'=>(int)$this->user_id, ':own'=>'Yes'));
$user_pets = Users::model()->getUserPets($condition);
$profile_images = UserProfileImages::model()->getProfileImages( array('select'=>'all'), $this->user_id );
foreach( $profile_images as $profile_img ) {
$images[] = $profile_img->profile_image;
}
$image = '';
if( $images ){
$main_image = HTTP_HOST . PROFILE_IMAGES_THUMB . $images[0];
$image = '<img src="'. $main_image .'" />';
}
$address1 = $basic['address1'];
if($basic['address2'] != "")
$address1 .= ", ".$basic['address2'];
$address2 = $basic['city']." ".$basic['state'].", ". $basic['zip'];
$editprofile = url('/users/account');
$editimglink = url('/images/icons/Modify.png');
}
}
My goal is to simply call this extension in my view as follwos:
$this->widget('ext.UserProfile.BasicProfile',array('user_id'=>$user_id));
However, I'm wondering if my extension is the proper place to encapsulate the image rotator? Should the rotator be included in the extension, or as part of the view? Should a generic JQuery image rotator be used, or is there one that plays well with Yii Framework?
I like to use JQuery.Cycle as my image rotator. I suggest that you build an extension with assets to keep the code in one place. you can however put your css in your theme folder and build a basic css in your extension to keep it clean like the basic pager of yii.
You could call your widget like this:
$this->widget("application.extensions.rotator", array("images" => array("/path/to/image/1", "/path/to/image/2"), "prevBtn" => "/path/to/prev/button");