Example #1
0
 public function filter($value)
 {
     $ext = strrpos($value, '.');
     if ($ext !== false) {
         $t = substr($value, $ext + 1);
         $value = substr($value, 0, $ext);
         $ext = $t;
     }
     $stitle = Zkernel_Common::stitle($value, $this->_length);
     $p = '';
     while (file_exists($this->_directory . '/' . $stitle . $p . ($ext ? '.' . $ext : ''))) {
         $p = $p ? $p + 1 : 1;
     }
     return $stitle . $p . ($ext ? '.' . $ext : '');
 }
Example #2
0
 function overrideZappsimpleband(&$r, $options = array())
 {
     if (!is_array($options)) {
         $options = (array) $options;
     }
     $default = array('length' => 0, 'cut' => true, 'date' => 'word', 'route' => '');
     $options = array_merge($default, $options);
     $r->date_valid = Zkernel_Common::getDate($r->date, $options['date']);
     if ($options['route']) {
         $r->url_valid = $this->view->url(array('stitle' => $r->stitle), $options['route']);
     }
     $this->overridePage($r);
     if ($options['length']) {
         $r->cut_message = $this->view->textHelper()->truncate($r->message, $options['length'], $options['cut']);
     }
 }
Example #3
0
 public function overrideSingle($data, $type = null, $options = null)
 {
     $r = $data instanceof Zkernel_View_Data ? $data : new Zkernel_View_Data($data);
     $reg = Zend_Registry::isRegistered('Zkernel_Multilang') ? Zend_Registry::get('Zkernel_Multilang') : '';
     if ($reg && isset($reg->id)) {
         foreach ($r as $k => $v) {
             if (preg_match('/^ml\\_([^\\_]+)\\_' . $reg->id . '$/i', $k, $f)) {
                 if ($v === null && !@$options['multilang_nofall']) {
                     if (@$r->{'ml_' . $f[1] . '_' . $reg->_default->id} !== null) {
                         $r->{$f[1]} = $r->{'ml_' . $f[1] . '_' . $reg->_default->id};
                     }
                 } else {
                     $r->{$f[1]} = $v;
                 }
                 /*$r->{$f[1]} = $v === null && !@$options['multilang_nofall']
                 		? @$r->{'ml_'.$f[1].'_'.$reg->_default->id}
                 		: $v;*/
             }
         }
     }
     if (isset($r->title)) {
         $r->title_valid = htmlspecialchars($r->title);
     }
     if (isset($r->date)) {
         $r->date_valid = Zkernel_Common::getDate($r->date);
     }
     //if (isset($options['num'])) $r->_num = $options['num'];
     //исключение в пользовательском оверрайде в админке приводит к труднонаходимой ошибке,
     //поэтому добавил эту отладочную печать.
     try {
         if ($type !== null && method_exists($this, 'override' . ucfirst($type))) {
             $this->{'override' . ucfirst((string) $type)}($r, $options);
         }
     } catch (Zend_Exception $e) {
         if (APPLICATION_ENV == 'development') {
             echo $e->getMessage();
             echo $e->getTraceAsString();
             exit;
         }
     }
     return $r;
 }
Example #4
0
 public function preview($dir = null, $name, $param = array())
 {
     if (!$dir || !$name) {
         return @$param['default'];
     }
     $prefix = $param['prefix'] = @$param['prefix'] ? $param['prefix'] . '_' : '';
     $ext = strrpos($name, '.');
     $ext = $ext === false ? '' : @substr($name, $ext + 1);
     $ctype = 'image';
     if ($ext == 'flv' || $ext == 'avi' || $ext == '3gp' || $ext == 'wmv') {
         $ctype = 'video';
     }
     $modified_o = @filemtime(PUBLIC_PATH . '/upload/' . $dir . '/' . $name);
     if (!$modified_o) {
         return @$param['default'];
     }
     $png_name = @$param['corner'] && $ctype == 'image' ? preg_replace('/\\.(.+)$/', '.png', $name) : '';
     $param['new_name'] = $png_name;
     $cp = defined('CACHE_DIR') ? CACHE_DIR : 'pc';
     $dir_dest = @$param['cache_dir_folder'] ? $param['cache_dir_folder'] : $dir;
     $modified = @filemtime(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name));
     if ($modified < $modified_o) {
         if (!@file_exists(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest)) {
             mkdir(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, 0777, true);
         }
         if ($ctype == 'image') {
             $preview = new Zkernel_Image_Preview(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, PUBLIC_PATH . '/upload/' . $dir);
             $preview->create($name, $param);
         } else {
             if ($ctype == 'video') {
                 $preview = new Zkernel_Video_Preview(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest, PUBLIC_PATH . '/upload/' . $dir);
                 $preview->create($name, $param);
             }
         }
         @chmod(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . $name, 0777);
         @clearstatcache();
         $modified = @filemtime(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . $name);
     }
     $ret = $modified || @file_exists(PUBLIC_PATH . '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name)) ? '/' . $cp . '/' . $dir_dest . '/' . $prefix . @$param['crop'] . ($png_name ? $png_name : $name) . '?' . $modified : @$param['default'];
     return Zkernel_Common::gen_static_url($ret);
 }
Example #5
0
 function fetchControlList()
 {
     $data = array();
     $dir = Zend_Controller_Front::getInstance()->getControllerDirectory();
     $dir = @$dir['default'];
     $handle = @opendir($dir);
     while ($path = @readdir($handle)) {
         if (is_file($dir . '/' . $path)) {
             $n = $nn = strtolower(str_ireplace('Controller.php', '', $path));
             $c = ucfirst($n) . 'Controller';
             if (!class_exists($c)) {
                 include $dir . '/' . $path;
             }
             $db = Zkernel_Common::getDocblock($c);
             if (isset($db['zk_title'])) {
                 $nn = $db['zk_title'];
             }
             $model = file_exists($dir . '/../models/' . ucfirst($n) . '.php');
             $data[] = array('id' => $n, 'name' => $n, 'zk_title' => $nn);
         }
     }
     @closedir($handle);
     return new Zkernel_View_Data($data);
 }
Example #6
0
 static function getControllerDocblock($c = null)
 {
     $dbs = array();
     $controllers = $c ? array($c) : array();
     $dir = Zend_Controller_Front::getInstance()->getControllerDirectory();
     if (!$c) {
         $dir = @$dir['default'];
         $handle = @opendir($dir);
         while ($path = @readdir($handle)) {
             if (is_file($dir . '/' . $path)) {
                 $controllers[] = strtolower(str_ireplace('Controller.php', '', $path));
             }
         }
         @closedir($handle);
     }
     if ($controllers) {
         foreach ($controllers as $el) {
             $cc = ucfirst($el) . 'Controller';
             if (!class_exists($cc)) {
                 include $dir . '/' . $cc . '.php';
             }
             $dbs[$el] = Zkernel_Common::getDocblock($cc);
         }
     }
     if ($c) {
         $keys = array_keys($dbs);
         return @$dbs[$keys[0]];
     } else {
         return $dbs;
     }
 }
Example #7
0
 function linkSingle($name = null, $mtime = true)
 {
     $css = array();
     $i = (array) $this->getIterator();
     foreach ($i as $offset => $item) {
         if ($item->rel == 'stylesheet' && $item->type == 'text/css' && stripos($item->href, 'http://') === false) {
             $css[$item->media . '_' . $item->conditionalStylesheet] = isset($css[$item->media . '_' . $item->conditionalStylesheet]) ? $css[$item->media . '_' . $item->conditionalStylesheet] : array();
             $css[$item->media . '_' . $item->conditionalStylesheet][$offset] = $item;
             $this->offsetUnset($offset);
         }
     }
     if ($css) {
         $zp = defined('ZKERNEL_DIR') ? ZKERNEL_DIR : 'zkernel';
         $zpath = defined('ZKERNEL_PATH') ? ZKERNEL_PATH : realpath(PUBLIC_PATH . '/' . $zp);
         $cp = defined('CACHE_DIR') ? CACHE_DIR : 'pc';
         $m = '';
         foreach ($css as $media => $els) {
             $c = '';
             $items = array();
             foreach ($els as $item) {
                 $i = PUBLIC_PATH . $item->href;
                 $items[] = $i;
                 $m .= filesize($i) . filemtime($i);
             }
             $md5 = $name == null ? substr(md5($m), 0, 5) : $name;
             $nm = '/' . $cp . '/css/' . $md5 . '.css';
             $mod = false;
             $ex = file_exists(PUBLIC_PATH . $nm);
             if ($ex) {
                 $str = file_get_contents(PUBLIC_PATH . $nm);
                 preg_match('/\\/\\*\\ hash\\:\\ ([^\\ ]+)\\ \\*\\//si', $str, $res);
                 if ($res[1] != md5($m)) {
                     $mod = true;
                 }
             } else {
                 $mod = true;
             }
             if ($mod) {
                 foreach ($items as $k => $el) {
                     $dir_full = dirname($el);
                     $dir = str_ireplace(PUBLIC_PATH, '', $dir_full);
                     $str = $this->preprocessUtil(file_get_contents($el), $el);
                     $matches = $files = array();
                     preg_match_all('/url\\((\'|\\"|)(.*?)(\'|\\"|)\\)/si', $str, $res);
                     if (@$res[2]) {
                         foreach ($res[2] as $k_1 => $el_1) {
                             $matches[] = $res[0][$k_1];
                             $files[] = $el_1;
                         }
                     }
                     if ($files) {
                         foreach ($files as $k_1 => $el_1) {
                             if (stripos($el_1, 'http://') !== false || substr($el_1, 0, 1) == '/') {
                                 continue;
                             }
                             $su = realpath($dir_full . '/' . $el_1);
                             if (!$su) {
                                 continue;
                             }
                             $su = str_ireplace(array(PUBLIC_PATH, $zpath, '\\'), array('', '/' . $zp, '/'), $su);
                             $str = str_ireplace($matches[$k_1], 'url(' . Zkernel_Common::gen_static_url($su) . ($mtime ? '?' . filemtime($dir_full . '/' . $el_1) : '') . ')', $str);
                         }
                     }
                     $matches = $files = array();
                     preg_match_all('/src\\=(\'|\\"|)(.*?)(\'|\\"|\\,|\\))/si', $str, $res);
                     if (@$res[2]) {
                         foreach ($res[2] as $k_1 => $el_1) {
                             $matches[] = $res[0][$k_1];
                             $files[] = $el_1;
                         }
                     }
                     if ($files) {
                         foreach ($files as $k_1 => $el_1) {
                             if (stripos($el_1, 'http://') !== false || substr($el_1, 0, 1) == '/') {
                                 continue;
                             }
                             $su = realpath($dir_full . '/' . $el_1);
                             if (!$su) {
                                 continue;
                             }
                             $su = str_ireplace(array(PUBLIC_PATH, $zpath, '\\'), array('', '/zkernel', '/'), $su);
                             $str = str_ireplace($matches[$k_1], 'src="' . Zkernel_Common::gen_static_url($su) . ($mtime ? '?' . filemtime($dir_full . '/' . $el_1) : '') . '"', $str);
                         }
                     }
                     $c .= $str . "\n";
                 }
                 $c = trim($c);
                 if (!@file_exists(PUBLIC_PATH . '/' . $cp . '/css')) {
                     @mkdir(PUBLIC_PATH . '/' . $cp . '/css', 0777, true);
                     @chmod(PUBLIC_PATH . '/' . $cp . '/css', 0777);
                 }
                 $c = "/* hash: " . md5($m) . " */\n" . $this->view->minify($c, 'css');
                 file_put_contents(PUBLIC_PATH . $nm, $c);
                 @chmod(PUBLIC_PATH . $nm, 0777);
                 $config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
                 if (@$config['css']['static'] && function_exists('gzopen')) {
                     $zp1 = gzopen(PUBLIC_PATH . $nm . '.gz', 'wb9');
                     gzwrite($zp1, $c);
                     gzclose($zp1);
                     @chmod(PUBLIC_PATH . $nm . '.gz', 0777);
                 }
             }
             $media = explode('_', $media);
             $this->appendStylesheet($nm, $media[0], $media[1]);
         }
     }
     return $this->headLink();
 }
Example #8
0
                         $ap = $pp[0];
                         $k_1 = $pp[1];
                     } else {
                         $k_1 = $pp[0];
                     }
                     $inner[$n . '|' . ($is_route === false ? $k_1 : $ap . '|' . $k_1)] = $el_1;
                 }
             }
             break;
         }
     }
     if (!$exist) {
         foreach ($met as $el) {
             $db1 = Zkernel_Common::getDocblock($el, 'method');
             if (substr($el->name, -6) == 'Action') {
                 $db1 = Zkernel_Common::getDocblock($el, 'method');
                 if ($db1 && array_key_exists('zk_routable', $db1) && !(int) $db1['zk_routable']) {
                     continue;
                 }
                 if (!isset($db1['zk_title'])) {
                     continue;
                 }
                 $inner[$n . '|' . substr($el->name, 0, -6)] = $db1['zk_title'];
             }
         }
     }
 }
 if ($db && array_key_exists('zk_routable', $db) && !(int) $db['zk_routable']) {
     if ($inner) {
         $tt[$nn] = $inner;
     }
Example #9
0
 public function routeDelete()
 {
     $ids = $this->config->param['ids'];
     $ids = $ids ? explode(',', $ids) : array();
     if (!$ids) {
         $id = $this->config->param['id'];
         $ids = $id ? array($id) : array();
     }
     if ($this->config->tree && @$ids[0]) {
         $where = $this->config->where ? $this->config->where->toArray() : array();
         $where['`id` = ?'] = $ids[0];
         $pid = (string) $this->config->model->fetchOne($this->config->tree_field, $where);
         $s = new Zend_Session_Namespace();
         $s->control['history'][$this->config->controller]['oid'] = $pid;
     }
     $cnt = 0;
     if ($ids) {
         foreach ($ids as $el) {
             $where = $this->config->where ? $this->config->where->toArray() : array();
             $where['`id` = ?'] = $el;
             $data = $this->config->model->fetchControlCard($where);
             $data = $this->view->override()->overrideSingle($data, $this->config->controller, array('multilang_nofall' => true, 'module_nofall' => true));
             $this->config->data->set($data->toArray());
             $this->config->skip = false;
             $this->config->func_check;
             if (!$this->config->skip) {
                 if ($this->config->use_db) {
                     if ($this->config->delete_mode == 'db') {
                         $ok = $this->config->model->deleteControl($where);
                     } else {
                         $this->config->model->updateControl(array($this->config->delete_mode => 0), $where);
                         $ok = true;
                     }
                 } else {
                     $ok = true;
                 }
                 if ($ok) {
                     $form = $this->buildForm();
                     $els = $form->getElements();
                     if ($els) {
                         foreach ($els as $k => $v) {
                             if ($v->getType() == 'Zkernel_Form_Element_Uploadify') {
                                 if (isset($v->destination) && isset($this->config->data->{$k})) {
                                     @unlink($v->destination . '/' . $this->config->data->{$k});
                                 }
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
         if ($cnt) {
             $this->config->info[] = $this->config->control_lang_current['element_deleted'] . $cnt;
         }
     } else {
         $this->config->info[] = $this->config->control_lang_current['no_sel'];
     }
     if ($cnt) {
         $this->config->func_success;
         $this->view->inlineScript('script', 'c.go("' . $this->config->request_ok->controller . '", "' . $this->config->request_ok->action . '", ' . Zend_Json::encode(Zkernel_Common::url2array($this->config->request_ok->param)) . ');');
     } else {
         $this->config->stop_frame = true;
     }
     echo $this->view->render($this->config->view);
     return $this;
 }