Example #1
0
 function &recognize($Map = null)
 {
     AK_ENVIRONMENT != 'setup' ? $this->_connectToDatabase() : null;
     $this->_startSession();
     $this->_enableInternationalizationSupport();
     $this->_mapRoutes($Map);
     $params = $this->getParams();
     $module_path = $module_class_peffix = '';
     if (!empty($params['module'])) {
         $module_path = trim(str_replace(array('/', '\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS) . DS;
         $module_shared_model = AK_CONTROLLERS_DIR . DS . trim($module_path, DS) . '_controller.php';
         $module_class_peffix = str_replace(' ', '_', AkInflector::titleize(str_replace(DS, ' ', trim($module_path, DS)))) . '_';
     }
     $controller_file_name = AkInflector::underscore($params['controller']) . '_controller.php';
     $controller_class_name = $module_class_peffix . AkInflector::camelize($params['controller']) . 'Controller';
     $controller_path = AK_CONTROLLERS_DIR . DS . $module_path . $controller_file_name;
     include_once AK_APP_DIR . DS . 'application_controller.php';
     if (!empty($module_path) && file_exists($module_shared_model)) {
         include_once $module_shared_model;
     }
     if (!is_file($controller_path) || !(include_once $controller_path)) {
         defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller ' . $controller_path . ' not found.');
         if (AK_ENVIRONMENT == 'development') {
             trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for ' . 'the controller %controller_class_name', array('%controller_file_name' => $controller_file_name, '%controller_class_name' => $controller_class_name)), E_USER_ERROR);
         } elseif (@(include AK_PUBLIC_DIR . DS . '404.php')) {
             $response = new AkTestResponse();
             $response->addHeader('Status', 404);
             return false;
             //exit;
         } else {
             //header("HTTP/1.1 404 Not Found");
             $response = new AkResponse();
             $response->addHeader('Status', 404);
             return false;
             //die('404 Not found');
         }
     }
     if (!class_exists($controller_class_name)) {
         defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->error('Controller ' . $controller_path . ' does not implement ' . $controller_class_name . ' class.');
         if (AK_ENVIRONMENT == 'development') {
             trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist', array('%controller_name' => $controller_class_name)), E_USER_ERROR);
         } elseif (@(include AK_PUBLIC_DIR . DS . '405.php')) {
             exit;
         } else {
             $response = new AkResponse();
             $response->addHeader('Status', 405);
             return false;
             //header("HTTP/1.1 405 Method Not Allowed");
             //die('405 Method Not Allowed');
         }
     }
     $Controller =& new $controller_class_name(array('controller' => true));
     $Controller->_module_path = $module_path;
     isset($_SESSION) ? $Controller->session =& $_SESSION : null;
     return $Controller;
 }
Example #2
0
    function populateTables()
    {
        $args = func_get_args();
        $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
        foreach ($tables as $table){
            $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
            if(!file_exists($file)){
                continue;
            }
            $class_name = AkInflector::modulize($table);
            if($this->instantiateModel($class_name)){
                $items = Ak::convert('yaml','array',file_get_contents($file));
                foreach ($items as $item){
                    $this->{$class_name}->create($item);
                }
            }

        }
    }
Example #3
0
 protected function _getImagePath($path)
 {
     $tmp_dir = AkConfig::getDir('tmp');
     if (preg_match('/^http(s)?:\\/\\//', $path)) {
         $path_info = pathinfo($path);
         $base_file_name = Ak::sanitize_include($path_info['basename'], 'paranaoid');
         if (empty($path_info['extension'])) {
             // no extension, we don't do magic stuff
             $path = '';
         } else {
             $local_path = $tmp_dir . DS . 'mailer' . DS . 'remote_images' . DS . md5($path) . DS . $base_file_name . '.' . $path_info['extension'];
             if (!file_exists($local_path) || time() > filemtime($local_path) + 7200) {
                 if (!AkFileSystem::file_put_contents($local_path, Ak::url_get_contents($path), array('base_path' => $tmp_dir))) {
                     return '';
                 }
             }
             if (!file_exists($local_path) || filesize($local_path) < 1) {
                 return '';
             }
             return $local_path;
         }
     }
     $org_path = $path;
     $public_dir = AkConfig::getDir('public');
     $path = $public_dir . $path;
     $path = realpath($path);
     if (substr($path, 0, strlen($public_dir)) != $public_dir || !file_exists($path)) {
         $path = '';
     }
     return $path;
 }
Example #4
0
 static function setDictionary($dictionary, $language, $namespace = false, $comment = null)
 {
     $path = AkConfig::getDir('app') . DS . 'locales' . DS . ($namespace ? trim(Ak::sanitize_include($namespace, 'high'), DS) . DS : '') . basename($language) . '.php';
     AkLocaleManager::getDictionary($language, $namespace, true, $dictionary);
     AkFileSystem::file_put_contents($path, "<?php\n/** {$comment} */\n\n\$dictionary=" . var_export((array) $dictionary, true) . ";\n");
     return $path;
 }
Example #5
0
 /**
  * Gets a plugin base path.) ...
  * 
  * @param  string $plugin_name Plugins name
  * @return string Plugin root path
  * @access public 
  */
 function getBasePath($plugin_name)
 {
     return AK_PLUGINS_DIR.DS.Ak::sanitize_include($plugin_name);
 }
Example #6
0
 public function _getImagePath($path)
 {
     if (preg_match('/^http(s)?:\\/\\//', $path)) {
         $path_info = pathinfo($path);
         $base_file_name = Ak::sanitize_include($path_info['basename'], 'paranaoid');
         if (empty($path_info['extension'])) {
             // no extension, we don't do magic stuff
             $path = '';
         } else {
             $local_path = AK_TMP_DIR . DS . 'mailer' . DS . 'remote_images' . DS . md5($path) . DS . $base_file_name . '.' . $path_info['extension'];
             if (!file_exists($local_path) || time() > @filemtime($local_path) + 7200) {
                 if (!Ak::file_put_contents($local_path, Ak::url_get_contents($path))) {
                     return '';
                 }
             }
             if (@filesize($local_path) < 1) {
                 return '';
             }
             return $local_path;
         }
     }
     $org_path = $path;
     $path = AK_PUBLIC_DIR . $path;
     $path = realpath($path);
     if (substr($path, 0, strlen(AK_PUBLIC_DIR)) != AK_PUBLIC_DIR || !file_exists($path)) {
         $path = '';
     }
     return $path;
 }
Example #7
0
 function _generateConfigFileName($namespace, $environment = AK_ENVIRONMENT)
 {
     $namespace = Ak::sanitize_include($namespace, 'high');
     $yaml_file_name = AK_CONFIG_DIR . DS . $namespace . '.yml';
     return $yaml_file_name;
 }
Example #8
0
    function _getImagePath($path)
    {
        if(preg_match('/^http(s)?:\/\//', $path)){
            $path_info = pathinfo($path);
            $base_file_name = Ak::sanitize_include($path_info['basename'], 'paranaoid');
            if(empty($path_info['extension'])){ // no extension, we don't do magic stuff
                $path = '';
            }else{
                $local_path = AK_TMP_DIR.DS.'mailer'.DS.'remote_images'.DS.md5($base_file_name['dirname']).DS.$base_file_name.'.'.$path_info['extension'];
                if(!file_exists($local_path) || (time() > @filemtime($local_path)+7200)){
                    if(!Ak::file_put_contents($local_path, Ak::url_get_contents($path))){
                        return '';
                    }
                }
                return $local_path;
            }
        }

        $path = AK_PUBLIC_DIR.Ak::sanitize_include($path);

        if(!file_exists($path)){
            $path = '';
        }
        return $path;
    }
Example #9
0
 public function _generateConfigFileName($namespace, $environment = AK_ENVIRONMENT)
 {
     $namespace = Ak::sanitize_include($namespace, 'high');
     $yaml_file_name = AK_TEST_DIR . DS . 'fixtures' . DS . 'config' . DS . $namespace . '.yml';
     return $yaml_file_name;
 }
Example #10
0
 /**
  * Uninstalls an existing plugin
  *
  * Plugins can have an Akelos installer at located at "plugin_name/installer/plugin_name_installer.php"
  * If the installer is available, it will run the "PluginNameInstaller::uninstall()" method, which will trigger
  * all the down_* methods for the installer.
  *
  * @param  string  $plugin_name Plugin name
  * @return void
  * @access public
  */
 public function uninstallPlugin($plugin_name)
 {
     $plugin_name = Ak::sanitize_include($plugin_name, 'high');
     $this->_runInstaller($plugin_name, 'uninstall');
     if (is_dir(AK_PLUGINS_DIR . DS . $plugin_name)) {
         AkFileSystem::directory_delete(AK_PLUGINS_DIR . DS . $plugin_name);
     }
     if ($this->_shouldUseSvnExternals()) {
         $this->_uninstallExternals($plugin_name);
     }
 }
Example #11
0
 private function _getModuleDetailsFromParams($params = array())
 {
     $details = array();
     $details['name'] = $details['path'] = $details['class_peffix'] = '';
     if (!empty($params['module'])) {
         $details['name'] = Ak::sanitize_include($params['module'], 'high');
         $details['path'] = trim(str_replace(array('/', '\\'), DS, $details['name']), DS) . DS;
         $details['shared_controller'] = AkConfig::getDir('controllers') . DS . trim($details['path'], DS) . '_controller.php';
         $details['class_peffix'] = AkInflector::camelize($params['module']) . '_';
     }
     return $details;
 }
Example #12
0
 function setDictionary($dictionary,$language,$namespace=false,$comment=null)
 {
     $path = AK_APP_DIR.DS.'locales'.DS.($namespace?trim(Ak::sanitize_include($namespace,'high'),DS).DS:'').basename($language).'.php';
     AkLocaleManager::getDictionary($language,$namespace,true,$dictionary);
     return Ak::file_put_contents($path,"<?php\n/** $comment */\n\n\$dictionary=".var_export((array)$dictionary,true).";\n");
 }
Example #13
0
 /**
  * Renders the template present at <tt>template_path</tt>. If <tt>use_full_path</tt> is set to true,
  * it's relative to the template_root, otherwise it's absolute. The array in <tt>local_assigns</tt>
  * is made available as local variables.
  */
 public function renderFile($template_path, $use_full_path = true, $local_assigns = array())
 {
     if (empty($this->first_render)) {
         $this->first_render = $template_path;
     }
     list($template_extension, $template_file_name) = $this->_getTemplateExtenssionAndFileName($template_path, $use_full_path);
     $format = '';
     if (isset($local_assigns['params']['format']) && $local_assigns['params']['format'] != 'html') {
         $format = Ak::sanitize_include($local_assigns['params']['format'], 'paranoid');
         $template_extension = $format . '.' . $template_extension;
     }
     if (AK_DEBUG && AK_CALLED_FROM_LOCALHOST && AK_ENCLOSE_RENDERS_WITH_DEBUG_SPANS && empty($format)) {
         $files_name = trim(str_replace(AkConfig::getDir('base'), '', realpath($template_file_name)), '/');
         return "\n\n<span title='file: {$files_name}'>" . $this->renderTemplate($template_extension, null, $template_file_name, $local_assigns) . "\n\n</span>";
     }
     return $this->renderTemplate($template_extension, null, $template_file_name, $local_assigns);
 }
Example #14
0
 public function _deliverUsingMailDeliveryMethod($method, &$Message, $options)
 {
     $handler_name = 'Ak' . AkInflector::camelize(Ak::sanitize_include($method, 'paranoid')) . 'Delivery';
     $handler_path = AK_LIB_DIR . DS . 'AkActionMailer' . DS . 'AkMailDelivery' . DS . $handler_name . '.php';
     if (file_exists($handler_path)) {
         require_once $handler_path;
     }
     if (!class_exists($handler_name)) {
         trigger_error(Ak::t('Could not find message handler %handler_name', array('%handler_name' => $handler_name)), E_USER_ERROR);
         return false;
     }
     $DeliveryHandler = new $handler_name();
     $this->Message =& $Message;
     return $DeliveryHandler->deliver($this, $options);
 }
Example #15
0
 protected function _generateConfigFileName($namespace)
 {
     $namespace = Ak::sanitize_include($namespace, 'high');
     $yaml_file_name = AkConfig::getDir('config') . DS . $namespace . '.yml';
     return $yaml_file_name;
 }
Example #16
0
 function populateTables()
 {
     
     $args = func_get_args();
     $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
     foreach ($tables as $table){
         $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
         if(!file_exists($file)){
             continue;
         }
         $class_name = AkInflector::classify($table);
         if($this->instantiateModel($class_name)){
             $contents = &Ak::getStaticVar('yaml_fixture_'.$file);
             if (!$contents) {
                 ob_start();
                 require_once($file);
                 $contents = ob_get_clean();
                 Ak::setStaticVar('yaml_fixture_'.$file, $contents);
             }
             $items = Ak::convert('yaml','array',$contents);
             foreach ($items as $item){
                 
                 $obj=&$this->{$class_name}->create($item);
                 if (isset($item['created_at'])) {
                     $obj->updateAttribute('created_at',$item['created_at']);
                 } else if (isset($item['created_on'])) {
                     $obj->updateAttribute('created_on',$item['created_on']);
                 }
             }
         }
     }
 }
Example #17
0
 function _generateCacheFileName($table, $environment = AK_ENVIRONMENT)
 {
     $namespace = Ak::sanitize_include($table, 'high');
     $cacheFile = AK_CONFIG_DIR.DS.'cache'.DS.'activerecord'.DS.$environment.DS.$table.'.php';
     return $cacheFile;
 }
Example #18
0
 protected function _generateConfigFileName($namespace)
 {
     $namespace = Ak::sanitize_include($namespace, 'high');
     $yaml_file_name = self::TPV_CONFIG_DIR . DS . $namespace . '.yml';
     return $yaml_file_name;
 }
Example #19
0
    /**
    * Renders the template present at <tt>template_path</tt>. If <tt>use_full_path</tt> is set to true,
    * it's relative to the template_root, otherwise it's absolute. The array in <tt>local_assigns</tt>
    * is made available as local variables.
    */
    function renderFile($template_path, $use_full_path = true, $local_assigns = array())
    {
        if(empty($this->first_render)){
            $this->first_render = $template_path;
        }

        $template_path = substr($template_path,0,7) === 'layouts' ? AK_VIEWS_DIR.DS.$template_path.'.tpl' : $template_path;

        if(!$use_full_path && strstr($template_path,'.')){
            $template_file_name = $template_path;
            $template_extension = substr($template_path,strpos($template_path,'.')+1);
        }else{
            $template_extension = $this->pickTemplateExtension($template_path);
            $template_file_name = $this->getFullTemplatePath($template_path, $template_extension);
        }

        $format = '';
        if(isset($local_assigns['params']['format']) && $local_assigns['params']['format'] != 'html'){
            $format = Ak::sanitize_include($local_assigns['params']['format'],'paranoid');
            $template_extension = $format.'.'.$template_extension;
        }

        if(AK_DEBUG && AK_CALLED_FROM_LOCALHOST && defined('AK_ENCLOSE_RENDERS_WITH_DEBUG_SPANS') && AK_ENCLOSE_RENDERS_WITH_DEBUG_SPANS && empty($format)){
            $files_name = trim((str_replace(AK_BASE_DIR,'',realpath($template_file_name))), '/');
            return "\n\n<span title='file: $files_name'>".$this->renderTemplate($template_extension, null, $template_file_name, $local_assigns)."\n\n</span>";
        }

        return $this->renderTemplate($template_extension, null, $template_file_name, $local_assigns);
    }
Example #20
0
File: Ak.php Project: joeymetal/v1
 /**
  * Gets information about current locale from the locale settings on config/locales/LOCALE.php 
  * 
  * This are common settings on the locale file:
  * 'description' // Locale description Example. Spanish
  * 'charset' // 'ISO-8859-1';
  * 'date_time_format' // '%d/%m/%Y %H:%i:%s';
  * 'date_format' // '%d/%m/%Y';
  * 'long_date_format' // '%d/%m/%Y';
  * 'time_format' // '%H:%i';
  * 'long_time_format' // '%H:%i:%s';
  */
 function locale($locale_setting, $locale = null)
 {
     static $settings;
     // We initiate the locale settings
     Ak::t('Akelos');
     $locale = empty($locale) ? defined('AK_LOCALE') ? AK_LOCALE : Ak::t('Akelos') && Ak::locale($locale_setting) : $locale;
     if (empty($settings[$locale])) {
         if (func_num_args() != 3) {
             // First time we ask for something using this locale so we will load locale details
             $requested_locale = $locale;
             if (@(include AK_CONFIG_DIR . DS . 'locales' . DS . Ak::sanitize_include($requested_locale) . '.php')) {
                 $locale = !empty($locale) && is_array($locale) ? $locale : array();
                 Ak::locale(null, $requested_locale, $locale);
                 return Ak::locale($locale_setting, $requested_locale);
             }
         } else {
             $settings[$locale] = func_get_arg(2);
             if (isset($settings[$locale]['charset'])) {
                 defined('AK_CHARSET') ? null : define('AK_CHARSET', $settings[$locale]['charset']) && @ini_set('default_charset', AK_CHARSET);
             }
         }
     }
     return isset($settings[$locale][$locale_setting]) ? $settings[$locale][$locale_setting] : false;
 }
Example #21
0
    /**
    * Recognizes a Request and returns the responsible controller instance
    * 
    * @return AkActionController
    */
    function &recognize($Map = null)
    {
        $this->_connectToDatabase();
        $this->_startSession();
        $this->_enableInternationalizationSupport();
        $this->_mapRoutes($Map);
        
        $params = $this->getParams();

        $module_path = $module_class_peffix = '';
        if(!empty($params['module'])){
            $module_path = trim(str_replace(array('/','\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS).DS;
            $module_shared_model = AK_CONTROLLERS_DIR.DS.trim($module_path,DS).'_controller.php';
            $module_class_peffix = str_replace(' ','_',AkInflector::titleize(str_replace(DS,' ', trim($module_path, DS)))).'_';
        }
        
        $controller_file_name = AkInflector::underscore($params['controller']).'_controller.php';
        $controller_class_name = $module_class_peffix.AkInflector::camelize($params['controller']).'Controller';
        $controller_path = AK_CONTROLLERS_DIR.DS.$module_path.$controller_file_name;
        include_once(AK_APP_DIR.DS.'application_controller.php');
        
        if(!empty($module_path) && file_exists($module_shared_model)){
            include_once($module_shared_model);
        }
        
        if(@!include_once($controller_path)){
            trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for '.
            'the controller %controller_class_name',
            array('%controller_file_name'=> $controller_file_name,
            '%controller_class_name' => $controller_class_name)), E_USER_ERROR);
        }
        if(!class_exists($controller_class_name)){
            trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist',
            array('%controller_name' => $controller_class_name)), E_USER_ERROR);
        }
        $Controller =& new $controller_class_name(array('controller'=>true));
        $Controller->_module_path = $module_path;
        isset($_SESSION) ? $Controller->session =& $_SESSION : null;
        return $Controller;

    }
Example #22
0
 public function addCookieHeader(&$options, $url)
 {
     if(isset($options['cookies'])){
         $url_details = parse_url($url);
         $jar = Ak::sanitize_include((empty($options['jar']) ? $this->_cookie_jar : $options['jar']), 'paranoid');
         $this->setCookiePath(AK_TMP_DIR.DS.'cookies'.DS.$jar.DS.Ak::sanitize_include($url_details['host'],'paranoid'));
         if($options['cookies'] === false){
             $this->deletePersistedCookie();
             return;
         }
         if($cookie_value = $this->getPersistedCookie()){
             $this->_persisted_cookie = $cookie_value;
             $options['header']['cookie'] = $cookie_value;
         }
     }
 }
Example #23
0
 /**
  * AkCharset::RecodeString() Pure PHP implementation
  *
  * @access private
  * @uses _Utf8StringEncode
  * @uses _Utf8StringDecode
  * @see RecodeString
  * @see _Utf8StringEncode
  * @see _Utf8StringDecode
  * @return    string    Recoded string if possible, otherwise it will
  * return the string without modifications.
  */
 function _PhpStringRecode($string, $target_charset, $origin_charset)
 {
     $this->_originCharset = $origin_charset;
     $this->_error = false;
     $target_charset = $this->_GetCharset($target_charset, false);
     $origin_charset = $this->_GetCharset($origin_charset, false);
     if (empty($origin_charset)) {
         $this->_error = true;
         return $string;
     }
     if (!$this->_ConversionIsNeeded($origin_charset, $target_charset) | !$this->usePhpRecoding && !$this->isUtf8($string)) {
         return $string;
     }
     if ($origin_charset == 'utf8') {
         include_once AK_LIB_DIR . DS . 'AkCharset' . DS . 'utf8_mappings' . DS . $target_charset . '.php';
         if (class_exists($target_charset)) {
             $mappingObject =& Ak::singleton($target_charset, $target_charset);
             if (method_exists($mappingObject, '_Utf8StringDecode')) {
                 return $mappingObject->_Utf8StringDecode($string);
             } else {
                 return $string;
             }
         } else {
             return $string;
         }
     } elseif ($target_charset == 'utf8') {
         @(include_once AK_LIB_DIR . DS . 'AkCharset' . DS . 'utf8_mappings' . DS . Ak::sanitize_include($origin_charset, 'paranoid') . '.php');
         if (class_exists($origin_charset)) {
             $mappingObject =& Ak::singleton($origin_charset, $origin_charset);
             if (method_exists($mappingObject, '_Utf8StringEncode')) {
                 return $mappingObject->_Utf8StringEncode($string);
             } else {
                 return $string;
             }
         } else {
             return $string;
         }
     } else {
         $utf8String = $this->_PhpStringRecode($string, 'utf8', $origin_charset);
         return $this->_PhpStringRecode($utf8String, $target_charset, 'utf8');
     }
 }