public function beforeSave()
 {
     $roles = Rights::getAssignedRoles(Yii::app()->user->Id);
     // check for single role
     foreach ($roles as $role) {
         if ($role->name == 'Editor' or $role->name == 'Administrator' or $role->name == 'Superadmin') {
             $this->post_editor = Yii::app()->user->id;
         } else {
             $this->post_author = Yii::app()->user->id;
         }
     }
     if ($this->isNewRecord) {
         // jika record baru jalankan
         $this->post_created = date('Y-m-d H:i:s');
     }
     if ($this->post_name == '') {
         $this->post_name = 'No Title';
     }
     if ($this->post_link == '') {
         $this->post_link = $this->post_name;
     }
     if ($this->post_title == '') {
         $this->post_title = $this->post_name;
     }
     $this->post_type = $this->_type;
     $this->post_image = str_replace(Helper::rootImg('content'), '', $this->post_image);
     return parent::beforeSave();
 }
 public function beforeSave()
 {
     // create thumb with ext easyImage -> check components/helper and extensions/easyimage
     Helper::createThumb(array('thumbDir' => Helper::rootImg('content/.thumb'), 'imageDir' => Helper::rootImg('content'), 'image' => $this->photo, 'small' => array('width' => 100, 'height' => 100, 'type' => EasyImage::RESIZE_HEIGHT), 'medium' => array('width' => 300, 'height' => 150, 'type' => EasyImage::RESIZE_WIDTH), 'large' => array('width' => 600, 'height' => 350, 'type' => EasyImage::RESIZE_WIDTH)));
     $this->photo = str_replace(Helper::rootImg('content'), '', $this->photo);
     return parent::beforeSave();
 }
 public function beforeSave()
 {
     $this->images = str_replace(Helper::rootImg('content'), '', $this->images);
     $this->taxonomy = $this->_taxonomy;
     $this->name = Ucfirst($this->name);
     return true;
 }
 private function process($data, $model)
 {
     $setting = array();
     foreach ($data as $key) {
         $setting[$key] = $this->loadSetting($key);
         $model->{$key} = $setting[$key]->option_value;
     }
     if (isset($_POST['Form_API'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->attributes = $_POST['Form_API'];
             if ($model->validate()) {
                 foreach ($data as $key) {
                     $setting[$key]->option_value = str_replace(Helper::rootImg('content'), '', $_POST['Form_API'][$key]);
                     if (!$setting[$key]->save()) {
                         throw new Exception($setting[$key]->getError('value'));
                     }
                 }
                 $transaction->commit();
                 $message = "<strong>Well done!</strong> You successfully Update Settings";
                 Yii::app()->user->setFlash('info', $message);
                 $this->refresh();
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             $this->refresh();
         }
     }
 }
 public function beforeSave()
 {
     if ($this->parent != '' and $this->parent != 0) {
         $parent = $this->model()->resetScope()->findByPk((int) $this->parent);
         if ($this->slug == '') {
             $this->slug = $parent->slug . '-' . $this->name;
         } else {
             if ($this->isNewRecord) {
                 $this->slug = $parent->slug . '-' . $this->slug;
             } else {
                 $model = $this->model()->resetScope()->findByPk((int) $this->term_id);
                 if ($model->slug != $this->slug) {
                     $this->slug = $parent->slug . '-' . $this->slug;
                 }
             }
         }
     } else {
         if ($this->slug == '') {
             $this->slug = $this->name;
         }
     }
     $this->images = str_replace(Helper::rootImg('content'), '', $this->images);
     $this->taxonomy = $this->_taxonomy;
     $this->name = Ucfirst($this->name);
     return parent::beforeSave();
 }
 public function actionHeadermobile()
 {
     $model = new Form_Headers_Mobile();
     $setting = array();
     foreach (get_object_vars($model) as $key => $null) {
         $setting[$key] = $this->loadSetting($key);
         $model->{$key} = $setting[$key]->option_value;
     }
     if (isset($_POST['Form_Headers_Mobile'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->attributes = $_POST['Form_Headers_Mobile'];
             if ($model->validate()) {
                 foreach (get_object_vars($model) as $key => $null) {
                     $setting[$key]->option_value = str_replace(Helper::rootImg('content'), '', $_POST['Form_Headers_Mobile'][$key]);
                     if (!$setting[$key]->save()) {
                         throw new Exception($setting[$key]->getError('value'));
                     }
                 }
                 $transaction->commit();
                 $message = "<strong>Well done!</strong> You successfully Update Settings";
                 Yii::app()->user->setFlash('info', $message);
                 $this->refresh();
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             $this->refresh();
         }
     }
     $this->render('mobile', compact('model', 'data'));
 }
 protected function setWidget()
 {
     $child = get_called_class();
     include_once $child . '/models/model_' . $child . '.php';
     $modelClass = "model_{$child}";
     $model = new $modelClass();
     // set value of model property
     foreach (get_object_vars($model) as $property => $value) {
         if (isset($this->data[$property])) {
             $model->{$property} = $this->data[$property];
         }
     }
     // check if widget is isset and set attributes for validation
     if (isset($_POST[$this->param['ID'] . '-save'])) {
         $model->attributes = $_POST[$modelClass];
     }
     // check validation
     if (isset($_POST[$this->param['ID'] . '-save']) && $model->validate()) {
         // mulai transaksi
         $transaction = Yii::app()->db->beginTransaction();
         try {
             foreach ($_POST[$modelClass] as $field => $fd) {
                 $array["{$field}"] = $fd;
             }
             $array['last_update'] = date('Y-m-d H:i:s');
             if (isset($_POST['visibleOn'])) {
                 $array['visibleOn'] = $_POST['visibleOn'];
             }
             $model = Widget::model()->findByPk((int) $this->param['ID']);
             if ($model !== null) {
                 $model->description = serialize(str_replace(Helper::rootImg('content'), '', $array));
                 if ($model->save(false)) {
                     $transaction->commit();
                     $message = "<strong>Well done!</strong> You successfully Saving";
                     Yii::app()->user->setFlash('success', $message);
                     $this->controller->refresh();
                 } else {
                     Yii::app()->user->setFlash('error', "on error occured, please try again");
                 }
             } else {
                 Yii::app()->user->setFlash('error', "on error occured, please try again");
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             if (true == YII_DEBUG) {
                 Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             } else {
                 Yii::app()->user->setFlash('error', "on error occured, please try again");
             }
             // for production
             // $this->refresh();
         }
     } else {
         $this->render('_form', array('model' => $model, 'param' => $this->param, 'data' => $this->data));
     }
 }
 public function metaHead()
 {
     if ($this->favicon != '') {
         echo '<link rel="shortcut icon" href="' . Helper::rootImg('content', $this->favicon) . '" />';
     }
     echo '<link rel="canonical" href="' . Yii::app()->getBaseUrl(true) . Yii::app()->request->requestUri . '" />';
     if ($this->keyword != '') {
         echo '<meta name="keywords" content="' . $this->keyword . '" />';
     }
     if ($this->description != '') {
         echo '<meta name="description" content="' . $this->description . '" />';
     }
     if ($this->metaHead != '') {
         echo $this->metaHead;
     }
     echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
     echo '<meta http-equiv="imagetoolbar" content="no" />';
     echo '<meta name="language" content="Indonesia" />';
     echo '<meta name="generator" content="' . Yii::app()->params['system_name'] . '"/>';
     echo '<meta name="revisit-after" content="7" />';
     echo '<meta name="webcrawlers" content="all" />';
     echo '<meta name="rating" content="general" />';
     echo '<meta name="spiders" content="all" />';
     echo '<meta http-equiv="refresh" content="900;url=' . Yii::app()->getBaseUrl(true) . Yii::app()->request->requestUri . '" />';
     echo '<link rel="alternate" type="application/rss+xml" title="' . $this->pageTitle . '" href="' . Yii::app()->createAbsoluteUrl('/rss/terbaru') . '" />';
     echo '<meta content="' . $this->pageTitle . '" name="title" />';
     echo '<meta name="robots" content="index,follow" />';
     echo '<meta name="googlebot" content="all" />';
     echo '<meta  property="fb:app_id" content="1403183346590415" />';
     echo '<meta property="og:site_name" content="' . Yii::app()->params['system_name'] . '" />';
     echo '<meta property="og:title" content="' . $this->pageTitle . '" />';
     echo '<meta property="og:type" content="article" />';
     if ($this->image != '') {
         echo '<meta property="og:image" content="' . $this->image . '" />';
     }
     echo '<meta property="og:url" content="' . Yii::app()->getBaseUrl(true) . Yii::app()->request->requestUri . '" />';
     if ($this->description != '') {
         echo '<meta property="og:description" content="' . $this->description . '" />';
     }
 }
// count jika record baru = 1 jika bukan ambil dari count $model->photometa
$updateCount = $model->isNewRecord ? 1 : count($model->photometa);
// total photo di ambil dari hasil GET maupun dari updateCount
$photos = isset($_GET['photos']) ? (int) $_GET['photos'] : $updateCount;
$photos = $photos > 50 ? 49 : $photos;
$photos = $photos == '' ? 1 : $photos;
// box mulai
$this->beginWidget('bootstrap.widgets.TbBox', array('title' => $photos . ' Photos'));
// membuat function untuk set nilai value
function setupValue($model, $loop, $keyVal)
{
    $updateValue = $model->isNewRecord ? '' : isset($model->photometa[$loop]->{$keyVal}) ? $model->photometa[$loop]->{$keyVal} : '';
    return isset($_POST['Photometa'][$loop][$keyVal]) ? $_POST['Photometa'][$loop][$keyVal] : $updateValue;
}
// mulai looping
for ($i = 0; $i < $photos; $i++) {
    // set value untuk widget hasil custom elfinder "CustomArrayServerFileInput" untuk property photo
    $valuePhoto = setupValue($model, $i, 'photo');
    echo "<div class='well'>";
    // elfinder serverfileinput hasil "custom"
    $this->widget('CustomArrayServerFileInput', array('name' => "Photometa[{$i}][photo]", 'value' => $valuePhoto, 'connectorRoute' => $this->moduleName() . '/elfinder/connector/', 'htmlOptions' => array('height' => 30, 'id' => $i . 'photos'), 'buttonOptions' => array('label' => '<i class="fa fa-camera"></i> Upload Gambar', 'class' => 'btn btn-primary'), 'customSet' => array('imageOptions' => array('style' => 'max-width:100%;'), 'rootImg' => Helper::rootImg('content'))));
    echo "<br>";
    // set value untuk property credit_photo
    $valuePhotoCredit = setupValue($model, $i, 'photo_credit');
    // textarea field
    echo CHtml::textArea("Photometa[{$i}][photo_credit]", $valuePhotoCredit, array('class' => 'span12', 'placeholder' => 'Keterangan'));
    echo "</div>";
    // end loop
}
// box berakhir
$this->endWidget();
<?php

$htmlLink = array_merge($htmlOptions, array('href' => $this->data('header_link')));
echo CHtml::openTag("a", $htmlLink);
if ($this->data('header_images') != '') {
    echo CHtml::Image(Helper::rootImg('content', $this->data('header_images')), $this->data('header_alt'), array('title' => $this->data('header_title'), 'width' => $this->data('header_width'), 'height' => $this->data('header_height'), 'style' => $this->data('header_style')));
} else {
    echo "<h1>" . $this->data('header_title') . "</h1>";
}
echo CHtml::closeTag("a");
echo $form->textFieldRow($model, 'name', array('class' => 'span12'));
?>
	<p class='muted'>Nama yang akan Tampil.</p><hr>
	
	<?php 
echo $form->textFieldRow($model, 'slug', array('class' => 'span12'));
?>
	<p class=' muted'>'slug' adalah versi URL dari nama.
Dalam hal ini berupa huruf kecil semua dan hanya mengandung huruf,
angka, dan tanda (-). <br>(Jika Kosong maka akan di isi otomatis.)</p><hr>
	
            <?php 
echo $form->textAreaRow($model, 'description', array('class' => 'span12', 'rows' => '3'));
?>
        <hr>
	
        Image
        <?php 
$this->widget('CustomServerFileInput', array('model' => $model, 'attribute' => 'images', 'connectorRoute' => $this->moduleName() . '/elfinder/connector', 'htmlOptions' => array('height' => 30), 'buttonOptions' => array('label' => 'Upload Gambar', 'class' => 'btn'), 'customSet' => array('modelName' => 'Tag', 'modelVal' => $model->images, 'rootImg' => Helper::rootImg('content'))));
?>
  
	 
	<hr>
	<?php 
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => $model->isNewRecord ? 'info' : 'warning', 'label' => $model->isNewRecord ? 'Buat' : 'Ubah', 'loadingText' => 'Mohon Tunggu'));
?>
        <hr>
 
	 
	<?php 
$this->endWidget();
echo $form->textFieldRow($model, "header_alt", array('class' => 'span6', 'placeholder' => 'Alt image'));
echo $form->textFieldRow($model, "header_link", array('class' => 'span6', 'placeholder' => 'http://'));
echo $form->textAreaRow($model, "header_style", array('class' => 'span9', 'placeholder' => ''));
?>
 
</div></div>
<hr>


<div class='row-fluid'>
<div class='span2'>
<b>Favicon</b>	
</div>
<div class='span10'>
   <?php 
$this->widget('CustomServerFileInput', array('model' => $model, 'attribute' => 'header_favicon', 'connectorRoute' => $this->moduleName() . '/elfinder/connector', 'htmlOptions' => array('height' => 30), 'buttonOptions' => array('label' => '<i class="fa fa-camera"></i> Favicon', 'class' => 'btn btn-primary'), 'customSet' => array('modelName' => 'Form_Headers', 'modelVal' => $model->header_favicon, 'rootImg' => Helper::rootImg('content'))));
?>
<hr>	
<p class='muted'>Ukuran terbaik adalah 50px x 50px px dan tipe file adalah png/jpg/ico</p>
</div></div> 
 
 
<hr>
	<?php 
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'info', 'label' => 'Simpan'));
?>
</div>
</div> <!--end row-->

<?php 
$this->endWidget();
<?php

/* start box Categories */
$this->beginWidget('bootstrap.widgets.TbBox', array('title' => 'Gambar', 'headerIcon' => 'icon-eye-open'));
?>

  <?php 
$this->widget('CustomServerFileInput', array('model' => $model, 'attribute' => 'post_image', 'connectorRoute' => $this->moduleName() . '/elfinder/connector/', 'htmlOptions' => array('height' => 30), 'buttonOptions' => array('label' => 'Upload Gambar', 'class' => 'btn'), 'customSet' => array('modelName' => 'Post', 'modelVal' => $model->post_image, 'imageOptions' => array('style' => 'max-width:100%;margin-top:-10px;'), 'rootImg' => Helper::rootImg('content'))));
?>
 <br>
 
<hr>
<?php 
echo $form->textFieldRow($model, 'post_image_by');
echo $form->textAreaRow($model, 'post_image_credit', array('style' => 'height:50px;', 'class' => 'span12', 'placeholder' => 'Keterangan Gambar'));
?>

<?php 
/* end box Categories */
$this->endWidget();
 protected function process($model)
 {
     if (isset($_POST[$this->_model])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->attributes = $_POST[$this->_model];
             if ($model->save()) {
                 // create thumb with ext easyImage -> check components/helper and extensions/easyimage
                 Helper::createThumb(array('thumbDir' => Helper::rootImg('content/.thumb'), 'imageDir' => Helper::rootImg('content'), 'image' => $model->images, 'small' => array('type' => EasyImage::RESIZE_HEIGHT), 'medium' => array()));
                 $transaction->commit();
                 $message = "Well done! - You successfully";
                 Yii::app()->user->setFlash('info', $message);
                 $this->redirect(array('admin'));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
         }
     }
 }
<?php

if ($this->data('header_images') != '') {
    echo CHtml::Image(Helper::rootImg('content', $this->data('header_images')), $this->data('header_alt'), array('title' => $this->data('header_title'), 'width' => '100%'));
    echo "<hr>";
} else {
    echo "<h3>" . $this->data('header_title') . "</h3><hr>";
}
        <h4 class='modal-title'><?php 
    echo $this->data('title');
    ?>
</h4>
        <?php 
}
?>
      </div>
    <div class="modal-body">
  
        <?php 
if ($this->data('images') != '') {
    ?>
      <center>
<?php 
    $img = CHtml::Image(Helper::rootImg('content', $this->data('images')), '', array('width' => '100%'));
    echo CHtml::Link($img, $this->data('linkImage'));
    ?>
</center> 
 <?php 
} else {
    ?>
 <?php 
    echo $this->data('textIfImagesEmpty');
    ?>
 <?php 
}
?>
      </div>
    
    </div><!-- /.modal-content -->
<div class='widget widget_images'>
<center>
<?php 
$img = CHtml::Image(Helper::rootImg('content', $this->data('images')), $this->data('alt'), $this->align());
echo CHtml::Link($img, $this->data('link'));
?>
</center> 
</div>
<?php

$this->breadcumbs();
?>
	
 <h3>View slide #<?php 
echo $model->name;
?>
</h3>
 <?php 
$this->alert();
?>


<?php 
$this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'type' => 'bordered', 'attributes' => array('name', 'slug', 'sort', 'groups', 'description', array('name' => 'images', 'type' => 'raw', 'value' => CHtml::image(Helper::rootImg('content', $model->images))))));
 private function process($post)
 {
     if (isset($_POST[$this->_model])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $post->attributes = $_POST[$this->_model];
             // UPDATE SET TIMER
             $date = $_POST[$this->_model]['post_modified']['year'] . '-';
             $date .= $_POST[$this->_model]['post_modified']['month'] . '-';
             $date .= $_POST[$this->_model]['post_modified']['day'] . ' ';
             $date .= $_POST[$this->_model]['post_modified']['hour'] . ':';
             $date .= $_POST[$this->_model]['post_modified']['minute'];
             $post->post_modified = $date;
             if ($post->save()) {
                 // create thumb with ext easyImage -> check components/helper and extensions/easyimage
                 Helper::createThumb(array('thumbDir' => Helper::rootImg('content/.thumb'), 'imageDir' => Helper::rootImg('content'), 'image' => $post->post_image, 'small' => array('width' => 100, 'height' => 100, 'type' => EasyImage::RESIZE_HEIGHT), 'medium' => array('width' => 300, 'height' => 150, 'type' => EasyImage::RESIZE_WIDTH), 'large' => array('width' => 600, 'height' => 350, 'type' => EasyImage::RESIZE_WIDTH)));
                 $this->processTerm($post);
                 // oke sukses gan, langsung di commit !!!
                 $transaction->commit();
                 Yii::app()->user->setFlash('info', "<strong>Well done!</strong> You successfully ");
                 $this->redirect(array('view', 'id' => $post->ID));
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
         }
     }
 }
<?php

$form = $this->getFormBegin();
$this->getVisible();
?>
    <p class="help-block">Fields with <span class="required">*</span> are required.</p>
 
  
       Images<span class="required">*</span>
        <?php 
$this->widget('CustomServerFileInput', array('model' => $model, 'attribute' => 'images', 'connectorRoute' => 'appback/elfinder/connector', 'htmlOptions' => array('height' => 30, 'style' => 'margin-left:-20px;', 'id' => $this->param['ID']), 'buttonOptions' => array('label' => 'Setup Image', 'class' => 'btn btn-success'), 'customSet' => array('modelName' => 'model_widget_images', 'modelVal' => $this->data['images'], 'rootImg' => Helper::rootImg('content'))));
?>
  
        <?php 
echo $form->error($model, 'images');
?>
        <hr>
            
    
<?php 
echo CHtml::link('Setup', '#', array('class' => 'setup-' . $this->param['ID'] . ' btn'));
?>
<span class='setup-hide-<?php 
echo $this->param['ID'];
?>
 hide' style='display:none;'><hr>
       <?php 
echo $form->textFieldRow($model, 'link', array('placeholder' => 'http://'));
?>
       <?php 
echo $form->textFieldRow($model, 'width', array('placeholder' => 'auto'));
<?php

$this->breadcumbs();
?>
<h3>Lihat : <?php 
echo $model->name;
?>
  </h3><hr>
<?php 
$this->alert();
?>

<?php 
$webUrl = Yii::app()->FrontUrl->createUrl('/tags/index/', array('id' => $model->term_id, 'slug' => $model->slug));
$mobileUrl = Yii::app()->FrontMobileUrl->createUrl('/tags/index/', array('id' => $model->term_id, 'slug' => $model->slug));
$link = "Web Url : " . $webUrl . " - " . CHtml::Link('Go to Link', $webUrl) . "<br>";
$link .= frontendMobileUrl == '' ? "" : "Mobile url : " . $mobileUrl . " - " . CHtml::Link('Go to Link', $mobileUrl);
$this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'type' => 'bordered striped', 'attributes' => array('name', array('name' => 'slug', 'type' => 'raw', 'value' => $link), array('label' => 'Total Post', 'value' => count($model->postAll)), 'description', array('name' => 'images', 'type' => 'raw', 'value' => CHtml::image(Helper::rootImg('content', $model->images))))));
<small>
<b><?php 
echo $post->post_image_by;
?>
</b>
<?php 
echo $post->post_image_credit;
?>
</small> 



 
 
 <?php 
echo str_replace(Helper::rootImg('content'), frontendWebUrl . '/uploads/content/', $post->post_content);
?>
 
 
<?php 
if (count($post->categories) > 0) {
    echo "<hr>Kategori : ";
}
foreach ($post->categories as $tag) {
    echo CHtml::Link($tag->name, array('/category/index', 'id' => $tag->term_id, 'slug' => $tag->slug)) . ', ';
}
if (count($post->topics) > 0) {
    echo "<hr>Topik : ";
}
foreach ($post->topics as $topic) {
    echo CHtml::Link($topic->name, array('/topic/index', 'id' => $topic->term_id, 'slug' => $topic->slug)) . ", ";