Ejemplo n.º 1
0
    public function _encodeAddress($address_string, $header_name = '', $names = true)
    {
        $headers = '';
        $addresses = Ak::toArray($address_string);
        $addresses = array_map('trim', $addresses);
        foreach ($addresses as $address){
            $address_description = '';
            if(preg_match('#(.*?)<(.*?)>#', $address, $matches)){
                $address_description = trim($matches[1]);
                $address = $matches[2];
            }

            if(empty($address) || !$this->_isAscii($address) || !$this->_isValidAddress($address)){
                continue;
            }
            if($names && !empty($address_description)){
                $address = "<$address>";
                if(!$this->_isAscii($address_description)){
                    $address_description = '=?'.AK_ACTION_MAILER_DEFAULT_CHARSET.'?Q?'.$this->quoted_printable_encode($address_description, 0).'?=';
                }
            }
            $headers .= (!empty($headers)?','.AK_MAIL_HEADER_EOL.' ':'').$address_description.$address;
        }

        return empty($headers) ? false : (!empty($header_name) ? $header_name.': '.$headers.AK_MAIL_HEADER_EOL : $headers);
    }
Ejemplo n.º 2
0
 function _init()
 {
     $this->logger =& Ak::getLogger();
     $base = AK_TEST_DIR . DS . 'unit' . DS . 'lib' . DS;
     $this->GroupTest($this->title);
     $allFiles = glob($base . $this->baseDir);
     if (isset($this->excludes)) {
         $excludes = array();
         $this->excludes = @Ak::toArray($this->excludes);
         foreach ($this->excludes as $pattern) {
             $excludes = array_merge($excludes, glob($base . $pattern));
         }
         $this->excludes = $excludes;
     } else {
         $this->excludes = array();
     }
     if (count($allFiles) >= 1 && $allFiles[0] != $base . $this->baseDir && $this->partial_tests === true) {
         $this->_includeFiles($allFiles);
     } else {
         if (is_array($this->partial_tests)) {
             foreach ($this->partial_tests as $test) {
                 //$this->log('Including partial testfile:'.$test);
                 $this->addTestFile($base . $this->baseDir . DS . $test . '.php');
             }
         } else {
             echo "No files in : " . $this->title . "\n";
         }
     }
 }
Ejemplo n.º 3
0
 function _protectAction()
 {
     $protected_actions = Ak::toArray($this->protected_actions);
     $action_name = $this->getActionName();
     if (in_array($action_name, $protected_actions) && !$this->CurrentUser->can($action_name . ' action', 'Admin::' . $this->getControllerName())) {
         $this->redirectTo(array('action' => 'protected_action'));
     }
 }
Ejemplo n.º 4
0
 function _linkWebServiceApis()
 {
     if (!empty($this->web_service_api)) {
         $this->web_service_api = Ak::toArray($this->web_service_api);
         foreach ($this->web_service_api as $api) {
             $this->_linkWebServiceApi($api);
         }
     }
 }
Ejemplo n.º 5
0
 function _preloadPaths()
 {
     $this->class_name = AkInflector::camelize($this->class_name);
     $this->assignVarToTemplate('class_name', $this->class_name);
     $this->actions = Ak::toArray(@$this->actions);
     $this->assignVarToTemplate('actions', $this->actions);
     $this->underscored_class_name = AkInflector::underscore($this->class_name);
     $this->model_path = 'app' . DS . 'models' . DS . $this->underscored_class_name . '.php';
     $this->installer_path = 'app' . DS . 'installers' . DS . $this->underscored_class_name . '_installer.php';
 }
Ejemplo n.º 6
0
 function rss2_builder($items = array(), $channel_options = array(), $item_options = array())
 {
     $return = array();
     $default_channel_options = array('title' => 'Please put your custom channel title in $channel_options[title]', 'description' => 'Please put your custom channel description in $channel_options[description]', 'link' => 'http://example.com/put/your/custom/link/here', 'language' => Ak::base_lang());
     $channel_parameters = array('available_options' => array('title', 'description', 'link', 'language'));
     Ak::parseOptions($channel_options, $default_channel_options, $channel_parameters);
     $default_item_options = array('title' => 'name', 'description' => 'description', 'date' => 'created_at', 'author' => false, 'link' => true, 'guid' => false);
     $item_parameters = array('available_options' => array('title', 'description', 'link', 'date', 'author', 'guid', 'content:encoded'));
     Ak::parseOptions($item_options, $default_item_options, $item_parameters);
     $return[] = $this->xml_instruct('xml', array('version' => '1.0'));
     $return[] = $this->xml_rss_open(array('version' => "2.0", 'xmlns' => array('dc' => "http://purl.org/dc/elements/1.1/", 'atom' => "http://www.w3.org/2005/Atom", 'content' => 'http://purl.org/rss/1.0/modules/content/')));
     $return[] = $this->xml_channel_open();
     $return[] = $this->xml_title($channel_options['title']);
     $return[] = $this->xml_description($channel_options['description']);
     $return[] = $this->xml_link(htmlentities($channel_options['link']));
     $return[] = $this->xml_language($channel_options['language']);
     $items = Ak::toArray($items);
     foreach ($items as $item) {
         $return[] = $this->xml_item_open();
         if (!empty($item_options['title'])) {
             $title = $this->_getValue($item, $item_options['title']);
             !empty($title) ? $return[] = $this->xml_title($title) : null;
         }
         if (!empty($item_options['link'])) {
             $item_link = $this->_getValue($item, $item_options['link']);
             !empty($item_link) ? $return[] = $this->xml_link($item_link) : null;
         }
         if (!empty($item_options['guid'])) {
             $guid = $this->_getValue($item, $item_options['guid']);
             !empty($guid) ? $return[] = $this->xml_guid($guid, strstr($guid, 'http://') ? array() : array('isPermaLink' => 'false')) : (!empty($item_link) ? $return[] = $this->xml_guid($item_link, strstr($item_link, 'http://') ? array() : array('isPermaLink' => 'false')) : null);
         }
         if (!empty($item_options['content:encoded'])) {
             $encoded = $this->_getValue($item, $item_options['content:encoded']);
             !empty($encoded) ? $return[] = $this->xml_content__encoded('<![CDATA[' . $encoded . ']]>') : null;
         }
         if (!empty($item_options['description'])) {
             $description = $this->_getValue($item, $item_options['description']);
             !empty($description) ? $return[] = $this->xml_description('<![CDATA[' . $description . ']]>') : null;
         }
         if (!empty($item_options['date'])) {
             $created_at = $this->_getValue($item, $item_options['date']);
             !empty($created_at) ? $return[] = $this->xml_dc__date($this->_generate_date($created_at)) : null;
         }
         if (!empty($item_options['author'])) {
             $author = $this->_getValue($item, $item_options['author']);
             !empty($author) ? $return[] = $this->xml_dc__author($author) : null;
         }
         $return[] = $this->xml_item_close();
     }
     $return[] = $this->xml_channel_close();
     $return[] = $this->xml_rss_close();
     return implode("\n", $return);
 }
Ejemplo n.º 7
0
 function _preloadPaths()
 {
     $this->class_name = AkInflector::camelize($this->class_name);
     $this->assignVarToTemplate('class_name', $this->class_name);
     $this->actions = Ak::toArray(@$this->actions);
     if(empty($this->actions)){
         trigger_error(Ak::t('You must supply at least one action for the mailer.'), E_USER_ERROR);
     }
     $this->assignVarToTemplate('actions', $this->actions);
     $this->underscored_class_name = AkInflector::underscore($this->class_name);
     $this->model_path = 'app'.DS.'models'.DS.$this->underscored_class_name.'.php';
     $this->installer_path = 'app'.DS.'installers'.DS.$this->underscored_class_name.'_installer.php';
 }
Ejemplo n.º 8
0
 /**
  * Will add an error message to each of the attributes in $attributes that has a length outside of the passed boundary $range.
  * If the length is above the boundary, the too_long_message message will be used. If below, the too_short_message.
  */
 public function addErrorOnBoundaryBreaking($attribute_names, $range_begin, $range_end, $too_long_message = 'too_long', $too_short_message = 'too_short')
 {
     $too_long_message = $this->getDefaultErrorMessageFor($too_long_message);
     $too_short_message = $this->getDefaultErrorMessageFor($too_short_message);
     $attribute_names = Ak::toArray($attribute_names);
     foreach ($attribute_names as $attribute) {
         if (@$this->_Model->{$attribute} < $range_begin) {
             $this->addError($attribute, $too_short_message);
         }
         if (@$this->_Model->{$attribute} > $range_end) {
             $this->addError($attribute, $too_long_message);
         }
     }
 }
Ejemplo n.º 9
0
 function _getOrderFromAssociations(&$object, $paginator_name, &$find_options)
 {
     if (!empty($this->_controller->params['sort']) && !empty($this->{$paginator_name}->_ak_options['include']) && $object->hasAssociations()) {
         $included_models = Ak::toArray($this->{$paginator_name}->_ak_options['include']);
         foreach ($object->getAvailableAssociates() as $association_type => $associated_models) {
             foreach ($associated_models as $associated_model) {
                 if (in_array($this->_controller->params['sort'], array_keys($object->{$associated_model}->getAvailableAttributes()))) {
                     $find_options['order'] = $association_type . '_' . $associated_model . '.' . $this->_controller->params['sort'] . $this->getSortDirection();
                     return true;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 10
0
 public function createRoles()
 {
     $Role = new Role();
     $ApplicationOwner = $Role->create(array('name' => 'Application owner'));
     $Administrator = $ApplicationOwner->addChildrenRole('Administrator');
     foreach (Ak::toArray('add,destroy,edit,index,listing,show') as $action) {
         $Administrator->addPermission(array('name' => $action . ' action', 'extension' => $this->AdminUsers));
     }
     $Administrator->addPermission(array('name' => 'Manage Users (users controller)', 'extension' => $this->AdminMenuTabs));
     $Administrator->addPermission(array('name' => 'Accounts (users controller, listing action)', 'extension' => $this->AdminMenuTabs));
     $Administrator->addPermission(array('name' => 'Edit other users', 'extension' => $this->AdminUsers));
     $NormalUser = $Administrator->addChildrenRole('Registered user');
     $NormalUser->addPermission(array('name' => 'index action', 'extension' => $this->AdminDashboard));
     $NormalUser->addPermission(array('name' => 'Dashboard (dashboard controller)', 'extension' => $this->AdminMenuTabs));
 }
Ejemplo n.º 11
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);
                }
            }

        }
    }
Ejemplo n.º 12
0
    function _getAvailableHelpers()
    {
        $helpers = array();
        if(empty($this->available_helpers)){
            if(defined('AK_SINTAGS_AVALABLE_HELPERS')){
                $helpers = unserialize(AK_SINTAGS_AVALABLE_HELPERS);
            }else{
                require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkHelperLoader.php');
                if($underscored_helper_names = AkHelperLoader::getInstantiatedHelperNames()){
                    foreach ($underscored_helper_names as $underscored_helper_name){
                        $helper_class_name = AkInflector::camelize($underscored_helper_name);
                        if(class_exists($helper_class_name)){
                            $methods = get_class_methods($helper_class_name);
                            $vars=get_class_vars($helper_class_name);
                            if (AK_PHP5 && isset($vars['dynamic_helpers'])) {
                                $dynamic_helpers = Ak::toArray($vars['dynamic_helpers']);
                                foreach ($dynamic_helpers as $method_name){
                                    $this->dynamic_helpers[$method_name] = $underscored_helper_name;
                                }
                            }
                            foreach (get_class_methods($helper_class_name) as $method_name){
                                if($method_name[0] != '_'){
                                    $helpers[$method_name] = $underscored_helper_name;
                                }
                            }
                        }
                    }
                    $helpers['render'] = 'controller';
                    $helpers['render_partial'] = 'controller';
                }
            }
            $this->available_helpers = $helpers;
        }
        return $this->available_helpers;

    }
Ejemplo n.º 13
0
 /**
  * Creates an instance of each available helper and links it into into current mailer.
  * 
  * Mailer helpers work as Controller helpers but without the Request context
  */
 function &getHelpers()
 {
     static $helpers = array();
     require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'AkActionViewHelper.php';
     $mailer_helpers = array_merge(Ak::toArray($this->helpers), array(substr($this->getModelName(), -6)));
     $mailer_helpers = array_unique(array_map(array('AkInflector', 'underscore'), $mailer_helpers));
     foreach ($mailer_helpers as $file => $mailer_helper) {
         $full_path = preg_match('/[\\\\\\/]+/', $file);
         $helper_class_name = AkInflector::camelize($mailer_helper) . 'Helper';
         $attribute_name = !$full_path ? AkInflector::underscore($helper_class_name) : substr($file, 0, -4);
         if (empty($helpers[$attribute_name])) {
             if ($full_path) {
                 include_once $file;
             } else {
                 $helper_file_name = $mailer_helper . '_helper.php';
                 if (file_exists(AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . $helper_file_name)) {
                     include_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . $helper_file_name;
                 } elseif (file_exists(AK_HELPERS_DIR . DS . $helper_file_name)) {
                     include_once AK_HELPERS_DIR . DS . $helper_file_name;
                 }
             }
             if (class_exists($helper_class_name)) {
                 if (empty($helpers[$attribute_name])) {
                     $helpers[$attribute_name] =& new $helper_class_name(&$this);
                     if (method_exists($helpers[$attribute_name], 'setController')) {
                         $helpers[$attribute_name]->setController(&$this);
                     }
                     if (method_exists($helpers[$attribute_name], 'setMailer')) {
                         $helpers[$attribute_name]->setMailer(&$this);
                     }
                     if (method_exists($helpers[$attribute_name], 'init')) {
                         $helpers[$attribute_name]->init();
                     }
                 }
             }
         }
     }
     return $helpers;
 }
Ejemplo n.º 14
0
Archivo: Ak.php Proyecto: joeymetal/v1
 /**
  * Returns YAML settings from config/$namespace.yml
  */
 function getSettings($namespace, $raise_error_if_config_file_not_found = true, $environment = AK_ENVIRONMENT)
 {
     static $_config;
     if (!in_array($environment, Ak::toArray(AK_AVAILABLE_ENVIRONMENTS))) {
         trigger_error('The environment ' . $environment . ' is not allowed. Allowed environments: ' . AK_AVAILABLE_ENVIRONMENTS);
         return false;
     }
     if (!isset($_config)) {
         require_once AK_LIB_DIR . DS . 'AkConfig.php';
         $_config = new AkConfig();
     }
     return $_config->get($namespace, $environment, $raise_error_if_config_file_not_found);
 }
Ejemplo n.º 15
0
 function convert()
 {
     return Ak::toArray($this->source);
 }
Ejemplo n.º 16
0
 private function mapMemberActions($Map, $Resource)
 {
     foreach ($Resource->getMemberMethods() as $k => $actions) {
         foreach ($actions as $action) {
             foreach (Ak::toArray($k) as $method) {
                 if (!empty($Resource->options['path_names'][$action])) {
                     $action_path = $Resource->options['path_names'][$action];
                 } else {
                     $action_path = $Resource->getResourcePathNameFor($action, $action);
                 }
                 $this->mapResourceRoutes($Map, $Resource, $action, $Resource->getMemberPath() . $Resource->getActionSeparator() . $action_path, $action . '_' . $Resource->getShallowNamePrefix() . $Resource->singular, $method, array('force_id' => true));
             }
         }
         $route_path = $Resource->getShallowNamePrefix() . $Resource->singular;
         $this->mapResourceRoutes($Map, $Resource, 'show', $Resource->getMemberPath(), $route_path);
         $this->mapResourceRoutes($Map, $Resource, 'update', $Resource->getMemberPath(), $route_path);
         $this->mapResourceRoutes($Map, $Resource, 'destroy', $Resource->getMemberPath(), $route_path);
     }
 }
Ejemplo n.º 17
0
Archivo: Ak.php Proyecto: joeymetal/v1
 function delete($source_array, $attributes_to_delete_from_array)
 {
     $resulting_array = (array)$source_array;
     $args = array_slice(func_get_args(),1);
     $args = count($args) == 1 ? Ak::toArray($args[0]) : $args;
     foreach ($args as $arg){
         unset($resulting_array[$arg]);
     }
     return $resulting_array;
 }
Ejemplo n.º 18
0
 function _setColumnDefaults($columns)
 {
     $columns = Ak::toArray($columns);
     foreach ((array)$columns as $column){
         $column = trim($column, "\n\t\r, ");
         if(!empty($column)){
             $single_columns[$column] = $this->_setColumnDefault($column);
         }
     }
     if(!empty($this->timestamps) && !isset($single_columns['created_at']) &&  !isset($single_columns['updated_at'])){
         $single_columns['updated_at'] = $this->_setColumnDefault('updated_at');
         $single_columns['created_at'] = $this->_setColumnDefault('created_at');
     }
     return join(",\n", $single_columns);
 }
Ejemplo n.º 19
0
 /**
  * Returns an array which locales enabled on the public website.
  * In order to define available languages you must define AK_PUBLIC_LOCALES 
  * which a comma-separated list of locales
  *
  * @return array
  */
 function getPublicLocales()
 {
     static $public_locales;
     if (empty($public_locales)) {
         $public_locales = defined('AK_PUBLIC_LOCALES') ? Ak::toArray(AK_PUBLIC_LOCALES) : array_keys($this->available_locales);
     }
     return $public_locales;
 }
Ejemplo n.º 20
0
 public function readConfigArray($namespace, $config = array(), $environment = TPV_MODE)
 {
     if (!is_array($config)) {
         return false;
     }
     $default = isset($config['default']) ? $config['default'] : array();
     $configs = array();
     unset($config['default']);
     $environments = array_keys($config);
     $default_environments = Ak::toArray(TPV_AVAILABLE_MODES);
     $environments = array_merge($default_environments, $environments);
     foreach ($environments as $env) {
         $envConfig = $this->_merge($default, isset($config[$env]) ? $config[$env] : array());
         $this->writeCache($envConfig, $namespace, $env, $this->_useWriteCache($environment));
         $configs[$env] = $envConfig;
     }
     return isset($configs[$environment]) ? $configs[$environment] : (in_array($environments, $environments) ? $default : false);
 }
Ejemplo n.º 21
0
 public function &find()
 {
     $result = false;
     if (!$this->Owner->isNewRecord()) {
         $args = func_get_args();
         $num_args = func_num_args();
         if (!empty($args[$num_args - 1]) && is_array($args[$num_args - 1])) {
             $options_in_args = true;
             $options = $args[$num_args - 1];
         } else {
             $options_in_args = false;
             $options = array();
         }
         $this->constructSql(!empty($options['include']));
         $has_many_options = $this->getOptions($this->association_id);
         $Associated =& $this->getAssociatedModelInstance();
         if (empty($options['conditions'])) {
             $options['conditions'] = @$has_many_options['finder_sql'];
         } elseif (!empty($has_many_options['finder_sql']) && is_array($options['conditions']) && !strstr($options['conditions'][0], $has_many_options['finder_sql'])) {
             $options['conditions'][0] .= ' AND ' . $has_many_options['finder_sql'];
         } elseif (!empty($has_many_options['finder_sql']) && !strstr($options['conditions'], $has_many_options['finder_sql'])) {
             $options['conditions'] .= ' AND ' . $has_many_options['finder_sql'];
         }
         $options['bind'] = empty($options['bind']) ? @$has_many_options['bind'] : $options['bind'];
         $options['order'] = empty($options['order']) ? @$has_many_options['order'] : $options['order'];
         $options['group'] = empty($options['group']) ? @$has_many_options['group'] : $options['group'];
         $options['include'] = empty($options['include']) ? @$has_many_options['include'] : $options['include'];
         if (!empty($options['bind'])) {
             $options['bind'] = Ak::toArray($options['bind']);
             $options['bind'] = array_diff($options['bind'], array(''));
             $options['conditions'] = is_array($options['conditions']) ? $options['conditions'] : array($options['conditions']);
             $options['conditions'] = array_merge($options['conditions'], $options['bind']);
             unset($options['bind']);
         }
         if ($options_in_args) {
             $args[$num_args - 1] = $options;
         } else {
             $args = empty($args) ? array('all') : $args;
             array_push($args, $options);
         }
         $result =& Ak::call_user_func_array(array(&$Associated, 'find'), $args);
     }
     return $result;
 }
Ejemplo n.º 22
0
 function api($protocol = 'xml_rpc')
 {
     $web_services = array_merge(Ak::toArray($this->web_services), Ak::toArray($this->web_service));
     if (!empty($web_services)) {
         $web_services = array_unique($web_services);
         require_once AK_LIB_DIR . DS . 'AkActionWebService.php';
         require_once AK_LIB_DIR . DS . 'AkActionWebService' . DS . 'AkActionWebServiceServer.php';
         $Server =& new AkActionWebServiceServer($protocol);
         foreach ($web_services as $web_service) {
             $Server->addService($web_service);
         }
         $Server->init();
         $Server->serve();
         exit;
     } else {
         die(Ak::t('There is not any webservice configured at this endpoint'));
     }
 }
Ejemplo n.º 23
0
 public function getParameters($parameters_settings, $request_parameters)
 {
     $parameters_settings = Ak::toArray($parameters_settings);
     if (empty($parameters_settings)) {
         return $request_parameters;
     }
     $parameters = array();
     foreach ($parameters_settings as $k => $v) {
         $options = array();
         $required = true;
         if (is_numeric($k)) {
             $parameter_name = $v;
         } else {
             $parameter_name = $k;
             if (is_array($v) && !empty($v['optional'])) {
                 $required = false;
                 unset($v['optional']);
             }
         }
         if ($required && !isset($request_parameters[$parameter_name])) {
             $this->error("\nMissing \"{$parameter_name}\" parameter on {$this->current_task}\n", true);
         }
     }
 }
Ejemplo n.º 24
0
 /**
  * Includes and instantiates given models
  */
 function includeAndInstatiateModels()
 {
     $args = func_get_args();
     $models = isset($args[1]) ? (array)$args : Ak::toArray($args[0]);
     foreach ($models as $model){
         $this->_includeOrGenerateModel($model);
         $this->instantiateModel($model);
     }
 }
Ejemplo n.º 25
0
 public function getAutocompletionOptionsForTask($task, $options = array(), $level = 1)
 {
     $task_name = str_replace(':', DS, $task);
     $Makelos = $this;
     $autocompletion_options = array();
     $autocomplete_accessor = 'autocompletion' . ($level === 1 ? '' : '_' . $level);
     $autocompletion_executables = $this->multiGlob(array($task_name . '*.' . $autocomplete_accessor . '.*', $task_name . DS . $task_name . '.' . $autocomplete_accessor . '.*'));
     if (!empty($autocompletion_executables)) {
         ob_start();
         foreach ($autocompletion_executables as $file) {
             $pathinfo = pathinfo($file);
             if (isset($pathinfo['extension']) && $pathinfo['extension'] == 'php') {
                 include $file;
             } else {
                 echo `{$file}`;
             }
         }
         echo "\n";
         $autocompletion_options = array_diff(explode("\n", ob_get_clean()), array(''));
     }
     $autocomplete_accessor = 'autocompletion' . ($level === 1 ? '' : '_' . $level);
     if (isset($this->tasks[$task][$autocomplete_accessor])) {
         $autocompletion_options = array_merge(Ak::toArray($this->tasks[$task][$autocomplete_accessor]), $autocompletion_options);
     }
     array_unique($autocompletion_options);
     $autocompletion_options = array_diff($autocompletion_options, array_merge(array($task), $options));
     return $autocompletion_options;
 }
Ejemplo n.º 26
0
 function &findWithAssociations($options)
 {
     $result = false;
     $options['include'] = Ak::toArray($options['include']);
     $options['order'] = empty($options['order']) ? '' : $this->_addTableAliasesToAssociatedSql('__owner', $options['order']);
     $options['conditions'] = empty($options['conditions']) ? '' : $this->_addTableAliasesToAssociatedSql('__owner', $options['conditions']);
     $included_associations = array();
     $included_association_options = array();
     foreach ($options['include'] as $k => $v) {
         if (is_numeric($k)) {
             $included_associations[] = $v;
         } else {
             $included_associations[] = $k;
             $included_association_options[$k] = $v;
         }
     }
     $available_associated_options = array('order' => array(), 'conditions' => array(), 'joins' => array(), 'selection' => array());
     foreach ($included_associations as $association_id) {
         $association_options = empty($included_association_options[$association_id]) ? array() : $included_association_options[$association_id];
         $handler_name = $this->getCollectionHandlerName($association_id);
         $handler_name = empty($handler_name) ? $association_id : (in_array($handler_name, $included_associations) ? $association_id : $handler_name);
         $associated_options = $this->{$handler_name}->getAssociatedFinderSqlOptions($association_options);
         foreach (array_keys($available_associated_options) as $associated_option) {
             if (!empty($associated_options[$associated_option])) {
                 $available_associated_options[$associated_option][] = $associated_options[$associated_option];
             }
         }
     }
     foreach ($available_associated_options as $option => $values) {
         if (!empty($values)) {
             $separator = $option == 'joins' ? ' ' : (in_array($option, array('selection', 'order')) ? ', ' : ' AND ');
             $values = array_map('trim', $values);
             $options[$option] = empty($options[$option]) ? join($separator, $values) : trim($options[$option]) . $separator . join($separator, $values);
         }
     }
     $sql = trim($this->constructFinderSqlWithAssociations($options));
     if (!empty($options['bind']) && is_array($options['bind']) && strstr($sql, '?')) {
         $sql = array_merge(array($sql), $options['bind']);
     }
     $result =& $this->_findBySqlWithAssociations($sql, $options['include'], empty($options['virtual_limit']) ? false : $options['virtual_limit']);
     return $result;
 }
Ejemplo n.º 27
0
    /**
     * @static 
     * @param array $database_settings
     * @return AkDbAdapter
     */
    function &getInstance($database_specifications = AK_DEFAULT_DATABASE_PROFILE, $auto_connect = true)
    {
        static $connections;

        $settings_hash = is_string($database_specifications) ? $database_specifications : AkDbAdapter::_hash($database_specifications);

        if (empty($connections[$settings_hash])){
            if (empty($database_specifications)) {
                $settings_hash = AK_ENVIRONMENT;
                $database_specifications = Ak::getSettings('database',false,$settings_hash);
            } else if (is_string($database_specifications)){
                $environment_settings = Ak::getSettings('database',false,$database_specifications);
                if (!empty($environment_settings)){
                    $database_specifications = $environment_settings;
                } elseif(strstr($database_specifications, '://')) {
                    $database_specifications = AkDbAdapter::_getDbSettingsFromDsn($database_specifications);
                    $settings_hash = AK_ENVIRONMENT;
                } else {
                    global $database_settings;
                    if (isset($database_settings) && !file_exists(AK_CONFIG_DIR.DS.'database.yml')) {
                        trigger_error(Ak::t("You are still using the old config/config.php database configuration. Please upgrade to use the config/database.yml configuration."), E_USER_NOTICE);
                    } 
                    if (!file_exists(AK_CONFIG_DIR.DS.'database.yml')) {
                        trigger_error(Ak::t("Could not find the database configuration file in %dbconfig.",array('%dbconfig'=>AK_CONFIG_DIR.DS.'database.yml')),E_USER_ERROR);
                    } else {
                        trigger_error(Ak::t("Could not find the database profile '%profile_name' in config/database.yml.",array('%profile_name'=>$database_specifications)),E_USER_ERROR);
                    }
                    
                    
                    $return = false;
                    return $return;
                }
            }elseif (!empty($database_settings[$settings_hash])){
                $database_specifications = $database_settings[$settings_hash];
            }
            $available_adapters = Ak::toArray(AK_AVAILABLE_DATABASES);
            $class_name = 'AkDbAdapter';
            $designated_database = strtolower($database_specifications['type']);
            if (in_array($designated_database, $available_adapters)) {
                $class_name = 'Ak'.ucfirst($designated_database).'DbAdapter';
                require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkDbAdapters'.DS.$class_name.'.php');
            }
            $connections[$settings_hash] =& new $class_name($database_specifications,$auto_connect);
        }
        return $connections[$settings_hash];
    }
Ejemplo n.º 28
0
 function MetaIndexes($table, $primary = FALSE, $owner = false)
 {
     $false = false;
     // save old fetch mode
     global $ADODB_FETCH_MODE;
     $save = $ADODB_FETCH_MODE;
     $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     if ($this->fetchMode !== FALSE) {
         $savem = $this->SetFetchMode(FALSE);
     }
     $SQL = sprintf("SELECT name,sql FROM sqlite_master WHERE type='index' AND tbl_name='%s'", strtolower($table));
     $rs = $this->Execute($SQL);
     if (!is_object($rs)) {
         if (isset($savem)) {
             $this->SetFetchMode($savem);
         }
         $ADODB_FETCH_MODE = $save;
         return $false;
     }
     $indexes = array();
     while ($row = $rs->FetchRow()) {
         if ($primary && preg_match("/primary/i", $row[1]) == 0) {
             continue;
         }
         if (!isset($indexes[$row[0]])) {
             $indexes[$row[0]] = array('unique' => preg_match("/unique/i", $row[1]), 'columns' => array());
         }
         if (preg_match('/\\((.+)\\)$/', $row[1], $matches)) {
             $indexes[$row[0]]['columns'] = Ak::toArray($matches[1]);
         }
     }
     if (isset($savem)) {
         $this->SetFetchMode($savem);
         $ADODB_FETCH_MODE = $save;
     }
     return $indexes;
 }
Ejemplo n.º 29
0
 /**
  * adds itself to the models which are listed
  * in var $observe = array(...)
  *
  */
 function _initModelObserver()
 {
     $this->observe = Ak::toArray($this->observe);
     if (count($this->observe) > 0) {
         $this->setObservedModels($this->observe);
     }
 }
Ejemplo n.º 30
0
 function _checkInstallDependencies()
 {
     if (isset($this->php_min_version)) {
         if (version_compare(PHP_VERSION, $this->php_min_version, '<')) {
             echo "\n";
             Ak::t("This plugin requires at least php version: %version", array('%version', $this->php_min_version));
             echo "\n";
             return false;
         }
     }
     if (isset($this->php_max_version)) {
         if (version_compare(PHP_VERSION, $this->php_max_version, '>')) {
             echo "\n";
             Ak::t("This plugin runs only on php version <= %version", array('%version', $this->php_min_version));
             echo "\n";
             return false;
         }
     }
     if (isset($this->dependencies)) {
         $this->dependencies = Ak::toArray($this->dependencies);
         $pluginManager = new AkPluginManager();
         $plugins = $pluginManager->getInstalledPlugins();
         $missing = array();
         foreach ($this->dependencies as $dependency) {
             if (!in_array($dependency, $plugins)) {
                 $missing[] = $dependency;
             }
         }
         if (!empty($missing)) {
             echo "\n";
             $params = array('plugin' => AkT('plugin', 'quantify(' . count($missing) . ')'), 'missing' => AkT($missing, 'toSentence'));
             echo Ak::t("This plugin depends on the %plugin %missing. Please install the missing plugins first.", $params);
             echo "\n";
             return false;
         } else {
             /**
              * register the dependent plugins
              */
             foreach ($this->dependencies as $dependency) {
                 $dependencyFile = AK_PLUGINS_DIR . DS . $dependency . DS . 'dependent_plugins';
                 if ($fileExists = file_exists($dependencyFile)) {
                     $dependendPlugins = file($dependencyFile);
                 } else {
                     $dependendPlugins = array();
                 }
                 if (!in_array($this->plugin_name, $dependendPlugins)) {
                     $dependendPlugins[] = $this->plugin_name;
                 }
                 if (!empty($dependendPlugins)) {
                     Ak::file_put_contents($dependencyFile, implode("\n", $dependendPlugins));
                 } else {
                     if ($fileExists) {
                         unlink($dependencyFile);
                     }
                 }
             }
         }
     }
     return true;
 }