/**
  * Display the bulk actions dropdown.
  *
  * @since 3.1.0
  * @access public
  */
 function bulk_actions()
 {
     $screen = get_current_screen();
     if (is_null($this->_actions)) {
         $no_new_actions = $this->_actions = $this->get_bulk_actions();
         // This filter can currently only be used to remove actions.
         //$this->_actions = apply_filters( 'bulk_actions-cred' . $screen->id, $this->_actions );
         $this->_actions = array_intersect_assoc($this->_actions, $no_new_actions);
         $two = '';
     } else {
         $two = '2';
     }
     if (empty($this->_actions)) {
         return;
     }
     echo "<select name='action{$two}'>\n";
     echo "<option value='-1' selected='selected'>" . __('Bulk Actions', 'wp-cred') . "</option>\n";
     foreach ($this->_actions as $name => $title) {
         $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
         echo "\t<option value='{$name}'{$class}>{$title}</option>\n";
     }
     echo "</select>\n";
     submit_button(__('Apply', 'wp-cred'), 'button-secondary action', false, false, array('id' => "doaction{$two}"));
     echo "\n";
 }
Beispiel #2
0
 function context_check($check, $settings)
 {
     if (empty($settings)) {
         return $check;
     }
     $status = array();
     if (!is_array($this->post_types)) {
         $this->set_objects();
     }
     foreach ($this->post_types as $post_type => $post_type_settings) {
         if (isset($settings['is_singular-' . $post_type]) && $settings['is_singular-' . $post_type]) {
             $status['is_singular-' . $post_type] = is_singular($post_type);
         }
         if (isset($settings['is_archive-' . $post_type]) && $settings['is_archive-' . $post_type]) {
             $status['is_archive-' . $post_type] = is_post_type_archive($post_type);
         }
     }
     foreach ($this->taxonomies as $taxonomy => $tax_settings) {
         if (isset($settings['is_tax-' . $taxonomy]) && $settings['is_tax-' . $taxonomy]) {
             $status['is_tax-' . $taxonomy] = is_tax($taxonomy);
         }
     }
     $matched = array_intersect_assoc($settings, $status);
     if (!empty($matched)) {
         return true;
     }
     return $check;
 }
Beispiel #3
0
 /**
  *
  * Merge array two arrays recursively
  * @see testing : M/tests/MArray_test.php
  *
  * @access	public
  * @return	Merged array	array
  * @static
  *
  */
 public static function array_merge_recursive_unique($first, $second, $greedy = false)
 {
     $inter = array_intersect_assoc(array_keys($first), array_keys($second));
     # shaired keys
     # the idea next, is to strip and append from $second into $first
     foreach ($inter as $key) {
         # recursion if both are arrays
         if (is_array($first[$key]) && is_array($second[$key])) {
             $first[$key] = self::array_merge_recursive_unique($first[$key], $second[$key]);
         } else {
             if (is_array($first[$key] && !$greedy)) {
                 $first[$key][] = $second[$key];
             } else {
                 if (is_array($second[$key]) && !$greedy) {
                     $second[$key][] = $first[$key];
                     $first[$key] = $second[$key];
                 } else {
                     $first[$key] = $second[$key];
                 }
             }
         }
         unset($second[$key]);
     }
     # merge the unmatching keys onto first
     return array_merge($first, $second);
 }
 /**
  * Extract current session page
  *
  * @param string $root_path current root path (phpbb_root_path)
  */
 function extract_current_page($root_path)
 {
     $page_array = array();
     // First of all, get the request uri...
     $script_name = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
     $args = !empty($_SERVER['QUERY_STRING']) ? explode('&', $_SERVER['QUERY_STRING']) : explode('&', getenv('QUERY_STRING'));
     // If we are unable to get the script name we use REQUEST_URI as a failover and note it within the page array for easier support...
     if (!$script_name) {
         $script_name = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
         $script_name = ($pos = strpos($script_name, '?')) !== false ? substr($script_name, 0, $pos) : $script_name;
         $page_array['failover'] = 1;
     }
     // Replace backslashes and doubled slashes (could happen on some proxy setups)
     $script_name = str_replace(array('\\', '//'), '/', $script_name);
     // Now, remove the sid and let us get a clean query string...
     $use_args = array();
     // Since some browser do not encode correctly we need to do this with some "special" characters...
     // " -> %22, ' => %27, < -> %3C, > -> %3E
     $find = array('"', "'", '<', '>');
     $replace = array('%22', '%27', '%3C', '%3E');
     foreach ($args as $key => $argument) {
         if (strpos($argument, 'sid=') === 0) {
             continue;
         }
         $use_args[] = str_replace($find, $replace, $argument);
     }
     unset($args);
     // The following examples given are for an request uri of {path to the phpbb directory}/adm/index.php?i=10&b=2
     // The current query string
     $query_string = trim(implode('&', $use_args));
     // basenamed page name (for example: index.php)
     $page_name = substr($script_name, -1, 1) == '/' ? '' : basename($script_name);
     $page_name = urlencode(htmlspecialchars($page_name));
     // current directory within the phpBB root (for example: adm)
     $root_dirs = explode('/', str_replace('\\', '/', phpbb_realpath($root_path)));
     $page_dirs = explode('/', str_replace('\\', '/', phpbb_realpath('./')));
     $intersection = array_intersect_assoc($root_dirs, $page_dirs);
     $root_dirs = array_diff_assoc($root_dirs, $intersection);
     $page_dirs = array_diff_assoc($page_dirs, $intersection);
     $page_dir = str_repeat('../', sizeof($root_dirs)) . implode('/', $page_dirs);
     if ($page_dir && substr($page_dir, -1, 1) == '/') {
         $page_dir = substr($page_dir, 0, -1);
     }
     // Current page from phpBB root (for example: adm/index.php?i=10&b=2)
     $page = ($page_dir ? $page_dir . '/' : '') . $page_name . ($query_string ? "?{$query_string}" : '');
     // The script path from the webroot to the current directory (for example: /phpBB3/adm/) : always prefixed with / and ends in /
     $script_path = trim(str_replace('\\', '/', dirname($script_name)));
     // The script path from the webroot to the phpBB root (for example: /phpBB3/)
     $script_dirs = explode('/', $script_path);
     array_splice($script_dirs, -sizeof($page_dirs));
     $root_script_path = implode('/', $script_dirs) . (sizeof($root_dirs) ? '/' . implode('/', $root_dirs) : '');
     // We are on the base level (phpBB root == webroot), lets adjust the variables a bit...
     if (!$root_script_path) {
         $root_script_path = $page_dir ? str_replace($page_dir, '', $script_path) : $script_path;
     }
     $script_path .= substr($script_path, -1, 1) == '/' ? '' : '/';
     $root_script_path .= substr($root_script_path, -1, 1) == '/' ? '' : '/';
     $page_array += array('page_name' => $page_name, 'page_dir' => $page_dir, 'query_string' => $query_string, 'script_path' => str_replace(' ', '%20', htmlspecialchars($script_path)), 'root_script_path' => str_replace(' ', '%20', htmlspecialchars($root_script_path)), 'page' => $page, 'forum' => isset($_REQUEST['f']) && $_REQUEST['f'] > 0 ? (int) $_REQUEST['f'] : 0);
     return $page_array;
 }
Beispiel #5
0
 private function _aGetCurrentMenu()
 {
     $cur_uri = KOperation_Func::sGetCurUri();
     $cur_uri_params = KOperation_Func::aGetCurUriParams();
     $has_params = false;
     $cur_menu = array();
     if ($cur_uri) {
         $menu_api = new KOperation_Menu_Api();
         $cur_menus = $menu_api->aGetByUri($cur_uri);
         if ($cur_menus) {
             foreach ($cur_menus as $menu) {
                 $tmp_menu_params = KOperation_Func::aGetUriParams($menu['url']);
                 if ($cur_uri_params === $tmp_menu_params || count(array_intersect_assoc($tmp_menu_params, $cur_uri_params)) > 0) {
                     $cur_menu = $menu;
                     $has_params = true;
                     break;
                 }
             }
         }
     }
     if (!$has_params && !empty($cur_menus)) {
         $cur_menu = array_shift($cur_menus);
     }
     return $cur_menu;
 }
Beispiel #6
0
 public static function getTypes(array $filter = null)
 {
     if (!($types =& static::$types)) {
         static::getTypesInternal();
     }
     if (!static::$ready) {
         static::$ready = true;
         uasort($types, function ($a, $b) {
             $a = $a['SORT'];
             $b = $b['SORT'];
             return $a < $b ? -1 : ($a > $b ? 1 : 0);
         });
         if (static::$checkModule) {
             $modules = Config::getModules();
             foreach ($types as &$type) {
                 $module = $modules[$type['MODULE']];
                 $type['ACTIVE'] = $module && $module['ACTIVE'];
             }
             unset($type);
         }
     }
     if ($filter) {
         $count = count($filter);
         return array_filter($types, function (array $type) use($count, $filter) {
             return $count == count(array_intersect_assoc($filter, $type));
         });
     } else {
         return $types;
     }
 }
 /**
  * Display the bulk actions dropdown.
  *
  * @since 3.1.0
  * @access public
  */
 function bulk_actions()
 {
     $screen = get_current_screen();
     if (is_null($this->_actions)) {
         $no_new_actions = $this->_actions = $this->get_bulk_actions();
         // This filter can currently only be used to remove actions.
         //$this->_actions = apply_filters( 'bulk_actions-cred' . $screen->id, $this->_actions );
         $this->_actions = array_intersect_assoc($this->_actions, $no_new_actions);
         $two = '';
     } else {
         $two = '2';
     }
     if (empty($this->_actions)) {
         return;
     }
     echo "<select name='action{$two}'>\n";
     echo "<option value='-1' selected='selected'>" . __('Bulk Actions', 'wp-cred') . "</option>\n";
     foreach ($this->_actions as $name => $title) {
         $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
         echo "\t<option value='{$name}'{$class}>{$title}</option>\n";
     }
     echo "</select>\n";
     submit_button(__('Apply', 'wp-cred'), 'button-secondary action', false, false, array('id' => "doaction{$two}"));
     echo "\n";
     echo "<a style='margin-left:15px' class='button cred-export-all' href='" . cred_route('/Forms/exportAll?all&_wpnonce=' . wp_create_nonce('cred-export-all')) . "' target='_blank' title='" . __('Export All Forms', 'wp-cred') . "'>" . __('Export All Forms', 'wp-cred') . "</a>";
 }
Beispiel #8
0
 /**
  * Adds phone numbers from Order to shipping and billing address records.
  *
  * @param $order
  */
 protected function updateAddresses($order)
 {
     $data = $order->toMap();
     // this is for matching existing address, we don't match on phone numbers though
     $shippingAddress = Address_Shipping::create(array('MemberID' => $this->owner->Member()->ID, 'FirstName' => $data['ShippingFirstName'], 'Surname' => $data['ShippingSurname'], 'Company' => $data['ShippingCompany'], 'Address' => $data['ShippingAddress'], 'AddressLine2' => $data['ShippingAddressLine2'], 'City' => $data['ShippingCity'], 'PostalCode' => $data['ShippingPostalCode'], 'State' => $data['ShippingState'], 'CountryName' => $data['ShippingCountryName'], 'CountryCode' => $data['ShippingCountryCode'], 'RegionName' => isset($data['ShippingRegionName']) ? $data['ShippingRegionName'] : null, 'RegionCode' => isset($data['ShippingRegionCode']) ? $data['ShippingRegionCode'] : null));
     $newShipping = array_filter($shippingAddress->toMap());
     $billingAddress = Address_Billing::create(array('MemberID' => $this->owner->Member()->ID, 'FirstName' => $data['BillingFirstName'], 'Surname' => $data['BillingSurname'], 'Company' => $data['BillingCompany'], 'Address' => $data['BillingAddress'], 'AddressLine2' => $data['BillingAddressLine2'], 'City' => $data['BillingCity'], 'PostalCode' => $data['BillingPostalCode'], 'State' => $data['BillingState'], 'CountryName' => $data['BillingCountryName'], 'CountryCode' => $data['BillingCountryCode'], 'RegionName' => isset($data['BillingRegionName']) ? $data['ShippingRegionName'] : null, 'RegionCode' => isset($data['BillingRegionCode']) ? $data['ShippingRegionCode'] : null));
     $newBilling = array_filter($billingAddress->toMap());
     foreach ($this->owner->Member()->ShippingAddresses() as $address) {
         $existing = array_filter($address->toMap());
         $result = array_intersect_assoc($existing, $newShipping);
         //If no difference, then match is found
         $diff = array_diff_assoc($newShipping, $result);
         $match = empty($diff);
         if ($match) {
             $address->StreakPhone = $order->ShippingStreakPhone;
             $address->StreakMobile = $order->ShippingStreakMobile;
             $address->write();
         }
     }
     foreach ($this->owner->Member()->BillingAddresses() as $address) {
         $existing = array_filter($address->toMap());
         $result = array_intersect_assoc($existing, $newBilling);
         $diff = array_diff_assoc($newBilling, $result);
         $match = empty($diff);
         if ($match) {
             $address->StreakPhone = $order->BillingStreakPhone;
             $address->StreakMobile = $order->BillingStreakMobile;
             $address->write();
         }
     }
 }
Beispiel #9
0
 public function findByTerms($queryString)
 {
     $terms = explode(" ", trim(preg_replace("/[ ]+/", " ", $queryString)));
     $results = null;
     foreach ($terms as $term) {
         if (strlen($term) < 2) {
             continue;
         }
         $q = $this->createQueryBuilder();
         $q->field('cloture')->equals(false);
         $q->field('numeroFacture')->notEqual(null);
         if (preg_match('/^[0-9]+\\.[0-9]+$/', $term)) {
             $nbInf = $term - 0.0001;
             $nbSup = $term + 0.0001;
             $q->addOr($q->expr()->field('montantTTC')->lt($nbSup)->gt($nbInf))->addOr($q->expr()->field('montantAPayer')->lt($nbSup)->gt($nbInf));
         } else {
             $q->addOr($q->expr()->field('destinataire.nom')->equals(new \MongoRegex('/.*' . RechercheTool::getCorrespondances($term) . '.*/i')))->addOr($q->expr()->field('numeroFacture')->equals(new \MongoRegex('/.*' . $term . '.*/i')));
         }
         $factures = $q->limit(1000)->getQuery()->execute();
         $currentResults = array();
         foreach ($factures as $facture) {
             $currentResults[$facture->getId()] = $facture->__toString();
         }
         if (!is_null($results)) {
             $results = array_intersect_assoc($results, $currentResults);
         } else {
             $results = $currentResults;
         }
     }
     return is_null($results) ? array() : $results;
 }
Beispiel #10
0
 public function findByTerms($queryString, $withNonActif = false, $limit = 1000, $mixWith = false)
 {
     $terms = explode(" ", trim(preg_replace("/[ ]+/", " ", $queryString)));
     $results = null;
     foreach ($terms as $term) {
         if (strlen($term) < 2) {
             continue;
         }
         $q = $this->createQueryBuilder();
         $q->addOr($q->expr()->field('identifiant')->equals(new \MongoRegex('/.*' . $term . '.*/i')))->addOr($q->expr()->field('raisonSociale')->equals(new \MongoRegex('/.*' . RechercheTool::getCorrespondances($term) . '.*/i')))->addOr($q->expr()->field('adresse.adresse')->equals(new \MongoRegex('/.*' . RechercheTool::getCorrespondances($term) . '.*/i')))->addOr($q->expr()->field('adresse.codePostal')->equals(new \MongoRegex('/.*' . $term . '.*/i')))->addOr($q->expr()->field('adresse.commune')->equals(new \MongoRegex('/.*' . RechercheTool::getCorrespondances($term) . '.*/i')));
         if (!$withNonActif) {
             $q->field('actif')->equals(true);
         }
         $societes = $q->limit($limit)->getQuery()->execute();
         $currentResults = array();
         foreach ($societes as $societe) {
             if ($mixWith) {
                 $currentResults[$societe->getId()] = array("doc" => $societe, "score" => "1", "instance" => "Societe");
             } else {
                 $currentResults[$societe->getId()] = $societe->getIntitule();
             }
         }
         if (!is_null($results)) {
             $results = array_intersect_assoc($results, $currentResults);
         } else {
             $results = $currentResults;
         }
     }
     return is_null($results) ? array() : $results;
 }
 public function isActive($recursive = false)
 {
     if ($this->request->attributes->get('_route') == $this->route) {
         return count(array_intersect_assoc($this->params, $this->request->query->all())) >= count($this->params);
     }
     return false;
 }
Beispiel #12
0
 /**
  * Test a very simple RESTful POST request.
  *
  * @group controller
  */
 public function testPostFromForm()
 {
     $bodyRaw = ['message' => 'mock me do you mocker?'];
     $this->mockEnvironment(['PATH_INFO' => '/', 'REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'slim.input' => 'target=mocker']);
     $response = $this->tacit->invoke();
     $this->assertEquals(array_intersect_assoc($bodyRaw, json_decode($response->getBody(), true)), $bodyRaw);
 }
Beispiel #13
0
 public function testSetGetParams()
 {
     $params = array('foo' => 'bar', 'boo' => 'bah', 'fee' => 'fi');
     $this->_request->setParams($params);
     $received = $this->_request->getParams();
     $this->assertSame($params, array_intersect_assoc($params, $received));
 }
 function updateCartProductPreHook(&$params, &$reference)
 {
     error_log("updateCartPostHook - begin");
     $shopping_cart_item = $params['shopping_cart_item'];
     $cart_product =& $params['cart']['products'][$shopping_cart_item];
     $product_id = $cart_product['products_id'];
     $attributes = $cart_product['attributes'];
     foreach ($attributes as $attr) {
         $attribute_id = $attr['products_attributes_id'];
         $qry_res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('va.variant_id', 'tx_msvariants_domain_model_variantsattributes va', 'va.product_id=' . $product_id . ' and va.attribute_id=' . $attribute_id);
         $ids = array();
         while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry_res)) != false) {
             $ids[$row['variant_id']] = '';
         }
         if (!isset($variant_id)) {
             $variant_id = $ids;
         } else {
             $variant_id = array_intersect_assoc($variant_id, $ids);
         }
     }
     // Variant found
     if (count($variant_id) == 1) {
         $cart_product['variant_id'] = array_keys($variant_id)[0];
     } else {
     }
     error_log("updateCartPostHook - end");
 }
 public function test_basic()
 {
     $g = new GroongaServer(array('groonga' => $this->bin));
     $g->run();
     $args = json_decode(file_get_contents($this->out), true);
     $expect = array('db' => $g->getDb(), '-d' => true, '--port' => (string) $g->getPort(), '--protocol' => 'http', '--log-path' => $g->getLogFile(), '-n' => true);
     $this->assertSame($expect, array_intersect_assoc($expect, $args));
 }
 /**
  * Checks the Module::getNamespaces() method.
  */
 public function testModuleNamespaces()
 {
     $expected_values = array('Drupal\\plug' => drupal_get_path('module', 'plug') . '/src', 'Drupal\\field' => 'modules/field/src', 'Drupal\\field_sql_storage' => 'modules/field/modules/field_sql_storage/src', 'Drupal\\filter' => 'modules/filter/src', 'Drupal\\node' => 'modules/node/src', 'Drupal\\user' => 'modules/user/src', 'Drupal\\standard' => 'profiles/standard/src', 'Drupal\\system' => 'modules/system/src');
     $namespaces = Module::getNamespaces();
     $this->assertEqual($expected_values, array_intersect_assoc($namespaces->getArrayCopy(), $expected_values));
     $cached_data = cache_get('module_namespaces');
     $this->assertEqual($expected_values, array_intersect_assoc($cached_data->data, $expected_values));
 }
 /**
  * Test a very simple RESTful POST request with Basic authentication.
  *
  * @group controller
  */
 public function testPostFromJson()
 {
     $bodyRaw = ['message' => 'mock me do you mocker?'];
     $clientKey = 'cb892ecb-6458-425c-9e3a-b3e99ec86f56';
     $secretKey = '4M2U1KSlv0jmqLAgs118fq4dugd534eP';
     $this->mockEnvironment(['PATH_INFO' => '/basic-test', 'REQUEST_METHOD' => 'POST', 'PHP_AUTH_USER' => $clientKey, 'PHP_AUTH_PW' => $secretKey, 'CONTENT_TYPE' => 'application/json', 'slim.input' => '{"target":"mocker"}']);
     $response = $this->tacit->invoke();
     $this->assertEquals(array_intersect_assoc($bodyRaw, json_decode($response->getBody(), true)), $bodyRaw);
 }
Beispiel #18
0
 protected function in_basket($basket, $product)
 {
     foreach ($basket as $key => $value) {
         if (count(array_intersect_assoc($basket[$key], $product)) == count($product)) {
             return $key;
         }
     }
     return -1;
 }
Beispiel #19
0
 /**
  * @param string $path
  * @param array  $params
  * @return bool True if path/queries match
  */
 public final function compare($path, array $params = array())
 {
     /** @var CM_Page_Abstract $pageClassName */
     $pageClassName = $this->getPageName();
     if ($path == $pageClassName::getPath() && array_intersect_assoc($this->getParams(), $params) == $this->getParams()) {
         return true;
     }
     return false;
 }
Beispiel #20
0
 function array_intersect_compare($array1, $array2)
 {
     $common_keys = array_intersect_key($array2, $array1);
     $common_values = array_intersect_assoc($array2, $array1);
     $against = array_intersect_key($common_keys, $common_values);
     if ($common_keys == $against) {
         return true;
     }
     return false;
 }
 /**
  * Test a very simple RESTful POST request with Basic authentication.
  *
  * @group controller
  */
 public function testPostFromJson()
 {
     $bodyRaw = ['message' => 'mock me do you mocker?'];
     $clientKey = 'cb892ecb-6458-425c-9e3a-b3e99ec86f56';
     $secretKey = '4M2U1KSlv0jmqLAgs118fq4dugd534eP';
     $fingerprint = implode("\n", ['POST', md5('{"target":"mocker"}'), 'application/json', '/hmac-test']);
     $this->mockEnvironment(['PATH_INFO' => '/hmac-test', 'REQUEST_METHOD' => 'POST', 'CONTENT_TYPE' => 'application/json', 'Http_Content-MD5' => md5(''), 'Http_Signature-HMAC' => dechex(time()) . ':' . $clientKey . ':' . hash_hmac('sha1', $fingerprint, $secretKey), 'slim.input' => '{"target":"mocker"}']);
     $response = $this->tacit->invoke();
     $this->assertEquals($bodyRaw, array_intersect_assoc($bodyRaw, json_decode($response->getBody(), true)));
 }
Beispiel #22
0
 /**
  * Outputs a stack trace based on the supplied options.
  *
  * @param array $options Format for outputting stack trace. Available options are:
  *        - `'args'`: A boolean indicating if arguments should be included.
  *        - `'depth'`: The maximum depth of the trace.
  *        - `'format'`: Either `null`, `'points'` or `'array'`.
  *        - `'includeScope'`: A boolean indicating if items within scope
  *           should be included.
  *        - `'scope'`: Scope for items to include.
  *        - `'start'`: The depth to start with.
  *        - `'trace'`: A trace to use instead of generating one.
  * @return string|array|null Stack trace formatted according to `'format'` option.
  */
 public static function trace(array $options = array())
 {
     $defaults = array('depth' => 999, 'format' => null, 'args' => false, 'start' => 0, 'scope' => array(), 'trace' => array(), 'includeScope' => true, 'closures' => true);
     $options += $defaults;
     $backtrace = $options['trace'] ?: debug_backtrace();
     $scope = $options['scope'];
     $count = count($backtrace);
     $back = array();
     $traceDefault = array('line' => '??', 'file' => '[internal]', 'class' => null, 'function' => '[main]');
     for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
         $trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]);
         $function = '[main]';
         if (isset($backtrace[$i + 1])) {
             $next = $backtrace[$i + 1] + $traceDefault;
             $function = $next['function'];
             if (!empty($next['class'])) {
                 $function = $next['class'] . '::' . $function . '(';
                 if ($options['args'] && isset($next['args'])) {
                     $args = array_map(array('static', 'export'), $next['args']);
                     $function .= join(', ', $args);
                 }
                 $function .= ')';
             }
         }
         if ($options['closures'] && strpos($function, '{closure}') !== false) {
             $function = static::_closureDef($backtrace[$i], $function);
         }
         if (in_array($function, array('call_user_func_array', 'trigger_error'))) {
             continue;
         }
         $trace['functionRef'] = $function;
         if ($options['format'] === 'points' && $trace['file'] !== '[internal]') {
             $back[] = array('file' => $trace['file'], 'line' => $trace['line']);
         } elseif (is_string($options['format']) && $options['format'] !== 'array') {
             $back[] = String::insert($options['format'], array_map(function ($data) {
                 return is_object($data) ? get_class($data) : $data;
             }, $trace));
         } elseif (empty($options['format'])) {
             $back[] = $function . ' - ' . $trace['file'] . ', line ' . $trace['line'];
         } else {
             $back[] = $trace;
         }
         if (!empty($scope) && array_intersect_assoc($scope, $trace) == $scope) {
             if (!$options['includeScope']) {
                 $back = array_slice($back, 0, count($back) - 1);
             }
             break;
         }
     }
     if ($options['format'] === 'array' || $options['format'] === 'points') {
         return $back;
     }
     return join("\n", $back);
 }
Beispiel #23
0
function getRelativePath($path, $from = __FILE__)
{
    $path = explode(DIRECTORY_SEPARATOR, $path);
    $from = explode(DIRECTORY_SEPARATOR, dirname($from . '.'));
    $common = array_intersect_assoc($path, $from);
    $base = array('.');
    if ($pre_fill = count(array_diff_assoc($from, $common))) {
        $base = array_fill(0, $pre_fill, '..');
    }
    $path = array_merge($base, array_diff_assoc($path, $common));
    return implode(DIRECTORY_SEPARATOR, $path);
}
 /**
  * @View(serializerGroups={"list"}, serializerEnableMaxDepthChecks=true)
  * @QueryParam(name="page", requirements="\d+", default="1")
  * @QueryParam(name="limit", requirements="\d+", default="7")
  *
  * @param Request $request
  * @param ParamFetcher $paramFetcher
  * @return \FOS\RestBundle\View\View
  */
 public function cgetAction(Request $request, ParamFetcher $paramFetcher)
 {
     $params = array_intersect_assoc($paramFetcher->all(), $request->query->all());
     /** @var Pagerfanta $pager */
     $pager = $this->getHandler()->cget($paramFetcher->all(), array_diff_assoc($request->query->all(), $params));
     $view = RestView::create(iterator_to_array($pager->getCurrentPageResults()), Codes::HTTP_OK, array('X-Current-Page' => $pager->getCurrentPage(), 'X-Total-Count' => $pager->getNbResults(), 'X-Total-Pages' => $pager->getNbPages(), 'X-Per-Page' => $pager->getMaxPerPage()));
     $context = SerializationContext::create();
     $context->enableMaxDepthChecks();
     $context->setGroups(array('list'));
     $view->setSerializationContext($context);
     return $view;
 }
Beispiel #25
0
 /**
  * Extract current session page
  *
  * @param string $root_path current root path (phpbb_root_path)
  */
 function extract_current_page($root_path)
 {
     $page_array = array();
     // First of all, get the request uri...
     $script_name = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
     $args = !empty($_SERVER['QUERY_STRING']) ? explode('&', $_SERVER['QUERY_STRING']) : explode('&', getenv('QUERY_STRING'));
     // If we are unable to get the script name we use REQUEST_URI as a failover and note it within the page array for easier support...
     if (!$script_name) {
         $script_name = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
         $page_array['failover'] = 1;
     }
     // Replace backslashes and doubled slashes (could happen on some proxy setups)
     $script_name = str_replace(array('\\', '//'), '/', $script_name);
     // Now, remove the sid and let us get a clean query string...
     foreach ($args as $key => $argument) {
         if (strpos($argument, 'sid=') === 0) {
             unset($args[$key]);
             break;
         }
     }
     // The following examples given are for an request uri of {path to the phpbb directory}/adm/index.php?i=10&b=2
     // The current query string
     $query_string = trim(implode('&', $args));
     // basenamed page name (for example: index.php)
     $page_name = htmlspecialchars(basename($script_name));
     // current directory within the phpBB root (for example: adm)
     $root_dirs = explode('/', str_replace('\\', '/', realpath($root_path)));
     $page_dirs = explode('/', str_replace('\\', '/', realpath('./')));
     $intersection = array_intersect_assoc($root_dirs, $page_dirs);
     $root_dirs = array_diff_assoc($root_dirs, $intersection);
     $page_dirs = array_diff_assoc($page_dirs, $intersection);
     $page_dir = str_repeat('../', sizeof($root_dirs)) . implode('/', $page_dirs);
     if ($page_dir && substr($page_dir, -1, 1) == '/') {
         $page_dir = substr($page_dir, 0, -1);
     }
     // Current page from phpBB root (for example: adm/index.php?i=10&b=2)
     $page = ($page_dir ? $page_dir . '/' : '') . $page_name . ($query_string ? "?{$query_string}" : '');
     // The script path from the webroot to the current directory (for example: /phpBB2/adm/) : always prefixed with / and ends in /
     $script_path = trim(str_replace('\\', '/', dirname($script_name)));
     // The script path from the webroot to the phpBB root (for example: /phpBB2/)
     $script_dirs = explode('/', $script_path);
     array_splice($script_dirs, -sizeof($page_dirs));
     $root_script_path = implode('/', $script_dirs) . (sizeof($root_dirs) ? '/' . implode('/', $root_dirs) : '');
     // We are on the base level (phpBB root == webroot), lets adjust the variables a bit...
     if (!$root_script_path) {
         $root_script_path = $page_dir ? str_replace($page_dir, '', $script_path) : $script_path;
     }
     $script_path .= substr($script_path, -1, 1) == '/' ? '' : '/';
     $root_script_path .= substr($root_script_path, -1, 1) == '/' ? '' : '/';
     $page_array += array('page_name' => $page_name, 'page_dir' => $page_dir, 'query_string' => $query_string, 'script_path' => htmlspecialchars($script_path), 'root_script_path' => htmlspecialchars($root_script_path), 'page' => $page);
     return $page_array;
 }
 public function testGetNextStatusListData()
 {
     $model = new Item04();
     $model->enterWorkflow();
     $ar = WorkflowHelper::getNextStatusListData($model);
     $expected = ['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published'];
     $this->assertEquals(2, count($ar));
     $this->assertEquals(2, count(array_intersect_assoc($expected, $ar)));
     $model->sendTostatus('B');
     $ar = WorkflowHelper::getNextStatusListData($model, false, false, true);
     $this->assertEquals(3, count($ar));
     $this->assertEquals(3, count(array_intersect_assoc(['Item04Workflow/A' => 'Entry', 'Item04Workflow/B' => 'Published', 'Item04Workflow/C' => 'node C'], $ar)));
 }
Beispiel #27
0
 public function getAcceptedValue(array $accept)
 {
     if (empty($accept)) {
         throw new \InvalidArgumentException('List of accepted formats cannot be empty');
     }
     try {
         $accept = $this->getParsedValues($accept);
     } catch (\DomainException $e) {
         throw new \InvalidArgumentException('List of accepted formats contains an invalid value', 0, $e);
     }
     // We're supposed to get all matching values, then order by quality first,
     // and "tiebreak" by specificity if we have >1 matches with the highest
     // quality. Specificity is determined by type matching first (wildcards
     // make the match less specific) and count of additional parameters later
     // (more parameters = better match).
     //
     // Separating these steps in separate algorithms may hurt performance, so
     // we'll do it all at once and compare input scores against best scores
     // first ... Chances are that higher quality/specificity inputs will come
     // first, so we should save a lot of processing.
     $bestMatch = [null, 0.0, 3, -1];
     foreach ($this->getParsedValues() as $inputString => &$inputArray) {
         if ($inputArray['quality'] < $bestMatch[1] or $inputArray['topLevel'] === '*' && $bestMatch[2] < 2 or $inputArray['subType'] === '*' && $bestMatch[2] === 0 or ($params = \count($inputArray['params'])) <= $bestMatch[3]) {
             continue;
         }
         // Non-wildcard matches
         if ($inputArray['subType'] !== '*') {
             foreach ($accept as $acceptString => &$acceptArray) {
                 // Best possible match
                 if ($inputString === $acceptString) {
                     return $acceptString;
                 } elseif ($inputArray['value'] === $acceptArray['value'] && $params > $bestMatch[3] && $params === \count(\array_intersect_assoc($acceptArray['params'], $inputArray['params']))) {
                     $bestMatch = [$acceptString, $inputArray['quality'], 0, $params];
                 }
             }
         } elseif ($bestMatch[2] > 0 && $inputArray['topLevel'] !== '*') {
             foreach ($accept as $acceptString => &$acceptArray) {
                 if ($inputArray['topLevel'] === $acceptArray['topLevel']) {
                     $bestMatch = [$acceptString, $inputArray['quality'], 1, $params];
                     continue 2;
                 }
             }
         } elseif ($bestMatch[2] > 1) {
             $bestMatch = [\array_keys($accept)[0], $inputArray['quality'], 2, $params];
         }
     }
     if (!isset($bestMatch[0]) or $bestMatch[1] === 0.0) {
         throw new \DomainException('Content negotiation failed, no acceptable format was found');
     }
     return $bestMatch[0];
 }
Beispiel #28
0
 /**
  * 检查权限
  * @param $name string|array  需要验证的规则列表,支持分隔的权限规则或索引数组
  * @param $uid  int           认证用户的id
  * @param $type  int          认证方式
  * @param $mode string        执行check的模式
  * @param $relation string    如果为 'or' 表示满足任一条规则即通过验证;如果为 'and'则表示需满足所有规则才能通过验证
  * @return boolean           通过验证返回true;失败返回false
  * @author liuxiaolin <*****@*****.**>
  */
 public function check($name, $uid, $type = 1, $mode = 'url', $relation = 'or')
 {
     if (!$this->_config['AUTH_ON']) {
         return true;
     }
     //没有在权限控制表的路径,默认放行
     $notCheck = M('auth_rule')->where(array('url' => array('like', '%' . $name . '%')))->find();
     if (empty($notCheck)) {
         return true;
     }
     $authList = $this->getAuthList($uid, $type);
     //获取用户需要验证的所有有效规则列表
     if (is_string($name)) {
         $name = strtolower($name);
         if (strpos($name, ',') !== false) {
             $name = explode(',', $name);
         } else {
             $name = array($name);
         }
     }
     $list = array();
     //保存验证通过的规则名
     if ($mode == 'url') {
         $REQUEST = unserialize(strtolower(serialize($_REQUEST)));
     }
     foreach ($authList as $auth) {
         $query = preg_replace('/^.+\\?/U', '', $auth);
         if ($mode == 'url' && $query != $auth) {
             parse_str($query, $param);
             //解析规则中的param
             $intersect = array_intersect_assoc($REQUEST, $param);
             $auth = preg_replace('/\\?.*$/U', '', $auth);
             if (in_array($auth, $name) && $intersect == $param) {
                 //如果节点相符且url参数满足
                 $list[] = $auth;
             }
         } else {
             if (in_array($auth, $name)) {
                 $list[] = $auth;
             }
         }
     }
     if ($relation == 'or' and !empty($list)) {
         return true;
     }
     $diff = array_diff($name, $list);
     if ($relation == 'and' and empty($diff)) {
         return true;
     }
     return false;
 }
Beispiel #29
0
 /**
  * Remove cache polluted by other tests excluding performance critical cache (configuration, ddl)
  */
 protected function _cleanupCache()
 {
     /*
      * Cache cleanup relies on the initialized config object, which could be polluted from within a test.
      * For instance, any test could explicitly call Mage::reset() to destroy the config object.
      */
     $expectedOptions = Magento_Test_Bootstrap::getInstance()->getAppOptions();
     $actualOptions = Mage::getConfig() ? Mage::getConfig()->getOptions()->getData() : array();
     $isConfigPolluted = array_intersect_assoc($expectedOptions, $actualOptions) !== $expectedOptions;
     if ($isConfigPolluted) {
         Magento_Test_Bootstrap::getInstance()->initialize();
     }
     Mage::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, array(Mage_Core_Model_Config::CACHE_TAG, Varien_Db_Adapter_Pdo_Mysql::DDL_CACHE_TAG, 'DB_PDO_MSSQL_DDL', 'DB_ORACLE_DDL'));
 }
 /**
  * Calculates the Jacard Similarity between the comparators' scalar attributes
  * @param  Comparator $a
  * @param  Comparator $b
  * @return float        Jaccard Similarity
  */
 public function analyse(Comparator $a, Comparator $b)
 {
     $aa = $a->getScalarAttributes();
     $ba = $b->getScalarAttributes();
     if (count($aa) != count($ba)) {
         throw new \LogicException("Cannot compute similary: attributes arrays are unequal");
     }
     if (count($aa) == 0 && count($ba) == 0) {
         return 1;
     }
     //follows the convention that two empty objects are equal
     $this->similarity = count(array_intersect_assoc($aa, $ba)) / count($aa);
     return $this->similarity;
 }