Wednesday, December 19, 2012

YII framework dynamic Table Model


/**
 * CActiveRecord implementation that allows specifying
 * DB table name instead of creating a class for each table.
 *
 * Usage (assuming table 'user' with columns 'id' and 'name'):
 *
 * $userModel = DynamicActiveRecord::forTable('user');
 * //list existing users
 * foreach ($userModel->findAll() as $user)
 * echo $user->id . ': ' . $user->name . '
';
 * //add new user
 * $userModel->name = 'Pavle Predic';
 * $userModel->save();
 *
 * @author Pavle Predic
 */
class DynamicActiveRecord extends CActiveRecord
{
/**
* Name of the DB table
* @var string
*/
protected $_tableName;

/**
* Table meta-data.
* Must redeclare, as parent::_md is private
* @var CActiveRecordMetaData
*/
protected $_md;

/**
* Constructor
* @param string $scenario (defaults to 'insert')
* @param string $tableName
*/
public function __construct($scenario = 'insert', $tableName = null)
{
$this->_tableName = $tableName;
parent::__construct($scenario);
}

/**
* Overrides default instantiation logic.
* Instantiates AR class by providing table name
* @see CActiveRecord::instantiate()
* @return DynamicActiveRecord
*/
protected function instantiate($attributes)
{
return new DynamicActiveRecord(null, $this->tableName());
}

/**
* Returns meta-data for this DB table
* @see CActiveRecord::getMetaData()
* @return CActiveRecordMetaData
*/
public function getMetaData()
{
if ($this->_md !== null)
return $this->_md;
else
return $this->_md = new CActiveRecordMetaData($this);
}

/**
* Returns table name
* @see CActiveRecord::tableName()
* @return string
*/
public function tableName()
{
if (!$this->_tableName)
$this->_tableName = parent::tableName();
return $this->_tableName;
}

/**
* Returns an instance of DynamicActiveRecord for the provided DB table.
* This is a helper method that may be used instead of constructor.
* @param string $tableName
* @param string $scenario
* @return DynamicActiveRecord
*/
public static function forTable($tableName, $scenario = 'insert')
{
return new DynamicActiveRecord($scenario, $tableName);
}
}

Thursday, December 6, 2012

YII Framework - Highcharts Extension - datetime issue Resolved


$this->Widget('ext.highcharts.HighchartsWidget', array(
   'options'=>'{
      "title": { "text": "MYSQL Replication" },
      "xAxis": {
      "title": { "text": "Month" },
"type": "datetime",
            "dateTimeLabelFormats": {
                "day": "%e"  
            }
      },
      "yAxis": {
         "title": { "text": "Time" },
"type": "datetime",
        "dateTimeLabelFormats": {
                "hour": "%H"
            }
      },
      "tooltip": {
            "xDateFormat": "%Y-%m-%d"
        },      
      "series": [
{ "name": "success", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms},
         { "name": "failure", "data": [[x_ms,y_ms],[x_ms,y_ms]],"pointStart": utc_ms, "pointInterval": date_ms}
      ]
   }'
));

<script src="http://code.highcharts.com/highcharts.js"></script>

Tuesday, December 4, 2012

SoapUI for ubuntu

http://askubuntu.com/questions/198896/what-is-a-simple-free-soap-client-gui


You can still use SOAPUI
download the script from here and save it on the disk.
then from a terminal
cd /path-to-directory-where-you-downlaod-it
sudo chmod +x soapUI-x32-4_0_0.sh
sudo ./soapUI-x32-4_0_0.sh

Monday, November 5, 2012

Install and configure OAuth in Ubuntu

http://djpate.com/2010/10/07/how-to-install-oauth-support-for-php-on-ubuntu/



First of all you need to make sure you already have php-pear and php5-dev.
If you are unsure just run
1sudo apt-get install php-pear php5-dev make
now run
1sudo pecl install oauth
Personnaly I had an error while compiling
1/usr/include/php5/ext/pcre/php_pcre.h:29: fatal error: pcre.h:
To fix that just install : libpcre3-dev
1sudo apt-get install libpcre3-dev
Once it’s done just add extension=oauth.so at the end of your php.ini (located in /etc/php5/apache2/php.ini) file and restart Apache.

Wednesday, September 26, 2012

Drupal Blog Page Not Found

If you have the problem of not being able to see the Blog Module page after enabling it, and you are using Clean URL for your site, then it's *probably* because you have accidentally created a subdomain with the name 'blog' (e.g. http://blog.example.com), or you have a subdirectory named 'blog' on your website's root folder (www, htdocs or public_html). You should be able to see Drupal's Blog Module after you remove the subdomain / subdirectory with that same name.

The reason you cannot view the Blog Module at your website's URL (e.g. http://www.example.com/blog) when you have a subdomain / subdirectory with the same name is because when using Clean URL, Drupal rewrites the Blog Module address (http://www.example.com/?q=blog to http://www.example.com/blog) using .htaccess file. This causes confusion on the webserver, because when we try to access http://www.example.com/blog, it doesn't know which URL it is suppose to display. It could be the URL that Drupal has rewritten, or it could also be the subdirectory that you have in your web root folder.

The same concept also apply with all the URL Aliases that you have created with your Drupal. Make sure you don't have a folder with the same name as your aliases, or else you will get a Page Not Found error.



Thursday, September 6, 2012

Wordpress - Exclude images from showing in the_content() - Resolved

<?php
   ob_start();
   the_content('Read the full post',true);
   $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
   ob_end_clean();
   echo $postOutput;
?>

Ref. Link: http://wordpress.org/support/topic/exclude-images-from-showing-in-the_content

Wednesday, September 5, 2012

XML Sitemap generation with php and mysql


<?php
$host = "localhost"; // host name
$user = "user"; // database user name
$pass = "password"; // database password
$database = "dbname"; // database name
// connecting to database
$connect = @mysql_connect($host,$user,$pass)or die (@mysql_error());
// selecting database
@mysql_select_db($database,$connect) or die (@mysql_error());

// default header(don't delete)
header("Content-Type: text/xml;charset=iso-8859-1");
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// mytable = your content table name
$query = @mysql_query("SELECT * FROM mytable");
while($row = @mysql_fetch_array($query)){
// [url] = content url
$url = $row['url'];
// [time] = content date
$date = date("Y-m-d", $row['time']);

// NO CHANGES BELOW
echo
    '<url>
     <loc>' . $url .'</loc>
     <lastmod>'. $date .'</lastmod>
     <changefreq>daily</changefreq>
     <priority>0.8</priority>
     </url>
    ';
}
echo '</urlset>';?>



.htaccess code ( Optional )


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
</IfModule>