/**
 * Translation helper
 * It returns a translated string if it is found; Otherwise, the given string itself
 *
 * @param string $str The string being translated
 * @param mixed $args The multiple arguments to be substituted in the string
 *
 * @return string The translated string
 */
function _t($str)
{
    global $lc_lang;
    global $lc_translation;
    global $lc_translationEnabled;
    $args = func_get_args();
    $str = array_shift($args);
    $str = trim($str);
    if ($lc_translationEnabled == false) {
        return count($args) ? vsprintf($str, $args) : $str;
    }
    $po = session_get('po');
    if (!is_array($po)) {
        $po = array();
    }
    $po[$str] = '';
    if (isset($lc_translation[$lc_lang])) {
        # check with lowercase
        $lowerStr = strtolower($str);
        if (isset($lc_translation[$lc_lang][$lowerStr]) && !empty($lc_translation[$lc_lang][$lowerStr])) {
            $translated = $lc_translation[$lc_lang][$lowerStr];
            $str = is_array($translated) ? $translated[0] : $translated;
        }
    }
    if (isset($translated)) {
        $po[$str] = $translated;
    }
    return count($args) ? vsprintf($str, $args) : $str;
}
Example #2
0
 public static function process($action = 'list', $id = null)
 {
     $errors = array();
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && $action == 'edit') {
         // instancia
         $data = array('id' => $_POST['id'], 'name' => $_POST['name'], 'amount' => $_POST['amount']);
         if (WorthLib::save($data, $errors)) {
             $action = 'list';
             Message::Info(Text::_('Nivel de meritocracia modificado'));
             // Evento Feed
             $log = new Feed();
             $log->populate(Text::_('Nivel de meritocracia modificado'), '/admin/worth', \vsprintf("El admin %s ha %s el nivel de meritocrácia %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Modificado'), Feed::item('project', $icon->name))));
             $log->doAdmin('admin');
             unset($log);
         } else {
             Message::Error(Text::_('No se ha guardado correctamente. ') . implode('<br />', $errors));
             return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'edit', 'action' => 'edit', 'worth' => (object) $data));
         }
     }
     switch ($action) {
         case 'edit':
             $worth = WorthLib::getAdmin($id);
             return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'edit', 'action' => 'edit', 'worth' => $worth));
             break;
     }
     $worthcracy = WorthLib::getAll();
     return new View('view/admin/index.html.php', array('folder' => 'worth', 'file' => 'list', 'worthcracy' => $worthcracy));
 }
Example #3
0
 /**
  * Query database
  *
  * @param   string        $sql          SQL Query
  * @param   array|string  $replacement  Replacement
  * @return  mixed
  */
 public function query()
 {
     $args = func_get_args();
     $sql = array_shift($args);
     // Menerapkan $replacement ke pernyataan $sql
     if (!empty($args)) {
         $sql = vsprintf($sql, $args);
     }
     try {
         // Return 'false' kalo belum ada koneksi
         if (!$this->_db) {
             $this->connect();
         }
         $this->_sql = $sql;
         // Eksekusi SQL Query
         if ($results = $this->_db->query($sql)) {
             if (is_bool($results)) {
                 return $results;
             }
             $this->_results = $results;
             $this->_num_rows = $this->_results->num_rows;
             return $this;
         } else {
             App::error($this->_db->error . '<br>' . $this->_sql);
         }
     } catch (Exception $e) {
         setAlert('error', $e->getMessage());
         return false;
     }
 }
 /**
  * Creates an exception using a formatted message.
  *
  * @param string $format    The message format.
  * @param mixed  $value,... A value.
  *
  * @return static The exception.
  */
 public static function format($format, $value = null)
 {
     if (1 < func_num_args()) {
         $format = vsprintf($format, array_slice(func_get_args(), 1));
     }
     return new static($format);
 }
Example #5
0
 /**
  * Create a new Eloquent model instance.
  *
  * @param array $attributes
  *
  * @throws LackOfCoffeeException
  */
 public function __construct(array $attributes = [])
 {
     parent::__construct($attributes);
     if (!array_key_exists(static::class, static::$registered)) {
         throw new LackOfCoffeeException(vsprintf('You forgot to call registerEvents() on %s.' . ' The method should be called on a Service Provider.' . ' See http://laravel.com/docs/5.1/eloquent#events' . ' for more details.', [static::class]));
     }
 }
 /**
  * Generate a URL to an endpoint
  *
  * Used to construct meta links in API responses
  *
  * @param mixed $args Optional arguments to be appended to URL
  * @return string Endpoint URL
  **/
 function get_link()
 {
     $args = func_get_args();
     $format = array_shift($args);
     $base = WPCOM_JSON_API__BASE;
     $path = array_pop($args);
     if ($path) {
         $path = '/' . ltrim($path, '/');
     }
     $args[] = $path;
     // Escape any % in args before using sprintf
     $escaped_args = array();
     foreach ($args as $arg_key => $arg_value) {
         $escaped_args[$arg_key] = str_replace('%', '%%', $arg_value);
     }
     $relative_path = vsprintf("{$format}%s", $escaped_args);
     if (!wp_startswith($relative_path, '.')) {
         // Generic version. Match the requested version as best we can
         $api_version = $this->get_closest_version_of_endpoint($format, $relative_path);
         $base = substr($base, 0, -1) . $api_version;
     }
     // escape any % in the relative path before running it through sprintf again
     $relative_path = str_replace('%', '%%', $relative_path);
     // http, WPCOM_JSON_API__BASE, ...    , path
     // %s  , %s                  , $format, %s
     return esc_url_raw(sprintf("https://%s{$relative_path}", $base));
 }
 public function init()
 {
     $description = $this->getTranslator()->translate('Conrols settings about access to the admin panel. <br>');
     $settings = Engine_Api::_()->getApi('settings', 'core');
     if ($settings->getSetting('user.support.links', 0) == 1) {
         $moreinfo = $this->getTranslator()->translate('More Info: <a href="%1$s" target="_blank"> KB Article</a>');
     } else {
         $moreinfo = $this->getTranslator()->translate('');
     }
     $description = vsprintf($description . $moreinfo, array('http://support.socialengine.com/questions/170/Admin-Panel-Settings-Admin-Password'));
     // Decorators
     $this->loadDefaultDecorators();
     $this->getDecorator('Description')->setOption('escape', false);
     $this->setTitle('Admin Reauthentication')->setDescription($description);
     // Mode
     $this->addElement('Radio', 'mode', array('multiOptions' => array('none' => 'Do not require reauthentication.', 'user' => 'Require admins to re-enter their password when they try to access the admin panel.', 'global' => 'Require admins to enter a global password when they try to access the admin panel.')));
     // Password
     $this->addElement('Password', 'password', array('label' => 'Password', 'description' => 'The password for "Require admins to enter a global password when they try to access the admin panel." above (otherwise ignore).'));
     // Password confirm
     $this->addElement('Password', 'password_confirm', array('label' => 'Password Again', 'description' => 'Confirm password'));
     // timeout
     $this->addElement('Text', 'timeout', array('label' => 'Timeout', 'description' => 'How long (in seconds) before admins have to reauthenticate?', 'required' => true, 'allowEmpty' => false, 'validators' => array(array('NotEmpty', true), array('Int', true), array('Between', true, array(300, 86400)))));
     // init submit
     $this->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true));
 }
 public function setUp()
 {
     global $wpdb;
     parent::setUp();
     for ($i = 1; $i <= 13; $i++) {
         $object = new \stdClass();
         $object->ID = $i;
         $this->results[] = $object;
     }
     $wpdb = m::mock('wpdb');
     $wpdb->posts = 'wp_posts';
     $wpdb->shouldReceive('prepare')->andReturnUsing(function () {
         $args = func_get_args();
         $query = array_shift($args);
         // From WPDB::prepare method
         $query = str_replace("'%s'", '%s', $query);
         // in case someone mistakenly already singlequoted it
         $query = str_replace('"%s"', '%s', $query);
         // doublequote unquoting
         $query = preg_replace('|(?<!%)%f|', '%F', $query);
         // Force floats to be locale unaware
         $query = preg_replace('|(?<!%)%s|', "'%s'", $query);
         // quote the strings, avoiding escaped strings like %%s
         return vsprintf($query, $args);
     });
     $wpdb->shouldReceive('_real_escape')->andReturnUsing(function ($arg) {
         return $arg;
     });
     $wpdb->shouldReceive('get_var')->with("SELECT count(ID) FROM wp_posts WHERE post_type='post' AND post_status='publish'")->andReturn('13');
     $wpdb->shouldReceive('get_results')->andReturn(array_slice($this->results, 0, 5), array_slice($this->results, 5, 5), array_slice($this->results, 10, 3));
 }
Example #9
0
function getGUID()
{
    $data = openssl_random_pseudo_bytes(16);
    $data[6] = chr(ord($data[6]) & 0xf | 0x40);
    $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
    return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
 /**
  * Open a connection to the ActiveMQ queue.
  *
  * If there are queued subscriptions then these will be subscribed
  * to once the connection is opened.
  *
  * @throws ConnectionErrorException
  * @throws IncompatibleTopicException
  */
 private function connect()
 {
     // Create DSN
     $uri = vsprintf("%s://%s:%d", [self::SCHEME, self::HOST, self::PORT]);
     // This will be populated with various exceptions that can happen when connecting.
     $connectionError = false;
     // Attempt to open a connection to Stomp server. Don't bail on exceptions.
     try {
         $this->stomp = new \Stomp($uri, $this->username, $this->password);
     } catch (\Exception $e) {
         $connectionError = $e->getMessage();
     }
     // If connection could not be opened, then bail with our ConnectionError exception.
     // The passed argument is the message of the Stomp/PHP exception thrown earlier, if it exists.
     if (!$this->stomp) {
         throw new ConnectionErrorException($connectionError);
     }
     // If there are queued topics, then add them now that we have an open connection.
     if (!empty($this->queuedTopics)) {
         foreach ($this->queuedTopics as $topic) {
             $this->addTopic($topic);
         }
         $this->queuedTopics = [];
     }
 }
Example #11
0
 /**
  * This method generates the checkstyle.xml report
  *
  * @param ProjectDescriptor $project        Document containing the structure.
  * @param Transformation    $transformation Transformation to execute.
  *
  * @return void
  */
 public function transform(ProjectDescriptor $project, Transformation $transformation)
 {
     $artifact = $this->getDestinationPath($transformation);
     $this->checkForSpacesInPath($artifact);
     $document = new \DOMDocument();
     $document->formatOutput = true;
     $report = $document->createElement('checkstyle');
     $report->setAttribute('version', '1.3.0');
     $document->appendChild($report);
     /** @var FileDescriptor $fileDescriptor */
     foreach ($project->getFiles()->getAll() as $fileDescriptor) {
         $file = $document->createElement('file');
         $file->setAttribute('name', $fileDescriptor->getPath());
         $report->appendChild($file);
         /** @var Error $error */
         foreach ($fileDescriptor->getAllErrors()->getAll() as $error) {
             $item = $document->createElement('error');
             $item->setAttribute('line', $error->getLine());
             $item->setAttribute('severity', $error->getSeverity());
             $item->setAttribute('message', vsprintf($this->getTranslator()->translate($error->getCode()), $error->getContext()));
             $item->setAttribute('source', 'phpDocumentor.file.' . $error->getCode());
             $file->appendChild($item);
         }
     }
     $this->saveCheckstyleReport($artifact, $document);
 }
Example #12
0
 public static function process($action = 'list', $id = null, $filters = array())
 {
     $groups = Model\Icon::groups();
     $errors = array();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         // instancia
         $icon = new Model\Icon(array('id' => $_POST['id'], 'name' => $_POST['name'], 'description' => $_POST['description'], 'order' => $_POST['order'], 'group' => empty($_POST['group']) ? null : $_POST['group']));
         if ($icon->save($errors)) {
             switch ($_POST['action']) {
                 case 'add':
                     Message::Info('Nuevo tipo añadido correctamente');
                     break;
                 case 'edit':
                     Message::Info('Tipo editado correctamente');
                     // Evento Feed
                     $log = new Feed();
                     $log->populate('modificacion de tipo de retorno/recompensa (admin)', '/admin/icons', \vsprintf("El admin %s ha %s el tipo de retorno/recompensa %s", array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('relevant', 'Modificado'), Feed::item('project', $icon->name))));
                     $log->doAdmin('admin');
                     unset($log);
                     break;
             }
         } else {
             Message::Error(implode('<br />', $errors));
             return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'edit', 'action' => $_POST['action'], 'icon' => $icon, 'groups' => $groups));
         }
     }
     switch ($action) {
         case 'edit':
             $icon = Model\Icon::get($id);
             return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'edit', 'action' => 'edit', 'icon' => $icon, 'groups' => $groups));
             break;
     }
     $icons = Model\Icon::getAll($filters['group']);
     return new View('view/admin/index.html.php', array('folder' => 'icons', 'file' => 'list', 'icons' => $icons, 'groups' => $groups, 'filters' => $filters));
 }
Example #13
0
 public function postSendCode(Request $request)
 {
     //get data
     extract($this->parseInput($request));
     //validate
     $verifyResult = SmsManager::validator(['mobile' => $mobile, 'seconds' => $seconds, 'uuid' => $uuid], $rule);
     if (!$verifyResult['success']) {
         return response()->json($verifyResult);
     }
     //send verify sms
     $code = SmsManager::generateCode();
     $minutes = SmsManager::getCodeValidTime();
     $templates = SmsManager::getVerifySmsTemplates();
     $template = SmsManager::getVerifySmsContent();
     try {
         $content = vsprintf($template, [$code, $minutes]);
     } catch (\Exception $e) {
         $content = $template;
     }
     $result = $this->phpSms->make($templates)->to($mobile)->data(['code' => $code, 'minutes' => $minutes])->content($content)->send();
     if ($result['success']) {
         $data = SmsManager::getSentInfo();
         $data['sent'] = true;
         $data['mobile'] = $mobile;
         $data['code'] = $code;
         $data['deadline_time'] = time() + $minutes * 60;
         SmsManager::storeSentInfo($uuid, $data);
         SmsManager::storeCanSendTime($uuid, $seconds);
         $verifyResult = SmsManager::genResult(true, 'sms_send_success');
     } else {
         $verifyResult = SmsManager::genResult(false, 'sms_send_failure');
     }
     return response()->json($verifyResult);
 }
Example #14
0
 /**
  * Write a message to Monolog.
  *
  * @param  string  $level
  * @param  string  $message
  * @param  array  $context
  * @return void
  */
 protected function writeLog($level, $message, $context)
 {
     $this->getFileInfo(self::TRACE_DEPTH);
     $formatMessage = vsprintf(self::DEFAULT_LOG_FORMAT, array($this->getUrl(), $this->currentFile, $this->currentLine, $this->formatMessage($message)));
     $this->fireLogEvent($level, $formatMessage, $context);
     $this->monolog->{$level}($formatMessage, $context);
 }
Example #15
0
 function __construct()
 {
     parent::__construct();
     // Get CI instance to obtain DB settings
     $ci =& get_instance();
     $this->addConnection(array('driver' => 'mysql', 'host' => $ci->db->hostname, 'database' => $ci->db->database, 'username' => $ci->db->username, 'password' => $ci->db->password, 'charset' => $ci->db->char_set, 'collation' => $ci->db->dbcollat, 'prefix' => $ci->db->dbprefix));
     // Listen to Model related events (saving, saved, updating, updated, creating, created etc).
     $this->setEventDispatcher(new Dispatcher(new Container()));
     // For CI Profiler (debugging utility)
     $events = new Dispatcher();
     $events->listen('illuminate.query', function ($query, $bindings, $time, $name) {
         // Format binding data for sql insertion
         foreach ($bindings as $i => $binding) {
             if ($binding instanceof \DateTime) {
                 $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
             } else {
                 if (is_string($binding)) {
                     $bindings[$i] = "'{$binding}'";
                 }
             }
         }
         // Insert bindings into query
         $query = str_replace(array('%', '?'), array('%%', '%s'), $query);
         $query = vsprintf($query, $bindings);
         // Add it into CodeIgniter
         $ci =& get_instance();
         $ci->db->query_times[] = $time;
         $ci->db->queries[] = $query;
     });
     $this->setEventDispatcher($events);
     $this->setAsGlobal();
     $this->bootEloquent();
 }
 private function query($query, $args = array())
 {
     $query = str_replace('#__', DB_PREFIX, $query);
     $args = array_map('escape', $args);
     $query = vsprintf($query, $args);
     return mysql_query($query, $this->conn);
 }
Example #17
0
 protected function createSqlFromSpecificationAndParameters($specification, $parameters)
 {
     if (is_string($specification)) {
         return vsprintf($specification, $parameters);
     }
     $topSpec = key($specification);
     $paramSpecs = $specification[$topSpec];
     $topParameters = array();
     $position = -1;
     foreach ($parameters as $position => $paramsForPosition) {
         if (isset($paramSpecs[$position]['combinedby'])) {
             $multiParamValues = array();
             foreach ($paramsForPosition as $multiParamsForPosition) {
                 $ppCount = count($multiParamsForPosition);
                 if (!isset($paramSpecs[$position][$ppCount])) {
                     throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification');
                 }
                 $multiParamValues[] = vsprintf($paramSpecs[$position][$ppCount], $multiParamsForPosition);
             }
             $topParameters[] = implode($paramSpecs[$position]['combinedby'], $multiParamValues);
         } elseif ($paramSpecs[$position] !== null) {
             $ppCount = count($paramsForPosition);
             if (!isset($paramSpecs[$position][$ppCount])) {
                 //var_dump($specification, $parameters);
                 throw new Exception\RuntimeException('A number of parameters (' . $ppCount . ') was found that is not supported by this specification');
             }
             $topParameters[] = vsprintf($paramSpecs[$position][$ppCount], $paramsForPosition);
         } else {
             $topParameters[] = $paramsForPosition;
         }
     }
     return vsprintf($topSpec, $topParameters);
 }
Example #18
0
 public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
 {
     global $wpdb;
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     $user = new WP_User($user_id);
     $roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
     if (!isset($args['author_meta'])) {
         $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent());
         if (defined('WP_CLI') && function_exists('posix_getuid')) {
             $uid = posix_getuid();
             $user_info = posix_getpwuid($uid);
             $args['author_meta']['system_user_id'] = $uid;
             $args['author_meta']['system_user_name'] = $user_info['name'];
         }
     }
     // Remove meta with null values from being logged
     $meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
     $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr);
     return $record_id;
 }
Example #19
0
 /**
  * Translate a message
  * You can give multiple params or an array of params.
  * If you want to output another locale just set it as last single parameter
  * Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
  * Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
  *
  * @param  string $messageid Id of the message to be translated
  * @param  string $module    name of module
  * @return string|Zend_View_Helper_Translate Translated message
  */
 public function translate($messageid = null, $module = null)
 {
     if ($messageid === null) {
         return $this;
     }
     $translate = $this->getTranslator();
     $options = func_get_args();
     array_shift($options);
     $count = count($options);
     $locale = null;
     if ($count > 0) {
         if (Zend_Locale::isLocale($options[$count - 1], false, false) !== false) {
             $locale = array_pop($options);
         }
     }
     if (count($options) === 1 and is_array($options[0]) === true) {
         $options = $options[0];
     }
     if ($translate !== null) {
         $messageid = $translate->translate($messageid, $locale, $module);
     }
     if (count($options) === 0) {
         return $messageid;
     }
     return vsprintf($messageid, $options);
 }
Example #20
0
function t($str, $params = null)
{
    if ($params != null) {
        return vsprintf(tr(substr($str, 3, -4)), $params);
    }
    return tr(substr($str, 3, -4));
}
 /**
  * Constructor.
  *
  * @access  public
  * @param   string  $host  Redis host
  * @param   string  $port  Redis port
  */
 public function __construct($host, $port = 6379)
 {
     $this->connection = @fsockopen('tcp://' . $host, $port, $errNo, $errStr);
     if (!$this->connection) {
         throw new RedisException(vsprintf("%s(): %s", [__METHOD__, $errStr]), (int) $errNo);
     }
 }
Example #22
0
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  * @param   string                         $package      Package name
  * @param   string                         $description  Migration description
  */
 public function execute(Application $application, FileSystem $fileSystem, $package = null, $description = null)
 {
     // Get file path and namespace
     if (empty($package)) {
         $namespace = $application->getNamespace() . '\\migrations';
         $path = $application->getPath() . '/migrations/';
     } else {
         $package = $application->getPackage($package);
         $namespace = $package->getClassNamespace() . '\\migrations';
         $path = $package->getPath() . '/src/migrations/';
     }
     $path .= 'Migration_' . ($version = gmdate('YmdHis')) . '.php';
     // Create migration
     $description = str_replace("'", "\\'", $description);
     $search = ['{{namespace}}', '{{version}}', '{{description}}'];
     $replace = [$namespace, $version, $description];
     $migration = str_replace($search, $replace, $fileSystem->getContents(__DIR__ . '/resources/migration.template'));
     try {
         $fileSystem->putContents($path, $migration);
     } catch (Exception $e) {
         $this->error('Failed to create migration. Make sure that the migrations directory is writable.');
         return;
     }
     $this->write(vsprintf('Migration created at [ %s ].', [$path]));
 }
Example #23
0
 public function translate($message, $count = NULL)
 {
     $case = $this->detectCase($message);
     $args = func_get_args();
     if (is_string($count)) {
         if (isset($args[2]) && is_numeric($args[2])) {
             $count = $args[2];
         }
     }
     $counter = $count;
     if (is_numeric($count)) {
         $counter = $this->inflexion($count);
     }
     $node = String::lower($message . $counter);
     if (isset($this->dict[$node])) {
         $message = $this->dict[$node];
     } else {
         $message = implode(' ', explode('_', $message));
     }
     if (count($args) > 1) {
         array_shift($args);
         $message = vsprintf($message, $args);
     }
     if ($case == 'default') {
         return $message;
     } elseif ($case == 'firstUpper') {
         return ucfirst($message);
     } else {
         return call_user_func(array('String', $case), $message);
     }
 }
Example #24
0
function translateEngine($lang_subdirectory, $languageID, $messageID, $args = array(), $fallback = 'en')
{
    $lang_array = array("en", "de", "pt", "fr", "fi", "nn", "nl", "ca", "tr", "es", "it", "da", "cs", "ru", "et", "sr", "el", "pl", "hr", "hu", "br", "sv", "sk", "gl", "sl", "be", "lv", "lt", "zh", "cn", "ja", "ko", "bg", "mx", "uk", "id", "ro");
    if (!isset($lang_array[$languageID])) {
        return "Unknown Language Selected";
    }
    $lang_folder = ROOTPATH . "/data/langs/{$lang_subdirectory}";
    if (!is_readable($lang_folder)) {
        console("Language Folder for {$lang_subdirectory} is missing or not readable.");
        return "Language Folder for {$lang_subdirectory} is missing or not readable.";
    }
    $lang_file = "{$lang_folder}/{$lang_array[$languageID]}.ini";
    if (is_readable($lang_file)) {
        $LANG = parse_ini_file($lang_file);
    } else {
        $lang_file = "{$lang_folder}/{$fallback}.ini";
        if (is_readable($lang_file)) {
            $LANG = parse_ini_file($lang_file);
            console("Language File for {$lang_array[$languageID]} in {$lang_subdirectory} is missing or not readable.");
        } else {
            console("Language File for {$lang_array[$languageID]} in {$lang_subdirectory} is missing or not readable. No Fallback Available.");
            return "Language File for {$lang_array[$languageID]} in {$lang_subdirectory} is missing or not readable. No Fallback Available.";
        }
    }
    if (isset($LANG[$messageID])) {
        return vsprintf($LANG[$messageID], $args);
    } else {
        console("Missing Language Entry: {$messageID} in {$lang_array[$languageID]}");
        if ($languageID != $fallback) {
            return translateEngine($lang_subdirectory, $fallback, $messageID, $args, $fallback);
        } else {
            return "Missing Language Entry: {$messageID} in {$lang_array[$languageID]}";
        }
    }
}
function mysql_safe_query($format)
{
    $args = array_slice(func_get_args(), 1);
    $args = array_map('mysql_safe_string', $args);
    $query = vsprintf($format, $args);
    return mysql_query($query);
}
Example #26
0
 /**
  * Create a new AnewtException.
  *
  * \param $fmt
  *   A error message, optionally with sprintf format specifiers
  * \param $args
  *   Zero or more values passed to vsprintf
  */
 function __construct($fmt, $args = null)
 {
     $args = func_get_args();
     $fmt = array_shift($args);
     assert('is_string($fmt);');
     parent::__construct(vsprintf($fmt, $args));
 }
 public function getStrParam($cmd, $arr)
 {
     $contents = vsprintf($cmd, $arr);
     //print $contents;
     //return $contents;
     return $this->getStr($contents);
 }
 /**
  * Outputs specified text to the console window
  * You can specify arguments that will be passed to the text via sprintf
  * @see http://www.php.net/sprintf
  *
  * @param string $text Text to output
  * @param array $arguments Optional arguments to use for sprintf
  * @return void
  */
 public function output($text, array $arguments = array())
 {
     if ($arguments !== array()) {
         $text = vsprintf($text, $arguments);
     }
     $this->output->write($text);
 }
Example #29
0
 /**
  * @param Issue $issue
  * @param string $file
  * @param int $line
  * @param array $template_parameters
  */
 public function __construct(Issue $issue, string $file, int $line, array $template_parameters)
 {
     $this->issue = $issue;
     $this->file = $file;
     $this->line = $line;
     $this->message = vsprintf($issue->getTemplate(), $template_parameters);
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $configPath = __DIR__ . '/../config/sql-logging.php';
     $this->mergeConfigFrom($configPath, 'sql-logging');
     if (config('sql-logging.log', false)) {
         Event::listen('illuminate.query', function ($query, $bindings, $time) {
             $data = compact('bindings', 'time');
             // Format binding data for sql insertion
             foreach ($bindings as $i => $binding) {
                 if ($binding instanceof \DateTime) {
                     $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
                 } else {
                     if (is_string($binding)) {
                         $bindings[$i] = "'{$binding}'";
                     }
                 }
             }
             // Insert bindings into query
             $query = str_replace(array('%', '?'), array('%%', '%s'), $query);
             $query = vsprintf($query, $bindings);
             $log = new Logger('sql');
             $log->pushHandler(new StreamHandler(storage_path() . '/logs/sql-' . date('Y-m-d') . '.log', Logger::INFO));
             // add records to the log
             $log->addInfo($query, $data);
         });
     }
 }