getFuel() 공개 정적인 메소드

Get the Fuel specified by $name or NULL if it doesn't exist
사용 중단:
public static getFuel ( string $name = '' ) : mixed | null
$name string
리턴 mixed | null
예제 #1
0
/**
 * Perform a language translation
 * 
 * @param string $text Text for translation. 
 * @param string $textdomain Textdomain for the text, may be class name, filename, or something made up by you. If ommitted, a debug backtrace will attempt to determine it automatically.
 * @param string $context Name of context - DO NOT USE with this function for translation as it won't be parsed for translation. Use only with the _x() function, which will be parsed. 
 * @return string Translated text or original text if translation not available.
 *
 *
 */
function __($text, $textdomain = null, $context = '')
{
    if (!Wire::getFuel('languages')) {
        return $text;
    }
    if (!($language = Wire::getFuel('user')->language)) {
        return $text;
    }
    if (!$language->id) {
        return $text;
    }
    if (is_null($textdomain)) {
        $traces = @debug_backtrace(defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? DEBUG_BACKTRACE_IGNORE_ARGS : false);
        if (isset($traces[0]) && $traces[0]['file'] != __FILE__) {
            $textdomain = $traces[0]['file'];
        } else {
            if (isset($traces[1]) && $traces[1]['file'] != __FILE__) {
                $textdomain = $traces[1]['file'];
            }
        }
        if (is_null($textdomain)) {
            $textdomain = 'site';
        }
    }
    return htmlspecialchars($language->translator()->getTranslation($textdomain, $text, $context), ENT_QUOTES, 'UTF-8');
}
/**
 * Return all Fuel, or specified ProcessWire API variable, or NULL if it doesn't exist.
 *
 * Same as Wire::getFuel($name) and Wire::getAllFuel();
 * When a $name is specified, this function is identical to the wire() function.
 * Both functions exist more for consistent naming depending on usage. 
 *
 * @param string $name If ommitted, returns a Fuel object with references to all the fuel.
 * @return mixed Fuel value if available, NULL if not. 
 *
 */
function fuel($name = '')
{
    if (!$name) {
        return Wire::getAllFuel();
    }
    return Wire::getFuel($name);
}
예제 #3
0
/**
 * Perform a language translation
 *
 * If no context provided then a global context is assumed
 *
 */
function __($context, $text = null)
{
    if (is_null($text)) {
        $text = $context;
        $context = null;
    }
    if (!Wire::getFuel('languages')) {
        return $text;
    }
    if (!($language = Wire::getFuel('user')->language)) {
        return $text;
    }
    return $language->translator()->getTranslation($context, $text);
}
예제 #4
0
 /**
  * Save the template to database
  *
  * @return $this|bool Returns Template if successful, or false if not
  *
  */
 public function save()
 {
     $result = Wire::getFuel('templates')->save($this);
     return $result ? $this : false;
 }
예제 #5
0
 /**
  * Get a property via dot syntax: field.subfield (static)
  *
  * Static version for internal core use. Use the non-static getDot() instead.
  *
  * @param string $key 
  * @param Wire $from The instance you want to pull the value from
  * @return null|mixed Returns value if found or null if not
  *
  */
 public static function _getDot($key, Wire $from)
 {
     $key = trim($key, '.');
     if (strpos($key, '.')) {
         // dot present
         $keys = explode('.', $key);
         // convert to array
         $key = array_shift($keys);
         // get first item
     } else {
         // dot not present
         $keys = array();
     }
     if (Wire::getFuel($key) !== null) {
         return null;
     }
     // don't allow API vars to be retrieved this way
     if ($from instanceof WireData) {
         $value = $from->get($key);
     } else {
         if ($from instanceof WireArray) {
             $value = $from->getProperty($key);
         } else {
             $value = $from->{$key};
         }
     }
     if (!count($keys)) {
         return $value;
     }
     // final value
     if (is_object($value)) {
         if (count($keys) > 1) {
             $keys = implode('.', $keys);
             // convert back to string
             if ($value instanceof WireData) {
                 $value = $value->getDot($keys);
             } else {
                 $value = self::_getDot($keys, $value);
             }
         } else {
             $key = array_shift($keys);
             // just one key left, like 'title'
             if ($value instanceof WireData) {
                 $value = $value->get($key);
             } else {
                 if ($value instanceof WireArray) {
                     if ($key == 'count') {
                         $value = count($value);
                     } else {
                         $a = array();
                         foreach ($value as $v) {
                             $a[] = $v->get($key);
                         }
                         $value = $a;
                     }
                 }
             }
         }
     } else {
         // there is a dot property remaining and nothing to send it to
         $value = null;
     }
     return $value;
 }
 /**
  * Load's ProcessWire using the supplied Config and populates all API fuel
  *
  * $param Config $config
  *
  */
 public function load(Config $config)
 {
     Wire::setFuel('notices', new Notices());
     Wire::setFuel('sanitizer', new Sanitizer());
     if ($config->dbSocket) {
         $db = new Database($config->dbHost, $config->dbUser, $config->dbPass, $config->dbName, $config->dbPort, $config->dbSocket);
     } else {
         $db = new Database($config->dbHost, $config->dbUser, $config->dbPass, $config->dbName, $config->dbPort);
     }
     Wire::setFuel('db', $db);
     if ($config->dbCharset) {
         $db->set_charset($config->dbCharset);
     } else {
         if ($config->dbSetNamesUTF8) {
             $db->query("SET NAMES 'utf8'");
         }
     }
     $modules = new Modules($config->paths->modules, $config->paths->siteModules);
     $fieldtypes = new Fieldtypes();
     $fields = new Fields();
     $fieldgroups = new Fieldgroups();
     $templates = new Templates($fieldgroups, $config->paths->templates);
     Wire::setFuel('modules', $modules);
     Wire::setFuel('fieldtypes', $fieldtypes);
     Wire::setFuel('fields', $fields);
     Wire::setFuel('fieldgroups', $fieldgroups);
     Wire::setFuel('templates', $templates);
     Wire::setFuel('permissions', new Permissions());
     Wire::setFuel('roles', new Roles());
     Wire::setFuel('pages', new Pages(), true);
     Wire::setFuel('pagesRoles', new PagesRoles());
     Wire::setFuel('users', new Users());
     Wire::setFuel('user', Wire::getFuel('users')->getCurrentUser());
     Wire::setFuel('session', new Session());
     Wire::setFuel('input', new WireInput());
     $fieldtypes->init();
     $fields->init();
     $fieldgroups->init();
     $templates->init();
     $modules->init();
 }
예제 #7
0
/**
 * Handles dynamic loading of classes as registered with spl_autoload_register
 *
 */
function ProcessWireClassLoader($className)
{
    if ($className[0] == 'W' && $className != 'Wire' && strpos($className, 'Wire') === 0) {
        $className = substr($className, 4);
    }
    $file = PROCESSWIRE_CORE_PATH . "{$className}.php";
    if (is_file($file)) {
        require $file;
    } else {
        if ($modules = Wire::getFuel('modules')) {
            $modules->includeModule($className);
        }
    }
    // else die($className);
}