Advertisement

Friday 27 February 2015

How to add custom fields in user registration form in osclass.

In osclass user's registration form , you will see only few fields that's not enough for a user to register.
Osclass has functions to call the extra fields in the registration form. That can be called separately or it can be called by running a hook at last of the users registration page of osclass script.

Here i explain you the easiest way to implement the extra fields in the user registration form.First we need to download the 'requiredreg' plugin to achieve it in easy way. The name of the plugin is required registration plugins its a free plugin. we can directly download it and install in osclass and activate it.

After done the above things we just need to call a hook function in the user registration page of osclass, which is inside the theme folder user-registration.php file. 

call this hook at the end of the user-registration.php file but before submit button.

           <?php osc_run_hook('user_register_form'); ?>

    For Example:

             <?php osc_run_hook('user_register_form'); ?>
                    <div class="control-group">
                        <div class="controls">
                            <button type="submit" ><?php _e("Enregistrer", 'bender'); ?></button>
                        </div>
                    </div>
                </form>

Normally it will add the following fields inside the user registration form.

1)User Email

2)User Address

3)User Website Address

4)User Fax

5)Users country

We can remove the unwanted fields from the plugins form.php file.

How to write a cron function in osclass.

Cron job is a inbuilt functionality in osclass script. We don't have to set our own cron function in osclass. In osclass there are THREE types of cron functions available. That are given below.

1. Hourly Cron

2. Daily Cron

3.Weekly Cron

Hourly cron will be called for each hour and will execute the function every hour. Other type of crons also will work in the same way.

How to set up a cron funtion.
Create a function inside your theme folder's function.php file.

Example:
function callCronJobHourly(){

    Do something ...

}
Add this hook after the function.
osc_add_hook('cron_hourly', 'callCronJobHourly');

This is the hook function to call this function when executing hourly cron function in osclass.This means the function callCronJobHourly() will be executed hourly once inside the script. So we can have update and delete queris for expired items inside this function , it will be checked hourly and perfom the function.

If you want to run it once per day then replace the 'cron_hourly' to 'cron_daily' in the above hook. Same way will be followed for weekly cron.



Tuesday 27 January 2015

How to list items only from specific country in osclass main page listing.

Here i have given you a way to list the items only from specific country in osclass. Normally the osclass script will list all items from all country in the main page listing, But in some cases user need to list only from one country. Given below code is used to list only from one country from the database in the osclass script.

Replace in main.php(inside your current theme folder):

Replace this code: 

     <?php if( osc_count_latest_items() == 0) { ?>

With this code     :

      <?php if( osc_count_latest_items(null, array('sCountry' => 'XX')) == 0) { ?>

Change "XX" to your country code.(its fk_c_country_code field in the table oc_t_item_location in the osclass database).

Tuesday 28 October 2014

How to exclude items by user id in osclass.

In this post i have explained you how to exclude the items in main page listing by user id in osclass.
By using this function you can exclude the items posted by a user in main page listing or in any page listing.

Usually we will use the function osc_query_item in osclass to exclude the items.But in this case its not usefull to use the osc_query_item function to exclude the item using user id.We can only do this by the use of the functions . Follow the procedures to use the function.

Add this at the bottom of the functions.php file inside your theme folder.

<?php function cust_query_item($params = null) {
 $mSearch = new Search(); if($params==null) { $params = array(); }
else if(is_string($params)){
      $keyvalue = explode("=", $params); $params = array($keyvalue[0] => $keyvalue[1]);
}
 foreach($params as $key => $value) {
   switch($key) {
      case 'id': $mSearch->addItemId($value); break;
      case 'author': $tmp = explode(",", $value);
         foreach($tmp as $t) { $mSearch->fromUser($t); }
         break;
     case 'category':
     case 'category_name': $tmp = explode(",", $value);
          foreach($tmp as $t) { $mSearch->addCategory($t); }
         break;
   case 'country':
   case 'country_name': $tmp = explode(",", $value);
         foreach($tmp as $t) { $mSearch->addCountry($t); } break;
   case 'region':
   case 'region_name': $tmp = explode(",", $value);
        foreach($tmp as $t) { $mSearch->addRegion($t); }
        break;
   case 'city':
   case 'city_name': $tmp = explode(",", $value);
        foreach($tmp as $t) { $mSearch->addCity($t); }
        break;
   case 'city_area':
   case 'city_area_name': $tmp = explode(",", $value);
        foreach($tmp as $t) { $mSearch->addCityArea($t); }
        break;
  case 'results_per_page':
       $mSearch->set_rpp($value);
       break;
  case 'premium': $mSearch->onlyPremium(($value==1?true:false));
      break;
 case 'page': $mSearch->page($value);
      break;
 case 'offset': $mSearch->limit($value);
      break;
 case 'excluded_author':
       $mSearch->addConditions(sprintf("%st_item.fk_i_user_id NOT IN (%s)", DB_TABLE_PREFIX, implode(',', $value))); break; case 'order': $mSearch->order($value, '');
        break;
 default: osc_run_hook('custom_query', $mSearch, $key, $value); break;
   }
 }
View::newInstance()->_exportVariableToView("customItems", $mSearch->doSearch());
 }?>

Now, this is the same code as core function osc_query_item, but I've added two more customizable cases, "excluded_author" (for our needs) and "order" so you might get a truly randomized list. 

 Then you call this new function like this:
 
<?php
cust_query_item(array("premium"=>1, "results_per_page" => 495, "order"=> 'RAND()', 'excluded_author' => array(XX,YY,ZZ)));
?>
You can change the result per page as your wish. And you can edit the function as your need.

Monday 27 October 2014

How to insert a script file in osclass admin.

The enqueue functions are used for loading your javascript and css files in osclass admin.The reason for using enqueue functions is becuse many plugins are using javascript frameworks such as JQuery, JQuery-ui, and fancybox just to name a few. There is a chance that these javascript files could be loaded multiple times and that is why the enqueue functions are used. The enqueue functions help to reduce the chances of the same file getting loaded more than once in osclass. 

Here, I have explained with examples below about how to insert a script file in osclass admin when we creating a plugin.
Registering a javascript file
osc_register_script('jqueryPopup', osc_base_url() . 'oc-content/plugins/popup_for_osclass/js/jCarouselPopup.js', 'jquery');
Enqueueing the script
osc_enqueue_script('jqueryPopup');
Enqueueing a style
osc_enqueue_style('popuplCss', osc_base_url() . 'oc-content/plugins/popup_for_osclass/css/popup.css');
You may have noticed that i did not register the style and that is because it is not required and there is no function to do so.Real life example,for inserting a script file in osclass admin.Ok now let us move to a real life example. To use these functions you have to create a function for this example I am going to use examle_load_scripts() please use a unique function name in your plugin if you are planning on releasing it otherwise we could end up with conflicting function names.

function examle_load_scripts() {
     osc_register_script('jqueryPopup', osc_base_url() . 'oc-content/plugins/popup_for_osclass/js/jCarouselPopup.js', 'jquery');
     osc_enqueue_script('jqueryPopup');
     osc_enqueue_style('carouselCss', osc_base_url() . 'oc-content/plugins/popup_for_osclass/css/popup.css');
 }
Once you add that code you will then need to add the following hook to your index.php file of your plugin. 

osc_add_hook('init', 'examle_load_scripts');
To load the script on the admin side you would use this hook

osc_add_hook('init_admin', 'examle_load_scripts');
This is the way of inserting a script or a css file into osclass admin.

Sunday 31 August 2014

How to write a custom query in osclass to fetch results from database.

Here in this tutorials, we have explained you about how to write the custom query in osclass.In osclass classified script, it is easy to write a custom query to fetch some result from the database or insert or update some fields into the database table. 

We can use some predefined functions to print some fields from osclass database. But the predefined functions in osclass are limited, so we can't get all field's data from osclass database by the predefined functions.  Another one important thing in osclass , there is no way to update or insert any fields using any predefined functions .

 For that we need to write a custom query and execute it in osclass. This post will be very much usefull to the osclass users those who customising the functionality to their needs in osclass. If we want to use the custom queries in osclass , we need to have it as a seperate function inside theme funtions.php  file. The main reason for keeping it as a seperate function is, to avoid the repetation of the code.

 Example custom query for selecting the post count for a user in osclass is given below. Paste this function at the bottom of the functions.php file inside the theme folder.Make sure , not to leave any space after the function.
For Select
if( !function_exists('logged_user_post_count') ){
    function logged_user_post_count($userId) {
        $conn = getConnection();
        $item_count = $conn->osc_dbFetchResults("SELECT count(*) FROM %st_item WHERE fk_i_user_id='%d' AND b_active='1'", DB_TABLE_PREFIX, $userId);
        return $item_count[0]['count(*)'];
     }
 }


You can call the fucntion by passing user id to the function as parameter. Here $conn = getConnection(); is the connections string to establish the connection to the osclass database to execute the query.
$conn = getConnection();
This function is only used to select the fields from database using custom Query in osclass.
$conn->osc_dbFetchResults();
Example custom query for Inserting the a value to the database in osclass.Paste this function at the bottom of the functions.php file inside the theme folder.Make sure , not to leave any space after the function.
For Insert
 $conn = getConnection();
 $conn->osc_dbExec("INSERT INTO %st_pages (s_internal_name, b_indelible, dt_pub_date) VALUES ('subscription_email', 1,'%s' )", DB_TABLE_PREFIX, date('Y-m-d H:i:s'));

$conn->osc_dbExec();
 
This function is used to execute the custom query in osclass for Insert,update,delete  .The table names which are used in the above examples are osclass table names to understand better for the users. This is the way to write custom query to select , insert, update, delete operations in osclass.

Wednesday 27 August 2014

osclass tutorials for beginners

osclass is an open source script that allows you to create a classifieds site easily without any technical knowledge.

 There are plenty of osclass themes comes with responsive designs ,so the we don't have to worry about the user interface in mobile,tablet views.

The osclass-tutorials.blogspot.in is specially created for the peoples those who is interested in learning osclass classifieds.

The post "osclass tutorials for beginners." is created to give guidelines to the developers and interested peoples.

First of all we need to know what is osclass classifieds scripts and how the structure of the scripts. In this tutorial we are giving guidelines about the given below topics.


 2. Default admin settings in osclass.

 3. Theme customization in osclass.

 4. Functions we should know in osclass.

 These are all the important things for the beginners to work in osclass. Here we are providing every post with a good examples , so that the beginners will easily understand about how to start work in osclass.

 For the time being we have the linked only the first topic(How to install a osclass site in local server or localhost).

We will post the link very soon for the users about the other topics.