Example #1
0
 function singular_plural($int = 0, $text = NULL)
 {
     if ((int) $int > 1) {
         return (int) $int . nbs() . plural($text);
     }
     return (int) $int . nbs() . $text;
 }
Example #2
0
 /**
  * Gets the specified table name of the model.
  *
  * @return string
  */
 public function getTableName()
 {
     if (!$this->table) {
         return plural(strtolower(get_class($this)));
     }
     return $this->table;
 }
function pleac_Printing_Correct_Plurals()
{
    function pluralise($value, $root, $singular = '', $plural = 's')
    {
        return $root . ($value > 1 ? $plural : $singular);
    }
    // ------------
    $duration = 1;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    $duration = 5;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    // ----------------------------
    function plural($singular)
    {
        $s2p = array('/ss$/' => 'sses', '/([psc]h)$/' => '${1}es', '/z$/' => 'zes', '/ff$/' => 'ffs', '/f$/' => 'ves', '/ey$/' => 'eys', '/y$/' => 'ies', '/ix$/' => 'ices', '/([sx])$/' => '$1es', '$' => 's');
        foreach ($s2p as $s => $p) {
            if (preg_match($s, $singular)) {
                return preg_replace($s, $p, $singular);
            }
        }
    }
    // ------------
    foreach (array('mess', 'index', 'leaf', 'puppy') as $word) {
        printf("%6s -> %s\n", $word, plural($word));
    }
}
Example #4
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     $columnFields = ['name', 'description', 'label'];
     $table = $this->describe->getTable($this->data['name']);
     foreach ($table as $column) {
         if ($column->isAutoIncrement()) {
             continue;
         }
         $field = strtolower($column->getField());
         $method = 'set_' . $field;
         $this->data['camel'][$field] = lcfirst(camelize($method));
         $this->data['underscore'][$field] = underscore($method);
         array_push($this->data['columns'], $field);
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = $referencedTable;
             array_push($this->data['models'], $referencedTable);
             $dropdown = ['list' => plural($referencedTable), 'table' => $referencedTable, 'field' => $field];
             if (!in_array($field, $columnFields)) {
                 $field = $this->describe->getPrimaryKey($referencedTable);
                 $dropdown['field'] = $field;
             }
             array_push($this->data['dropdowns'], $dropdown);
         }
     }
     return $this->data;
 }
Example #5
0
 /**
  * Calcula la diferencia entre dos timestamps y retorna un array con las
  * unidades temporales mรกs altas, en orden descendente (aรฑo, mes, semana, dia. etc).
  * Sirve para calcular las fechas de "hace x minutos" o "en x semanas".
  * Maneja automรกticamente los singulares y plurales.
  * 
  * @param  integer $timestamp Tiempo a comparar, en el pasado o futuro
  * @param  integer $unidades  Unidades temporales a mostrar. 
  *                            Ej: 1 puede devolver "hora", 2 puede devolver
  *                            "semanas" y "dias".
  * @param  integer $comparar  Fecha a comparar. Por defecto, time().
  * @return array              Array de 2 o mรกs valores.
  *                            El primero es un booleano que indica si el tiempo estรก
  *                            en el futuro. El resto son las unidades temporales.
  */
 function fechaTextual($timestamp = 0, $unidades = 2, $comparar = 0)
 {
     if (!is_numeric($timestamp)) {
         return array();
     }
     if (!$comparar) {
         $comparar = time();
     }
     $diferencia = $comparar - $timestamp;
     $fechaEsFutura = $diferencia < 0 ? true : false;
     $valores = array('aรฑo' => 0, 'mes' => 0, 'semana' => 0, 'dia' => 0, 'hora' => 0, 'minuto' => 0, 'segundo' => 0);
     $constantes = array('aรฑo' => YEAR_IN_SECONDS, 'mes' => MONTH_IN_SECONDS, 'semana' => WEEK_IN_SECONDS, 'dia' => DAY_IN_SECONDS, 'hora' => HOUR_IN_SECONDS, 'minuto' => MINUTE_IN_SECONDS, 'segundo' => 1);
     foreach ($constantes as $k => $constante) {
         if ($diferencia > $constante) {
             $valores[$k] = floor($diferencia / $constante);
             $diferencia = $diferencia % $constante;
         }
     }
     $retorno = array($fechaEsFutura);
     $plural = array('aรฑo' => 'aรฑos', 'mes' => 'meses', 'semana' => 'semanas', 'dia' => 'dias', 'hora' => 'horas', 'minuto' => 'minutos', 'segundo' => 'segundos');
     while ($unidades > 0) {
         foreach ($valores as $k => $v) {
             if ($v != 0) {
                 $retorno[] = $v . ' ' . plural($v, $k, $plural[$k]);
                 unset($valores[$k]);
                 break;
             }
             unset($valores[$k]);
         }
         $unidades--;
     }
     return $retorno;
 }
Example #6
0
 /**
  * Executes the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = Tools::stripTableSchema(plural($input->getArgument('name')));
     if ($input->getOption('keep')) {
         $name = Tools::stripTableSchema($input->getArgument('name'));
     }
     $validator = new ViewValidator($name);
     if ($validator->fails()) {
         $message = $validator->getMessage();
         return $output->writeln('<error>' . $message . '</error>');
     }
     $data = ['isBootstrap' => $input->getOption('bootstrap'), 'isCamel' => $input->getOption('camel'), 'name' => $input->getArgument('name')];
     $generator = new ViewGenerator($this->describe, $data);
     $result = $generator->generate();
     $results = ['create' => $this->renderer->render('Views/create.tpl', $result), 'edit' => $this->renderer->render('Views/edit.tpl', $result), 'index' => $this->renderer->render('Views/index.tpl', $result), 'show' => $this->renderer->render('Views/show.tpl', $result)];
     $filePath = APPPATH . 'views/' . $name;
     $create = new File($filePath . '/create.php');
     $edit = new File($filePath . '/edit.php');
     $index = new File($filePath . '/index.php');
     $show = new File($filePath . '/show.php');
     $create->putContents($results['create']);
     $edit->putContents($results['edit']);
     $index->putContents($results['index']);
     $show->putContents($results['show']);
     $create->close();
     $edit->close();
     $index->close();
     $show->close();
     $message = 'The views folder "' . $name . '" has been created successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
Example #7
0
function getRelativeTime($date)
{
    $time = @strtotime($date);
    $diff = time() - $time;
    if ($diff < 60) {
        return $diff . " second" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 60) {
        return $diff . " minute" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 24) {
        return $diff . " hour" . plural($diff) . " ago";
    }
    $diff = round($diff / 24);
    if ($diff < 7) {
        return $diff . " day" . plural($diff) . " ago";
    }
    $diff = round($diff / 7);
    if ($diff < 4) {
        return $diff . " week" . plural($diff) . " ago";
    }
    if (date('Y', $time) != date('Y', time())) {
        return date("j-M Y", $time);
    }
    return date("j-M", $time);
}
Example #8
0
 public function edit()
 {
     $sModel = $this->uri->segment(4);
     if (class_exists($sModel)) {
         $oModel = new $sModel();
         $oResult = $oModel->load()->where('id', $this->uri->segment(5))->get();
         //** Build array to populate form
         foreach ($oModel->fieldNames as $sValue) {
             $aOut[$sModel][$sValue] = $oResult->{$sValue};
         }
         //** Any __includes ?
         foreach ($oModel->form as $k => $aValue) {
             if ($k == '__include') {
                 foreach ($aValue['model'] as $k2 => $v2) {
                     //** Add these models to the aFormData array
                     $oObj = new $v2();
                     $oResult = $oObj->load()->where(strtolower($sModel) . '_id', $this->uri->segment(5))->get();
                     foreach ($oObj->fieldNames as $sValue) {
                         $aOut[ucfirst($v2)][$sValue] = $oResult->{$sValue};
                     }
                 }
             }
         }
         $this->aData['aFormData'] = $aOut;
         $this->aData['iEditId'] = $this->uri->segment(5);
         //** each form needs these
         $this->aData['sView'] = 'includes/forms/' . ucfirst(plural($oModel)) . '_form';
         $this->aData['sTarget'] = '/admin/master/listall/' . $sModel;
         $this->load->view('form', $this->aData);
     }
 }
Example #9
0
function relative_time($date)
{
    $diff = time() - $date;
    $poststr = $diff > 0 ? " ago" : "";
    $adiff = abs($diff);
    if ($adiff < 60) {
        return $adiff . " second" . plural($adiff) . $poststr;
    }
    if ($adiff < 3600) {
        // 60*60
        return round($adiff / 60) . " minute" . plural($adiff) . $poststr;
    }
    if ($adiff < 86400) {
        // 24*60*60
        return round($adiff / 3600) . " hour" . plural($adiff) . $poststr;
    }
    if ($adiff < 604800) {
        // 7*24*60*60
        return round($adiff / 86400) . " day" . plural($adiff) . $poststr;
    }
    if ($adiff < 2419200) {
        // 4*7*24*60*60
        return $adiff . " week" . plural($adiff) . $poststr;
    }
    return "on " . date("F j, Y", strtotime($date));
}
Example #10
0
 function Orm($name = null, $table = null, $primaryKey = null)
 {
     $this->_assignLibraries();
     $this->_loadHelpers();
     if ($name == null) {
         if ($this->name == null) {
             $this->name = ucfirst(singular(get_class($this)));
         }
     } else {
         $this->name = $name;
     }
     if ($this->alias === null) {
         $this->alias = $this->name;
     }
     if ($table == null) {
         if ($this->table == null) {
             $this->table = plural($this->name);
         }
     } else {
         $this->table = $table;
     }
     $this->table = $this->prefix . $this->table;
     if ($primaryKey == null) {
         if ($this->primaryKey == null) {
             $this->primaryKey = 'id';
         }
     } else {
         $this->primaryKey = $primaryKey;
     }
     Registry::addObject($this->alias, $this);
     $this->createLinks();
 }
Example #11
0
 public function index()
 {
     $this->document->setTitle(tt('BitsyBay - Sell and Buy Digital Content with BitCoin'), false);
     if (isset($this->request->get['route'])) {
         $this->document->addLink(HTTP_SERVER, 'canonical');
     }
     if ($this->auth->isLogged()) {
         $data['title'] = sprintf(tt('Welcome, %s!'), $this->auth->getUsername());
         $data['user_is_logged'] = true;
     } else {
         $data['title'] = tt('Welcome to the BitsyBay store!');
         $data['user_is_logged'] = false;
     }
     $total_products = $this->model_catalog_product->getTotalProducts(array());
     $data['total_products'] = sprintf(tt('%s %s'), $total_products, plural($total_products, array(tt('offer'), tt('offers'), tt('offers'))));
     $total_categories = $this->model_catalog_category->getTotalCategories();
     $data['total_categories'] = sprintf(tt('%s %s'), $total_categories, plural($total_categories, array(tt('category'), tt('categories'), tt('categories'))));
     $total_sellers = $this->model_account_user->getTotalSellers();
     $data['total_sellers'] = sprintf(tt('%s %s'), $total_sellers, plural($total_sellers, array(tt('seller'), tt('sellers'), tt('sellers'))));
     $total_buyers = $this->model_account_user->getTotalUsers();
     $data['total_buyers'] = sprintf(tt('%s %s'), $total_buyers, plural($total_buyers, array(tt('buyer'), tt('buyers'), tt('buyers'))));
     $redirect = base64_encode($this->url->getCurrentLink($this->request->getHttps()));
     $data['login_action'] = $this->url->link('account/account/login', 'redirect=' . $redirect, 'SSL');
     $data['href_account_create'] = $this->url->link('account/account/create', 'redirect=' . $redirect, 'SSL');
     $data['module_search'] = $this->load->controller('module/search', array('class' => 'col-lg-8 col-lg-offset-2'));
     $data['module_latest'] = $this->load->controller('module/latest', array('limit' => 8));
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $this->response->setOutput($this->load->view('common/home.tpl', $data));
 }
Example #12
0
 public function index()
 {
     $this->document->setTitle(tt('BitsyBay - Sell and Buy Digital Creative with BitCoin'), false);
     $this->document->setDescription(tt('BTC Marketplace for royalty-free photos, arts, templates, codes, books and other digital creative with BitCoin. Only quality and legal content from them authors. Free seller fee up to 2016!'));
     $this->document->setKeywords(tt('bitsybay, bitcoin, btc, indie, marketplace, store, buy, sell, royalty-free, photos, arts, illustrations, 3d, templates, codes, extensions, books, content, digital, creative, quality, legal'));
     if (isset($this->request->get['route'])) {
         $this->document->addLink(URL_BASE, 'canonical');
     }
     if ($this->auth->isLogged()) {
         $data['title'] = sprintf(tt('Welcome, %s!'), $this->auth->getUsername());
         $data['user_is_logged'] = true;
     } else {
         $data['title'] = tt('Welcome to the BitsyBay store!');
         $data['user_is_logged'] = false;
     }
     $total_products = $this->model_catalog_product->getTotalProducts(array());
     $data['total_products'] = sprintf(tt('%s %s'), $total_products, plural($total_products, array(tt('offer'), tt('offers'), tt('offers'))));
     $total_categories = $this->model_catalog_category->getTotalCategories();
     $data['total_categories'] = sprintf(tt('%s %s'), $total_categories, plural($total_categories, array(tt('category'), tt('categories'), tt('categories'))));
     $total_sellers = $this->model_account_user->getTotalSellers();
     $data['total_sellers'] = sprintf(tt('%s %s'), $total_sellers, plural($total_sellers, array(tt('sellers'), tt('sellers'), tt('sellers'))));
     $total_buyers = $this->model_account_user->getTotalUsers();
     $data['total_buyers'] = sprintf(tt('%s %s'), $total_buyers, plural($total_buyers, array(tt('buyers'), tt('buyers'), tt('buyers'))));
     $redirect = base64_encode($this->url->getCurrentLink());
     $data['login_action'] = $this->url->link('account/account/login', 'redirect=' . $redirect);
     $data['href_account_create'] = $this->url->link('account/account/create', 'redirect=' . $redirect);
     $data['module_search'] = $this->load->controller('module/search', array('class' => 'col-lg-8 col-lg-offset-2'));
     $data['module_latest'] = $this->load->controller('module/latest', array('limit' => 4));
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $this->response->setOutput($this->load->view('common/home.tpl', $data));
 }
function table_torch_nav()
{
    $CI =& get_instance();
    $tables = $CI->config->item('torch_tables');
    $prefs = $tables[TORCH_TABLE];
    $extra_links = $CI->config->item('table_extra_nav_links');
    if (isset($_SERVER['HTTP_REFERER'])) {
        $refer = $_SERVER['HTTP_REFERER'];
    } else {
        $refer = CUR_CONTROLLER;
    }
    $str = "<ul id=\"navHeader\">\n";
    if (TORCH_METHOD == 'edit' or TORCH_METHOD == 'add') {
        $str .= "<li class=\"backLink\"><a href=\"{$refer}\">" . $CI->lang->line('table_torch_back_to_listing') . "</a></li>\n";
    } else {
        if (TORCH_METHOD == 'listing' and $prefs['add'] == TRUE) {
            $str .= "<li class=\"backLink\">\n" . anchor(CUR_CONTROLLER . '/' . CUR_METHOD . "/add/" . TORCH_TABLE, $CI->lang->line('table_torch_add_new_link')) . "</li>\n";
        }
    }
    foreach ($tables as $key => $table) {
        if ($key == TORCH_TABLE) {
            $class = 'active';
        } else {
            $class = '';
        }
        $label = ucwords(plural(table_torch_title($key)));
        $url = site_url(CUR_CONTROLLER . '/' . CUR_METHOD . '/listing/' . $key);
        $str .= "<li><a href=\"{$url}\" class=\"{$class}\">{$label}</a></li>\n";
    }
    foreach ($extra_links as $url => $label) {
        $str .= "<li>" . anchor($url, $label) . "</li>\n";
    }
    return $str . "\n</ul>\n";
}
 public function test_plural()
 {
     $strs = array('telly' => 'tellies', 'smelly' => 'smellies', 'abjectness' => 'abjectnesses', 'smell' => 'smells', 'witch' => 'witches', 'equipment' => 'equipment');
     foreach ($strs as $str => $expect) {
         $this->assertEquals($expect, plural($str));
     }
 }
Example #15
0
function get_relative_date($date)
{
    /*
    Returns relative(more human) date string.
    Uses: `plural`.
    
    Usage:
    `get_relative_date(get_the_date())`
    */
    $diff = time() - strtotime($date);
    if ($diff < 60) {
        return $diff . " second" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 60) {
        return $diff . " minute" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 24) {
        return $diff . " hour" . plural($diff) . " ago";
    }
    $diff = round($diff / 24);
    if ($diff < 7) {
        return $diff . " day" . plural($diff) . " ago";
    }
    $diff = round($diff / 7);
    if ($diff < 4) {
        return $diff . " week" . plural($diff) . " ago";
    }
    return date("F j, Y", strtotime($date));
}
 public function __construct()
 {
     if (empty($this->count_name)) {
         $et = explode('_', $this->table);
         $this->count_name = plural($et[0]) . '_count';
     }
     $this->pdo = $this->load->database('pdo', true);
 }
Example #17
0
/**
 * Function to process the items in an X amount of comments
 * 
 * @param array $comments The comments to process
 * @return array
 */
function process_comment_items($comments)
{
	$ci =& get_instance();

	foreach($comments as &$comment)
	{
		// work out who did the commenting
		if($comment->user_id > 0)
		{
			$comment->name = anchor('admin/users/edit/' . $comment->user_id, $comment->name);
		}

		// What did they comment on
		switch ($comment->module)
		{
			case 'news': # Deprecated v1.1.0
				$comment->module = 'blog';
				break;
			case 'gallery':
				$comment->module = plural($comment->module);
				break;
			case 'gallery-image':
				$comment->module = 'galleries';
				$ci->load->model('galleries/gallery_images_m');
				if ($item = $ci->gallery_images_m->get($comment->module_id))
				{
					$comment->item = anchor('admin/' . $comment->module . '/image_preview/' . $item->id, $item->title, 'class="modal-large"');
					continue 2;
				}
				break;
		}

		if (module_exists($comment->module))
		{
			if ( ! isset($ci->{$comment->module . '_m'}))
			{
				$ci->load->model($comment->module . '/' . $comment->module . '_m');
			}

			if ($item = $ci->{$comment->module . '_m'}->get($comment->module_id))
			{
				$comment->item = anchor('admin/' . $comment->module . '/preview/' . $item->id, $item->title, 'class="modal-large"');
			}
		}
		else
		{
			$comment->item = $comment->module .' #'. $comment->module_id;
		}
		
		// Link to the comment
		if (strlen($comment->comment) > 30)
		{
			$comment->comment = character_limiter($comment->comment, 30);
		}
	}
	
	return $comments;
}
Example #18
0
 /**
  * Tests the {@link plural()} function in the old calling style.
  */
 function testPluralOld()
 {
     $this->assertEquals("1 account", plural(1, "account"));
     $this->assertEquals("2 accounts", plural(2, "account"));
     $this->assertEquals("1 account", plural(1, "account", "accounts"));
     $this->assertEquals("9 accounts", plural(9, "account", "accounts"));
     $this->assertEquals("1,000 accounts", plural(1000, "account", "accounts"));
     $this->assertEquals("9 addresses", plural(9, "account", "addresses"));
 }
Example #19
0
 public function __construct()
 {
     parent::__construct();
     $this->load->database();
     $this->load->helper('inflector');
     if (!$this->table_name) {
         $this->table_name = strtolower(plural(get_class($this)));
     }
 }
Example #20
0
 /**
  * ะ˜ะฝะธั†ะธะฐะปะธะทะฐั†ะธั ะฟะพ ัƒะผะพะปั‡ะฐะฝะธัŽ ะฟั€ะธ ะทะฐะณั€ัƒะทะบะต
  *
  * @param string $name	ะฝะฐะทะฒะฐะฝะธะต ั‚ะฐะฑะปะธั†ั‹
  */
 public function set_table($name = '')
 {
     if (empty($name)) {
         $name = get_class($this);
     }
     if (empty($this->table) or $name == 'MY_Model') {
         $this->table = plural(str_ireplace('_mod', '', $name));
     }
 }
Example #21
0
 public function up()
 {
     $this->dbforge->modify_column('blog', array('comments_enabled' => array('type' => 'set', 'constraint' => array('no', '1 day', '1 week', '2 weeks', '1 month', '3 months', 'always'), 'null' => false, 'default' => 'always')));
     $this->db->update('blog', array('comments_enabled' => '3 months'));
     // Lets update the comments table with these new awesome fields
     $this->dbforge->modify_column('comments', array('module_id' => array('name' => 'entry_id', 'type' => 'varchar', 'constraint' => 255, 'null' => true), 'name' => array('name' => 'user_name', 'type' => 'varchar', 'constraint' => 255), 'email' => array('name' => 'user_email', 'type' => 'varchar', 'constraint' => 255), 'website' => array('name' => 'user_website', 'type' => 'varchar', 'constraint' => 255, 'null' => true)));
     $this->dbforge->add_column('comments', array('entry_title' => array('type' => 'char', 'constraint' => 255, 'null' => false), 'entry_key' => array('type' => 'varchar', 'constraint' => 100, 'null' => false), 'entry_plural' => array('type' => 'varchar', 'constraint' => 100, 'null' => false), 'uri' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'cp_uri' => array('type' => 'varchar', 'constraint' => 255, 'null' => true)));
     $comments = $this->db->get('comments')->result();
     foreach ($comments as &$comment) {
         // What did they comment on
         switch ($comment->module) {
             case 'gallery':
                 $comment->module = plural($comment->module);
                 break;
             case 'gallery-image':
                 $comment->module = 'galleries';
                 $ci->load->model('galleries/gallery_image_m');
                 if ($item = $ci->gallery_image_m->get($comment->module_id)) {
                     continue 2;
                 }
                 break;
         }
         $this->load->model('addons/module_m');
         // Use the old comment logic to grab title names, then we can never have to use this junk again
         if (in_array($comment->module, array('blog', 'pages'))) {
             // Grab an item
             switch ($comment->module) {
                 case 'blog':
                     // Get this one article out of the db
                     $item = $this->db->get_where('blog', array('id' => $comment->entry_id))->row();
                     $comment->entry_title = $item->title;
                     $comment->uri = 'blog/' . date('Y/m', $item->created_on) . '/' . $item->slug;
                     $comment->entry_key = 'blog:post';
                     $comment->entry_plural = 'blog:posts';
                     $comment->cp_uri = 'admin/' . $comment->module . '/preview/' . $item->id;
                     break;
                 case 'pages':
                     // Get this one page out of the db
                     $item = $this->db->get_where('pages', array('id' => $comment->entry_id))->row();
                     $comment->entry_title = $item->title;
                     $comment->uri = $item->uri;
                     $comment->entry_key = 'pages:page';
                     $comment->entry_plural = 'pages:pages';
                     $comment->cp_uri = 'admin/' . $comment->module . '/preview/' . $item->id;
                     break;
             }
         } else {
             $comment->entry_title = $comment->module . ' #' . $comment->entry_id;
             $comment->entry_key = humanize(singular($comment->module));
             $comment->entry_plural = humanize(plural($comment->module));
         }
         // Save this comment again
         $this->db->where('id', $comment->id)->update('comments', $comment);
     }
 }
 function generate_navigation_entries($current_path_info = "./")
 {
     $DB_wsi = $this->load->database('ws_info', TRUE);
     $equipment_listed = false;
     $DB_wsi->not_like('entry', 'List of Available');
     $DB_wsi->where("(`category_site_id` = {$this->site_id} or `category_site_id` = 0)");
     $DB_wsi->where("(`entry_site_id` = {$this->site_id} or `entry_site_id` = 0)");
     $where_array = array('enabled' => true, 'req_access_level <=' => $this->admin_access_level);
     if (ENVIRONMENT == 'production') {
         $where_array['dev_only'] = 0;
     }
     $query = $DB_wsi->get_where(NAV_INFO_TABLE, $where_array);
     $current_cat = false;
     $equipment_list = $this->get_equipment_types($this->site_id);
     $instrument_list = $this->get_scheduling_instrument_list($this->site_id);
     $nav_info = array();
     foreach ($query->result() as $row) {
         $current_uri = $row->uri;
         $current_uri = rtrim($current_uri, '/');
         if ($current_uri == rtrim($current_path_info, '/')) {
             $current_page_info = array('name' => $row->entry, 'uri' => $current_uri);
         }
         if ($current_cat != $row->category) {
             $current_cat = $row->category;
             $current_sorting_index = 'category_' . $row->category_display_order;
             $nav_info[$current_sorting_index] = array('name' => $current_cat, 'entries' => array());
             if ($row->category_description != null) {
                 $nav_info[$current_sorting_index]['description'] = $row->description;
             }
         }
         $nav_info[$current_sorting_index]['entries']['entry_' . $row->category_display_order . "." . $row->entry_display_order] = array('name' => $row->entry, 'uri' => $current_uri, 'alt_text' => $row->alt_text);
         if ($current_cat == "Equipment / Software") {
             $new_display_order = $row->entry_display_order;
             foreach ($equipment_list as $equip_type => $equip_info) {
                 $desc_array = explode(" ", $equip_info['description']);
                 $last_word = plural(array_pop($desc_array));
                 array_push($desc_array, $last_word);
                 $equip_desc = implode(" ", $desc_array) . " [{$equip_info['counts']}]";
                 $new_display_order++;
                 $nav_info[$current_sorting_index]['entries']["entry_{$row->category_display_order}.{$new_display_order}"] = array('name' => "List of {$equip_desc}", 'uri' => "equipment/{$equip_type}", 'alt_text' => "");
             }
         }
         if ($current_cat == "Instrument Scheduling" && $row->entry == "Instrument List") {
             $new_display_order = $row->entry_display_order;
             foreach ($instrument_list as $inst_id => $inst_info) {
                 $new_display_order++;
                 $nav_info[$current_sorting_index]['entries']["entry_{$row->category_display_order}.{$new_display_order}"] = array('name' => "&nbsp;&mdash;&nbsp;&nbsp;{$inst_info['display_name']}", 'uri' => "scheduling/calendar/{$inst_info['short_name']}", 'alt_text' => "");
             }
         }
     }
     if (!isset($current_page_info)) {
         $current_page_info = array('name' => 'Undefined Page', 'uri' => $current_path_info);
     }
     return array('categories' => $nav_info, 'current_page_info' => $current_page_info);
 }
Example #23
0
 function get_option($lang = 'th')
 {
     $query = "SELECT id,name\n\t\t\t\t\tFROM {$this->table}\n\t\t\t\t\tWHERE module = '" . plural($this->parent['model']) . "'\n\t\t\t\t\tAND parents <> 0  \n\t\t\t\t\tORDER BY id asc";
     //$query = $this->query($query)->all_to_assoc('id','name');
     //return $query;
     $CI =& get_instance();
     $query = $CI->db->query($query);
     foreach ($query->result() as $item) {
         $option[$item->id] = lang_decode($item->name, $lang);
     }
     return $option;
 }
 /**
  * Start a new conversation.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Recipient Username of the recipient.
  */
 public function add($Recipient = '')
 {
     $this->permission('Conversations.Conversations.Add');
     $this->Form->setModel($this->ConversationModel);
     // Set recipient limit
     if (!checkPermission('Garden.Moderation.Manage') && c('Conversations.MaxRecipients')) {
         $this->addDefinition('MaxRecipients', c('Conversations.MaxRecipients'));
         $this->setData('MaxRecipients', c('Conversations.MaxRecipients'));
     }
     if ($this->Form->authenticatedPostBack()) {
         $RecipientUserIDs = array();
         $To = explode(',', $this->Form->getFormValue('To', ''));
         $UserModel = new UserModel();
         foreach ($To as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->getByUsername(trim($Name));
                 if (is_object($User)) {
                     $RecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         // Enforce MaxRecipients
         if (!$this->ConversationModel->addUserAllowed(0, count($RecipientUserIDs))) {
             // Reuse the Info message now as an error.
             $this->Form->addError(sprintf(plural($this->data('MaxRecipients'), "You are limited to %s recipient.", "You are limited to %s recipients."), c('Conversations.MaxRecipients')));
         }
         $this->EventArguments['Recipients'] = $RecipientUserIDs;
         $this->fireEvent('BeforeAddConversation');
         $this->Form->setFormValue('RecipientUserID', $RecipientUserIDs);
         $ConversationID = $this->Form->save($this->ConversationMessageModel);
         if ($ConversationID !== false) {
             $Target = $this->Form->getFormValue('Target', 'messages/' . $ConversationID);
             $this->RedirectUrl = url($Target);
             $Conversation = $this->ConversationModel->getID($ConversationID, Gdn::session()->UserID);
             $NewMessageID = val('FirstMessageID', $Conversation);
             $this->EventArguments['MessageID'] = $NewMessageID;
             $this->fireEvent('AfterConversationSave');
         }
     } else {
         if ($Recipient != '') {
             $this->Form->setValue('To', $Recipient);
         }
     }
     if ($Target = Gdn::request()->get('Target')) {
         $this->Form->addHidden('Target', $Target);
     }
     Gdn_Theme::section('PostConversation');
     $this->title(t('New Conversation'));
     $this->setData('Breadcrumbs', array(array('Name' => t('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->data('Title'), 'Url' => 'messages/add')));
     $this->CssClass = 'NoPanel';
     $this->render();
 }
Example #25
0
 public function index()
 {
     $this->document->setTitle(tt('BitsyBay - Be Your Own Bitcoin Marketplace. Shop Directly.'), false);
     $this->document->setDescription(tt('BTC Marketplace for royalty-free photos, arts, templates, codes, books and other digital creative with BitCoin. Only quality and legal content from them authors. Buy with Bitcoin. Sell online. Open your own virtual store.'));
     $this->document->setKeywords(tt('bitsybay, bitcoin, btc, indie, marketplace, store, buy, sell, royalty-free, photos, arts, illustrations, 3d, templates, codes, extensions, books, content, digital, creative, quality, legal'));
     $this->document->addLink($this->url->link('common/home'), 'canonical');
     if ($this->auth->isLogged()) {
         $data['title'] = sprintf(tt('Welcome, %s!'), $this->auth->getUsername());
         $data['user_is_logged'] = true;
     } else {
         $data['title'] = tt('Welcome to the BitsyBay store!');
         $data['user_is_logged'] = false;
     }
     // Show SEO description for guests (and search engines)
     if (!$this->auth->isLogged()) {
         // Get tags
         $tags = array();
         foreach ($this->model_catalog_tag->getTags(array('limit' => 15, 'order' => 'RAND()'), $this->language->getId()) as $category_tag) {
             $tags[$category_tag->name] = $category_tag->name;
         }
         // Get active categories
         $categories = array();
         foreach ($this->model_catalog_category->getCategories(null, $this->language->getId()) as $category) {
             $categories[$category->title] = mb_strtolower($category->title);
             // Get child categories
             foreach ($this->model_catalog_category->getCategories($category->category_id, $this->language->getId(), true) as $child_category) {
                 if ($child_category->total_products) {
                     $categories[$child_category->title] = mb_strtolower($child_category->title);
                 }
             }
         }
         $data['description'] = sprintf(tt('%s is a simple and minimalistic marketplace to help you buy and or sell creative digital products with cryptocurrency like BitCoin. %s provides only high-quality offers from verified authors. It\'s include a BTC marketplace for %s about %s. Buy or sell original content with Bitcoin fast, directly and safely from any country without compromises!'), PROJECT_NAME, PROJECT_NAME, implode(', ', $categories), implode(', ', $tags));
     } else {
         $data['description'] = false;
     }
     $total_products = $this->model_catalog_product->getTotalProducts(array());
     $data['total_products'] = sprintf(tt('%s %s'), $total_products, plural($total_products, array(tt('original high-quality offer'), tt('original high-quality offers'), tt('original high-quality offers '))));
     $total_categories = $this->model_catalog_category->getTotalCategories();
     $data['total_categories'] = sprintf(tt('%s %s'), $total_categories, plural($total_categories, array(tt('category'), tt('categories'), tt('categories '))));
     $total_sellers = $this->model_account_user->getTotalSellers();
     $data['total_sellers'] = sprintf(tt('%s %s'), $total_sellers, plural($total_sellers, array(tt('verified seller'), tt('verified sellers'), tt('verified sellers '))));
     $total_buyers = $this->model_account_user->getTotalUsers();
     $data['total_buyers'] = sprintf(tt('%s %s'), $total_buyers, plural($total_buyers, array(tt('buyer'), tt('buyers'), tt('buyers '))));
     $redirect = urlencode($this->url->getCurrentLink());
     $data['login_action'] = $this->url->link('account/account/login', 'redirect=' . $redirect);
     $data['href_account_create'] = $this->url->link('account/account/create', 'redirect=' . $redirect);
     $data['module_search'] = $this->load->controller('module/search', array('class' => 'col-lg-8 col-lg-offset-2'));
     $data['module_latest'] = $this->load->controller('module/latest', array('limit' => 4));
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $this->response->setOutput($this->load->view('common/home.tpl', $data));
 }
Example #26
0
 function get($identifier, $default = '', array $values = array())
 {
     $locales = container();
     $translation = $default;
     if (isset($locales[$identifier])) {
         if (is_array($locales[$identifier])) {
             $translation = plural($identifier, $default, $values);
         } else {
             $translation = $locales[$identifier];
         }
     }
     return $translation;
 }
 public function toString()
 {
     $users = Gdn::UserModel()->GetIDs($this->getBirthdays());
     if (!$users) {
         return;
     }
     $return = '<div class="Box BirthdayModule"><h4>' . plural(count($users), T("Today's Birthday"), T("Today's Birthdays")) . '</h4><p>';
     foreach ($users as $user) {
         $return .= userPhoto($user, 'Medium') . ' ';
     }
     $return .= '</p></div>';
     return $return;
 }
Example #28
0
function modelsToTableNames()
{
    if ($handle = opendir(APPPATH . 'models/')) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != ".svn" && !eregi('model', $file)) {
                $aParts = explode(".", $file);
                $aOut[$aParts[0]] = ucfirst(plural($aParts[0]));
            }
        }
        closedir($handle);
    }
    return $aOut;
}
 public function packageCliAction($path = null)
 {
     $this->load->helper('inflector');
     if (!$path) {
         show_error('Please provide path');
     }
     $path = implode('/', func_get_args());
     $path = '/' . strtolower(trim($path, '/'));
     $dir = dirname($path);
     $filename = basename($path);
     $root = ROOTPATH . '/packages/' . $filename;
     mkdir($root);
     touch($root . '/composer.json');
     mkdir($root . '/public');
     mkdir($root . '/support');
     mkdir($root . '/support/migrations');
     touch($root . '/support/onload.php');
     touch($root . '/support/migrations/v1.0.0-' . $filename . '.php');
     mkdir($root . '/controllers');
     mkdir($root . '/controllers/' . $dir, 0777, true);
     touch($root . '/controllers/' . $dir . '/' . ucfirst($filename) . 'Controller.php');
     mkdir($root . '/helpers');
     mkdir($root . '/language');
     mkdir($root . '/libraries');
     mkdir($root . '/models');
     touch($root . '/models/' . ucfirst($filename) . '_model.php');
     mkdir($root . '/views');
     mkdir($root . '/views/' . $path, 0777, true);
     touch($root . '/views/' . $path . '/index.php');
     touch($root . '/views/' . $path . '/form.php');
     $data = [];
     $this->model($filename, $data);
     $this->view($filename, $data);
     $data['controller'] = ucfirst(strtolower(str_replace('-', '_', $filename)));
     $data['uname'] = ucfirst(strtolower($filename));
     $data['lname'] = strtolower($filename);
     $data['path'] = trim($path, '/');
     $data['model'] = $filename . '_model';
     $data['single'] = singular($filename);
     $data['plural'] = plural($filename);
     $data['name'] = strtolower($filename);
     //var_dump($data);
     file_put_contents($root . '/views/' . $path . '/index.php', $this->merge('index', $data));
     file_put_contents($root . '/views/' . $path . '/form.php', $this->merge('form', $data));
     file_put_contents($root . '/controllers/' . $dir . '/' . ucfirst($filename) . 'Controller.php', $this->merge('controller', $data));
     file_put_contents($root . '/models/' . ucfirst($filename) . '_model.php', $this->merge('model', $data));
     file_put_contents($root . '/support/migrations/v1.0.0-' . $filename . '.php', $this->merge('migration', $data));
     file_put_contents($root . '/composer.json', $this->merge('composer', $data));
 }
Example #30
0
 public function index($settings)
 {
     // Init variables
     $data = array();
     $filter_data = array();
     if (isset($settings['limit'])) {
         $filter_data = array('limit' => $settings['limit'], 'order' => 'DESC');
     }
     $product_data = $this->model_catalog_product->getProducts($filter_data, $this->language->getId(), $this->auth->getId(), ORDER_APPROVED_STATUS_ID);
     $data['products'] = array();
     foreach ($product_data as $product_info) {
         // Prepare special counter
         if ($product_info->special_date_end) {
             $special_left_seconds = strtotime($product_info->special_date_end) - time();
             $special_left_minutes = floor($special_left_seconds / 60);
             $special_left_hours = floor($special_left_minutes / 60);
             $special_left_days = floor($special_left_hours / 24);
             if ($special_left_minutes < 60) {
                 $special_expires = sprintf(tt('%s %s left'), $special_left_minutes, plural($special_left_minutes, array(tt('minute'), tt('minutes'), tt('minutes'))));
             } else {
                 if ($special_left_hours < 24) {
                     $special_expires = sprintf(tt('%s %s left'), $special_left_hours, plural($special_left_hours, array(tt('hour'), tt('hours'), tt('hours'))));
                 } else {
                     $special_expires = sprintf(tt('%s %s left'), $special_left_days, plural($special_left_days, array(tt('day'), tt('days'), tt('days'))));
                 }
             }
         } else {
             $special_expires = false;
         }
         switch ($product_info->order_status_id) {
             case ORDER_APPROVED_STATUS_ID:
                 $product_order_status = 'approved';
                 break;
             case ORDER_PROCESSED_STATUS_ID:
                 $product_order_status = 'processed';
                 break;
             default:
                 $product_order_status = $product_info->user_id == $this->auth->getId() ? 'approved' : false;
         }
         // Generate products
         $data['products'][] = array('product_order_status' => $product_order_status, 'favorite' => $product_info->favorite, 'demo' => $product_info->main_product_demo_id ? true : false, 'product_id' => $product_info->product_id, 'title' => $product_info->title, 'favorites' => $product_info->favorites ? $product_info->favorites : false, 'status' => $product_info->status, 'src' => $this->cache->image($product_info->main_product_image_id, $product_info->user_id, 144, 144), 'href_view' => $this->url->link('catalog/product', 'product_id=' . $product_info->product_id), 'href_download' => $this->url->link('catalog/product/download', 'product_id=' . $product_info->product_id), 'href_demo' => $this->url->link('catalog/product/demo', 'product_demo_id=' . $product_info->main_product_demo_id), 'special_expires' => $special_expires, 'special_regular_price' => $product_info->special_regular_price > 0 ? $this->currency->format($product_info->special_regular_price, $product_info->currency_id) : 0, 'special_exclusive_price' => $product_info->special_exclusive_price > 0 ? $this->currency->format($product_info->special_exclusive_price, $product_info->currency_id) : 0, 'regular_price' => $this->currency->format($product_info->regular_price, $product_info->currency_id), 'exclusive_price' => $this->currency->format($product_info->exclusive_price, $product_info->currency_id), 'has_regular_price' => $product_info->regular_price > 0 ? true : false, 'has_exclusive_price' => $product_info->exclusive_price > 0 ? true : false, 'has_special_regular_price' => $product_info->special_regular_price > 0 ? true : false, 'has_special_exclusive_price' => $product_info->special_exclusive_price > 0 ? true : false);
     }
     $data['user_is_logged'] = $this->auth->isLogged();
     // Renter the template
     return $this->load->view('module/common/product_list.tpl', $data);
 }