------------------------------------------------------------
revno: 894
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Wed 2011-09-07 23:21:22 +0200
message:
  multisite in url
modified:
  src/index.php
  src/libs/aiki.php
  src/libs/site.php
  src/libs/url.php
  src/libs/widgets.php
  src/sql/CreateTables.sql


--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk

Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to 
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'src/index.php'
--- src/index.php	2011-08-20 21:29:58 +0000
+++ src/index.php	2011-09-07 21:21:22 +0000
@@ -62,6 +62,7 @@
 	$nogui = true;
 }
 
+
 /**
  * @todo fix the misspelling
  */

=== modified file 'src/libs/aiki.php'
--- src/libs/aiki.php	2011-08-21 21:17:52 +0000
+++ src/libs/aiki.php	2011-09-07 21:21:22 +0000
@@ -27,6 +27,24 @@
  */
 class aiki
 {
+ 
+    private $pretty_url; // aiki store the pretty_url because some lib, need access / modify this url
+    
+    /**
+     * return pretty url (path of url request)
+     * Example www.foo.com/bar/something bar/something is the pretty url.
+     * @return string 
+     */
+    
+    function pretty_url(){
+        return $this->pretty_url;
+    }
+    
+            
+    public function __construct(){        
+        $this->pretty_url = isset($_GET["pretty"]) ?  $_GET["pretty"] : "" ; 
+    }
+    
 
     /**
      * Loads an aiki library.
@@ -189,15 +207,16 @@
         
         
         // calculate route, including if need, language.
-        if ( count($aiki->site->languages()) > 1 ){
-            $route= $config['url'] . '/' . $aiki->site->language();
+        $prefix = $aiki->site->prefix();
+        if ( count($aiki->site->languages()) > 1 ){                        
+            $route= $config['url']  .  ($prefix ? "/$prefix" : "" ) . '/' . $aiki->site->language();
         } else {
-            $route= $config['url'];
+            $route= $config['url'] . ($prefix ? "/$prefix" : "" ) ;
         }
-        
         $routes= array(
             '[root]'          => $config['url'], 
-            '[root-language]' => $config['url']."/". $aiki->site->language(),
+            '[root-language]' => $config['url'].  "/" . $aiki->site->language(),
+            '[site_prefix]'   => $prefix ,
             '[route]'         => $route );        
 
         if ($config['pretty_urls'] == 0){

=== modified file 'src/libs/site.php'
--- src/libs/site.php	2011-08-20 21:29:58 +0000
+++ src/libs/site.php	2011-09-07 21:21:22 +0000
@@ -30,7 +30,27 @@
     private $languages; // a array like [0]=>'en',[1]=>'fr'...
     private $need_translation;
     private $default_language;
-
+    private $pretty_url;
+    private $site_prefix; // 
+
+
+    /**
+     * return site prefix (beginin with "/" or blank space)
+     * @return string 
+     */      
+
+    function prefix(){
+        return $this->site_prefix;        
+    }
+
+    /**
+     * return the pretty url ( with site path removed )
+     * @return string 
+     */      
+
+    function pretty_url(){
+        return $this->pretty_url;        
+    }
     
      /**
      * return the default language of a site.
@@ -113,6 +133,21 @@
             $config['site'] = 'default';
         }  
         
+        // determine site by url (for multisite and apps)
+        $this->site_prefix = "";                    
+        $this->pretty_url= $aiki->pretty_url();        
+        if ( $this->pretty_url ){
+            $paths = explode("/", str_replace("|", "/", $this->pretty_url));
+            if ( $paths[0] ) {                
+                $site= $db->get_var("SELECT site_shortcut from aiki_sites where site_prefix='{$paths[0]}'" );
+                if ( $site ){
+                    $config['site'] = $site;                    
+                    $this->pretty_url = count($paths)==1 ? "" : substr( $this->pretty_url, strpos($this->pretty_url,"/")+1);
+                    $this->site_prefix = "{$paths[0]}";                    
+                }    
+            }                
+        } 
+        
         // try read site information and test if is_active.
         $info = $db->get_row("SELECT * from aiki_sites where site_shortcut='{$config['site']}' limit 1");
         $error = false;

=== modified file 'src/libs/url.php'
--- src/libs/url.php	2011-08-20 21:29:58 +0000
+++ src/libs/url.php	2011-09-07 21:21:22 +0000
@@ -59,8 +59,8 @@
 		 * So, in homepage (direct index.php)) 'pretty' doesn't exist, 		
 		 * 
 		 */
-		if (isset($_GET["pretty"]) and $_GET["pretty"]) { 
-			$this->pretty=$_GET["pretty"];
+		if ( $aiki->site->pretty_url() ) { 
+			$this->pretty= $aiki->site->pretty_url();
 			$this->url = explode("/", str_replace("|", "/", $this->pretty) );
             
             // check if url begins with a valid language.

=== modified file 'src/libs/widgets.php'
--- src/libs/widgets.php	2011-08-20 21:29:58 +0000
+++ src/libs/widgets.php	2011-09-07 21:21:22 +0000
@@ -113,7 +113,8 @@
 					$unique_widget_exists = true;
 					break;
 				}
-			}							
+			}		
+            					
 		}
 
 		// ..page not found..
@@ -1089,7 +1090,7 @@
 			"SELECT id, display_urls,kill_urls,widget_name ".
 			" FROM aiki_widgets ".
 			" WHERE father_widget=$father AND is_active=1 AND ".
-			" (widget_site='{$aiki->site}' OR widget_site ='aiki_shared' OR widget_site ='default') AND ".
+			" (widget_site='{$aiki->site}' OR widget_site ='aiki_shared') AND ". // default.
 			" (display_urls LIKE '%$search%' OR display_urls = '*' OR display_urls LIKE '%#%#%') AND ".
 			" (kill_urls='' OR kill_urls<> '$search') ".	
 			" ORDER BY  display_order, id";

=== modified file 'src/sql/CreateTables.sql'
--- src/sql/CreateTables.sql	2011-08-20 21:29:58 +0000
+++ src/sql/CreateTables.sql	2011-09-07 21:21:22 +0000
@@ -148,7 +148,9 @@
   site_default_language varchar(5) NOT NULL DEFAULT '',
   site_languages text NOT NULL,
   widget_language varchar(5) NOT NULL,
-  PRIMARY KEY (site_id)
+  site_prefix varchar(80) NOT NULL DEFAULT '',
+  PRIMARY KEY (`site_id`),
+  KEY `site_prefix` (`site_prefix`)
 ) ENGINE=MyISAM CHARSET=utf8;
 
 -- ------------------------------------------------------

_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help   : https://help.launchpad.net/ListHelp

Reply via email to