Mediawiki add user from custom registration page - php

I set up a custom registration page to my http server (apache) which hosts a number of services, including a wiki.
The intended goal is to have the user sign-up at once to all these services including the wiki of course.
For the wiki I'm trying to rearrange the "CreateAndPromote" maintenance script and fit it into my page. By now I came up with this snippet
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
chdir("wiki");
$mediaWiki = new MediaWiki();
$name = $_POST['username'];
$pass = $_POST['password'];
$user = User::newFromName( $name );
if ( !is_object( $user ) ) {
die("Invalid user!\n");
}
$exists = ( 0 !== $user->idForName() );
if ( !$exists ) {
$user->addToDatabase();
}
try {
$user->setPassword( $pass );
} catch ( PasswordError $pwe ) {
die("password error:" . $pwe->getText()."");
}
$user->addGroup("editor");
$user->saveSettings();
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();
But i get
Error: LightnCandy class not defined
MediaWiki 1.25.2
PHP 5.6.12 (apache2handler)

The problem was simple as that:
declaring the MW_INSTALL_PATH like that apparently did not work
$path = "/wiki";
putenv("MW_INSTALL_PATH={$path}");
require_once ("/wiki/includes/WebStart.php");
so I had to change dir to the wiki BEFORE requiring the webstart.php
chdir("wiki");
require_once ("/includes/WebStart.php");

Related

How would I keep the slash in my $domain when using wpmu_create_blog to create a site

I am currently working on an automated site creation function on my local installation of wordpress. In essence, a form is filled out on an already existing site and that info is pulled to create a new site automatically via an endpoint that activates some queries. So far I have been able to successfully pull the information into an array and then pass that to the wpmu_create_blog function. The issue is that the $domain isn't being called correctly(that is to say, how I intend it to be called), the '/' is lost between 'localhost' and 'wordpress'.
public function create_endpoint($request) {
$key = $request['key'];
if ($this->validate_key($key)) {
$newsite = array (
$title = $request['name'],
$path = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost/wordpress';
$site_id = get_blog_id_from_url($domain, $path);
$user_id = get_user_by('login', $admin_user);
if ( !empty($title) and !empty($domain) and !empty($path) and empty($user_id) ) {
return wpmu_create_blog($domain, $path, $title, $user_id, $site_id);
}
else {
return "Not enough information";
}
}
else {
return $this->invalid_key_message;
}
}
Everything but the domain being called as intended is working as intended. This is also just the static prototype, my end goal is that this is entirely dynamic including the $domain variable.
I'm just totally lost on where to go from here. I've tried some appendage stuff and moving syntax around in all types of ways but keep hitting a wall. Any input or suggestions are happily accepted.
I have a solution implemented. In the array $path has been changed to $slug (use of slug is specific to my code). The $domain now only calls 'localhost' and I create $path using plain text the 'wordpress' and then add the slug via a $request.
$newsite = array (
$title = $request['name'],
$slug = $request['slug'],
$admin_user = $request['admin_user'],
);
$domain = 'localhost';
$path = 'wordpress/'.$request['slug'];

Wordpress xmlprc not working in https

Recently, I have updated my site using an SSL and all URIs are now "https://".
My site is developed with Symfony 2 and mixing a Wordpress installation inside Symfony 2 web/wordpress directory.
All regular access is fine. Only one question:
In my Symfony 2, there is this code snippet:
private function getRecentPosts($num = 4)
{
require_once 'wordpress/wp-includes/class-IXR.php';
$user = '11111';
$pwd = '22222';
$host='https://www.rsywx.net';
$script='/wordpress/xmlrpc.php';
$port=443;
$client = new \IXR_Client($host, $script, $port);
$params = array(0, $user, $pwd, $num);
$client->query('metaWeblog.getRecentPosts', $params);
$wp = $client->getResponse();
return $wp;
}
When my site is not wrapped with https, the above code works fine. But now it is under https, the above code is not working. If I dump the $client variable after the query function call, it gives an error like:
+error: IXR_Error {#256 ▼
+code: -32300
+message: "transport error - could not open socket"
Any hints? Do I need to tweak my WP?
The problem was on the file wp-includes/class-IXR.php, it doesn't work with HTTPS, you must use also class-wp-http-ixr-client.php . And don't forget to include the configuration file wp-load.php.
The code snippet will be:
private function getRecentPosts($num = 4)
{
include 'wordpress/wp-load.php';
require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-IXR.php';
require_once ABSPATH . WPINC . 'wordpress/wp-includes/class-wp-http-ixr-client.php';
$user = '11111';
$pwd = '22222';
//Deprecated
/*
$host='https://www.rsywx.net';
$script='/wordpress/xmlrpc.php';
$port=443;
$client = new \IXR_Client($host, $script, $port);
*/
$client = new WP_HTTP_IXR_CLIENT('https://www.rsywx.net/wordpress/xmlrpc.php');
$params = array(0, $user, $pwd, $num);
$client->query('metaWeblog.getRecentPosts', $params);
$wp = $client->getResponse();
return $wp;
}
I just avoided using XMLRPC at all to solve this.
In my Symfony 2 application, I just used a 2nd database to directly access the underlying wordpress database. It is a hack but it resolves my issue for the time being.

how can we create search webservice in magento?

I am making a web service in magento. I have created many web-service of magento project like login, register, etc in magento project. I am not using third party web-service (default magento webservice).
I am follow the step: just create folder in magento root directory(webservice) then after create file serach.php and write the code for searching:
require("../app/Mage.php");
Mage::app();
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) {
$text = $_REQUEST['search_text'];
} else {
$text = "";
}
$search = "%" . trim($text) . "%";
$collection->addCategoryFilter()->addAttributeToSelect('name')->addAttributeToFilter('name', array(
'like' => $search
));
echo "";
print_r($collection);
die;
I am getting the error:
Fatal error: Call to a member function getId() on a non-object in /home/demo/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php on line 700
require("../app/Mage.php");
Mage::app();
if (isset($_REQUEST['search_text']) && ($_REQUEST['search_text'] != "")) {
$text = $_REQUEST['search_text'];
}
else{
$text = "";
}
$search = "%".trim($text)."%";
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku');
$collection->addAttributeToSelect('city');
$collection->joinAttribute('city', 'catalog_product/city', 'entity_id', null, 'inner');
$category = Mage::getModel('catalog/category')->load();
$productCollection = $collection->addCategoryFilter($category)
->addAttributeToSelect('name')
->addAttributeToFilter('name',array('like'=>$search));
Magento provides inbuilt easy to use SOAP and REST API..both easily extendable ..you can refer to Vinai Kopps got repo for REST API by session authentication
You haven't initialized and load the collection.
I'm missing such a line as:
$collection = Mage::getModel('catalog/product')->getCollection()...

Script doesn't get session variable

I made a website using WordPress, and on one page I've included my own script to guide users through a series of steps to calculate an outcome. The scripts are included in this order
Main page -> includes my Wizard.php -> Wizard.php include's Wizard_Step_xx.php
The Wizard reload's new steps every time from Step_01 until Step_10.php, this is done by a jQuery script.
Now my problem is that whenever a user finishis this "Wizard" he gets the option to log in and get redirected to his own page. Now when a user clicks the link to get to the "Wizard" I want to show the users personal page instead of showing him the first step of the wizard which would normally happen.
I've made this simple script that sets a $_SESSION variable when the user logs in :
//Validate Log In
if(isset($_POST['Validate'])) //submit login button
{
$inlog_naam = ( $_POST['inlognaam'] );
$wachtwoord = ( $_POST['wachtwoord'] );
$try = mysql_query("SELECT * FROM xxxx WHERE username = '$inlog_naam' AND password = '$wachtwoord'") or die (mysql_error() );
$result = mysql_num_rows($try);
if($result == 0)
{
$page = ( 8 );
$_SESSION['Invalid_Login_1'] = ( "true" );
}
else
{
$_SESSION['Invalid_Login_1'] = ( "false" );
$user_info = mysql_query("SELECT * FROM xxxxx WHERE username = '$inlog_naam' AND password = '$wachtwoord'") or die ( mysql_error() );
$user_info_result = mysql_fetch_array($user_info, MYSQLI_BOTH);
$user_lastname = ( $user_info_result['contact_Achternaam'] );
$user_id = ( $user_info_result['user_id'] );
$_SESSION['user_id_1'] = ( $user_id );
$_SESSION['user_name'] = ( $inlog_naam );
$_SESSION['user_lastname'] = ( $user_lastname );
$session_id = ( session_id() );
mysql_query("UPDATE xxxxx SET user_id = '$user_id', user_username = '$inlog_naam', user_lastname = '$user_lastname' WHERE session_id = '$session_id'") or die (mysql_error() );
$page = ( 9 );
$_SESSION['user_login'] = ( "true" );
$_SESSION['user_main_screen'] = ( "true" );
}
Now this part of the script works perferct, and the $_SESSION variables gets set.
But when I click on the link to go to the Wizard again I got this script in the Wizard.php file to show the users personal page instead of Wizard_Step_01.php which would normally happen.
if(isset($_SESSION['user_login']) && $_SESSION['user_login'] == 'true')
{
$page = 9;
}
else
{
echo $_SESSION['user_login'];
}
This script doesn't seem to see the $_SESSION variable, though when I click next on this page to go to Wizard_Step_02.php it DOES recognize it.
I've also noticed that for some reason, my site is running 2 PHPSESSID's , I thought I would prevent this by doing this :
<?php if(!isset( $_SESSION )) { session_start(); } ?>
but for some reason it still creates a second PHPSESSID.
If anyone has any idea on how to disable/delete/unset 1 of the 2 PHPSESSID's if this is where the problem lies, or any idea why this is happening....
To be clear: I want to know why my page doesn't find the setted $_SESSION['user_login'] when I load the page. Also any suggestions or any form of help is appreciated.
Thanks for reading.

Single Sign On : Stuck on progressing image in jsconnect

what i want to achieve is, user login in my wordpress website and also login on vanilla forum, i have installed jsconnect plugin in vanilla forum, and using the php's jsconnect library from following location jsConnectPHP
Here is my code:
require_once('functions.jsconnect.php');
$clientID = "1501569466";
$secret = "xxxxxxxxxxxxxxxxxxxxxx";
$userD = array();
if( isset($_POST['log']) ){
$data = array();
$data['user_login'] = $_POST['u_user'];
$data['user_password'] = $_POST['u_pass'];
$data['remember'] = TRUE;
$user = wp_signon($data, FALSE);
if(!is_wp_error($user)){
$userD['uniqueid'] = $user->ID;
$userD['name'] = $user->user_login;
$userD['email'] = $user->user_email;
$userD['photourl'] = '';
$secure = true;
WriteJsConnect($user, $_GET, $clientID, $secret, $secure);
$redirect = "http://localhost/vanilla/entry/jsconnect?client_id={$clientID}";
echo "<script>document.location.href='".$redirect."';</script>";
}
}
when the user login on wordpress i redirect it to jsconnect url in vanilla where i just found only a progress image, and can't figure out where is the problem..
jsconnect authentication url expects jsonp array like the following:
test({"email":"test#test.com",
"name":"testuser",
"photourl":"",
"uniqueid":1234,
"client_id":"12345678",
"signature":"XXXX"})
You authorization url you specify inside jsconnect should see this output to process further. In fact I am stuck at that point. I could see vanilla forum when loaded gets this input but no login happens.

Categories