How to permit arabic characters in url - codeigniter-3

My url has arabic characters like http://localhost/Mypro/ar/flights/رخيص-هواء-تذاكر-البحرين-إلى-مومباي-بوم-باه and i was route this to a method. When I load this url I've got an error:
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.39 (Win64) OpenSSL/1.1.1b PHP/7.2.18.
Can any one help me to fix this issue.
config\route.php
$path = urlencode('الرخيصة من الجو تذاكر - (: وجدت) -to - (: أي) - (: أي) - (: وجدت)');
$route['^(en|ar)/'.$path] = "Seo/viewCities";
config\config.php
$config['permitted_uri_chars'] .= '%D8%A2%D8%A7%D8%A8%D9%BE%D8%AA%D8%AB%D8%AC%DA%86%D8%AD%D8%AE%D8%AF%D8%B0%D8%B1%D8%B2%D8%B3%D8%B4%D8%B5%D8%B6%D8%B7%D8%B8%D8%B9%D8%BA%D9%81%D9%82%DA%A9%DA%AF%D9%84%D9%85%D9%86%D9%88%D9%87%DB%8C%D9%8A%DB%B1%DB%B2%DB%B3%DB%B4%DB%B5%DB%B6%DB%B7%DB%B8%DB%B9%DB%B0';
system\core\uri.php
public function filter_uri(&$str)
{
if (!preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
}

This piece of code maybe can help
$string ="العربی (العربی";
$string=str_replace(")","",$string);
//and u can use other str_replace
$this->load->helper('text');
$til = url_title(convert_accented_characters($string), 'dash', true);
//$til your slug for url
this work for me :)

Related

Getting restrictions from Confluence page

I'm not very savvy with web API calls, but I've been using the following powershell code (this site in this example is one I found that has some public data... my site is internal and requires I pass the credential, which has been working for me without issue):
If(-not (Get-InstalledModule -Name 'ConfluencePS')){Install-Module ConfluencePS}
Import-Module ConfluencePS
Set-ConfluenceInfo -BaseUri "https://wiki.opnfv.org"
$space = Get-confluencepage -Spacekey ds
ForEach($item in $space)
{
$splatParams = #{
Uri = "https://wiki.opnfv.org/rest/api/content/$($item.ID)/restriction"
ContentType = 'application/json'
method = 'GET'
}
#reference https://developer.atlassian.com/cloud/confluence/rest/#api-api-content-id-restriction-get
Invoke-RestMethod #splatParams
}
The documentation for the ConfluencePS shows that restrictions is still an open feature request but I need to get this working for a project.
I put a breakpoint in on line 982 from ConfluencePS.psm1 and was able to see the various calls and how the params are structured but when I try to mimic it (and change the URI based on the confluence documentation) I get an error "HTTP error 405 - MethodNotAllowed". Anyone have suggestions on how I can get this working? I'm trying to return back the permissions applied for all pages in a specific space.
Get Restrictions by Content ID
As you found out by yourself, it is required to add "byOperation".
I was able to get the restrictions of a specific page with the following code:
# for testing purposes ONLY, I've specified the URL and ID
$wikiUrl = "https://wiki.opnfv.org"
$itemId = "6820746"
$splatParams = #{
Uri = "$wikiUrl/rest/api/content/$itemId/restriction/byOperation"
ContentType = 'application/json'
method = 'GET'
}
$result = Invoke-RestMethod #splatParams
Tested on version 6.0.4 and 6.15.9
Filter by user name
If you like to filter the result by a specific username, you can use the following URI:
"$wikiUrl/rest/api/content/$itemId/restriction/byOperation/.../user?userName=".
Bt, there's an open bug on this way of action:
restriction returns ambiguous responses

Errors in codeigniter-restserver library

I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)

Mantis Bug Tracker SOAP API Response XML Error

I am using Mantis Bug Tracker SOAP API, but unfortunately every time it returns to me message like
"looks like we got no XML document",
after tracing the last response I got following message
"<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Issue does not exist.</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>"
I hope that, I am getting xml respose back, it appears that there is a addition of "" characters in the beginning.
Any clue or help would be great, in removing those characters.
The code for connecting to MANTIS SOAP API SERVER
<?php
$c = new \SoapClient("http://dev06/api/soap/mantisconnect.php?wsdl", array('trace'=> true, 'encoding'=>' UTF-8', 'soap_version'=>1.2));
$username = "xxxxx";
$password = "xxxxx";
try {
$c->mc_issue_get(trim($username), trim($password), 2331);
} catch (SoapFault $exception) {
var_dump($c->__getLastResponse());
}
?>
I don't see any issue with your code and it works perfectly in my environment with slight modifications:
$c = new \SoapClient("http://localhost/demo/mantisbt-1.2.15/api/soap/mantisconnect.php?wsdl", array('trace'=> true, 'encoding'=>' UTF-8', 'soap_version'=>SOAP_1_2));
$username = "XXXXXXXX";
$password = "XXXX";
try {
$issue = $c->mc_issue_get(trim($username), trim($password), 31);
var_dump($issue);
} catch (SoapFault $exception) {
var_dump($c->__getLastResponse());
}
It could be the soap_version, so may be you could try with soap_version=SOAP_1_1
Oh...!
Finally got the solution for it. Its very simple.
Firstly mantis SOAP API code base contains may be more than 20,000 lines of code. I think there is some where some one is printing some BOM characters.
So best solution would be, just use following function,
ob_clean();
This function must be used in
/library/nusoap/nusoap.php
Because this file has
send_response()
That printouts payload, So just use ob_clean() at the beginning of the send_response() function.
Thanks and hope it will help others.

facebook api in R: OAuthException error, code 803

Im trying to connect to Facebook using R. I tried to use the codes from
https://github.com/datamgmt/facebook-data-mining
Which gets the user information with the following code:
access.token<- "AAACE________n6bcITRIMCZCKhMySOV" #my access token
FacebookFetch <- function(access.path = "me", access.token, access.options) {
if (missing(access.options)) {
access.options <- ""
}
else {
access.options <- sprintf("?%s", paste(names(access.options), "=",
unlist(access.options), collapse = "&", sep = ""))
}
data <- getURL(sprintf("https://graph.facebook.com/%s%s&access_token=%s",
access.path, access.options, access.token),cainfo="cacert.pem")
fromJSON(data)
}
individual.id <- "100__72" # my ID
individual <- FacebookFetch(access.path=paste(individual.id),access.token=access.token )
if (length(individual$id)) {
cat ("Working with individual: ",individual$name," (",individual$id,")\n", sep="")
} else{
cat("Message: ", unlist(individual)[1], "\n")
cat("Type: ", unlist(individual)[2], "\n")
cat("Code: ", unlist(individual)[3], "\n")
stop(" Cannot continue")
}
where cainfo="cacert.pem" is added to work around the SSL certificate verification error.
Although now I get the following error and I have no idea how to solve this.
Message: (#803) Some of the aliases you requested do not exist: 100__72&access_token=AAACE________n6bcITRIMCZCKhMySOV
Type: OAuthException
Code: 803
I found some posts where people got the same problem, only not using R but other programs, the problem was fixed by making the token and id a character. However, in R, these are already of class character.
When im recreating the url in the browser it returns the same error, while the graph explorer returns all the correct information. I have tried to refresh the token multiple times, but that didn't work.
The API reference book doesn't state what error code 803 entails.
does anybody have an idea how to solve this?
Im using r 2.15.2 in Rstudio on a windows 7 pro (also tried it on windows vista)

malformed email subject header when subject > 75 chars using codeigniter email lib

I'm getting some garble in my MIME headers when the subject is over 75 chars.
When the line break is encoded in the header there is an extra line break that is invalid.
Some email gateways are bouncing the email with a "Malformed MIME field: ?= =?utf-8?Q?SUBJECT?=" error.
Does anyone have any experience with utf-8 problems sending emails with CodeIgniter?
-snip-
Return-Path: ***
Subject: =?utf-8?Q?SUBJECT_LINE <--
?= <-- Problem in Subject header
=?utf-8?Q?SUBECT_LINE_2?= <--
To: ***
Reply-To: ***
-snip-
Update:
This has nothing to do with gmail smtp. I have rewritten the question in the hope that it will help someone out in the future.
Apparently this is a known issue, caused by Subject lines > 75 chars.
http://codeigniter.com/forums/viewthread/154493/P15/#925385
The fix was to change the email config like this:
$config['newline'] = "\r\n";
$config['crlf'] = "\n";
Since I myself had this exact problem I will share the solution here since the one shared does not work with version 2.2
Find this piece of code located in system/libraries/Email.php:365
public function subject($subject)
{
$subject = $this->_prep_q_encoding($subject);
$this->_set_header('Subject', $subject);
return $this;
}
With this one
public function subject($subject)
{
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$this->_set_header('Subject', $subject);
return $this;
}