PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Radovan Janjic   On Page SEO   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: On Page SEO
Adjust page parameters for SEO purposes
Author: By
Last change:
Date: 11 years ago
Size: 4,729 bytes


Class file image Download

// include class
include_once "seo.class.php";
// create object
$seo = new seo ("");

// set vars
// $vars[var_name] = var value
// var names a-zA-Z0-9_ eg. asdf or asd_f9
// var values can be plain text or html
$vars = array();
$vars['id'] = 32;
$vars['cat'] = "Chrome Web Apps";
$vars['title'] = "How To Create Your Own Chrome Web Apps";
$vars['date'] = "21 dec 2012"; // :-)
$vars['author'] = "Radovan Janjic";
$vars['desc'] = "<!-- some comment -->ćčjklč<em>\"Google\"</em> recently launched the <b>Chrome Web Store</b> and I was excited to see a lot of really cool web apps being added to the Web Store everyday. Most of the Web Apps listed are just regular websites packaged to be installable on your Chrome browser, and these apps and extensions can then be synched across computers, so that you always get the same personalized experience in your browser, no matter which computer you use.
We have created some Google Chrome Themes and I wanted to see how to create a Web App. After reading the <strong>Chrome Web Apps</strong> Documentation for a while, I found that the process of making a web app from any existing website is quite easy. As an example, I created a Web App for which is my favorite site for creating Mind Maps.
Using the process described below you can create your own Chrome Web Apps. Lets see how it's done."

// add vars

/* examples

    // page stuf
    $page['title'] = $seo->getPageTitle("[title] |");
    $page['description'] = $seo->getDescription("[date] - [title] - [author] - [desc]");
    $page['canonical'] = $seo->getCanonical();
    // link
    $link['href'] = $seo->getHref("/[cat]/[id]-[title].html");
    $link['title'] = $seo->getTitle("[title]");
    // img
    $img['src'] = $seo->getHref("/images/[img_id]-[title].jpg");
    $img['alt'] = $seo->getAlt("[title]");
    $img['title'] = $seo->getTitle("[title]");
    // db example /////////////////////////////
    include_once "seo.class.php";
    // create object
    $seo = new seo ("");

    mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error());
    $result = mysql_query("SELECT id, title, desc FROM mynews");
    $news = array(array());
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $vars = $row;
        $news[$i][href] = $seo->getHref("/news/[id]-[title].html");
        $news[$i][title] = $seo->getTitle("[title]");
        $news[$i][alt] = $seo->getAlt("[title]");
        // etc.
     // to use seo url u mast have .htaccess in root dir /////////////////////////////////////////////
     // .htaccess example

        RewriteEngine On
      # redirect non-www to www
      RewriteCond %{HTTP_HOST} !^www..* [NC]
      RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+..+ [NC]
      RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
      # $seo->getHref("/[cat]/[id]-[title].html")
      # ([0-9]+) => int
      # ([0-9a-zA-Z_-]+) => a-z, A-Z, int, -, _
      RewriteRule ^([0-9a-zA-Z_-]+)/([0-9]+)-([0-9a-zA-Z_-]+).html$ index.php?id=$2
        <title><?php echo $seo->getPageTitle("[title] |"); ?></title>
        <meta name="robots" content="index,follow" />
        <meta name="description" content="<?php echo $seo->getDescription("[date] - [title] - [author] - [desc]"); ?>" />
        <link rel="canonical" href="<?php echo $seo->getCanonical(); ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <h1><?php echo $vars['title']; ?></h1>
            Date: <?php echo $vars['date']; ?> |
            Autor: <a href="<?php echo $seo->getHref("/author/[author]"); ?>" title="<?php echo $seo->getTitle("[author]"); ?>"><?php echo $vars['author']; ?></a> |
            Category: <a href="<?php echo $seo->getHref("/[cat]"); ?>" title="<?php echo $seo->getTitle("[cat]"); ?>"><?php echo $vars['cat']; ?></a>
            <img src="" alt="<?php echo $seo->getAlt("[title]"); ?>" title="<?php echo $seo->getTitle("[title]"); ?>" />
                <?php echo $vars['desc']; ?>

        <a href="<?php echo $seo->getHref("/[cat]/[id]-[title].html"); ?>" title="<?php echo $seo->getTitle("[title]"); ?>"> <?php echo $vars['title'] ?></a>