public static function getChecksum($class, $id, $type, $encodedFilename) { if (substr($type, 0, strlen(Kwf_Media::DONT_HASH_TYPE_PREFIX)) == Kwf_Media::DONT_HASH_TYPE_PREFIX) { $type = Kwf_Media::DONT_HASH_TYPE_PREFIX; } return substr(Kwf_Util_Hash::hash($class . $id . $type . rawurldecode($encodedFilename)), 0, 8); }
public function generateAutoLoginToken(Kwf_Model_Row_Interface $row) { $token = Kwf_Util_Hash::hash(microtime(true) . uniqid('', true) . mt_rand()); $expire = time() + 100 * 24 * 60 * 60; $row->autologin = $expire . ':' . $this->_encodeToken($row, $token); $row->save(); return $token; }
public function generateActivationToken(Kwf_Model_Row_Interface $row, $type) { $token = substr(Kwf_Util_Hash::hash(microtime(true) . uniqid('', true) . mt_rand()), 0, 10); $days = $type == self::TYPE_ACTIVATE ? 7 : 1; $expire = time() + $days * 24 * 60 * 60; $row->activate_token = $expire . ':' . $this->_encodePasswordBcrypt($row, $token); $row->save(); return $token; }
public function load($row) { $model = Kwc_Abstract::createOwnModel($this->_class); $componentId = $row->component_id . '-' . $row->id; if ($this->_subComponent) { $componentId .= $this->_subComponent; } $row = $model->getRow($componentId); if ($row && $row->kwf_upload_id) { $hashKey = Kwf_Util_Hash::hash($row->kwf_upload_id); return Kwf_Setup::getBaseUrl() . '/kwf/media/upload/preview?uploadId=' . $row->kwf_upload_id . '&hashKey=' . $hashKey . '&size=' . $this->_size; } else { return ''; } }
public function build(ContainerBuilder $container) { parent::build($container); $container->setParameter('kernel.secret', \Kwf_Util_Hash::getPrivatePart()); $container->setParameter('kernel.framework.session.storage_id', 'session.storage.kwf'); $container->setParameter('framework.session.storage_id', 'session.storage.kwf'); $container->setParameter('session.storage_id', 'session.storage.kwf'); $container->setParameter('session', null); $container->setParameter('kernel.session', null); $container->set('kernel.framework.session.storage_id', 'session.storage.kwf'); $container->set('framework.session.storage_id', 'session.storage.kwf'); $container->set('session.storage_id', 'session.storage.kwf'); $container->setParameter('kernel.framework.session.storage', 'session.storage.kwf'); $container->setParameter('framework.session.storage', 'session.storage.kwf'); $container->setParameter('session.storage', 'session.storage.kwf'); $container->set('kernel.framework.session.storage', 'session.storage.kwf'); $container->set('framework.session.storage', 'session.storage.kwf'); $container->set('session.storage', 'session.storage.kwf'); }
public static function decodeCallback($c) { if ($c && substr($c, 0, 4) == 'kwf:') { $c = substr($c, 4); $hash = substr($c, 0, 10); $c = substr($c, 10); $c = base64_decode($c); if (!$c) { throw new Kwf_Exception("Invalid kwfProcessIpnEntry: can't base64_decode"); } if (substr(Kwf_Util_Hash::hash($c), 0, 10) != $hash) { throw new Kwf_Exception("Invalid kwfProcessIpnEntry: hash not correct"); } $c = @unserialize($c); if (!$c) { throw new Kwf_Exception("Invalid kwfProcessIpnEntry: can't unserialize"); } return $c; } return false; }
public function getTemplateVars() { $ret = Kwc_Abstract::getTemplateVars(); $this->_checkWasProcessed(); $ret['isPosted'] = $this->_posted; $ret['showSuccess'] = false; $ret['errors'] = Kwf_Form::formatValidationErrors($this->getErrors()); if ($this->isSaved()) { if (!$ret['errors'] && $this->getSuccessComponent()) { $ret['showSuccess'] = true; } } if ($ret['showSuccess']) { $ret['success'] = $this->getSuccessComponent(); } else { foreach ($this->getData()->getChildComponents(array('generator' => 'child')) as $c) { if ($c->id != 'success') { $ret[$c->id] = $c; } } } if (!$ret['showSuccess']) { $values = $this->getForm()->load(null, $this->_postData); $ret['form'] = $this->getForm()->getTemplateVars($values, '', $this->getData()->componentId . '_'); $dec = $this->_getSetting('decorator'); if ($dec && is_string($dec)) { $dec = new $dec(); $ret['form'] = $dec->processItem($ret['form'], $this->getErrors()); } $ret['formName'] = $this->getData()->componentId; $ret['buttonClass'] = $this->_getSetting('buttonClass'); $ret['formId'] = $this->getForm()->getId(); if ($ret['formId']) { $ret['formIdHash'] = Kwf_Util_Hash::hash($ret['formId']); } $page = $this->getData()->getPage(); if (!$page) { throw new Kwf_Exception('Form must have an url so it must be on a page but is on "' . $this->getData()->componentId . '". (If component is a box it must not be unique)'); } $cachedContent = Kwf_Component_Cache::getInstance()->load($page->componentId, 'componentLink'); if ($cachedContent) { $targetPage = unserialize($cachedContent); $ret['action'] = $targetPage[0]; } else { $ret['action'] = $this->getData()->url; } if (isset($_SERVER["QUERY_STRING"])) { $ret['action'] .= '?' . $_SERVER["QUERY_STRING"]; } $ret['method'] = $this->_getSetting('method'); } $ret['isUpload'] = false; foreach (new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->getForm()->fields)) as $f) { if ($f instanceof Kwf_Form_Field_File) { $ret['isUpload'] = true; break; } } $ret['message'] = null; $cacheId = 'kwcFormCu-' . get_class($this); $controllerUrl = Kwf_Cache_SimpleStatic::fetch($cacheId); if (!$controllerUrl) { $controllerUrl = Kwc_Admin::getInstance(get_class($this))->getControllerUrl('FrontendForm'); Kwf_Cache_SimpleStatic::add($cacheId, $controllerUrl); } $hideForValue = array(); foreach ($this->_form->getHideForValue() as $v) { $hideForValue[] = array('field' => $v['field']->getFieldName(), 'value' => $v['value'], 'hide' => $v['hide']->getFieldName()); } $baseParams = $this->_getBaseParams(); $baseParams['componentId'] = $this->getData()->componentId; $fieldConfig = array(); $iterator = new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->_form->fields), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $field) { if ($field->getFieldName()) { $fieldConfig[$field->getFieldName()] = (object) $field->getFrontendMetaData(); } } $errorStyle = $this->_getSetting('errorStyle'); if (!$errorStyle) { $errorStyle = Kwf_Config::getValue('kwc.form.errorStyle'); } $ret['config'] = array('controllerUrl' => $controllerUrl, 'useAjaxRequest' => $this->_getSetting('useAjaxRequest'), 'hideFormOnSuccess' => $this->_getSetting('hideFormOnSuccess'), 'componentId' => $this->getData()->componentId, 'hideForValue' => $hideForValue, 'fieldConfig' => (object) $fieldConfig, 'errorStyle' => $errorStyle, 'baseParams' => $baseParams); $ret['uniquePrefix'] = Kwf_Config::getValue('application.uniquePrefix'); if ($ret['uniquePrefix']) { $ret['uniquePrefix'] .= '-'; } return $ret; }
public function getHashKey() { return Kwf_Util_Hash::hash($this->id); }
private function _getHash(array $hashData) { $hashData = implode('', $hashData); return substr(Kwf_Util_Hash::hash($hashData), 0, 6); }
protected function _createItemByRow($row) { $truncateHelper = new Kwf_View_Helper_Truncate(); $primaryKey = $this->_primaryKey; $r = array(); if (!isset($r[$primaryKey]) && isset($row->{$primaryKey})) { $r[$primaryKey] = $row->{$primaryKey}; } if (!$this->_labelField && $row instanceof Kwf_Model_Row_Interface) { $r['label'] = $row->__toString(); } else { if ($this->_labelField) { $r['label'] = $row->{$this->_labelField}; } else { throw new Kwf_Exception("You have to set _labelField in the ImageGrid Controller"); } } if (!empty($r['label'])) { $r['label_short'] = $r['label']; } if (!empty($r['label_short']) && $this->_maxLabelLength) { $r['label_short'] = $truncateHelper->truncate($r['label_short'], $this->_maxLabelLength, '…', true, false); } $imageRef = $this->_getImageReference(); $hashKey = Kwf_Util_Hash::hash($row->{$imageRef['column']}); $r['src'] = '/kwf/media/upload/preview?uploadId=' . $row->{$imageRef['column']} . '&hashKey=' . $hashKey . '&size=imageGrid'; $r['src_large'] = '/kwf/media/upload/preview?uploadId=' . $row->{$imageRef['column']} . '&hashKey=' . $hashKey . '&size=imageGridLarge'; if ($uploadRow = $row->getParentRow($this->_imageRule)) { $dim = Kwf_Media_Image::calculateScaleDimensions($uploadRow->getFileSource(), array(400, 400, 'cover' => false)); $r['src_large_width'] = $dim['width']; $r['src_large_height'] = $dim['height']; } foreach ($this->_additionalDataFields as $f) { $r[$f] = $row->{$f}; } return $r; }