/**
  * Defines how a geopicker widget should be built.
  *
  * @param Dataface_Record $record The Dataface_Record that is being edited.
  * @param array &$field The field configuration data structure that the widget is being generated for.
  * @param HTML_QuickForm The form to which the field is to be added.
  * @param string $formFieldName The name of the field in the form.
  * @param boolean $new Whether this widget is being built for a new record form.
  * @return HTML_QuickForm_element The element that can be added to a form.
  *
  */
 function &buildWidget($record, &$field, $form, $formFieldName, $new = false)
 {
     $factory = Dataface_FormTool::factory();
     $mt = Dataface_ModuleTool::getInstance();
     $mod = $mt->loadModule('modules_geopicker');
     $widget =& $field['widget'];
     $atts = array();
     if (!@$atts['class']) {
         $atts['class'] = '';
     }
     $atts['class'] .= ' xf-geopicker';
     $atts['df:cloneable'] = 1;
     $perms = $record->getPermissions(array('field' => $field['name']));
     $noEdit = ($new and !@$perms['new']) or !$new and !@$perms['edit'];
     if ($noEdit) {
         $atts['data-geopicker-read-only'] = "1";
     }
     $mod->registerPaths();
     // Add our javascript
     Dataface_JavascriptTool::getInstance()->import('xataface/modules/geopicker/widgets/geopicker.js');
     $el = $factory->addElement('text', $formFieldName, $widget['label'], $atts);
     if (PEAR::isError($el)) {
         throw new Exception($el->getMessage(), $el->getCode());
     }
     return $el;
 }
 public function handle($params)
 {
     $uitk = Dataface_ModuleTool::getInstance()->loadModule('modules_uitk');
     $uitk->registerPaths();
     Dataface_JavascriptTool::getInstance()->import('swete/actions/import_translations.js');
     df_display(array(), 'swete/actions/import_translations.html');
 }
示例#3
0
文件: g2.php 项目: minger11/Pipeline
 /**
  * @brief Returns the base URL to this module's directory.  Useful for including
  * Javascripts and CSS.
  *
  */
 public function getBaseURL()
 {
     if (!isset($this->baseURL)) {
         $this->baseURL = Dataface_ModuleTool::getInstance()->getModuleURL(__FILE__);
     }
     return $this->baseURL;
 }
 /**
  * Defines how a depselect widget should be built.
  *
  * @param Dataface_Record $record The Dataface_Record that is being edited.
  * @param array &$field The field configuration data structure that the widget is being generated for.
  * @param HTML_QuickForm The form to which the field is to be added.
  * @param string $formFieldName The name of the field in the form.
  * @param boolean $new Whether this widget is being built for a new record form.
  * @return HTML_QuickForm_element The element that can be added to a form.
  *
  */
 function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false)
 {
     $factory = Dataface_FormTool::factory();
     $mt = Dataface_ModuleTool::getInstance();
     $mod = $mt->loadModule('modules_depselect');
     //$atts = $el->getAttributes();
     $widget =& $field['widget'];
     $atts = array();
     if (!@$atts['class']) {
         $atts['class'] = '';
     }
     $atts['class'] .= ' xf-depselect';
     if (!@$atts['data-xf-table']) {
         $atts['data-xf-table'] = $field['tablename'];
     }
     $targetTable = Dataface_Table::loadTable($field['widget']['table']);
     if (PEAR::isError($targetTable)) {
         error_log("Your field {$formFieldName} is missing the widget:table directive or the table does not exist.");
         throw new Exception("Your field {$formFieldName} is missing the widget:table directive or the table does not exist.");
     }
     $targetPerms = $targetTable->getPermissions();
     $atts['data-xf-depselect-options-table'] = $field['widget']['table'];
     if (@$targetPerms['new']) {
         $atts['data-xf-depselect-perms-new'] = 1;
     }
     $atts['df:cloneable'] = 1;
     $jt = Dataface_JavascriptTool::getInstance();
     $jt->addPath(dirname(__FILE__) . '/js', $mod->getBaseURL() . '/js');
     $ct = Dataface_CSSTool::getInstance();
     $ct->addPath(dirname(__FILE__) . '/css', $mod->getBaseURL() . '/css');
     // Add our javascript
     $jt->import('xataface/widgets/depselect.js');
     $filters = array();
     if (@$field['widget']['filters'] and is_array($field['widget']['filters'])) {
         foreach ($field['widget']['filters'] as $key => $val) {
             $filters[] = urlencode($key) . '=' . urlencode($val);
         }
     }
     $atts['data-xf-depselect-filters'] = implode('&', $filters);
     if (@$field['widget']['nomatch']) {
         $atts['data-xf-depselect-nomatch'] = $field['widget']['nomatch'];
     }
     if (@$field['widget']['dialogSize']) {
         $atts['data-xf-depselect-dialogSize'] = $field['widget']['dialogSize'];
     }
     if (@$field['widget']['dialogMargin']) {
         $atts['data-xf-depselect-dialogMargin'] = $field['widget']['dialogMargin'];
     }
     //$el->setAttributes($atts);
     $el = $factory->addElement('depselect', $formFieldName, $widget['label'], $atts);
     if (PEAR::isError($el)) {
         throw new Exception($el->getMessage(), $el->getCode());
     }
     return $el;
 }
示例#5
0
 function process($vals)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $grid = $mod->createDataGrid($vals['title'], $query['-table'], $vals['fields']);
     $res = $mod->saveDataGrid($grid);
     return $res;
 }
示例#6
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $res = mysql_query("select gridID,gridName from dataface__DataGrids where tableName='" . addslashes($query['-table']) . "'", df_db());
     $grids = array();
     while ($row = mysql_fetch_assoc($res)) {
         $grids[$row['gridID']] = array('name' => $row['gridName'], 'url' => $app->url('-gridid=' . $row['gridID'] . '&-action=DataGrid_view'));
     }
     //print_r($grids);
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     df_display(array('grids' => $grids), 'DataGrid/list.html');
 }
示例#7
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     // We need to load the current data grid from the database.
     // Its id is provided in the -gridid request parameter.
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     if (!@$query['-gridid']) {
         // No grid was specified.. so we will just take the first grid
         $grids = $mod->getDataGrids();
         if (!$grids) {
             // No grids were found.  We need to create one
             $table =& Dataface_Table::loadTable($query['-table']);
             $grid = $mod->createDataGrid($query['-table'] . ' default grid', $query['-table'], array_keys($table->fields()));
             $res = $mod->saveDataGrid($grid);
             if (PEAR::isError($res)) {
                 return $res;
             }
             $dataGrid =& $grid;
         } else {
             $dataGrid = $grids[0];
         }
     }
     if (PEAR::isError($dataGrid)) {
         return $dataGrid;
     }
     if (!@$dataGrid) {
         $dataGrid =& $mod->getDataGrid($query['-gridid']);
     }
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     $json = new Services_JSON();
     $jsonFieldDefs = $json->encode($dataGrid->getFieldDefs(true));
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     df_display(array('grid' => &$dataGrid, 'fieldDefs' => $jsonFieldDefs, 'json' => &$json), 'DataGrid/view.html');
 }
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $json = new Services_JSON();
     if (!@$query['-data']) {
         $this->error('No Data was provided');
     }
     $updates = $json->decode($query['-data']);
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $dataGrid = $mod->getDataGrid($query['-gridid']);
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     $result = array();
     foreach ($updates as $recordID => $vals) {
         $res = $dataGrid->saveRow($recordID, $vals, true);
         if (is_array($res)) {
             foreach ($res as $err) {
                 $result['errors'][$recordID] = $err->getMessage();
             }
         } else {
             if (PEAR::isError($res)) {
                 $result['errors'][strval($recordID)] = $res->getMessage();
             } else {
                 if (is_a($res, 'Dataface_Record')) {
                     $result['updated_rows'][$recordID] = $dataGrid->buildRow($res);
                 }
             }
         }
     }
     $result['success'] = 1;
     header('Content-type: text/json');
     echo $json->encode($result);
     exit;
 }
示例#9
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     if (!is_array(@$app->_conf['_modules'])) {
         $app->_conf['_modules'] = array();
     }
     if (!isset($app->_conf['_modules']['Dataface_TranslationTool'])) {
         $app->_conf['_modules']['Dataface_TranslationTool'] = 'Dataface/TranslationTool.php';
     }
     $context = array();
     $mt =& Dataface_ModuleTool::getInstance();
     if (count($_POST) > 0) {
         $modules = $_POST['modules'];
         $log = $mt->migrate(array_keys($modules));
         $context['log'] = $log;
     } else {
         $context['migrations'] = $mt->getMigrations();
         ob_start();
         //$form->display();
         $context['form'] = ob_get_contents();
         ob_end_clean();
     }
     df_display($context, 'actions_manage_migrate.html');
 }
示例#10
0
require_once 'inc/SweteTools.php';
class test_SweteTools extends PHPUnit_TestCase
{
    function test_SweteTools($name = 'test_SweteTools')
    {
        $this->PHPUnit_TestCase($name);
    }
    function setUp()
    {
    }
    function tearDown()
    {
    }
    function testNormalizeUrl()
    {
        $strs = array('http://xataface.com/index.php?foo=1&bar=2&foo=3' => 'http://xataface.com/index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3' => 'index.php?bar=2&foo=1&foo=3', 'http://xataface.com/index.php?foo=1&bar=2&foo=3#hello_world' => 'http://xataface.com/index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3#hello_world' => 'index.php?bar=2&foo=1&foo=3', '/index.php?foo=1&bar=2&foo=3#hello_world' => '/index.php?bar=2&foo=1&foo=3', '../index.php?foo=1&bar=2&foo=3#hello_world' => '../index.php?bar=2&foo=1&foo=3', 'index.php?foo=1&bar=2&foo=3#hello_world?foo=15' => 'index.php?bar=2&foo=1&foo=3', 'https://xataface.com/index.php?foo=1&bar=2&foo=3' => 'https://xataface.com/index.php?bar=2&foo=1&foo=3');
        foreach ($strs as $k => $v) {
            $this->assertEquals($v, SweteTools::normalizeUrl($k));
        }
    }
    function testAbsoluteUrl()
    {
        $tests = array(array('base' => 'http://solutions.weblite.ca/', 'in' => 'index.html', 'out' => 'http://solutions.weblite.ca/index.html'), array('base' => 'http://solutions.weblite.ca/', 'in' => '/index.html', 'out' => 'http://solutions.weblite.ca/index.html'), array('base' => 'http://solutions.weblite.ca/foo/', 'in' => '/index.html', 'out' => 'http://solutions.weblite.ca/index.html'), array('base' => 'http://solutions.weblite.ca', 'in' => 'index.html', 'out' => 'http://solutions.weblite.ca/index.html'), array('base' => 'http://solutions.weblite.ca/foo', 'in' => 'index.html', 'out' => 'http://solutions.weblite.ca/foo/index.html'), array('base' => 'http://solutions.weblite.ca/foo/', 'in' => 'index.html', 'out' => 'http://solutions.weblite.ca/foo/index.html'), array('base' => 'https://foo.bar.com/foo/', 'in' => 'http://foo.bar.com/foo/index.html', 'out' => 'http://foo.bar.com/foo/index.html'), array('base' => 'https://foo.bar.com/foo/', 'in' => '//foo.bar.com/foo/index.html', 'out' => 'https://foo.bar.com/foo/index.html'), array('base' => 'http://foo.bar.com/foo/', 'in' => 'index.html?go=1&bar=2', 'out' => 'http://foo.bar.com/foo/index.html?go=1&bar=2'));
        foreach ($tests as $test) {
            $this->assertEquals($test['out'], SweteTools::absoluteUrl($test['in'], $test['base']), 'Converting ' . $test['in'] . ', ' . $test['base']);
        }
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('test_SweteTools');
示例#11
0
        $client->URL = df_absolute_url('tests/test_ProxyClient/test1.html');
        $outputFile = tempnam(sys_get_temp_dir(), 'test_ProxyClient');
        $client->outputFile = $outputFile;
        $client->process();
        $this->assertEquals(null, $client->content, 'Content should be written to output file, not saved to variable.');
        $expected = file_get_contents('tests/test_ProxyClient/test1.html');
        $doc = new DOMDocument();
        @$doc->loadHtml($expected);
        $expected = $doc->saveHtml();
        $actual = file_get_contents($outputFile);
        $actual = '';
        $fh = fopen($outputFile, 'r');
        while (!feof($fh) and trim($line = fgets($fh, 1024))) {
            // We skip the headers
        }
        ob_start();
        fpassthru($fh);
        fclose($fh);
        $actual = ob_get_contents();
        ob_end_clean();
        unset($doc);
        $doc = new DOMDocument();
        @$doc->loadHtml($actual);
        $actual = $doc->saveHtml();
        unset($doc);
        $this->assertEquals($expected, $actual);
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('test_ProxyClient');
示例#12
0
        $q = "select * from formulas limit 4";
        $reader = new Dataface_ResultReader($q, df_db(), 3);
        $result = array();
        foreach ($reader as $key => $record) {
            $result[$key] = $record;
        }
        $this->assertEquals(4, count($result));
        $this->assertEquals('Test formula', $result[0]->formula_name);
        $this->assertEquals('Test formula Copy', $result[3]->formula_name);
        $q = "select * from formulas limit 1,4";
        $reader = new Dataface_ResultReader($q, df_db(), 3);
        $result = array();
        foreach ($reader as $key => $record) {
            $result[$key] = $record;
        }
        $this->assertEquals(4, count($result));
        $this->assertEquals('Test formula Copy', $result[1]->formula_name);
        $this->assertEquals('Test formula Copy Again', $result[4]->formula_name);
    }
    static function q($sql)
    {
        $res = xf_db_query($sql, df_db());
        if (!$res) {
            throw new Exception(xf_db_error(df_db()));
        }
        return $res;
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('xataface_Dataface_RecordTest');
示例#13
0
 /**
  * Handle a request.  This method is the starting point for all Dataface application requests.
  * It will delegate the request to the appropriate handler.
  * The order of delegation is as follows:
  *  0. Uses the ActionTool to check permissions for the action.  If permissions are not granted,
  *		dispatch the error handler.  If permissions are granted then we continue down the delegation
  *		chain.
  *  1. If the current table's delegate class defines a handleRequest() method, then call that.
  *	2. If the current table's delegate class does not have a handleRequest() method or that method
  *		returns a PEAR_Error object with code E_DATAFACE_REQUEST_NOT_HANDLED, then check for a handler
  *		bearing the name of the action in one of the actions directories.  Check the directories 
  *		in the following order:
  *		a. <site url>/tables/<table name>/actions
  *		b. <site url>/actions
  *		b. <dataface url>/actions
  *	3. If no handler can be found then use the default handler.  The default handler can be quite 
  *		powerful as it accepts the '-template' query parameter to use a specific template for display.
  */
 function handleRequest($disableCache = false)
 {
     if (!$disableCache and @$_GET['-action'] != 'getBlob' and isset($this->_conf['_output_cache']) and @$this->_conf['_output_cache']['enabled'] and count($_POST) == 0) {
         import('Dataface/OutputCache.php');
         $oc = new Dataface_OutputCache($this->_conf['_output_cache']);
         $oc->ob_start();
     }
     import('Dataface/ActionTool.php');
     import('Dataface/PermissionsTool.php');
     import('Dataface/Table.php');
     $applicationDelegate = $this->getDelegate();
     if (isset($applicationDelegate) and method_exists($applicationDelegate, 'beforeHandleRequest')) {
         // Do whatever we need to do before the request is handled.
         $applicationDelegate->beforeHandleRequest();
     }
     // Set up security filters
     $query =& $this->getQuery();
     $table = Dataface_Table::loadTable($query['-table']);
     //$table->setSecurityFilter();
     /*
      * Set up some preferences for the display of the application.
      * These can be overridden by the getPreferences() method in the
      * application delegate class.
      */
     if (isset($this->_conf['_prefs']) and is_array($this->_conf['_prefs'])) {
         $this->prefs = array_merge($this->prefs, $this->_conf['_prefs']);
     }
     if (@$this->_conf['hide_nav_menu']) {
         $this->prefs['show_tables_menu'] = 0;
     }
     if (@$this->_conf['hide_view_tabs']) {
         $this->prefs['show_table_tabs'] = 0;
     }
     if (@$this->_conf['hide_result_controller']) {
         $this->prefs['show_result_controller'] = 0;
     }
     if (@$this->_conf['hide_table_result_stats']) {
         $this->prefs['show_result_stats'] = 0;
     }
     if (@$this->_conf['hide_search']) {
         $this->prefs['show_search'] = 0;
     }
     if (!isset($this->prefs['disable_ajax_record_details'])) {
         $this->prefs['disable_ajax_record_details'] = 1;
     }
     if ($query['-action'] == 'login_prompt') {
         $this->prefs['no_history'] = 1;
     }
     if (isset($applicationDelegate) and method_exists($applicationDelegate, 'getPreferences')) {
         $this->prefs = array_merge($this->prefs, $applicationDelegate->getPreferences());
     }
     // Check to make sure that this table hasn't been disallowed
     $disallowed = false;
     if (isset($this->_conf['_disallowed_tables'])) {
         foreach ($this->_conf['_disallowed_tables'] as $name => $pattern) {
             if ($pattern[0] == '/' and preg_match($pattern, $query['-table'])) {
                 $disallowed = true;
                 break;
             } else {
                 if ($pattern == $query['-table']) {
                     $disallowed = true;
                     break;
                 }
             }
         }
     }
     if ($disallowed and isset($this->_conf['_allowed_tables'])) {
         foreach ($this->_conf['_allowed_tables'] as $name => $pattern) {
             if ($pattern[0] == '/' and preg_match($pattern, $query['-table'])) {
                 $disallowed = false;
                 break;
             } else {
                 if ($pattern == $query['-table']) {
                     $disallowed = false;
                     break;
                 }
             }
         }
     }
     if ($disallowed) {
         return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate("Permission Denied. This table has been disallowed in the conf.ini file", "Permission denied because this table has been disallowed in the conf.ini file '"));
     }
     $actionTool = Dataface_ActionTool::getInstance();
     //if ( $this->_conf['multilingual_content'] ){
     //import('I18Nv2/I18Nv2.php');
     //I18Nv2::autoConv();
     //}
     $params = array('table' => $query['-table'], 'name' => $query['-action']);
     if (strpos($query['-action'], 'custom_') === 0) {
         $action = array('name' => $query['-action'], 'page' => substr($query['-action'], 7), 'permission' => 'view', 'mode' => 'browse', 'custom' => true);
     } else {
         $action = $actionTool->getAction($params);
         if (is_array($action) and @$action['related'] and @$query['-relationship'] and preg_match('/relationships\\.ini/', @$action['allow_override'])) {
             // This action is to be performed on the currently selected relationship.
             $raction = $table->getRelationshipsAsActions(array(), $query['-relationship']);
             if (is_array($raction)) {
                 $action = array_merge($action, $raction);
             }
         }
         if (is_array($action) and isset($action['delegate'])) {
             $params['name'] = $query['-action'] = $action['delegate'];
             $tmp = $actionTool->getActions($params);
             unset($action);
             $action =& $tmp;
             unset($tmp);
         }
         if (is_array($action) and isset($action['auth_type'])) {
             $authTool = $this->getAuthenticationTool();
             $authTool->setAuthType($action['auth_type']);
         }
     }
     if ((PEAR::isError($action) or !@$action['permission']) and $this->_conf['security_level'] >= DATAFACE_STRICT_PERMISSIONS) {
         // The only reason getAction() will return an error is if the specified action could not be found.
         // If the application is set to use strict permissions and no action was defined in the ini file
         // then this action cannot be performed.  Strict permissions mode requires that permissions be
         // strictly set or permission will be denied.
         return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate("Permission Denied. No action found in strict permissions mode", "Permission denied for action '" . $query['-action'] . "'.  No entry for this action was found in the actions.ini file.  \n\t\t\t\t\tYou are currently using strict permissions mode which requires that you define all actions that you want to use in the actions.ini file with appropriate permissions information.", array('action' => $query['-action'])));
     } else {
         if (PEAR::isError($action)) {
             $action = array('name' => $query['-action'], 'label' => $query['-action']);
         }
     }
     // Step 1:  See if the delegate class has a handler.
     $delegate = $table->getDelegate();
     $handled = false;
     if (method_exists($delegate, 'handleRequest')) {
         $result = $delegate->handleRequest();
         if (PEAR::isError($result) and $result->getCode() === DATAFACE_E_REQUEST_NOT_HANDLED) {
             $handled = false;
         } else {
             if (PEAR::isError($result)) {
                 return $result;
             } else {
                 $handled = true;
             }
         }
     }
     if (isset($action['mode']) and $action['mode']) {
         $query['-mode'] = $action['mode'];
     }
     // Step 2: Look to see if there is a handler defined
     if (isset($action['custom'])) {
         $locations = array(DATAFACE_PATH . '/actions/custom.php' => 'dataface_actions_custom');
     } else {
         $locations = array();
         $locations[DATAFACE_SITE_PATH . '/tables/' . basename($query['-table']) . '/actions/' . basename($query['-action']) . '.php'] = 'tables_' . $query['-table'] . '_actions_' . $query['-action'];
         $locations[DATAFACE_SITE_PATH . '/actions/' . basename($query['-action']) . '.php'] = 'actions_' . $query['-action'];
         if (isset($this->_conf['_modules']) and count($this->_conf['_modules']) > 0) {
             $mt = Dataface_ModuleTool::getInstance();
             foreach ($this->_conf['_modules'] as $modname => $modpath) {
                 $mt->loadModule($modname);
                 if ($modpath[0] == '/') {
                     $locations[dirname($modpath) . '/actions/' . basename($query['-action']) . '.php'] = 'actions_' . $query['-action'];
                 } else {
                     $locations[DATAFACE_SITE_PATH . '/' . dirname($modpath) . '/actions/' . basename($query['-action']) . '.php'] = 'actions_' . $query['-action'];
                     $locations[DATAFACE_PATH . '/' . dirname($modpath) . '/actions/' . basename($query['-action']) . '.php'] = 'actions_' . $query['-action'];
                 }
             }
         }
         $locations[DATAFACE_PATH . '/actions/' . basename($query['-action']) . '.php'] = 'dataface_actions_' . $query['-action'];
         $locations[DATAFACE_PATH . '/actions/default.php'] = 'dataface_actions_default';
     }
     $doParams = array('action' => &$action);
     //parameters to be passed to the do method of the handler
     foreach ($locations as $handlerPath => $handlerClassName) {
         if (is_readable($handlerPath)) {
             import($handlerPath);
             $handler = new $handlerClassName();
             $params = array();
             if (is_array($action) and @$action['related'] and @$query['-relationship']) {
                 $params['relationship'] = $query['-relationship'];
             }
             if (!PEAR::isError($action) and method_exists($handler, 'getPermissions')) {
                 // check the permissions on this action to make sure that we are 'allowed' to perform it
                 // this method will return an array of Strings that are names of permissions granted to
                 // the current user.
                 //echo "Checking permissions:";
                 //print_r($params);
                 $permissions = $handler->getPermissions($params);
                 //} else if ( $applicationDelegate !== null and method_exists($applicationDelegate, 'getPermissions') ){
                 //	$permissions =& $applicationDelegate->getPermissions($params);
             } else {
                 //print_r($params);
                 //print_r($action);
                 $permissions = $this->getPermissions($params);
             }
             if (isset($action['permission']) && !(isset($permissions[$action['permission']]) and $permissions[$action['permission']])) {
                 return Dataface_Error::permissionDenied(Dataface_LanguageTool::translate("Permission Denied for action.", "Permission to perform action '" . $action['name'] . "' denied.  \n\t\t\t\t\t\t\tRequires permission '" . $action['permission'] . "' but only granted '" . Dataface_PermissionsTool::namesAsString($permissions) . "'.", array('action' => $action, 'permissions_granted' => Dataface_PermissionsTool::namesAsString($permissions))));
             }
             if (method_exists($handler, 'handle')) {
                 $result = $handler->handle($doParams);
                 if (PEAR::isError($result) and $result->getCode() === DATAFACE_E_REQUEST_NOT_HANDLED) {
                     continue;
                 }
                 return $result;
             }
         }
     }
     trigger_error(df_translate('scripts.Dataface.Application.handleRequest.NO_HANDLER_FOUND', "No handler found for request.  This should never happen because, at the very least, the default handler at dataface/actions/default.php should be called.  Check the permissions on dataface/actions/default.php to make sure that it is readable by the web server.") . Dataface_Error::printStackTrace(), E_USER_ERROR);
 }
示例#14
0
	<div>{{$0$}}</div>
	<div>{{$1$}}</div>
</body></html>');
        $tr = new WebLite_HTML_Translator();
        $extracted = $tr->extractStrings($html);
        $tr = new WebLite_HTML_Translator();
        $extracted = $tr->extractStrings($html);
        $this->assertEquals(trim($expected), trim($extracted));
        $expected = array(0 => 'Entrées', 1 => 'Test2');
        $this->assertEquals($expected, $tr->strings);
    }
    function testExtractStringsKarelia()
    {
        $s = DIRECTORY_SEPARATOR;
        $html = file_get_contents(dirname(__FILE__) . $s . 'testsites' . $s . 'site3' . $s . 'index.html');
        $tr = new WebLite_HTML_Translator();
        $extracted = $tr->extractStrings($html);
        //echo $extracted;exit;
        $expected = file_get_contents(dirname(__FILE__) . $s . 'testsites' . $s . 'site3' . $s . 'index.extracted.html');
        $this->assertEquals(trim($expected), trim($extracted));
        $expected = file_get_contents(dirname(__FILE__) . $s . 'testsites' . $s . 'site3' . $s . 'index.strings.json');
        $expected = json_decode($expected, true);
        $this->assertEquals($expected, $tr->strings);
    }
    function tearDown()
    {
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('test_Translator');
示例#15
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $dataGrid = $mod->getDataGrid($query['-gridid']);
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     import('Dataface/XMLTool.php');
     $xmlTool = new Dataface_XMLTool();
     $records = df_get_records_array($query['-table'], $query, null, null, false);
     $rows = array();
     $fieldDefs = $dataGrid->getFieldDefs();
     foreach ($records as $record) {
         $row = array();
         $row['__recordID__'] = $record->getId();
         foreach ($fieldDefs as $colName => $fieldDef) {
             if (strpos($colName, '#') === false) {
                 // No index was provided so index is 0
                 $index = 0;
                 $fieldName = $colName;
             } else {
                 list($fieldName, $index) = explode('#', $colName);
             }
             $row[str_replace('.', '-', $colName)] = $xmlTool->xmlentities($record->strval($fieldName, $index));
         }
         $rows[] = $row;
         unset($record);
     }
     if (@$_GET['--format'] == 'csv') {
         import('actions/export_csv.php');
         $temp = tmpfile();
         $headings = array();
         if ($rows) {
             foreach ($fieldDefs as $key => $val) {
                 $headings[] = $val['widget']['label'];
             }
         }
         fputcsv($temp, $headings, ",", '"');
         foreach ($rows as $row) {
             $thisrow = array();
             foreach ($row as $key => $val) {
                 if ($key != '__recordID__') {
                     $thisrow[] = $val;
                 }
             }
             fputcsv($temp, $thisrow, ",", '"');
         }
         fseek($temp, 0);
         header("Content-type: text/csv; charset=" . $app->_conf['oe']);
         header('Content-disposition: attachment; filename="' . $query['-table'] . '_' . $dataGrid->name . '_export_' . date('Y_m_d_H_i_s') . '.csv"');
         $fstats = fstat($temp);
         echo fread($temp, $fstats['size']);
         fclose($temp);
     } else {
         header("Content-type: application/xml; charset=" . $app->_conf['oe']);
         df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
         df_display(array('rows' => &$rows), 'DataGrid/datastore.xml');
     }
     exit;
 }
import('HTML/QuickForm/select.php');
class xataface_HTML_QuickForm_select extends PHPUnit_TestCase
{
    function xataface_Dataface_RecordTest($name = 'xataface_HTML_QuickForm_select')
    {
        $this->PHPUnit_TestCase($name);
    }
    function setUp()
    {
    }
    function tearDown()
    {
    }
    /**
     * This test was created to test the change to preg_split() in setValues() due
     * to the PHP 5.3 deprecation of the split() function.
     * http://bugs.weblite.ca/view.php?id=809
     */
    function testPregSplit()
    {
        $select = new HTML_QuickForm_select('test', 'Test', array('a1' => 'Tom', 'b2' => 'Dick', 'c3' => 'Harry'));
        $select->setMultiple(true);
        $select->setSelected('a1');
        $this->assertEquals(array(0 => 'a1'), $select->getSelected(), 'setSelected failed to select value.');
        $select->setSelected('a1, c3');
        $this->assertEquals(array(0 => 'a1', 1 => 'c3'), $select->getSelected(), 'setSelectedFailed to select double value.');
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('xataface_HTML_QuickForm_select');
示例#17
0
    function update_4797()
    {
        import('Dataface/Table.php');
        Dataface_ModuleTool::getInstance()->loadModule('modules_tm');
        $sql[] = "CREATE VIEW `swete_strings` AS\n            select  s.string_id,\n                    s.normalized_value as normalized_string,\n                    s.normalized_value as string,\n                    s.num_words,\n                    t.normalized_translation_value,\n                    if(tml.webpage_id is null,hrl.proxy_request_url, concat(ws.website_url,w.webpage_url)) as request_url,\n                    ifnull(tml.translation_memory_id,tm.translation_memory_id) as translation_memory_id,\n                    ifnull(tm2.translation_memory_uuid, tm.translation_memory_uuid) as translation_memory_uuid,\n                    ifnull(tm2.translation_memory_name,tm.translation_memory_name) as translation_memory_name,\n                    ifnull(tm2.source_language,tm.source_language) as source_language,\n                    ifnull(tm2.destination_language, tm.destination_language) as destination_language,\n                    ws.website_name,\n                    ws.website_id,\n                    tml.date_inserted\n                    from \n                    xf_tm_strings s\n                    left join xf_tm_translation_memory_strings tms on s.string_id=tms.string_id\n                    left join xf_tm_translations t on tms.current_translation_id=t.translation_id\n                    left join xf_tm_translation_memories tm on tms.translation_memory_id=tm.translation_memory_id\n                    left join translation_miss_log tml on tml.string_id=s.string_id \n                    left join xf_tm_translation_memories tm2 on tml.translation_memory_id=tm2.translation_memory_id\n                    left join http_request_log hrl on tml.http_request_log_id=hrl.http_request_log_id\n                    left join webpages w on tml.webpage_id=w.webpage_id\n                    left join websites ws on tml.website_id=ws.website_id\n                    where ifnull(tml.translation_memory_id,tm.translation_memory_id) IS NOT NULL\n            ";
        df_q($sql);
        $res = df_q('select distinct `target_language` from websites');
        $languages = array();
        while ($row = mysql_fetch_row($res)) {
            $languages[] = $row[0];
        }
        @mysql_free_result($res);
        $res = df_q('select distinct `source_language` from websites');
        while ($row = mysql_fetch_row($res)) {
            $languages[] = $row[0];
        }
        @mysql_free_result($res);
        $languages = array_unique($languages);
        $missing = $languages;
        foreach ($missing as $lang) {
            if (!preg_match('/^[a-zA-Z0-9]{2}/', $lang)) {
                throw new Exception("Invalid language code " . $lang);
            }
            $sql = <<<END
CREATE TABLE IF NOT EXISTS `swete_strings_{$lang}` (
`string_id` int(11) unsigned not null,
`translation_memory_id` int(11) unsigned not null,
`string` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`string_id`,`translation_memory_id`)
) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
END;
            df_q($sql);
        }
    }
示例#18
0
        $this->assertEquals('BackgroundProcess', $prec->val('process_class'));
        $this->assertEquals(0, intval($prec->val('running')));
        $this->assertEquals(0, intval($prec->val('complete')));
        $this->assertEquals(0, intval($prec->val('error')));
        $res = BackgroundProcess::runProcesses();
        $this->assertTrue($res);
        if ($res) {
            $prec = df_get_record('background_processes', array('process_id' => '=' . $process->getProcessId()));
            $this->assertTrue($prec instanceof Dataface_Record);
            $this->assertTrue(isset($prec));
            if ($prec) {
                $this->assertEquals($process->getProcessId(), $prec->val('process_id'));
                $this->assertEquals('BackgroundProcess', $prec->val('process_class'));
                $this->assertEquals(0, intval($prec->val('running')));
                $this->assertEquals(1, intval($prec->val('complete')));
                $this->assertEquals(0, intval($prec->val('error')));
            }
        }
    }
    static function q($sql)
    {
        $res = mysql_query($sql, df_db());
        if (!$res) {
            throw new Exception(mysql_error(df_db()));
        }
        return $res;
    }
}
// Add this test to the suite of tests to be run by the testrunner
Dataface_ModuleTool::getInstance()->loadModule('modules_testrunner')->addTest('test_BackgroundProcess');
示例#19
0
文件: Table.php 项目: promoso/HVAC
 /**
  * Displays a block from the delegate class.  Blocks are defined in the delegate
  * class by defining methods with names starting with 'block__'.  Eg: block__header()
  * @param blockName The name of the block.
  * @param params Associative array of key/value pairs to pass to the block.
  *
  */
 function displayBlock($blockName, $params = array())
 {
     if (@$this->app->_conf['debug']) {
         echo "<div class=\"debug_marker\">Block &quot;{$blockName}&quot;</div>";
     }
     $delegate =& $this->getDelegate();
     //echo "Checking for block $blockName";
     $res = false;
     // Add the ability for Modules to define blocks without conflicting with
     // defined blocks in the application.
     // Added Feb. 28, 2007 by Steve Hannah for 0.6.14 release.
     $mres = false;
     if (isset($this->app->_conf['_modules']) and count($this->app->_conf['_modules']) > 0) {
         $mtool =& Dataface_ModuleTool::getInstance();
         $mres = $mtool->displayBlock($blockName, $params);
     }
     if (isset($delegate) and method_exists($delegate, 'block__' . $blockName)) {
         $methodname = 'block__' . $blockName;
         $fres = $delegate->{$methodname}($params);
         //$fres = call_user_func(array(&$delegate, 'block__'.$blockName), $params);
         if (!PEAR::isError($fres)) {
             $res = true;
         }
     } else {
         $appDelegate =& $this->app->getDelegate();
         if (isset($appDelegate) and method_exists($appDelegate, 'block__' . $blockName)) {
             $methodname = 'block__' . $blockName;
             $fres = $appDelegate->{$methodname}($params);
             //$fres = call_user_func(array(&$appDelegate, 'block__'.$blockName), $params);
             if (!PEAR::isError($fres)) {
                 $res = true;
             }
         }
     }
     return $res or $mres;
 }
示例#20
0
 function handle($params)
 {
     session_write_close();
     header('Connection: close');
     $app = Dataface_Application::getInstance();
     $query = $app->getQuery();
     $table = Dataface_Table::loadTable($query['-table']);
     $customPath = Dataface_Table::getBasePath($table->tablename);
     $findPath = $customPath . DIRECTORY_SEPARATOR . basename($table->tablename) . DIRECTORY_SEPARATOR . 'find.html';
     if (file_exists($findPath)) {
         $html = file_get_contents($findPath);
     } else {
         $fields = array_keys($table->fields(false, true));
         $temp = $fields;
         foreach ($temp as $k => $v) {
             $fperms = $table->getPermissions(array('field' => $v));
             if (!@$fperms['find']) {
                 unset($fields[$k]);
             }
         }
         foreach ($table->relationships() as $relationship) {
             if (@$relationship->_schema['visibility'] and @$relationship->_schema['visibility']['find'] == 'hidden') {
                 continue;
             }
             $rperms = $table->getPermissions(array('relationship' => $relationship->getName()));
             if (!@$rperms['find']) {
                 continue;
             }
             $rfields = $relationship->fields(true);
             $fkeys = $relationship->getForeignKeyValues();
             $removedKeys = array();
             foreach ($fkeys as $fkeyTable => $fkey) {
                 foreach (array_keys($fkey) as $fkeyKey) {
                     $removedKeys[] = $fkeyTable . '.' . $fkeyKey;
                 }
             }
             $rfields = array_diff($rfields, $removedKeys);
             foreach ($rfields as $rfield) {
                 list($rtable, $rfield) = explode('.', $rfield);
                 //$rfperms = $table->getPermissions(array('relationship' => $relationship->getName(), 'field'=>$rfield));
                 $rfperms = $relationship->getPermissions(array('field' => $rfield));
                 if (@$rfperms['find']) {
                     $fields[] = $relationship->getName() . '.' . $rfield;
                 }
             }
             unset($rfields);
             unset($relationship);
         }
         $finalFields = array();
         foreach ($fields as $fieldname) {
             $finalFields[$fieldname] =& $table->getField($fieldname);
             if (@$finalFields[$fieldname]['visibility']['find'] == 'hidden') {
                 unset($finalFields[$fieldname]);
                 continue;
             }
             $tbl = Dataface_Table::loadTable($finalFields[$fieldname]['tablename']);
             if ($tbl->isDate($finalFields[$fieldname]['name'])) {
                 $finalFields[$fieldname]['find']['type'] = 'date';
             }
         }
         $context['fields'] = array();
         $context['relatedFields'] = array();
         foreach ($finalFields as $k => $fld) {
             if (strpos($k, '.') !== false) {
                 list($rel, $fldname) = explode('.', $k);
                 $relationship = $table->getRelationship($rel);
                 $context['relatedFields'][$relationship->getLabel()][$k] = $fld;
             } else {
                 $context['fields'][$k] = $fld;
             }
         }
         ob_start();
         df_display($context, 'xataface/modules/g2/advanced_find_form.html');
         $html = ob_get_contents();
         ob_end_clean();
     }
     $mod = Dataface_ModuleTool::getInstance()->loadModule('modules_g2');
     require_once 'modules/g2/inc/simple_html_dom.php';
     $dom = str_get_html($html);
     $els = $dom->find('select');
     foreach ($els as $el) {
         $vocab = $el->{'data-xf-vocabulary'};
         if (!$vocab) {
             continue;
         }
         $options = array('' => '', '=' => df_translate('g2_advanced_find_form.empty_list_label', "<Empty>"));
         $fieldTableName = $el->{'data-xf-table'};
         if ($fieldTableName) {
             $fieldTable = Dataface_Table::loadTable($fieldTableName);
         } else {
             $fieldTable = null;
         }
         if (!$fieldTable) {
             $fieldTable = $table;
         }
         $o2 = $fieldTable->getValuelist($vocab);
         if ($o2) {
             foreach ($o2 as $k => $v) {
                 $options[$k] = $v;
             }
         }
         $opts = array();
         foreach ($options as $k => $v) {
             $opts[] = '<option value="' . htmlspecialchars($k) . '">' . htmlspecialchars($v) . '</option>';
         }
         $el->innertext = implode("\n", $opts);
     }
     header('Content-type: text/html; charset="' . $app->_conf['oe'] . '"');
     $out = $dom->save();
     header('Content-length: ' . strlen($out));
     echo $out;
     flush();
 }