Ejemplo n.º 1
0
 public function process()
 {
     $params = Toolkit::i()->request->getParams();
     if (count($params) < 2) {
         echo "Please specify module and command\n";
     } else {
         $module = $params[0];
         $controller = $params[1];
         Core::import('Modules.' . $module);
         $sController = $module . $controller . 'Command';
         $sControllerFull = 'ruxon\\modules\\' . $module . '\\commands\\' . $sController;
         if (class_exists($sControllerFull)) {
             $oController = new $sControllerFull();
         } else {
             $oController = new $sController();
         }
         unset($params[0]);
         unset($params[1]);
         $par = array_values($params);
         $action_params = array();
         if (count($par)) {
             foreach ($par as $k => $val) {
                 if (substr_count($val, "=") > 0) {
                     $tmp = explode("=", $val);
                     $action_params[$tmp[0]] = trim($tmp[1]);
                 } else {
                     $action_params[] = $val;
                 }
             }
         }
         $oController->run('Execute', $action_params);
     }
 }
Ejemplo n.º 2
0
 public function __construct($inputs = array(), $action = false, $method = 'post', $view = 'forms/_table_form')
 {
     Core::import('helpers/html', 'helpers/text');
     $this->setInputs($inputs);
     $this->action = $action ? $action : $_SERVER['REQUEST_URI'];
     $this->method = strtolower($method);
     $this->view = $view;
 }
Ejemplo n.º 3
0
 protected function loadCommonExtensions()
 {
     $aExtensions = $this->config()->getExtensions();
     if (count($aExtensions)) {
         foreach ($aExtensions as $ext) {
             Core::import(array('Extensions', $ext));
         }
     }
 }
Ejemplo n.º 4
0
 public function get(Object $oObject, $aParams = array())
 {
     if (isset($this->aParams['ToModuleAlias'])) {
         Core::import('Modules.' . $this->aParams['ToModuleAlias']);
     }
     $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapperAlias']);
     $aParams['Criteria'][$this->aParams['Field']] = $oObject->getId();
     return $oMapper->findFirst($aParams);
 }
Ejemplo n.º 5
0
 public function result403()
 {
     Core::import('Modules.Main');
     $oController = new SiteController();
     $oResult = $oController->run('403', array());
     Core::app()->response()->setStatus(403);
     Core::app()->theme()->getLayout()->setContent($oResult->getHtml());
     Core::app()->response()->setResponseText(Core::app()->theme()->fetch());
     Core::app()->end();
     Core::app()->hardEnd();
 }
 public function eagerFetching(DbFetcher $oQuery, ObjectMapper $oParentMapper, $sPrefix, $aParams = array(), $aLocalParams = array())
 {
     if (isset($this->aParams['ToModuleAlias'])) {
         Core::import('Modules.' . $this->aParams['ToModuleAlias']);
     }
     $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapperAlias']);
     //echo '<pre>', print_r($oMapper, true), '</pre>'; die();
     $aContainer = $oMapper->getContainer();
     if ($oMapper) {
         $oParentFields = $oParentMapper->getFields();
         $oQuery->addJoinTable($aContainer['TableName'], $sPrefix . '_' . $this->getAlias(), DbFetcher::JOIN_LEFT, $sPrefix . '.' . $oParentFields->get($this->getField())->getField() . ' = ' . $sPrefix . '_' . $this->getAlias() . '.id');
         $oFields = $oMapper->getFields();
         foreach ($oFields as $alias => $field) {
             if ($field->getType() != 'Object' && $field->getField()) {
                 $oQuery->addSelectField($sPrefix . '_' . $this->getAlias() . '.' . $field->getField(), $sPrefix . '_' . $this->getAlias() . '_' . $field->getField());
             }
         }
         // Условия выборки
         if (isset($aLocalParams['Criteria']) && is_object($aLocalParams['Criteria'])) {
             $oQuery->addCriteria(call_user_func(array($aLocalParams['Criteria'], 'renderWhere')));
         }
         if (isset($aLocalParams['Criteria']) && is_array($aLocalParams['Criteria']) && count($aLocalParams['Criteria']) > 0) {
             $oCriteria = new CriteriaGroup(Criteria::TYPE_AND);
             foreach ($aLocalParams['Criteria'] as $k => $itm) {
                 if (is_object($itm)) {
                     $oCriteria->addElement($itm);
                 } else {
                     if (is_array($itm)) {
                         $oCriteria->addElement(new CriteriaElement($k, $itm['Type'], $itm['Value']));
                     } else {
                         $oCriteria->addElement(new CriteriaElement($k, '=', $itm));
                     }
                 }
             }
             $oQuery->addCriteria($oMapper->parseFindCriteria($oCriteria->renderWhere(), $sPrefix . '_' . $this->getAlias()));
         }
         if (isset($aLocalParams['Criteria']) && is_string($aLocalParams['Criteria'])) {
             $oQuery->addCriteria($oMapper->parseFindCriteria($aLocalParams['Criteria'], $sPrefix . '_' . $this->getAlias()));
         }
         // Сортировка
         if (isset($aLocalParams['Order']) && is_array($aLocalParams['Order']) && count($aLocalParams['Order']) > 0) {
             foreach ($aLocalParams['Order'] as $k => $itm) {
                 $oQuery->addOrder($oMapper->parseFindField($k, $sPrefix . '_' . $this->getAlias()), $itm);
             }
         }
         if (isset($aLocalParams['With']) && is_array($aLocalParams['With']) && count($aLocalParams['With'])) {
             // TODO: Вложенные JOINы
         }
     }
     return $oQuery;
 }
Ejemplo n.º 7
0
 public function get(Object $oObject, $aParams = array())
 {
     if (isset($this->aParams['ToModuleAlias'])) {
         Core::import('Modules.' . $this->aParams['ToModuleAlias']);
     }
     $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapperAlias']);
     $aLocCriteria = array($this->aParams['Field'] => $oObject->getId());
     if (!empty($aParams)) {
         if (isset($aParams['Criteria'])) {
             foreach ($aParams['Criteria'] as $key => $val) {
                 $aLocCriteria[$key] = $val;
             }
         }
     }
     $nRelation = $oMapper->findStat('count', 'c', isset($this->aParams['FunctionParams']) ? $this->aParams['FunctionParams'] : '*', array('Criteria' => $aLocCriteria));
     return $nRelation;
 }
 public function set(Object $oObject, $mValue)
 {
     if (isset($this->aParams['ToModuleAlias'])) {
         Core::import('Modules.' . $this->aParams['ToModuleAlias']);
     }
     if (is_array($mValue)) {
         $oObject->aForSaveRelationsData[$this->aParams['Alias']] = array('Delete' => 'all', 'Add' => $mValue);
     }
     /*if (!$oObject->isNew())
             {
                 $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapper']);
                 $aContainer = $oMapper->getContainer();
                 $sClassName = $aContainer['Object'];
     
                 if (is_array($mValue))
                 {
                     // Удаляем все что есть
                     $oQuery = new DbUpdater(DbUpdater::TYPE_DELETE, $aContainer['TableName'], $sClassName, $this->getDbConnectionAlias());
                     $oCriteria = new CriteriaElement($this->aParams['Field'], Criteria::EQUAL, (int)$oObject->getId());
     
                     $oQuery->addCriteria($this->parseUpdateCriteria($oCriteria->renderWhere()));
     
                     return $oQuery->delete();
     
                     if (count($mValue))
                     {
                         foreach ($mValue as $val) 
                         {
                             // сохраняем в базу
                             $oQuery = new DbUpdater(DbUpdater::TYPE_INSERT, $aContainer['TableName'], $sClassName, $this->getDbConnectionAlias());
                             $oQuery->setElement(array(
                                 $this->aParams['Field'] => (int)$oObject->getId(),
                                 $this->aParams['Field2'] => $val
                             ));
     
                             return $oQuery->insert();
                         }
                     }
                 }
     
                 return true;
             }*/
     return false;
 }
 public function set(Object $oObject, $mValue)
 {
     if (is_array($mValue) && count($mValue)) {
         if (isset($this->aParams['ToModuleAlias'])) {
             Core::import('Modules.' . $this->aParams['ToModuleAlias']);
         }
         if (is_array($mValue)) {
             $oObject->aForSaveRelationsData[$this->aParams['Alias']] = array('Set' => $mValue);
         }
         /*$result = new SimpleCollection;
         
                     $oMapper = Manager::getInstance()->getMapper($this->aParams['ToMapperAlias']);
                     
                     foreach ($mValue as $k => $itm)
                     {
                         if (!empty($itm['Id']))
                         {
                             $obj = $oMapper->findById($itm['Id']);
                         } else {
                             $obj = $oMapper->create();
                         }
                         
                         unset($itm['Id']);
                         
                         $obj->import($itm);
                         $obj->set($this->aParams['Field'], $oObject->getId());
                         $obj->save();
                         
                         //Core::p($obj);
                         
                         $result->add($obj);
                     }
                     
                     $oObject->simpleSet($this->getAlias(), $result);*/
     }
     return true;
 }
Ejemplo n.º 10
0
 public function renderPackages()
 {
     if (Core::app()->checkInstalledModule($this->assetsModule)) {
         Core::import("Modules." . $this->assetsModule);
         $assetsUrl = Manager::getInstance()->getModule($this->assetsModule)->publishAssets();
         $assetsPath = Manager::getInstance()->getModule($this->assetsModule)->pathAssets();
         $sResult = '';
         if (count($this->aPackages)) {
             foreach ($this->aPackages as $package) {
                 $aPackage = Loader::loadConfigFile($assetsPath . '/' . $package, 'package');
                 if (isset($aPackage['Includes']) && count($aPackage['Includes'])) {
                     foreach ($aPackage['Includes'] as $file) {
                         $sExt = mb_substr($file, mb_strrpos($file, ".") + 1);
                         $file_path = str_replace("~/", $assetsPath . '/' . $package . '/', $file);
                         $file = str_replace("~/", $assetsUrl . '/' . $package . '/', $file);
                         switch ($sExt) {
                             case 'js':
                                 $sResult .= '<script type="text/javascript" src="' . $file . '"></script>';
                                 $sResult .= "\n\t";
                                 break;
                             case 'css':
                                 $sResult .= '<link href="' . $file . '" type="text/css" rel="stylesheet" />';
                                 $sResult .= "\n\t";
                                 break;
                             case 'tpl':
                                 $sResult .= file_get_contents($file_path);
                                 $sResult .= "\n\t";
                                 break;
                         }
                     }
                 }
             }
         }
         return $sResult;
     }
 }
Ejemplo n.º 11
0
 public function component($sModuleAlias, $sComponentAlias, $aParams = array())
 {
     Core::import('Components.' . $sModuleAlias . '.' . $sComponentAlias);
     $sFullClassName = 'ruxon\\modules\\' . $sModuleAlias . '\\components\\' . $sComponentAlias . '\\classes\\' . $sComponentAlias . 'Component';
     $sClassName = $sModuleAlias . $sComponentAlias . 'Component';
     $oComponent = class_exists($sFullClassName) ? new $sFullClassName() : new $sClassName();
     $oComponent->init($aParams);
     $oComponent->run();
     $bLayout = $this->sLayout === false ? false : true;
     $oResponse = new ActionResponse($bLayout);
     $oResponse->setHtml($oComponent->fetch());
     return $oResponse;
 }
Ejemplo n.º 12
0
 public function init()
 {
     if (Core::app()->checkInstalledModule($this->module_alias)) {
         Core::import('Modules.' . $this->module_alias);
     }
 }
Ejemplo n.º 13
0
 protected function init()
 {
     Core::import('Modules.' . $this->_module);
     $this->_path = RX_PATH . '/ruxon/modules/' . $this->_module . '/migrations';
     if ($this->getDbConnection()->tableExists('main_module')) {
         $this->_currentVersion = (int) Manager::getInstance()->getModule($this->_module)->dbRevision();
     } else {
         $this->_currentVersion = 0;
     }
     $this->_versions = array();
     if (is_dir($this->_path)) {
         $files = scandir($this->_path);
         natsort($files);
         foreach ($files as $file) {
             if ($file[0] == '.' || $file[0] == '..') {
                 continue;
             }
             $info = pathinfo($file);
             $tmpData = array('id' => substr($info['filename'], 0, strpos($info['filename'], "_")), 'name' => $info['filename']);
             if (strrpos($info['filename'], ".class") !== false) {
                 // Class
                 include_once $this->_path . '/' . $file;
                 $tmpClassName = substr($file, strpos($file, "_") + 1);
                 $tmpData['className'] = str_replace(".class.php", "", $tmpClassName);
             } else {
                 // Simple
                 $tmpData['migration'] = (include $this->_path . '/' . $file);
             }
             $this->_versions[] = (object) $tmpData;
         }
     }
 }
Ejemplo n.º 14
0
 protected function executeRequest($nStatusCode, $aParams)
 {
     $sModule = $aParams['Module'];
     $sController = 'ruxon\\modules\\' . $sModule . '\\controllers\\' . $aParams['Controller'] . 'Controller';
     $sAction = $aParams['Action'];
     Core::import('Modules.' . $sModule);
     if (!class_exists($sController)) {
         $sController = $aParams['Controller'] . 'Controller';
     }
     Core::app()->theme()->getLayout()->setMetaTitle($aParams['Action'] . ' - ' . $aParams['Controller'] . ' - ' . $aParams['Module']);
     $oController = new $sController($sModule, $aParams['Controller']);
     unset($aParams['Action']);
     unset($aParams['Controller']);
     unset($aParams['Module']);
     $oResult = $oController->run($sAction, $aParams);
     Core::app()->response()->setStatus($nStatusCode);
     if (is_object($oResult)) {
         if ($oResult->getLayout()) {
             Core::app()->theme()->getLayout()->setContent($oResult->getHtml());
             $fullcontent = Core::app()->theme()->fetch();
             Core::app()->response()->setResponseText($fullcontent);
         } else {
             $res = Toolkit::getInstance()->client->renderAjaxScriptFiles();
             $res .= Toolkit::getInstance()->client->renderAjaxCssFiles();
             Core::app()->response()->setResponseText($res . $oResult->getHtml());
         }
     }
     return true;
 }
Ejemplo n.º 15
0
 protected function execute($url, $class, $method, $parameters = NULL, $cache = NULL)
 {
     global $config;
     if ($cache === NULL) {
         $cache = $config['cache']['level'] == 'url';
         $cache_expiry = $config['cache']['expiry'];
     }
     try {
         if ($cache) {
             $cache_file = $config['cache']['directory'] . '/' . sha1($url);
             $buffering = false;
         }
         if ($cache && file_exists($cache_file) && time() - filemtime($cache_file) < $cache_expiry) {
             readfile($cache_file);
             return true;
         } else {
             if ($cache) {
                 ob_start();
                 $buffering = true;
             }
             Core::import($class);
             $controller_name = $class . 'Controller';
             $controller = new $controller_name($parameters);
             if (isset($parameters[0])) {
                 unset($parameters[0]);
             }
             # Don't pass the complete match
             call_user_func_array(array(&$controller, $method), $parameters);
             if ($cache) {
                 file_put_contents($cache_file, ob_get_flush());
                 $buffering = false;
             }
             return $controller;
         }
     } catch (MissingResource $e) {
         if ($cache && $buffering) {
             ob_end_flush();
             $buffering = false;
         }
         return false;
     }
 }
Ejemplo n.º 16
0
 public function init($module)
 {
     Core::import('Modules.' . $module);
 }
Ejemplo n.º 17
0
 /**
  * 加载模块类
  *
  * @param string $filePath 类路径
  * @param bool $initialize 是否自动实例化
  */
 public static function plugin($filePath, $initialize = true)
 {
     if (!$filePath) {
         return;
     }
     if (isset(self::$instances[$filePath])) {
         return self::$instances[$filePath];
     }
     $fileName = Core::import($filePath, PLUGIN_PATH);
     if (!$initialize) {
         return true;
     }
     self::$instances[$filePath] = Core::get_instance($fileName);
     return self::$instances[$filePath];
 }
Ejemplo n.º 18
0
Archivo: func.php Proyecto: hubs/yuncms
/**
 * 载入文件或类
 *
 * @param string $name 文件名称 或带路径的文件名称
 * @param string $folder 文件夹默认为空
 */
function import($name, $folder = '')
{
    return Core::import($name, $folder);
}
Ejemplo n.º 19
0
<?php

Core::import('site.myapp.models');
function example_view($request, $attributes)
{
    $item = new MyAppItem();
    $message = "This is a " . $item->name . " view on " . $item->created;
    return new Response($message);
}