/** * webalize test. * @return void */ public function testWebalize() { $this->assertEquals("zlutoucky-kun-oooo", String::webalize("&ŽLUŤOUČKÝ KŮŇ öőôo!")); // &ŽLUŤOUČKÝ KŮŇ öőôo! $this->assertEquals("ZLUTOUCKY-KUN-oooo", String::webalize("&ŽLUŤOUČKÝ KŮŇ öőôo!", NULL, FALSE)); // &ŽLUŤOUČKÝ KŮŇ öőôo! $this->assertEquals("1-4-!", String::webalize("¼!", '!')); }
public function _save($values) { $values['parent'] = (int) $values['parent']; $values['slug'] = String::webalize($values['title']); $position = (int) db::select('max(position)')->from(':table:')->where('parent = %i', $values['parent'])->fetchSingle(); $values['position'] = $position + 1; db::insert(':table:', $values)->execute(); return array('id' => db::getInsertId(), 'title' => $values['title'], 'parent_id' => $values['parent'], 'position' => $values['position']); }
/** * treats filename for potentionally dangerous characters ensuring safe saving to filesystem * enables '.' except the very first and very last character for security reasons * @param string * @return string * @throws InvalidFilenameException */ public static function handleFilename($filename) { $filename = String::webalize($filename, '.'); // check if '.' is the very first or very last character - should be enough to check that if (strpos($filename, '.') == 0 or strrpos($filename, '.') == strlen($filename) - 1) { // throw new InvalidFilenameException('Zadajte platný názov súboru! Nie sú povolené bodky na začiatku ani na konci názvu súboru.'); throw new InvalidFilenameException('Enter valid filename! Dots are not allowed at the very start nor the very end of filename.'); } return $filename; }
public function _save($values) { $values['slug'] = String::webalize($values['title']); if (isset($values['link'])) { if ($values['link'] > 0) { $link = array(); $slug = $values['slug']; if ($values['category'] > 0) { $cat_model = new Admin_CategoriesModel(); $cat = $cat_model->getById((int) $values['category']); $slug = $cat->slug . '/' . $slug; } $link['title'] = $values['title']; $link['url'] = $slug; $link['parent'] = 0; $link['level'] = 1; $link['menu_id'] = (int) $values['link']; $link_model = new Admin_MenuItemsModel(); $link_model->create($link); //refresh table alias $this->__after_startup(); } unset($values['link']); } $values['content_type'] = 'page'; if (!isset($values['publish_time'])) { $values['publish_time'] = time(); } $values['publish_time'] = db::datetime($values['publish_time']); if (isset($values['homepage'])) { if ($values['homepage'] == 1) { $update = array('homepage' => 0); db::update(':table:', $update)->execute(); } } db::insert(':table:', $values)->execute(); return db::getInsertId(); }
public function onNewPictureSubmit(Form $form) { if (!$form->isValid()) { return; } $file = $form['file']->getValue(); // save thumbnail try { $image = $file->getImage(); } catch (Exception $e) { $form->addError(__('Uploaded file has to be an image.')); return; } if ($image->getWidth() > $image->getHeight()) { $image->resize(NULL, 60); } else { $image->resize(60, NULL); } $image->crop(intval(($image->getWidth() - 60) / 2), intval(($image->getHeight() - 60) / 2), 60, 60); $thumbnail_filename = sha1(microtime()) . '.png'; $image->save(Environment::expand('%mediaDir%/' . $thumbnail_filename)); unset($image); // save big picture $big_filename = String::webalize($form['rename']->getValue()); $need_resave = TRUE; if (empty($big_filename)) { $big_filename = $file->getName(); } if (($pos = strrpos($big_filename, '.')) !== FALSE) { $ext = substr($big_filename, $pos); $before_ext = substr($big_filename, 0, $pos); if (strtolower($ext) !== '.png') { $big_filename = $before_ext . '.png'; } else { $need_resave = FALSE; } } else { $big_filename .= '.png'; } if ($need_resave) { $image = $file->getImage(); $image->save(Environment::expand('%mediaDir%/' . $big_filename)); } else { $file->move(Environment::expand('%mediaDir%/' . $big_filename)); } $image = $file->getImage(); $image->resize(300, 300, Image::ENLARGE); $image->save(Environment::expand('%mediaDir%/' . $big_filename)); // save to db if (!mapper::pictures()->insertOne($big_filename, $thumbnail_filename, $form['description']->getValue())) { $form->addError(__('Cannot save image data into the database, try again.')); } else { adminlog::log(__('Added picture "%s"'), $big_filename); $this->redirect('pictures'); $this->terminate(); } }
/** * Rename file or directory * @param string folder * @param string old item name * @param string new item name */ public function actionRename($folder, $oldname, $newname) { $oldpath = $this->getFolderPath($folder) . "/" . $oldname; $newpath = $this->getFolderPath($folder) . "/" . String::webalize($newname, "."); if (!file_exists($oldpath)) { $this->sendError("File does not exist."); } if (rename($oldpath, $newpath)) { $this->terminate(new JsonResponse(array("deleted" => true))); } else { $this->sendError("Unable to rename file."); } }
public function deletePage($params, $dialog) { $title = $params; $webalized_title = String::webalize($title); try { $this->model('pages')->delete($title); $this->model('menuItems')->deleteRelated($webalized_title); $this['page']->redraw('Pages'); $this->flash('Page ' . $title . ' deleted!'); if (!$this->isAjax()) { $this->redirect('Pages:'); } } catch (DibiDriverException $e) { $this->flash($e->getMessage()); } }
public function onImportFormSubmit(Form $form) { if (!$form->isValid()) { return; } if (!($handle = @fopen('safe://' . $form['file']->getValue()->getTemporaryFile(), 'r'))) { $form->addError(__('Cannot read file.')); return; } adminlog::log(__('Attempt to import products')); // provision $provision = intval($form['provision']->getValue()); // read file $import = array(); $codes = array(); while (($_ = fgetcsv($handle)) !== FALSE) { $product = array(); list($product['code'], $product['manufacturer'], $product['name'], $product['category'], , , $product['price']) = $_; $product['price'] = intval(round($product['price'] / (100 - $provision) * 100)); $import[$product['code']] = $product; $codes[] = $product['code']; } fclose($handle); $updated = 0; // update in db foreach (mapper::products()->findByCodes($codes) as $product) { $values = array('id' => $product->getId(), 'price' => $import[$product->getCode()]['price']); mapper::products()->updateOne($values); unset($import[$product->getCode()]); $updated++; } adminlog::log(__('Updated %d products'), $updated); // update only? if ($form['update_only']->getValue()) { adminlog::log(__('Import successful')); $this->redirect('this'); $this->terminate(); return; } // manufacturers & categories $manufacturers = array(); $categories = array(); foreach ($import as $k => $_) { $m_key = String::webalize($_['manufacturer']); $manufacturers[$m_key] = $_['manufacturer']; $import[$k]['manufacturer'] = $m_key; $c_key = String::webalize($_['category']); $categories[$c_key] = $_['category']; $import[$k]['category'] = $c_key; } $manufacturers_added = 0; foreach ($manufacturers as $nice_name => $name) { if (($_ = mapper::manufacturers()->findByNiceName($nice_name)) === NULL) { mapper::manufacturers()->insertOne(array('nice_name' => $nice_name, 'name' => $name)); $manufacturers[$nice_name] = mapper::manufacturers()->findByNiceName($nice_name)->getId(); $manufacturers_added++; } else { $manufacturers[$nice_name] = $_->getId(); } $manufacturers[$nice_name] = intval($manufacturers[$nice_name]); } adminlog::log(__('Added %d new manufacturers'), $manufacturers_added); $categories_added = 0; foreach ($categories as $nice_name => $name) { if (($_ = mapper::categories()->findByNiceName($nice_name)) === NULL) { mapper::categories()->addOne(array('nice_name' => $nice_name, 'name' => $name)); $categories[$nice_name] = mapper::categories()->findByNiceName($nice_name)->getId(); $categories_added++; } else { $categories[$nice_name] = $_->getId(); } $categories[$nice_name] = intval($categories[$nice_name]); } adminlog::log(__('Added %d new categories'), $categories_added); // other $other = array(); if ($form['availability_id']->getValue() != 0) { $other['availability_id'] = intval($form['availability_id']->getValue()); } $products_added = 0; // insert products foreach ($import as $_) { $_['manufacturer_id'] = $manufacturers[$_['manufacturer']]; unset($_['manufacturer']); $_['category_id'] = $categories[$_['category']]; unset($_['category']); $_['nice_name'] = String::webalize($_['name']); $_ = array_merge($_, $other); mapper::products()->insertOne($_); $products_added++; } adminlog::log(__('Added %d new products'), $products_added); adminlog::log(__('Import successful')); // all done $this->redirect('this'); $this->terminate(); }
public function getTags($args) { $pageId = (int) $args[0]; $username = $args[1]; $password = $args[2]; $user = $this->login($username, $password); if (!$user) { return $this->error; } $tags = $this->model('tags')->getAll(); $array = array(); foreach ($tags as $tag) { $struct = array(); $struct['tag_id'] = (int) $tag->tag_id; $struct['name'] = (string) $tag->tag_name; $struct['count'] = 1; $struct['slug'] = String::webalize($struct['name']); $struct['html_url'] = ''; $struct['rss_url'] = ''; $array[] = $struct; } return $array; }
public function nullUnikatnySubor() { return String::webalize($this->nazov); }
/** * Retype value of field to string * @param mixed $value * @return string */ public function retype($value) { return is_null($value) ? null : String::webalize($value); }
public function nullKod() { return String::webalize($this->nazov); }