/**
 * Smarty {getchromemenu} function plugin
 *
 * Type:     function<br>
 * Name:     getchromemenu<br>
 * Purpose:  display the chrome menu
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_getchromemenu($params, &$smarty)
{
    global $router, $user;
    $cloc = $smarty->getTemplateVars('__loc');
    $module = $params['module'];
    $list = '<ul class="container-menu">';
    $list .= '<li class="container-info">' . $module->action . ' / ' . str_replace($module->action . '_', '', $module->view) . '</li>';
    if (!empty($params['rank']) && expPermissions::check('order_modules', $cloc)) {
        $uplink = $router->makeLink(array('module' => 'containermodule', 'src' => $cloc->src, 'action' => 'order', 'a' => $params['rank'] - 2, 'b' => $params['rank'] - 1));
        $downlink = $router->makeLink(array('module' => 'containermodule', 'src' => $cloc->src, 'action' => 'order', 'a' => $params['rank'] - 1, 'b' => $params['rank']));
        if ($params['rank'] != 1) {
            //dont show this up arrow if it's the first module in a container
            $list .= '<li><a href="' . $uplink . '" class="mod-up">' . gt("Move Module Up") . '</a></li>';
        }
        if (!$params['last']) {
            //if this is the last module in a container don't show down arrow.
            $list .= '<li><a href="' . $downlink . '" class="mod-down">' . gt("Move Module Down") . '</a></li>';
        }
    }
    $rerank = $params['rerank'];
    if ($rerank == 'false') {
        $rerank = 0;
    } else {
        $rerank = 1;
    }
    if ($user->isAdmin()) {
        $userlink = $router->makeLink(array('module' => expModules::getControllerName($module->info['class']), 'src' => $module->info['source'], 'action' => 'userperms', '_common' => 1));
        $grouplink = $router->makeLink(array('module' => expModules::getControllerName($module->info['class']), 'src' => $module->info['source'], 'action' => 'groupperms', '_common' => 1));
        $list .= '<li><a href="' . $userlink . '" class="user">' . gt("User Permissions") . '</a></li>';
        $list .= '<li><a href="' . $grouplink . '" class="group">' . gt("Group Permissions") . '</a></li>';
    }
    if (!empty($module->id) && expPermissions::check('edit_module', $cloc) && $module->permissions['administrate'] == 1) {
        $editlink = $router->makeLink(array('module' => 'containermodule', 'id' => $module->id, 'action' => 'edit', 'src' => $module->info['source']));
        $list .= '<li><a href="' . $editlink . '" class="config-view">' . gt("Configure Action") . " &amp; " . gt("View") . '</a></li>';
    }
    if ($module->permissions['configure'] == 1) {
        if (expModules::controllerExists($module->info['class'])) {
            $configlink = $router->makeLink(array('module' => expModules::getControllerName($module->info['class']), 'src' => $module->info['source'], 'action' => 'configure', 'hcview' => $module->view));
            $list .= '<li><a href="' . $configlink . '" class="config-mod">' . gt("Configure Settings") . '</a></li>';
        } elseif ($module->info['hasConfig']) {
            $configlink = $router->makeLink(array('module' => $module->info['class'], 'src' => $module->info['source'], 'action' => 'configure', '_common' => 1));
            $list .= '<li><a href="' . $configlink . '" class="config-mod">' . gt("Configure Settings") . '</a></li>';
        }
    }
    if (!empty($module->id) && expPermissions::check('delete_module', $cloc)) {
        $deletelink = $router->makeLink(array('module' => 'containermodule', 'id' => $module->id, 'action' => 'delete', 'rerank' => $rerank));
        $list .= '<li><a href="' . $deletelink . '" class="delete" onclick="alert(\'' . gt("This content is being sent to the Recycle Bin to be recovered later if you wish.") . '\')">' . gt("Remove Module") . '</a></li>';
    }
    if (HELP_ACTIVE) {
        $helplink = help::makeHelpLink(expModules::getControllerName($module->info['class']));
        $list .= '<li><a href="' . $helplink . '" class="helplink" target="_blank">' . gt("Get Help") . '</a></li>';
    }
    $list .= '</ul>';
    expCSS::pushToHead(array("unique" => "container-chrome", "link" => PATH_RELATIVE . "framework/modules/container/assets/css/admin-container.css"));
    expJavascript::pushToFoot(array("unique" => 'container-chrome', "yui3mods" => 'node', "src" => PATH_RELATIVE . "framework/core/assets/js/exp-container.js"));
    echo $list;
}
Beispiel #2
0
 /**
  * update item in module
  */
 function update()
 {
     global $db;
     //check for and handle tags
     if (array_key_exists('expTag', $this->params) && !empty($this->params['expTag'])) {
         if (isset($this->params['id'])) {
             $db->delete('content_expTags', 'content_type="' . (!empty($this->params['content_type']) ? $this->params['content_type'] : $this->basemodel_name) . '" AND content_id=' . $this->params['id']);
         }
         $tags = explode(",", trim($this->params['expTag']));
         unset($this->params['expTag']);
         foreach ($tags as $tag) {
             if (!empty($tag)) {
                 $tag = strtolower(trim($tag));
                 $expTag = new expTag($tag);
                 if (empty($expTag->id)) {
                     $expTag->update(array('title' => $tag));
                 }
                 $this->params['expTag'][] = $expTag->id;
             }
         }
     }
     $modelname = $this->basemodel_name;
     $this->{$modelname}->update($this->params);
     $this->addContentToSearch($this->params);
     // check for eAlerts
     if (!empty($this->params['send_ealerts'])) {
         redirect_to(array('controller' => 'ealert', 'action' => 'send_confirm', 'model' => $modelname, 'id' => $this->{$modelname}->id, 'src' => $this->loc->src, 'orig_controller' => expModules::getControllerName($this->classname)));
     } else {
         expHistory::back();
     }
 }
Beispiel #3
0
 public static function makeHelpLink($module)
 {
     // make sure the module name is in the right format.
     $module = expModules::getControllerName($module);
     // figure out which version we're on
     $full_version = EXPONENT_VERSION_MAJOR . '.' . EXPONENT_VERSION_MINOR . '.' . EXPONENT_VERSION_REVISION . EXPONENT_VERSION_TYPE;
     $link = HELP_URL;
     $link .= 'docs';
     $link .= '/' . $full_version;
     $link .= '/' . $module;
     return $link;
 }
/**
 * Smarty {getcontrollername} modifier plugin
 *
 * Type:     modifier<br>
 * Name:     getcontrollername<br>
 * Purpose:  Return the module name for this module
 * 
 * @param string $str
 * @return string
 */
function smarty_modifier_getcontrollername($str)
{
    return expModules::getControllerName($str);
}
Beispiel #5
0
 public function beforeSave()
 {
     $this->module = expModules::getControllerName($this->module);
     parent::beforeSave();
 }
Beispiel #6
0
 public function setHistory($url_type, $params)
 {
     global $router;
     // if the history gets bigger than 10 then we will trim it.
     $size = empty($this->history[$url_type]) ? 0 : count($this->history[$url_type]);
     if ($size > 10) {
         array_shift($this->history[$url_type]);
         $size = $size - 1;
     }
     // if we're in an action, we'll only set history if the action we're trying to set
     // matches the action the we're in...otherwise if we're on a page we check to make sure
     // the page we're trying to set isn't the same as the last one we just set.  This will keep
     // page refreshes the controllers on the same page from loading up the viewable array with a
     // bunch of identical entries
     $url = '';
     if (stristr($router->current_url, 'EXPONENT.')) {
         return false;
     }
     if (expTheme::inAction()) {
         // we don't want to save history for these action...it screws up the flow when logging in
         if (!isset($router->params['action']) || $router->params['action'] == 'loginredirect' || $router->params['action'] == 'logout') {
             return false;
         }
         // figure out the module/controller names
         $router_name = isset($router->params['controller']) ? $router->params['controller'] : $router->params['module'];
         $params_name = isset($params['controller']) ? $params['controller'] : $params['module'];
         // make sure the controller action is the one specified via the URL
         if (expModules::getControllerName($router_name) == expModules::getControllerName($params_name) && $router->params['action'] == $params['action']) {
             $url = array('url_type' => $router->url_type, 'params' => $router->params);
         }
     } else {
         //if we hit here it should be a page, not an action
         $url = array('url_type' => $router->url_type, 'params' => $router->params);
     }
     if (!empty($url)) {
         $diff = array();
         // if this url is the exact same as the last for this type we won't save it..that way refresh won't fill up our history
         if ($size > 0) {
             $diff = array_diff_assoc($router->params, $this->history[$url_type][$size - 1]['params']);
         }
         if (!empty($diff) || $size == 0) {
             $this->history[$url_type][] = $url;
         }
         // save the "lasts" information
         $this->history['lasts']['type'] = $url_type;
         if ($url_type != 'editable') {
             $this->history['lasts']['not_editable'] = $url_type;
         }
     }
     expSession::set('history', $this->history);
 }
Beispiel #7
0
 static function spiderContent($item = null)
 {
     global $db;
     //global $sections;
     global $router;
     $db->delete('search', "ref_module='navigationmodule' AND ref_type='section'");
     // this now ensures we get internal pages, instead of relying on the global $sections, which does not.
     $sections = $db->selectObjects('section', '1');
     foreach ($sections as $section) {
         $search = null;
         $search->category = 'Webpages';
         $search->ref_module = 'navigationmodule';
         $search->ref_type = 'section';
         $search->original_id = $section->id;
         $search->title = $section->name;
         //$search->view_link = $router->buildUrlByPageId($section->id);
         $link = str_replace(URL_FULL, '', makeLink(array('section' => $section->id)));
         $search->view_link = $link;
         $search->body = $section->description;
         $search->keywords = $section->keywords;
         // now we're going to grab all the textmodules on this page and build the body for the page based off the content
         // of all the text module added together.
         $modnames = array('text', 'textController');
         foreach ($modnames as $mod) {
             $loc->mod = expModules::getControllerName($mod);
             $controllername = expModules::getControllerClassName($mod);
             foreach ($db->selectObjects('sectionref', "module='" . $controllername . "' AND section=" . $section->id) as $module) {
                 $loc->src = $module->source;
                 $loc->int = '';
                 $controller = new $controllername();
                 $textitems = $db->selectObjects($controller->model_table, "location_data='" . serialize($loc) . "'");
                 foreach ($textitems as $textitem) {
                     if (!empty($textitem)) {
                         $search->body .= ' ' . search::removeHTML($textitem->body) . ' ';
                         $search->keywords .= " " . $textitem->title;
                     }
                 }
             }
         }
         $db->insertObject($search, 'search');
     }
     return true;
 }
Beispiel #8
0
/**
 * Smarty {icon} function plugin
 *
 * Type:     function<br>
 * Name:     icon<br>
 * Purpose:  create an icon type link
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_icon($params, &$smarty)
{
    $loc = $smarty->getTemplateVars('__loc');
    if (isset($params['record'])) {
        $record = $params['record'];
        $params['id'] = $record->id;
    }
    if ($record && empty($params['id'])) {
        $params['id'] = $record->id;
    }
    // setup the link params
    if (!isset($params['controller'])) {
        if (!isset($params['module'])) {
            $params['module'] = $loc->mod;
        }
        if (expModules::controllerExists($params['module'])) {
            $params['controller'] = expModules::getControllerName($params['module']);
            unset($params['module']);
        }
    }
    // guess the src if it is not set
    if (!isset($params['src'])) {
        if ($record) {
            $modloc = expUnserialize($record->location_data);
            $params['src'] = $modloc->src;
        } else {
            if (!empty($params['controller']) || @call_user_func(array($loc->mod, 'hasSources'))) {
                $params['src'] = $loc->src;
            }
        }
    }
    if (!is_object($smarty->getTemplateVars('config')) && !empty($smarty->getTemplateVars('config')->noeditagg) && $smarty->getTemplateVars('__loc')->src != $params['src']) {
        return;
    }
    if (!isset($params['int'])) {
        $params['int'] = $loc->int;
    }
    // attempt to translate the alt, text, & title
    if (!empty($params['alt'])) {
        $params['alt'] = gt($params['alt']);
    }
    if (!empty($params['text'])) {
        $params['text'] = gt($params['text']);
    }
    if (!empty($params['title'])) {
        $params['title'] = gt($params['title']);
    }
    // figure out whether to use the edit icon or text, alt tags, etc.
    $alt = empty($params['alt']) ? '' : $params['alt'];
    $class = empty($params['class']) && empty($params['img']) ? $params['action'] : $params['class'];
    $text = empty($params['text']) ? '' : $params['text'];
    $title = empty($params['title']) ? empty($text) ? ucfirst($class) . ' ' . gt('this') . ' ' . $smarty->getTemplateVars('modelname') . ' ' . gt('item') : $text : $params['title'];
    if (!empty($params['hash'])) {
        $hash = $params['hash'];
        unset($params['hash']);
    }
    if (empty($params['img']) && empty($params['text'])) {
        $img = gt(ucfirst($class));
    } else {
        if (!empty($params['img'])) {
            $img = '<img src="' . ICON_RELATIVE . $params['img'] . '" title="' . $title . '" alt="' . $alt . '"' . XHTML_CLOSING . '>';
        }
    }
    $linktext = $img . $text;
    // we need to unset these vars before we pass the params array off to makeLink
    unset($params['alt']);
    unset($params['title']);
    unset($params['text']);
    unset($params['img']);
    unset($params['class']);
    unset($params['record']);
    unset($params['record']);
    $onclick = $params['onclick'];
    unset($params['onclick']);
    //eDebug($params);
    if (!empty($params['action'])) {
        echo '<a href="' . expCore::makeLink($params) . '" title="' . $title . '" class="' . $class . '"';
        if ($params['action'] == "delete" && empty($onclick)) {
            echo ' onclick="return confirm(\'' . gt('Are you sure you want to delete this') . ' ' . $smarty->getTemplateVars('modelname') . ' ' . gt('item') . '?\');"';
        }
        if (!empty($onclick)) {
            echo ' onclick="' . $onclick . '"';
        }
        echo '>' . $linktext . '</a>';
    } else {
        echo $linktext;
    }
}
Beispiel #9
0
function renderAction(array $parms = array())
{
    global $user;
    //Get some info about the controller
    $baseControllerName = expModules::getControllerName($parms['controller']);
    $fullControllerName = expModules::getControllerClassName($parms['controller']);
    $controllerClass = new ReflectionClass($fullControllerName);
    // Figure out the action to use...if the specified action doesn't exist then
    // we look for the index action.
    if ($controllerClass->hasMethod($parms['action'])) {
        $action = $parms['action'];
        /* TODO:  Not sure if this needs to be here. FJD
        		$meth = $controllerClass->getMethod($action);
                if ($meth->isPrivate()) expQueue::flashAndFlow('error', 'The requested action could not be performed: Action not found');*/
    } elseif ($controllerClass->hasMethod('index')) {
        $action = 'index';
    } elseif ($controllerClass->hasMethod('showall')) {
        $action = 'showall';
    } else {
        expQueue::flashAndFlow('error', gt('The requested action could not be performed: Action not found'));
    }
    // initialize the controller.
    $src = isset($parms['src']) ? $parms['src'] : null;
    $controller = new $fullControllerName($src, $parms);
    //Set up the template to use for this action
    global $template;
    $view = !empty($parms['view']) ? $parms['view'] : $action;
    $template = get_template_for_action($controller, $view, $controller->loc);
    // have the controller assign knowledge about itself to the template.
    // this has to be done after the controller get the template for its actions
    $controller->moduleSelfAwareness();
    //if this controller is being called by a container then we should have a module title.
    if (isset($parms['moduletitle'])) {
        $template->assign('moduletitle', $parms['moduletitle']);
    }
    //setup some default models for this controller's actions to use
    foreach ($controller->getModels() as $model) {
        $controller->{$model} = new $model(null, false, false);
        //added null,false,false to reduce unnecessary queries. FJD
    }
    // add the $_REQUEST values to the controller <- pb: took this out and passed in the params to the controller constructor above
    //$controller->params = $parms;
    //check the perms for this action
    $perms = $controller->permissions();
    //we have to treat the update permission a little different..it's tied to the create/edit
    //permissions.  Really the only way this will fail will be if someone bypasses the perm check
    //on the edit form somehow..like a hacker trying to bypass the form and just submit straight to
    //the action. To safeguard, we'll catch if the action is update and change it either to create or
    //edit depending on whether an id param is passed to. that should be sufficient.
    $common_action = null;
    if ($parms['action'] == 'update') {
        $perm_action = !isset($parms['id']) || $parms['id'] == 0 ? 'create' : 'edit';
    } elseif ($parms['action'] == 'saveconfig') {
        $perm_action = 'configure';
    } else {
        // action convention for controllers that manage more than one model (datatype).
        // if you preface the name action name with a common crud action name we can check perms on
        // it with the developer needing to specify any...better safe than sorry.
        // i.e if the action is edit_mymodel it will be checked against the edit permission
        if (stristr($parms['action'], '_')) {
            $parts = explode("_", $parms['action']);
        }
        $common_action = isset($parts[0]) ? $parts[0] : null;
        $perm_action = $parms['action'];
    }
    if (array_key_exists($perm_action, $perms)) {
        if (!expPermissions::check($perm_action, $controller->loc)) {
            if (expTheme::inAction()) {
                flash('error', gt("You don't have permission to") . " " . $perms[$perm_action]);
                expHistory::returnTo('viewable');
            } else {
                return false;
            }
        }
    } elseif (array_key_exists($common_action, $perms)) {
        if (!expPermissions::check($common_action, $controller->loc)) {
            if (expTheme::inAction()) {
                flash('error', gt("You don't have permission to") . " " . $perms[$common_action]);
                expHistory::returnTo('viewable');
            } else {
                return false;
            }
        }
    } elseif (array_key_exists($perm_action, $controller->requires_login)) {
        // check if the action requires the user to be logged in
        if (!$user->isLoggedIn()) {
            $msg = empty($controller->requires_login[$perm_action]) ? gt("You must be logged in to perform this action") : $controller->requires_login[$perm_action];
            flash('error', $msg);
            expHistory::redirecto_login();
        }
    } elseif (array_key_exists($common_action, $controller->requires_login)) {
        // check if the action requires the user to be logged in
        if (!$user->isLoggedIn()) {
            $msg = empty($controller->requires_login[$common_action]) ? gt("You must be logged in to perform this action") : $controller->requires_login[$common_action];
            flash('error', $msg);
            expHistory::redirecto_login();
        }
    }
    // run the action
    $controller->{$action}();
    //register this controllers permissions to the view for in view perm checks
    $template->register_permissions(array_keys($perms), $controller->loc);
    // pass this controllers config off to the view
    $template->assign('config', $controller->config);
    // globalizing $user inside all templates
    $template->assign('user', $user);
    //assign the controllers basemodel to the view
    $template->assign('modelname', $controller->basemodel_name);
    if (empty($parms['no_output'])) {
        $template->output();
    } else {
        $html = $template->render();
        return $html;
    }
    //$html = $template->output();
    //return $html;
}