Sunday, November 18, 2012

My First take on PyroCMS


What is PyroCMS ?

PyroCMS is a open source framework for content management system created with standard PHP/MVC framework CodeIgniter. It is light and simple to use and is for both the developers and the end users. Generally it is used for websites which contains large amount of content/articles. The content should be well presented to the user for displaying as per requirement . This is where pyrocms comes which can manage the display of those content as per requirement.


How PyroCMS can be customized to develop websites on it ?

PyroCMS provide the dashboard for administration section to be used for developing big content based websites easily.
As it provides various tools/modules for implementing the website design and functionality which are very necessary for the a perfect websites.

Modules such as:

Navigation: It is used for the navigate through out website links.
Blog: This is used for the articles to be posted like blogs, also they can be well surfed by the end users.
Comment: Users and guests can write comments for content published and share their views.
Pages: Add pages to the site with content that are mostly static or vary in time.There are many other modules that can used


Why PyroCMS is better than Wordpress, Drupal and other existing CMSes ?

All of the CMSes have not any fixed and standard framework for using it. Therefore it will be difficult for different developers to interact with various created sites. With pyro we are developing a cms with customized outlook and standard framwork which can be very developer friendly.

What can we do with PyroCMS ?

Being small and flexible, PyroCMS can be very usefull to small and to large content based sites.


What are PyroCMS Themes ? 

Themes are the outlook that are presented to users. It contains the design that can be navigated by the users. PyroCMS provides suitable method to develop the themes. PyroCMS contains main layout and the partials files that make up the single website theme.


How to build PyroCMS themes ?

In PyroCMS Theme are structured in different folders like css for stylesheets files, js for javascripts and views for overall structure of the website. In views folder the main design is kept inside layouts which is the central look . The designs are splitted within the folder called partials which contains the design units like header, footer, sidebar etc.  Also necessary information about the theme and the screenshot is also included for informations.


Lastly, using Pyrocms was very fun to use. It is more similar to CodeIgniter therefore people comfortable with codeIgniter may find it very easy to use. Also it is very useful for customizing our desired look and functionality. Also we should use it very calmly. Despite of few documentations and support i am sure user/develop would find it very handy. 
 

Monday, November 12, 2012

Android asynchronous/synchronous HTTP request

 

////////////////////////OBHttpClient.java /////////////////

package com.semicolondev.baghchal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.os.Handler;
import android.util.Log;

public class OBHttpClient {
    /** The time it takes for our client to timeout */
    public static final int HTTP_TIMEOUT = 60 * 1000; // milliseconds

    /** Single instance of our HttpClient */
    private HttpClient mHttpClient;
    /** Asynchronous request handler */
    private Handler mHandler;
    public static int METHOD_GET = 1;
    public static int METHOD_POST = 2;
    /**
     * Get our single instance of our HttpClient object.
     *
     * @return an HttpClient object with connection parameters set
     */
    private HttpClient getHttpClient() {
        if (mHttpClient == null) {
            mHttpClient = new DefaultHttpClient();
            final HttpParams params = mHttpClient.getParams();
            HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
            HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
            ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
        }
        return mHttpClient;
    }

    /**
     * Performs an HTTP synchronous request to the specified url with the
     * specified parameters of get or post.
     * @param method GET or POST method
     * @param url The web address to post the request to
     * @param postParameters The parameters to send via the request for POST request – null for GET request
     * @return The result of the request as a string
     * @throws Exception
     */
    public String OBrequestHttp(int method, String url, ArrayList<NameValuePair> postParameters) throws Exception {
        BufferedReader in = null;
        try {
            HttpClient client = getHttpClient();
            if(method == METHOD_GET){
                HttpGet request = new HttpGet();
                request.setURI(new URI(url));
                HttpResponse response = client.execute(request);
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            }
            else if(method == METHOD_POST){
                HttpPost postrequest = new HttpPost(url);
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
                postrequest.setEntity(formEntity);
                HttpResponse postresponse = client.execute(postrequest);
                in = new BufferedReader(new InputStreamReader(postresponse.getEntity().getContent()));
            }
            else{
                return "INVALID METHOD";
            }
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) {
                sb.append(line + NL);
            }
            in.close();

            String result = sb.toString();
            //Log.d("Login Response", result);
            return result;
        } catch(Exception e){
            return "REQUEST ERROR";
        }
            finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

/**
     * Performs an HTTP asynchronous request to the specified url with the
     * specified parameters of get or post.
     * @param method GET or POST method
     * @param url The web address to post the request to
     * @param postParameters The parameters to send via the request for POST request – null for GET request
     * @type which url the request has suggested

     * @obaction result send back to the activity

    * @return The result of the request as a string
     * @throws Exception


     */


    public void OBrequestAsyncHttp(final int method, final String urls,final OnlineGameView.url_enumb type,final ArrayList<NameValuePair> formParams,final OBActionResult obaction) {
        if (mHandler == null){
            mHandler = new Handler();
        }
        //Log.i("OB","Thread started for url = " + urls);
        new Thread(new Runnable() {
            public void run() {
                final String restResponse;
                restResponse = requestposturl(method, urls, formParams);
                mHandler.post(new Runnable() {
                    public void run() {
                        obaction.completedWithResult(type, restResponse);
                        //Log.i("OB","Result sent");
                    }
                });
            }

            private String requestposturl(int method, String urls, ArrayList<NameValuePair> formParams) {
                try{
                    //Log.i("OB","Url = " + urls);
                    String response = OBrequestHttp(method,urls, formParams);
                    return response;
                }
                catch(Exception e){Log.i("OB","Something error");return "";}
            }
        }).start();
}
}

 

///////////////OOActionResult.java ///////////////////

package com.semicolondev.baghchal;

public interface OBActionResult {
    public void completedWithResult(String type, String response);   
}

 

////////////////////////mainActivity.java/////////////

public class mainActivity extends Activity implements OBActionResult{

//the request should be done by

OBHttpClient obclient = new OBHttpClient();
        obclient.OBrequestAsyncHttp(OBHttpClient.METHOD_GET, “http://localhost/query”, “login”, null, this);

// and the result will be collected in

@Override
    public void completedWithResult(String urlfrom, String response) {
        Log.i("OB","url = "+urlfrom+" data = " + response);

}

}

Wednesday, November 7, 2012

Android Simple Login Dialogue Box

package com.semicolondev.baghchal;

import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public abstract class test extends Activity
{

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.login, null);
final EditText userText = (EditText) textEntryView.findViewById(R.id.login_userID);
final EditText passText = (EditText) textEntryView.findViewById(R.id.login_password);
AlertDialog.Builder builder = new AlertDialog.Builder(this);  
AlertDialog alert;
builder.setMessage("Enter Username and Password")
.setCancelable(true)
.setView(textEntryView)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Log.i("OB","Logging in ..");
try{
String url = "http://192.168.1.16/api/login?userID="+userText.getText().toString().trim()+"&password="+passText.getText().toString().trim();
Log.i("OB","url= "+url);
String response = OBHttpClient.executeHttpGet(url);
Log.i("OB","Response="+response);              // if valid login response ={"res":"success"}
JSONObject resObj = new JSONObject(response);
String resServer = resObj.getString("res");
if(resServer.equals("success")){
Toast.makeText(this,"Login Success", Toast.LENGTH_LONG).show();
Log.i("OB","Success");
}
else{
Toast.makeText(this,"Login Failed", Toast.LENGTH_LONG).show();
Log.i("OB","Invalid");
}
}catch(Exception e){Toast.makeText(this,"Sorry", Toast.LENGTH_LONG).show();}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {                                                 
}
});
alert = builder.create();
alert.show();

}
}

.... login.xml ....
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip">
<!--  Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Username"/>
<EditText android:id="@+id/login_userID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="20dip"
android:singleLine="true"/>
<!--  Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372c24"
android:text="Password"/>
<EditText android:id="@+id/login_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:password="true"/>
</LinearLayout>

Tuesday, November 6, 2012

Android HttpClient- Parse JSON


JSON from server:

{"res":"success","click":{"value":[0,2,1,1,1,1,0,2,1,1,1,1,1,0,5,2,1,1,0,0,1,1,1,1,7],"gameID":"5098fac4c96d664f690079d2","turn":"winBagh","goat_count":20,"dead_goat":5,"timestamp":"1352203321097","_id":"5098fc39c96d664f69007a41"}}

try{
postParameters= new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("gameID", online_gameID));
String response = OBHttpClient.executeHttpPost("http://192.168.135.136/json", postParameters);

JSONObject resObj = new JSONObject(response);
Log.i("OB","resObj = " + resObj  );
String resServer = resObj.getString("res");
Log.i("OB","resServer = " + resServer  );

if(resServer.equals("error")){
Toast.makeText(ctx,"Wait for other user move", Toast.LENGTH_LONG).show();
    return false;
}
else{

JSONObject clickObj = resObj.getJSONObject("click");
Log.i("OB","clickObj = " + clickObj  );
String value = clickObj.getString("value").replace("[", "").replace("]", "");
String[] coord = value.split(",");
int[] orgval = new int[25];
for(int i=0; i<25 ; i++)
orgval[i] = Integer.parseInt(coord[i]);
//click.setGameValue(orgval);
click.setClicks(orgval, ((clickObj.getString("turn") == "goat")? 1 : 2), clickObj.getInt("dead_goat"), clickObj.getInt("goat_count"));//, clickObj.getString("timestamp"), clickObj.getString("gameID"));
return true;

}
}
catch(Exception e){
    Toast.makeText(ctx,"Error", Toast.LENGTH_LONG).show();
}

 

© 2013 Echo "Semicolon Developers"; Kathmandu. All rights resevered @ Semicolon Developers Network Pvt. Ltd.. Designed by Templateism

Back To Top