コード例 #1
0
ファイル: templates.php プロジェクト: phpsource/openclerk
/**
 * Display any errors or messages, including those passed through temporary_messages/errors.
 */
function display_messages()
{
    global $messages;
    global $errors;
    if (!isset($messages)) {
        $messages = array();
    }
    if (!isset($errors)) {
        $errors = array();
    }
    if (get_temporary_messages()) {
        $messages = array_join($messages, get_temporary_messages());
    }
    if (get_temporary_errors()) {
        $errors = array_join($errors, get_temporary_errors());
    }
    // if admin, load any admin messages
    if (is_admin()) {
        $q = db()->prepare("SELECT * FROM admin_messages WHERE is_read=0 ORDER BY created_at ASC");
        $q->execute();
        while ($message = $q->fetch()) {
            $messages[] = "Admin message: " . $message['message'] . " (<a href=\"" . htmlspecialchars(url_for('admin_message', array('id' => $message['id']))) . "\">hide</a>)";
        }
    }
    if ($messages) {
        ?>
<div class="message">
<ul>
  <?php 
        foreach ($messages as $m) {
            echo "<li>" . $m . "</li>";
        }
        /* do NOT accept user input for messages! */
        ?>
</ul>
</div>
<?php 
    }
    if ($errors) {
        ?>
<div class="error">
<ul>
  <?php 
        foreach ($errors as $m) {
            echo "<li>" . $m . "</li>";
        }
        /* do NOT accept user input for messages! */
        ?>
</ul>
</div>
<?php 
    }
}
コード例 #2
0
ファイル: settings.php プロジェクト: alexhava/elixirjuice
function array_join()
{
    // Get array arguments
    $arrays = func_get_args();
    // Define the original array
    $original = array_shift($arrays);
    // Loop through arrays
    foreach ($arrays as $array) {
        // Loop through array key/value pairs
        foreach ($array as $key => $value) {
            // Value is an array
            if (is_array($value)) {
                // Traverse the array; replace or add result to original array
                $original[$key] = array_join($original[$key], $array[$key]);
            } else {
                // Replace or add current value to original array
                $original[$key] = $value;
            }
        }
    }
    // Return the joined array
    return $original;
}
コード例 #3
0
 /**
  * Set the editor to use to open referenced files, by a string
  * identifier, or a callable that will be executed for every
  * file reference, with a $file and $line argument, and should
  * return a string.
  *
  * @example
  *   $run->setEditor(function($file, $line) { return "file:///{$file}"; });
  * @example
  *   $run->setEditor('sublime');
  *
  * @param string|callable $editor
  */
 public function setEditor($editor)
 {
     if (!is_callable($editor) && !isset($this->editors[$editor])) {
         throw new InvalidArgumentException("Unknown editor identifier: {$editor}. Known editors:" . array_join(",", array_keys($this->editors)));
     }
     $this->editor = $editor;
 }
コード例 #4
0
 /**
  * Set the current template, or other property
  * @param string $property Property name
  * @param string $value The property's value
  * @return void
  */
 function __set($property, $value)
 {
     if ($property == 'current') {
         $a = $this->__get($value);
         $a->vars = array_join($a->vars, $this->current->vars);
         $this->current = $a;
     }
 }
コード例 #5
0
     $args[] = $data;
 }
 if ($account_data['disabled']) {
     $errors[] = t("Cannot add a new account; that account type is disabled.");
 }
 if (!is_valid_title(require_post("title", false))) {
     $errors[] = t("That is not a valid title.");
 }
 if (!can_user_add($user, $account_data['exchange'])) {
     $errors[] = t("Cannot add :title: too many existing accounts.", array(':title' => $account_data['title'])) . ($user['is_premium'] ? "" : " " . t("To add more accounts, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account')))));
 }
 if (!$errors) {
     $title = htmlspecialchars(require_post("title", ""));
     // we don't care if the address already exists
     $q = db()->prepare("INSERT INTO " . $account_data['table'] . " SET user_id=?, title=? {$query}");
     $full_args = array_join(array(user_id(), require_post("title", false)), $args);
     $q->execute($full_args);
     $id = db()->lastInsertId();
     if (!$title) {
         $title = t("(untitled)");
     }
     $messages[] = t("Added new :title :name. Balances from this account will be retrieved shortly.", array(':name' => "<i>" . htmlspecialchars($title) . "</i>", ':title' => htmlspecialchars($account_data['title'])));
     // create a test job for this new account
     $q = db()->prepare("INSERT INTO jobs SET\n          job_type=:job_type,\n          job_prefix=:job_prefix,\n          user_id=:user_id,\n          arg_id=:arg_id,\n          priority=:priority,\n          is_test_job=1");
     $q->execute(array('job_type' => $account_data['job_type'], 'job_prefix' => \Openclerk\Jobs\JobQueuer::getJobPrefix($account_data['exchange']), 'user_id' => user_id(), 'arg_id' => $id, 'priority' => get_site_config('job_test_priority')));
     // update has_added_account
     $q = db()->prepare("UPDATE user_properties SET has_added_account=1,last_account_change=NOW() WHERE id=?");
     $q->execute(array(user_id()));
     // redirect to GET
     set_temporary_errors($errors);
     set_temporary_messages($messages);
コード例 #6
0
ファイル: mysql.php プロジェクト: tapiau/muyo
 /**
  * Return settings only for set columns
  * @return array
  */
 public function getColumnSettings($columns = null)
 {
     if (null == $columns) {
         $columns = array_map(function ($descriptor) {
             return zend_column_name($descriptor);
         }, $this->getColumns());
     }
     $k = array_find_key($columns, function ($v, $k) {
         return $v == $this->getPrimaryKey();
     });
     if (null !== $k) {
         unset($columns[$k]);
     }
     return array_join($columns, $this->_settings, false);
 }
コード例 #7
0
ファイル: MY_Model.php プロジェクト: linzequan/miyaki
 /**
  * 数据集与数据库表left join
  *
  * @param array $list
  * @param string $table
  * @param string $fields
  * @param string $join_key
  * @return array
  */
 protected function list_join_query($list, $table, $fields, $join_key = '')
 {
     if (count($list) <= 0) {
         return $list;
     }
     if ($join_key == '') {
         if (strpos($table, 'member') === 0 || strpos($table, 'sso_member') === 0) {
             $join_key = 'mem_id';
         } elseif (strpos($table, 'event') === 0 || strpos($table, 'sso_event') === 0) {
             $join_key = 'event_id';
         } else {
             return $list;
         }
     }
     if (strpos($fields, $join_key) === false) {
         $fields = $join_key . ',' . $fields;
     }
     // 是否链接碎片库
     $sd = false;
     if (strpos($table, 'member') === 0 || strpos($table, 'event') === 0) {
         $sd = true;
     }
     // 获取连接ID
     $ids = array();
     foreach ($list as $item) {
         if (!in_array($item[$join_key], $ids)) {
             array_push($ids, $item[$join_key]);
         }
     }
     $result_list = array();
     // 和主库表合并
     if ($sd == false) {
         $query = $this->db->select($fields)->where_in($join_key, $ids)->get($table);
         if ($query->num_rows() > 0) {
             $result_list = $query->result_array();
         }
     } else {
         $db_keys = array();
         foreach ($ids as $id) {
             $index = $this->divide($id);
             if (isset($db_keys[$index]) == false) {
                 $db_keys[$index] = array();
             }
             array_push($db_keys[$index], $id);
         }
         $method = 'mdb';
         if ($join_key == 'event_id') {
             $method = 'edb';
         }
         foreach ($db_keys as $key => $val) {
             if ($join_key == 'mem_id') {
                 $query = $this->mdb($key)->select($fields)->where_in($join_key, $val)->get($table);
             } else {
                 $query = $this->edb($key)->select($fields)->where_in($join_key, $val)->get($table);
             }
             if ($query->num_rows() > 0) {
                 $result_list = array_merge($result_list, $query->result_array());
             }
             $query->free_result();
         }
     }
     $list = array_join($list, $result_list, $join_key, $fields);
     return $list;
 }
コード例 #8
0
 /**
  * Get a list of all jobs that need to be queued, as an array of associative
  * arrays with (job_type, arg_id, [user_id]).
  *
  * This could use e.g. {@link JobTypeFinder}
  */
 function findJobs(Connection $db, Logger $logger)
 {
     $standard_jobs = self::getStandardJobs();
     $logger->info("Current time: " . date('r'));
     // get all disabled users
     $disabled = array();
     $q = $db->prepare("SELECT * FROM user_properties WHERE is_disabled=1");
     $q->execute();
     while ($d = $q->fetch()) {
         $disabled[$d['id']] = $d;
     }
     foreach (array(true, false) as $is_premium_only) {
         $job_count = 0;
         foreach ($standard_jobs as $standard) {
             $always = isset($standard['always']) && $standard['always'];
             $field = isset($standard['user_id_field']) ? $standard['user_id_field'] : 'user_id';
             $query_extra = isset($standard['query']) ? $standard['query'] : "";
             $args_extra = isset($standard['args']) ? $standard['args'] : array();
             if (isset($standard['failure']) && $standard['failure']) {
                 $query_extra .= " AND is_disabled=0";
             }
             $args = array();
             if (!$always) {
                 // we want to run system jobs at least every 0.1 hours = 6 minutes
                 $args[] = isset($standard['hours']) ? $standard['hours'] : (isset($standard['user_id']) && $standard['user_id'] == get_site_config('system_user_id') ? get_site_config('refresh_queue_hours_system') : ($is_premium_only ? get_site_config('refresh_queue_hours_premium') : get_site_config('refresh_queue_hours')));
             }
             $queue_field = isset($standard['queue_field']) ? $standard['queue_field'] : 'last_queue';
             if ($is_premium_only && (!isset($standard['user_id']) || $standard['user_id'] != get_site_config('system_user_id'))) {
                 $query_extra .= " AND {$field} IN (SELECT id FROM user_properties WHERE is_premium=1)";
             }
             // multiply queue_hours by 0.8 to ensure that user jobs are always executed within the specified timeframe
             try {
                 $q = $db->prepare("SELECT * FROM " . $standard['table'] . " WHERE " . ($always ? "1" : "({$queue_field} <= DATE_SUB(NOW(), INTERVAL (? * 0.8) HOUR) OR ISNULL({$queue_field}))") . " {$query_extra}");
                 $q->execute(array_join($args, $args_extra));
             } catch (\PdoException $e) {
                 throw new \Exception("Could not find jobs for table '" . $standard['table'] . "': " . $e->getMessage(), $e->getCode(), $e);
             }
             $disabled_count = 0;
             while ($address = $q->fetch()) {
                 $job = array("job_type" => $standard['type'], "user_id" => isset($standard['user_id']) ? $standard['user_id'] : $address[$field], "arg_id" => $address['id'], "queue_field" => $queue_field, "object" => $address, "table" => $standard['table']);
                 // check that this user is not disabled
                 if (isset($disabled[$job['user_id']])) {
                     if ($disabled_count == 0) {
                         $logger->info("Skipping job '" . $standard['type'] . "' for user " . $job['user_id'] . ": user is disabled");
                     }
                     $disabled_count++;
                     continue;
                 }
                 $result[] = $job;
                 $job_count++;
             }
             if ($disabled_count > 1) {
                 $logger->info("Also skipped another " . number_format($disabled_count) . " " . $standard['type'] . " jobs due to disabled users");
             }
         }
         $logger->info($is_premium_only ? "Found {$job_count} premium jobs" : "Found {$job_count} general user jobs");
     }
     $block_jobs = array('version_check', 'vote_coins', 'average', 'missing_average_find');
     foreach ($block_jobs as $name) {
         // as often as we can (or on request), run litecoin_block jobs
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // block count jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getBlockCurrencies() as $cur) {
         $name = "blockcount_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // difficulty jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getDifficultyCurrencies() as $cur) {
         $name = "difficulty_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // markets jobs (using the new Exchanges framework: #400)
     foreach (\DiscoveredComponents\Exchanges::getKeys() as $exchange) {
         if (!in_array($exchange, \DiscoveredComponents\Exchanges::getDisabled())) {
             $name = "markets_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
             $name = "ticker_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported currencies jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getKeys() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "currencies_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported hashrates jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getMiners() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "hashrates_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     return $result;
 }
コード例 #9
0
 /**
  * Merges records from two arrays using the specified primary key field.
  * When keys collide, the corresponding values are assumed to be arrays and they are merged.
  *
  * @param array|PowerArray $array
  * @param string           $field
  *
  * @return PowerArray Self, for chaining.
  */
 function joinRecords($array, $field)
 {
     // NOT IMPLEMENTED!!! DUMMY CODE!
     $this->A = array_join($this->A, $array instanceof self ? $array->A : $array, $field);
     return $this;
 }