hi i am trying to use openinviter gmail plugin . i downloaded the gmail.plg.php from
http://debug.openinviter.com/download.php
i created a new project(not a codeigniter project) in xampp->htdocs->gmail when i tried to run the code it said .
Fatal error: Class 'openinviter_base' not found in C:\xampp\htdocs\gmail\gmail.plg.php on line 26
so i downloaded the openinviter_base.php and added to top of my gmail.plg.php now the problem is nothing shown , how can i integrate this , any one know how to use this plugin .
and also i need to use this plugin with codeigniter , i have no idea .
i also saw this code , but unable to get an idea
http://code.google.com/p/spherenetwork/source/browse/trunk/plugins/lcOpenInviterPlugin/lib/openInviter/openinviter_base.php?r=146
please help me , i tried very much but failed , thanks ....................................
The plug-ins are very coupled with the overall open inviter framework, so I just added basically the whole thing. Perhaps overkill, but nice if you want to add other plug-ins. I placed the entire inviter tree at the top level (probably not the best place). I then added the following lib into the libraries directory. This was taken off of one of the codeigniter forums. Both in code grabbed from the forum and the main openinviter scripts, i found I had to put in a fair amount of small tweaks.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/* tky#tmo.blackberry.net inviter.php Fri May 22 04:00:19 GMT 2009 */
require_once($_SERVER['DOCUMENT_ROOT'].'/OpenInviter/openinviter.php');
class Importer
{
var $ci;
var $imported;
var $open_inviter;
var $plug_ins;
public function __construct()
{
$this->ci=&get_instance();
$this->open_inviter = new OpenInviter();
$this->plug_ins = $this->open_inviter->getPlugIns();
}
public function grab_contacts($plugin,$username,$password)
{
require_once($_SERVER['DOCUMENT_ROOT'].'/OpenInviter/openinviter.php');
$this->open_inviter->startPlugin($plugin);
if($this->open_inviter->login($username,$password))
{
$array = $this->open_inviter->getMyContacts();
if(is_array($array) && count($array)>=1)
{
$this->imported = $array;
//$this->_store_invited();
return($this->imported);
}
else
{
return $array;
}
}
else
{
//return 'ERROR on login.';
return false;
}
}
public function login($plugin,$username,$password)
{
$result = FALSE;
$this->open_inviter->startPlugin($plugin);
if($this->open_inviter->login($username,$password))
{
$result = TRUE;
}
return $result;
}
private function _store_invited()
{
foreach($this->imported as $mail=>$name)
{
$a = array
(
//'user_id' => ospc_user_id(),
'name' => $name,
'email_address' => $mail,
'status' => 0,
'time_imported' => time()
);
$this->ci->db->insert('ospc_imported',$a);
unset($a);
}
}
}
?>
Related
How can i get remote file's file size with codeigniter?
after making a connection , i want to get properties.xml file's size. in ordinery ftp i would get it with no problem but since i start using codeigniter it is kinda difficult.
this is in procedurel php ;
$remote_filesize = ftp_size($conn_id, "properties.xml");
but how can i do it in codeigniter?
if($this->ftp->connect($config))
{
/*here some magic code*/
}
this a small example
Controller_ftp.php
class Controller_ftp extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->library('ftp');
}
publilc function get_ftp_info(){
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug'] = TRUE;
foreach($this->ftp->list_files('/public_html/') as $item){
$size = filesize($item);
echo "name => $item - size => $size - etc <br>";
clearstatcache();
}
}
}
If you want to use $this->ftp->file_size($file), you need to extend ftp library and create the function retunring filesize($item);
ok i went to library->ftp.php and basically added a function
public function get_conn_id()
{ return $this->conn_id;}
and later all i need to do was calling the function like this
$conn_id = $this->ftp->get_conn_id();
$remote_filesize = ftp_size($conn_id, "properties.xml");
We're building a web application with CodeIgniter 2.1.4. It's in the crawling stages. Right now, it only has a basic logging and registering system.
What we've so far functions as expected locally, but when we try it online, we get the following error:
Fatal error: Class 'CI_Model' not found in /home4/csurmeli/public_html/other/ems/system/core/Common.php on line 174
It doesn't make any sense since we haven't changed any of the core files. And our online server is well established.
Any suggestions?
The controller calling login:
function login(){
if($this->session->userdata('userid') !== false){
redirect(base_url()."index.php/users/success");
}
$data['error'] = 0;
if($_POST){
$this->load->model('user');
$username = $this->input->post('username',true);
$password = $this->input->post('password',true);
$user = $this->user->login($username,$password);
if(!$user){
$data['error']=1;
redirect(base_url()."index.php/users/error");
}else{
$this->session->set_userdata('userid',$user['userid']);
$this->session->set_userdata('privilege',$user['privilege']);
redirect(base_url()."index.php/users/success");
}
}
$this->load->view('header');
$this->load->view('login',$data);
$this->load->view('footer');
}
Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class User Extends CI_Model{
public function __construct(){
parent::__construct();
}
function create_user($data){
if($data['is_sent']){
$query = array("username" => $data['username'],
"password" => $data['password'],
"email" => $data['email']
);
$this->db->insert('users',$query);
}
}
function login($username,$password){
$where = array(
'username'=>$username,
'password'=>$password
);
$this->db->select()->from('users')->where($where);
$query = $this->db->get();
return $query->first_row('array');
}
}
?>
if it works locally - its probably just an issue on the main index.php page
in index.php find the banners: SYSTEM FOLDER NAME and APPLICATION FOLDER NAME
then double check that the file path and the folder names are correct for your server.
<?php
class Home extends CI_Controller
{
public function __construct()
{
// load libraries //
$this->load->library('session');
$this->load->library('database');
$this->load->library('captcha');
// alternative
$this->load->library(array('session', 'database', 'captcha'));
// load models //
$this->load->model('menu_model', 'mmodel');
$this->load->model('user_model', 'umodel');
$this->load->model('admin_model', 'amodel');
// alternative
$this->load->model(array(?));
}
}
?>
How can i load all models in array? is it possible?
For models, you can do this:
$models = array(
'menu_model' => 'mmodel',
'user_model' => 'umodel',
'admin_model' => 'amodel',
);
foreach ($models as $file => $object_name)
{
$this->load->model($file, $object_name);
}
But as mentioned, you can create file application/core/MY_Loader.php and write your own method for loading models. I think this might work (not tested):
class MY_Loader extends CI_Loader {
function model($model, $name = '', $db_conn = FALSE)
{
if (is_array($model))
{
foreach ($model as $file => $object_name)
{
// Linear array was passed, be backwards compatible.
// CI already allows loading models as arrays, but does
// not accept the model name param, just the file name
if ( ! is_string($file))
{
$file = $object_name;
$object_name = NULL;
}
parent::model($file, $object_name);
}
return;
}
// Call the default method otherwise
parent::model($model, $name, $db_conn);
}
}
Usage with our variable from above:
$this->load->model($models);
You could also allow a separate DB connection to be passed in an array, but then you'd need to have a multidimensional array, and not the simple one we used. It's not too often you'll need to do that anyways.
I don't have any idea about the CodeIgniter 2.x but in CodeIgniter 3.x, this will also works :
$models = array(
'menu_model' => 'mmodel',
'user_model' => 'umodel',
'admin_model' => 'amodel',
);
$this->load->model($models);
Not natively, but you can easily extend Loader->model() to support that logic.
This work fine for me:
$this->load->model(array('menu_model'=>'menu','user_model'=>'user','admin_model'=>'admin'));
I searched the whole Internet and either there is no one mentioning my problem, or I'm stupid, or maybe it's just a bad day for coding.
What's the situation:
controller "source"
model "source"
model "login"
The "login" model is loaded from autoload.php, then in each controller's constructor I have $this->login->check(), which is checking if the user is logged in (obviously). Then in some of the methods I'm using the "source" model to connect to the database.
I tried loading both of the models from the autoload array, I also tried to load them in the way described here, but it's obviously for an old CI version (the thread is from 2008) and I tried all the possible ways I had in my mind.
Anyway, the result is this:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Source::$login
Filename: controllers/source.php
Line Number: 10
Fatal error: Call to a member function check() on a non-object in ...\application\controllers\source.php on line 10
Any ideas what I'm missing or how to fix it...? I'm stuck for hours and I don't have any ideas what I could do...
Edit 1: here is the code from the "source" controller:
class Source extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('login');
$this->login->check();
}
function index() {
// Pagination config, getting records from DB
$this->load->view('templates/layout', $data);
}
function add() {
$this->load->model('source', '', true);
$btn = $this->input->post('btn');
if(isset($btn)) {
// More form validation
if($this->form_validation->run() == TRUE) {
if($btn == "Add") {
// here I am supposed to use the source model...
}
}
}
$data['page'] = 'source_add';
$this->load->view('templates/layout', $data);
}
}
?>
Edit 2: login.php:
<?php
class Login extends CI_Model {
function __construct() {
parent::__construct();
}
function authenticate($username, $password) {
// the login script comes here
}
function logged() {
if($this->session->userdata('logged') == true) {
return true;
} else return false;
}
function check() {
if(!$this->logged()) {
redirect('/authentication');
}
}
}
?>
Conventionally, the classname of Models should end with _model, so it not collides with controllers with the same name, so try changing
class Login extends CI_Model {
to
class Login_model extends CI_Model {
I resolved this issue by utilizing the hooks and turned the login process into a controller, thereby being able to access user information and setting access levels.
First I added the following to the hooks.php file in the config folder
$hook['post_controller_constructor'][] = array('function' => 'check_login','filename' => 'authority.php','filepath' => 'hooks');
Then I have the following functions in a hook file called authority.php
[EDIT]Having reviewed this I am going to change it to a pre_controller_constructor and see if I can remove what seems to be a double page flash on initial construct.[/EDIT]
function check_login(){
$CI =& get_instance();
$is_logged_in = $CI->session->userdata('is_logged_in');
if(!$is_logged_in){
$unauth_pages = array(your unauthorized pages go here);
if(!in_array($CI->router->class,$unauth_pages)){
$CI->session->set_userdata('before_login_url',current_url());
redirect('login');
}
}
}
function check_authority(){
$CI =& get_instance();
if($CI->session->userdata('usergroupID') == 'SUPADMIN'){return;}
$page = $CI->router->class ;
$method = $CI->router->method;
$method = ($method=='index')?'':$method;
$unauth_pages = array(your unauthorized pages go here);
if(in_array($page,$unauth_pages))return;
$user_group = $CI->session->userdata('usergroupID');
$CI->load->model('user_model');
if($user_group == 'ADMIN' || $user_group == 'USER'){
if($CI->session->userdata('timezone') == ''){
date_default_timezone_set('Canada/Pacific');
} else {
date_default_timezone_set($CI->session->userdata('timezone'));
}
}
if( !$CI->user_model->authorized_content($CI->session->userdata('usergroupID'),$page, $method)){
redirect('unauthorized');
}
}
With the above I dont have to worry about checking on each page but instead utilize the ci framework to do the checking for me.. if its not in the unauth page array then it is a page that requires authorization checking.
Hope this works for you.
I'm using the technique of saving codeigniter form validation rules to a config file as specified here, but can't seem to get it working.
I am also attempting to invoke validation callback functions from a Validation_Callbacks.php library which I'm autoloading via the autoload.php mechanism.
Below is a snippet from my form_validation.php form validation rules config file:
<?php
/* This config file contains the form validation sets used by the application */
$config = array(
'register_user' => array(
array(
'field' => 'dob',
'label' => 'lang:register_dob',
'rules' => 'trim|required|date_check|age_check|xss_clean'
), ...
)
)
And here is the Validation_Callbacks.php file, that lives under application/libraries:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Custom validator library containing app-specific validation functions
*/
class Validation_Callbacks {
/* Checks that the given date string is formatted as expected */
function date_check($date) {
$ddmmyyyy='(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)[0-9]{2}';
if(preg_match("/$ddmmyyyy$/", $date)) {
return TRUE;
} else {
$this->form_validation->set_message('date_check', $this->lang->line('error_register_dob_format'));
return FALSE;
}
}
/* Checks that the given birthday belongs to someone older than 18 years old. We assume
* that the date_check method has already been run, and that the given date is in the
* expected format of dd/mm/yyyy */
function age_check($date) {
$piecesDate = explode('/', $date);
$piecesNow = array(date("d"), date("m"), date("Y"));
$jdDate = gregoriantojd($piecesDate[1], $piecesDate[0], $piecesDate[2]);
$jdNow = gregoriantojd($piecesNow[1], $piecesNow[0], $piecesNow[2]);
$dayDiff = $jdNow - $jdDate;
if ($dayDiff >= 6570) {
return TRUE;
} else {
$this->form_validation->set_message('age_check', $this->lang->line('error_register_age_check'));
return FALSE;
}
}
}
I'm invoking this using the standard:
if ($this->form_validation->run('register_user') == FALSE) {
My callback functions are not being called. Is there something I'm missing here? Thanks in advance for any help you may be able to provide!
Ensure that:
When a rule group is named identically
to a controller class/function it will
be used automatically when the run()
function is invoked from that
class/function.
To test you can try using:
$this->load->config('configname');