/** * Get the init field values * * @return array */ protected function getInitFields() { $check = Version::check(Version::DATA); foreach ($check as $key => $value) { if (strpos($key, 'db') !== false) { if ($value == 'Yes' && stripos($key, 'sqlsrv') === false && stripos($key, 'oracle') === false) { $db = str_replace('db', '', $key); if (strpos($db, 'Pdo') !== false && $db != 'Pdo') { $db = 'Pdo\\' . ucfirst(strtolower(str_replace('Pdo', '', $db))); $this->dbAdapters[$db] = $db; } else { if ($db != 'Pdo') { $db = ucfirst(strtolower($db)); if ($db != 'Mysql') { $this->dbAdapters[$db] = $db; } } } } } } $langs = I18n::getLanguages(__DIR__ . '/../../../data/assets/i18n'); foreach ($langs as $key => $value) { $langs[$key] = substr($value, 0, strpos($value, ' (')); } $fields = array('language' => array('type' => 'select', 'label' => $this->i18n->__('Language'), 'value' => $langs, 'marked' => POP_LANG, 'attributes' => array('onchange' => "changeLanguage(this);", 'style' => 'width: 260px;')), 'db_adapter' => array('type' => 'select', 'label' => $this->i18n->__('DB Adapter'), 'required' => true, 'value' => $this->dbAdapters, 'attributes' => array('style' => 'width: 260px;')), 'db_name' => array('type' => 'text', 'label' => $this->i18n->__('DB Name'), 'attributes' => array('size' => 30)), 'db_username' => array('type' => 'text', 'label' => $this->i18n->__('DB Username'), 'attributes' => array('size' => 30)), 'db_password' => array('type' => 'text', 'label' => $this->i18n->__('DB Password'), 'attributes' => array('size' => 30)), 'db_host' => array('type' => 'text', 'label' => $this->i18n->__('DB Host'), 'attributes' => array('size' => 30), 'value' => 'localhost'), 'db_prefix' => array('type' => 'text', 'name' => 'db_prefix', 'label' => $this->i18n->__('DB Table Prefix'), 'attributes' => array('size' => 30), 'value' => 'ph_'), 'app_uri' => array('type' => 'text', 'label' => $this->i18n->__('Application URI') . '<br /><em style="font-size: 0.9em; color: #666; font-weight: normal;">(' . $this->i18n->__('How you will access the system') . ')</em>', 'attributes' => array('size' => 30), 'value' => APP_URI), 'content_path' => array('type' => 'text', 'label' => $this->i18n->__('Content Path') . '<br /><em style="font-size: 0.9em; color: #666; font-weight: normal;">(' . $this->i18n->__('Where assets will be located') . ')</em>', 'required' => true, 'attributes' => array('size' => 30), 'value' => CONTENT_PATH), 'password_encryption' => array('type' => 'hidden', 'value' => 4), 'submit' => array('type' => 'submit', 'label' => ' ', 'value' => $this->i18n->__('NEXT'), 'attributes' => array('class' => 'install-btn'))); return $fields; }
/** * Error method * * @return void */ public function error() { $install = new Model\Install(array('title' => $this->i18n->__('404 Error') . ' > ' . $this->i18n->__('Page Not Found'))); $this->view = View::factory($this->viewPath . '/error.phtml', $install->getData()); $this->view->set('i18n', $this->i18n); $this->send(404); }
/** * Method to evaluate the validator * * @param mixed $input * @throws Exception * @return boolean */ public function evaluate($input = null) { // Check to make sure the input is a valid Ipv4 address. $ip = new Ipv4(); if (!Ipv4::factory()->evaluate($input)) { throw new Exception('The IP address must be a valid IPv4 address.'); } // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be part of the subnet %1.', $this->value); } else { $this->defaultMessage = I18n::factory()->__('The value must not be part of the subnet %1.', $this->value); } } // Evaluate the input against the validator if ((substr($this->input, 0, strrpos($this->input, '.')) == $this->value) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; if (strpos($this->input, ' ') !== false) { $this->input = str_replace(' ', '', $this->input); } if (strpos($this->input, '-') !== false) { $this->input = str_replace('-', '', $this->input); } } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be a valid credit card number.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be a valid credit card number.'); } } // Evaluate the input against the validator $nums = str_split($this->input); $check = $nums[count($nums) - 1]; $start = count($nums) - 2; $sum = 0; $double = true; for ($i = $start; $i >= 0; $i--) { if ($double) { $num = $nums[$i] * 2; if ($num > 9) { $num = substr($num, 0, 1) + substr($num, 1, 1); } $sum += $num; $double = false; } else { $sum += $nums[$i]; $double = true; } } $sum += $check; $rem = $sum % 10; if (($rem == 0) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Install index controller and web config files prompt * * @return string */ public static function installWeb() { $msg = \Pop\I18n\I18n::factory()->__('Install index controller and web configuration files?') . ' ([A]pache/[I]IS/[O]ther/[N]o) '; echo $msg; $input = null; while ($input != 'a' && $input != 'i' && $input != 'o' && $input != 'n') { if (null !== $input) { echo $msg; } $prompt = fopen("php://stdin", "r"); $input = fgets($prompt, 32); $input = substr(strtolower(rtrim($input)), 0, 1); fclose($prompt); } return $input; }
/** * Install the model class files * * @param \Pop\Config $install * @return void */ public static function install($install) { echo \Pop\I18n\I18n::factory()->__('Creating model class files...') . PHP_EOL; // Create model class folder $modelDir = $install->project->base . '/module/' . $install->project->name . '/src/' . $install->project->name . '/Model'; if (!file_exists($modelDir)) { mkdir($modelDir); } $models = $install->models->asArray(); foreach ($models as $model) { $modelName = ucfirst(\Pop\Filter\String::underscoreToCamelcase($model)); // Define namespace $ns = new NamespaceGenerator($install->project->name . '\\Model'); // Create and save model class file $modelCls = new Generator($modelDir . '/' . $modelName . '.php', Generator::CREATE_CLASS); $modelCls->setNamespace($ns); $modelCls->save(); } }
/** * Install the controller class files * * @param \Pop\Config $install * @param string $installDir * @return void */ public static function install($install, $installDir) { echo \Pop\I18n\I18n::factory()->__('Creating controller class files...') . PHP_EOL; // Make the controller folder $module = substr($install->project->base, -1) == '/' ? 'module/' : '/module/'; $ctrlDir = $install->project->base . $module . $install->project->name . '/src/' . $install->project->name . '/Controller'; $viewDir = $install->project->base . $module . $install->project->name . '/view'; if (!file_exists($ctrlDir)) { mkdir($ctrlDir); } if (!file_exists($viewDir)) { mkdir($viewDir); } // Create the controller class files if (isset($install->controllers)) { $controllers = $install->controllers->asArray(); self::createControllers($controllers, array('src' => realpath($ctrlDir), 'view' => realpath($viewDir), 'namespace' => $install->project->name . '\\Controller', 'installDir' => $installDir)); } }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value format is not correct.'); } else { $this->defaultMessage = I18n::factory()->__('The value format is not correct.'); } } // Evaluate the input against the validator if (preg_match($this->value, $this->input) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be a valid email format.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be a valid email format.'); } } // Evaluate the input against the validator if (preg_match('/[a-zA-Z0-9\\.\\-\\_+%]+@[a-zA-Z0-9\\-\\_\\.]+\\.[a-zA-Z]{2,4}/', $this->input) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be included.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be included.'); } } // If input check is an array if (is_array($this->input)) { if (!is_array($this->value)) { $this->value = array($this->value); } $this->result = true; foreach ($this->value as $value) { if (in_array($value, $this->input) != $this->condition) { $this->result = false; } } // Else, if input check is a string } else { if (is_array($this->value)) { $this->result = in_array($this->input, $this->value) != $this->condition ? false : true; } else { if ((strpos((string) $this->input, (string) $this->value) !== false) == $this->condition) { $this->result = true; } else { $this->result = false; } } } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must only contain characters of the alphabet.'); } else { $this->defaultMessage = I18n::factory()->__('The value must contain characters not in the alphabet.'); } } // Evaluate the input against the validator if (preg_match('/^[a-zA-Z]+$/', $this->input) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be a valid IPv4 subnet.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be a valid IPv4 subnet.'); } } // Evaluate the input against the validator if (preg_match('/^\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]|[0-9])\\b$/', $this->input) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be numeric.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be numeric.'); } } // Evaluate the input against the validator if ((is_numeric($this->input) == $this->value) != $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be greater than or equal to %1.', $this->value); } else { $this->defaultMessage = I18n::factory()->__('The value must not be greater than or equal to %1.', $this->value); } } // Evaluate the input against the validator if ($this->input >= $this->value == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value must be a valid IPv6 address.'); } else { $this->defaultMessage = I18n::factory()->__('The value must not be a valid IPv6 address.'); } } // Evaluate the input against the validator if (preg_match('/^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$/', $this->input) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Method to evaluate the validator * * @param mixed $input * @return boolean */ public function evaluate($input = null) { // Set the input, if passed if (null !== $input) { $this->input = $input; } $nums = explode('|', $this->value); // Set the default message if (null === $this->defaultMessage) { if ($this->condition) { $this->defaultMessage = I18n::factory()->__('The value length must be between or equal to %1 and %2.', $nums); } else { $this->defaultMessage = I18n::factory()->__('The value length must not be between or equal to %1 and %2.', $nums); } } // Evaluate the input against the validator if ((strlen($this->input) >= $nums[0] && strlen($this->input) <= $nums[1]) == $this->condition) { $this->result = true; } else { $this->result = false; } return $this->result; }
/** * Install the table class files * * @param \Pop\Config $install * @param array $dbTables * @return void */ public static function install($install, $dbTables) { echo \Pop\I18n\I18n::factory()->__('Creating database table class files...') . PHP_EOL; // Create table class folder $tableDir = $install->project->base . '/module/' . $install->project->name . '/src/' . $install->project->name . '/Table'; if (!file_exists($tableDir)) { mkdir($tableDir); } // Loop through the tables, creating the classes foreach ($dbTables as $table => $value) { $prefix = isset($value['prefix']) ? $value['prefix'] : null; $tableName = ucfirst(\Pop\Filter\String::underscoreToCamelcase(str_replace($prefix, '', $table))); $ns = new NamespaceGenerator($install->project->name . '\\Table'); $ns->setUse('Pop\\Db\\Record'); if (strpos($value['primaryId'], '|') !== false) { $pIdType = 'array'; $pId = explode('|', $value['primaryId']); } else { $pIdType = 'string'; $pId = $value['primaryId']; } if (null !== $prefix) { $prefix = new PropertyGenerator('prefix', 'string', $prefix, 'protected'); } $propId = new PropertyGenerator('primaryId', $pIdType, $pId, 'protected'); $propAuto = new PropertyGenerator('auto', 'boolean', $value['auto'], 'protected'); // Create and save table class file $tableCls = new Generator($tableDir . '/' . $tableName . '.php', Generator::CREATE_CLASS); $tableCls->setNamespace($ns); $tableCls->code()->setParent('Record')->addProperty($propId)->addProperty($propAuto); if (null !== $prefix) { $tableCls->code()->addProperty($prefix); } $tableCls->save(); } }
/** * Method to set the validator * * @throws \Pop\Form\Exception * @return void */ protected function setValidator() { // Get query data if ($_SERVER['REQUEST_METHOD']) { $queryData = array(); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': $queryData = $_GET; break; case 'POST': $queryData = $_POST; break; default: $input = fopen('php://input', 'r'); $qData = null; while ($data = fread($input, 1024)) { $qData .= $data; } parse_str($qData, $queryData); } // If there is query data, set validator to check against the token value if (count($queryData) > 0) { if (isset($queryData[$this->name])) { $captcha = $this->token['captcha']; if (stripos($captcha, '<img') !== false) { $answer = $this->token['value']; } else { if (strpos($captcha, '<img') === false && (strpos($captcha, ' + ') !== false || strpos($captcha, ' - ') !== false || strpos($captcha, ' * ') !== false || strpos($captcha, ' / ') !== false)) { $answer = eval("return ({$captcha});"); } else { $answer = $captcha; } } $this->addValidator(new \Pop\Validator\Equal($answer, \Pop\I18n\I18n::factory()->__('The answer is incorrect.'))); } } } else { throw new \Pop\Form\Exception('Error: The server request method is not set.'); } }
/** * Return the two-letter language code from STDIN * * @param array $langs * @return string */ public static function getLanguage($langs) { $msg = I18n::factory()->__('Enter the numeric code for the default language: '); echo $msg; $lang = null; $keys = array_keys($langs); while (!array_key_exists($lang, $keys)) { if (null !== $lang) { echo $msg; } $prompt = fopen("php://stdin", "r"); $lang = fgets($prompt, 5); $lang = rtrim($lang); fclose($prompt); } return $lang; }
/** * Method to calculate the elapsed time between the date passed and now. * * @param string $time * @return string */ public static function calculateTime($time) { // Calculate the difference. $timeDiff = time() - strtotime($time); $timePhrase = null; // If less than an hour. if ($timeDiff < 3600) { $elapsedTime = round($timeDiff / 60); if ($elapsedTime <= 0) { $timePhrase = I18n::factory()->__('A few seconds ago'); } else { if ($elapsedTime == 1) { $timePhrase = I18n::factory()->__('1 minute ago'); } else { $timePhrase = I18n::factory()->__('%1 minutes ago', $elapsedTime); } } // If less than a day. } else { if ($timeDiff >= 3600 && $timeDiff < 86400) { $elapsedTime = round($timeDiff / 60 / 60); $timePhrase = $elapsedTime == 1 ? I18n::factory()->__('1 hour ago') : I18n::factory()->__('%1 hours ago', $elapsedTime); // If less than a month. } else { if ($timeDiff >= 86400 && $timeDiff < 2592000) { $elapsedTime = round($timeDiff / 60 / 60 / 24); $timePhrase = $elapsedTime == 1 ? I18n::factory()->__('1 day ago') : I18n::factory()->__('%1 days ago', $elapsedTime); // If more than a month, less than 2 years } else { if ($timeDiff >= 2592000 && $timeDiff < 63072000) { $elapsedTime = round($timeDiff / 60 / 60 / 24 / 30); $timePhrase = $elapsedTime == 1 ? I18n::factory()->__('1 month ago') : I18n::factory()->__('%1 months ago', $elapsedTime); // If more than 2 years ago } else { $elapsedTime = round($timeDiff / 60 / 60 / 24 / 30 / 12); $timePhrase = I18n::factory()->__('%1 years ago', $elapsedTime); } } } } // Return the calculated elapsed time. return $timePhrase; }
/** * Return the input from STDIN * * @param string $msg * @return string */ protected static function cliInput($msg = null) { echo null === $msg ? \Pop\I18n\I18n::factory()->__('Continue?') . ' (Y/N) ' : $msg; $input = null; while (null === $input) { $prompt = fopen("php://stdin", "r"); $input = fgets($prompt); $input = rtrim($input); fclose($prompt); } return $input; }
/** * Install the form class files * * @param \Pop\Config $install * @return void */ public static function install($install) { echo \Pop\I18n\I18n::factory()->__('Creating form class files...') . PHP_EOL; // Create form class folder $formDir = $install->project->base . '/module/' . $install->project->name . '/src/' . $install->project->name . '/Form'; if (!file_exists($formDir)) { mkdir($formDir); } $forms = $install->forms->asArray(); foreach ($forms as $name => $form) { $formName = ucfirst(\Pop\Filter\String::underscoreToCamelcase($name)); // Define namespace $ns = new NamespaceGenerator($install->project->name . '\\Form'); $ns->setUse('Pop\\Form\\Form')->setUse('Pop\\Form\\Element')->setUse('Pop\\Validator'); // Create the constructor $construct = new MethodGenerator('__construct'); $construct->setDesc('Constructor method to instantiate the form object'); $construct->getDocblock()->setReturn('self'); $construct->addArguments(array(array('name' => 'action', 'value' => 'null', 'type' => 'string'), array('name' => 'method', 'value' => "'post'", 'type' => 'string'), array('name' => 'fields', 'value' => 'null', 'type' => 'array'), array('name' => 'indent', 'value' => 'null', 'type' => 'string'))); // Create the init values array within the constructor if (is_array($form) && count($form) > 0) { $construct->appendToBody("\$this->initFieldsValues = array ("); $i = 0; foreach ($form as $name => $field) { $i++; $construct->appendToBody(" '" . $name . "' => array ("); $j = 0; foreach ($field as $key => $value) { $j++; $comma = $j < count($field) ? ',' : null; if ($key == 'validators') { $val = null; if (is_array($value)) { $val = 'array(' . PHP_EOL; foreach ($value as $v) { $val .= ' new Validator\\' . $v . ',' . PHP_EOL; } $val .= ' )'; } else { $val = 'new Validator\\' . $value; } $construct->appendToBody(" '{$key}' => {$val}{$comma}"); } else { if ($key == 'value' || $key == 'marked' || $key == 'attributes' || $key == 'error') { $val = var_export($value, true); $val = str_replace(PHP_EOL, PHP_EOL . ' ', $val); if (strpos($val, 'Select::') !== false) { $val = 'Element\\' . str_replace("'", '', $val); } $construct->appendToBody(" '{$key}' => {$val}{$comma}"); } else { if (is_bool($value)) { $val = $value ? 'true' : 'false'; } else { $val = "'" . $value . "'"; } $construct->appendToBody(" '{$key}' => {$val}{$comma}"); } } } $end = $i < count($form) ? ' ),' : ' )'; $construct->appendToBody($end); } $construct->appendToBody(");"); } $construct->appendToBody("parent::__construct(\$action, \$method, \$fields, \$indent);"); // Create and save form class file $formCls = new Generator($formDir . '/' . $formName . '.php', Generator::CREATE_CLASS); $formCls->setNamespace($ns); $formCls->code()->setParent('Form')->addMethod($construct); $formCls->save(); } }
/** * Validate the form element object. * * @return boolean */ public function validate() { $this->errors = array(); // Check if the element is required. if ($this->required == true) { if (is_array($this->value)) { $curElemValue = $this->marked; } else { if ($_FILES && isset($_FILES[$this->name]['name'])) { $curElemValue = $_FILES[$this->name]['name']; } else { $curElemValue = $this->value; } } if (empty($curElemValue) && $curElemValue != '0') { $this->errors[] = \Pop\I18n\I18n::factory()->__('This field is required.'); } } // Check the element's validators. if (isset($this->validators[0])) { foreach ($this->validators as $validator) { $curElemSize = null; if (is_array($this->value)) { $curElemValue = $this->marked; } else { if ($_FILES && isset($_FILES[$this->name]['name'])) { $curElemValue = $_FILES[$this->name]['name']; $curElemSize = $_FILES[$this->name]['size']; } else { $curElemValue = $this->value; } } // If Pop\Validator\* if ($validator instanceof \Pop\Validator\ValidatorInterface) { if ('Pop\\Validator\\NotEmpty' == get_class($validator)) { if (!$validator->evaluate($curElemValue)) { $this->errors[] = $validator->getMessage(); } } else { if (null !== $curElemSize && 'Pop\\Validator\\LessThanEqual' == get_class($validator)) { if (!$validator->evaluate($curElemSize)) { $this->errors[] = $validator->getMessage(); } } else { if (!empty($curElemValue) && !$validator->evaluate($curElemValue)) { $this->errors[] = $validator->getMessage(); } } } // Else, if callable } else { $result = call_user_func_array($validator, array($curElemValue)); if (null !== $result) { $this->errors[] = $result; } } } } // If errors are found on any of the form elements, return false. return count($this->errors) > 0 ? false : true; }
public function testCreateXmlFromTextNoTargetException() { $this->setExpectedException('Pop\\I18n\\Exception'); I18n::createXmlFromText(__DIR__ . '/../tmp/bad.txt', __DIR__ . '/../tmp/de.txt', __DIR__ . '/../bad'); }
/** * Get configuration values * * @return void */ public function getAll() { $cfg = Table\Config::getConfig(); $config = array(); $formattedConfig = array(); foreach ($cfg->rows as $c) { $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? $value = unserialize($c->value) : $c->value; } $sysVersion = $config['system_version']; $latest = ''; $handle = fopen('http://update.phirecms.org/system/version', 'r'); if ($handle !== false) { $latest = trim(stream_get_contents($handle)); fclose($handle); } if (version_compare(\Phire\Project::VERSION, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) { $sysVersion .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)'; } // Set server config settings $formattedConfig['server'] = array('system_version' => $sysVersion, 'system_domain' => $config['system_domain'], 'system_document_root' => $config['system_document_root'], 'system_base_path' => BASE_PATH, 'system_application_path' => APP_PATH, 'system_content_path' => CONTENT_PATH, 'server_operating_system' => $config['server_operating_system'], 'server_software' => $config['server_software'], 'database_version' => $config['database_version'], 'php_version' => $config['php_version'], 'installed_on' => date($this->config->datetime_format, strtotime($config['installed_on'])), 'updated_on' => $config['updated_on'] != '0000-00-00 00:00:00' ? date($this->config->datetime_format, strtotime($config['updated_on'])) : '(' . $this->i18n->__('Never') . ')'); // Set site title form element $siteTitle = new Element('text', 'site_title', $config['site_title']); $siteTitle->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;'); // Set system title form element $systemTitle = new Element('text', 'system_title', $config['system_title']); $systemTitle->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;'); // Set system email form element $systemEmail = new Element('text', 'system_email', $config['system_email']); $systemEmail->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;'); // Set system email form element $replyEmail = new Element('text', 'reply_email', $config['reply_email']); $replyEmail->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;'); // Set separator form element $separator = new Element('text', 'separator', $config['separator']); $separator->setAttributes('size', 3)->setAttributes('style', 'padding: 5px;'); // Set default language form element $langs = I18n::getLanguages(); foreach ($langs as $key => $value) { $langs[$key] = substr($value, 0, strpos($value, ' (')); } $lang = new Element\Select('default_language', $langs, $config['default_language'], ' '); // Set date and time format form element $datetime = $this->getDateTimeFormat($config['datetime_format']); // Set max media size form element $maxSize = new Element('text', 'media_max_filesize', $this->getMaxSize($config['media_max_filesize'])); $maxSize->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;'); // Set page limit form element $pageLimit = new Element('text', 'pagination_limit', $config['pagination_limit']); $pageLimit->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;'); // Set page range form element $pageRange = new Element('text', 'pagination_range', $config['pagination_range']); $pageRange->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;'); // Set media actions and media types form elements $mediaConfig = $this->getMediaConfig($config['media_actions']); $mediaTypes = $this->getMediaAllowedTypes($config['media_allowed_types']); $imageAdapters = array('Gd' => 'Gd'); if (\Pop\Image\Imagick::isInstalled()) { $imageAdapters['Imagick'] = 'Imagick'; } $phpLimits = array('post_max_size' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('post_max_size'))), 'upload_max_filesize' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('upload_max_filesize'))), 'max_file_uploads' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('max_file_uploads')))); $phpLimitsString = ''; foreach ($phpLimits as $limit => $limitValue) { $phpLimitsString .= '<span style="padding: 0 5px 0 5px;">' . $this->i18n->__(ucwords(str_replace('_', ' ', $limit))) . ': ' . '<strong>' . $limitValue . '</strong></span>'; } $formattedConfig['settings'] = array('site_title' => $siteTitle, 'system_title' => $systemTitle, 'system_email' => $systemEmail, 'reply_email' => $replyEmail, 'separator' => $separator, 'default_language' => $lang, 'datetime_format' => $datetime, 'media_allowed_types' => $mediaTypes, 'media_max_filesize' => ' ' . $maxSize . ' [<strong style="color: #f00; padding: 0 0 0 5px;">PHP ' . $this->i18n->__('Limits') . ':</strong> ' . $phpLimitsString . ']', 'media_actions' => $mediaConfig, 'media_image_adapter' => new Element\Select('media_image_adapter', $imageAdapters, $config['media_image_adapter'], ' '), 'pagination_limit' => ' ' . $pageLimit, 'pagination_range' => ' ' . $pageRange, 'force_ssl' => new Element\Radio('force_ssl', array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), $config['force_ssl'], ' '), 'live' => new Element\Radio('live', array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), $config['live'], ' ')); $this->data['config'] = new \ArrayObject($formattedConfig, \ArrayObject::ARRAY_AS_PROPS); }
/** * Install the base folder and file structure * * @param \Pop\Config $install * @return void */ public static function install($install) { echo \Pop\I18n\I18n::factory()->__('Creating base folder and file structure...') . PHP_EOL; // Define folders to create $folders = array($install->project->base, $install->project->base . '/config', $install->project->base . '/module', $install->project->base . '/module/' . $install->project->name, $install->project->base . '/module/' . $install->project->name . '/config', $install->project->base . '/module/' . $install->project->name . '/data', $install->project->base . '/module/' . $install->project->name . '/src', $install->project->base . '/module/' . $install->project->name . '/src/' . $install->project->name, $install->project->base . '/module/' . $install->project->name . '/view', $install->project->docroot); // Create the folders foreach ($folders as $folder) { if (!file_exists($folder)) { mkdir($folder); } } // Make the '/data' folder writable chmod($install->project->base . '/module/' . $install->project->name . '/data', 0777); // Figure out the relative base and docroot $base = str_replace("\\", '/', realpath($install->project->base)); $docroot = str_replace("\\", '/', realpath($install->project->docroot)); $base = substr($base, -1) == '/' ? substr($base, 0, -1) : $base; $docroot = substr($docroot, -1) == '/' ? substr($docroot, 0, -1) : $docroot; // If the base and docroot are the same if (strlen($base) == strlen($docroot)) { $base = "__DIR__ . '/../'"; $docroot = "__DIR__ . '/../'"; // If the docroot is under the base } else { if (strlen($base) < strlen($docroot)) { $relDocroot = str_replace($base, '', $docroot); $base = "__DIR__ . '/../'"; $docroot = "__DIR__ . '/.." . $relDocroot . "'"; // If the base is under the docroot } else { if (strlen($base) > strlen($docroot)) { // Calculate how many levels up the docroot is from the base $diff = str_replace($docroot, '/', $base); $levels = substr_count($diff, '/'); $dirs = null; for ($i = 0; $i < $levels; $i++) { $dirs .= '../'; } $base = "__DIR__ . '/../'"; $docroot = "__DIR__ . '/" . $dirs . "'"; } } } // Create project.php file $projectCfg = new \Pop\Code\Generator($install->project->base . '/config/project.php'); $projectCfg->appendToBody('return new Pop\\Config(array(', true)->appendToBody(" 'base' => " . $base . ",")->appendToBody(" 'docroot' => " . $docroot, false); // Add the database config to it if (isset($install->databases)) { $projectCfg->appendToBody(",")->appendToBody(" 'databases' => array("); $databases = $install->databases->asArray(); $default = null; $i = 0; foreach ($databases as $dbname => $db) { $isPdo = stripos($db['type'], 'pdo') !== false ? true : false; $isSqlite = stripos($db['type'], 'sqlite') !== false ? true : false; if ($isPdo) { $pdoType = strtolower(substr($db['type'], strpos($db['type'], '_') + 1)); $realDbType = 'Pdo'; } else { $pdoType = null; $realDbType = $db['type']; } $projectCfg->appendToBody(" '" . $dbname . "' => Pop\\Db\\Db::factory('" . $realDbType . "', array ("); $j = 0; $default = $db['default'] ? $dbname : null; $dbCreds = $db; unset($dbCreds['type']); unset($dbCreds['prefix']); unset($dbCreds['default']); foreach ($dbCreds as $key => $value) { $j++; if ($isSqlite) { $dbFile = "__DIR__ . '/../module/" . $install->project->name . "/data/" . basename($value) . "'"; $ary = " '{$key}' => {$dbFile}"; } else { $ary = " '{$key}' => '{$value}'"; } if ($isPdo) { $ary .= "," . PHP_EOL . " 'type' => '{$pdoType}'"; } if ($j < count($dbCreds)) { $ary .= ','; } $projectCfg->appendToBody($ary); } $i++; $end = $i < count($databases) ? ' )),' : ' ))'; $projectCfg->appendToBody($end); } $projectCfg->appendToBody(' )', false); if (null !== $default) { $projectCfg->appendToBody("," . PHP_EOL . " 'defaultDb' => '" . $default . "'", false); } } // Save project config $projectCfg->appendToBody(PHP_EOL . '));', false); $projectCfg->save(); // Create the module config file $moduleCfg = new \Pop\Code\Generator($install->project->base . '/module/' . $install->project->name . '/config/module.php'); $moduleCfg->appendToBody('return array(')->appendToBody(" '{$install->project->name}' => new Pop\\Config(array(")->appendToBody(" 'base' => __DIR__ . '/../',")->appendToBody(" 'config' => __DIR__ . '/../config',")->appendToBody(" 'data' => __DIR__ . '/../data',")->appendToBody(" 'src' => __DIR__ . '/../src',")->appendToBody(" 'view' => __DIR__ . '/../view'")->appendToBody(" ))")->appendToBody(");", false)->save(); }
/** * Method to set the validator * * @throws \Pop\Form\Exception * @return void */ protected function setValidator() { // Get query data if ($_SERVER['REQUEST_METHOD']) { $queryData = array(); switch ($_SERVER['REQUEST_METHOD']) { case 'GET': $queryData = $_GET; break; case 'POST': $queryData = $_POST; break; default: $input = fopen('php://input', 'r'); $qData = null; while ($data = fread($input, 1024)) { $qData .= $data; } parse_str($qData, $queryData); } // If there is query data, set validator to check against the token value if (count($queryData) > 0) { $val = isset($queryData[$this->name]) ? $queryData[$this->name] : ''; $this->addValidator(new \Pop\Validator\Equal($val, \Pop\I18n\I18n::factory()->__('The security token does not match.'))); } } else { throw new \Pop\Form\Exception('Error: The server request method is not set.'); } }
/** * Static method to get i18n object * * @return \Pop\I18n\I18n */ public static function getI18n() { $lang = static::findById('default_language')->value; if (!defined('POP_LANG')) { define('POP_LANG', $lang); $i18n = \Pop\I18n\I18n::factory($lang); } else { $i18n = \Pop\I18n\I18n::factory(POP_LANG); } $i18n->loadFile(__DIR__ . '/../../../data/assets/i18n/' . $i18n->getLanguage() . '.xml'); // Load any module language files $modules = Extensions::findAll(null, array('type' => 1)); foreach ($modules->rows as $module) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name) && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data') && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n') && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n/' . $i18n->getLanguage() . '.xml')) { $i18n->loadFile($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules/' . $module->name . '/data/assets/i18n/' . $i18n->getLanguage() . '.xml'); } } return $i18n; }
echo 'Help' . PHP_EOL; echo '----' . PHP_EOL; Install::cliHelp(); // Else, show instructions } else { if ($argv[1] == '-s' || $argv[1] == '--show') { echo 'Project Install Instructions' . PHP_EOL; echo '----------------------------' . PHP_EOL; Install::instructions(); // Else, set default project language } else { if ($argv[1] == '-l' || $argv[1] == '--lang') { echo 'Set Default Project Language' . PHP_EOL; echo '----------------------------' . PHP_EOL; // Create list of available languages $langs = I18n::getLanguages(); $langsList = null; $i = 0; foreach ($langs as $key => $value) { $num = $i < 10 ? ' ' . $i : $i; $langsList .= ' ' . $num . ' : [' . $key . '] ' . $value . PHP_EOL; $i++; } // Prompt user to select language if (isset($argv[2])) { if (!array_key_exists($argv[2], $langs)) { echo $langsList . PHP_EOL; $lang = Install::getLanguage($langs); } else { $lang = $argv[2]; }
/** * Method to get the authentication result message * * @return string */ public function getResultMessage() { $msg = null; switch ($this->result) { case self::USER_IS_VALID: $msg = I18n::factory()->__('The user is valid.'); break; case self::USER_NOT_FOUND: $msg = I18n::factory()->__('The user was not found.'); break; case self::USER_IS_BLOCKED: $msg = I18n::factory()->__('The user is blocked.'); break; case self::PASSWORD_INCORRECT: $msg = I18n::factory()->__('The password was incorrect.'); break; case self::ATTEMPTS_EXCEEDED: $msg = I18n::factory()->__('The allowed login attempts (%1) have been exceeded.', $this->validators['attempts']->getValue()); break; case self::IP_BLOCKED: $msg = I18n::factory()->__('That IP address is blocked.'); break; case self::IP_NOT_ALLOWED: $msg = I18n::factory()->__('That IP address is not allowed.'); break; } return $msg; }