]> git.andy128k.dev Git - ipf.git/commitdiff
more autoloading
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 22 Jun 2013 13:22:07 +0000 (16:22 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 22 Jun 2013 13:22:07 +0000 (16:22 +0300)
ipf/admin/app.php
ipf/admin/model.php
ipf/admin/models/AdminLog.php
ipf/admin/views.php
ipf/http/url.php
ipf/template/tag/url.php

index 4e4d786a8993c5f24cb49663f6e1be12e20e34a1..eaa4769ec5cb385b685450ce39d54eb65f176489 100644 (file)
@@ -37,7 +37,7 @@ class IPF_Admin_App extends IPF_Application
         if ($ok)
             return true;
         else
-            return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
+            return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView('IPF_Admin_Views_Login'));
     }
 
     static function GetAppModelFromSlugs($lapp, $lmodel)
index e063a31b4902a1828c1f980e0b1690e514377db1..3e353bcd6f05459cbe464c953363e32b9dfd1c35 100644 (file)
@@ -544,7 +544,7 @@ class IPF_Admin_Model
                 $this->_afterAdd($item);
                 $url = @$request->POST['ipf_referrer'];
                 if ($url=='')
-                    $url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
+                    $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
                 return new IPF_HTTP_Response_Redirect($url);
             }
         }
@@ -585,7 +585,7 @@ class IPF_Admin_Model
             $o->delete();
             $url = @$request->POST['ipf_referrer'];
             if ($url=='')
-                $url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
+                $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
             return new IPF_HTTP_Response_Redirect($url);
         }
         $context = array(
@@ -627,7 +627,7 @@ class IPF_Admin_Model
                 $this->_afterEdit($item);
                 $url = @$request->POST['ipf_referrer'];
                 if ($url=='')
-                    $url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
+                    $url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel));
                 return new IPF_HTTP_Response_Redirect($url);
             }
         }
index 85d9acc2f7aeebdb669dd2a57c899613319bcc66..04aa978b49cf3d80e4dd5c75a6a5f428ec469b94 100644 (file)
@@ -6,7 +6,8 @@ class AdminLog extends BaseAdminLog
     const CHANGE    = 2;
     const DELETION  = 3;
 
-    public static function logAction($request, $object, $action_flag, $message=''){
+    public static function logAction($request, $object, $action_flag, $message='')
+    {
         $log = new AdminLog();
         $log->username = $request->user->username;
         $log->user_id = $request->user->id;
@@ -18,27 +19,30 @@ class AdminLog extends BaseAdminLog
         $log->save();
     }
 
-    public function is_addition(){
+    public function is_addition()
+    {
         if ($this->action_flag==AdminLog::ADDITION)
             return true;
         return false;
     }
 
-    public function is_change(){
+    public function is_change()
+    {
         if ($this->action_flag==AdminLog::CHANGE)
             return true;
         return false;
     }
 
-    public function is_deletion(){
+    public function is_deletion()
+    {
         if ($this->action_flag==AdminLog::DELETION)
             return true;
         return false;
     }
 
-    public function GetAdminUrl(){
-        return IPF_HTTP_URL_urlForView('IPF_Admin_Views_Index').IPF_Utils::appLabelByModel($this->object_class).'/'.strtolower($this->object_class).'/'.$this->object_id.'/';
+    public function GetAdminUrl()
+    {
+        return IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index').IPF_Utils::appLabelByModel($this->object_class).'/'.strtolower($this->object_class).'/'.$this->object_id.'/';
     }
-
 }
 
index 85a0e1aae2df641e9b89c4cc01450481820cec07..b451d0614893b85b682daca9a4faeae4213a6f22 100644 (file)
@@ -251,7 +251,7 @@ function IPF_Admin_Views_ChangePassword($request, $match)
                     $user->setPassword($form->cleaned_data['password1']);
                     $user->save();
                    
-                    return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel)));
+                    return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL::urlForView('IPF_Admin_Views_ListItems', array($lapp, $lmodel)));
                 }
             }
             else $form = new IPF_Auth_Forms_ChangePassword();
@@ -282,7 +282,7 @@ function IPF_Admin_Views_Login($request, $match)
     if (!empty($request->REQUEST['next']))
         $success_url = $request->REQUEST['next'];
     if (trim($success_url)=='')
-        $success_url = IPF_HTTP_URL_urlForView('IPF_Admin_Views_Index');
+        $success_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index');
 
     if ($request->method == 'POST') {
         $form = new IPF_Auth_Forms_Login($request->POST);
index d92c442fccbe20a0f9b2ba4e99926f09a4038d57..ea8502608333d6e81c71c4da1bcf701d03709678 100644 (file)
@@ -32,65 +32,66 @@ class IPF_HTTP_URL
         }
         return '/';
     }
-}
 
-function IPF_HTTP_URL_urlForView($view, $params=array(), $by_name=false, 
-                                  $get_params=array(), $encoded=true)
-{
-    $action = IPF_HTTP_URL_reverse($view, $params, $by_name);
-    return IPF_HTTP_URL::generate($action, $get_params, $encoded);
-}
+    public static function urlForView($view, $params=array(), $by_name=false,
+                                      $get_params=array(), $encoded=true)
+    {
+        $action = self::reverse($view, $params, $by_name);
+        return self::generate($action, $get_params, $encoded);
+    }
 
-function IPF_HTTP_URL_reverse($view, $params=array(), $by_name=false)
-{
-    $regex = null;
-    
-    foreach (IPF::get('urls') as $url) {
-        $prefix = $url['prefix'];
-        foreach ($url['urls'] as $suburl){
-            if ($suburl['func']==$view){
-                $regex = $prefix.$suburl['regex'];
-                break;
+    public static function reverse($view, $params=array(), $by_name=false)
+    {
+        $regex = null;
+        
+        foreach (IPF::get('urls') as $url) {
+            $prefix = $url['prefix'];
+            foreach ($url['urls'] as $suburl){
+                if ($suburl['func']==$view){
+                    $regex = $prefix.$suburl['regex'];
+                    break;
+                }
             }
+            if ($regex!==null)
+                break;
         }
-        if ($regex!==null)
-            break;
-    }
-    if ($regex === null) {
-        throw new IPF_Exception('Error, the view: '.$view.' has not been found.');
+        if ($regex === null) {
+            throw new IPF_Exception('Error, the view: '.$view.' has not been found.');
+        }
+        $url = self::buildReverseUrl($regex, $params);
+        return IPF::get('app_base').$url;
     }
-    $url = IPF_HTTP_URL_buildReverseUrl($regex, $params);
-    return IPF::get('app_base').$url;
-}
 
-function IPF_HTTP_URL_buildReverseUrl($url_regex, $params=array())
-{
-    $url_regex = str_replace('\\.', '.', $url_regex);
-    $url_regex = str_replace('\\-', '-', $url_regex);
-    $url = $url_regex;
-    $groups = '#\(([^)]+)\)#';
-    $matches = array();
-    preg_match_all($groups, $url_regex, $matches);
-    reset($params);
-    if (count($matches[0]) && count($matches[0]) == count($params)) {
-        // Test the params against the pattern
-        foreach ($matches[0] as $pattern) {
-            $in = current($params);
-            if (0 === preg_match('#'.$pattern.'#', $in)) {
-                throw new IPF_Exception('Error, param: '.$in.' is not matching the pattern: '.$pattern);
+    public static function buildReverseUrl($url_regex, $params=array())
+    {
+        $url_regex = str_replace('\\.', '.', $url_regex);
+        $url_regex = str_replace('\\-', '-', $url_regex);
+        $url = $url_regex;
+        $groups = '#\(([^)]+)\)#';
+        $matches = array();
+        preg_match_all($groups, $url_regex, $matches);
+        reset($params);
+        if (count($matches[0]) && count($matches[0]) == count($params)) {
+            // Test the params against the pattern
+            foreach ($matches[0] as $pattern) {
+                $in = current($params);
+                if (0 === preg_match('#'.$pattern.'#', $in)) {
+                    throw new IPF_Exception('Error, param: '.$in.' is not matching the pattern: '.$pattern);
+                }
+                next($params);
             }
-            next($params);
+            $func = create_function('$matches', 
+                                    'static $p = '.var_export($params, true).'; '.
+                                    '$a = current($p); '.
+                                    'next($p); '.
+                                    'return $a;');
+            $url = preg_replace_callback($groups, $func, $url_regex);
         }
-        $func = create_function('$matches', 
-                                'static $p = '.var_export($params, true).'; '.
-                                '$a = current($p); '.
-                                'next($p); '.
-                                'return $a;');
-        $url = preg_replace_callback($groups, $func, $url_regex);
-    }
-    $url = substr(substr($url, 2), 0, -2);
-    if (substr($url, -1) !== '$') {
-        return $url;
+        $url = substr(substr($url, 2), 0, -2);
+        if (substr($url, -1) !== '$') {
+            return $url;
+        }
+        return substr($url, 0, -1);
     }
-    return substr($url, 0, -1);
 }
+
index 1f75995f818ed70db88f08cad17f5061e65ab17d..2a3bb558f0d29ef194ebef6f95da1d4be866b72f 100644 (file)
@@ -1,11 +1,10 @@
 <?php
 
-IPF::loadFunction('IPF_HTTP_URL_urlForView');
-
 class IPF_Template_Tag_Url extends IPF_Template_Tag
 {
     function start($view, $params=array(), $by_name=false, $get_params=array())
     {
-        echo IPF_HTTP_URL_urlForView($view, $params, $by_name, $get_params);
+        echo IPF_HTTP_URL::urlForView($view, $params, $by_name, $get_params);
     }
 }
+