/** * Publications Module * * @package modules * @subpackage publications module * @category Third Party Xaraya Module * @version 2.0.0 * @copyright (C) 2011 Netspan AG * @license GPL {@link http://www.gnu.org/licenses/gpl.html} * @author Marc Lutolf <*****@*****.**> */ function publications_userapi_prepareforbl($args) { if (empty($args['string'])) { return ''; } $args['string'] = str_replace(array_keys(merge_array()), merge_array(), $args['string']); return $args['string']; }
/** * Load language XML file(s) * * @param string $name * @param string $language * @param string $path * @param bool $merge * @param bool load_custom * @return array/false */ public function loadLanguageXML($name, $language = '', $path = CC_LANGUAGE_DIR, $merge = true, $load_custom = true) { $language = empty($language) ? $this->_language : $language; if (!$this->_checkPath($path)) { trigger_error('Invalid language path ' . $path, E_USER_ERROR); } if ($path !== CC_LANGUAGE_DIR) { $path = appendDS($path); } if ($GLOBALS['cache']->exists('lang.' . $name . '.xml.' . $language) && $GLOBALS['cache']->exists('lang.info.' . $language)) { $strings = $GLOBALS['cache']->read('lang.' . $name . '.xml.' . $language); $this->_language_data = $GLOBALS['cache']->read('lang.info.' . $language); } else { $strings = array(); $data = $this->_extractXML($path . $language); if (!empty($data)) { $xml = new SimpleXMLElement($data); if (!empty($xml)) { if (!empty($xml->info)) { foreach ((array) $xml->info as $key => $value) { $lang_data[$key] = (string) $value; } $GLOBALS['cache']->write($lang_data, 'lang.info.' . (string) $xml->info->code); $this->_language_data = $lang_data; } switch (floor((double) $xml->attributes()->version)) { case 2: //Â New format - Similar layout to the definition file if ($xml->translation && $xml->translation->group) { foreach ($xml->translation->group as $groups) { $group = (string) $groups->attributes()->name; foreach ($groups->string as $string) { $xml_name = $string->attributes()->name; $strings[(string) $group][(string) $xml_name] = trim((string) $string); } } unset($groups, $group, $xml_name, $string); } break; default: trigger_error('Language format error - exiting.', E_USER_WARNING); die; } } // Load custom strings from database if ($load_custom && isset($GLOBALS['db']) && ($custom = $GLOBALS['db']->select('CubeCart_lang_strings', false, array('language' => $language))) !== false) { foreach ($custom as $string) { $strings[(string) $string['type']][(string) $string['name']] = $string['value']; } } } unset($custom, $data, $string, $xml); if (!empty($this->_language_strings)) { $GLOBALS['cache']->write($strings, 'lang.' . $name . '.xml.' . $language); } } if ($merge && !empty($strings)) { $this->_language_strings = merge_array($this->_language_strings, $strings); } return !empty($strings) ? $strings : false; }
/** * Merge an emlemet to the config * * This is done for items that do not need to be recorded to the db * or are single use config items. For example ssl enable/disable. * * @param string $config_name * @param string $element * @param string $data */ public function merge($config_name, $element, $data) { if (!empty($element)) { $this->_temp[$config_name][$element] = $data; $this->_config[$config_name][$element] = $data; } else { if (is_array($data)) { if (isset($this->_temp[$config_name])) { $this->_temp[$config_name] = merge_array($this->_temp[$config_name], $data); } else { $this->_temp[$config_name] = $data; } $this->_config[$config_name] = merge_array($this->_config[$config_name], $data); } } }
/** * Display debug * * @param bool $return * @param glue $string * @return bool */ public function display($return = false, $glue = "\n") { // Cheeky hack for the w3c validator - we don't want it seeing the debug output if (strstr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { $this->_enabled = false; } if ($this->_display && $this->_enabled) { $output[] = "<div style='font-family: \"Courier New\",Courier,monospace;font-size: 10px;border-top: 5px dashed silver;color: #000;background-color: #E7E7E7; clear: both'>"; // Display the PHP errors $output[] = '<strong>PHP</strong>:<br />' . htmlspecialchars(strip_tags($this->_errorDisplay())) . '<hr size="1" />'; //Get the super globals if (($ret = $this->_makeExportString('GET', merge_array(array('Before Sanitise:' => $GLOBALS['RAW']['GET']), array('After Sanitise:' => $_GET)))) !== false) { $output[] = $ret; } if (($ret = $this->_makeExportString('POST', $_POST)) !== false) { $output[] = $ret; } if (isset($_SESSION) && !empty($_SESSION) && ($ret = $this->_makeExportString('SESSION', $_SESSION)) !== false) { $output[] = $ret; } if (($ret = $this->_makeExportString('COOKIE', $_COOKIE)) !== false) { $output[] = $ret; } if (($ret = $this->_makeExportString('FILES', $_FILES)) !== false) { $output[] = $ret; } //Custom timers if (!empty($this->_timers)) { $output[] = '<strong>Timers</strong><br />'; foreach ($this->_timers as $name => $timer) { $output[] = '<strong>' . $name . '</strong>: ' . $timer['diff'] . '<br />'; } $output[] = '<hr size="1" />'; } // Display SQL Queries and Errors if (!empty($this->_sql)) { $output[] = '<strong>' . Database::getInstance()->getDbEngine() . '</strong><br />'; if (!empty($this->_sql['query'])) { $output[] = '<strong>Queries (' . count($this->_sql['query']) . ')</strong>:<br />'; foreach ($this->_sql['query'] as $index => $query) { if (!empty($query)) { $output[] = '[<strong>' . ($index + 1) . '</strong>] ' . $query . '<br />'; } } } if (!empty($this->_sql['error'])) { $output[] = '<strong>Errors</strong>:<br />'; foreach ($this->_sql['error'] as $index => $error) { if (!empty($error)) { $sql_error = true; $output[] = '<span style="color: #ff0000">[<strong>' . ($index + 1) . '</strong>] ' . strip_tags($error) . '</span><br />'; } } if (!isset($sql_error)) { $output[] = 'No Errors'; } } $output[] = '<hr size="1" />'; } if (!empty($this->_messages)) { $output[] = '<strong>Debug Messages</strong>:<br />'; foreach ($this->_messages as $key => $message) { $output[] = '[' . $key . '] ' . $message . '<br />'; } $output[] = '<hr size="1" />'; } // Display logged variables if (!empty($this->_custom)) { foreach ($this->_custom as $name => $data) { if (empty($data)) { $data = 'No data'; } if (is_numeric($name)) { $name = "customLog[{$name}]"; } if (is_array($data)) { ksort($data); $data = '<pre>' . print_r($data, true) . '</pre>'; } $output[] = '<strong>' . htmlentities($name, ENT_QUOTES, 'UTF-8') . '</strong>:<br />' . $data . '<hr size="1" />'; } } // Show some performance data $output[] = '<strong>Memory: Peak Usage / Max (%)</strong>:<br />' . $this->_debugMemoryUsage(true) . '<hr size="1" />'; // Show cache stats //We need another cache instance because of the destruct $cache = Cache::getInstance(); $cache->status(); $cacheState = $cache->status ? '<span style="color: #008000">' . $cache->status_desc . '</span>' : '<span style="color: #ff0000">' . $cache->status_desc . '</span>'; $output[] = '<strong>Cache (' . $cache->getCacheSystem() . '): ' . $cacheState . '</strong><br />' . $cache->usage() . ' [<a href="' . currentPage(null, array('debug-cache-clear' => 'true')) . '">Clear Cache</a>]<hr size="1" />'; // Page render timer $output[] = '<strong>Page Load Time</strong>:<br />' . ($this->_getTime() - $this->_debug_timer) . ' seconds'; if ($this->_xdebug && ini_get('xdebug.profiler_enable_trigger') == 1) { $output[] = ' [<a href="' . currentPage(null, array('XDEBUG_PROFILE' => 'true')) . '">CacheGrind</a>]'; } $output[] = '</div>'; $content = implode($glue, $output); $this->_display = false; if ($return) { return $content; } else { echo $content; } } }
/** * Set a session value to something * * @param string $name * @param string $value * @param string $namespace * @param bool $overwrite * @return bool */ public function set($name, $value, $namespace = 'system', $overwrite = false) { $namespace = $this->_namespace($namespace); if ($this->_state != 'active') { return true; } if (is_null($value)) { unset($_SESSION[$namespace][$name]); } else { if (empty($name)) { if (!is_array($value)) { $_SESSION[$namespace] = $value; } else { if (isset($_SESSION[$namespace]) && !$overwrite) { $_SESSION[$namespace] = merge_array($_SESSION[$namespace], $value); } else { $_SESSION[$namespace] = $value; } } } else { if (!is_array($value)) { $_SESSION[$namespace][$name] = $value; } else { if (isset($_SESSION[$namespace][$name]) && !$overwrite) { $_SESSION[$namespace][$name] = merge_array($_SESSION[$namespace][$name], $value); } else { $_SESSION[$namespace][$name] = $value; } } } } return true; }
/** * Sends header of the API to the client. Those header containing the API-Version * and some more fields. * * @author Benjamin Carl <*****@*****.**> * @return void * @access public * @throws Doozr_Exception */ protected function sendHeader() { /* @var $response Doozr_Response_Web */ $response = $this->front->getResponse(); // Custom default header configured? try { $headers = object_to_array($this->configuration->kernel->transmission->response->header->api->rest); } catch (Exception $e) { $headers = []; } // add our REST API Header set ... $headers $headers = $this->normalizeHeaders(merge_array($this->getDefaultApiResponseHeader(), $headers)); // Send configured header foreach ($headers as $header) { $response->sendHeader($header); } }
foreach ($customers as $customer) { $customer_type[$customer['customer_id']] = $customer['type']; } foreach ($unsettled_orders as $order) { $cart_order_ids[] = "'" . $order['cart_order_id'] . "'"; $order['icon'] = $customer_type[$order['customer_id']] == 1 ? 'user_registered' : 'user_ghost'; $order['date'] = formatTime($order['order_date']); $order['total'] = Tax::getInstance()->priceFormat($order['total']); $order['status'] = $lang['order_state']['name_' . $order['status']]; $orders[$order['cart_order_id']] = $order; } if (($notes = $GLOBALS['db']->select('CubeCart_order_notes', '`cart_order_id`,`time`,`content`', array('cart_order_id' => $cart_order_ids))) !== false) { foreach ($notes as $note) { $order_notes[$note['cart_order_id']]['notes'][] = $note; } $orders = merge_array($orders, $order_notes); } $GLOBALS['smarty']->assign('ORDERS', $orders); $GLOBALS['smarty']->assign('ORDER_PAGINATION', $GLOBALS['db']->pagination($unsettled_count, $results_per_page, $page, $show = 5, 'orders', 'orders', $glue = ' ', $view_all = true)); } ## Product Reviews Tab $page = isset($_GET['reviews']) ? $_GET['reviews'] : 1; if (($reviews = $GLOBALS['db']->select('CubeCart_reviews', false, array('approved' => '0'), false, 25, $page)) !== false) { $reviews_count = $GLOBALS['db']->getFoundRows(); $GLOBALS['main']->addTabControl($lang['dashboard']['title_reviews_pending'], 'product_reviews', null, null, $reviews_count); foreach ($reviews as $review) { $product = $GLOBALS['db']->select('CubeCart_inventory', array('name'), array('product_id' => (int) $review['product_id'])); $review['product'] = $product[0]; $review['date'] = formatTime($review['time']); $review['delete'] = "?_g=products&node=reviews&delete=" . (int) $review['id']; $review['edit'] = "?_g=products&node=reviews&edit=" . (int) $review['id'];
function merge($b, $c, $a) { $i = $j = $k = 0; $p = count($b); $q = count($c); $a = array(); while ($i < $p && $j < $q) { if ($b[$i][0] <= $c[$j][0]) { $a[$k] = $b[$i]; $i++; } else { $a[$k] = $c[$j]; $j++; } $k++; } if ($i == $p) { $x = slice_array($c, $j, $q); } else { $x = slice_array($b, $i, $p); } return merge_array($a, $x); }
/** * Validate a route. * * @param string|array|Route|HasRoute $route A route array, string, or * object. * @return Route\Route Validated route. * @throws Route\RouteError If the route is invalid. * @throws \Jivoo\InvalidArgumentException If `$route` is not a recognized * type. */ public function validate($route) { if ($route instanceof Route\Route) { return $route; } if ($route instanceof Route\HasRoute) { return $this->validate($route->getRoute()); } if (is_callable($route)) { return new Route\CallableRoute($route); } if (is_string($route)) { if ($route == '') { $route = $this->findMatch([], 'GET'); if (!isset($route)) { throw new Route\RouteException('No root route'); } return $route; } else { if (preg_match('/^([a-zA-Z0-9\\.\\-+]+):/', $route, $matches) === 1) { $prefix = $matches[1]; if (isset($this->schemePrefixes[$prefix])) { $scheme = $this->schemePrefixes[$prefix]; return $scheme->fromString($route); } throw new Route\RouteException('Unknown route scheme: ' . $prefix); } // TODO: use current scheme .. e.g. 'action:' if in a controller throw new Route\RouteException('Missing route scheme'); } } \Jivoo\Assume::isArray($route); $default = ['parameters' => [], 'query' => [], 'fragment' => '', 'mergeQuery' => false]; $scheme = null; $parameters = []; foreach ($route as $key => $value) { if (is_int($key)) { $parameters[] = $value; } elseif ($key == 'parameters') { $parameters = array_merge($parameters, $value); } elseif (in_array($key, ['query', 'fragment', 'mergeQuery'])) { $default[$key] = $value; } elseif (isset($this->schemeKeys[$key])) { $default[$key] = $value; if (!isset($scheme)) { $scheme = $this->schemeKeys[$key]; } } else { throw new Route\RouteException('Undefined key in route: ' . $key); } } $route = $default; if (count($parameters)) { $route['parameters'] = $parameters; } if ($route['mergeQuery']) { $query = []; if (isset($this->request)) { $query = $this->request->getQueryParams(); } if (isset($route['query'])) { $query = merge_array($query, $route['query']); } $route['query'] = $query; } unset($route['mergeQuery']); if (isset($scheme)) { return $scheme->fromArray($route); } if (!isset($this->route)) { throw new Route\RouteException('Unknown route scheme'); } $copy = $this->route; if (isset($route['parameters'])) { $copy = $copy->withParameters($route['parameters']); } if (isset($route['query'])) { $copy = $copy->withQuery($route['query']); } if (isset($route['fragment'])) { $copy = $copy->withFragment($route['fragment']); } return $copy; }
$query2 = squery(0, $row[2]); while ($result2 = sql_fetch_array($query2)) { $selects[$row[0]][] = array($result2[0], $result2[1]); } sql_free_result($query2); } $row = $row[0]; } echo "<th>{$row}</th>"; } ?> </tr> <?php $curcol = "col2"; $cnt = 0; $query = squery(0, "SELECT " . $sql_id . "," . merge_array($sql_rows) . " FROM {$sql_table} ORDER BY " . $sql_id); if ($query) { while ($result = sql_fetch_array($query)) { $cnt++; if ($curcol == "col1") { $curcol = "col2"; } else { $curcol = "col1"; } ?> <tr> <?php foreach ($sql_rows as $row) { if (is_array($row)) { if ($row[1] == "password") { $text = "*";
/** * This method is an extension to PHP's builtin functions array_merge and array_merge_recursive but * with a little difference - This method replace existing values for duplicate keys instead of adding * a numeric index like array_merge_recursive does! * And it does not simply replace the existing keys like array_merge does - instead it extend existing * keys with new keys/values from second array given. * * @param array $array_1 The array which should be extended ($array_2 overwrites values of duplicate keys!) by $array_2 * @param array $array_2 The array which extend / overwrite values of $array_1 * * @example $resultingArray = merge_array($array_1, $array_2); * * @author Benjamin Carl <*****@*****.**> * * @return array The resulting / merged array */ function merge_array(array $array_1, array $array_2) { // Iterate over array which overwrites/supplements array_1 foreach ($array_2 as $key => $value) { // Check if element is an array or a value if (is_array($value)) { if (!isset($array_1[$key])) { // If key does not exist - just set it $array_1[$key] = $value; } else { // If key already exist - start recursion $array_1[$key] = merge_array($array_1[$key], $value); } } else { // Values could be stored directly $array_1[$key] = $value; } } // Return the new merged array return $array_1; }