addItem(__('Templates'), 'plugin.php?p=templator','index.php?pf=templator/icon.png', preg_match('/plugin.php\?p=templator(&.*)?$/',$_SERVER['REQUEST_URI']), $core->auth->check('contentadmin,templator',$core->blog->id)); $core->auth->setPermissionType('templator',__('manage templates')); if ($core->auth->check('templator,contentadmin',$core->blog->id)) { $core->addBehavior('adminPostFormSidebar',array('templatorBehaviors','adminPostFormSidebar')); $core->addBehavior('adminPageFormSidebar',array('templatorBehaviors','adminPostFormSidebar')); $core->addBehavior('adminAfterPostCreate',array('templatorBehaviors','adminBeforePostUpdate')); $core->addBehavior('adminBeforePostUpdate',array('templatorBehaviors','adminBeforePostUpdate')); $core->addBehavior('adminAfterPageCreate',array('templatorBehaviors','adminBeforePostUpdate')); $core->addBehavior('adminBeforePageUpdate',array('templatorBehaviors','adminBeforePostUpdate')); $core->addBehavior('adminPostsActionsCombo',array('templatorBehaviors','adminPostsActionsCombo')); $core->addBehavior('adminPostsActions',array('templatorBehaviors','adminPostsActions')); $core->addBehavior('adminPostsActionsContent',array('templatorBehaviors','adminPostsActionsContent')); $core->addBehavior('adminPagesActionsCombo',array('templatorBehaviors','adminPostsActionsCombo')); $core->addBehavior('adminPagesActions',array('templatorBehaviors','adminPostsActions')); $core->addBehavior('adminPagesActionsContent',array('templatorBehaviors','adminPostsActionsContent')); } class templatorBehaviors { public static function adminPostFormSidebar($post) { global $core; $tpl = array(' ' => ''); $tpl_post = array(); $selected = ''; foreach ($core->templator->tpl as $k => $v) { if (!preg_match('/^category-(.+)$/',$k)) { $tpl_post= array_merge($tpl_post, array($k => $k)); } } $tpl = array_merge($tpl,$tpl_post); if ($post) { $params['meta_type'] = 'template'; $params['post_id'] = $post->post_id; $post_meta = $core->meta->getMetadata($params); $selected = $post_meta->isEmpty()? '' : $post_meta->meta_id ; } echo '
'.form::combo('post_tpl',$tpl,$selected).'
'; } public static function adminBeforePostUpdate($cur,$post_id) { global $core; $post_id = (integer) $post_id; if (isset($_POST['post_tpl'])) { $tpl = $_POST['post_tpl']; $core->meta->delPostMeta($post_id,'template'); if (!empty($_POST['post_tpl'])) { $core->meta->setPostMeta($post_id,'template',$tpl); } } } public static function adminPostsActionsCombo($args) { $args[0][__('Appearance')] = array(__('Select the template') => 'tpl'); } public static function adminPostsActions($core,$posts,$action,$redir) { if ($action == 'tpl' && isset($_POST['post_tpl'])) { try { $tpl = $_POST['post_tpl']; while ($posts->fetch()) { $core->meta->delPostMeta($posts->post_id,'template'); if (!empty($_POST['post_tpl'])) { $core->meta->setPostMeta($posts->post_id,'template',$tpl); } } http::redirect($redir); } catch (Exception $e) { $core->error->add($e->getMessage()); } } } public static function adminPostsActionsContent($core,$action,$hidden_fields) { if ($action == 'tpl') { $tpl = array(' ' => ''); $tpl_post = array(); $selected = ''; foreach ($core->templator->tpl as $k => $v) { if (!preg_match('/^category-(.+)$/',$k) && !preg_match('/^list-(.+)$/',$k)) { $tpl_post= array_merge($tpl_post, array($k => $k)); } } $tpl = array_merge($tpl,$tpl_post); echo '

'.__('Select template for these entries').'

'. '
'. '

'. $hidden_fields. $core->formNonce(). form::hidden(array('action'),'tpl'). '

'. '
'; } } } ?>