Пример #1
4
/**
 * Dropdown(select with options) shortcode attribute type generator.
 *
 * @param $settings
 * @param $value
 *
 * @since 4.4
 * @return string - html string.
 */
function vc_dropdown_form_field($settings, $value)
{
    $output = '';
    $css_option = str_replace('#', 'hash-', vc_get_dropdown_option($settings, $value));
    $output .= '<select name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . ' ' . $css_option . '" data-option="' . $css_option . '">';
    if (is_array($value)) {
        $value = isset($value['value']) ? $value['value'] : array_shift($value);
    }
    if (!empty($settings['value'])) {
        foreach ($settings['value'] as $index => $data) {
            if (is_numeric($index) && (is_string($data) || is_numeric($data))) {
                $option_label = $data;
                $option_value = $data;
            } elseif (is_numeric($index) && is_array($data)) {
                $option_label = isset($data['label']) ? $data['label'] : array_pop($data);
                $option_value = isset($data['value']) ? $data['value'] : array_pop($data);
            } else {
                $option_value = $data;
                $option_label = $index;
            }
            $selected = '';
            $option_value_string = (string) $option_value;
            $value_string = (string) $value;
            if ('' !== $value && $option_value_string === $value_string) {
                $selected = ' selected="selected"';
            }
            $option_class = str_replace('#', 'hash-', $option_value);
            $output .= '<option class="' . esc_attr($option_class) . '" value="' . esc_attr($option_value) . '"' . $selected . '>' . htmlspecialchars($option_label) . '</option>';
        }
    }
    $output .= '</select>';
    return $output;
}
Пример #2
3
 /**
  * Saves default_billing and default_shipping flags for customer address
  *
  * @param array $addressIdList
  * @param array $extractedCustomerData
  * @return array
  */
 protected function saveDefaultFlags(array $addressIdList, array &$extractedCustomerData)
 {
     $result = [];
     $extractedCustomerData[CustomerInterface::DEFAULT_BILLING] = null;
     $extractedCustomerData[CustomerInterface::DEFAULT_SHIPPING] = null;
     foreach ($addressIdList as $addressId) {
         $scope = sprintf('address/%s', $addressId);
         $addressData = $this->_extractData($this->getRequest(), 'adminhtml_customer_address', \Magento\Customer\Api\AddressMetadataInterface::ENTITY_TYPE_ADDRESS, ['default_billing', 'default_shipping'], $scope);
         if (is_numeric($addressId)) {
             $addressData['id'] = $addressId;
         }
         // Set default billing and shipping flags to customer
         if (!empty($addressData['default_billing']) && $addressData['default_billing'] === 'true') {
             $extractedCustomerData[CustomerInterface::DEFAULT_BILLING] = $addressId;
             $addressData['default_billing'] = true;
         } else {
             $addressData['default_billing'] = false;
         }
         if (!empty($addressData['default_shipping']) && $addressData['default_shipping'] === 'true') {
             $extractedCustomerData[CustomerInterface::DEFAULT_SHIPPING] = $addressId;
             $addressData['default_shipping'] = true;
         } else {
             $addressData['default_shipping'] = false;
         }
         $result[] = $addressData;
     }
     return $result;
 }
function array_to_xml($phpResponse, &$phpResponseToXML)
{
    foreach ($phpResponse as $key => $value) {
        if (is_array($value)) {
            if (!is_numeric($key)) {
                // For non-numeric keys, give name same as key to the node
                $subnode = $phpResponseToXML->addChild("{$key}");
                // Recursive call to the function since the value was an array
                array_to_xml($value, $subnode);
            } else {
                // For numeric keys, give a name to the node
                //$subnode = $phpResponseToXML->addChild("item$key");
                if (current($phpResponseToXML->xpath('parent::*'))) {
                    $subnode = $phpResponseToXML->addChild("Showing");
                } else {
                    $subnode = $phpResponseToXML->addChild("Show");
                }
                //Recursive call to the function since the value was an array
                array_to_xml($value, $subnode);
            }
        } else {
            // Save the node and its value in XMLFiles format
            //$phpResponseToXML->addChild("$key","$value");
            $phpResponseToXML->{$key} = $value;
        }
    }
}
Пример #4
1
 /**
  * @param array $fields
  * @return array|null
  */
 public static function getEndpointFromFields(array $fields)
 {
     $arEndpointList = null;
     $fieldsTmp = array();
     foreach ($fields as $moduleId => $arConnectorSettings) {
         if (is_numeric($moduleId)) {
             $moduleId = '';
         }
         foreach ($arConnectorSettings as $connectorCode => $arConnectorFields) {
             foreach ($arConnectorFields as $k => $arFields) {
                 if (isset($fieldsTmp[$moduleId][$connectorCode][$k]) && is_array($arFields)) {
                     $fieldsTmp[$moduleId][$connectorCode][$k] = array_merge($fieldsTmp[$moduleId][$connectorCode][$k], $arFields);
                 } else {
                     $fieldsTmp[$moduleId][$connectorCode][$k] = $arFields;
                 }
             }
         }
     }
     foreach ($fieldsTmp as $moduleId => $arConnectorSettings) {
         if (is_numeric($moduleId)) {
             $moduleId = '';
         }
         foreach ($arConnectorSettings as $connectorCode => $arConnectorFields) {
             foreach ($arConnectorFields as $arFields) {
                 $arEndpoint = array();
                 $arEndpoint['MODULE_ID'] = $moduleId;
                 $arEndpoint['CODE'] = $connectorCode;
                 $arEndpoint['FIELDS'] = $arFields;
                 $arEndpointList[] = $arEndpoint;
             }
         }
     }
     return $arEndpointList;
 }
 /**
  * Parses the arguments for ":nth-child()" and friends.
  *
  * @param Token[] $tokens
  *
  * @throws SyntaxErrorException
  *
  * @return array
  */
 public static function parseSeries(array $tokens)
 {
     foreach ($tokens as $token) {
         if ($token->isString()) {
             throw SyntaxErrorException::stringAsFunctionArgument();
         }
     }
     $joined = trim(implode('', array_map(function (Token $token) {
         return $token->getValue();
     }, $tokens)));
     $int = function ($string) {
         if (!is_numeric($string)) {
             throw SyntaxErrorException::stringAsFunctionArgument();
         }
         return (int) $string;
     };
     switch (true) {
         case 'odd' === $joined:
             return array(2, 1);
         case 'even' === $joined:
             return array(2, 0);
         case 'n' === $joined:
             return array(1, 0);
         case false === strpos($joined, 'n'):
             return array(0, $int($joined));
     }
     $split = explode('n', $joined);
     $first = isset($split[0]) ? $split[0] : null;
     return array($first ? '-' === $first || '+' === $first ? $int($first . '1') : $int($first) : 1, isset($split[1]) && $split[1] ? $int($split[1]) : 0);
 }
 /**
  * @return ICC_Ecodes_Model_Downloadable
  */
 public function remainingSerialsReport()
 {
     /** added for log tracking by anil 28 jul **/
     $currDate = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
     $fileName = date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
     Mage::log("Controller Name : Ecode/Downloadable , Action Name : remainingSerialsReport , Start Time : {$currDate}", null, $fileName);
     /** end **/
     $threshold = Mage::getStoreConfig(self::XML_PATH_REPORT_THRESHOLD);
     $errors = array();
     if (!is_numeric($threshold) || $threshold < 0) {
         $error = "Threshold was not a positive integer.";
         $errors[] = $error;
         Mage::log("Error while attempting to run " . __METHOD__ . ". " . $error);
     } else {
         $notifications = $this->getCollection()->prepareForRemainingReport($threshold);
         if ($notifications->count()) {
             try {
                 $this->sendNotificationEmail($notifications);
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
     }
     /** added for log tracking by anil 28 jul start **/
     $currDate = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
     Mage::log("Controller Name : Ecode/Downloadable , Action Name : remainingSerialsReport , End Time : {$currDate}", null, $fileName);
     /** end **/
     return $this;
 }
Пример #7
0
 /**
  * Append any supported $content to $parent
  *
  * @param  DOMNode $parent  Node to append to
  * @param  mixed   $content Content to append
  * @return self
  */
 protected function XMLAppend(\DOMNode &$parent = null, $content = null)
 {
     if (is_null($parent)) {
         $parent = $this->root;
     }
     if (is_string($content) or is_numeric($content) or is_object($content) and method_exists($content, '__toString')) {
         $parent->appendChild($this->createTextNode("{$content}"));
     } elseif (is_object($content) and is_subclass_of($content, '\\DOMNode')) {
         $parent->appendChild($content);
     } elseif (is_array($content) or is_object($content) and $content = get_object_vars($content)) {
         array_map(function ($node, $value) use(&$parent) {
             if (is_string($node)) {
                 if (substr($node, 0, 1) === '@') {
                     $parent->setAttribute(substr($node, 1), $value);
                 } else {
                     $node = $parent->appendChild($this->createElement($node));
                     if (is_string($value)) {
                         $this->XMLAppend($node, $this->createTextNode($value));
                     } else {
                         $this->XMLAppend($node, $value);
                     }
                 }
             } else {
                 $this->XMLAppend($parent, $value);
             }
         }, array_keys($content), array_values($content));
     } elseif (is_bool($content)) {
         $parent->appendChild($this->createTextNode($content ? 'true' : 'false'));
     } else {
         throw new \InvalidArgumentException(sprintf('Unable to append unknown content [%s] to %s', get_class($content), get_class($this)));
     }
     return $this;
 }
 function test_smarty_modifier_unique()
 {
     //  配列でない場合
     $result = smarty_modifier_unique('a');
     $this->assertTrue('a', $result);
     $result = smarty_modifier_unique(NULL);
     $this->assertNULL($result);
     //  第2引数なしの場合
     $input = array(1, 2, 1, 1, 3, 2, 4);
     $result = smarty_modifier_unique($input);
     $this->assertTrue(is_numeric(array_search(1, $result)));
     $this->assertTrue(is_numeric(array_search(2, $result)));
     $this->assertTrue(is_numeric(array_search(3, $result)));
     $this->assertTrue(is_numeric(array_search(4, $result)));
     $this->assertFalse(is_numeric(array_search(5, $result)));
     //  第2引数ありの場合
     $input = array(array("foo" => 1, "bar" => 4), array("foo" => 1, "bar" => 4), array("foo" => 1, "bar" => 4), array("foo" => 2, "bar" => 5), array("foo" => 3, "bar" => 6), array("foo" => 2, "bar" => 5));
     $result = smarty_modifier_unique($input, 'bar');
     $this->assertTrue(is_numeric(array_search(4, $result)));
     $this->assertTrue(is_numeric(array_search(5, $result)));
     $this->assertTrue(is_numeric(array_search(6, $result)));
     $this->assertFalse(is_numeric(array_search(1, $result)));
     $this->assertFalse(is_numeric(array_search(2, $result)));
     $this->assertFalse(is_numeric(array_search(3, $result)));
 }
Пример #9
0
 public function validates()
 {
     if (!isset($this->property_id) || !is_numeric($this->property_id)) {
         $this->addValError('Invalid property id');
     }
     $this->doValType(Validate::TEXT, 'option_val', $this->option_val, false);
 }
Пример #10
0
 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  *
  * @param \Model $object    the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     if (!is_numeric($value)) {
         // https://github.com/yiisoft/yii/issues/1955
         // https://github.com/yiisoft/yii/issues/1669
         $message = $this->message !== null ? $this->message : '{attribute} must be a number.';
         $this->addError($object, $attribute, $message);
         return;
     }
     if ($this->integerOnly) {
         if (!preg_match($this->integerPattern, "{$value}")) {
             $message = $this->message !== null ? $this->message : '{attribute} must be an integer.';
             $this->addError($object, $attribute, $message);
         }
     } else {
         if (!preg_match($this->numberPattern, "{$value}")) {
             $message = $this->message !== null ? $this->message : '{attribute} must be a number.';
             $this->addError($object, $attribute, $message);
         }
     }
     if ($this->min !== null && $value < $this->min) {
         $message = $this->tooSmall !== null ? $this->tooSmall : '{attribute} is too small (minimum is {min}).';
         $this->addError($object, $attribute, $message, ['{min}' => $this->min]);
     }
     if ($this->max !== null && $value > $this->max) {
         $message = $this->tooBig !== null ? $this->tooBig : '{attribute} is too big (maximum is {max}).';
         $this->addError($object, $attribute, $message, ['{max}' => $this->max]);
     }
 }
Пример #11
0
 function mdl_const($str_type)
 {
     if (!fn_token("chk")) {
         //令牌
         $this->obj_ajax->halt_alert("x030102");
     }
     $_arr_opt = fn_post("opt");
     $_str_content = "<?php" . PHP_EOL;
     foreach ($_arr_opt as $_key => $_value) {
         $_arr_optChk = validateStr($_value, 1, 900);
         $_str_optValue = $_arr_optChk["str"];
         if (is_numeric($_value)) {
             $_str_content .= "define(\"" . $_key . "\", " . $_str_optValue . ");" . PHP_EOL;
         } else {
             $_str_content .= "define(\"" . $_key . "\", \"" . str_replace(PHP_EOL, "|", $_str_optValue) . "\");" . PHP_EOL;
         }
     }
     if ($str_type == "base") {
         $_str_content .= "define(\"BG_SITE_SSIN\", \"" . fn_rand(6) . "\");" . PHP_EOL;
     } else {
         if ($str_type == "visit") {
             if ($_arr_opt["BG_VISIT_TYPE"] != "static") {
                 $_str_content .= "define(\"BG_VISIT_FILE\", \"html\");" . PHP_EOL;
             }
         }
     }
     $_str_content = str_replace("||", "", $_str_content);
     $_num_size = file_put_contents(BG_PATH_CONFIG . "opt_" . $str_type . ".inc.php", $_str_content);
     if ($_num_size > 0) {
         $_str_alert = "y060101";
     } else {
         $_str_alert = "x060101";
     }
     return array("alert" => $_str_alert);
 }
Пример #12
0
function maj_vieille_base_1927_create() {
  global $tables_principales, $tables_auxiliaires, $tables_images, $tables_sequences, $tables_documents, $tables_mime;

	// ne pas revenir plusieurs fois (si, au contraire, il faut pouvoir
	// le faire car certaines mises a jour le demandent explicitement)
	# static $vu = false;
	# if ($vu) return; else $vu = true;

	foreach($tables_principales as $k => $v)
		spip_create_vieille_table($k, $v['field'], $v['key'], true);

	foreach($tables_auxiliaires as $k => $v)
		spip_create_vieille_table($k, $v['field'], $v['key'], false);

	foreach($tables_images as $k => $v)
		sql_query("INSERT IGNORE INTO spip_types_documents (extension, inclus, titre, id_type) VALUES ('$k', 'image', '" .
			      (is_numeric($v) ?
			       (strtoupper($k) . "', $v") :
			       "$v', 0") .
			      ")");

	foreach($tables_sequences as $k => $v)
		sql_query("INSERT IGNORE INTO spip_types_documents (extension, titre, inclus) VALUES ('$k', '$v', 'embed')");

	foreach($tables_documents as $k => $v)
		sql_query("INSERT IGNORE INTO spip_types_documents (extension, titre, inclus) VALUES ('$k', '$v', 'non')");

	foreach ($tables_mime as $extension => $type_mime)
	  sql_query("UPDATE spip_types_documents
		SET mime_type='$type_mime' WHERE extension='$extension'");
}
Пример #13
0
 public function test_isNumericNotValid()
 {
     $notvalid = array('-1.0.0', '1,2', '--1', '-.', '- 1', '1-');
     foreach ($notvalid as $toTest) {
         $this->assertFalse(is_numeric($toTest), $toTest . " valid but shouldn't!");
     }
 }
Пример #14
0
 /**
  * Check move quote item to wishlist request
  *
  * @param   Observer $observer
  * @return  $this
  */
 public function execute(Observer $observer)
 {
     $cart = $observer->getEvent()->getCart();
     $data = $observer->getEvent()->getInfo()->toArray();
     $productIds = [];
     $wishlist = $this->getWishlist($cart->getQuote()->getCustomerId());
     if (!$wishlist) {
         return $this;
     }
     /**
      * Collect product ids marked for move to wishlist
      */
     foreach ($data as $itemId => $itemInfo) {
         if (!empty($itemInfo['wishlist']) && ($item = $cart->getQuote()->getItemById($itemId))) {
             $productId = $item->getProductId();
             $buyRequest = $item->getBuyRequest();
             if (array_key_exists('qty', $itemInfo) && is_numeric($itemInfo['qty'])) {
                 $buyRequest->setQty($itemInfo['qty']);
             }
             $wishlist->addNewItem($productId, $buyRequest);
             $productIds[] = $productId;
             $cart->getQuote()->removeItem($itemId);
         }
     }
     if (count($productIds)) {
         $wishlist->save();
         $this->wishlistData->calculate();
     }
     return $this;
 }
Пример #15
0
 /**
  * Function for building Pledge Name combo box
  */
 function pledgeName(&$config)
 {
     $getRecords = FALSE;
     if (isset($_GET['name']) && $_GET['name']) {
         $name = CRM_Utils_Type::escape($_GET['name'], 'String');
         $name = str_replace('*', '%', $name);
         $whereClause = "p.creator_pledge_desc LIKE '%{$name}%' ";
         $getRecords = TRUE;
     }
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $pledgeId = CRM_Utils_Type::escape($_GET['id'], 'Integer');
         $whereClause = "p.id = {$pledgeId} ";
         $getRecords = TRUE;
     }
     if ($getRecords) {
         $query = "\nSELECT p.creator_pledge_desc, p.id\nFROM civicrm_pb_pledge p\nWHERE {$whereClause}\n";
         $dao = CRM_Core_DAO::executeQuery($query);
         $elements = array();
         while ($dao->fetch()) {
             $elements[] = array('name' => $dao->creator_pledge_desc, 'value' => $dao->id);
         }
     }
     if (empty($elements)) {
         $name = $_GET['name'];
         if (!$name && isset($_GET['id'])) {
             $name = $_GET['id'];
         }
         $elements[] = array('name' => trim($name, '*'), 'value' => trim($name, '*'));
     }
     echo CRM_Utils_JSON::encode($elements, 'value');
     CRM_Utils_System::civiExit();
 }
 /**
  * Constructor.
  *
  * @param array $config Socket configuration, which will be merged with the base configuration
  * @see CakeSocket::$_baseConfig
  */
 public function __construct($config = array())
 {
     $this->config = array_merge($this->_baseConfig, $config);
     if (!is_numeric($this->config['protocol'])) {
         $this->config['protocol'] = getprotobyname($this->config['protocol']);
     }
 }
Пример #17
0
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  */
 public function testBundleImport()
 {
     // import data from CSV file
     $pathToFile = __DIR__ . '/../../_files/import_bundle.csv';
     $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
     $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $pathToFile, 'directory' => $directory]);
     $errors = $this->model->setSource($source)->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'catalog_product'])->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0);
     $this->model->importData();
     $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
     $productId = $resource->getIdBySku(self::TEST_PRODUCT_NAME);
     $this->assertTrue(is_numeric($productId));
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
     $product->load($productId);
     $this->assertFalse($product->isObjectNew());
     $this->assertEquals(self::TEST_PRODUCT_NAME, $product->getName());
     $this->assertEquals(self::TEST_PRODUCT_TYPE, $product->getTypeId());
     $this->assertEquals(1, $product->getShipmentType());
     $optionIdList = $resource->getProductsIdsBySkus($this->optionSkuList);
     $bundleOptionCollection = $product->getExtensionAttributes()->getBundleProductOptions();
     $this->assertEquals(2, count($bundleOptionCollection));
     foreach ($bundleOptionCollection as $optionKey => $option) {
         $this->assertEquals('checkbox', $option->getData('type'));
         $this->assertEquals('Option ' . ($optionKey + 1), $option->getData('title'));
         $this->assertEquals(self::TEST_PRODUCT_NAME, $option->getData('sku'));
         $this->assertEquals($optionKey + 1, count($option->getData('product_links')));
         foreach ($option->getData('product_links') as $linkKey => $productLink) {
             $optionSku = 'Simple ' . ($optionKey + 1 + $linkKey);
             $this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
             $this->assertEquals($optionSku, $productLink->getData('sku'));
         }
     }
 }
Пример #18
0
/**
 * Starts the backup of a whole module instance
 *
 * @param object $bf Backup file
 * @param object $preferences Backup preferences
 * @param object $pagemenu A full pagemenu record object
 * @return boolean
 **/
function pagemenu_backup_one_mod($bf, $preferences, $pagemenu)
{
    $status = true;
    if (is_numeric($pagemenu)) {
        $pagemenu = get_record('pagemenu', 'id', $pagemenu);
    }
    // Start mod
    fwrite($bf, start_tag('MOD', 3, true));
    // Print pagemenu data
    fwrite($bf, full_tag('ID', 4, false, $pagemenu->id));
    fwrite($bf, full_tag('MODTYPE', 4, false, 'pagemenu'));
    fwrite($bf, full_tag('NAME', 4, false, $pagemenu->name));
    fwrite($bf, full_tag('DISPLAYNAME', 4, false, $pagemenu->displayname));
    fwrite($bf, full_tag('USEASTAB', 4, false, $pagemenu->useastab));
    fwrite($bf, full_tag('TABORDER', 4, false, $pagemenu->taborder));
    fwrite($bf, full_tag('TIMEMODIFIED', 4, false, $pagemenu->timemodified));
    // Backup Links
    if (!($status = backup_pagemenu_links($bf, $preferences, $pagemenu))) {
        debugging('Link Backup Failed!');
    }
    // End mod
    if ($status) {
        $status = fwrite($bf, end_tag('MOD', 3, true));
    }
    return $status;
}
Пример #19
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     $options[] = JHtml::_('select.option', 'id', JText::_('COM_VISFORMS_ID'), 'value', 'text', false);
     $options[] = JHtml::_('select.option', 'created', JText::_('COM_VISFORMS_SUBMISSIONDATE'), 'value', 'text', false);
     $options[] = JHtml::_('select.option', 'ismfd', JText::_('COM_VISFORMS_MODIFIED'), 'value', 'text', false);
     $id = 0;
     //extract form id
     $form = $this->form;
     $link = $form->getValue('link');
     if (isset($link) && $link != "") {
         $parts = array();
         parse_str($link, $parts);
         if (isset($parts['id']) && is_numeric($parts['id'])) {
             $id = $parts['id'];
         }
     }
     // Create options according to visfield settings
     $db = JFactory::getDbo();
     $query = ' SELECT c.id , c.label from #__visfields as c where c.fid=' . $id . ' AND c.published = 1 AND (c.frontdisplay is null or c.frontdisplay = 1 or c.frontdisplay = 2) ' . "and !(c.typefield = 'reset') and !(c.typefield = 'submit') and !(c.typefield = 'image') and !(c.typefield = 'fieldsep') and !(c.typefield = 'hidden')";
     $db->setQuery($query);
     $fields = $db->loadObjectList();
     if ($fields) {
         foreach ($fields as $field) {
             $tmp = JHtml::_('select.option', $field->id, $field->label, 'value', 'text', false);
             // Add the option object to the result set.
             $options[] = $tmp;
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Пример #20
0
 /**
  * Constructor.
  *
  * @param string|number $value value to store in this numericNode
  * @throws \TYPO3\CMS\Fluid\Core\Parser\Exception
  */
 public function __construct($value)
 {
     if (!is_numeric($value)) {
         throw new \TYPO3\CMS\Fluid\Core\Parser\Exception('Numeric node requires an argument of type number, "' . gettype($value) . '" given.', 1360414192);
     }
     $this->value = $value + 0;
 }
Пример #21
0
 /**
  * 文件上传
  * @param  array  $files   要上传的文件列表(通常是$_FILES数组)
  * @param  array  $setting 文件上传配置
  * @param  string $driver  上传驱动名称
  * @param  array  $config  上传驱动配置
  * @return array           文件上传成功后的信息
  */
 public function upload($files, $setting, $driver = 'Local', $config = null)
 {
     /* 上传文件 */
     $setting['callback'] = array($this, 'isFile');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     /* 设置文件保存位置 */
     $this->_auto[] = array('location', 'ftp' === strtolower($driver) ? 1 : 0, self::MODEL_INSERT);
     if ($info) {
         //文件上传成功,记录文件信息
         foreach ($info as $key => &$value) {
             /* 已经存在文件记录 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
                 //在模板里的url路径
                 continue;
             }
             $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
             //在模板里的url路径
             /* 记录文件信息 */
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             } else {
                 //TODO: 文件上传成功,但是记录文件信息失败,需记录日志
                 unset($info[$key]);
             }
         }
         return $info;
         //文件上传成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
 public static function partitionTwo(DataSet $wholeSet, $partitionRelation, $seed = null)
 {
     if (!is_numeric($partitionRelation) || $partitionRelation <= 0 || $partitionRelation >= 1) {
         throw new InvalidArgumentException();
     }
     // mt_srand(null) === mt_srand(0)
     if ($seed !== null) {
         mt_srand($seed);
     }
     $numElements = count($wholeSet->getData());
     $indexes = range(0, $numElements - 1);
     self::shuffle($indexes);
     $trainingSet = [];
     $trainingSetLabels = [];
     $testSet = [];
     $testSetLabels = [];
     $data = $wholeSet->getData();
     $labels = $wholeSet->getLabels();
     for ($i = 0; $i < $numElements; $i++) {
         $index = $indexes[$i];
         if ($i < $partitionRelation * $numElements) {
             $trainingSet[] = $data[$index];
             $trainingSetLabels[] = $labels[$index];
         } else {
             $testSet[] = $data[$index];
             $testSetLabels[] = $labels[$index];
         }
     }
     $trainingDataSet = new DataSet($trainingSet, $trainingSetLabels);
     $testDataSet = new DataSet($testSet, $testSetLabels);
     return new Partition($trainingDataSet, $testDataSet);
 }
 /**
  * @access public
  */
 function &getCategoryById($id)
 {
     $id = (int) $id;
     if (!is_numeric($id)) {
         return null;
     }
     $query = 'SELECT * FROM ' . OOMediaCategory::_getTableName() . ' WHERE id = ' . $id;
     $sql = new rex_sql();
     //        $sql->debugsql = true;
     $result = $sql->getArray($query);
     if (count($result) == 0) {
         // Zuerst einer Variable zuweisen, da RETURN BY REFERENCE
         $return = null;
         return $return;
     }
     $result = $result[0];
     $cat =& new OOMediaCategory();
     $cat->_id = $result['id'];
     $cat->_parent_id = $result['re_id'];
     $cat->_name = $result['name'];
     $cat->_path = $result['path'];
     $cat->_createdate = $result['createdate'];
     $cat->_updatedate = $result['updatedate'];
     $cat->_createuser = $result['createuser'];
     $cat->_updateuser = $result['updateuser'];
     $cat->_children = null;
     $cat->_files = null;
     return $cat;
 }
 function Inicializar()
 {
     $retorno = "Novo";
     @session_start();
     $this->pessoa_logada = $_SESSION['id_pessoa'];
     @session_write_close();
     $this->cod_software = $_GET["cod_software"];
     if (is_numeric($this->cod_software)) {
         $obj = new clsPmicontrolesisSoftware($this->cod_software);
         $registro = $obj->detalhe();
         if ($registro) {
             foreach ($registro as $campo => $val) {
                 // passa todos os valores obtidos no registro para atributos do objeto
                 $this->{$campo} = $val;
             }
             $this->data_cadastro = dataFromPgToBr($this->data_cadastro);
             $this->data_exclusao = dataFromPgToBr($this->data_exclusao);
             $this->fexcluir = true;
             $retorno = "Editar";
         }
     }
     $this->url_cancelar = $retorno == "Editar" ? "controlesis_software_det.php?cod_software={$registro["cod_software"]}" : "controlesis_software_lst.php";
     $this->nome_url_cancelar = "Cancelar";
     return $retorno;
 }
Пример #25
0
 /**
  * @param string $channel
  *
  * @return Event
  */
 public function setChannel($channel)
 {
     if ((is_string($channel) || is_numeric($channel)) && !empty($channel)) {
         $this->addMetaData('channel', $channel);
     }
     return $this;
 }
Пример #26
0
 /**
  * @param mixed            $value
  * @param AbstractPlatform $platform
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (empty($value)) {
         return '';
     }
     if ($value instanceof \stdClass) {
         $value = get_object_vars($value);
     }
     if (!is_array($value)) {
         throw new \InvalidArgumentException("Hstore value must be off array or \\stdClass.");
     }
     $hstoreString = '';
     foreach ($value as $k => $v) {
         if (!is_string($v) && !is_numeric($v) && !is_bool($v)) {
             throw new \InvalidArgumentException("Cannot save 'nested arrays' into hstore.");
         }
         $v = trim($v);
         if (!is_numeric($v) && false !== strpos($v, ' ')) {
             $v = sprintf('"%s"', $v);
         }
         $hstoreString .= "{$k} => {$v}," . "\n";
     }
     $hstoreString = substr(trim($hstoreString), 0, -1) . "\n";
     return $hstoreString;
 }
Пример #27
0
 /**
  * Constructor.
  *
  * @param   ObjectConfig $config Configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     //Set the object manager
     if (isset($config->object_manager)) {
         $this->__object_manager = $config->object_manager;
     }
     //Set the object identifier
     if (isset($config->object_identifier)) {
         $this->__object_identifier = $config->object_identifier;
     }
     //Initialise the object
     $this->_initialize($config);
     //Add the mixins
     $mixins = (array) ObjectConfig::unbox($config->mixins);
     foreach ($mixins as $key => $value) {
         if (is_numeric($key)) {
             $this->mixin($value);
         } else {
             $this->mixin($key, $value);
         }
     }
     //Register the decorators
     $decorators = (array) ObjectConfig::unbox($config->decorators);
     foreach ($decorators as $key => $value) {
         if (is_numeric($key)) {
             $this->getIdentifier()->getDecorators()->append(array($value));
         } else {
             $this->getIdentifier()->getDecorators()->append(array($key, $value));
         }
     }
     //Set the object config
     $this->__object_config = $config;
 }
Пример #28
0
 public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
 {
     $params = $compiler->getCompiledParams($params);
     $parsedParams = array();
     if (!isset($params['*'])) {
         $params['*'] = array();
     }
     foreach ($params['*'] as $param => $defValue) {
         if (is_numeric($param)) {
             $param = $defValue;
             $defValue = null;
         }
         $param = trim($param, '\'"');
         if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
             throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
         }
         $parsedParams[$param] = $defValue;
     }
     $params['name'] = substr($params['name'], 1, -1);
     $params['*'] = $parsedParams;
     $params['uuid'] = uniqid();
     $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
     $currentBlock =& $compiler->getCurrentBlock();
     $currentBlock['params'] = $params;
     return '';
 }
Пример #29
0
function valida_valor($valor, $aceita_float)
{
    // valida valor
    if ($valor == null) {
        // informa que nao e um valor
        return false;
    }
    // remove a virgula se houver
    $valor = str_replace(",", ".", $valor);
    // remove espaco vazio no meio se houver
    $valor = str_replace(" ", null, $valor);
    // remove o espaco em branco
    $valor = trim($valor);
    // valida se e numero, e se e numero positivo
    if (is_numeric($valor) == false or $valor < 0) {
        // informa que nao e um numero
        return false;
    }
    // arredonda valor se nao aceitar float
    if ($aceita_float == false) {
        // arredonda
        $valor = round($valor, 0);
    }
    // se aceitar float, e for float entao arredonda
    if ($aceita_float == true) {
        // arredonda
        $valor = round($valor, 2);
    }
    // retorno
    return $valor;
}
Пример #30
0
/**
 * Implemensts hook_breadcrumb().
 *
 * tth@bellcom.dk check if there is a better way to do this...
 */
function cmstheme_breadcrumb($variables)
{
    $breadcrumb = $variables['breadcrumb'];
    $nid = arg(1);
    if (is_numeric($nid)) {
        $node = node_load($nid);
    }
    if (!empty($breadcrumb)) {
        $output = '<div class="breadcrumb you-are-here">' . t('Du er her: ') . '</div>';
        $title = drupal_get_title();
        $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside')));
        $breadcrumb[] = '<a href="#" title="' . $title . '">' . $title . '</a>';
        if ($title == 'Søg') {
            unset($breadcrumb);
            $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside')));
            $breadcrumb[] = '<a href="#" title="Søgning">Søgning</a>';
        }
        if (isset($node) && is_object($node) && $node->type == 'meeting') {
            unset($breadcrumb);
            $breadcrumb[0] = l(t('Forside'), '<front>', array('attributes' => array('title' => 'Forside')));
            $breadcrumb[] = l(t('Politik & planer'), 'politik-og-planer', array('attributes' => array('title' => 'Politik og planer')));
            $breadcrumb[] = l(t('Søg i dagsordener og referater'), 'dagsorden-og-referat', array('attributes' => array('title' => 'Søg i dagsordner og referater')));
            $breadcrumb[] = l(t($title), '#');
        }
        $output .= '<div class="breadcrumb">' . implode('<div class="bread-crumb"> &gt; </div> ', $breadcrumb) . '</div>';
        return $output;
    }
}