Reputable weblinks php. Hacks and additions. How to make one position randomly show one of the modules assigned to it

I continue to share with you small but very useful site scripts that help improve the attitude of search engines towards your site. This time we will talk about proper page linking.

First, let's create a database of page addresses and possible anchors for each of them. We will use a *.txt file as a base. The file structure will be like this:

Page_address_1; anchor_1, anchor_2, anchor_3,..., anchor_n page_address_2; ​​anchor_1, anchor_2, anchor_3,..., anchor_n page_address_3; anchor_1, anchor_2, anchor_3,..., anchor_n ... page_address_n; anchor_1, anchor_2, anchor_3, ..., anchor_n

As you can see, further use of the script is possible with any number of page addresses and anchors for them. The page address is written without http://www.site.ru/, i.e. immediately from the root without the first slash. The address is separated from the anchors by a semicolon, and the anchors are separated by just a comma. You can also write the full address, it’s just more convenient for me personally, but you can change the filling and output of the result yourself, I think you will intuitively figure it out yourself.

And so, a database of links and anchors for them has been created, below I will give an example of PHP code for directly displaying links for linking on the site:

".$tex2[$tex3].""; } ?>

We paste this code anywhere on the site, which displays 5 random links from the database and a random anchor. It is better to dilute anchors, rather than write only 1 to the link. With proper linking on your website, you will immediately see an increase in traffic and an improvement in other website indicators.

I look forward to your questions in the comments to this post.

Date of publication: March 03, 2014
    Reviews and comments:

    Dmitriy:
    Thanks for the script, I will implement it. It is impossible to copy the source code from the site; it is copied only in small fragments; it would be more convenient in its entirety.

    Kirill:
    Thanks for the note about copying, I just saw it now, I’ll try to fix it soon.

    Alexey Pavlov:
    Error in the line $tex = explode(":",$sendlist[$count] You need a semicolon, not a colon. I changed the code a little to make it clearer:$anchor"; } ?>

    Matrk:
    The article is completely useless, because... The blog has text copy protection.

    Kirill:
    There is a small bug in js, yes, there is no time to fix it, but probably someone else is useless, since they are not smart enough, in this case, look at the source code of the page and take it from there

    Matrk:
    Those. Should I still go through the source code and clean it of all garbage? You're funny.

    Kirill:
    Does it mean I owe someone something? Did I take your money, are you trying here, giving free advice :))) Free cheese is only in a mousetrap, as you get older you will understand.

    Kirill:
    I removed the jamb, enjoy it for your health.

    Andrey Kopaev:
    1 - it’s probably better to do this using a mysql database, it will work faster, and it’s easier to add 2 - I don’t understand what’s the point of generating a list of links every time? How does this affect traffic growth? Is it possible to load using Ajax, i.e. is this for people or for bots?

    www.site:
    For promotion, though, I personally am not a supporter of such manipulations with the PS.

Let's start looking at the components by looking at how the basic Weblinks component operates in the admin portion of a website. This component, which is typical for this part of the website, is very similar to its other components designed to manage articles, users, modules, etc.

The program files for this component are listed below. All these files are located in the folder administator/components/com_weblinks. Throughout the rest of this chapter, all Weblinks component file names are referred to relative to this starting folder unless otherwise noted. Most of the files are organized according to the MVC pattern. Specifically, all view files are in the views subfolder, and all main model and controller files are in the models and controllers subfolders, respectively. They are also supplemented by installation, configuration and auxiliary files.

Files of the administrative part of the componentWeblinks, except index.html files

  • controllers/weblink.php - Main controller for editing Single weblink controller
  • controllers/weblinks.php - Main controller for compiling the Controller and displaying a list of web links on the Weblinks Manager screen
  • helpers/weblinks.php - Provides various methods used in controllers and views
  • models/fields/ordering.php - JformField model displaying the weblink ordering column on the Weblinks Manager screen
  • models/forms/weblink.xml - XML ​​file used in the Jform-Model Field class to layout a form with input fields and edit web links on the screen
  • models/weblink.php - Model for a single screen form Web link model
  • models/weblinks.php - Model for the manager screen form Model of web links
  • sql/install.mysql.utf8.sql - SQL file to create a table of web links during installation
  • sql/uninstall.mysql.ut8.sql - SQL file to remove the weblink table during installation
  • tables/weblink.php - Provides the Model class
  • views/weblink/tmpl/edit_metadata.php - Source layout file for editing web link metadata

Administrative part of the Weblinks component

  • views/weblink/tmpl/edit_params.php - Source layout file for editing single web link selection options
  • views/weblink/tmpl/edit.php - Source layout file for editing a web link
  • views/view.html.php - Main view class for displaying a single web link in HTML format Source layout file for web link manager
  • views/weblinks/view.html.php - Main view class for displaying web links in HTML format directly on the Weblinks Manager screen
  • access.xml - XML ​​file providing a list of actions for an access control list (ACL) system
  • config.xml - XML ​​file providing a list of options for selecting the configuration of the component
  • controller.php - Main controller class
  • weblinks.php - Entry point for the request
  • weblinks.xml - XML ​​file used to control the installation process

There is a suggestion in the file /includes/joomla.php in function cleanText replace line

$text = strip_tags($text); $text = strip_tags ( $text , " " ) ;

This hack is intended only for pictures that are inserted as normal images. For images inserted by a mambot (mosimage), this hack will not work.

How to make a direct link appear in the com_weblinks component

IN weblinks.html.php you need to replace the line:

$link = sefRelToAbs( "index.php?option=com_weblinks&task=view&catid=". $catid ."&id=" . $row ->id ) ; $link = $row ->url ;

How to make Joomla work on two hosts (domains) at the same time. Those. for example, on the local network at 10.0.0.15 and from the Internet site-firmy.ru. Despite the fact that both addresses are assigned to the same machine.

Firstly, the whole point of the problem is that Joomla displays all images and CSS files (their paths in the template) relative to its $mosConfig_live_site variable - the base address of the site entered during installation. And if someone tries to access it with a different address, then nothing in the logic of its operation changes - the base address is taken from the configuration file. For example, if the configuration states that Joomla is located on localhost, then accessing from the local network, even to a correctly configured Apache listening to the address 192.168.0.1, will not change anything in it - the src of the images will still begin with “localhost”, which for other machines will already have its own localhost. The focus of solutions for such cases is to replace the $mosConfig_live_site variable for the requested host, so that all functions can issue the correct links and already lead the user to either one or another virtual site (give the correct basic paths to pictures and basic paths to addresses). There is a mambot Auto live site that can automate this. If it does not suit you in some way, then in principle it can be repeated, for this purpose. configuration.php In place of the definition of $mosConfig_live_site you need to write your code. Something like:

if ($_SERVER [ "HTTP_HOST" ] =="host1.ru" ) $mosConfig_live_site = "host1.ru" ; else $mosConfig_live_site = "host2.ru" ;

It is necessary to pay attention that if you use a cache, you must also have two different caching directories for two hosts, because links to different hosts may intersect in the cache, and then a user from the wrong network will not get anywhere at all. The $mosConfig_cachepath variable is responsible for the cache.

How to make two components appear simultaneously on one page

I’ll tell you right away - not everything is so simple. It's not a module, after all. Therefore, firstly, it is worth looking for an alternative, i.e. Surely a popular component comes with modules that can replicate its functionality. If there is nothing like that then this is an option. It can be made as a module, or, in theory, it can be inserted into a template. The idea is this - calling the component via index2.php (what and why - read the entire fact). Those. you can make an iframe with src="index2.php?option=com_component&no_html=1" at the desired insertion point for the second component. And it will be displayed there. Another thing is that it is unlikely that it will be possible to fully ensure functionality. But nevertheless, this is a way out.

Or use the construction: mosLoadComponent("com_mycomp" ) ;

But, if the component is executed in this way, then you need to understand that it does not know about your manipulations and will work according to its $option and $task.

How to increase the length of the title in an article

You need to run the following two commands in phpMyAdmin (there is a special page for executing SQL queries), just replace ###_ with your real table prefix. The maximum possible number is 255. In the example, 200 is used.

ALTER TABLE `###_content` CHANGE `title_alias` `title_alias` VARCHAR(200) NOT NULL; ALTER TABLE `###_content` CHANGE `title` `title` VARCHAR(200) NOT NULL;

How to include full news texts in your RSS feed, not just their headlines

To do this, in the file /components/com_rss/rss.php, you need to replace

$item_description = $row ->introtext ; $item_description = $row ->fulltext ;

How can I make two Joomla sites using the same database or using the same files?

As for using one database, you need to write one database in configuration.php for two engines, but you need to understand what you are doing. Because maintaining sessions for users in this case will be very problematic, because the domains are different. Those. login entries in the #__sessions table will (may) overlap.

If you want to use the same files without copying a large distribution, then in principle you can use the “ln -s” command in Linux to create symbolic links to existing files and not copy them for the new site.

How to create a virtual page accessible at a specific address in the general Joomla design (http:/ /site.ru/super_page)

  • The first way is to use some kind of SEF component, in which you specify the desired virtual path for a static page. There is a minus here - this component will begin to remake all other links (and in general these components are very power-hungry and require a lot of resources to work).
  • Create an alias for such a page using mod_rewrite And .htaccess. To do this you need:
    • Create a static page with the text you need, find out its ID and address (it is not necessary to create such a page, it may already exist and in general it is just any component, not necessarily com_content)
    • Come up with an alias, let it be " super_puper"
    • Open .htaccess and before the line "RewriteCond %(REQUEST_FILENAME) !-f" write:
RewriteRule ^(super_puper) index.php?option=com_content&task=view&id=12 RewriteCond %(REQUEST_FILENAME) !-f
    • And now, provided that Joomla is located at site.ru, when you open the link http:/ /site.ru/super_puper the required static page with your information will open. The link itself "index.php?option=com_content&task=view&id=12" can be whatever you need, the main thing is that the link was not absolute (i.e. with http:/ /...) and relative ( must start with index.php?...)

How to disable caching for a specific article

This may be necessary if you use the rd_addphp mambot to insert any scripts that should generate random numbers or random text every time, regardless of the Joomla caching system. To disable caching of a certain item, you need to find out its ID (in the admin panel, when editing, look at the address bar, it will say something like "...&id=123..."). So 123 will be our article ID. It is necessary to replace in the file /components/com_content/content.php approximately on line 1600

$cache ->call ( "HTML_content::show" , $row , $params , $access , $page ) ; if ($row ->id !="123" ) $cache ->call ( "HTML_content::show" , $row , $params , $access , $page ) ; else HTML_content::show ($row, $params, $access, $page) ;

Where 123 is the article ID you need.

I installed a lot of components, but the list of components in the admin menu shows a reduced number of them, and then it says “More components...”. How to display all components.

You need a line in the file /administrator/modules/mod_fullmenu.php

$topLevelLimit = 19 ;

replaced by

$topLevelLimit = 199 ;

How to install a copy of a component

It must be said that the task is extremely difficult. If you don't understand how the component works, then you shouldn't even try. For those who still want to note the main points:

  • In the XML file, rename the component name in the name tag
  • Next, you need to rename the tables used (firstly in the XML file, and secondly in all component files, wherever the database object is used $database and method setQuery)
  • Rename all paths in components too. Paths can be used in references to itself or in the names of included files. Most often, this comes down to searching for the substring com_component name and replacing it with a new one.

But this method does not guarantee anything. With simple ones, this is possible and will pass, but with complex ones, no one can guarantee.

How to make one position randomly show one of the modules assigned to it

  • Option 1 - hack the mosLoadModules function. In the template, in the place where it is necessary to display one of N modules, we write (pay attention to the third argument):
mosLoadModules("position", display_setup,true);

And we slightly correct the above function itself:

function mosLoadModules( $position ="left" , $style =0 , $show_random = false ) ( ... $allModules =& initModules() ; if (isset ( $GLOBALS [ "_MOS_MODULES" ] [ $position ] ) ) ( $modules = $GLOBALS [ "_MOS_MODULES" ] [ $position ] ; ) else ( $modules = array () ; ) //add here if ($show_random && sizeof ($modules ) >0 ) ( $tmp = $modules [ rand (0 ,sizeof ($modules ) -1 ) ] ; $modules = array ($tmp ) ; // end of statement if ( count ( $modules )< 1 ) { $style = 0 ; }

We added a third argument to it (which is used in the template, where we wrote true) and modified the code.

  • Option two is more painless, we only modify the template. But more labor-intensive - we need to create several positions. First, we create several new module positions, for example new1 ... new10. Save. In the right place in the template, before calling the mosLoadModules function, add the necessary code:
$rand_num = rand(1,10); //from 1 to 10 - as in the position name mosLoadModules ( "new" . $rand_num , display_settings ) ;

I believe that by renaming the /adminisrator/ folder I will make my site more secure

This option is not provided as standard. But in fact, it is possible, by organizing a search in Joomla files, to replace any occurrence of such a word with yours - secret. Sometimes later errors may appear about the inability to access files, but knowing the file and line number they can be corrected. Therefore, the problem is, in principle, solvable.

Layered cake

We will talk about the com_weblinks component and the html markup of the Joomla page. About how to easily and simply create a directory of links on a Joomla website.

This CMS was created for interactive work with a registered user, without direct coding. Although the development trend of Joomla is leading to the abandonment of the com_weblinks component as completely useless on the site, and simply adding extra weight (more than 100 kb - 90 files) to an already “heavy” system. But for now this component is still present in the distribution and is used by some programmers.

The Joomla website page visible on the screen is a layer cake, in the construction of which many blocks (and therefore many templates) are simultaneously involved. This is where the Joomla philosophy comes into play - large-block site building. Each block must have its own HTML markup template (layout).

Main blocks:

The main page template (site_template/index.php), which with its html markup defines positions for modules and components and displays these modules and components.
- page template
- module templates
- component templates

Each of these large blocks is available for editing (changes). That is, you can edit separately, for example, the template of any module or component, and it will look new on the page. The same goes for the page template.

It can be difficult for a novice programmer to understand that the first line in the content part of the page is displayed as the page title and is edited on the edit page of the menu item that points to this page. That the second line is derived from the com_content or com_weblinks component template. And strings in templates are usually string variables and their initialization and localization is carried out in language files, such as language\ru-RU\ru-RU.mod_weblinks.ini and the like.

Sometimes a beginner is perplexed by which template produced this or that line, which on the screen page looks like a logical continuation of the same narrative. It turns out that one line is in one template, another in the second template, and a third in the third. And the tabbed table below is the output from the mod_tabform module template.

Sometimes module templates are called layouts. But this is a question of terminology. The essence is the same - it is “clothing” for the content. It would be more correct to say marking. So, the markup of one screen page is located in different Joomla directory files.

Menu

Many new Joomla programmers often do not understand that menu items can have different types. In other words, menu items can refer to Joomla objects of different types. These can be different objects, such as: components (voting, search, link directory, etc.).

Selecting a menu item type:

Contacts (com_contact)
List of contact categories (categories)
List of contacts of a given category (category)
Contact ( contact)
Favorite contacts (featured)

Materials (com_content)
Archive materials (archive)
Material (article)
List of all categories ( categories)
Blog category
List of category materials (category)
Featured materials
Create material

Smart Search (com_search)
Search ( search)

Hello World! ( com_helloworld)
Message ( helloworld)

News feeds (com_newsfeeds)
List of all news feed categories ( categories)
List of news feeds in category (category)
Newsfeed

Search ( com_search)
Search form and list of search results (search)

User Manager (com_users)
Authorization form (login)
User profile (profile)
Change user profile
Registration form
Username recovery (remind)
Changing the password (reset)

Wrapper (com_wrapper)
Wrapper

As you can see, here all menu types are components. By its name, the menu item type actually indicates the name of the template of its component type. And component templates are located in the views directories:

joomla\components\com_weblinks\views\categories
joomla\components\com_weblinks\views\category
joomla\components\com_weblinks\views\weblink
joomla\components\com_users\views\login

As you can see, the names of the link types in the menu and the names of the templates in the vews directories are the same.

The developer has the ability to create new non-standard templates (layouts) for components. These new layouts will also be reflected as new menu types in the menu type selection window. This is a separate topic.

Joomla distribution demo content

Let's see how the hierarchy of the "About Joomla" Menu items is built to display the com_weblinks Component on the default demo content (Beez2 - Default) Joomla template.

Let's go to the admin panel to edit the com_weblinks component: Components->Links. We see that in the demo content that comes with the distribution, five categories have been created for the com_weblinks component. This means the links will be distributed into five categories. All created categories will be saved in the #_categories database table. Categories for other components are also stored in the same table.

Sample Data-Weblinks
|-Park Links
|-Joomla! Specific Links
|-|-Other Resources
Uncategorised

In the About Joomla menu (in the menu editor), a hierarchy of menu items has been created accordingly:

Hierarchy of menu items:

Using Joomla! (type: material)
|-Using Extensions (type: list of all categories) :: list of categories in materials
|-|-Components (type: category blog) :: category in materials
|-|-|-Weblinks Component (type: material)
|-|-|-|-Submit a Weblink (type: create link) :: in the Links component
|-|-|-|-Weblinks Single Category (type: list of links in a category) :: in the Links component
|-|-|-|-Weblinks Categories (type: list of link categories) :: in the Links component

We see that some menu items have types: list of categories, list of links in a category, and create link.
The "List of Link Categories" specifies the top category from which the hierarchy will be shown.
The "List of links in a category" specifies the category whose links will be displayed.
In the “Create link” item, a form will be displayed that the registered user will have to fill out.
By the way, this is what the link to this form looks like in the editor (its appearance will change in the address bar):

index.php?option=com_weblinks&view=form&layout=edit

Some menu items can only be shown to registered users! For example, a menu item with the type "Create link" will be visible only to registered users. This feature was created specifically so that registered users can create links that will be posted on the page.

Thus, the com_weblinks component provides a good way to interactively populate a page with interesting links. Moreover, all links that will be placed on such a page have a redirect, that is, they will not be indexed as external. You may have seen such links on forums. When you hover your mouse over such a link, you will see the address of your site, and only after clicking on it will you be redirected to the address you specified.

The ability for the user to add links to external sites is the main advantage and meaning of the com_weblinks component, as is the ability for the user to add new content - articles, images, video files, etc.

Allowing a registered user with rights to fill the site with content without direct coding is the basic philosophy of CMS Joomla.

Uncategorised
Sample Data-Articles
|- Joomla!
|-|- Extensions
|-|-|- Components
|-|-|- Modules
|-|-|-|- Content Modules
|-|-|-|- User Modules
|-|-|-|- Display Modules
|-|-|-|- Utility Modules
|-|-|-|- Navigation Modules
|-|-|- Templates
|-|-|-|- Atomic
|-|-|-|- Beez 20
|-|-|-|- Beez 5
|-|-|- Languages
|-|-|- Plugins
|- Park Site
|-|- Park Blog
|-|- Photo Gallery
|-|-|- Animals
|-|-|- Scenery
|- Fruit Shop Site
|-|- Growers
|-|- Recipes

There don't seem to be too many categories for content!
You can also view the hierarchy of categories in materials using a query to the category table in the database:

SELECT * FROM `#_categories` WHERE `extension` = "com_content"